Add Download All files in Channel post

This commit is contained in:
Phenom 2020-11-06 18:05:39 +01:00
parent e0ce5632ef
commit c5a80cce36
5 changed files with 109 additions and 47 deletions

View File

@ -284,6 +284,7 @@ void GxsChannelFilesStatusWidget::download()
rsFiles->FileRequest(mFile.mName, mFile.mHash, mFile.mSize, destination, RS_FILE_REQ_ANONYMOUS_ROUTING, sources); rsFiles->FileRequest(mFile.mName, mFile.mHash, mFile.mSize, destination, RS_FILE_REQ_ANONYMOUS_ROUTING, sources);
emit onButtonClick();// Signals the parent widget to e.g. update the downloadable file count
check(); check();
} }
@ -291,6 +292,7 @@ void GxsChannelFilesStatusWidget::pause()
{ {
rsFiles->FileControl(mFile.mHash, RS_FILE_CTRL_PAUSE); rsFiles->FileControl(mFile.mHash, RS_FILE_CTRL_PAUSE);
emit onButtonClick();// Signals the parent widget to e.g. update the downloadable file count
check(); check();
} }
@ -298,6 +300,7 @@ void GxsChannelFilesStatusWidget::resume()
{ {
rsFiles->FileControl(mFile.mHash, RS_FILE_CTRL_START); rsFiles->FileControl(mFile.mHash, RS_FILE_CTRL_START);
emit onButtonClick();// Signals the parent widget to e.g. update the downloadable file count
check(); check();
} }
@ -309,6 +312,7 @@ void GxsChannelFilesStatusWidget::cancel()
rsFiles->FileCancel(mFile.mHash); rsFiles->FileCancel(mFile.mHash);
emit onButtonClick();// Signals the parent widget to e.g. update the downloadable file count
check(); check();
} }

View File

@ -37,6 +37,10 @@ public:
explicit GxsChannelFilesStatusWidget(const RsGxsFile &file, QWidget *parent = 0); explicit GxsChannelFilesStatusWidget(const RsGxsFile &file, QWidget *parent = 0);
~GxsChannelFilesStatusWidget(); ~GxsChannelFilesStatusWidget();
signals:
void onButtonClick();
private slots: private slots:
void check(); void check();
void download(); void download();

View File

@ -56,7 +56,7 @@
* #define DEBUG_CHANNEL * #define DEBUG_CHANNEL
***/ ***/
static const int mTokenTypeGroupData = 1; //static const int mTokenTypeGroupData = 1;
static const int CHANNEL_TABS_DETAILS= 0; static const int CHANNEL_TABS_DETAILS= 0;
static const int CHANNEL_TABS_POSTS = 1; static const int CHANNEL_TABS_POSTS = 1;
@ -268,14 +268,18 @@ void ChannelPostDelegate::setWidgetGrid(bool use_grid)
//=== ChannelPostFilesDelegate ===// //=== ChannelPostFilesDelegate ===//
//===============================================================================================================================================// //===============================================================================================================================================//
QWidget *ChannelPostFilesDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const QWidget *ChannelPostFilesDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/*option*/, const QModelIndex& index) const
{ {
ChannelPostFileInfo file = index.data(Qt::UserRole).value<ChannelPostFileInfo>() ; ChannelPostFileInfo file = index.data(Qt::UserRole).value<ChannelPostFileInfo>() ;
if(index.column() == RsGxsChannelPostFilesModel::COLUMN_FILES_FILE) if(index.column() == RsGxsChannelPostFilesModel::COLUMN_FILES_FILE)
return new GxsChannelFilesStatusWidget(file,parent); {
else GxsChannelFilesStatusWidget* w = new GxsChannelFilesStatusWidget(file,parent);
return NULL; connect(w,SIGNAL(onButtonClick()),this->parent(),SLOT(updateDAll_PB()));
return w;
}
else
return NULL;
} }
void ChannelPostFilesDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const void ChannelPostFilesDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
{ {
@ -381,7 +385,7 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI
connect(ui->commentsDialog,SIGNAL(commentsLoaded(int)),this,SLOT(updateCommentsCount(int))); connect(ui->commentsDialog,SIGNAL(commentsLoaded(int)),this,SLOT(updateCommentsCount(int)));
ui->channelPostFiles_TV->setModel(mChannelPostFilesModel = new RsGxsChannelPostFilesModel(this)); ui->channelPostFiles_TV->setModel(mChannelPostFilesModel = new RsGxsChannelPostFilesModel(this));
ui->channelPostFiles_TV->setItemDelegate(new ChannelPostFilesDelegate()); ui->channelPostFiles_TV->setItemDelegate(new ChannelPostFilesDelegate(this));
ui->channelPostFiles_TV->setPlaceholderText(tr("No files in this post, or no post selected")); ui->channelPostFiles_TV->setPlaceholderText(tr("No files in this post, or no post selected"));
ui->channelPostFiles_TV->setSortingEnabled(true); ui->channelPostFiles_TV->setSortingEnabled(true);
ui->channelPostFiles_TV->sortByColumn(3, Qt::AscendingOrder); // sort by time ui->channelPostFiles_TV->sortByColumn(3, Qt::AscendingOrder); // sort by time
@ -391,7 +395,7 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI
connect(ui->channelFiles_TV->header(),SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(sortColumnFiles(int,Qt::SortOrder))); connect(ui->channelFiles_TV->header(),SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(sortColumnFiles(int,Qt::SortOrder)));
ui->channelFiles_TV->setModel(mChannelFilesModel = new RsGxsChannelPostFilesModel()); ui->channelFiles_TV->setModel(mChannelFilesModel = new RsGxsChannelPostFilesModel());
ui->channelFiles_TV->setItemDelegate(mFilesDelegate = new ChannelPostFilesDelegate()); ui->channelFiles_TV->setItemDelegate(mFilesDelegate = new ChannelPostFilesDelegate(this));
ui->channelFiles_TV->setPlaceholderText(tr("No files in the channel, or no channel selected")); ui->channelFiles_TV->setPlaceholderText(tr("No files in the channel, or no channel selected"));
ui->channelFiles_TV->setSortingEnabled(true); ui->channelFiles_TV->setSortingEnabled(true);
ui->channelFiles_TV->sortByColumn(3, Qt::AscendingOrder); // sort by time ui->channelFiles_TV->sortByColumn(3, Qt::AscendingOrder); // sort by time
@ -404,6 +408,9 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI
ui->postName_LB->hide(); ui->postName_LB->hide();
ui->postTime_LB->hide(); ui->postTime_LB->hide();
ui->postLogo_LB->hide(); ui->postLogo_LB->hide();
ui->postDAll_PB->hide();
connect(ui->postDAll_PB,SIGNAL(clicked()),this,SLOT(download()));
ui->postDetails_TE->setPlaceholderText(tr("No text to display")); ui->postDetails_TE->setPlaceholderText(tr("No text to display"));
@ -411,11 +418,11 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI
ui->splitter->setStretchFactor(0, 1); ui->splitter->setStretchFactor(0, 1);
ui->splitter->setStretchFactor(1, 0); ui->splitter->setStretchFactor(1, 0);
QFontMetricsF fm(font()); QFontMetricsF fm(font());
if(mChannelPostsModel->getMode() == RsGxsChannelPostsModel::TREE_MODE_GRID) if(mChannelPostsModel->getMode() == RsGxsChannelPostsModel::TREE_MODE_GRID)
for(int i=0;i<mChannelPostsModel->columnCount();++i) for(int i=0;i<mChannelPostsModel->columnCount();++i)
ui->postsTree->setColumnWidth(i,mChannelPostsDelegate->cellSize(i,font(),ui->postsTree->width())); ui->postsTree->setColumnWidth(i,mChannelPostsDelegate->cellSize(i,font(),ui->postsTree->width()));
/* Setup UI helper */ /* Setup UI helper */
@ -659,6 +666,34 @@ void GxsChannelPostsWidgetWithModel::download()
rsFiles->FileRequest(file.mName, file.mHash, file.mSize, destination, RS_FILE_REQ_ANONYMOUS_ROUTING, sources); rsFiles->FileRequest(file.mName, file.mHash, file.mSize, destination, RS_FILE_REQ_ANONYMOUS_ROUTING, sources);
} }
ui->postDAll_PB->hide();
}
void GxsChannelPostsWidgetWithModel::updateDAll_PB()
{
QModelIndex index = ui->postsTree->selectionModel()->currentIndex();
RsGxsChannelPost post = index.data(Qt::UserRole).value<RsGxsChannelPost>() ;
size_t newFileToDl = 0;
uint64_t newFileTotalSize = 0;
QString newFilesDetails;
for(auto& file:post.mFiles)
{
FileInfo fileInfo;
if (!rsFiles->FileDetails(file.mHash, RS_FILE_HINTS_DOWNLOAD | RS_FILE_HINTS_SPEC_ONLY, fileInfo)) {
++newFileToDl;
newFileTotalSize += file.mSize;
newFilesDetails += QString::fromUtf8(file.mName.c_str()) + " " + misc::friendlyUnit(file.mSize) + "\n";
}
}
ui->postDAll_PB->setHidden(newFileToDl == 0);
ui->postDAll_PB->setToolTip((newFileToDl == 1 ? tr("Download this file:") : tr("Download All these %1 files:").arg(newFileToDl) ) + "\n"
+ newFilesDetails
+ tr("Totaling: %1").arg(misc::friendlyUnit(newFileTotalSize)));
} }
void GxsChannelPostsWidgetWithModel::editPost() void GxsChannelPostsWidgetWithModel::editPost()
@ -745,9 +780,9 @@ void GxsChannelPostsWidgetWithModel::showPostDetails()
std::cerr << "showPostDetails: setting mSelectedPost to current post Id " << post.mMeta.mMsgId << ". Previous value: " << mSelectedPost << std::endl; std::cerr << "showPostDetails: setting mSelectedPost to current post Id " << post.mMeta.mMsgId << ". Previous value: " << mSelectedPost << std::endl;
mSelectedPost = post.mMeta.mMsgId; mSelectedPost = post.mMeta.mMsgId;
std::list<ChannelPostFileInfo> files; std::list<ChannelPostFileInfo> files;
for(auto& file:post.mFiles) for(auto& file:post.mFiles)
files.push_back(ChannelPostFileInfo(file,post.mMeta.mPublishTs)); files.push_back(ChannelPostFileInfo(file,post.mMeta.mPublishTs));
mChannelPostFilesModel->setFiles(files); mChannelPostFilesModel->setFiles(files);
@ -793,6 +828,8 @@ void GxsChannelPostsWidgetWithModel::showPostDetails()
RsThread::async([postId]() { rsGxsChannels->markRead(postId, true) ; } ); RsThread::async([postId]() { rsGxsChannels->markRead(postId, true) ; } );
} }
updateDAll_PB();
} }
void GxsChannelPostsWidgetWithModel::updateCommentsCount(int n) void GxsChannelPostsWidgetWithModel::updateCommentsCount(int n)
@ -842,21 +879,21 @@ void GxsChannelPostsWidgetWithModel::updateGroupData()
void GxsChannelPostsWidgetWithModel::postChannelPostLoad() void GxsChannelPostsWidgetWithModel::postChannelPostLoad()
{ {
std::cerr << "Post channel load..." << std::endl; std::cerr << "Post channel load..." << std::endl;
if(!mSelectedPost.isNull()) if(!mSelectedPost.isNull())
{ {
QModelIndex index = mChannelPostsModel->getIndexOfMessage(mSelectedPost); QModelIndex index = mChannelPostsModel->getIndexOfMessage(mSelectedPost);
std::cerr << "Setting current index to " << index.row() << ","<< index.column() << " for current post " std::cerr << "Setting current index to " << index.row() << ","<< index.column() << " for current post "
<< mSelectedPost.toStdString() << std::endl; << mSelectedPost.toStdString() << std::endl;
ui->postsTree->selectionModel()->setCurrentIndex(index,QItemSelectionModel::ClearAndSelect); ui->postsTree->selectionModel()->setCurrentIndex(index,QItemSelectionModel::ClearAndSelect);
ui->postsTree->scrollTo(index);//May change if model reloaded ui->postsTree->scrollTo(index);//May change if model reloaded
ui->postsTree->setFocus(); ui->postsTree->setFocus();
} }
else else
std::cerr << "No pre-selected channel post." << std::endl; std::cerr << "No pre-selected channel post." << std::endl;
std::list<ChannelPostFileInfo> files; std::list<ChannelPostFileInfo> files;
@ -891,6 +928,8 @@ void GxsChannelPostsWidgetWithModel::postChannelPostLoad()
void GxsChannelPostsWidgetWithModel::updateDisplay(bool complete) void GxsChannelPostsWidgetWithModel::updateDisplay(bool complete)
{ {
// First, clear all widget
blank();
#ifdef DEBUG_CHANNEL #ifdef DEBUG_CHANNEL
std::cerr << "udateDisplay: groupId()=" << groupId()<< std::endl; std::cerr << "udateDisplay: groupId()=" << groupId()<< std::endl;
#endif #endif
@ -911,7 +950,7 @@ void GxsChannelPostsWidgetWithModel::updateDisplay(bool complete)
} }
if(complete) // need to update the group data, reload the messages etc. if(complete) // need to update the group data, reload the messages etc.
{ {
#warning todo #warning csoler 2020-06-02 : todo
//saveExpandedItems(mSavedExpandedMessages); //saveExpandedItems(mSavedExpandedMessages);
//if(mGroupId != mChannelPostsModel->currentGroupId()) //if(mGroupId != mChannelPostsModel->currentGroupId())
@ -972,7 +1011,7 @@ QString GxsChannelPostsWidgetWithModel::groupName(bool)
return QString::fromUtf8(mGroup.mMeta.mGroupName.c_str()); return QString::fromUtf8(mGroup.mMeta.mGroupName.c_str());
} }
void GxsChannelPostsWidgetWithModel::groupNameChanged(const QString &name) void GxsChannelPostsWidgetWithModel::groupNameChanged(const QString &/*name*/)
{ {
// if (groupId().isNull()) { // if (groupId().isNull()) {
// ui->nameLabel->setText(tr("No Channel Selected")); // ui->nameLabel->setText(tr("No Channel Selected"));
@ -1114,13 +1153,13 @@ void GxsChannelPostsWidgetWithModel::insertChannelDetails(const RsGxsChannelGrou
ui->infoAdministrator->setId(group.mMeta.mAuthorId) ; ui->infoAdministrator->setId(group.mMeta.mAuthorId) ;
if(!group.mMeta.mAuthorId.isNull()) if(!group.mMeta.mAuthorId.isNull())
{ {
RetroShareLink link = RetroShareLink::createMessage(group.mMeta.mAuthorId, ""); RetroShareLink link = RetroShareLink::createMessage(group.mMeta.mAuthorId, "");
ui->infoAdministrator->setText(link.toHtml()); ui->infoAdministrator->setText(link.toHtml());
} }
else else
ui->infoAdministrator->setText("[No contact author]"); ui->infoAdministrator->setText("[No contact author]");
ui->infoCreated->setText(DateTime::formatLongDateTime(group.mMeta.mPublishTs)); ui->infoCreated->setText(DateTime::formatLongDateTime(group.mMeta.mPublishTs));
@ -1233,6 +1272,7 @@ void GxsChannelPostsWidgetWithModel::blank()
ui->postLogo_LB->hide(); ui->postLogo_LB->hide();
ui->postName_LB->hide(); ui->postName_LB->hide();
ui->postTime_LB->hide(); ui->postTime_LB->hide();
ui->postDAll_PB->hide();
groupNameChanged(QString()); groupNameChanged(QString());
} }
@ -1320,11 +1360,11 @@ public:
void GxsChannelPostsWidgetWithModel::setAllMessagesReadDo(bool read, uint32_t& /*token*/) void GxsChannelPostsWidgetWithModel::setAllMessagesReadDo(bool read, uint32_t& /*token*/)
{ {
if (groupId().isNull() || !IS_GROUP_SUBSCRIBED(mGroup.mMeta.mSubscribeFlags)) if (groupId().isNull() || !IS_GROUP_SUBSCRIBED(mGroup.mMeta.mSubscribeFlags))
return; return;
QModelIndex src_index; //QModelIndex src_index;
mChannelPostsModel->setAllMsgReadStatus(read); mChannelPostsModel->setAllMsgReadStatus(read);
} }

View File

@ -142,8 +142,9 @@ protected:
private slots: private slots:
void showPostDetails(); void showPostDetails();
void updateGroupData(); void updateGroupData();
void download(); void download();
void createMsg(); void updateDAll_PB();
void createMsg();
// void toggleAutoDownload(); // void toggleAutoDownload();
void subscribeGroup(bool subscribe); void subscribeGroup(bool subscribe);
void filterChanged(QString); void filterChanged(QString);

View File

@ -380,7 +380,7 @@
<string notr="true">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt; <string notr="true">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt; &lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; } p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;&quot;&gt; &lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Noto Sans'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:8pt;&quot;&gt;Description&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> &lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:8pt;&quot;&gt;Description&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>
<property name="textInteractionFlags"> <property name="textInteractionFlags">
@ -496,6 +496,17 @@ p, li { white-space: pre-wrap; }
</property> </property>
</spacer> </spacer>
</item> </item>
<item>
<widget class="QPushButton" name="postDAll_PB">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/icons/png/download.png</normaloff>:/icons/png/download.png</iconset>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
<item> <item>
@ -506,6 +517,7 @@ p, li { white-space: pre-wrap; }
<font> <font>
<weight>75</weight> <weight>75</weight>
<bold>true</bold> <bold>true</bold>
<kerning>true</kerning>
</font> </font>
</property> </property>
<property name="text"> <property name="text">
@ -613,24 +625,25 @@ p, li { white-space: pre-wrap; }
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>
<class>GxsIdLabel</class> <class>LineEditClear</class>
<extends>QLabel</extends> <extends>QLineEdit</extends>
<header>gui/gxs/GxsIdLabel.h</header> <header>gui/common/LineEditClear.h</header>
</customwidget> </customwidget>
<customwidget> <customwidget>
<class>SubscribeToolButton</class> <class>SubscribeToolButton</class>
<extends>QToolButton</extends> <extends>QToolButton</extends>
<header>gui/common/SubscribeToolButton.h</header> <header>gui/common/SubscribeToolButton.h</header>
</customwidget> </customwidget>
<customwidget>
<class>GxsIdLabel</class>
<extends>QLabel</extends>
<header>gui/gxs/GxsIdLabel.h</header>
</customwidget>
<customwidget> <customwidget>
<class>RSTreeView</class> <class>RSTreeView</class>
<extends>QTreeView</extends> <extends>QTreeView</extends>
<header>gui/common/RSTreeView.h</header> <header>gui/common/RSTreeView.h</header>
</customwidget> <container>1</container>
<customwidget>
<class>LineEditClear</class>
<extends>QLineEdit</extends>
<header>gui/common/LineEditClear.h</header>
</customwidget> </customwidget>
<customwidget> <customwidget>
<class>GxsCommentDialog</class> <class>GxsCommentDialog</class>