added post into forum menu entry in SharedFilesDialog

This commit is contained in:
csoler 2017-10-29 20:33:56 +01:00
parent 0c97d5bc3c
commit 9ad635a665
6 changed files with 87 additions and 20 deletions

View File

@ -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"
@ -1026,33 +1028,55 @@ void LocalSharedFilesDialog::spawnCustomPopupMenu( QPoint point )
}
GxsChannelDialog *channelDialog = dynamic_cast<GxsChannelDialog*>(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<RsGroupMetaData> grp_metas ;
channelDialog->getGroupList(grp_metas) ;
std::vector<std::pair<std::string,RsGxsGroupId> > chnls ; // I dont use a std::map because two or more channels may have the same name.
std::vector<std::pair<std::string,RsGxsGroupId> > 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))
chnls.push_back(std::make_pair((*it).mGroupName, (*it).mGroupId));
grplist.push_back(std::make_pair((*it).mGroupName, (*it).mGroupId));
std::sort(chnls.begin(),chnls.end(),ChannelCompare()) ;
std::sort(grplist.begin(),grplist.end(),ChannelCompare()) ;
for(auto it(chnls.begin());it!=chnls.end();++it)
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<GxsForumsDialog*>(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<RsGroupMetaData> grp_metas ;
forumsDialog->getGroupList(grp_metas) ;
std::vector<std::pair<std::string,RsGxsGroupId> > 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<QAction*>(sender())->data().toString().toStdString());
@ -1071,6 +1095,24 @@ void LocalSharedFilesDialog::shareOnChannel()
channelDialog->shareOnChannel(groupId,file_links_list) ;
}
void LocalSharedFilesDialog::shareInForum()
{
RsGxsGroupId groupId(qobject_cast<QAction*>(sender())->data().toString().toStdString());
GxsForumsDialog *forumsDialog = dynamic_cast<GxsForumsDialog*>(MainWindow::getPage(MainWindow::Forums));
if(forumsDialog == NULL)
return ;
std::list<DirDetails> files_info ;
QList<RetroShareLink> file_links_list ;
bool has_unhashed_files ;
copyLinks(getSelected(),false,file_links_list,has_unhashed_files) ;
forumsDialog->shareInMessage(groupId,file_links_list) ;
}
//============================================================================

View File

@ -160,6 +160,7 @@ class LocalSharedFilesDialog : public SharedFilesDialog
void tryToAddNewAssotiation();
void forceCheck();
void shareOnChannel();
void shareInForum();
QAction* fileAssotiationAction(const QString fileName);

View File

@ -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);
}

View File

@ -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<HashedFile> hashedFiles);

View File

@ -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<RetroShareLink>& file_links)
{
CreateGxsForumMsg *msgDialog = new CreateGxsForumMsg(forum_id,RsGxsMessageId(),RsGxsMessageId(),RsGxsId()) ;
QString txt ;
for(QList<RetroShareLink>::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);

View File

@ -40,6 +40,8 @@ public:
virtual UserNotify *getUserNotify(QObject *parent);
void shareInMessage(const RsGxsGroupId& forum_id, const QList<RetroShareLink>& file_link) ;
protected:
virtual QString getHelpString() const ;
virtual RetroShareLink::enumType getLinkType() { return RetroShareLink::TYPE_FORUM; }