From 5b1fae0123a21b0e62425128617bc2bc61f91918 Mon Sep 17 00:00:00 2001 From: thunder2 Date: Mon, 14 Jun 2010 18:16:32 +0000 Subject: [PATCH] all messages in MessagesDialog are now editable from context menu or with double click changes from defnax with some corrections from me git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3135 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/gui/MessagesDialog.cpp | 72 +++++++++++-------- retroshare-gui/src/gui/MessagesDialog.h | 1 + .../src/gui/msgs/MessageComposer.cpp | 12 +++- retroshare-gui/src/gui/msgs/MessageComposer.h | 3 +- 4 files changed, 54 insertions(+), 34 deletions(-) diff --git a/retroshare-gui/src/gui/MessagesDialog.cpp b/retroshare-gui/src/gui/MessagesDialog.cpp index 96a7f701d..6f40ddf15 100644 --- a/retroshare-gui/src/gui/MessagesDialog.cpp +++ b/retroshare-gui/src/gui/MessagesDialog.cpp @@ -755,12 +755,22 @@ void MessagesDialog::messageslistWidgetCostumPopupMenu( QPoint point ) connect( forwardmsgAct , SIGNAL( triggered() ), this, SLOT( forwardmessage() ) ); contextMnu.addAction( forwardmsgAct); - contextMnu.addSeparator(); - QList RowsRead; QList RowsUnread; int nCount = getSelectedMsgCount (NULL, &RowsRead, &RowsUnread); + QAction *editAct = new QAction(tr( "Edit..." ), this ); + connect(editAct, SIGNAL(triggered()), this, SLOT(editmessage())); + contextMnu.addAction(editAct); + + if (nCount == 1) { + editAct->setEnabled(true); + } else { + editAct->setDisabled(true); + } + + contextMnu.addSeparator(); + QAction *markAsRead = new QAction(QIcon(":/images/message-mail-read.png"), tr( "Mark as read" ), this); connect(markAsRead , SIGNAL(triggered()), this, SLOT(markAsRead())); contextMnu.addAction(markAsRead); @@ -782,7 +792,7 @@ void MessagesDialog::messageslistWidgetCostumPopupMenu( QPoint point ) contextMnu.addSeparator(); QAction *removemsgAct; - if (nCount > 1) { + if (nCount > 1) { removemsgAct = new QAction(QIcon(IMAGE_MESSAGEREMOVE), tr( "Remove Messages" ), this ); } else { removemsgAct = new QAction(QIcon(IMAGE_MESSAGEREMOVE), tr( "Remove Message" ), this ); @@ -858,6 +868,30 @@ void MessagesDialog::newmessage() /* window will destroy itself! */ } +void MessagesDialog::editmessage() +{ + std::string cid; + std::string mid; + + if(!getCurrentMsg(cid, mid)) + return ; + + MessageInfo msgInfo; + if (!rsMsgs->getMessage(mid, msgInfo)) { + std::cerr << "MessagesDialog::editmessage() Couldn't find Msg" << std::endl; + return; + } + + MessageComposer *pMsgDialog = new MessageComposer(); + /* fill it in */ + pMsgDialog->newMsg(msgInfo.msgId); + + pMsgDialog->show(); + pMsgDialog->activateWindow(); + + /* window will destroy itself! */ +} + void MessagesDialog::replytomessage() { /* put msg on msgBoard, and switch to it. */ @@ -1594,35 +1628,11 @@ void MessagesDialog::clicked(const QModelIndex &index ) // double click in messagestreeView void MessagesDialog::doubleClicked(const QModelIndex &index) { - int mappedRow = proxyModel->mapToSource(index).row(); - - QStandardItem *pItem = MessagesModel->item(mappedRow, COLUMN_MSGID); - if (pItem == NULL) { - return; - } - - std::string mid = pItem->text().toStdString(); - - MessageInfo msgInfo; - if (!rsMsgs->getMessage(mid, msgInfo)) { - std::cerr << "MessagesDialog::doubleClicked() Couldn't find Msg" << std::endl; - return; - } - - if ((msgInfo.msgflags & RS_MSG_BOXMASK) != RS_MSG_DRAFTBOX) { - // only draft box for now - return; - } - - MessageComposer *pMsgDialog = new MessageComposer(); - /* fill it in */ - pMsgDialog->newMsg(msgInfo.msgId); - - pMsgDialog->show(); - pMsgDialog->activateWindow(); - - /* window will destroy itself! */ + /* activate row */ + clicked (index); + /* edit message */ + editmessage(); } // show current message directly diff --git a/retroshare-gui/src/gui/MessagesDialog.h b/retroshare-gui/src/gui/MessagesDialog.h index f44b71f22..d88534d26 100644 --- a/retroshare-gui/src/gui/MessagesDialog.h +++ b/retroshare-gui/src/gui/MessagesDialog.h @@ -73,6 +73,7 @@ private slots: void doubleClicked(const QModelIndex &); void newmessage(); + void editmessage(); void replytomessage(); void replyallmessage(); diff --git a/retroshare-gui/src/gui/msgs/MessageComposer.cpp b/retroshare-gui/src/gui/msgs/MessageComposer.cpp index fb18340e5..3b807b44a 100644 --- a/retroshare-gui/src/gui/msgs/MessageComposer.cpp +++ b/retroshare-gui/src/gui/msgs/MessageComposer.cpp @@ -43,7 +43,9 @@ MessageComposer::MessageComposer(QWidget *parent, Qt::WFlags flags) { /* Invoke the Qt Designer generated object setup routine */ ui.setupUi(this); - + + m_nBox = -1; // not defined + setupFileActions(); setupEditActions(); setupViewActions(); @@ -397,6 +399,7 @@ void MessageComposer::newMsg(std::string msgId /*= ""*/) insertSendList(); m_sMsgId = msgId; + m_nBox = -1; // not defined if (m_sMsgId.empty() == false) { // fill existing message @@ -407,6 +410,8 @@ void MessageComposer::newMsg(std::string msgId /*= ""*/) return; } + m_nBox = msgInfo.msgflags & RS_MSG_BOXMASK; + insertTitleText( QString::fromStdWString(msgInfo.title).toStdString()); setWindowTitle( tr ("Compose: ") + QString::fromStdWString(msgInfo.title)); @@ -518,7 +523,10 @@ void MessageComposer::sendMessage_internal(bool bDraftbox) } if (bDraftbox) { - mi.msgId = m_sMsgId; + if (m_nBox != -1 && (m_nBox & RS_MSG_DRAFTBOX) == RS_MSG_DRAFTBOX) { + // only save draft box to draft box again, for all other message create a new one in draft box + mi.msgId = m_sMsgId; + } rsMsgs->MessageToDraft(mi); } else { rsMsgs->MessageSend(mi); diff --git a/retroshare-gui/src/gui/msgs/MessageComposer.h b/retroshare-gui/src/gui/msgs/MessageComposer.h index 3aed675ce..5bc4c8ff1 100644 --- a/retroshare-gui/src/gui/msgs/MessageComposer.h +++ b/retroshare-gui/src/gui/msgs/MessageComposer.h @@ -175,7 +175,8 @@ private: QHash autoLinkTitleDictionary; QHash autoLinkTargetDictionary; - std::string m_sMsgId; // exisiting message + std::string m_sMsgId; // existing message id + int m_nBox; // box from the existing message /* maps of files */ std::list mAttachments;