diff --git a/libretroshare/src/rsiface/rsmsgs.h b/libretroshare/src/rsiface/rsmsgs.h index afa00103d..79cd3b0e7 100644 --- a/libretroshare/src/rsiface/rsmsgs.h +++ b/libretroshare/src/rsiface/rsmsgs.h @@ -124,6 +124,8 @@ virtual bool getMessage(std::string mId, MessageInfo &msg) = 0; virtual void getMessageCount(unsigned int *pnInbox, unsigned int *pnInboxNew, unsigned int *pnOutbox, unsigned int *pnDraftbox, unsigned int *pnSentbox) = 0; virtual bool MessageSend(MessageInfo &info) = 0; +virtual bool MessageToDraft(MessageInfo &info) = 0; + virtual bool MessageDelete(std::string mid) = 0; virtual bool MessageRead(std::string mid) = 0; diff --git a/libretroshare/src/rsserver/p3msgs.cc b/libretroshare/src/rsserver/p3msgs.cc index abbabb3a9..0c3a1a1d1 100644 --- a/libretroshare/src/rsserver/p3msgs.cc +++ b/libretroshare/src/rsserver/p3msgs.cc @@ -75,6 +75,11 @@ bool p3Msgs::MessageSend(MessageInfo &info) return mMsgSrv->MessageSend(info); } +bool p3Msgs::MessageToDraft(MessageInfo &info) +{ + return mMsgSrv->MessageToDraft(info); +} + /****************************************/ /****************************************/ bool p3Msgs::MessageDelete(std::string mid) diff --git a/libretroshare/src/rsserver/p3msgs.h b/libretroshare/src/rsserver/p3msgs.h index 65736a2a3..67d41e112 100644 --- a/libretroshare/src/rsserver/p3msgs.h +++ b/libretroshare/src/rsserver/p3msgs.h @@ -57,7 +57,8 @@ class p3Msgs: public RsMsgs virtual bool getMessage(std::string mId, MessageInfo &msg); virtual void getMessageCount(unsigned int *pnInbox, unsigned int *pnInboxNew, unsigned int *pnOutbox, unsigned int *pnDraftbox, unsigned int *pnSentbox); - virtual bool MessageSend(MessageInfo &info); + virtual bool MessageSend(MessageInfo &info); + virtual bool MessageToDraft(MessageInfo &info); virtual bool MessageDelete(std::string mid); virtual bool MessageRead(std::string mid); diff --git a/libretroshare/src/services/p3msgservice.cc b/libretroshare/src/services/p3msgservice.cc index d255ab427..f4650a1a6 100644 --- a/libretroshare/src/services/p3msgservice.cc +++ b/libretroshare/src/services/p3msgservice.cc @@ -264,9 +264,6 @@ int p3MsgService::checkOutgoingMessages() bool p3MsgService::saveConfiguration() { - std::list::iterator it; - std::string empty(""); - pqioutput(PQL_DEBUG_BASIC, msgservicezone, "p3MsgService::save_config()"); @@ -309,8 +306,6 @@ bool p3MsgService::saveConfiguration() bool p3MsgService::loadConfiguration(std::string &loadHash) { - std::list::iterator it; - std::string msgfile = Filename(); RsSerialiser *rss = new RsSerialiser(); @@ -659,6 +654,51 @@ bool p3MsgService::MessageSend(MessageInfo &info) return true; } +bool p3MsgService::MessageToDraft(MessageInfo &info) +{ + RsMsgItem *msg = initMIRsMsg(info, mConnMgr->getOwnId()); + if (msg) + { + uint32_t msgId = 0; + if (info.msgId.empty() == false) { + std::istringstream instream(info.msgId); + instream >> msgId; + } + + if (msgId) { + msg->msgId = msgId; + } else { + msg->msgId = getNewUniqueMsgId(); /* grabs Mtx as well */ + } + + { + RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/ + + /* add pending flag */ + msg->msgFlags |= (RS_MSG_OUTGOING | RS_MSG_FLAGS_DRAFT); + + if (msgId) { + // remove existing message + RsMsgItem *existingMsg = imsg[msgId]; + if (existingMsg) { + delete (existingMsg); + } + imsg.erase(msgId); + } + /* STORE MsgID */ + imsg[msg->msgId] = msg; + } + + IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/ + + rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_MOD); + + return true; + } + + return false; +} + /****************************************/ /****************************************/ @@ -686,7 +726,11 @@ void p3MsgService::initRsMI(RsMsgItem *msg, MessageInfo &mi) { mi.msgflags |= RS_MSG_PENDING; } - if (msg->msgFlags & RS_MSG_FLAGS_NEW) + if (msg->msgFlags & RS_MSG_FLAGS_DRAFT) + { + mi.msgflags |= RS_MSG_DRAFT; + } + if (msg->msgFlags & RS_MSG_FLAGS_NEW) { mi.msgflags |= RS_MSG_NEW; } @@ -761,7 +805,11 @@ void p3MsgService::initRsMIS(RsMsgItem *msg, MsgInfoSummary &mis) { mis.msgflags |= RS_MSG_PENDING; } - if (msg->msgFlags & RS_MSG_FLAGS_NEW) + if (msg->msgFlags & RS_MSG_FLAGS_DRAFT) + { + mis.msgflags |= RS_MSG_DRAFT; + } + if (msg->msgFlags & RS_MSG_FLAGS_NEW) { mis.msgflags |= RS_MSG_NEW; } diff --git a/libretroshare/src/services/p3msgservice.h b/libretroshare/src/services/p3msgservice.h index a1d5e3b27..3284c1f78 100644 --- a/libretroshare/src/services/p3msgservice.h +++ b/libretroshare/src/services/p3msgservice.h @@ -63,6 +63,7 @@ bool removeMsgId(std::string mid); bool markMsgIdRead(std::string mid); bool MessageSend(MessageInfo &info); +bool MessageToDraft(MessageInfo &info); diff --git a/retroshare-gui/src/gui/ForumsDialog.cpp b/retroshare-gui/src/gui/ForumsDialog.cpp index 2e31e76a7..fa87861e0 100644 --- a/retroshare-gui/src/gui/ForumsDialog.cpp +++ b/retroshare-gui/src/gui/ForumsDialog.cpp @@ -1344,7 +1344,7 @@ void ForumsDialog::replytomessage() if (rsPeers->getPeerName(msgInfo.srcId) !="") { - MessageComposer *nMsgDialog = new MessageComposer(true); + MessageComposer *nMsgDialog = new MessageComposer(); nMsgDialog->newMsg(); nMsgDialog->insertTitleText( (QString("Re: ") + QString::fromStdWString(msgInfo.title)).toStdString()) ; nMsgDialog->setWindowTitle(tr("Re: ") + QString::fromStdWString(msgInfo.title) ) ; diff --git a/retroshare-gui/src/gui/MessagesDialog.cpp b/retroshare-gui/src/gui/MessagesDialog.cpp index 949df1d0f..e7f89e430 100644 --- a/retroshare-gui/src/gui/MessagesDialog.cpp +++ b/retroshare-gui/src/gui/MessagesDialog.cpp @@ -133,6 +133,7 @@ MessagesDialog::MessagesDialog(QWidget *parent) connect( ui.messagestreeView, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( messageslistWidgetCostumPopupMenu( QPoint ) ) ); connect( ui.msgList, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( msgfilelistWidgetCostumPopupMenu( QPoint ) ) ); connect( ui.messagestreeView, SIGNAL(clicked ( const QModelIndex &) ) , this, SLOT( clicked( const QModelIndex & ) ) ); + connect( ui.messagestreeView, SIGNAL(doubleClicked ( const QModelIndex& ) ) , this, SLOT( doubleClicked( const QModelIndex & ) ) ); connect( ui.listWidget, SIGNAL( currentRowChanged ( int) ), this, SLOT( changeBox ( int) ) ); connect(ui.newmessageButton, SIGNAL(clicked()), this, SLOT(newmessage())); @@ -475,7 +476,7 @@ void MessagesDialog::msgfilelistWidgetCostumPopupMenu( QPoint point ) void MessagesDialog::newmessage() { - MessageComposer *nMsgDialog = new MessageComposer(true); + MessageComposer *nMsgDialog = new MessageComposer(); /* fill it in */ //std::cerr << "MessagesDialog::newmessage()" << std::endl; @@ -504,7 +505,7 @@ void MessagesDialog::replytomessage() if (!rsMsgs -> getMessage(mid, msgInfo)) return ; - MessageComposer *nMsgDialog = new MessageComposer(true); + MessageComposer *nMsgDialog = new MessageComposer(); /* fill it in */ //std::cerr << "MessagesDialog::newmessage()" << std::endl; nMsgDialog->newMsg(); @@ -552,7 +553,7 @@ void MessagesDialog::replyallmessage() if (!rsMsgs -> getMessage(mid, msgInfo)) return ; - MessageComposer *nMsgDialog = new MessageComposer(true); + MessageComposer *nMsgDialog = new MessageComposer(); /* fill it in */ //std::cerr << "MessagesDialog::newmessage()" << std::endl; nMsgDialog->newMsg(); @@ -607,7 +608,7 @@ void MessagesDialog::forwardmessage() if (!rsMsgs -> getMessage(mid, msgInfo)) return ; - MessageComposer *nMsgDialog = new MessageComposer(true); + MessageComposer *nMsgDialog = new MessageComposer(); /* fill it in */ //std::cerr << "MessagesDialog::newmessage()" << std::endl; nMsgDialog->newMsg(); @@ -978,7 +979,7 @@ void MessagesDialog::insertMessages() // From .... { - if (msgbox == RS_MSG_INBOX) { + if (msgbox == RS_MSG_INBOX || msgbox == RS_MSG_OUTBOX) { text = QString::fromStdString(rsPeers->getPeerName(it->srcId)); } else { if (bGotInfo || rsMsgs->getMessage(it->msgId, msgInfo)) { @@ -1098,6 +1099,40 @@ void MessagesDialog::clicked(const QModelIndex &index ) updateCurrentMessage(); } +// 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! */ + +} + // show current message directly void MessagesDialog::updateCurrentMessage() { @@ -1316,8 +1351,16 @@ void MessagesDialog::insertMsgTxtAndFiles(QModelIndex Index, bool bSetToRead) ui.dateText-> setText(timestamp); } ui.toText->setText(msgTxt); - ui.fromText->setText(" " + QString::fromStdString(rsPeers->getPeerName(msgInfo.srcId)) +""); - ui.fromText->setToolTip(QString::fromStdString(rsPeers->getPeerName(msgInfo.srcId)) + "@" + QString::fromStdString(msgInfo.srcId)); + + std::string sSrcId; + if ((msgInfo.msgflags & RS_MSG_BOXMASK) == RS_MSG_OUTBOX) { + // outgoing message are from me + sSrcId = rsPeers->getOwnId(); + } else { + sSrcId = msgInfo.srcId; + } + ui.fromText->setText(" " + QString::fromStdString(rsPeers->getPeerName(sSrcId)) +""); + ui.fromText->setToolTip(QString::fromStdString(rsPeers->getPeerName(sSrcId)) + "@" + QString::fromStdString(sSrcId)); ui.subjectText->setText(QString::fromStdWString(msgInfo.title)); ui.msgText->setHtml(QString::fromStdWString(msgInfo.msg)); diff --git a/retroshare-gui/src/gui/MessagesDialog.h b/retroshare-gui/src/gui/MessagesDialog.h index e00678a98..605dbb4a3 100644 --- a/retroshare-gui/src/gui/MessagesDialog.h +++ b/retroshare-gui/src/gui/MessagesDialog.h @@ -63,6 +63,7 @@ private slots: void updateCurrentMessage(); void currentChanged(const QModelIndex&); void clicked(const QModelIndex&); + void doubleClicked(const QModelIndex &); void newmessage(); diff --git a/retroshare-gui/src/gui/MessengerWindow.cpp b/retroshare-gui/src/gui/MessengerWindow.cpp index bd49b8dc1..a9456ce2a 100644 --- a/retroshare-gui/src/gui/MessengerWindow.cpp +++ b/retroshare-gui/src/gui/MessengerWindow.cpp @@ -846,7 +846,7 @@ void MessengerWindow::sendMessage() } /* create a message */ - MessageComposer *nMsgDialog = new MessageComposer(true); + MessageComposer *nMsgDialog = new MessageComposer(); nMsgDialog->newMsg(); nMsgDialog->show(); diff --git a/retroshare-gui/src/gui/PeersDialog.cpp b/retroshare-gui/src/gui/PeersDialog.cpp index d06351a63..dd265c6f7 100644 --- a/retroshare-gui/src/gui/PeersDialog.cpp +++ b/retroshare-gui/src/gui/PeersDialog.cpp @@ -712,7 +712,7 @@ void PeersDialog::msgfriend() } /* create a message */ - MessageComposer *nMsgDialog = new MessageComposer(true); + MessageComposer *nMsgDialog = new MessageComposer(); nMsgDialog->newMsg(); nMsgDialog->show(); diff --git a/retroshare-gui/src/gui/SearchDialog.cpp b/retroshare-gui/src/gui/SearchDialog.cpp index f4ec1f4d5..91a08773a 100644 --- a/retroshare-gui/src/gui/SearchDialog.cpp +++ b/retroshare-gui/src/gui/SearchDialog.cpp @@ -1194,7 +1194,7 @@ void SearchDialog::sendLinkTo( ) copysearchLink(); /* create a message */ - MessageComposer *nMsgDialog = new MessageComposer(true); + MessageComposer *nMsgDialog = new MessageComposer(); nMsgDialog->newMsg(); nMsgDialog->insertTitleText("New RetroShare Link(s)"); diff --git a/retroshare-gui/src/gui/SharedFilesDialog.cpp b/retroshare-gui/src/gui/SharedFilesDialog.cpp index cd878c6db..8b4b383b0 100644 --- a/retroshare-gui/src/gui/SharedFilesDialog.cpp +++ b/retroshare-gui/src/gui/SharedFilesDialog.cpp @@ -334,7 +334,7 @@ void SharedFilesDialog::sendremoteLinkTo() copyLinkRemote (); /* create a message */ - MessageComposer *nMsgDialog = new MessageComposer(true); + MessageComposer *nMsgDialog = new MessageComposer(); /* fill it in * files are receommended already @@ -355,7 +355,7 @@ void SharedFilesDialog::sendLinkTo() copyLinkLocal (); /* create a message */ - MessageComposer *nMsgDialog = new MessageComposer(true); + MessageComposer *nMsgDialog = new MessageComposer(); /* fill it in @@ -378,7 +378,7 @@ void SharedFilesDialog::sendHtmlLinkTo( ) copyLinkLocal (); /* create a message */ - MessageComposer *nMsgDialog = new MessageComposer(true); + MessageComposer *nMsgDialog = new MessageComposer(); /* fill it in * files are receommended already @@ -517,7 +517,7 @@ void SharedFilesDialog::recommendFilesTo( std::string rsid ) return ; /* create a message */ - MessageComposer *nMsgDialog = new MessageComposer(true); + MessageComposer *nMsgDialog = new MessageComposer(); /* fill it in * files are receommended already @@ -547,7 +547,7 @@ void SharedFilesDialog::recommendFilesToMsg( std::string rsid ) /* create a message */ - MessageComposer *nMsgDialog = new MessageComposer(true); + MessageComposer *nMsgDialog = new MessageComposer(); nMsgDialog->insertFileList(files_info) ; nMsgDialog->newMsg(); diff --git a/retroshare-gui/src/gui/feeds/MsgItem.cpp b/retroshare-gui/src/gui/feeds/MsgItem.cpp index a0961bf10..0fc6d50ae 100644 --- a/retroshare-gui/src/gui/feeds/MsgItem.cpp +++ b/retroshare-gui/src/gui/feeds/MsgItem.cpp @@ -254,7 +254,7 @@ void MsgItem::replyMsg() if (!rsMsgs -> getMessage(mMsgId, msgInfo)) return ; - MessageComposer *nMsgDialog = new MessageComposer(true); + MessageComposer *nMsgDialog = new MessageComposer(); nMsgDialog->newMsg(); nMsgDialog->insertTitleText( (QString("Re: ") + QString::fromStdWString(msgInfo.title)).toStdString()) ; nMsgDialog->setWindowTitle(tr("Re: ") + QString::fromStdWString(msgInfo.title) ) ; diff --git a/retroshare-gui/src/gui/feeds/PeerItem.cpp b/retroshare-gui/src/gui/feeds/PeerItem.cpp index 7608818c4..0ca24b8ef 100644 --- a/retroshare-gui/src/gui/feeds/PeerItem.cpp +++ b/retroshare-gui/src/gui/feeds/PeerItem.cpp @@ -294,7 +294,7 @@ void PeerItem::sendMsg() { //mParent->openMsg(FEEDHOLDER_MSG_MESSAGE, mPeerId, ""); - MessageComposer *nMsgDialog = new MessageComposer(true); + MessageComposer *nMsgDialog = new MessageComposer(); nMsgDialog->newMsg(); nMsgDialog->addRecipient( mPeerId ) ; diff --git a/retroshare-gui/src/gui/msgs/MessageComposer.cpp b/retroshare-gui/src/gui/msgs/MessageComposer.cpp index 9b77fafaf..2469a96e5 100644 --- a/retroshare-gui/src/gui/msgs/MessageComposer.cpp +++ b/retroshare-gui/src/gui/msgs/MessageComposer.cpp @@ -37,8 +37,8 @@ /** Constructor */ -MessageComposer::MessageComposer(bool msg, QWidget *parent, Qt::WFlags flags) -: QMainWindow(parent, flags), mIsMsg(msg), mCheckAttachment(true) +MessageComposer::MessageComposer(QWidget *parent, Qt::WFlags flags) +: QMainWindow(parent, flags), mCheckAttachment(true) { /* Invoke the Qt Designer generated object setup routine */ ui.setupUi(this); @@ -108,17 +108,7 @@ MessageComposer::MessageComposer(bool msg, QWidget *parent, Qt::WFlags flags) connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(clipboardDataChanged())); - /* if Msg */ - if (mIsMsg) - { - connect(ui.msgSendList, SIGNAL(itemChanged( QTreeWidgetItem *, int ) ), - this, SLOT(togglePersonItem( QTreeWidgetItem *, int ) )); - } - else - { - connect(ui.msgSendList, SIGNAL(itemChanged( QTreeWidgetItem *, int ) ), - this, SLOT(toggleChannelItem( QTreeWidgetItem *, int ) )); - } + connect(ui.msgSendList, SIGNAL(itemChanged( QTreeWidgetItem *, int ) ), this, SLOT(togglePersonItem( QTreeWidgetItem *, int ) )); connect(ui.msgFileList, SIGNAL(itemChanged( QTreeWidgetItem *, int ) ), this, SLOT(toggleRecommendItem( QTreeWidgetItem *, int ) )); @@ -202,34 +192,41 @@ MessageComposer::MessageComposer(bool msg, QWidget *parent, Qt::WFlags flags) void MessageComposer::closeEvent (QCloseEvent * event) { - //=== uncheck all repecient's boxes ======= - QTreeWidget *sendWidget = ui.msgSendList; + bool bClose = true; - for(int i=0;itopLevelItemCount();++i) - sendWidget->topLevelItem(i)->setCheckState(0,Qt::Unchecked) ; + /* Save to Drafts? */ - - event->accept(); - return; - - /* We can save to Drafts.... but we'll do this later. - * ... no auto saving for the moment, - */ - -#if 0 - if (maybeSave()) - { - event->accept(); + if (ui.msgText->document()->isModified()) { + QMessageBox::StandardButton ret; + ret = QMessageBox::warning(this, tr("Save Message"), + tr("Message has not been Sent.\n" + "Do you want to save message to draft box?"), + QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel); + switch (ret) { + case QMessageBox::Yes: + sendMessage_internal(true); + break; + case QMessageBox::Cancel: + bClose = false; + break; + default: + break; + } } - else - { - event->ignore(); - hide(); - - Settings->saveWidgetInformation(this); - } -#endif + if (bClose) { + Settings->saveWidgetInformation(this); + + //=== uncheck all repecient's boxes ======= + QTreeWidget *sendWidget = ui.msgSendList; + + for (int i=0;itopLevelItemCount();++i) + sendWidget->topLevelItem(i)->setCheckState(0,Qt::Unchecked) ; + + QMainWindow::closeEvent(event); + } else { + event->ignore(); + } } void MessageComposer::insertSendList() @@ -304,75 +301,6 @@ void MessageComposer::insertSendList() } -void MessageComposer::insertChannelSendList() -{ -#if 0 - rsiface->lockData(); /* Lock Interface */ - - std::map::const_iterator it; - const std::map &chans = - rsiface->getChannels(); - - /* get a link to the table */ - QTreeWidget *sendWidget = ui.msgSendList; - - /* remove old items ??? */ - sendWidget->clear(); - sendWidget->setColumnCount(4); - - QList items; - for(it = chans.begin(); it != chans.end(); it++) - { - /* make a widget per friend */ - QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget*)0); - - /* (0) Title */ - item -> setText(0, QString::fromStdString(it->second.chanName)); - if (it->second.publisher) - { - item -> setText(1, "Publisher"); - } - else - { - item -> setText(1, "Listener"); - } - - { - std::ostringstream out; - out << it->second.chanId; - item -> setText(2, QString::fromStdString(out.str())); - } - - item -> setText(3, "Channel"); - - item -> setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled); - item -> setCheckState(0, Qt::Unchecked); - - if (it -> second.inBroadcast) - { - item -> setCheckState(0, Qt::Checked); - } - else - { - item -> setCheckState(0, Qt::Unchecked); - } - - /* add to the list */ - items.append(item); - } - - /* add the items in! */ - sendWidget->insertTopLevelItems(0, items); - - - rsiface->unlockData(); /* UnLock Interface */ - - sendWidget->update(); /* update display */ -#endif -} - - - /* Utility Fns */ /*** RsCertId getSenderRsCertId(QTreeWidgetItem *i) @@ -446,27 +374,44 @@ void MessageComposer::insertFileList(const std::list& files_info) tree->update(); /* update display */ } -void MessageComposer::newMsg() +void MessageComposer::newMsg(std::string msgId /*= ""*/) { - /* clear all */ - QString titlestring = ui.titleEdit->text(); + /* clear all */ + QString titlestring = ui.titleEdit->text(); - setWindowTitle(tr("Compose: ") + titlestring ); - ui.titleEdit->setText("No Title"); + setWindowTitle(tr("Compose: ") + titlestring ); + ui.titleEdit->setText("No Title"); - ui.msgText->setText(""); + ui.msgText->setText(""); - /* worker fns */ - if (mIsMsg) - { - insertSendList(); - } - else - { - insertChannelSendList(); - } + /* worker fns */ + insertSendList(); -// insertFileList(std::list()); + m_sMsgId = msgId; + + if (m_sMsgId.empty() == false) { + // fill existing message + MessageInfo msgInfo; + if (!rsMsgs->getMessage(m_sMsgId, msgInfo)) { + std::cerr << "MessageComposer::newMsg() Couldn't find Msg" << std::endl; + m_sMsgId.clear(); + return; + } + + insertTitleText( QString::fromStdWString(msgInfo.title).toStdString()); + setWindowTitle( tr ("Compose: ") + QString::fromStdWString(msgInfo.title)); + + insertMsgText(QString::fromStdWString(msgInfo.msg).toStdString()); + + insertFileList(msgInfo.files); + + std::list::iterator to; + for (to = msgInfo.msgto.begin(); to != msgInfo.msgto.end(); to++ ) { + addRecipient(*to) ; + } + + ui.msgText->document()->setModified(false); + } } void MessageComposer::insertTitleText(std::string title) @@ -476,91 +421,102 @@ void MessageComposer::insertTitleText(std::string title) void MessageComposer::insertPastedText(std::string msg) { - std::string::size_type i=0 ; - while( (i=msg.find_first_of('\n',i+1)) < msg.size()) - msg.replace(i,1,std::string("\n
> ")) ; + std::string::size_type i=0 ; + while( (i=msg.find_first_of('\n',i+1)) < msg.size()) + msg.replace(i,1,std::string("\n
> ")) ; - ui.msgText->setHtml(QString("")+QString::fromStdString(std::string("> ") + msg)+"

") ; - - ui.msgText->setFocus( Qt::OtherFocusReason ); - - QTextCursor c = ui.msgText->textCursor(); - c.movePosition(QTextCursor::End); - ui.msgText->setTextCursor(c); + ui.msgText->setHtml(QString("")+QString::fromStdString(std::string("> ") + msg)+"

") ; + + ui.msgText->setFocus( Qt::OtherFocusReason ); + + QTextCursor c = ui.msgText->textCursor(); + c.movePosition(QTextCursor::End); + ui.msgText->setTextCursor(c); + + ui.msgText->document()->setModified(true); } void MessageComposer::insertForwardPastedText(std::string msg) { - std::string::size_type i=0 ; - while( (i=msg.find_first_of('\n',i+1)) < msg.size()) - msg.replace(i,1,std::string("\n
> ")) ; + std::string::size_type i=0 ; + while( (i=msg.find_first_of('\n',i+1)) < msg.size()) + msg.replace(i,1,std::string("\n
> ")) ; - ui.msgText->setHtml(QString("
")+QString::fromStdString(std::string("") + msg)+"

") ; - - ui.msgText->setFocus( Qt::OtherFocusReason ); - - QTextCursor c = ui.msgText->textCursor(); - c.movePosition(QTextCursor::End); - ui.msgText->setTextCursor(c); + ui.msgText->setHtml(QString("
")+QString::fromStdString(std::string("") + msg)+"

") ; + + ui.msgText->setFocus( Qt::OtherFocusReason ); + + QTextCursor c = ui.msgText->textCursor(); + c.movePosition(QTextCursor::End); + ui.msgText->setTextCursor(c); + + ui.msgText->document()->setModified(true); } void MessageComposer::insertMsgText(std::string msg) { - ui.msgText->setText(QString::fromStdString(msg)); - - ui.msgText->setFocus( Qt::OtherFocusReason ); - - QTextCursor c = ui.msgText->textCursor(); - c.movePosition(QTextCursor::End); - ui.msgText->setTextCursor(c); + ui.msgText->setText(QString::fromStdString(msg)); + + ui.msgText->setFocus( Qt::OtherFocusReason ); + + QTextCursor c = ui.msgText->textCursor(); + c.movePosition(QTextCursor::End); + ui.msgText->setTextCursor(c); + + ui.msgText->document()->setModified(true); } void MessageComposer::insertHtmlText(std::string msg) { - ui.msgText->setHtml(QString(" ") ) + QString::fromStdString(std::string(msg)) + "") ; - -} + ui.msgText->setHtml(QString(" ") ) + QString::fromStdString(std::string(msg)) + "") ; + ui.msgText->document()->setModified(true); +} void MessageComposer::sendMessage() { - /* construct a message */ - MessageInfo mi; - - mi.title = ui.titleEdit->text().toStdWString(); - mi.msg = ui.msgText->toHtml().toStdWString(); - - - rsiface->lockData(); /* Lock Interface */ - -// const std::list& recList = rsiface->getRecommendList(); - for(std::list::const_iterator it(_recList.begin()); it != _recList.end(); ++it) - if (it -> inRecommend) - mi.files.push_back(*it); - - rsiface->unlockData(); /* UnLock Interface */ - - /* get the ids from the send list */ - std::list peers; - std::list msgto; - std::list::iterator iit; - - rsPeers->getFriendList(peers); - - for(iit = peers.begin(); iit != peers.end(); iit++) - { - if (rsicontrol->IsInMsg(*iit)) - { - mi.msgto.push_back(*iit); - } - } - - rsMsgs->MessageSend(mi); - - close(); - return; + sendMessage_internal(false); + close(); } +void MessageComposer::sendMessage_internal(bool bDraftbox) +{ + /* construct a message */ + MessageInfo mi; + + mi.title = ui.titleEdit->text().toStdWString(); + mi.msg = ui.msgText->toHtml().toStdWString(); + + rsiface->lockData(); /* Lock Interface */ + +// const std::list& recList = rsiface->getRecommendList(); + for(std::list::const_iterator it(_recList.begin()); it != _recList.end(); ++it) + if (it -> inRecommend) + mi.files.push_back(*it); + + rsiface->unlockData(); /* UnLock Interface */ + + /* get the ids from the send list */ + std::list peers; + std::list::iterator iit; + + rsPeers->getFriendList(peers); + + for(iit = peers.begin(); iit != peers.end(); iit++) { + if (rsicontrol->IsInMsg(*iit)) { + mi.msgto.push_back(*iit); + } + } + + if (bDraftbox) { + mi.msgId = m_sMsgId; + rsMsgs->MessageToDraft(mi); + } else { + rsMsgs->MessageSend(mi); + } + + ui.msgText->document()->setModified(false); +} void MessageComposer::cancelMessage() { @@ -604,24 +560,6 @@ void MessageComposer::togglePersonItem( QTreeWidgetItem *item, int col ) return; } -/* Second the Channel ones */ -void MessageComposer::toggleChannelItem( QTreeWidgetItem *item, int col ) -{ - //std::cerr << "ToggleChannelItem()" << std::endl; - - /* extract id */ - std::string id = (item -> text(2)).toStdString(); - - /* get state */ - bool inBroad = (Qt::Checked == item -> checkState(0)); /* alway column 0 */ - - /* call control fns */ - - rsicontrol -> SetInBroadcast(id, inBroad); - return; -} - -/* This is actually for both */ void MessageComposer::toggleRecommendItem( QTreeWidgetItem *item, int col ) { //std::cerr << "ToggleRecommendItem()" << std::endl; diff --git a/retroshare-gui/src/gui/msgs/MessageComposer.h b/retroshare-gui/src/gui/msgs/MessageComposer.h index 45802995f..1ab137145 100644 --- a/retroshare-gui/src/gui/msgs/MessageComposer.h +++ b/retroshare-gui/src/gui/msgs/MessageComposer.h @@ -44,15 +44,13 @@ class MessageComposer : public QMainWindow public: /** Default Constructor */ - MessageComposer(bool isMsg, QWidget *parent = 0, Qt::WFlags flags = 0); - /** Default Destructor */ + MessageComposer(QWidget *parent = 0, Qt::WFlags flags = 0); - void newMsg(); + void newMsg(std::string msgId = ""); /* worker fns */ - void insertSendList(); /* for Msgs */ - void insertChannelSendList(); /* for Channels */ - void insertFileList(const std::list&); /* for Both */ + void insertSendList(); + void insertFileList(const std::list&); void insertFileList(const std::list&); void insertTitleText(std::string title); void insertPastedText(std::string msg) ; @@ -80,7 +78,6 @@ private slots: /* for toggling flags */ void togglePersonItem( QTreeWidgetItem *item, int col ); - void toggleChannelItem( QTreeWidgetItem *item, int col ); void toggleRecommendItem( QTreeWidgetItem *item, int col ); void fileNew(); @@ -136,6 +133,8 @@ private: void colorChanged(const QColor &c); void alignmentChanged(Qt::Alignment a); + void sendMessage_internal(bool bDraftbox); + /** Define the popup menus for the Context menu */ QMenu* contextMnu; @@ -165,11 +164,12 @@ private: QHash autoLinkDictionary; QHash autoLinkTitleDictionary; QHash autoLinkTargetDictionary; - - /* maps of files */ - std::list mAttachments; - bool mIsMsg; /* different behaviour for Msg or ChanMsg */ + std::string m_sMsgId; // exisiting message + + /* maps of files */ + std::list mAttachments; + bool mCheckAttachment; /** Qt Designer generated object */