diff --git a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp index 6035d37d2..bf3e1c92b 100644 --- a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp @@ -42,6 +42,7 @@ #include "gui/msgs/MessageComposer.h" #include "gui/settings/AddFileAssociationDialog.h" #include "gui/gxschannels/GxsChannelDialog.h" +#include "gui/gxsforums/GxsForumsDialog.h" #include "gui/settings/rsharesettings.h" #include "util/QtVersion.h" #include "util/RsAction.h" @@ -64,6 +65,7 @@ #define IMAGE_OPENFILE ":/images/fileopen.png" #define IMAGE_LIBRARY ":/images/library.png" #define IMAGE_CHANNEL ":/images/channels32.png" +#define IMAGE_FORUMS ":/icons/png/forums.png" #define IMAGE_COLLCREATE ":/images/library_add.png" #define IMAGE_COLLMODIF ":/images/library_edit.png" #define IMAGE_COLLVIEW ":/images/library_view.png" @@ -963,6 +965,15 @@ void SharedFilesDialog::postModDirectories(bool local) QCoreApplication::flush(); } +class ChannelCompare +{ +public: + bool operator()(const std::pair& id1,const std::pair& id2) const + { + return id1.first < id2.first ; + } +}; + void LocalSharedFilesDialog::spawnCustomPopupMenu( QPoint point ) { if (!rsPeers) return; /* not ready yet! */ @@ -1017,26 +1028,55 @@ void LocalSharedFilesDialog::spawnCustomPopupMenu( QPoint point ) } GxsChannelDialog *channelDialog = dynamic_cast(MainWindow::getPage(MainWindow::Channels)); + QMenu shareChannelMenu(tr("Share on channel...")) ; // added here because the shareChannelMenu QMenu object is deleted afterwards if(channelDialog != NULL) { - QMenu shareChannelMenu(tr("Share on channel...")) ; shareChannelMenu.setIcon(QIcon(IMAGE_CHANNEL)); std::list grp_metas ; channelDialog->getGroupList(grp_metas) ; + std::vector > grplist ; // I dont use a std::map because two or more channels may have the same name. + for(auto it(grp_metas.begin());it!=grp_metas.end();++it) if(IS_GROUP_PUBLISHER((*it).mSubscribeFlags) && IS_GROUP_SUBSCRIBED((*it).mSubscribeFlags)) - shareChannelMenu.addAction(QString::fromUtf8((*it).mGroupName.c_str()), this, SLOT(shareOnChannel()))->setData(QString::fromStdString((*it).mGroupId.toStdString())) ; + grplist.push_back(std::make_pair((*it).mGroupName, (*it).mGroupId)); + + std::sort(grplist.begin(),grplist.end(),ChannelCompare()) ; + + for(auto it(grplist.begin());it!=grplist.end();++it) + shareChannelMenu.addAction(QString::fromUtf8((*it).first.c_str()), this, SLOT(shareOnChannel()))->setData(QString::fromStdString((*it).second.toStdString())) ; contextMnu.addMenu(&shareChannelMenu) ; - contextMnu.exec(QCursor::pos()) ; // added here because the shareChannelMenu QMenu object is deleted afterwards } - else - contextMnu.exec(QCursor::pos()) ; -} + GxsForumsDialog *forumsDialog = dynamic_cast(MainWindow::getPage(MainWindow::Forums)); + QMenu shareForumMenu(tr("Share on forum...")) ; // added here because the shareChannelMenu QMenu object is deleted afterwards + + if(forumsDialog != NULL) + { + shareForumMenu.setIcon(QIcon(IMAGE_FORUMS)); + + std::list grp_metas ; + forumsDialog->getGroupList(grp_metas) ; + + std::vector > grplist ; // I dont use a std::map because two or more channels may have the same name. + + for(auto it(grp_metas.begin());it!=grp_metas.end();++it) + if(IS_GROUP_SUBSCRIBED((*it).mSubscribeFlags)) + grplist.push_back(std::make_pair((*it).mGroupName, (*it).mGroupId)); + + std::sort(grplist.begin(),grplist.end(),ChannelCompare()) ; + + for(auto it(grplist.begin());it!=grplist.end();++it) + shareForumMenu.addAction(QString::fromUtf8((*it).first.c_str()), this, SLOT(shareInForum()))->setData(QString::fromStdString((*it).second.toStdString())) ; + + contextMnu.addMenu(&shareForumMenu) ; + } + + contextMnu.exec(QCursor::pos()) ; +} void LocalSharedFilesDialog::shareOnChannel() { RsGxsGroupId groupId(qobject_cast(sender())->data().toString().toStdString()); @@ -1055,6 +1095,24 @@ void LocalSharedFilesDialog::shareOnChannel() channelDialog->shareOnChannel(groupId,file_links_list) ; } +void LocalSharedFilesDialog::shareInForum() +{ + RsGxsGroupId groupId(qobject_cast(sender())->data().toString().toStdString()); + + GxsForumsDialog *forumsDialog = dynamic_cast(MainWindow::getPage(MainWindow::Forums)); + + if(forumsDialog == NULL) + return ; + + std::list files_info ; + + QList file_links_list ; + bool has_unhashed_files ; + + copyLinks(getSelected(),false,file_links_list,has_unhashed_files) ; + + forumsDialog->shareInMessage(groupId,file_links_list) ; +} //============================================================================ diff --git a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.h b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.h index 885bab91a..8e242a0a6 100644 --- a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.h +++ b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.h @@ -160,6 +160,7 @@ class LocalSharedFilesDialog : public SharedFilesDialog void tryToAddNewAssotiation(); void forceCheck(); void shareOnChannel(); + void shareInForum(); QAction* fileAssotiationAction(const QString fileName); diff --git a/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp b/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp index 8c4f2c524..e8b15ed8e 100644 --- a/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp +++ b/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp @@ -412,6 +412,11 @@ void CreateGxsChannelMsg::addExtraFile() } } +void CreateGxsChannelMsg::addSubject(const QString& text) +{ + subjectEdit->setText(text) ; +} + void CreateGxsChannelMsg::addHtmlText(const QString& text) { msgEdit->setHtml(text) ; diff --git a/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.h b/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.h index 5168c6226..3e9f6ccc6 100644 --- a/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.h +++ b/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.h @@ -44,6 +44,7 @@ public: ~CreateGxsChannelMsg(); void addHtmlText(const QString& text) ; + void addSubject(const QString& text) ; void addAttachment(const std::string &path); void addAttachment(const RsFileHash &hash, const std::string &fname, uint64_t size, bool local, const RsPeerId &srcId,bool assume_file_ready = false); diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp index c011621a8..4bff7528b 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp @@ -87,6 +87,12 @@ void GxsChannelDialog::shareOnChannel(const RsGxsGroupId& channel_id,const QList for(QList::const_iterator it(file_links.begin());it!=file_links.end();++it) txt += (*it).toHtml() + "\n" ; + if(!file_links.empty()) + { + QString subject = (*file_links.begin()).name() ; + msgDialog->addSubject(subject); + } + msgDialog->addHtmlText(txt); msgDialog->show(); } diff --git a/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.cpp b/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.cpp index c0fe50316..60f34221f 100644 --- a/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.cpp +++ b/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.cpp @@ -152,12 +152,13 @@ void CreateGxsForumMsg::newMsg() mStateHelper->setActive(CREATEGXSFORUMMSG_FORUMINFO, false); mStateHelper->setActive(CREATEGXSFORUMMSG_PARENTMSG, false); mStateHelper->setActive(CREATEGXSFORUMMSG_ORIGMSG, false); + mStateHelper->clear(CREATEGXSFORUMMSG_FORUMINFO); mStateHelper->clear(CREATEGXSFORUMMSG_PARENTMSG); mStateHelper->clear(CREATEGXSFORUMMSG_ORIGMSG); ui.forumName->setText(tr("No Forum")); return; - }//if ( mForumId.isNull()) + } {/* request Data */ mStateHelper->setLoading(CREATEGXSFORUMMSG_FORUMINFO, true); @@ -192,7 +193,7 @@ void CreateGxsForumMsg::newMsg() uint32_t token; mForumQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, msgIds, CREATEGXSFORUMMSG_PARENTMSG); - }//if (mParentId.isNull()) + } if (mOrigMsgId.isNull()) { mStateHelper->setActive(CREATEGXSFORUMMSG_ORIGMSG, true); @@ -212,7 +213,7 @@ void CreateGxsForumMsg::newMsg() uint32_t token; mForumQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, msgIds, CREATEGXSFORUMMSG_ORIGMSG); - }//if (mParentId.isNull()) + } } void CreateGxsForumMsg::loadFormInformation() @@ -307,17 +308,14 @@ void CreateGxsForumMsg::loadFormInformation() } ui.forumName->setText(misc::removeNewLine(name)); - ui.forumSubject->setText(misc::removeNewLine(subj)); - //ui.forumSubject->setReadOnly(!mOrigMsgId.isNull()); + + if(!subj.isNull()) + ui.forumSubject->setText(misc::removeNewLine(subj)); if (ui.forumSubject->text().isEmpty()) - { ui.forumSubject->setFocus(); - } else - { ui.forumMessage->setFocus(); - } #ifdef TOGXS if (mForumMeta.mGroupFlags & RS_DISTRIB_AUTHEN_REQ) @@ -687,8 +685,12 @@ void CreateGxsForumMsg::loadRequest(const TokenQueue *queue, const TokenRequest } } } +void CreateGxsForumMsg::setSubject(const QString& msg) +{ + ui.forumSubject->setText(msg); +} -void CreateGxsForumMsg::insertPastedText(QString msg) +void CreateGxsForumMsg::insertPastedText(const QString& msg) { ui.forumMessage->append(msg); } diff --git a/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.h b/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.h index 7f84a434b..a7e4c78c3 100644 --- a/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.h +++ b/retroshare-gui/src/gui/gxsforums/CreateGxsForumMsg.h @@ -41,7 +41,8 @@ public: void newMsg(); /* cleanup */ virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req); -void insertPastedText(QString msg) ; + void insertPastedText(const QString& msg) ; + void setSubject(const QString& msg); private slots: void fileHashingFinished(QList hashedFiles); diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumsDialog.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumsDialog.cpp index 9dcbc24f5..38a57742f 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumsDialog.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumsDialog.cpp @@ -22,6 +22,7 @@ #include "GxsForumsDialog.h" #include "GxsForumGroupDialog.h" #include "GxsForumThreadWidget.h" +#include "CreateGxsForumMsg.h" #include "GxsForumUserNotify.h" #include "gui/notifyqt.h" #include "gui/gxs/GxsGroupShareKey.h" @@ -60,6 +61,24 @@ QString GxsForumsDialog::getHelpString() const return hlp_str ; } +void GxsForumsDialog::shareInMessage(const RsGxsGroupId& forum_id,const QList& file_links) +{ + CreateGxsForumMsg *msgDialog = new CreateGxsForumMsg(forum_id,RsGxsMessageId(),RsGxsMessageId(),RsGxsId()) ; + + QString txt ; + for(QList::const_iterator it(file_links.begin());it!=file_links.end();++it) + txt += (*it).toHtml() + "\n" ; + + if(!file_links.empty()) + { + QString subject = (*file_links.begin()).name() ; + msgDialog->setSubject(subject); + } + + msgDialog->insertPastedText(txt); + msgDialog->show(); +} + UserNotify *GxsForumsDialog::getUserNotify(QObject *parent) { return new GxsForumUserNotify(rsGxsForums, parent); diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumsDialog.h b/retroshare-gui/src/gui/gxsforums/GxsForumsDialog.h index 60a713151..2183a9000 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumsDialog.h +++ b/retroshare-gui/src/gui/gxsforums/GxsForumsDialog.h @@ -40,6 +40,8 @@ public: virtual UserNotify *getUserNotify(QObject *parent); + void shareInMessage(const RsGxsGroupId& forum_id, const QList& file_link) ; + protected: virtual QString getHelpString() const ; virtual RetroShareLink::enumType getLinkType() { return RetroShareLink::TYPE_FORUM; }