diff --git a/.gitmodules b/.gitmodules index 9ac26001d..c9696bc60 100644 --- a/.gitmodules +++ b/.gitmodules @@ -32,3 +32,6 @@ path = libretroshare url = ../libretroshare branch = master +[submodule "retroshare-webui"] + path = retroshare-webui + url = git@github.com:Retroshare/RSNewWebUI diff --git a/RetroShare.pro b/RetroShare.pro index 58ae659ab..944e8204e 100644 --- a/RetroShare.pro +++ b/RetroShare.pro @@ -68,6 +68,13 @@ retroshare_plugins { plugins.target = plugins } +rs_webui { + SUBDIRS += retroshare-webui + retroshare-webui.file = retroshare-webui/webui.pro + retroshare-webui.target = rs_webui + retroshare-webui.depends = retroshare_gui +} + wikipoos { SUBDIRS += pegmarkdown pegmarkdown.file = supportlibs/pegmarkdown/pegmarkdown.pro diff --git a/libbitdht b/libbitdht index 2ddc86fb5..659423769 160000 --- a/libbitdht +++ b/libbitdht @@ -1 +1 @@ -Subproject commit 2ddc86fb575a61170f4c06a00152e3e7dc74c8f4 +Subproject commit 659423769541169457c41f71c8a038e2d64ba079 diff --git a/libretroshare b/libretroshare index a9d4447c5..74cd958cf 160000 --- a/libretroshare +++ b/libretroshare @@ -1 +1 @@ -Subproject commit a9d4447c5660337b4f7945d20e0f4ffd68d918e9 +Subproject commit 74cd958cf8a3c8b3e2d3f8a22657b5e16bdad476 diff --git a/retroshare-gui/src/gui/Circles/CreateCircleDialog.cpp b/retroshare-gui/src/gui/Circles/CreateCircleDialog.cpp index 3c323e286..92003e0a6 100644 --- a/retroshare-gui/src/gui/Circles/CreateCircleDialog.cpp +++ b/retroshare-gui/src/gui/Circles/CreateCircleDialog.cpp @@ -357,8 +357,8 @@ void CreateCircleDialog::addMember(const QString& keyId, const QString& idtype, member->setText(RSCIRCLEID_COL_IDTYPE, idtype); tree->addTopLevelItem(member); - - ui.members_groupBox->setTitle( tr("Invited Members") + " (" + QString::number(ui.treeWidget_membership->topLevelItemCount()) + ")" ); + + updateMembership(); } /** Maybe we can use RsGxsCircleGroup instead of RsGxsCircleDetails ??? (TODO)**/ @@ -413,6 +413,8 @@ void CreateCircleDialog::removeMember() // does this just work? (TODO) delete(item); + + updateMembership(); } void CreateCircleDialog::createCircle() @@ -952,3 +954,8 @@ void CreateCircleDialog::MembershipListCustomPopupMenu( QPoint ) contextMnu.exec(QCursor::pos()); } +void CreateCircleDialog::updateMembership() +{ + ui.members_groupBox->setTitle( tr("Invited Members") + " (" + QString::number(ui.treeWidget_membership->topLevelItemCount()) + ")" ); +} + diff --git a/retroshare-gui/src/gui/Circles/CreateCircleDialog.h b/retroshare-gui/src/gui/Circles/CreateCircleDialog.h index fbbaacb2c..5e713b9c3 100644 --- a/retroshare-gui/src/gui/Circles/CreateCircleDialog.h +++ b/retroshare-gui/src/gui/Circles/CreateCircleDialog.h @@ -56,6 +56,7 @@ private slots: void filterChanged(const QString &text); void createNewGxsId(); void idTypeChanged(); + void updateMembership(); /** Create the context popup menu and it's submenus */ void IdListCustomPopupMenu( QPoint point ); diff --git a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp index ba5fc017d..bb516d5c1 100644 --- a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp @@ -21,6 +21,7 @@ #include "TransfersDialog.h" #include "gui/notifyqt.h" +#include "gui/SoundManager.h" #include "gui/RetroShareLink.h" #include "gui/common/FilesDefs.h" #include "gui/common/RsCollection.h" @@ -1110,9 +1111,16 @@ void TransfersDialog::handleEvent_main_thread(std::shared_ptr eve if(!fe) return; + FileInfo nfo ; + if(!rsFiles->FileDetails(fe->mHash, RS_FILE_HINTS_DOWNLOAD, nfo)) + return ; + switch (fe->mFileTransferEventCode) { case RsFileTransferEventCode::DOWNLOAD_COMPLETE: + SoundManager::play(SOUND_DOWNLOAD_COMPLETE); + if (Settings->getNotifyFlags() & RS_POPUP_DOWNLOAD) + NotifyQt::getInstance()->addToaster(RS_POPUP_DOWNLOAD, fe->mHash.toStdString(), nfo.fname.c_str(),""); case RsFileTransferEventCode::COMPLETED_FILES_REMOVED: getUserNotify()->updateIcon(); diff --git a/retroshare-gui/src/gui/MainWindow.cpp b/retroshare-gui/src/gui/MainWindow.cpp index 0af20e824..a59d76dfb 100644 --- a/retroshare-gui/src/gui/MainWindow.cpp +++ b/retroshare-gui/src/gui/MainWindow.cpp @@ -1628,6 +1628,11 @@ NATStatus *MainWindow::natstatusInstance() return natstatus; } +void MainWindow::torstatusReset() +{ + if(torstatus != nullptr) + torstatus->reset(); +} DHTStatus *MainWindow::dhtstatusInstance() { return dhtstatus; diff --git a/retroshare-gui/src/gui/MainWindow.h b/retroshare-gui/src/gui/MainWindow.h index 23b70e66f..bac210f2c 100644 --- a/retroshare-gui/src/gui/MainWindow.h +++ b/retroshare-gui/src/gui/MainWindow.h @@ -187,6 +187,7 @@ public: RSComboBox *statusComboBoxInstance(); PeerStatus *peerstatusInstance(); NATStatus *natstatusInstance(); + void torstatusReset(); DHTStatus *dhtstatusInstance(); HashingStatus *hashingstatusInstance(); DiscStatus *discstatusInstance(); diff --git a/retroshare-gui/src/gui/NewsFeed.cpp b/retroshare-gui/src/gui/NewsFeed.cpp index 252560d43..36f547738 100644 --- a/retroshare-gui/src/gui/NewsFeed.cpp +++ b/retroshare-gui/src/gui/NewsFeed.cpp @@ -441,6 +441,8 @@ void NewsFeed::handleConnectionEvent(std::shared_ptr event) { case RsConnectionEventCode::PEER_CONNECTED: addFeedItemIfUnique(new PeerItem(this, NEWSFEED_PEERLIST, e.mSslId, PEER_TYPE_CONNECT, false), true); + if (Settings->getNotifyFlags() & RS_POPUP_CONNECT) + NotifyQt::getInstance()->addToaster(RS_POPUP_CONNECT, e.mSslId.toStdString().c_str(), "", ""); break; case RsConnectionEventCode::PEER_DISCONNECTED: // not handled yet break; @@ -476,6 +478,7 @@ void NewsFeed::handleSecurityEvent(std::shared_ptr event) addFeedItemIfUnique(new PeerItem(this, NEWSFEED_PEERLIST, e.mSslId, PEER_TYPE_HELLO, false), true ); return; } + uint32_t FeedItemType=0; @@ -504,6 +507,9 @@ void NewsFeed::handleSecurityEvent(std::shared_ptr event) if (Settings->getMessageFlags() & RS_MESSAGE_CONNECT_ATTEMPT) MessageComposer::addConnectAttemptMsg(e.mPgpId, e.mSslId, QString::fromStdString(det.name + "(" + det.location + ")")); + + if (Settings->getNotifyFlags() & RS_POPUP_CONNECT_ATTEMPT) + NotifyQt::getInstance()->addToaster(RS_POPUP_CONNECT_ATTEMPT, e.mPgpId.toStdString().c_str(), det.location, e.mSslId.toStdString().c_str()); } void NewsFeed::testFeeds(uint /*notifyFlags*/) diff --git a/retroshare-gui/src/gui/TheWire/PulseMessage.cpp b/retroshare-gui/src/gui/TheWire/PulseMessage.cpp index 8f4a91873..34724282f 100644 --- a/retroshare-gui/src/gui/TheWire/PulseMessage.cpp +++ b/retroshare-gui/src/gui/TheWire/PulseMessage.cpp @@ -29,10 +29,10 @@ PulseMessage::PulseMessage(QWidget *parent) { setupUi(this); - connect(label_image1, SIGNAL(clicked()), this, SLOT(viewPicture())); - connect(label_image2, SIGNAL(clicked()), this, SLOT(viewPicture())); - connect(label_image3, SIGNAL(clicked()), this, SLOT(viewPicture())); - connect(label_image4, SIGNAL(clicked()), this, SLOT(viewPicture())); + connect(label_image1, SIGNAL(clicked()), this, SLOT(viewPictureOne())); + connect(label_image2, SIGNAL(clicked()), this, SLOT(viewPictureTwo())); + connect(label_image3, SIGNAL(clicked()), this, SLOT(viewPictureThree())); + connect(label_image4, SIGNAL(clicked()), this, SLOT(viewPictureFour())); } void PulseMessage::setup(RsWirePulseSPtr pulse) @@ -148,7 +148,7 @@ void PulseMessage::setRefImageCount(uint32_t count) } } -void PulseMessage::viewPicture() +void PulseMessage::viewPictureOne() { PhotoView *photoView = new PhotoView(this); @@ -158,21 +158,69 @@ void PulseMessage::viewPicture() pixmap.loadFromData(mPulse->mImage1.mData, mPulse->mImage1.mSize); photoView->setPixmap(pixmap); } - + + QString timestamp = misc::timeRelativeToNow(mPulse->mRefPublishTs); + + photoView->setTitle(QString::fromStdString(mPulse->mPulseText)); + photoView->setGroupNameString(QString::fromStdString(mPulse->mRefGroupName)); + photoView->setTime(timestamp); + //photoView->setGroupId(mPulse->mRefGroupId); + + photoView->show(); + + /* window will destroy itself! */ +} + +void PulseMessage::viewPictureTwo() +{ + PhotoView *photoView = new PhotoView(this); + if (!mPulse->mImage2.empty()) { // install image. QPixmap pixmap; pixmap.loadFromData(mPulse->mImage2.mData, mPulse->mImage2.mSize); photoView->setPixmap(pixmap); } - + + QString timestamp = misc::timeRelativeToNow(mPulse->mRefPublishTs); + + photoView->setTitle(QString::fromStdString(mPulse->mPulseText)); + photoView->setGroupNameString(QString::fromStdString(mPulse->mRefGroupName)); + photoView->setTime(timestamp); + //photoView->setGroupId(mPulse->mRefGroupId); + + photoView->show(); + + /* window will destroy itself! */ +} + +void PulseMessage::viewPictureThree() +{ + PhotoView *photoView = new PhotoView(this); + if (!mPulse->mImage3.empty()) { // install image. QPixmap pixmap; pixmap.loadFromData(mPulse->mImage3.mData, mPulse->mImage3.mSize); photoView->setPixmap(pixmap); } - + + QString timestamp = misc::timeRelativeToNow(mPulse->mRefPublishTs); + + photoView->setTitle(QString::fromStdString(mPulse->mPulseText)); + photoView->setGroupNameString(QString::fromStdString(mPulse->mRefGroupName)); + photoView->setTime(timestamp); + //photoView->setGroupId(mPulse->mRefGroupId); + + photoView->show(); + + /* window will destroy itself! */ +} + +void PulseMessage::viewPictureFour() +{ + PhotoView *photoView = new PhotoView(this); + if (!mPulse->mImage4.empty()) { // install image. QPixmap pixmap; diff --git a/retroshare-gui/src/gui/TheWire/PulseMessage.h b/retroshare-gui/src/gui/TheWire/PulseMessage.h index a2372ebbf..234f0da02 100644 --- a/retroshare-gui/src/gui/TheWire/PulseMessage.h +++ b/retroshare-gui/src/gui/TheWire/PulseMessage.h @@ -37,7 +37,10 @@ public: void setRefImageCount(uint32_t count); private slots: - void viewPicture(); + void viewPictureOne(); + void viewPictureTwo(); + void viewPictureThree(); + void viewPictureFour(); private: RsWirePulseSPtr mPulse; diff --git a/retroshare-gui/src/gui/common/Emoticons.cpp b/retroshare-gui/src/gui/common/Emoticons.cpp index 9da7530b1..2341039cd 100644 --- a/retroshare-gui/src/gui/common/Emoticons.cpp +++ b/retroshare-gui/src/gui/common/Emoticons.cpp @@ -51,7 +51,7 @@ static QHash iconcache; void Emoticons::load() { loadSmiley(); - filters << "*.png" << "*.jpg" << "*.gif" << "*.webp"; + filters << "*.png" << "*.jpg" << "*.jpeg" << "*.gif" << "*.webp"; stickerFolders << (QString::fromStdString(RsAccounts::AccountDirectory()) + "/stickers"); //under account, unique for user stickerFolders << (QString::fromStdString(RsAccounts::ConfigDirectory()) + "/stickers"); //under .retroshare, shared between users stickerFolders << (QString::fromStdString(RsAccounts::systemDataDirectory()) + "/stickers"); //exe's folder, shipped with RS diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.cpp index a0db07085..856ef32e1 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.cpp @@ -33,11 +33,11 @@ #include "GxsChannelPostFilesModel.h" -//#define DEBUG_CHANNEL_MODEL +//#define DEBUG_CHANNEL_FILES_MODEL Q_DECLARE_METATYPE(ChannelPostFileInfo) -#ifdef DEBUG_CHANNEL_MODEL +#ifdef DEBUG_CHANNEL_FILES_MODEL static std::ostream& operator<<(std::ostream& o, const QModelIndex& i);// defined elsewhere #endif @@ -161,8 +161,8 @@ QModelIndex RsGxsChannelPostFilesModel::index(int row, int column, const QModelI quintptr ref = getChildRef(parent.internalId(),row); -#ifdef DEBUG_CHANNEL_MODEL - std::cerr << "index-3(" << row << "," << column << " parent=" << parent << ") : " << createIndex(row,column,ref) << std::endl; +#ifdef DEBUG_CHANNEL_FILES_MODEL + RsDbg() << "index-3(" << row << "," << column << " parent=" << parent << ") : " << createIndex(row,column,ref) ; #endif return createIndex(row,column,ref) ; } @@ -242,7 +242,7 @@ QVariant RsGxsChannelPostFilesModel::headerData(int section, Qt::Orientation /*o QVariant RsGxsChannelPostFilesModel::data(const QModelIndex &index, int role) const { -#ifdef DEBUG_CHANNEL_MODEL +#ifdef DEBUG_CHANNEL_FILES_MODEL std::cerr << "calling data(" << index << ") role=" << role << std::endl; #endif @@ -259,13 +259,13 @@ QVariant RsGxsChannelPostFilesModel::data(const QModelIndex &index, int role) co quintptr ref = (index.isValid())?index.internalId():0 ; uint32_t entry = 0; -#ifdef DEBUG_CHANNEL_MODEL +#ifdef DEBUG_CHANNEL_FILES_MODEL std::cerr << "data(" << index << ")" ; #endif if(!ref) { -#ifdef DEBUG_CHANNEL_MODEL +#ifdef DEBUG_CHANNEL_FILES_MODEL std::cerr << " [empty]" << std::endl; #endif return QVariant() ; @@ -273,7 +273,7 @@ QVariant RsGxsChannelPostFilesModel::data(const QModelIndex &index, int role) co if(!convertRefPointerToTabEntry(ref,entry) || entry >= mFilteredFiles.size()) { -#ifdef DEBUG_CHANNEL_MODEL +#ifdef DEBUG_CHANNEL_FILES_MODEL std::cerr << "Bad pointer: " << (void*)ref << std::endl; #endif return QVariant() ; @@ -426,7 +426,6 @@ QVariant RsGxsChannelPostFilesModel::userRole(const ChannelPostFileInfo& fmpe,in void RsGxsChannelPostFilesModel::clear() { - initEmptyHierarchy(); emit channelLoaded(); @@ -444,7 +443,7 @@ void RsGxsChannelPostFilesModel::setFiles(const std::list & for(uint32_t i=0;i & postMods(); } + +void RsGxsChannelPostFilesModel::update_files(std::set& added_files,std::set& removed_files) +{ + // 1 - remove common files from both lists + +#ifdef DEBUG_CHANNEL_FILES_MODEL + RsDbg() << "RsGxsChannelPostsFilesModel:: updating files." ; +#endif + + for(auto afit=added_files.begin();afit!=added_files.end();) + { + auto rfit = removed_files.find(*afit); + + if(rfit != removed_files.end()) + { +#ifdef DEBUG_CHANNEL_FILES_MODEL + RsDbg() << " Eliminating common file " << rfit->mName ; +#endif + removed_files.erase(rfit); + auto tmp = afit; + ++tmp; + added_files.erase(afit); + afit = tmp; + } + else + ++afit; + } + + RsDbg() << " Remains: " << added_files.size() << " added files and " << removed_files.size() << " removed files" ; + + // 2 - add whatever file remains, + + for(const auto& f:removed_files) + { +#ifdef DEBUG_CHANNEL_FILES_MODEL + RsDbg() << " Removing deleted file " << f.mName ; +#endif + + for(uint32_t i=0;i& files); + void setFiles(const std::list& files); void setFilter(const QStringList &strings, uint32_t &count) ; + // This method adds/removes the given lists of files. Useful when a single post is updated + void update_files(std::set &added_files, std::set &removed_files); + #ifdef TODO - QModelIndex getIndexOfFile(const RsFileHash& hash) const; + QModelIndex getIndexOfFile(const RsFileHash& hash) const; void setSortMode(SortMode mode) ; - void setTextColorRead (QColor color) { mTextColorRead = color;} - void setTextColorUnread (QColor color) { mTextColorUnread = color;} - void setTextColorUnreadChildren(QColor color) { mTextColorUnreadChildren = color;} - void setTextColorNotSubscribed (QColor color) { mTextColorNotSubscribed = color;} - void setTextColorMissing (QColor color) { mTextColorMissing = color;} - void setAuthorOpinion(const QModelIndex& indx,RsOpinion op); + void setTextColorRead (QColor color) { mTextColorRead = color;} + void setTextColorUnread (QColor color) { mTextColorUnread = color;} + void setTextColorUnreadChildren(QColor color) { mTextColorUnreadChildren = color;} + void setTextColorNotSubscribed (QColor color) { mTextColorNotSubscribed = color;} + void setTextColorMissing (QColor color) { mTextColorMissing = color;} + void setAuthorOpinion(const QModelIndex& indx,RsOpinion op); #endif // Helper functions @@ -112,25 +115,25 @@ public: Qt::ItemFlags flags(const QModelIndex& index) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; - QVariant headerData(int section, Qt::Orientation orientation, int role) const override; + QVariant headerData(int section, Qt::Orientation orientation, int role) const override; // Custom item roles QVariant sizeHintRole (int col) const; - QVariant displayRole (const ChannelPostFileInfo& fmpe, int col) const; - QVariant toolTipRole (const ChannelPostFileInfo& fmpe, int col) const; - QVariant userRole (const ChannelPostFileInfo& fmpe, int col) const; - QVariant sortRole (const ChannelPostFileInfo& fmpe, int col) const; - QVariant filterRole (const ChannelPostFileInfo& fmpe, int col) const; + QVariant displayRole (const ChannelPostFileInfo& fmpe, int col) const; + QVariant toolTipRole (const ChannelPostFileInfo& fmpe, int col) const; + QVariant userRole (const ChannelPostFileInfo& fmpe, int col) const; + QVariant sortRole (const ChannelPostFileInfo& fmpe, int col) const; + QVariant filterRole (const ChannelPostFileInfo& 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 fontRole (const ForumModelPostEntry& fmpe, int col) const; - QVariant textColorRole (const ForumModelPostEntry& fmpe, int col) const; - QVariant backgroundRole(const ForumModelPostEntry& fmpe, int col) const; + 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 fontRole (const ForumModelPostEntry& fmpe, int col) const; + QVariant textColorRole (const ForumModelPostEntry& fmpe, int col) const; + QVariant backgroundRole(const ForumModelPostEntry& fmpe, int col) const; #endif /*! @@ -151,20 +154,20 @@ private: bool mFilteringEnabled; SortMode mSortMode; #endif - void preMods() ; - void postMods() ; + void preMods() ; + void postMods() ; quintptr getParentRow(quintptr ref,int& row) const; quintptr getChildRef(quintptr ref, int index) const; int getChildrenCount(quintptr ref) const; static bool convertTabEntryToRefPointer(uint32_t entry, quintptr& ref); - static bool convertRefPointerToTabEntry(quintptr ref,uint32_t& entry); + static bool convertRefPointerToTabEntry(quintptr ref,uint32_t& entry); #ifdef TODO - static void generateMissingItem(const RsGxsMessageId &msgId,ChannelPostsModelPostEntry& entry); + static void generateMissingItem(const RsGxsMessageId &msgId,ChannelPostsModelPostEntry& entry); #endif - void initEmptyHierarchy(); + void initEmptyHierarchy(); std::vector mFilteredFiles ; // store the list of files for the post std::vector mFiles ; // store the list of files for the post diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp index 25fdd6d0f..11a29903a 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp @@ -35,10 +35,10 @@ #include "GxsChannelPostsModel.h" #include "GxsChannelPostFilesModel.h" -#define DEBUG_CHANNEL_MODEL +//#define DEBUG_CHANNEL_MODEL_DATA +//#define DEBUG_CHANNEL_MODEL Q_DECLARE_METATYPE(RsMsgMetaData) - Q_DECLARE_METATYPE(RsGxsChannelPost) std::ostream& operator<<(std::ostream& o, const QModelIndex& i);// defined elsewhere @@ -47,14 +47,6 @@ RsGxsChannelPostsModel::RsGxsChannelPostsModel(QObject *parent) : QAbstractItemModel(parent), mTreeMode(RsGxsChannelPostsModel::TREE_MODE_GRID), mColumns(6) { initEmptyHierarchy(); - - mEventHandlerId = 0; - // Needs to be asynced because this function is called by another thread! - - rsEvents->registerEventsHandler( [this](std::shared_ptr event) - { - RsQThreadUtils::postToObject([=](){ handleEvent_main_thread(event); }, this ); - }, mEventHandlerId, RsEventType::GXS_CHANNELS ); } RsGxsChannelPostsModel::~RsGxsChannelPostsModel() @@ -72,7 +64,7 @@ void RsGxsChannelPostsModel::setMode(TreeMode mode) triggerViewUpdate(); } -void updateCommentCounts( std::vector& posts, std::vector& comments) +void RsGxsChannelPostsModel::computeCommentCounts( std::vector& posts, std::vector& comments) { // Store posts IDs in a std::map to avoid a quadratic cost @@ -108,99 +100,6 @@ void updateCommentCounts( std::vector& posts, std::vector event) -{ - const RsGxsChannelEvent *e = dynamic_cast(event.get()); - - if(!e) - return; - - switch(e->mChannelEventCode) - { - case RsChannelEventCode::UPDATED_MESSAGE: - case RsChannelEventCode::READ_STATUS_CHANGED: - { - // Normally we should just emit dataChanged() on the index of the data that has changed: - // We need to update the data! - - // make a copy of e, so as to avoid destruction of the shared pointer during async thread execution, since [e] doesn't actually tell - // the original shared_ptr that it is copied! So no counter is updated in event, which will be destroyed (as e will be) during or even before - // the execution of the lambda. - - RsGxsChannelEvent E(*e); - - if(E.mChannelGroupId == mChannelGroup.mMeta.mGroupId) - RsThread::async([this, E]() - { - // 1 - get message data from p3GxsChannels. No need for pointers here, because we send only a single post to postToObject() - // At this point we dont know what kind of msg id we have. It can be a vote, a comment or an actual message. - - std::vector posts; - std::vector comments; - std::vector votes; - std::set msg_ids{ E.mChannelMsgId }; - - if(!rsGxsChannels->getChannelContent(E.mChannelGroupId,msg_ids, posts,comments,votes)) - { - std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve channel message data for channel/msg " << E.mChannelGroupId << "/" << E.mChannelMsgId << std::endl; - return; - } - - // Check if what we have actually is a comment or a vote. If so we need to update the actual message they refer to - - if(posts.empty()) // means we have a comment or a vote - { - msg_ids.clear(); - - for(auto c:comments) msg_ids.insert(c.mMeta.mThreadId); - for(auto v:votes ) msg_ids.insert(v.mMeta.mThreadId); - - comments.clear(); - votes.clear(); - - if(!rsGxsChannels->getChannelContent(E.mChannelGroupId,msg_ids,posts,comments,votes)) - { - std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve channel message data for channel/msg " << E.mChannelGroupId << "/" << E.mChannelMsgId << std::endl; - return; - } - } - - // Need to call this in order to get the actuall comment count. The previous call only retrieves the message, since we supplied the message ID. - // another way to go would be to save the comment ids of the existing message and re-insert them before calling getChannelContent. - - if(!rsGxsChannels->getChannelComments(E.mChannelGroupId,msg_ids,comments)) - { - std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve message comment data for channel/msg " << E.mChannelGroupId << "/" << E.mChannelMsgId << std::endl; - return; - } - - updateCommentCounts(posts,comments); - - // 2 - update the model in the UI thread. - - RsQThreadUtils::postToObject( [posts,this]() - { - for(uint32_t i=0;i& files) files.push_back(it.second); } +bool RsGxsChannelPostsModel::postPassesFilter(const RsGxsChannelPost& post,const QStringList& strings,bool only_unread) const +{ + bool passes_strings = true; + + for(auto& s:strings) + passes_strings = passes_strings && QString::fromStdString(post.mMeta.mMsgName).contains(s,Qt::CaseInsensitive); + + if(strings.empty()) + passes_strings = true; + + if(passes_strings && (!only_unread || (IS_MSG_UNREAD(post.mMeta.mMsgStatus) || IS_MSG_NEW(post.mMeta.mMsgStatus)))) + return true; + + return false; +} + void RsGxsChannelPostsModel::setFilter(const QStringList& strings,bool only_unread, uint32_t& count) +{ + mFilteredStrings = strings; + mFilterUnread = only_unread; + + updateFilter(count); +} + +void RsGxsChannelPostsModel::updateFilter(uint32_t& count) { preMods(); @@ -252,18 +175,8 @@ void RsGxsChannelPostsModel::setFilter(const QStringList& strings,bool only_unre endResetModel(); for(size_t i=0;i= mFilteredPosts.size()) { -#ifdef DEBUG_CHANNEL_MODEL +#ifdef DEBUG_CHANNEL_MODEL_DATA std::cerr << "Bad pointer: " << (void*)ref << std::endl; #endif return QVariant() ; @@ -564,6 +477,79 @@ bool operator<(const RsGxsChannelPost& p1,const RsGxsChannelPost& p2) return p1.mMeta.mPublishTs > p2.mMeta.mPublishTs; } +void RsGxsChannelPostsModel::updateSinglePost(const RsGxsChannelPost& post,std::set& added_files,std::set& removed_files) +{ +#ifdef DEBUG_CHANNEL_MODEL + RsDbg() << "updating single post for group id=" << currentGroupId() << " and msg id=" << post.mMeta.mMsgId ; +#endif + added_files.clear(); + removed_files.clear(); + + emit layoutAboutToBeChanged(); + + // linear search. Not good at all, but normally this is just for a single post. + + bool found = false; + const auto& new_post_meta(post.mMeta); + + for(uint32_t j=0;j& posts) { preMods(); @@ -593,6 +579,8 @@ void RsGxsChannelPostsModel::setPosts(const RsGxsChannelGroup& group, std::vecto emit channelPostsLoaded(); } + + void RsGxsChannelPostsModel::update_posts(const RsGxsGroupId& group_id) { if(group_id.isNull()) @@ -635,7 +623,7 @@ void RsGxsChannelPostsModel::update_posts(const RsGxsGroupId& group_id) // This shouldn't be needed normally. We need it until a background process computes the number of comments per // post and stores it in the service string. Since we request all data, this process isn't costing much anyway. - updateCommentCounts(*posts,*comments); + computeCommentCounts(*posts,*comments); // 2 - update the model in the UI thread. @@ -945,8 +933,28 @@ void RsGxsChannelPostsModel::setAllMsgReadStatus(bool read_status) if(!rsGxsChannels->setMessageReadStatus(p,read_status)) RsErr() << "setAllMsgReadStatus: failed to change status of msg " << p.first << " in group " << p.second << " to status " << read_status << std::endl; }); + + // 3 - update the local model data, since we don't catch the READ_STATUS_CHANGED event later, to avoid re-loading the msg. + + for(uint32_t i=0;isetMessageReadStatus(RsGxsGrpMsgIdPair(mPosts[mFilteredPosts[entry]].mMeta.mGroupId,mPosts[mFilteredPosts[entry]].mMeta.mMsgId),read_status); + + // Quick update to the msg itself. Normally setMsgReadStatus will launch an event, + // that we can catch to update the msg, but all the information is already here. + + if(read_status) + mPosts[mFilteredPosts[entry]].mMeta.mMsgStatus &= ~(GXS_SERV::GXS_MSG_STATUS_GUI_UNREAD | GXS_SERV::GXS_MSG_STATUS_GUI_NEW); + else + mPosts[mFilteredPosts[entry]].mMeta.mMsgStatus |= GXS_SERV::GXS_MSG_STATUS_GUI_UNREAD; + + mPosts[mFilteredPosts[entry]].mUnreadCommentCount = 0; + + emit dataChanged(i,i); } QModelIndex RsGxsChannelPostsModel::getIndexOfMessage(const RsGxsMessageId& mid) const diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.h b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.h index 642bfaa5a..c12e31635 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.h @@ -101,6 +101,7 @@ public: SORT_MODE_CHILDREN_PUBLISH_TS = 0x01, }; #endif + static void computeCommentCounts( std::vector& posts, std::vector& comments); QModelIndex root() const{ return createIndex(0,0,(void*)NULL) ;} QModelIndex getIndexOfMessage(const RsGxsMessageId& mid) const; @@ -138,8 +139,11 @@ public: void setMsgReadStatus(const QModelIndex &i, bool read_status); void setAllMsgReadStatus(bool read_status); + void updatePostWithNewComment(const RsGxsMessageId& msg_id); void setFilter(const QStringList &strings, bool only_unread,uint32_t &count) ; + bool postPassesFilter(const RsGxsChannelPost &post, const QStringList &strings, bool only_unread) const; + void updateFilter(uint32_t& count); #ifdef TODO void setAuthorOpinion(const QModelIndex& indx,RsOpinion op); @@ -215,6 +219,8 @@ private: void update_posts(const RsGxsGroupId& group_id); +private: + #ifdef TODO void setForumMessageSummary(const std::vector& messages); #endif @@ -232,8 +238,13 @@ private: void old_createPostsArray(std::vector &posts); void createPostsArray(std::vector& posts); void setPosts(const RsGxsChannelGroup& group, std::vector &posts); - void initEmptyHierarchy(); - void handleEvent_main_thread(std::shared_ptr event); +public: + void updateSinglePost(const RsGxsChannelPost& post, std::set& added_files, std::set& removed_files); +private: + void initEmptyHierarchy(); + + QStringList mFilteredStrings; + bool mFilterUnread; std::vector mFilteredPosts; // stores the list of displayes indices due to filtering. std::vector mPosts ; // store the list of posts updated from rsForums. diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp index c5b0e010c..b99f71faf 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp @@ -73,12 +73,13 @@ QColor SelectedColor = QRgb(0xff308dc7); #define COLUMN_SIZE_FONT_FACTOR_W 6 #define COLUMN_SIZE_FONT_FACTOR_H 10 -#define STAR_OVERLAY_IMAGE ":icons/star_overlay_128.png" -#define COMMENT_OVERLAY_IMAGE ":images/white-bubble-64.png" -#define IMAGE_COPYLINK ":icons/png/copy.png" -#define IMAGE_GRID_VIEW ":icons/png/menu.png" -#define IMAGE_DOWNLOAD ":icons/png/download.png" -#define IMAGE_UNREAD ":icons/png/message.png" +#define STAR_OVERLAY_IMAGE ":icons/star_overlay_128.png" +#define COMMENT_OVERLAY_IMAGE ":images/white-bubble-64.png" +#define UNREAD_COMMENT_OVERLAY_IMAGE ":images/orange-bubble-64.png" +#define IMAGE_COPYLINK ":icons/png/copy.png" +#define IMAGE_GRID_VIEW ":icons/png/menu.png" +#define IMAGE_DOWNLOAD ":icons/png/download.png" +#define IMAGE_UNREAD ":icons/png/message.png" Q_DECLARE_METATYPE(ChannelPostFileInfo) @@ -99,9 +100,9 @@ int ChannelPostDelegate::cellSize(int col,const QFont& font,uint32_t parent_widt void ChannelPostDelegate::zoom(bool zoom_or_unzoom) { if(zoom_or_unzoom) - mZoom *= 1.02; + mZoom *= 1.02; else - mZoom /= 1.02; + mZoom /= 1.02; if(mZoom < 0.5) mZoom = 0.5; @@ -121,11 +122,7 @@ void ChannelPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem & RsGxsChannelPost post = index.data(Qt::UserRole).value() ; - // if(index.row() & 0x01) - // painter->fillRect( option.rect, option.palette.alternateBase().color()); - // else - painter->fillRect( option.rect, option.palette.base().color()); - + painter->fillRect( option.rect, option.palette.base().color()); painter->restore(); if(mUseGrid || index.column()==0) @@ -144,14 +141,7 @@ void ChannelPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem & if((option.state & QStyle::State_Selected) && post.mMeta.mPublishTs > 0) // check if post is selected and is not empty (end of last row) pixmap.fill(SelectedColor); // I dont know how to grab the backgroud color for selected objects automatically. else - { - // we need to do the alternate color manually - - //if(index.row() & 0x01) - // pixmap.fill(option.palette.alternateBase().color()); - //else - pixmap.fill(option.palette.base().color()); - } + pixmap.fill(option.palette.base().color()); w.render(&pixmap,QPoint(),QRegion(),QWidget::DrawChildren );// draw the widgets, not the background @@ -168,33 +158,39 @@ void ChannelPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem & // file.close(); // } - if(mUseGrid || index.column()==0) + if(mZoom != 1.0) + pixmap = pixmap.scaled(mZoom*pixmap.size(),Qt::KeepAspectRatio,Qt::SmoothTransformation); + + if(IS_MSG_UNREAD(post.mMeta.mMsgStatus) || IS_MSG_NEW(post.mMeta.mMsgStatus)) { - if(mZoom != 1.0) - pixmap = pixmap.scaled(mZoom*pixmap.size(),Qt::KeepAspectRatio,Qt::SmoothTransformation); + QPainter p(&pixmap); + QFontMetricsF fm(option.font); - if(IS_MSG_UNREAD(post.mMeta.mMsgStatus) || IS_MSG_NEW(post.mMeta.mMsgStatus)) - { - QPainter p(&pixmap); - QFontMetricsF fm(option.font); + p.drawPixmap(mZoom*QPoint(0.1*fm.height(),-3.4*fm.height()),FilesDefs::getPixmapFromQtResourcePath(STAR_OVERLAY_IMAGE).scaled(mZoom*6*fm.height(),mZoom*6*fm.height(),Qt::KeepAspectRatio,Qt::SmoothTransformation)); + } - p.drawPixmap(mZoom*QPoint(0.1*fm.height(),-3.4*fm.height()),FilesDefs::getPixmapFromQtResourcePath(STAR_OVERLAY_IMAGE).scaled(mZoom*6*fm.height(),mZoom*6*fm.height(),Qt::KeepAspectRatio,Qt::SmoothTransformation)); - } + if(post.mUnreadCommentCount > 0) + { + QPainter p(&pixmap); + QFontMetricsF fm(option.font); - if(post.mUnreadCommentCount) - { - QPainter p(&pixmap); - QFontMetricsF fm(option.font); - - p.drawPixmap(QPoint(pixmap.width(),0.0)+mZoom*QPoint(-2.9*fm.height(),0.4*fm.height()), - FilesDefs::getPixmapFromQtResourcePath(COMMENT_OVERLAY_IMAGE).scaled(mZoom*3*fm.height(),mZoom*3*fm.height(), - Qt::KeepAspectRatio,Qt::SmoothTransformation)); - } + p.drawPixmap(QPoint(pixmap.width(),0.0)+mZoom*QPoint(-2.9*fm.height(),0.4*fm.height()), + FilesDefs::getPixmapFromQtResourcePath(UNREAD_COMMENT_OVERLAY_IMAGE).scaled(mZoom*3*fm.height(),mZoom*3*fm.height(), + Qt::KeepAspectRatio,Qt::SmoothTransformation)); + } + else if(post.mCommentCount > 0) + { + QPainter p(&pixmap); + QFontMetricsF fm(option.font); + p.drawPixmap(QPoint(pixmap.width(),0.0)+mZoom*QPoint(-2.9*fm.height(),0.4*fm.height()), + FilesDefs::getPixmapFromQtResourcePath(COMMENT_OVERLAY_IMAGE).scaled(mZoom*3*fm.height(),mZoom*3*fm.height(), + Qt::KeepAspectRatio,Qt::SmoothTransformation)); } painter->drawPixmap(option.rect.topLeft(), - pixmap.scaled(option.rect.width(),option.rect.width()*pixmap.height()/(float)pixmap.width(),Qt::IgnoreAspectRatio,Qt::SmoothTransformation)); + pixmap.scaled(option.rect.width(),option.rect.width()*pixmap.height()/(float)pixmap.width(), + Qt::IgnoreAspectRatio,Qt::SmoothTransformation)); } else { @@ -262,6 +258,9 @@ QSize ChannelPostDelegate::sizeHint(const QStyleOptionViewItem& option, const QM float cell_width = mZoom*COLUMN_SIZE_FONT_FACTOR_W*fm.height(); float cell_height = mZoom*COLUMN_SIZE_FONT_FACTOR_W*fm.height()*aspect_ratio; +#ifdef DEBUG_CHANNEL_POSTS_WIDGET + RsDbg() << "SizeHint: mUseGrid=" << mUseGrid << " cell_width=" << cell_width << " cell_height=" << cell_height << " mZoom=" << mZoom ; +#endif if(mUseGrid || index.column()==0) return QSize(cell_width,cell_height); @@ -295,39 +294,39 @@ QWidget *ChannelPostFilesDelegate::createEditor(QWidget *parent, const QStyleOpt } void ChannelPostFilesDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const { - editor->setGeometry(option.rect); + editor->setGeometry(option.rect); } void ChannelPostFilesDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const { - ChannelPostFileInfo file = index.data(Qt::UserRole).value() ; + ChannelPostFileInfo file = index.data(Qt::UserRole).value() ; - // prepare - painter->save(); - painter->setClipRect(option.rect); + // prepare + painter->save(); + painter->setClipRect(option.rect); painter->save(); painter->fillRect( option.rect, option.backgroundBrush); - //optionFocusRect.backgroundColor = option.palette.color(colorgroup, (option.state & QStyle::State_Selected) ? QPalette::Highlight : QPalette::Background); + //optionFocusRect.backgroundColor = option.palette.color(colorgroup, (option.state & QStyle::State_Selected) ? QPalette::Highlight : QPalette::Background); painter->restore(); switch(index.column()) { case RsGxsChannelPostFilesModel::COLUMN_FILES_NAME: painter->drawText(option.rect,Qt::AlignLeft | Qt::AlignVCenter," " + QString::fromUtf8(file.mName.c_str())); - break; + break; case RsGxsChannelPostFilesModel::COLUMN_FILES_SIZE: painter->drawText(option.rect,Qt::AlignRight | Qt::AlignVCenter,misc::friendlyUnit(qulonglong(file.mSize))); - break; + break; case RsGxsChannelPostFilesModel::COLUMN_FILES_DATE: painter->drawText(option.rect,Qt::AlignLeft | Qt::AlignVCenter,QDateTime::fromMSecsSinceEpoch(file.mPublishTime*1000).toString("MM/dd/yyyy, hh:mm")); - break; + break; case RsGxsChannelPostFilesModel::COLUMN_FILES_FILE: { - GxsChannelFilesStatusWidget w(file); + GxsChannelFilesStatusWidget w(file); w.setFixedWidth(option.rect.width()); - w.setFixedHeight(option.rect.height()); + w.setFixedHeight(option.rect.height()); - QPixmap pixmap(w.size()); + QPixmap pixmap(w.size()); // apparently we need to do the alternate colors manually //if(index.row() & 0x01) @@ -343,13 +342,13 @@ void ChannelPostFilesDelegate::paint(QPainter * painter, const QStyleOptionViewI default: painter->drawText(option.rect,Qt::AlignLeft,QString("[No data]")); - break; + break; } } QSize ChannelPostFilesDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const { - ChannelPostFileInfo file = index.data(Qt::UserRole).value() ; + ChannelPostFileInfo file = index.data(Qt::UserRole).value() ; QFontMetricsF fm(option.font); @@ -369,11 +368,11 @@ QSize ChannelPostFilesDelegate::sizeHint(const QStyleOptionViewItem& option, con /** Constructor */ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupId &channelId, QWidget *parent) : - GxsMessageFrameWidget(rsGxsChannels, parent), - ui(new Ui::GxsChannelPostsWidgetWithModel) + GxsMessageFrameWidget(rsGxsChannels, parent), + ui(new Ui::GxsChannelPostsWidgetWithModel) { - /* Invoke the Qt Designer generated object setup routine */ - ui->setupUi(this); + /* Invoke the Qt Designer generated object setup routine */ + ui->setupUi(this); ui->viewType_TB->setIcon(FilesDefs::getIconFromQtResourcePath(":icons/svg/gridlayout.svg")); ui->viewType_TB->setToolTip(tr("Click to switch to list view")); @@ -431,75 +430,75 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI ui->postDetails_TE->setPlaceholderText(tr("No text to display")); - // Set initial size of the splitter - ui->splitter->setStretchFactor(0, 1); - ui->splitter->setStretchFactor(1, 0); + // Set initial size of the splitter + ui->splitter->setStretchFactor(0, 1); + ui->splitter->setStretchFactor(1, 0); - QFontMetricsF fm(font()); + QFontMetricsF fm(font()); - if(mChannelPostsModel->getMode() == RsGxsChannelPostsModel::TREE_MODE_GRID) - for(int i=0;icolumnCount();++i) - ui->postsTree->setColumnWidth(i,mChannelPostsDelegate->cellSize(i,font(),ui->postsTree->width())); + if(mChannelPostsModel->getMode() == RsGxsChannelPostsModel::TREE_MODE_GRID) + for(int i=0;icolumnCount();++i) + ui->postsTree->setColumnWidth(i,mChannelPostsDelegate->cellSize(i,font(),ui->postsTree->width())); - /* Setup UI helper */ + /* Setup UI helper */ - /* Connect signals */ - connect(ui->postButton, SIGNAL(clicked()), this, SLOT(createMsg())); - connect(ui->subscribeToolButton, SIGNAL(subscribe(bool)), this, SLOT(subscribeGroup(bool))); - connect(NotifyQt::getInstance(), SIGNAL(settingsChanged()), this, SLOT(settingsChanged())); + /* Connect signals */ + connect(ui->postButton, SIGNAL(clicked()), this, SLOT(createMsg())); + connect(ui->subscribeToolButton, SIGNAL(subscribe(bool)), this, SLOT(subscribeGroup(bool))); + connect(NotifyQt::getInstance(), SIGNAL(settingsChanged()), this, SLOT(settingsChanged())); - ui->postButton->setText(tr("Add new post")); - - /* add filter actions */ + ui->postButton->setText(tr("Add new post")); + + /* add filter actions */ ui->filterLineEdit->setPlaceholderText(tr("Search...")); - connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterChanged(QString))); + connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterChanged(QString))); ui->postsTree->setPlaceholderText(tr("No posts available in this channel")); ui->postsTree->setMinimumWidth(COLUMN_SIZE_FONT_FACTOR_W*QFontMetricsF(font()).height()+1); connect(ui->postsTree,SIGNAL(sizeChanged(QSize)),this,SLOT(handlePostsTreeSizeChange(QSize))); - /* Set initial section sizes */ - QHeaderView * channelpostfilesheader = ui->channelPostFiles_TV->header () ; - QHeaderView * channelfilesheader = ui->channelFiles_TV->header () ; + /* Set initial section sizes */ + QHeaderView * channelpostfilesheader = ui->channelPostFiles_TV->header () ; + QHeaderView * channelfilesheader = ui->channelFiles_TV->header () ; - channelpostfilesheader->resizeSection (RsGxsChannelPostFilesModel::COLUMN_FILES_NAME, fm.width("RetroShare-v0.6.5-1487-g6714648e5-Windows-x64-portable-20200518-Qt-5.14.2.7z")); - channelfilesheader->resizeSection (RsGxsChannelPostFilesModel::COLUMN_FILES_NAME, fm.width("RetroShare-v0.6.5-1487-g6714648e5-Windows-x64-portable-20200518-Qt-5.14.2.7z")); + channelpostfilesheader->resizeSection (RsGxsChannelPostFilesModel::COLUMN_FILES_NAME, fm.width("RetroShare-v0.6.5-1487-g6714648e5-Windows-x64-portable-20200518-Qt-5.14.2.7z")); + channelfilesheader->resizeSection (RsGxsChannelPostFilesModel::COLUMN_FILES_NAME, fm.width("RetroShare-v0.6.5-1487-g6714648e5-Windows-x64-portable-20200518-Qt-5.14.2.7z")); - /* Initialize feed widget */ - //ui->feedWidget->setSortRole(ROLE_PUBLISH, Qt::DescendingOrder); - //ui->feedWidget->setFilterCallback(filterItem); + /* Initialize feed widget */ + //ui->feedWidget->setSortRole(ROLE_PUBLISH, Qt::DescendingOrder); + //ui->feedWidget->setFilterCallback(filterItem); - /* load settings */ - processSettings(true); + /* load settings */ + processSettings(true); ui->channelPostFiles_TV->setColumnHidden(RsGxsChannelPostFilesModel::COLUMN_FILES_DATE, true); // no need to show this here. - /* Initialize subscribe button */ - QIcon icon; + /* Initialize subscribe button */ + QIcon icon; icon.addPixmap(FilesDefs::getPixmapFromQtResourcePath(":/images/redled.png"), QIcon::Normal, QIcon::On); icon.addPixmap(FilesDefs::getPixmapFromQtResourcePath(":/images/start.png"), QIcon::Normal, QIcon::Off); #ifdef TO_REMOVE - mAutoDownloadAction = new QAction(icon, "", this); - mAutoDownloadAction->setCheckable(true); - connect(mAutoDownloadAction, SIGNAL(triggered()), this, SLOT(toggleAutoDownload())); + mAutoDownloadAction = new QAction(icon, "", this); + mAutoDownloadAction->setCheckable(true); + connect(mAutoDownloadAction, SIGNAL(triggered()), this, SLOT(toggleAutoDownload())); - ui->subscribeToolButton->addSubscribedAction(mAutoDownloadAction); + ui->subscribeToolButton->addSubscribedAction(mAutoDownloadAction); setAutoDownload(false); #endif ui->commentsDialog->setGxsService(rsGxsChannels); - /* Initialize GUI */ - settingsChanged(); + /* Initialize GUI */ + settingsChanged(); setGroupId(channelId); - mChannelPostsModel->updateChannel(channelId); + mChannelPostsModel->updateChannel(channelId); - mEventHandlerId = 0; - // Needs to be asynced because this function is called by another thread! - rsEvents->registerEventsHandler( [this](std::shared_ptr event) + mEventHandlerId = 0; + // Needs to be asynced because this function is called by another thread! + rsEvents->registerEventsHandler( [this](std::shared_ptr event) { RsQThreadUtils::postToObject([=](){ handleEvent_main_thread(event); }, this ); }, mEventHandlerId, RsEventType::GXS_CHANNELS ); @@ -532,7 +531,7 @@ void GxsChannelPostsWidgetWithModel::updateZoomFactor(bool zoom_or_unzoom) int n_columns = std::max(1,(int)floor(s.width() / (mChannelPostsDelegate->cellSize(0,font(),s.width())))); - mChannelPostsModel->setNumColumns(n_columns); // forces the update + mChannelPostsModel->setNumColumns(n_columns); // forces the update ui->postsTree->dataChanged(QModelIndex(),QModelIndex()); } @@ -575,10 +574,10 @@ void GxsChannelPostsWidgetWithModel::postContextMenu(const QPoint&) } menu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_COPYLINK), tr("Copy RetroShare Link"), this, SLOT(copyMessageLink())); - if(IS_GROUP_PUBLISHER(mGroup.mMeta.mSubscribeFlags)) - menu.addAction(FilesDefs::getIconFromQtResourcePath(":/icons/png/pencil-edit-button.png"), tr("Edit"), this, SLOT(editPost())); + if(IS_GROUP_PUBLISHER(mGroup.mMeta.mSubscribeFlags)) + menu.addAction(FilesDefs::getIconFromQtResourcePath(":/icons/png/pencil-edit-button.png"), tr("Edit"), this, SLOT(editPost())); - menu.exec(QCursor::pos()); + menu.exec(QCursor::pos()); } void GxsChannelPostsWidgetWithModel::markMessageUnread() @@ -648,29 +647,29 @@ void GxsChannelPostsWidgetWithModel::switchView() void GxsChannelPostsWidgetWithModel::copyMessageLink() { try - { - if (groupId().isNull()) - throw std::runtime_error("No channel currently selected!"); + { + if (groupId().isNull()) + throw std::runtime_error("No channel currently selected!"); - QModelIndex index = ui->postsTree->selectionModel()->currentIndex(); + QModelIndex index = ui->postsTree->selectionModel()->currentIndex(); - if(!index.isValid()) - throw std::runtime_error("No post under mouse!"); + if(!index.isValid()) + throw std::runtime_error("No post under mouse!"); - RsGxsChannelPost post = index.data(Qt::UserRole).value() ; + RsGxsChannelPost post = index.data(Qt::UserRole).value() ; - if(post.mMeta.mMsgId.isNull()) - throw std::runtime_error("Post has empty MsgId!"); + if(post.mMeta.mMsgId.isNull()) + throw std::runtime_error("Post has empty MsgId!"); - RetroShareLink link = RetroShareLink::createGxsMessageLink(RetroShareLink::TYPE_CHANNEL, groupId(), post.mMeta.mMsgId, QString::fromUtf8(post.mMeta.mMsgName.c_str())); + RetroShareLink link = RetroShareLink::createGxsMessageLink(RetroShareLink::TYPE_CHANNEL, groupId(), post.mMeta.mMsgId, QString::fromUtf8(post.mMeta.mMsgName.c_str())); - if (!link.valid()) - throw std::runtime_error("Link is not valid"); + if (!link.valid()) + throw std::runtime_error("Link is not valid"); - QList urls; - urls.push_back(link); - RSLinkClipboard::copyLinks(urls); - } + QList urls; + urls.push_back(link); + RSLinkClipboard::copyLinks(urls); + } catch(std::exception& e) { QMessageBox::critical(NULL,tr("Link creation error"),tr("Link could not be created: ")+e.what()); @@ -699,41 +698,41 @@ void GxsChannelPostsWidgetWithModel::download() rsFiles->FileRequest(file.mName, file.mHash, file.mSize, destination, RS_FILE_REQ_ANONYMOUS_ROUTING, sources); } - ui->postDAll_PB->hide(); + ui->postDAll_PB->hide(); } void GxsChannelPostsWidgetWithModel::updateDAll_PB() { - QModelIndex index = ui->postsTree->selectionModel()->currentIndex(); - RsGxsChannelPost post = index.data(Qt::UserRole).value() ; + QModelIndex index = ui->postsTree->selectionModel()->currentIndex(); + RsGxsChannelPost post = index.data(Qt::UserRole).value() ; - size_t newFileToDl = 0; - uint64_t newFileTotalSize = 0; - QString newFilesDetails; + 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"; - } - } + 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))); + 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() { QModelIndex index = ui->postsTree->selectionModel()->currentIndex(); - RsGxsChannelPost post = index.data(Qt::UserRole).value() ; + RsGxsChannelPost post = index.data(Qt::UserRole).value() ; - CreateGxsChannelMsg *msgDialog = new CreateGxsChannelMsg(post.mMeta.mGroupId,post.mMeta.mMsgId); + CreateGxsChannelMsg *msgDialog = new CreateGxsChannelMsg(post.mMeta.mGroupId,post.mMeta.mMsgId); msgDialog->show(); } @@ -743,7 +742,7 @@ void GxsChannelPostsWidgetWithModel::handlePostsTreeSizeChange(QSize s,bool forc return; int n_columns = std::max(1,(int)floor(s.width() / (mChannelPostsDelegate->cellSize(0,font(),ui->postsTree->width())))); - std::cerr << "nb columns: " << n_columns << " current count=" << mChannelPostsModel->columnCount() << std::endl; + RsDbg() << "nb columns: " << n_columns << " current count=" << mChannelPostsModel->columnCount() ; // save current post. The setNumColumns() indeed loses selection @@ -762,69 +761,139 @@ void GxsChannelPostsWidgetWithModel::handlePostsTreeSizeChange(QSize s,bool forc void GxsChannelPostsWidgetWithModel::handleEvent_main_thread(std::shared_ptr event) { - const RsGxsChannelEvent *e = dynamic_cast(event.get()); + const RsGxsChannelEvent *e = dynamic_cast(event.get()); - if(!e) - return; + if(!e) + return; - switch(e->mChannelEventCode) - { - case RsChannelEventCode::NEW_CHANNEL: // [[fallthrough]]; + switch(e->mChannelEventCode) + { + case RsChannelEventCode::NEW_CHANNEL: // [[fallthrough]]; case RsChannelEventCode::DELETED_CHANNEL: // [[fallthrough]]; - case RsChannelEventCode::NEW_COMMENT: // [[fallthrough]]; - case RsChannelEventCode::NEW_VOTE: // [[fallthrough]]; case RsChannelEventCode::UPDATED_CHANNEL: // [[fallthrough]]; - case RsChannelEventCode::NEW_MESSAGE: // [[fallthrough]]; - case RsChannelEventCode::UPDATED_MESSAGE: case RsChannelEventCode::RECEIVED_PUBLISH_KEY: case RsChannelEventCode::SYNC_PARAMETERS_UPDATED: { - if(e->mChannelGroupId == groupId()) - updateDisplay(true); - } + if(e->mChannelGroupId == groupId()) + updateDisplay(true,false); + } + break; - default: - break; - } + case RsChannelEventCode::READ_STATUS_CHANGED: // This is already handled by setMsgReadStatus() that has been called and issued this event. + break; + + case RsChannelEventCode::NEW_MESSAGE: + { + if(e->mChannelGroupId == groupId()) + { + RsDbg() << "Received new message in current channel, msgId=" << e->mChannelMsgId ; + + RsThread::async([this,E=*e]() // dereferencing to make a copy that will survive while e is deleted by the parent thread. + { + // 1 - get message data from p3GxsChannels. No need for pointers here, because we send only a single post to postToObject() + // At this point we dont know what kind of msg id we have. It can be a vote, a comment or an actual message. + + std::vector posts; + std::vector comments; + std::vector votes; + + const auto& msg_id(E.mChannelMsgId); + const auto& grp_id(E.mChannelGroupId); + + if(!rsGxsChannels->getChannelContent(grp_id, { msg_id }, posts,comments,votes) || posts.size() != 1) + { + RsErr() << " failed to retrieve channel message data for channel/msg " << grp_id << "/" << msg_id; + return; + } + + // Need to call this in order to get the actual comment count. The previous call only retrieves the message, since we supplied the message ID. + // another way to go would be to save the comment ids of the existing message and re-insert them before calling getChannelContent. + + if(!rsGxsChannels->getChannelComments(grp_id,{ msg_id },comments)) + { + RsErr() << " failed to retrieve message comment data for channel/msg " << grp_id << "/" << msg_id ; + return; + } + + // Normally, there's a single post in the "post" array. The function below takes a full array of posts however. + + RsGxsChannelPostsModel::computeCommentCounts(posts,comments); + + // 2 - update the model in the UI thread. + + RsQThreadUtils::postToObject( [post=posts[0],this]() + { + std::set added_files,removed_files; + + mChannelPostsModel->updateSinglePost(post,added_files,removed_files); + + std::set added_filesi,removed_filesi; + + for(auto f:added_files) added_filesi.insert(ChannelPostFileInfo(f,post.mMeta.mPublishTs)); + for(auto f:removed_files) removed_filesi.insert(ChannelPostFileInfo(f,post.mMeta.mPublishTs)); + + mChannelFilesModel->update_files(added_filesi,removed_filesi); + + },this); + }); + } + } + break; + + case RsChannelEventCode::NEW_COMMENT: + + if(e->mChannelGroupId == groupId() && e->mChannelThreadId != ui->commentsDialog->messageId()) + mChannelPostsModel->updatePostWithNewComment(e->mChannelThreadId); [[fallthrough]]; + + case RsChannelEventCode::NEW_VOTE: + + if(e->mChannelGroupId == groupId() && e->mChannelThreadId == ui->commentsDialog->messageId()) + ui->commentsDialog->refresh(); + break; + + default: + break; + + } } void GxsChannelPostsWidgetWithModel::showPostDetails() { QModelIndex index = ui->postsTree->selectionModel()->currentIndex(); - RsGxsChannelPost post = index.data(Qt::UserRole).value() ; + RsGxsChannelPost post = index.data(Qt::UserRole).value() ; #ifdef DEBUG_CHANNEL_POSTS_WIDGET - std::cerr << "showPostDetails: current index is " << index.row() << "," << index.column() << std::endl; + RsDbg() << "showPostDetails: current index is " << index.row() << "," << index.column() ; #endif - //QTextDocument doc; - //doc.setHtml(post.mMsg.c_str()); + //QTextDocument doc; + //doc.setHtml(post.mMsg.c_str()); - if(post.mMeta.mPublishTs == 0) - { - ui->postDetails_TE->clear(); - ui->postLogo_LB->hide(); - ui->postName_LB->hide(); - ui->postTime_LB->hide(); - mChannelPostFilesModel->clear(); - ui->details_TW->setEnabled(false); - //mLastSelectedPosts[groupId()].clear(); + if(post.mMeta.mPublishTs == 0) + { + ui->postDetails_TE->clear(); + ui->postLogo_LB->hide(); + ui->postName_LB->hide(); + ui->postTime_LB->hide(); + mChannelPostFilesModel->clear(); + ui->details_TW->setEnabled(false); + //mLastSelectedPosts[groupId()].clear(); - return; - } - ui->details_TW->setEnabled(true); + return; + } + ui->details_TW->setEnabled(true); - ui->postLogo_LB->show(); - ui->postName_LB->show(); - ui->postTime_LB->show(); + ui->postLogo_LB->show(); + ui->postName_LB->show(); + ui->postTime_LB->show(); #ifdef DEBUG_CHANNEL_POSTS_WIDGET - std::cerr << "showPostDetails: setting mLastSelectedPosts[groupId()] to current post Id " << post.mMeta.mMsgId << ". Previous value: " << mLastSelectedPosts[groupId()] << std::endl; + RsDbg() << "showPostDetails: setting mLastSelectedPosts[groupId()] to current post Id " << post.mMeta.mMsgId << ". Previous value: " << mLastSelectedPosts[groupId()] ; #endif - mLastSelectedPosts[groupId()] = post.mMeta.mMsgId; + mLastSelectedPosts[groupId()] = post.mMeta.mMsgId; - std::list files; - for(auto& file:post.mFiles) - files.push_back(ChannelPostFileInfo(file,post.mMeta.mPublishTs)); + std::list files; + for(auto& file:post.mFiles) + files.push_back(ChannelPostFileInfo(file,post.mMeta.mPublishTs)); mChannelPostFilesModel->setFiles(files); @@ -834,46 +903,51 @@ void GxsChannelPostsWidgetWithModel::showPostDetails() ui->commentsDialog->commentLoad(post.mMeta.mGroupId, all_msgs_versions, post.mMeta.mMsgId,true); #ifdef DEBUG_CHANNEL_POSTS_WIDGET - std::cerr << "Showing details about selected index : "<< index.row() << "," << index.column() << std::endl; + RsDbg() << "Showing details about selected index : "<< index.row() << "," << index.column() ; #endif ui->postDetails_TE->setText(RsHtml().formatText(NULL, QString::fromUtf8(post.mMsg.c_str()), /* RSHTML_FORMATTEXT_EMBED_SMILEYS |*/ RSHTML_FORMATTEXT_EMBED_LINKS)); - QPixmap postImage; + QPixmap postImage; - if (post.mThumbnail.mData != NULL) - GxsIdDetails::loadPixmapFromData(post.mThumbnail.mData, post.mThumbnail.mSize, postImage,GxsIdDetails::ORIGINAL); - else - postImage = FilesDefs::getPixmapFromQtResourcePath(ChannelPostThumbnailView::CHAN_DEFAULT_IMAGE); + if (post.mThumbnail.mData != NULL) + GxsIdDetails::loadPixmapFromData(post.mThumbnail.mData, post.mThumbnail.mSize, postImage,GxsIdDetails::ORIGINAL); + else + postImage = FilesDefs::getPixmapFromQtResourcePath(ChannelPostThumbnailView::CHAN_DEFAULT_IMAGE); int W = QFontMetricsF(font()).height() * 8; // Using fixed width so that the post will not displace the text when we browse. - ui->postLogo_LB->setPixmap(postImage); - ui->postLogo_LB->setFixedSize(W,postImage.height()/(float)postImage.width()*W); + ui->postLogo_LB->setPixmap(postImage); + ui->postLogo_LB->setFixedSize(W,postImage.height()/(float)postImage.width()*W); - ui->postName_LB->setText(QString::fromUtf8(post.mMeta.mMsgName.c_str())); + ui->postName_LB->setText(QString::fromUtf8(post.mMeta.mMsgName.c_str())); - ui->postTime_LB->setText(QDateTime::fromMSecsSinceEpoch(post.mMeta.mPublishTs*1000).toString("MM/dd/yyyy, hh:mm")); - ui->postTime_LB->setFixedWidth(W); + ui->postTime_LB->setText(QDateTime::fromMSecsSinceEpoch(post.mMeta.mPublishTs*1000).toString("MM/dd/yyyy, hh:mm")); + ui->postTime_LB->setFixedWidth(W); //ui->channelPostFiles_TV->resizeColumnToContents(RsGxsChannelPostFilesModel::COLUMN_FILES_FILE); //ui->channelPostFiles_TV->resizeColumnToContents(RsGxsChannelPostFilesModel::COLUMN_FILES_SIZE); ui->channelPostFiles_TV->setAutoSelect(true); - // Now also set the post as read + // Now also set the post as read - if(IS_MSG_UNREAD(post.mMeta.mMsgStatus) || IS_MSG_NEW(post.mMeta.mMsgStatus)) - { - RsGxsGrpMsgIdPair postId; - postId.second = post.mMeta.mMsgId; - postId.first = post.mMeta.mGroupId; + if(IS_MSG_UNREAD(post.mMeta.mMsgStatus) || IS_MSG_NEW(post.mMeta.mMsgStatus) || post.mUnreadCommentCount > 0) + { + mChannelPostsModel->setMsgReadStatus(index,true); - RsThread::async([postId]() { rsGxsChannels->setMessageReadStatus(postId, true) ; } ); - } + //RsGxsGrpMsgIdPair postId; + //postId.second = post.mMeta.mMsgId; + //postId.first = post.mMeta.mGroupId; - updateDAll_PB(); + //RsThread::async([postId]() + //{ + //rsGxsChannels->setMessageReadStatus(postId, true) ; + //} ); + } + + updateDAll_PB(); } void GxsChannelPostsWidgetWithModel::updateCommentsCount(int n) @@ -883,30 +957,30 @@ void GxsChannelPostsWidgetWithModel::updateCommentsCount(int n) else ui->details_TW->setTabText(2,tr("Comments")); } -void GxsChannelPostsWidgetWithModel::updateGroupData() +void GxsChannelPostsWidgetWithModel::updateData(bool update_group_data, bool update_posts) { - if(groupId().isNull()) + if(groupId().isNull()) { // clear post, files and comment widgets showPostDetails(); - return; + return; } - RsThread::async([this]() - { - RsGxsChannelGroup group; - std::vector groups; + RsThread::async([this,update_group_data,update_posts]() + { + std::vector groups; + RsGxsChannelGroup group; - if(rsGxsChannels->getChannelsInfo(std::list{ groupId() }, groups) && groups.size()==1) + if(rsGxsChannels->getChannelsInfo(std::list{ groupId() }, groups) && groups.size()==1) group = groups[0]; else if(!rsGxsChannels->getDistantSearchResultGroupData(groupId(),group)) - { - std::cerr << __PRETTY_FUNCTION__ << " failed to get group data for channel: " << groupId() << std::endl; - return; - } + { + std::cerr << __PRETTY_FUNCTION__ << " failed to get group data for channel: " << groupId() << std::endl; + return; + } - RsQThreadUtils::postToObject( [this,group]() + RsQThreadUtils::postToObject( [this,update_group_data,update_posts,group]() { if(mGroup.mMeta.mGroupId != group.mMeta.mGroupId) // this prevents any attempt to display the wrong index. Navigate() if needed will use mNavigatePendingMsgId { @@ -918,52 +992,58 @@ void GxsChannelPostsWidgetWithModel::updateGroupData() updateCommentsCount(0); } - mGroup = group; + if(update_group_data) + { + mGroup = group; + insertChannelDetails(mGroup); + } - ui->postsTree->setPlaceholderText(tr("Loading...")); + if(update_posts) + { + ui->postsTree->setPlaceholderText(tr("Loading...")); - mChannelPostsModel->updateChannel(groupId()); - whileBlocking(ui->filterLineEdit)->clear(); - whileBlocking(ui->showUnread_TB)->setChecked(false); + mChannelPostsModel->updateChannel(groupId()); - insertChannelDetails(mGroup); + whileBlocking(ui->filterLineEdit)->clear(); + whileBlocking(ui->showUnread_TB)->setChecked(false); + } emit groupDataLoaded(); emit groupChanged(this); // signals the parent widget to e.g. update the group tab name } ); - }); + }); } void GxsChannelPostsWidgetWithModel::postChannelPostLoad() { - std::cerr << "Post channel load..." << std::endl; + std::cerr << "Post channel load..." << std::endl; - if (!mNavigatePendingMsgId.isNull()) - navigate(mNavigatePendingMsgId); + if (!mNavigatePendingMsgId.isNull()) + navigate(mNavigatePendingMsgId); - else if( (mLastSelectedPosts.count(groupId()) > 0) + else if( (mLastSelectedPosts.count(groupId()) > 0) && !mLastSelectedPosts[groupId()].isNull()) - { - QModelIndex index = mChannelPostsModel->getIndexOfMessage(mLastSelectedPosts[groupId()]); + { + QModelIndex index = mChannelPostsModel->getIndexOfMessage(mLastSelectedPosts[groupId()]); - std::cerr << "Setting current index to " << index.row() << ","<< index.column() << " for current post " - << mLastSelectedPosts[groupId()].toStdString() << std::endl; + std::cerr << "Setting current index to " << index.row() << ","<< index.column() << " for current post " + << mLastSelectedPosts[groupId()].toStdString() << std::endl; - ui->postsTree->selectionModel()->setCurrentIndex(index,QItemSelectionModel::ClearAndSelect); - ui->postsTree->scrollTo(index);//May change if model reloaded - ui->postsTree->setFocus(); - } - else - std::cerr << "No pre-selected channel post." << std::endl; + ui->postsTree->selectionModel()->setCurrentIndex(index,QItemSelectionModel::ClearAndSelect); + ui->postsTree->scrollTo(index);//May change if model reloaded + ui->postsTree->setFocus(); + } + else + std::cerr << "No pre-selected channel post." << std::endl; - std::list files; + std::list files; mChannelPostsModel->getFilesList(files); mChannelFilesModel->setFiles(files); - ui->channelFiles_TV->setAutoSelect(true); - ui->channelFiles_TV->sortByColumn(ui->channelFiles_TV->header()->sortIndicatorSection() - ,ui->channelFiles_TV->header()->sortIndicatorOrder()); + ui->channelFiles_TV->setAutoSelect(true); + ui->channelFiles_TV->sortByColumn(ui->channelFiles_TV->header()->sortIndicatorSection() + ,ui->channelFiles_TV->header()->sortIndicatorOrder()); // if there's no posts, this is what's going to be displayed. ui->postsTree->setPlaceholderText(tr("No posts available in this channel.")); @@ -991,84 +1071,75 @@ void GxsChannelPostsWidgetWithModel::postChannelPostLoad() handlePostsTreeSizeChange(ui->postsTree->size(),true); // force the update } -void GxsChannelPostsWidgetWithModel::updateDisplay(bool complete) +void GxsChannelPostsWidgetWithModel::updateDisplay(bool update_group_data,bool update_posts) { - // First, clear all widget - blank(); + // First, clear all widget + #ifdef DEBUG_CHANNEL std::cerr << "udateDisplay: groupId()=" << groupId()<< std::endl; #endif - if(groupId().isNull()) + if(groupId().isNull()) { #ifdef DEBUG_CHANNEL std::cerr << " group_id=0. Return!"<< std::endl; #endif - return; + return; } - if(mGroup.mMeta.mGroupId.isNull() && !groupId().isNull()) + if(mGroup.mMeta.mGroupId != groupId()) { #ifdef DEBUG_FORUMS std::cerr << " inconsistent group data. Reloading!"<< std::endl; #endif - complete = true; + update_group_data = true; + update_posts = true; } - if(complete) // need to update the group data, reload the messages etc. - { -#warning csoler 2020-06-02 : todo - //saveExpandedItems(mSavedExpandedMessages); - //if(mGroupId != mChannelPostsModel->currentGroupId()) - // mThreadId.clear(); - - updateGroupData(); - - return; - } + updateData(update_group_data,update_posts); } GxsChannelPostsWidgetWithModel::~GxsChannelPostsWidgetWithModel() { - rsEvents->unregisterEventsHandler(mEventHandlerId); - // save settings - processSettings(false); + rsEvents->unregisterEventsHandler(mEventHandlerId); + // save settings + processSettings(false); //delete(mAutoDownloadAction); delete mFilesDelegate; - delete ui; + delete ui; } void GxsChannelPostsWidgetWithModel::processSettings(bool load) { - QHeaderView *channelpostfilesheader = ui->channelPostFiles_TV->header () ; - QHeaderView *channelfilesheader = ui->channelFiles_TV->header () ; - - Settings->beginGroup(QString("ChannelPostsWidget")); + QHeaderView *channelpostfilesheader = ui->channelPostFiles_TV->header () ; + QHeaderView *channelfilesheader = ui->channelFiles_TV->header () ; - if (load) { + Settings->beginGroup(QString("ChannelPostsWidget")); - // state of files tree - channelpostfilesheader->restoreState(Settings->value("PostFilesTree").toByteArray()); - channelfilesheader->restoreState(Settings->value("FilesTree").toByteArray()); + if (load) { - // state of splitter - ui->splitter->restoreState(Settings->value("SplitterChannelPosts").toByteArray()); - } else { - // state of files tree - Settings->setValue("PostFilesTree", channelpostfilesheader->saveState()); - Settings->setValue("FilesTree", channelfilesheader->saveState()); + // state of files tree + channelpostfilesheader->restoreState(Settings->value("PostFilesTree").toByteArray()); + channelfilesheader->restoreState(Settings->value("FilesTree").toByteArray()); - // state of splitter - Settings->setValue("SplitterChannelPosts", ui->splitter->saveState()); - } + // state of splitter + ui->splitter->restoreState(Settings->value("SplitterChannelPosts").toByteArray()); + } else { + // state of files tree + Settings->setValue("PostFilesTree", channelpostfilesheader->saveState()); + Settings->setValue("FilesTree", channelfilesheader->saveState()); - Settings->endGroup(); + // state of splitter + Settings->setValue("SplitterChannelPosts", ui->splitter->saveState()); + } + + Settings->endGroup(); } void GxsChannelPostsWidgetWithModel::settingsChanged() { - mUseThread = Settings->getChannelLoadThread(); + mUseThread = Settings->getChannelLoadThread(); - //mStateHelper->setWidgetVisible(ui->progressBar, mUseThread); + //mStateHelper->setWidgetVisible(ui->progressBar, mUseThread); } QString GxsChannelPostsWidgetWithModel::groupName(bool) @@ -1088,15 +1159,15 @@ void GxsChannelPostsWidgetWithModel::groupNameChanged(const QString &/*name*/) QIcon GxsChannelPostsWidgetWithModel::groupIcon() { - /* CHANNEL IMAGE */ - QPixmap chanImage; - if (mGroup.mImage.mData != NULL) { - GxsIdDetails::loadPixmapFromData(mGroup.mImage.mData, mGroup.mImage.mSize, chanImage,GxsIdDetails::ORIGINAL); - } else { - chanImage = FilesDefs::getPixmapFromQtResourcePath(ChannelPostThumbnailView::CHAN_DEFAULT_IMAGE); - } + /* CHANNEL IMAGE */ + QPixmap chanImage; + if (mGroup.mImage.mData != NULL) { + GxsIdDetails::loadPixmapFromData(mGroup.mImage.mData, mGroup.mImage.mSize, chanImage,GxsIdDetails::ORIGINAL); + } else { + chanImage = FilesDefs::getPixmapFromQtResourcePath(ChannelPostThumbnailView::CHAN_DEFAULT_IMAGE); + } - return QIcon(chanImage); + return QIcon(chanImage); } /*************************************************************************************/ @@ -1106,50 +1177,50 @@ QIcon GxsChannelPostsWidgetWithModel::groupIcon() // Callback from Widget->FeedHolder->ServiceDialog->CommentContainer->CommentDialog, void GxsChannelPostsWidgetWithModel::openComments(uint32_t /*type*/, const RsGxsGroupId &groupId, const QVector& msg_versions,const RsGxsMessageId &msgId, const QString &title) { - emit loadComment(groupId, msg_versions,msgId, title); + emit loadComment(groupId, msg_versions,msgId, title); } void GxsChannelPostsWidgetWithModel::createMsg() { - if (groupId().isNull()) { - return; - } + if (groupId().isNull()) { + return; + } - if (!IS_GROUP_SUBSCRIBED(mGroup.mMeta.mSubscribeFlags)) { - return; - } + if (!IS_GROUP_SUBSCRIBED(mGroup.mMeta.mSubscribeFlags)) { + return; + } - CreateGxsChannelMsg *msgDialog = new CreateGxsChannelMsg(groupId()); - msgDialog->show(); + CreateGxsChannelMsg *msgDialog = new CreateGxsChannelMsg(groupId()); + msgDialog->show(); - /* window will destroy itself! */ + /* window will destroy itself! */ } void GxsChannelPostsWidgetWithModel::insertChannelDetails(const RsGxsChannelGroup &group) { // save selection if needed - /* IMAGE */ - QPixmap chanImage; - if (group.mImage.mData != NULL) { - GxsIdDetails::loadPixmapFromData(group.mImage.mData, group.mImage.mSize, chanImage,GxsIdDetails::ORIGINAL); - } else { + /* IMAGE */ + QPixmap chanImage; + if (group.mImage.mData != NULL) { + GxsIdDetails::loadPixmapFromData(group.mImage.mData, group.mImage.mSize, chanImage,GxsIdDetails::ORIGINAL); + } else { chanImage = FilesDefs::getPixmapFromQtResourcePath(ChannelPostThumbnailView::CHAN_DEFAULT_IMAGE); - } + } if(group.mMeta.mGroupName.empty()) - ui->channelName_LB->setText(tr("[No name]")); + ui->channelName_LB->setText(tr("[No name]")); else - ui->channelName_LB->setText(QString::fromUtf8(group.mMeta.mGroupName.c_str())); + ui->channelName_LB->setText(QString::fromUtf8(group.mMeta.mGroupName.c_str())); - ui->logoLabel->setPixmap(chanImage); + ui->logoLabel->setPixmap(chanImage); ui->logoLabel->setFixedSize(QSize(ui->logoLabel->height()*chanImage.width()/(float)chanImage.height(),ui->logoLabel->height())); // make the logo have the same aspect ratio than the original image - ui->postButton->setEnabled(bool(group.mMeta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_PUBLISH)); + ui->postButton->setEnabled(bool(group.mMeta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_PUBLISH)); #ifdef TO_REMOVE - bool autoDownload ; - rsGxsChannels->getChannelAutoDownload(group.mMeta.mGroupId,autoDownload); - setAutoDownload(autoDownload); + bool autoDownload ; + rsGxsChannels->getChannelAutoDownload(group.mMeta.mGroupId,autoDownload); + setAutoDownload(autoDownload); #endif setSubscribeButtonText(group.mMeta.mGroupId,group.mMeta.mSubscribeFlags, group.mMeta.mPop); @@ -1174,12 +1245,12 @@ void GxsChannelPostsWidgetWithModel::insertChannelDetails(const RsGxsChannelGrou } - ui->infoPosts->setText(QString::number(group.mMeta.mVisibleMsgCount)); + ui->infoPosts->setText(QString::number(group.mMeta.mVisibleMsgCount)); - if(group.mMeta.mLastPost==0) - ui->infoLastPost->setText(tr("Never")); - else - ui->infoLastPost->setText(DateTime::formatLongDateTime(group.mMeta.mLastPost)); + if(group.mMeta.mLastPost==0) + ui->infoLastPost->setText(tr("Never")); + else + ui->infoLastPost->setText(DateTime::formatLongDateTime(group.mMeta.mLastPost)); uint32_t current_sync_time = GxsGroupFrameDialog::checkDelay(rsGxsChannels->getSyncPeriod(group.mMeta.mGroupId))/86400 ; @@ -1205,65 +1276,65 @@ void GxsChannelPostsWidgetWithModel::insertChannelDetails(const RsGxsChannelGrou ui->infoSyncTimeLabel->setText(sync_string); - QString formatDescription = QString::fromUtf8(group.mDescription.c_str()); + QString formatDescription = QString::fromUtf8(group.mDescription.c_str()); - unsigned int formatFlag = RSHTML_FORMATTEXT_EMBED_LINKS; + unsigned int formatFlag = RSHTML_FORMATTEXT_EMBED_LINKS; - // embed smileys ? - if (Settings->valueFromGroup(QString("ChannelPostsWidget"), QString::fromUtf8("Emoteicons_ChannelDecription"), true).toBool()) { - formatFlag |= RSHTML_FORMATTEXT_EMBED_SMILEYS; - } + // embed smileys ? + if (Settings->valueFromGroup(QString("ChannelPostsWidget"), QString::fromUtf8("Emoteicons_ChannelDecription"), true).toBool()) { + formatFlag |= RSHTML_FORMATTEXT_EMBED_SMILEYS; + } - formatDescription = RsHtml().formatText(NULL, formatDescription, formatFlag); + formatDescription = RsHtml().formatText(NULL, formatDescription, formatFlag); - ui->infoDescription->setText(formatDescription); + ui->infoDescription->setText(formatDescription); - ui->infoAdministrator->setId(group.mMeta.mAuthorId) ; + ui->infoAdministrator->setId(group.mMeta.mAuthorId) ; - if(!group.mMeta.mAuthorId.isNull()) - { - RetroShareLink link = RetroShareLink::createMessage(group.mMeta.mAuthorId, ""); - ui->infoAdministrator->setText(link.toHtml()); - } - else - ui->infoAdministrator->setText("[No contact author]"); + if(!group.mMeta.mAuthorId.isNull()) + { + RetroShareLink link = RetroShareLink::createMessage(group.mMeta.mAuthorId, ""); + ui->infoAdministrator->setText(link.toHtml()); + } + else + ui->infoAdministrator->setText("[No contact author]"); - ui->infoCreated->setText(DateTime::formatLongDateTime(group.mMeta.mPublishTs)); + ui->infoCreated->setText(DateTime::formatLongDateTime(group.mMeta.mPublishTs)); - QString distrib_string ( "[unknown]" ); + QString distrib_string ( "[unknown]" ); - switch((RsGxsCircleType)group.mMeta.mCircleType) - { - case RsGxsCircleType::PUBLIC: distrib_string = tr("Public") ; - break ; - case RsGxsCircleType::EXTERNAL: - { - RsGxsCircleDetails det ; + switch((RsGxsCircleType)group.mMeta.mCircleType) + { + case RsGxsCircleType::PUBLIC: distrib_string = tr("Public") ; + break ; + case RsGxsCircleType::EXTERNAL: + { + RsGxsCircleDetails det ; - // !! What we need here is some sort of CircleLabel, which loads the circle and updates the label when done. + // !! What we need here is some sort of CircleLabel, which loads the circle and updates the label when done. - if(rsGxsCircles->getCircleDetails(group.mMeta.mCircleId,det)) - distrib_string = tr("Restricted to members of circle \"")+QString::fromUtf8(det.mCircleName.c_str()) +"\""; - else - distrib_string = tr("Restricted to members of circle ")+QString::fromStdString(group.mMeta.mCircleId.toStdString()) ; - } - break ; - case RsGxsCircleType::YOUR_EYES_ONLY: distrib_string = tr("Your eyes only"); - break ; - case RsGxsCircleType::LOCAL: distrib_string = tr("You and your friend nodes"); - break ; - default: - std::cerr << "(EE) badly initialised group distribution ID = " << group.mMeta.mCircleType << std::endl; - } + if(rsGxsCircles->getCircleDetails(group.mMeta.mCircleId,det)) + distrib_string = tr("Restricted to members of circle \"")+QString::fromUtf8(det.mCircleName.c_str()) +"\""; + else + distrib_string = tr("Restricted to members of circle ")+QString::fromStdString(group.mMeta.mCircleId.toStdString()) ; + } + break ; + case RsGxsCircleType::YOUR_EYES_ONLY: distrib_string = tr("Your eyes only"); + break ; + case RsGxsCircleType::LOCAL: distrib_string = tr("You and your friend nodes"); + break ; + default: + std::cerr << "(EE) badly initialised group distribution ID = " << group.mMeta.mCircleType << std::endl; + } - ui->infoDistribution->setText(distrib_string); + ui->infoDistribution->setText(distrib_string); #ifdef TODO - ui->infoWidget->show(); - ui->feedWidget->hide(); - ui->fileWidget->hide(); + ui->infoWidget->show(); + ui->feedWidget->hide(); + ui->fileWidget->hide(); - //ui->feedToolButton->setEnabled(false); - //ui->fileToolButton->setEnabled(false); + //ui->feedToolButton->setEnabled(false); + //ui->fileToolButton->setEnabled(false); #endif setSubscribeButtonText(group.mMeta.mGroupId,group.mMeta.mSubscribeFlags, group.mMeta.mPop); @@ -1342,70 +1413,70 @@ void GxsChannelPostsWidgetWithModel::switchOnlyUnread(bool) } void GxsChannelPostsWidgetWithModel::filterChanged(QString s) { - QStringList ql = s.split(' ',QString::SkipEmptyParts); - uint32_t count; - mChannelPostsModel->setFilter(ql,ui->showUnread_TB->isChecked(),count); - mChannelFilesModel->setFilter(ql,count); + QStringList ql = s.split(' ',QString::SkipEmptyParts); + uint32_t count; + mChannelPostsModel->setFilter(ql,ui->showUnread_TB->isChecked(),count); + mChannelFilesModel->setFilter(ql,count); } void GxsChannelPostsWidgetWithModel::blank() { - ui->postButton->setEnabled(false); - ui->subscribeToolButton->setEnabled(false); + ui->postButton->setEnabled(false); + ui->subscribeToolButton->setEnabled(false); - ui->channelName_LB->setText(tr("No Channel Selected")); - ui->logoLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/icons/png/channels.png")); - ui->infoPosts->setText(""); - ui->infoLastPost->setText(""); - ui->infoAdministrator->setText(""); - ui->infoDistribution->setText(""); - ui->infoCreated->setText(""); - ui->infoDescription->setText(""); + ui->channelName_LB->setText(tr("No Channel Selected")); + ui->logoLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/icons/png/channels.png")); + ui->infoPosts->setText(""); + ui->infoLastPost->setText(""); + ui->infoAdministrator->setText(""); + ui->infoDistribution->setText(""); + ui->infoCreated->setText(""); + ui->infoDescription->setText(""); - mChannelPostsModel->clear(); - mChannelPostFilesModel->clear(); - ui->postDetails_TE->clear(); - ui->postLogo_LB->hide(); - ui->postName_LB->hide(); - ui->postTime_LB->hide(); - ui->postDAll_PB->hide(); - groupNameChanged(QString()); + mChannelPostsModel->clear(); + mChannelPostFilesModel->clear(); + ui->postDetails_TE->clear(); + ui->postLogo_LB->hide(); + ui->postName_LB->hide(); + ui->postTime_LB->hide(); + ui->postDAll_PB->hide(); + groupNameChanged(QString()); } bool GxsChannelPostsWidgetWithModel::navigate(const RsGxsMessageId& msgId) { - QModelIndex index = mChannelPostsModel->getIndexOfMessage(msgId); + QModelIndex index = mChannelPostsModel->getIndexOfMessage(msgId); - if(!index.isValid()) - { - std::cerr << "(EE) Cannot navigate to msg " << msgId << " in channel " << mGroup.mMeta.mGroupId << ": index unknown. Setting mNavigatePendingMsgId." << std::endl; + if(!index.isValid()) + { + std::cerr << "(EE) Cannot navigate to msg " << msgId << " in channel " << mGroup.mMeta.mGroupId << ": index unknown. Setting mNavigatePendingMsgId." << std::endl; - mNavigatePendingMsgId = msgId; // not found. That means the forum may not be loaded yet. So we keep that post in mind, for after loading. - return true; // we have to return true here, otherwise the caller will intepret the async loading as an error. - } + mNavigatePendingMsgId = msgId; // not found. That means the forum may not be loaded yet. So we keep that post in mind, for after loading. + return true; // we have to return true here, otherwise the caller will intepret the async loading as an error. + } - ui->postsTree->selectionModel()->setCurrentIndex(index,QItemSelectionModel::ClearAndSelect); - ui->postsTree->scrollTo(index);//May change if model reloaded - ui->postsTree->setFocus(); + ui->postsTree->selectionModel()->setCurrentIndex(index,QItemSelectionModel::ClearAndSelect); + ui->postsTree->scrollTo(index);//May change if model reloaded + ui->postsTree->setFocus(); - ui->channel_TW->setCurrentIndex(CHANNEL_TABS_POSTS); - ui->details_TW->setCurrentIndex(CHANNEL_TABS_DETAILS); + ui->channel_TW->setCurrentIndex(CHANNEL_TABS_POSTS); + ui->details_TW->setCurrentIndex(CHANNEL_TABS_DETAILS); - mNavigatePendingMsgId.clear(); + mNavigatePendingMsgId.clear(); - return true; + return true; } void GxsChannelPostsWidgetWithModel::subscribeGroup(bool subscribe) { - RsGxsGroupId grpId(groupId()); - if (grpId.isNull()) return; + RsGxsGroupId grpId(groupId()); + if (grpId.isNull()) return; - RsThread::async([=]() - { - rsGxsChannels->subscribeToChannel(grpId, subscribe); - } ); + RsThread::async([=]() + { + rsGxsChannels->subscribeToChannel(grpId, subscribe); + } ); } #ifdef TO_REMOVE @@ -1417,50 +1488,50 @@ void GxsChannelPostsWidgetWithModel::setAutoDownload(bool autoDl) void GxsChannelPostsWidgetWithModel::toggleAutoDownload() { - RsGxsGroupId grpId = groupId(); - if (grpId.isNull()) { - return; - } + RsGxsGroupId grpId = groupId(); + if (grpId.isNull()) { + return; + } - bool autoDownload; - if(!rsGxsChannels->getChannelAutoDownload(grpId, autoDownload)) - { - std::cerr << __PRETTY_FUNCTION__ << " failed to get autodownload value " - << "for channel: " << grpId.toStdString() << std::endl; - return; - } + bool autoDownload; + if(!rsGxsChannels->getChannelAutoDownload(grpId, autoDownload)) + { + std::cerr << __PRETTY_FUNCTION__ << " failed to get autodownload value " + << "for channel: " << grpId.toStdString() << std::endl; + return; + } - RsThread::async([this, grpId, autoDownload]() - { - if(!rsGxsChannels->setChannelAutoDownload(grpId, !autoDownload)) - { - std::cerr << __PRETTY_FUNCTION__ << " failed to set autodownload " - << "for channel: " << grpId.toStdString() << std::endl; - return; - } - }); + RsThread::async([this, grpId, autoDownload]() + { + if(!rsGxsChannels->setChannelAutoDownload(grpId, !autoDownload)) + { + std::cerr << __PRETTY_FUNCTION__ << " failed to set autodownload " + << "for channel: " << grpId.toStdString() << std::endl; + return; + } + }); } #endif class GxsChannelPostsReadData { public: - explicit GxsChannelPostsReadData(bool read) - { - mRead = read; - } + explicit GxsChannelPostsReadData(bool read) + { + mRead = read; + } public: - bool mRead; + bool mRead; }; void GxsChannelPostsWidgetWithModel::setAllMessagesReadDo(bool read) { - if (groupId().isNull() || !IS_GROUP_SUBSCRIBED(mGroup.mMeta.mSubscribeFlags)) - return; + if (groupId().isNull() || !IS_GROUP_SUBSCRIBED(mGroup.mMeta.mSubscribeFlags)) + return; - //QModelIndex src_index; + //QModelIndex src_index; - mChannelPostsModel->setAllMsgReadStatus(read); + mChannelPostsModel->setAllMsgReadStatus(read); } diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h index 8cacbebe4..70673f57f 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h @@ -104,11 +104,11 @@ public: /* GxsMessageFrameWidget */ virtual QIcon groupIcon() override; - virtual void groupIdChanged() override { updateDisplay(true); } + virtual void groupIdChanged() override { updateDisplay(true,true); } virtual QString groupName(bool) override; virtual bool navigate(const RsGxsMessageId&) override; - void updateDisplay(bool complete); + void updateDisplay(bool update_group_data, bool update_posts); #ifdef TODO /* FeedHolder */ @@ -141,7 +141,7 @@ protected: private slots: void showPostDetails(); - void updateGroupData(); + void updateData(bool update_group_data,bool update_posts); void download(); void updateDAll_PB(); void createMsg(); diff --git a/retroshare-gui/src/gui/msgs/MessageModel.cpp b/retroshare-gui/src/gui/msgs/MessageModel.cpp index 4e1debaba..a19087dc0 100644 --- a/retroshare-gui/src/gui/msgs/MessageModel.cpp +++ b/retroshare-gui/src/gui/msgs/MessageModel.cpp @@ -387,12 +387,11 @@ void RsMessageModel::setFilter(FilterType filter_type, const QStringList& string std::cerr << std::endl; #endif - preMods(); - mFilterType = filter_type; mFilterStrings = strings; - postMods(); + if(rowCount() > 0) + emit dataChanged(createIndex(0,0),createIndex(rowCount()-1,RsMessageModel::columnCount()-1)); } QVariant RsMessageModel::toolTipRole(const Rs::Msgs::MsgInfoSummary& fmpe,int column) const diff --git a/retroshare-gui/src/gui/msgs/MessageUserNotify.cpp b/retroshare-gui/src/gui/msgs/MessageUserNotify.cpp index fddf2c8d5..60e6ec197 100644 --- a/retroshare-gui/src/gui/msgs/MessageUserNotify.cpp +++ b/retroshare-gui/src/gui/msgs/MessageUserNotify.cpp @@ -23,6 +23,7 @@ #include "gui/notifyqt.h" #include "gui/MainWindow.h" #include "util/qtthreadsutils.h" +#include "gui/settings/rsharesettings.h" #include "gui/msgs/MessageInterface.h" @@ -91,8 +92,18 @@ void MessageUserNotify::handleEvent_main_thread(std::shared_ptr e return; } + std::set::const_iterator it; + switch (fe->mMailStatusEventCode) { case RsMailStatusEventCode::NEW_MESSAGE: + if (Settings->getNotifyFlags() & RS_POPUP_MSG) + for (it = fe->mChangedMsgIds.begin(); it != fe->mChangedMsgIds.end(); ++it) { + MessageInfo msgInfo; + if (rsMail->getMessage(*it, msgInfo)) { + NotifyQt::getInstance()->addToaster(RS_POPUP_MSG, msgInfo.msgId.c_str(), msgInfo.title.c_str(), msgInfo.msg.c_str() ); + } + } + break; case RsMailStatusEventCode::MESSAGE_CHANGED: case RsMailStatusEventCode::MESSAGE_REMOVED: updateIcon(); diff --git a/retroshare-gui/src/gui/notifyqt.cpp b/retroshare-gui/src/gui/notifyqt.cpp index 7d2e9a207..59d102170 100644 --- a/retroshare-gui/src/gui/notifyqt.cpp +++ b/retroshare-gui/src/gui/notifyqt.cpp @@ -1162,3 +1162,82 @@ void NotifyQt::runningTick() } } +void NotifyQt::addToaster(uint notifyFlags, const std::string& id, const std::string& title, const std::string& msg) +{ + uint pos = 0; + + while (notifyFlags) { + uint type = notifyFlags & (1 << pos); + notifyFlags &= ~(1 << pos); + ++pos; + + ToasterItem *toaster = NULL; + + switch(type) + { + case RS_POPUP_ENCRYPTED_MSG: + SoundManager::play(SOUND_MESSAGE_ARRIVED); + + toaster = new ToasterItem(new MessageToaster(std::string(), tr("Unknown title"), QString("[%1]").arg(tr("Encrypted message")))); + break; + case RS_POPUP_MSG: + SoundManager::play(SOUND_MESSAGE_ARRIVED); + + toaster = new ToasterItem(new MessageToaster(id, QString::fromUtf8(title.c_str()), QString::fromUtf8(msg.c_str()))); + break; + case RS_POPUP_CONNECT: + SoundManager::play(SOUND_USER_ONLINE); + + toaster = new ToasterItem(new OnlineToaster(RsPeerId(id))); + break; + case RS_POPUP_DOWNLOAD: + SoundManager::play(SOUND_DOWNLOAD_COMPLETE); + + toaster = new ToasterItem(new DownloadToaster(RsFileHash(id), QString::fromUtf8(title.c_str()))); + break; + case RS_POPUP_CHAT: + toaster = new ToasterItem(new ChatToaster(RsPeerId(id), QString::fromUtf8(msg.c_str()))); + break; + case RS_POPUP_GROUPCHAT: +#ifdef RS_DIRECT_CHAT + toaster = new ToasterItem(new GroupChatToaster(RsPeerId(id), QString::fromUtf8(msg.c_str()))); +#endif // RS_DIRECT_CHAT + break; + case RS_POPUP_CHATLOBBY: + { + ChatId chat_id(id); + + ChatDialog *chatDialog = ChatDialog::getChat(chat_id); + ChatWidget *chatWidget; + if (chatDialog && (chatWidget = chatDialog->getChatWidget()) && chatWidget->isActive()) { + // do not show when active + break; + } + + ChatLobbyDialog *chatLobbyDialog = dynamic_cast(chatDialog); + + RsGxsId sender(title); + if (!chatLobbyDialog || chatLobbyDialog->isParticipantMuted(sender)) + break; // participant is muted + + toaster = new ToasterItem(new ChatLobbyToaster(chat_id.toLobbyId(), sender, QString::fromUtf8(msg.c_str()))); + } + break; + case RS_POPUP_CONNECT_ATTEMPT: + // id = gpgid + // title = ssl name + // msg = peer id + toaster = new ToasterItem(new FriendRequestToaster(RsPgpId(id), QString::fromUtf8(title.c_str()), RsPeerId(msg))); + break; + } + + if (toaster) { + /* init attributes */ + toaster->widget->setWindowFlags(Qt::ToolTip | Qt::WindowStaysOnTopHint); + + /* add toaster to waiting list */ + //QMutexLocker lock(&waitingToasterMutex); + waitingToasterList.push_back(toaster); + } + } +} diff --git a/retroshare-gui/src/gui/notifyqt.h b/retroshare-gui/src/gui/notifyqt.h index f4fc063c7..d2b15fa09 100644 --- a/retroshare-gui/src/gui/notifyqt.h +++ b/retroshare-gui/src/gui/notifyqt.h @@ -95,6 +95,7 @@ class NotifyQt: public QObject, public NotifyClient void testToaster(ToasterNotify *toasterNotify, /*RshareSettings::enumToasterPosition*/ int position, QPoint margin); void testToaster(QString tag, ToasterNotify *toasterNotify, /*RshareSettings::enumToasterPosition*/ int position, QPoint margin); + void addToaster(uint notifyFlags, const std::string& id, const std::string& title, const std::string& msg); void notifySettingsChanged(); signals: diff --git a/retroshare-gui/src/gui/settings/ServerPage.cpp b/retroshare-gui/src/gui/settings/ServerPage.cpp index 4dd49ed80..3dfe9069d 100755 --- a/retroshare-gui/src/gui/settings/ServerPage.cpp +++ b/retroshare-gui/src/gui/settings/ServerPage.cpp @@ -21,6 +21,7 @@ #include "ServerPage.h" #include +#include "gui/MainWindow.h" #include "rshare.h" #include "rsharesettings.h" #include "util/i2pcommon.h" @@ -1366,6 +1367,7 @@ void ServerPage::saveAddressesHiddenNode() void ServerPage::updateOutProxyIndicator() { + MainWindow::getInstance()->torstatusReset(); QTcpSocket socket ; // Tor @@ -1382,22 +1384,39 @@ void ServerPage::updateOutProxyIndicator() ui.iconlabel_tor_outgoing->setToolTip(tr("Tor proxy is not enabled")) ; } - // I2P - SAM - // Note: there is only "the SAM port", there is no additional proxy port! - samStatus ss; - rsAutoProxyMonitor::taskSync(autoProxyType::I2PSAM3, autoProxyTask::status, &ss); - if(ss.state == samStatus::samState::online) + if (mHiddenType == RS_HIDDEN_TYPE_I2P && mSamSettings.enable) { - socket.disconnectFromHost(); - ui.iconlabel_i2p_outgoing->setPixmap(FilesDefs::getPixmapFromQtResourcePath(ICON_STATUS_OK)) ; - ui.iconlabel_i2p_outgoing->setToolTip(tr("Proxy seems to work.")) ; + // I2P - SAM + // Note: there is only "the SAM port", there is no additional proxy port! + samStatus ss; + rsAutoProxyMonitor::taskSync(autoProxyType::I2PSAM3, autoProxyTask::status, &ss); + if(ss.state == samStatus::samState::online) + { + socket.disconnectFromHost(); + ui.iconlabel_i2p_outgoing->setPixmap(FilesDefs::getPixmapFromQtResourcePath(ICON_STATUS_OK)) ; + ui.iconlabel_i2p_outgoing->setToolTip(tr("Proxy seems to work.")) ; + } + else + { + ui.iconlabel_i2p_outgoing->setPixmap(FilesDefs::getPixmapFromQtResourcePath(ICON_STATUS_UNKNOWN)) ; + ui.iconlabel_i2p_outgoing->setToolTip(tr("I2P proxy is not enabled")) ; + } } else { - ui.iconlabel_i2p_outgoing->setPixmap(FilesDefs::getPixmapFromQtResourcePath(ICON_STATUS_UNKNOWN)) ; - ui.iconlabel_i2p_outgoing->setToolTip(tr("I2P proxy is not enabled")) ; + socket.connectToHost(ui.hiddenpage_proxyAddress_i2p->text(),ui.hiddenpage_proxyPort_i2p->text().toInt()); + if(socket.waitForConnected(500)) + { + socket.disconnectFromHost(); + ui.iconlabel_i2p_outgoing->setPixmap(FilesDefs::getPixmapFromQtResourcePath(ICON_STATUS_OK)) ; + ui.iconlabel_i2p_outgoing->setToolTip(tr("Proxy seems to work.")) ; + } + else + { + ui.iconlabel_i2p_outgoing->setPixmap(FilesDefs::getPixmapFromQtResourcePath(ICON_STATUS_UNKNOWN)) ; + ui.iconlabel_i2p_outgoing->setToolTip(tr("I2P proxy is not enabled")) ; + } } - socket.connectToHost(ui.hiddenpage_proxyAddress_i2p_2->text(), 7656); if(true == (mSamAccessible = socket.waitForConnected(1000))) { diff --git a/retroshare-gui/src/gui/statusbar/torstatus.cpp b/retroshare-gui/src/gui/statusbar/torstatus.cpp index fdde22337..d43de1df3 100644 --- a/retroshare-gui/src/gui/statusbar/torstatus.cpp +++ b/retroshare-gui/src/gui/statusbar/torstatus.cpp @@ -168,7 +168,7 @@ void TorStatus::getTorStatus() torstatusLabel->setToolTip( text + tr("Tor proxy is not available")); } } - if(hiddentype == RS_HIDDEN_TYPE_I2P) + else if(hiddentype == RS_HIDDEN_TYPE_I2P) { statusTor->setText("" + tr("I2P") + ":"); rsPeers->getProxyServer(RS_HIDDEN_TYPE_I2P, proxyaddr, proxyport, status); @@ -185,6 +185,11 @@ void TorStatus::getTorStatus() torstatusLabel->setToolTip( text + tr("i2p proxy is not available")); } } + else + { + torstatusLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/icons/tile_inactive_48.png").scaledToHeight(S,Qt::SmoothTransformation)); + torstatusLabel->setToolTip(tr("No tor configuration")); + } _updated = true; } } diff --git a/retroshare-gui/src/gui/toaster/MessageToaster.cpp b/retroshare-gui/src/gui/toaster/MessageToaster.cpp index 93772ca68..1f4894ba3 100644 --- a/retroshare-gui/src/gui/toaster/MessageToaster.cpp +++ b/retroshare-gui/src/gui/toaster/MessageToaster.cpp @@ -21,7 +21,11 @@ #include "MessageToaster.h" #include "../MainWindow.h" +#include #include +#include + +#include "gui/msgs/MessageInterface.h" MessageToaster::MessageToaster(const std::string &peerId, const QString &title, const QString &message) : QWidget(NULL) { @@ -39,8 +43,24 @@ MessageToaster::MessageToaster(const std::string &peerId, const QString &title, ui.textLabel->setText(message); ui.textLabel->setToolTip(message); - std::string name = (!RsPeerId(peerId).isNull())? (rsPeers->getPeerName(RsPeerId(peerId))): (rsPeers->getGPGName(RsPgpId(peerId))) ; - ui.toasterLabel->setText(ui.toasterLabel->text() + " " + QString::fromUtf8(name.c_str())); + MessageInfo mi; + + if (!rsMail->getMessage(peerId, mi)) + return; + + QString srcName; + + if(mi.msgflags & RS_MSG_DISTANT) + { + RsIdentityDetails details ; + rsIdentity->getIdDetails(mi.from.toGxsId(), details) ; + + srcName = QString::fromUtf8(details.mNickname.c_str()); + } + else + srcName = QString::fromUtf8(rsPeers->getPeerName(mi.from.toRsPeerId()).c_str()); + + ui.toasterLabel->setText(ui.toasterLabel->text() + " " + srcName); } void MessageToaster::openmessageClicked() diff --git a/retroshare-webui b/retroshare-webui new file mode 160000 index 000000000..5cc37b3e5 --- /dev/null +++ b/retroshare-webui @@ -0,0 +1 @@ +Subproject commit 5cc37b3e5ad6b64b247e9d2066a9b6c8acae67ce