Fix Forum Post ToolButton enabled case.

Clear the tree widget too, when forum group selected else changing post
do nothing.
This commit is contained in:
Phenom 2020-04-28 19:39:07 +02:00
parent 40d9398b38
commit eab5821ac3
3 changed files with 174 additions and 165 deletions

View File

@ -328,15 +328,7 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget
//ui->threadTreeWidget->installEventFilter(this) ; //ui->threadTreeWidget->installEventFilter(this) ;
ui->postText->clear() ; blankPost();
ui->by_label->setId(RsGxsId()) ;
ui->time_label->clear();
ui->lineRight->hide();
ui->lineLeft->hide();
ui->by_text_label->hide();
ui->by_label->hide();
ui->postText->setImageBlockWidget(ui->imageBlockWidget) ;
ui->postText->resetImagesStatus(Settings->getForumLoadEmbeddedImages());
ui->subscribeToolButton->setToolTip(tr( "<p>Subscribing to the forum will gather \ ui->subscribeToolButton->setToolTip(tr( "<p>Subscribing to the forum will gather \
available posts from your subscribed friends, and make the \ available posts from your subscribed friends, and make the \
@ -376,29 +368,17 @@ void GxsForumThreadWidget::handleEvent_main_thread(std::shared_ptr<const RsEvent
void GxsForumThreadWidget::blank() void GxsForumThreadWidget::blank()
{ {
ui->progressBar->hide(); ui->subscribeToolButton->hide();
ui->progressText->hide(); ui->newthreadButton->hide();
ui->postText->clear() ;
ui->by_label->setId(RsGxsId()) ;
ui->time_label->clear();
ui->lineRight->hide();
ui->lineLeft->hide();
ui->by_text_label->hide();
ui->by_label->hide();
ui->postText->setImageBlockWidget(ui->imageBlockWidget) ;
ui->postText->resetImagesStatus(Settings->getForumLoadEmbeddedImages());
#ifdef SUSPENDED_CODE
ui->threadTreeWidget->clear();
#endif
ui->forumName->setText(""); ui->forumName->setText("");
ui->progressText->hide();
ui->progressBar->hide();
ui->viewBox->setEnabled(false);
ui->filterLineEdit->setEnabled(false);
//mThreadModel->clear(); mThreadModel->clear();
mStateHelper->setWidgetEnabled(ui->newthreadButton, false); blankPost();
mStateHelper->setWidgetEnabled(ui->previousButton, false);
mStateHelper->setWidgetEnabled(ui->nextButton, false);
ui->versions_CB->hide();
} }
GxsForumThreadWidget::~GxsForumThreadWidget() GxsForumThreadWidget::~GxsForumThreadWidget()
@ -883,16 +863,38 @@ void GxsForumThreadWidget::clearForumDescription()
ui->postText->clear(); ui->postText->clear();
} }
void GxsForumThreadWidget::blankPost()
{
ui->newmessageButton->setEnabled(false);
ui->previousButton->setEnabled(false);
ui->nextButton->setEnabled(false);
ui->nextUnreadButton->setEnabled(false);
ui->downloadButton->setEnabled(false);
ui->lineLeft->hide();
ui->time_label->clear();
ui->versions_CB->hide();
ui->lineRight->hide();
ui->by_text_label->hide();
ui->by_label->setId(RsGxsId()) ;
ui->by_label->hide();
ui->expandButton->hide();
ui->postText->clear() ;
ui->postText->setImageBlockWidget(ui->imageBlockWidget) ;
ui->postText->resetImagesStatus(Settings->getForumLoadEmbeddedImages());
}
void GxsForumThreadWidget::updateForumDescription(bool success) void GxsForumThreadWidget::updateForumDescription(bool success)
{ {
if(!success) if(!success)
{ {
blank();
QString forum_description = QString("<b>ERROR:</b> Forum could not be loaded. Database might be in heavy use. Please try later."); QString forum_description = QString("<b>ERROR:</b> Forum could not be loaded. Database might be in heavy use. Please try later.");
ui->postText->setText(forum_description); ui->postText->setText(forum_description);
mStateHelper->setWidgetEnabled(ui->newthreadButton, false); mStateHelper->setWidgetEnabled(ui->newthreadButton, false);
return;
return; }
}
std::cerr << "Updating forum description" << std::endl; std::cerr << "Updating forum description" << std::endl;
if (!mThreadId.isNull()) if (!mThreadId.isNull())
@ -906,7 +908,10 @@ void GxsForumThreadWidget::updateForumDescription(bool success)
const RsGxsForumGroup& group = mForumGroup; const RsGxsForumGroup& group = mForumGroup;
ui->forumName->setText(QString::fromUtf8(group.mMeta.mGroupName.c_str())); ui->newthreadButton->show();
ui->forumName->setText(QString::fromUtf8(group.mMeta.mGroupName.c_str()));
ui->viewBox->setEnabled(true);
ui->filterLineEdit->setEnabled(true);
QString anti_spam_features1 ; QString anti_spam_features1 ;
QString forum_description; QString forum_description;
@ -1019,6 +1024,9 @@ void GxsForumThreadWidget::insertMessage()
return; return;
} }
/* blank text, incase we get nothing */
blankPost();
// We use this instead of getCurrentIndex() because right here the currentIndex() is not set yet. // We use this instead of getCurrentIndex() because right here the currentIndex() is not set yet.
QModelIndex index = mThreadProxyModel->mapFromSource(mThreadModel->getIndexOfMessage(mOrigThreadId)); QModelIndex index = mThreadProxyModel->mapFromSource(mThreadModel->getIndexOfMessage(mOrigThreadId));
@ -1043,18 +1051,7 @@ void GxsForumThreadWidget::insertMessage()
return; return;
} }
mStateHelper->setWidgetEnabled(ui->newmessageButton, (IS_GROUP_SUBSCRIBED(mForumGroup.mMeta.mSubscribeFlags) && mThreadId.isNull() == false)); ui->newmessageButton->setEnabled(IS_GROUP_SUBSCRIBED(mForumGroup.mMeta.mSubscribeFlags) && mThreadId.isNull() == false);
/* blank text, incase we get nothing */
ui->postText->clear();
ui->by_label->setId(RsGxsId()) ;
ui->time_label->clear();
ui->lineRight->hide();
ui->lineLeft->hide();
ui->by_text_label->hide();
ui->by_label->hide();
ui->postText->setImageBlockWidget(ui->imageBlockWidget) ;
ui->postText->resetImagesStatus(Settings->getForumLoadEmbeddedImages());
// add/show combobox for versions, if applicable, and enable it. If no older versions of the post available, hide the combobox. // add/show combobox for versions, if applicable, and enable it. If no older versions of the post available, hide the combobox.
@ -1145,11 +1142,12 @@ void GxsForumThreadWidget::insertMessageData(const RsGxsForumMsg &msg)
bool redacted = bool redacted =
(overall_reputation == RsReputationLevel::LOCALLY_NEGATIVE); (overall_reputation == RsReputationLevel::LOCALLY_NEGATIVE);
ui->time_label->setText(DateTime::formatLongDateTime(msg.mMeta.mPublishTs)); ui->nextUnreadButton->setEnabled(true);
ui->by_label->setId(msg.mMeta.mAuthorId);
ui->lineRight->show();
ui->lineLeft->show(); ui->lineLeft->show();
ui->time_label->setText(DateTime::formatLongDateTime(msg.mMeta.mPublishTs));
ui->lineRight->show();
ui->by_text_label->show(); ui->by_text_label->show();
ui->by_label->setId(msg.mMeta.mAuthorId);
ui->by_label->show(); ui->by_label->show();
ui->threadTreeWidget->setFocus(); ui->threadTreeWidget->setFocus();
@ -1171,6 +1169,10 @@ void GxsForumThreadWidget::insertMessageData(const RsGxsForumMsg &msg)
QString extraTxt = RsHtml().formatText(ui->postText->document(), QString::fromUtf8(msg.mMsg.c_str()),flags); QString extraTxt = RsHtml().formatText(ui->postText->document(), QString::fromUtf8(msg.mMsg.c_str()),flags);
ui->postText->setHtml(extraTxt); ui->postText->setHtml(extraTxt);
} }
QStringList urls;
RsHtml::findAnchors(ui->postText->toHtml(), urls);
ui->downloadButton->setEnabled(urls.count() > 0);
} }
void GxsForumThreadWidget::previousMessage() void GxsForumThreadWidget::previousMessage()
@ -1675,6 +1677,9 @@ void GxsForumThreadWidget::filterItems(const QString& text)
void GxsForumThreadWidget::postForumLoading() void GxsForumThreadWidget::postForumLoading()
{ {
if(groupId().isNull())
return;
#ifdef DEBUG_FORUMS #ifdef DEBUG_FORUMS
std::cerr << "Post forum loading..." << std::endl; std::cerr << "Post forum loading..." << std::endl;
#endif #endif
@ -1719,12 +1724,15 @@ void GxsForumThreadWidget::postForumLoading()
// we also need to restore expanded threads // we also need to restore expanded threads
} }
ui->newthreadButton->show();
ui->forumName->setText(QString::fromUtf8(mForumGroup.mMeta.mGroupName.c_str())); ui->forumName->setText(QString::fromUtf8(mForumGroup.mMeta.mGroupName.c_str()));
ui->threadTreeWidget->sortByColumn(RsGxsForumModel::COLUMN_THREAD_DATE, Qt::DescendingOrder); ui->threadTreeWidget->sortByColumn(RsGxsForumModel::COLUMN_THREAD_DATE, Qt::DescendingOrder);
ui->threadTreeWidget->update(); ui->threadTreeWidget->update();
ui->viewBox->setEnabled(true);
ui->filterLineEdit->setEnabled(true);
recursRestoreExpandedItems(mThreadProxyModel->mapFromSource(mThreadModel->root()),mSavedExpandedMessages); recursRestoreExpandedItems(mThreadProxyModel->mapFromSource(mThreadModel->root()),mSavedExpandedMessages);
//mUpdating = false; //mUpdating = false;
} }
void GxsForumThreadWidget::updateGroupData() void GxsForumThreadWidget::updateGroupData()

View File

@ -101,9 +101,9 @@ private slots:
void changedSelection(const QModelIndex &, const QModelIndex &); void changedSelection(const QModelIndex &, const QModelIndex &);
void changedThread(QModelIndex index); void changedThread(QModelIndex index);
void changedVersion(); void changedVersion();
void clickedThread (QModelIndex index); void clickedThread (QModelIndex index);
void postForumLoading(); void postForumLoading();
void reply_with_private_message(); void reply_with_private_message();
void replytoforummessage(); void replytoforummessage();
void editforummessage(); void editforummessage();
@ -157,9 +157,9 @@ private:
void saveExpandedItems(QList<RsGxsMessageId>& expanded_items) const; void saveExpandedItems(QList<RsGxsMessageId>& expanded_items) const;
int getSelectedMsgCount(QList<QTreeWidgetItem*> *pRows, QList<QTreeWidgetItem*> *pRowsRead, QList<QTreeWidgetItem*> *pRowsUnread); int getSelectedMsgCount(QList<QTreeWidgetItem*> *pRows, QList<QTreeWidgetItem*> *pRowsRead, QList<QTreeWidgetItem*> *pRowsUnread);
void setMsgReadStatus(QList<QTreeWidgetItem*> &rows, bool read); void setMsgReadStatus(QList<QTreeWidgetItem*> &rows, bool read);
void markMsgAsReadUnread(bool read, bool children, bool forum, RsGxsMessageId msgId = RsGxsMessageId()); void markMsgAsReadUnread(bool read, bool children, bool forum, RsGxsMessageId msgId = RsGxsMessageId());
void calculateUnreadCount(); void calculateUnreadCount();
void togglethreadview_internal(); void togglethreadview_internal();
@ -178,6 +178,7 @@ private:
private: private:
void setForumDescriptionLoading(); void setForumDescriptionLoading();
void clearForumDescription(); void clearForumDescription();
void blankPost();
RsGxsGroupId mLastForumID; RsGxsGroupId mLastForumID;
RsGxsMessageId mThreadId; RsGxsMessageId mThreadId;

View File

@ -245,32 +245,6 @@
</item> </item>
<item> <item>
<layout class="QGridLayout" name="postLayout"> <layout class="QGridLayout" name="postLayout">
<item row="0" column="6">
<widget class="QToolButton" name="downloadButton">
<property name="maximumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="toolTip">
<string>Download all files</string>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/icons/png/download.png</normaloff>:/icons/png/download.png</iconset>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QToolButton" name="newmessageButton"> <widget class="QToolButton" name="newmessageButton">
<property name="maximumSize"> <property name="maximumSize">
@ -300,53 +274,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="16"> <item row="0" column="2">
<widget class="QPushButton" name="expandButton">
<property name="maximumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/edit_remove24.png</normaloff>:/images/edit_remove24.png</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="10">
<widget class="Line" name="lineRight">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item row="0" column="13">
<spacer name="postHSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="3">
<widget class="QToolButton" name="previousButton"> <widget class="QToolButton" name="previousButton">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed"> <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
@ -384,7 +312,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="4"> <item row="0" column="3">
<widget class="QToolButton" name="nextButton"> <widget class="QToolButton" name="nextButton">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
@ -425,38 +353,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="12"> <item row="0" column="4">
<widget class="GxsIdLabel" name="by_label">
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
<item row="0" column="7">
<widget class="Line" name="lineLeft">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item row="0" column="9">
<widget class="QComboBox" name="versions_CB"/>
</item>
<item row="0" column="8">
<widget class="QLabel" name="time_label">
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
<item row="0" column="11">
<widget class="QLabel" name="by_text_label">
<property name="text">
<string>By </string>
</property>
</widget>
</item>
<item row="0" column="5">
<widget class="QToolButton" name="nextUnreadButton"> <widget class="QToolButton" name="nextUnreadButton">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed"> <sizepolicy hsizetype="Maximum" vsizetype="Fixed">
@ -479,6 +376,109 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="5">
<widget class="QToolButton" name="downloadButton">
<property name="maximumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="toolTip">
<string>Download all files</string>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/icons/png/download.png</normaloff>:/icons/png/download.png</iconset>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="6">
<widget class="Line" name="lineLeft">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item row="0" column="7">
<widget class="QLabel" name="time_label">
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
<item row="0" column="8">
<widget class="QComboBox" name="versions_CB"/>
</item>
<item row="0" column="9">
<widget class="Line" name="lineRight">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item row="0" column="10">
<widget class="QLabel" name="by_text_label">
<property name="text">
<string>By </string>
</property>
</widget>
</item>
<item row="0" column="11">
<widget class="GxsIdLabel" name="by_label">
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
<item row="0" column="12">
<spacer name="postHSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="13">
<widget class="QPushButton" name="expandButton">
<property name="maximumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/edit_remove24.png</normaloff>:/images/edit_remove24.png</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>