added list of files for the whole channel

This commit is contained in:
csoler 2020-06-07 14:50:31 +02:00
parent 591ffc2fa7
commit 944c5b3592
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
7 changed files with 67 additions and 34 deletions

View File

@ -345,6 +345,7 @@ QVariant RsGxsChannelPostFilesModel::data(const QModelIndex &index, int role) co
{
case Qt::DisplayRole: return displayRole (fmpe,index.column()) ;
case Qt::UserRole: return userRole (fmpe,index.column()) ;
case SortRole: return sortRole (fmpe,index.column()) ;
#ifdef TODO
case Qt::DecorationRole: return decorationRole(fmpe,index.column()) ;
case Qt::ToolTipRole: return toolTipRole (fmpe,index.column()) ;
@ -355,7 +356,6 @@ QVariant RsGxsChannelPostFilesModel::data(const QModelIndex &index, int role) co
case ThreadPinnedRole: return pinnedRole (fmpe,index.column()) ;
case MissingRole: return missingRole (fmpe,index.column()) ;
case StatusRole: return statusRole (fmpe,index.column()) ;
case SortRole: return sortRole (fmpe,index.column()) ;
#endif
default:
return QVariant();
@ -542,39 +542,26 @@ QVariant RsGxsChannelPostFilesModel::sizeHintRole(int col) const
#endif
}
#ifdef TODO
QVariant RsGxsForumModel::authorRole(const ForumModelPostEntry& fmpe,int column) const
{
if(column == COLUMN_THREAD_DATA)
return QVariant(QString::fromStdString(fmpe.mAuthorId.toStdString()));
return QVariant();
}
QVariant RsGxsForumModel::sortRole(const ForumModelPostEntry& fmpe,int column) const
QVariant RsGxsChannelPostFilesModel::sortRole(const RsGxsFile& fmpe,int column) const
{
switch(column)
{
case COLUMN_THREAD_DATE: if(mSortMode == SORT_MODE_PUBLISH_TS)
return QVariant(QString::number(fmpe.mPublishTs)); // we should probably have leading zeroes here
else
return QVariant(QString::number(fmpe.mMostRecentTsInThread)); // we should probably have leading zeroes here
case COLUMN_THREAD_READ: return QVariant((bool)IS_MSG_UNREAD(fmpe.mMsgStatus));
case COLUMN_THREAD_DISTRIBUTION: return decorationRole(fmpe,column);
case COLUMN_THREAD_AUTHOR:
case COLUMN_FILES_NAME: return QVariant(QString::fromUtf8(fmpe.mName.c_str()));
case COLUMN_FILES_SIZE: return QVariant(qulonglong(fmpe.mSize));
case COLUMN_FILES_FILE:
{
QString str,comment ;
QList<QIcon> icons;
GxsIdDetails::MakeIdDesc(fmpe.mAuthorId, false, str, icons, comment,GxsIdDetails::ICON_TYPE_NONE);
FileInfo finfo;
if(rsFiles->FileDetails(fmpe.mHash,RS_FILE_HINTS_DOWNLOAD,finfo))
return qulonglong(finfo.transfered);
return QVariant(str);
return QVariant(qulonglong(fmpe.mSize));
}
break;
default:
return displayRole(fmpe,column);
}
}
#endif
QVariant RsGxsChannelPostFilesModel::displayRole(const RsGxsFile& fmpe,int col) const
{

View File

@ -53,15 +53,9 @@ public:
COLUMN_FILES_NB_COLUMNS = 0x03
};
#ifdef TODO
enum Roles{ SortRole = Qt::UserRole+1,
ThreadPinnedRole = Qt::UserRole+2,
MissingRole = Qt::UserRole+3,
StatusRole = Qt::UserRole+4,
UnreadChildrenRole = Qt::UserRole+5,
FilterRole = Qt::UserRole+6,
FilterRole = Qt::UserRole+2,
};
#endif
#ifdef TODO
enum SortMode{ SORT_MODE_PUBLISH_TS = 0x00,
@ -110,13 +104,13 @@ public:
QVariant displayRole (const RsGxsFile& fmpe, int col) const;
QVariant toolTipRole (const RsGxsFile& fmpe, int col) const;
QVariant userRole (const RsGxsFile& fmpe, int col) const;
QVariant sortRole (const RsGxsFile& fmpe, int col) const;
#ifdef TODO
QVariant decorationRole(const ForumModelPostEntry& fmpe, int col) const;
QVariant pinnedRole (const ForumModelPostEntry& fmpe, int col) const;
QVariant missingRole (const ForumModelPostEntry& fmpe, int col) const;
QVariant statusRole (const ForumModelPostEntry& fmpe, int col) const;
QVariant authorRole (const ForumModelPostEntry& fmpe, int col) const;
QVariant sortRole (const ForumModelPostEntry& fmpe, int col) const;
QVariant fontRole (const ForumModelPostEntry& fmpe, int col) const;
QVariant filterRole (const ForumModelPostEntry& fmpe, int col) const;
QVariant textColorRole (const ForumModelPostEntry& fmpe, int col) const;

View File

@ -71,6 +71,22 @@ void RsGxsChannelPostsModel::postMods()
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mPosts.size(),mColumns-1,(void*)NULL));
}
void RsGxsChannelPostsModel::getFilesList(std::list<RsGxsFile>& files)
{
// We use an intermediate map so as to remove duplicates
std::map<RsFileHash,RsGxsFile> files_map;
for(uint32_t i=1;i<mPosts.size();++i)
for(auto& file:mPosts[i].mFiles)
files_map[file.mHash] = file;
files.clear();
for(auto& it:files_map)
files.push_back(it.second);
}
void RsGxsChannelPostsModel::setTreeMode(TreeMode mode)
{
if(mode == mTreeMode)

View File

@ -111,6 +111,11 @@ public:
void setTreeMode(TreeMode mode) ;
void setNumColumns(int n);
// Retrieve the full list of files for all posts.
void getFilesList(std::list<RsGxsFile>& files);
#ifdef TODO
void setSortMode(SortMode mode) ;

View File

@ -255,8 +255,11 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI
ui->channelPostFiles_TV->setPlaceholderText(tr("Post files"));
ui->channelFiles_TV->setPlaceholderText(tr("All files in the channel"));
ui->channelFiles_TV->setModel(mChannelFilesModel = new RsGxsChannelPostFilesModel());
ui->channelFiles_TV->setItemDelegate(new ChannelPostFilesDelegate());
connect(ui->postsTree->selectionModel(),SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)),this,SLOT(showPostDetails()));
connect(mChannelPostsModel,SIGNAL(channelLoaded()),this,SLOT(updateChannelFiles()));
QFontMetricsF fm(font());
@ -416,6 +419,20 @@ void GxsChannelPostsWidgetWithModel::showPostDetails()
ui->channelPostFiles_TV->resizeColumnToContents(RsGxsChannelPostFilesModel::COLUMN_FILES_SIZE);
ui->channelPostFiles_TV->resizeColumnToContents(RsGxsChannelPostFilesModel::COLUMN_FILES_NAME);
ui->channelPostFiles_TV->setAutoSelect(true);
}
void GxsChannelPostsWidgetWithModel::updateChannelFiles()
{
std::list<RsGxsFile> files;
mChannelPostsModel->getFilesList(files);
mChannelFilesModel->setFiles(files);
ui->channelFiles_TV->resizeColumnToContents(RsGxsChannelPostFilesModel::COLUMN_FILES_FILE);
ui->channelFiles_TV->resizeColumnToContents(RsGxsChannelPostFilesModel::COLUMN_FILES_SIZE);
ui->channelFiles_TV->resizeColumnToContents(RsGxsChannelPostFilesModel::COLUMN_FILES_NAME);
ui->channelFiles_TV->setAutoSelect(true);
}
void GxsChannelPostsWidgetWithModel::updateGroupData()

View File

@ -136,6 +136,7 @@ private slots:
void setViewMode(int viewMode);
void settingsChanged();
void handlePostsTreeSizeChange(QSize s);
void updateChannelFiles();
private:
void processSettings(bool load);
@ -157,6 +158,7 @@ private:
RsGxsChannelPostsModel *mChannelPostsModel;
RsGxsChannelPostFilesModel *mChannelPostFilesModel;
RsGxsChannelPostFilesModel *mChannelFilesModel;
/* UI - from Designer */
Ui::GxsChannelPostsWidgetWithModel *ui;

View File

@ -224,7 +224,7 @@
<item>
<widget class="QTabWidget" name="channel_TW">
<property name="currentIndex">
<number>1</number>
<number>2</number>
</property>
<widget class="QWidget" name="tab_3">
<attribute name="title">
@ -530,6 +530,11 @@ p, li { white-space: pre-wrap; }
<attribute name="title">
<string>Comments</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QWidget" name="commentsDialog" native="true"/>
</item>
</layout>
</widget>
</widget>
</widget>
@ -542,7 +547,14 @@ p, li { white-space: pre-wrap; }
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="RSTreeView" name="channelFiles_TV"/>
<widget class="RSTreeView" name="channelFiles_TV">
<property name="editTriggers">
<set>QAbstractItemView::CurrentChanged|QAbstractItemView::SelectedClicked</set>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>