diff --git a/retroshare-gui/src/gui/PeersDialog.cpp b/retroshare-gui/src/gui/PeersDialog.cpp index dfae36f95..2ea77f757 100644 --- a/retroshare-gui/src/gui/PeersDialog.cpp +++ b/retroshare-gui/src/gui/PeersDialog.cpp @@ -156,6 +156,7 @@ PeersDialog::PeersDialog(QWidget *parent) connect(ui.textitalicChatButton, SIGNAL(clicked()), this, SLOT(setFont())); connect(ui.fontsButton, SIGNAL(clicked()), this, SLOT(getFont())); connect(ui.colorChatButton, SIGNAL(clicked()), this, SLOT(setColor())); + connect(ui.actionSave_History, SIGNAL(triggered()), this, SLOT(fileSaveAs())); ui.fontsButton->setIcon(QIcon(QString(":/images/fonts.png"))); @@ -179,6 +180,7 @@ PeersDialog::PeersDialog(QWidget *parent) QMenu * grpchatmenu = new QMenu(); grpchatmenu->addAction(ui.actionClearChat); + grpchatmenu->addAction(ui.actionSave_History); grpchatmenu->addAction(ui.actionDisable_Emoticons); ui.menuButton->setMenu(grpchatmenu); @@ -1789,3 +1791,36 @@ void PeersDialog::dragEnterEvent(QDragEnterEvent *event) std::cerr << "PeersDialog::dragEnterEvent() No Urls" << std::endl; } } + +bool PeersDialog::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()->toPlainText(); + ui.msgText->document()->setModified(false); + return true; +} + +bool PeersDialog::fileSaveAs() +{ + QString fn = QFileDialog::getSaveFileName(this, tr("Save as..."), + QString(), tr("Text File (*.txt );;All Files (*)")); + if (fn.isEmpty()) + return false; + setCurrentFileName(fn); + return fileSave(); +} + +void PeersDialog::setCurrentFileName(const QString &fileName) +{ + this->fileName = fileName; + ui.msgText->document()->setModified(false); + + setWindowModified(false); +} \ No newline at end of file diff --git a/retroshare-gui/src/gui/PeersDialog.h b/retroshare-gui/src/gui/PeersDialog.h index a4325e1be..1f5c70c68 100644 --- a/retroshare-gui/src/gui/PeersDialog.h +++ b/retroshare-gui/src/gui/PeersDialog.h @@ -138,7 +138,11 @@ private slots: void addExtraFile(); void anchorClicked (const QUrl &); void addAttachment(std::string); + + bool fileSave(); + bool fileSaveAs(); + void setCurrentFileName(const QString &fileName); signals: void friendsUpdated() ; @@ -149,7 +153,9 @@ private: class QLabel *iconLabel, *textLabel; class QWidget *widget; class QWidgetAction *widgetAction; - class QSpacerItem *spacerItem; + class QSpacerItem *spacerItem; + + QString fileName; /* Worker Functions */ /* (1) Update Display */ @@ -169,7 +175,7 @@ private: QAction* exportfriendAct; QAction* removefriendAct; - //QTreeWidget *peertreeWidget; + //QTreeWidget *peertreeWidget; IMHistoryKeeper historyKeeper; diff --git a/retroshare-gui/src/gui/PeersDialog.ui b/retroshare-gui/src/gui/PeersDialog.ui index 3838f7f64..507467e59 100644 --- a/retroshare-gui/src/gui/PeersDialog.ui +++ b/retroshare-gui/src/gui/PeersDialog.ui @@ -1418,6 +1418,14 @@ p, li { white-space: pre-wrap; } Disable Emoticons + + + Save Chat History + + + Save Chat History + + diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp index 47d7dc940..fbfe834c0 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp @@ -96,6 +96,7 @@ PopupChatDialog::PopupChatDialog(std::string id, std::string name, connect(ui.colorButton, SIGNAL(clicked()), this, SLOT(setColor())); connect(ui.emoteiconButton, SIGNAL(clicked()), this, SLOT(smileyWidget())); connect(ui.styleButton, SIGNAL(clicked()), SLOT(changeStyle())); + connect(ui.actionSave_Chat_History, SIGNAL(triggered()), this, SLOT(fileSaveAs())); connect(ui.textBrowser, SIGNAL(anchorClicked(const QUrl &)), SLOT(anchorClicked(const QUrl &))); @@ -133,6 +134,7 @@ PopupChatDialog::PopupChatDialog(std::string id, std::string name, QMenu * toolmenu = new QMenu(); toolmenu->addAction(ui.actionClear_Chat); + toolmenu->addAction(ui.actionSave_Chat_History); toolmenu->addAction(ui.action_Disable_Emoticons); ui.pushtoolsButton->setMenu(toolmenu); @@ -978,4 +980,35 @@ void PopupChatDialog::dragEnterEvent(QDragEnterEvent *event) } } +bool PopupChatDialog::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.textBrowser->document()->toPlainText(); + ui.textBrowser->document()->setModified(false); + return true; +} + +bool PopupChatDialog::fileSaveAs() +{ + QString fn = QFileDialog::getSaveFileName(this, tr("Save as..."), + QString(), tr("Text File (*.txt );;All Files (*)")); + if (fn.isEmpty()) + return false; + setCurrentFileName(fn); + return fileSave(); +} + +void PopupChatDialog::setCurrentFileName(const QString &fileName) +{ + this->fileName = fileName; + ui.textBrowser->document()->setModified(false); + + setWindowModified(false); +} diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.h b/retroshare-gui/src/gui/chat/PopupChatDialog.h index 959e6acdb..f9e7b1ae5 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.h +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.h @@ -61,9 +61,7 @@ public: void updateAvatar(); QString loadEmptyStyle(); - - - QPixmap picture; + QPixmap picture; public slots: @@ -107,6 +105,10 @@ private slots: void getAvatar(); void on_actionClear_Chat_triggered(); + + bool fileSave(); + bool fileSaveAs(); + void setCurrentFileName(const QString &fileName); private: @@ -117,13 +119,13 @@ private: QAction *actionTextBold; QAction *actionTextUnderline; QAction *actionTextItalic; - QAction *pasteLinkAct ; + QAction *pasteLinkAct ; std::string dialogId, dialogName; unsigned int lastChatTime; std::string lastChatName; - time_t last_status_send_time ; + time_t last_status_send_time ; QHash smileys; QColor mCurrentColor; QFont mCurrentFont; @@ -131,7 +133,8 @@ private: QString styleHtm; QString emptyStyle; QStringList history; - QString wholeChat; + QString wholeChat; + QString fileName; /** Qt Designer generated object */ Ui::PopupChatDialog ui; diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.ui b/retroshare-gui/src/gui/chat/PopupChatDialog.ui index dd56a64fa..513ebcdc7 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.ui +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.ui @@ -639,6 +639,14 @@ border: 1px solid #CCCCCC; Disable Emoticons + + + Save Chat History + + + Save Chat History + +