Merge pull request #1084 from csoler/v0.6-Links2

added sorting of channels to push to, and auto-fill of channel subject
This commit is contained in:
csoler 2017-10-29 21:31:10 +01:00 committed by GitHub
commit b77e895691
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 112 additions and 17 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"
@ -963,6 +965,15 @@ void SharedFilesDialog::postModDirectories(bool local)
QCoreApplication::flush();
}
class ChannelCompare
{
public:
bool operator()(const std::pair<std::string,RsGxsGroupId>& id1,const std::pair<std::string,RsGxsGroupId>& 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<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> > 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<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());
@ -1055,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

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

View File

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

View File

@ -87,6 +87,12 @@ void GxsChannelDialog::shareOnChannel(const RsGxsGroupId& channel_id,const QList
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->addSubject(subject);
}
msgDialog->addHtmlText(txt);
msgDialog->show();
}

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