added copy link and navigate functions.

This commit is contained in:
csoler 2020-06-19 23:03:13 +02:00
parent 7bb56953bd
commit 6a3fe9ebf0
No known key found for this signature in database
GPG key ID: 7BCA522266C0804C
3 changed files with 89 additions and 32 deletions

View file

@ -22,6 +22,7 @@
#include <QMenu> #include <QMenu>
#include <QSignalMapper> #include <QSignalMapper>
#include <QPainter> #include <QPainter>
#include <QMessageBox>
#include "retroshare/rsgxscircles.h" #include "retroshare/rsgxscircles.h"
@ -71,6 +72,7 @@ static const int CHANNEL_TABS_POSTS = 1;
#define COLUMN_SIZE_FONT_FACTOR_H 10 #define COLUMN_SIZE_FONT_FACTOR_H 10
#define STAR_OVERLAY_IMAGE ":icons/star_overlay_128.png" #define STAR_OVERLAY_IMAGE ":icons/star_overlay_128.png"
#define IMAGE_COPYLINK ":/images/copyrslink.png"
Q_DECLARE_METATYPE(ChannelPostFileInfo) Q_DECLARE_METATYPE(ChannelPostFileInfo)
@ -326,11 +328,44 @@ void GxsChannelPostsWidgetWithModel::postContextMenu(const QPoint&)
{ {
QMenu menu(this); QMenu menu(this);
menu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_COPYLINK), tr("Copy RetroShare Link"), this, SLOT(copyMessageLink()));
if(IS_GROUP_PUBLISHER(mGroup.mMeta.mSubscribeFlags)) if(IS_GROUP_PUBLISHER(mGroup.mMeta.mSubscribeFlags))
{
menu.addAction(FilesDefs::getIconFromQtResourcePath(":/images/edit_16.png"), tr("Edit"), this, SLOT(editPost())); menu.addAction(FilesDefs::getIconFromQtResourcePath(":/images/edit_16.png"), tr("Edit"), this, SLOT(editPost()));
menu.exec(QCursor::pos()); menu.exec(QCursor::pos());
} }
void GxsChannelPostsWidgetWithModel::copyMessageLink()
{
try
{
if (groupId().isNull())
throw std::runtime_error("No channel currently selected!");
QModelIndex index = ui->postsTree->selectionModel()->currentIndex();
if(!index.isValid())
throw std::runtime_error("No post under mouse!");
RsGxsChannelPost post = index.data(Qt::UserRole).value<RsGxsChannelPost>() ;
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()));
if (!link.valid())
throw std::runtime_error("Link is not valid");
QList<RetroShareLink> 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());
}
} }
void GxsChannelPostsWidgetWithModel::editPost() void GxsChannelPostsWidgetWithModel::editPost()
@ -386,7 +421,6 @@ void GxsChannelPostsWidgetWithModel::showPostDetails()
ui->postName_LB->hide(); ui->postName_LB->hide();
ui->postTime_LB->hide(); ui->postTime_LB->hide();
mChannelPostFilesModel->clear(); mChannelPostFilesModel->clear();
mSelectedGroup.clear();
mSelectedPost.clear(); mSelectedPost.clear();
return; return;
} }
@ -398,7 +432,6 @@ void GxsChannelPostsWidgetWithModel::showPostDetails()
if(index.row()==0 && index.column()==0) if(index.row()==0 && index.column()==0)
std::cerr << "here" << std::endl; std::cerr << "here" << std::endl;
mSelectedGroup = mGroup.mMeta.mGroupId;
mSelectedPost = post.mMeta.mMsgId; mSelectedPost = post.mMeta.mMsgId;
std::list<ChannelPostFileInfo> files; std::list<ChannelPostFileInfo> files;
@ -454,7 +487,12 @@ void GxsChannelPostsWidgetWithModel::showPostDetails()
void GxsChannelPostsWidgetWithModel::updateGroupData() void GxsChannelPostsWidgetWithModel::updateGroupData()
{ {
if(groupId().isNull()) if(groupId().isNull())
{
// clear post, files and comment widgets
showPostDetails();
return; return;
}
RsThread::async([this]() RsThread::async([this]()
{ {
@ -486,12 +524,18 @@ void GxsChannelPostsWidgetWithModel::postChannelPostLoad()
{ {
std::cerr << "Post channel load..." << std::endl; std::cerr << "Post channel load..." << std::endl;
if(!mSelectedPost.isNull() && mGroup.mMeta.mGroupId == mSelectedGroup) if(!mSelectedPost.isNull())
{ {
QModelIndex index = mChannelPostsModel->getIndexOfMessage(mSelectedPost); QModelIndex index = mChannelPostsModel->getIndexOfMessage(mSelectedPost);
std::cerr << "Setting current index to " << index.row() << ","<< index.column() << " for current post " << mSelectedPost << std::endl; std::cerr << "Setting current index to " << index.row() << ","<< index.column() << " for current post " << mSelectedPost << std::endl;
whileBlocking(ui->postsTree)->setCurrentIndex(index);
ui->postsTree->selectionModel()->setCurrentIndex(index,QItemSelectionModel::ClearAndSelect);
ui->postsTree->scrollTo(ui->postsTree->currentIndex());//May change if model reloaded
ui->postsTree->setFocus();
ui->postsTree->update();
} }
else
mSelectedPost.clear();
std::list<ChannelPostFileInfo> files; std::list<ChannelPostFileInfo> files;
@ -980,8 +1024,21 @@ void GxsChannelPostsWidgetWithModel::blank()
bool GxsChannelPostsWidgetWithModel::navigate(const RsGxsMessageId& msgId) bool GxsChannelPostsWidgetWithModel::navigate(const RsGxsMessageId& msgId)
{ {
#warning TODO QModelIndex index = mChannelPostsModel->getIndexOfMessage(msgId);
//return ui->feedWidget->scrollTo(feedItem, true);
if(!index.isValid())
{
std::cerr << "(EE) Cannot navigate to msg " << msgId << " in channel " << mGroup.mMeta.mGroupId << ": index unknown. Setting mNavigatePendingMsgId." << std::endl;
mSelectedPost = 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(ui->postsTree->currentIndex());//May change if model reloaded
ui->postsTree->setFocus();
ui->postsTree->update();
return true; return true;
} }

View file

@ -141,6 +141,7 @@ private slots:
void postChannelPostLoad(); void postChannelPostLoad();
void editPost(); void editPost();
void postContextMenu(const QPoint&); void postContextMenu(const QPoint&);
void copyMessageLink();
public slots: public slots:
void sortColumnFiles(int col,Qt::SortOrder so); void sortColumnFiles(int col,Qt::SortOrder so);
@ -169,7 +170,6 @@ private:
RsGxsChannelPostFilesModel *mChannelFilesModel; RsGxsChannelPostFilesModel *mChannelFilesModel;
RsGxsMessageId mSelectedPost; RsGxsMessageId mSelectedPost;
RsGxsGroupId mSelectedGroup;
/* UI - from Designer */ /* UI - from Designer */
Ui::GxsChannelPostsWidgetWithModel *ui; Ui::GxsChannelPostsWidgetWithModel *ui;

View file

@ -123,9 +123,9 @@ public:
{ {
default: default:
case 3: case 3:
case 0: icon = QIcon(IMAGE_VOID); break; case 0: icon = FilesDefs::getIconFromQtResourcePath(IMAGE_VOID); break;
case 1: icon = QIcon(IMAGE_WARNING_YELLOW); break; case 1: icon = FilesDefs::getIconFromQtResourcePath(IMAGE_WARNING_YELLOW); break;
case 2: icon = QIcon(IMAGE_WARNING_RED); break; case 2: icon = FilesDefs::getIconFromQtResourcePath(IMAGE_WARNING_RED); break;
} }
QPixmap pix = icon.pixmap(r.size()); QPixmap pix = icon.pixmap(r.size());
@ -172,9 +172,9 @@ public:
else else
{ {
if (unread) if (unread)
icon = QIcon(":/images/message-state-unread.png"); icon = FilesDefs::getIconFromQtResourcePath(":/images/message-state-unread.png");
else else
icon = QIcon(":/images/message-state-read.png"); icon = FilesDefs::getIconFromQtResourcePath(":/images/message-state-read.png");
} }
QPixmap pix = icon.pixmap(r.size()); QPixmap pix = icon.pixmap(r.size());
@ -462,7 +462,7 @@ QString GxsForumThreadWidget::groupName(bool withUnreadCount)
QIcon GxsForumThreadWidget::groupIcon() QIcon GxsForumThreadWidget::groupIcon()
{ {
if (mNewCount) { if (mNewCount) {
return QIcon(":/images/message-state-new.png"); return FilesDefs::getIconFromQtResourcePath(":/images/message-state-new.png");
} }
return QIcon(); return QIcon();
@ -561,35 +561,35 @@ void GxsForumThreadWidget::threadListCustomPopupMenu(QPoint /*point*/)
#ifdef DEBUG_FORUMS #ifdef DEBUG_FORUMS
std::cerr << "Clicked on msg " << current_post.mMsgId << std::endl; std::cerr << "Clicked on msg " << current_post.mMsgId << std::endl;
#endif #endif
QAction *editAct = new QAction(QIcon(IMAGE_MESSAGEEDIT), tr("Edit"), &contextMnu); QAction *editAct = new QAction(FilesDefs::getIconFromQtResourcePath(IMAGE_MESSAGEEDIT), tr("Edit"), &contextMnu);
connect(editAct, SIGNAL(triggered()), this, SLOT(editforummessage())); connect(editAct, SIGNAL(triggered()), this, SLOT(editforummessage()));
bool is_pinned = mForumGroup.mPinnedPosts.ids.find(mThreadId) != mForumGroup.mPinnedPosts.ids.end(); bool is_pinned = mForumGroup.mPinnedPosts.ids.find(mThreadId) != mForumGroup.mPinnedPosts.ids.end();
QAction *pinUpPostAct = new QAction(QIcon(IMAGE_PINPOST), (is_pinned?tr("Un-pin this post"):tr("Pin this post up")), &contextMnu); QAction *pinUpPostAct = new QAction(FilesDefs::getIconFromQtResourcePath(IMAGE_PINPOST), (is_pinned?tr("Un-pin this post"):tr("Pin this post up")), &contextMnu);
connect(pinUpPostAct , SIGNAL(triggered()), this, SLOT(togglePinUpPost())); connect(pinUpPostAct , SIGNAL(triggered()), this, SLOT(togglePinUpPost()));
QAction *replyAct = new QAction(QIcon(IMAGE_REPLY), tr("Reply"), &contextMnu); QAction *replyAct = new QAction(FilesDefs::getIconFromQtResourcePath(IMAGE_REPLY), tr("Reply"), &contextMnu);
connect(replyAct, SIGNAL(triggered()), this, SLOT(replytoforummessage())); connect(replyAct, SIGNAL(triggered()), this, SLOT(replytoforummessage()));
QAction *replyauthorAct = new QAction(QIcon(IMAGE_MESSAGEREPLY), tr("Reply to author with private message"), &contextMnu); QAction *replyauthorAct = new QAction(FilesDefs::getIconFromQtResourcePath(IMAGE_MESSAGEREPLY), tr("Reply to author with private message"), &contextMnu);
connect(replyauthorAct, SIGNAL(triggered()), this, SLOT(reply_with_private_message())); connect(replyauthorAct, SIGNAL(triggered()), this, SLOT(reply_with_private_message()));
QAction *flagaspositiveAct = new QAction(QIcon(IMAGE_POSITIVE_OPINION), tr("Give positive opinion"), &contextMnu); QAction *flagaspositiveAct = new QAction(FilesDefs::getIconFromQtResourcePath(IMAGE_POSITIVE_OPINION), tr("Give positive opinion"), &contextMnu);
flagaspositiveAct->setToolTip(tr("This will block/hide messages from this person, and notify friend nodes.")) ; flagaspositiveAct->setToolTip(tr("This will block/hide messages from this person, and notify friend nodes.")) ;
flagaspositiveAct->setData(static_cast<uint32_t>(RsOpinion::POSITIVE)); flagaspositiveAct->setData(static_cast<uint32_t>(RsOpinion::POSITIVE));
connect(flagaspositiveAct, SIGNAL(triggered()), this, SLOT(flagperson())); connect(flagaspositiveAct, SIGNAL(triggered()), this, SLOT(flagperson()));
QAction *flagasneutralAct = new QAction(QIcon(IMAGE_NEUTRAL_OPINION), tr("Give neutral opinion"), &contextMnu); QAction *flagasneutralAct = new QAction(FilesDefs::getIconFromQtResourcePath(IMAGE_NEUTRAL_OPINION), tr("Give neutral opinion"), &contextMnu);
flagasneutralAct->setToolTip(tr("Doing this, you trust your friends to decide to forward this message or not.")) ; flagasneutralAct->setToolTip(tr("Doing this, you trust your friends to decide to forward this message or not.")) ;
flagasneutralAct->setData(static_cast<uint32_t>(RsOpinion::NEUTRAL)); flagasneutralAct->setData(static_cast<uint32_t>(RsOpinion::NEUTRAL));
connect(flagasneutralAct, SIGNAL(triggered()), this, SLOT(flagperson())); connect(flagasneutralAct, SIGNAL(triggered()), this, SLOT(flagperson()));
QAction *flagasnegativeAct = new QAction(QIcon(IMAGE_NEGATIVE_OPINION), tr("Give negative opinion"), &contextMnu); QAction *flagasnegativeAct = new QAction(FilesDefs::getIconFromQtResourcePath(IMAGE_NEGATIVE_OPINION), tr("Give negative opinion"), &contextMnu);
flagasnegativeAct->setToolTip(tr("This will block/hide messages from this person, and notify friend nodes.")) ; flagasnegativeAct->setToolTip(tr("This will block/hide messages from this person, and notify friend nodes.")) ;
flagasnegativeAct->setData(static_cast<uint32_t>(RsOpinion::NEGATIVE)); flagasnegativeAct->setData(static_cast<uint32_t>(RsOpinion::NEGATIVE));
connect(flagasnegativeAct, SIGNAL(triggered()), this, SLOT(flagperson())); connect(flagasnegativeAct, SIGNAL(triggered()), this, SLOT(flagperson()));
QAction *newthreadAct = new QAction(QIcon(IMAGE_MESSAGE), tr("Start New Thread"), &contextMnu); QAction *newthreadAct = new QAction(FilesDefs::getIconFromQtResourcePath(IMAGE_MESSAGE), tr("Start New Thread"), &contextMnu);
newthreadAct->setEnabled (IS_GROUP_SUBSCRIBED(mForumGroup.mMeta.mSubscribeFlags)); newthreadAct->setEnabled (IS_GROUP_SUBSCRIBED(mForumGroup.mMeta.mSubscribeFlags));
connect(newthreadAct , SIGNAL(triggered()), this, SLOT(createthread())); connect(newthreadAct , SIGNAL(triggered()), this, SLOT(createthread()));
@ -599,19 +599,19 @@ void GxsForumThreadWidget::threadListCustomPopupMenu(QPoint /*point*/)
QAction* collapseAll = new QAction(tr( "Collapse all"), &contextMnu); QAction* collapseAll = new QAction(tr( "Collapse all"), &contextMnu);
connect(collapseAll, SIGNAL(triggered()), ui->threadTreeWidget, SLOT(collapseAll())); connect(collapseAll, SIGNAL(triggered()), ui->threadTreeWidget, SLOT(collapseAll()));
QAction *markMsgAsRead = new QAction(QIcon(":/images/message-mail-read.png"), tr("Mark as read"), &contextMnu); QAction *markMsgAsRead = new QAction(FilesDefs::getIconFromQtResourcePath(":/images/message-mail-read.png"), tr("Mark as read"), &contextMnu);
connect(markMsgAsRead, SIGNAL(triggered()), this, SLOT(markMsgAsRead())); connect(markMsgAsRead, SIGNAL(triggered()), this, SLOT(markMsgAsRead()));
QAction *markMsgAsReadChildren = new QAction(QIcon(":/images/message-mail-read.png"), tr("Mark as read") + " (" + tr ("with children") + ")", &contextMnu); QAction *markMsgAsReadChildren = new QAction(FilesDefs::getIconFromQtResourcePath(":/images/message-mail-read.png"), tr("Mark as read") + " (" + tr ("with children") + ")", &contextMnu);
connect(markMsgAsReadChildren, SIGNAL(triggered()), this, SLOT(markMsgAsReadChildren())); connect(markMsgAsReadChildren, SIGNAL(triggered()), this, SLOT(markMsgAsReadChildren()));
QAction *markMsgAsUnread = new QAction(QIcon(":/images/message-mail.png"), tr("Mark as unread"), &contextMnu); QAction *markMsgAsUnread = new QAction(FilesDefs::getIconFromQtResourcePath(":/images/message-mail.png"), tr("Mark as unread"), &contextMnu);
connect(markMsgAsUnread, SIGNAL(triggered()), this, SLOT(markMsgAsUnread())); connect(markMsgAsUnread, SIGNAL(triggered()), this, SLOT(markMsgAsUnread()));
QAction *markMsgAsUnreadChildren = new QAction(QIcon(":/images/message-mail.png"), tr("Mark as unread") + " (" + tr ("with children") + ")", &contextMnu); QAction *markMsgAsUnreadChildren = new QAction(FilesDefs::getIconFromQtResourcePath(":/images/message-mail.png"), tr("Mark as unread") + " (" + tr ("with children") + ")", &contextMnu);
connect(markMsgAsUnreadChildren, SIGNAL(triggered()), this, SLOT(markMsgAsUnreadChildren())); connect(markMsgAsUnreadChildren, SIGNAL(triggered()), this, SLOT(markMsgAsUnreadChildren()));
QAction *showinpeopleAct = new QAction(QIcon(":/images/info16.png"), tr("Show author in people tab"), &contextMnu); QAction *showinpeopleAct = new QAction(FilesDefs::getIconFromQtResourcePath(":/images/info16.png"), tr("Show author in people tab"), &contextMnu);
connect(showinpeopleAct, SIGNAL(triggered()), this, SLOT(showInPeopleTab())); connect(showinpeopleAct, SIGNAL(triggered()), this, SLOT(showInPeopleTab()));
if (IS_GROUP_SUBSCRIBED(mForumGroup.mMeta.mSubscribeFlags)) if (IS_GROUP_SUBSCRIBED(mForumGroup.mMeta.mSubscribeFlags))
@ -664,7 +664,7 @@ void GxsForumThreadWidget::threadListCustomPopupMenu(QPoint /*point*/)
contextMnu.addAction(replyAct); contextMnu.addAction(replyAct);
contextMnu.addAction(newthreadAct); contextMnu.addAction(newthreadAct);
QAction* action = contextMnu.addAction(QIcon(IMAGE_COPYLINK), tr("Copy RetroShare Link"), this, SLOT(copyMessageLink())); QAction* action = contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_COPYLINK), tr("Copy RetroShare Link"), this, SLOT(copyMessageLink()));
action->setEnabled(!groupId().isNull() && !mThreadId.isNull()); action->setEnabled(!groupId().isNull() && !mThreadId.isNull());
contextMnu.addSeparator(); contextMnu.addSeparator();
contextMnu.addAction(markMsgAsRead); contextMnu.addAction(markMsgAsRead);
@ -756,7 +756,7 @@ void GxsForumThreadWidget::togglethreadview_internal()
{ {
// if (ui->expandButton->isChecked()) { // if (ui->expandButton->isChecked()) {
ui->postText->setVisible(true); ui->postText->setVisible(true);
ui->expandButton->setIcon(QIcon(QString(":/images/edit_remove24.png"))); ui->expandButton->setIcon(FilesDefs::getIconFromQtResourcePath(QString(":/images/edit_remove24.png")));
ui->expandButton->setToolTip(tr("Hide")); ui->expandButton->setToolTip(tr("Hide"));
// } else { // } else {
// ui->postText->setVisible(false); // ui->postText->setVisible(false);