diff --git a/retroshare-gui/src/gui/MessagesDialog.cpp b/retroshare-gui/src/gui/MessagesDialog.cpp index 9fd1c7322..2f4410911 100644 --- a/retroshare-gui/src/gui/MessagesDialog.cpp +++ b/retroshare-gui/src/gui/MessagesDialog.cpp @@ -35,7 +35,6 @@ #include #include - #include #include #include @@ -87,7 +86,7 @@ MessagesDialog::MessagesDialog(QWidget *parent) connect(ui.actionIconOnly, SIGNAL(triggered()), this, SLOT(buttonsicononly())); connect(ui.actionTextUnderIcon, SIGNAL(triggered()), this, SLOT(buttonstextundericon())); - + connect(ui.actionSave_as, SIGNAL(triggered()), this, SLOT(fileSaveAs())); mCurrCertId = ""; mCurrMsgId = ""; @@ -192,7 +191,10 @@ void MessagesDialog::messageslistWidgetCostumPopupMenu( QPoint point ) connect( removemsgAct , SIGNAL( triggered() ), this, SLOT( removemessage() ) ); contextMnu.addAction( removemsgAct); } - + contextMnu.addAction( ui.actionSave_as); + contextMnu.addAction( ui.actionPrintPreview); + contextMnu.addAction( ui.actionPrint); + contextMnu.addSeparator(); contextMnu.addAction( newmsgAct); contextMnu.exec( mevent->globalPos() ); } @@ -963,6 +965,39 @@ void MessagesDialog::anchorClicked (const QUrl& link ) } } +bool MessagesDialog::fileSave() +{ + if (fileName.isEmpty()) + return fileSaveAs(); + + QFile file(fileName); + if (!file.open(QFile::WriteOnly)) + return false; + QTextStream ts(&file); + ts.setCodec(QTextCodec::codecForName("UTF-8")); + ts << ui.msgText->document()->toHtml("UTF-8"); + ui.msgText->document()->setModified(false); + return true; +} + +bool MessagesDialog::fileSaveAs() +{ + QString fn = QFileDialog::getSaveFileName(this, tr("Save as..."), + QString(), tr("HTML-Files (*.htm *.html);;All Files (*)")); + if (fn.isEmpty()) + return false; + setCurrentFileName(fn); + return fileSave(); +} + +void MessagesDialog::setCurrentFileName(const QString &fileName) +{ + this->fileName = fileName; + ui.msgText->document()->setModified(false); + + setWindowModified(false); +} + void MessagesDialog::buttonsicononly() { ui.newmessageButton->setToolButtonStyle(Qt::ToolButtonIconOnly); diff --git a/retroshare-gui/src/gui/MessagesDialog.h b/retroshare-gui/src/gui/MessagesDialog.h index 86dcf3082..c0ebdb462 100644 --- a/retroshare-gui/src/gui/MessagesDialog.h +++ b/retroshare-gui/src/gui/MessagesDialog.h @@ -58,6 +58,9 @@ private slots: void print(); void printpreview(); + bool fileSave(); + bool fileSaveAs(); + void removemessage(); void anchorClicked (const QUrl &); @@ -76,6 +79,8 @@ private: bool getCurrentMsg(std::string &cid, std::string &mid); void setMsgAsRead(QTreeWidgetItem *); + + void setCurrentFileName(const QString &fileName); std::string mCurrCertId; std::string mCurrMsgId; @@ -92,6 +97,9 @@ private: QAction* getRecAct; QAction* getAllRecAct; + + QString fileName; + /** Qt Designer generated object */ Ui::MessagesDialog ui; diff --git a/retroshare-gui/src/gui/MessagesDialog.ui b/retroshare-gui/src/gui/MessagesDialog.ui index f3d91a045..e789ef19f 100644 --- a/retroshare-gui/src/gui/MessagesDialog.ui +++ b/retroshare-gui/src/gui/MessagesDialog.ui @@ -550,7 +550,7 @@ border: 1px solid #CCCCCC;} - + 0 0 @@ -772,7 +772,7 @@ p, li { white-space: pre-wrap; } - + 0 0 @@ -816,7 +816,7 @@ p, li { white-space: pre-wrap; } - + 0 0 @@ -1388,12 +1388,15 @@ p, li { white-space: pre-wrap; } - Print + Print... + + + Print... - PrintPreview + Print Preview @@ -1420,6 +1423,11 @@ p, li { white-space: pre-wrap; } Set Text Under Icon + + + Save As... + + newmessageButton