Git commit 62195e4182e169ee154a340ea490396b54578823 by Jan Kundr?t. Committed on 21/05/2013 at 23:38. Pushed by jkt into branch 'master'.
GUI: unbreak saving of individual message parts and add proper menu for saving complete messages Also instantiate the download managers on demand to cut down the excessive memory use. This has apparently been broken since I merged the patch which added the FullMessageCombiner. Thanks to Caspar for his bugreport. fixes #643 M +41 -7 src/Gui/SimplePartWidget.cpp M +7 -3 src/Gui/SimplePartWidget.h http://commits.kde.org/trojita/62195e4182e169ee154a340ea490396b54578823 diff --git a/src/Gui/SimplePartWidget.cpp b/src/Gui/SimplePartWidget.cpp index 6210705..7546398 100644 --- a/src/Gui/SimplePartWidget.cpp +++ b/src/Gui/SimplePartWidget.cpp @@ -33,13 +33,15 @@ #include "Gui/Util.h" #include "Imap/Model/ItemRoles.h" #include "Imap/Model/MailboxTree.h" +#include "Imap/Model/Model.h" #include "Imap/Network/FileDownloadManager.h" namespace Gui { SimplePartWidget::SimplePartWidget(QWidget *parent, Imap::Network::MsgPartNetAccessManager *manager, const QModelIndex &partIndex): - EmbeddedWebView(parent, manager), flowedFormat(Composer::Util::FORMAT_PLAIN) + EmbeddedWebView(parent, manager), m_partIndex(partIndex), m_netAccessManager(manager), + flowedFormat(Composer::Util::FORMAT_PLAIN) { Q_ASSERT(partIndex.isValid()); QUrl url; @@ -52,12 +54,13 @@ SimplePartWidget::SimplePartWidget(QWidget *parent, Imap::Network::MsgPartNetAcc flowedFormat = Composer::Util::FORMAT_FLOWED; load(url); - fileDownloadManager = new Imap::Network::FileDownloadManager(this, manager, partIndex); - connect(fileDownloadManager, SIGNAL(fileNameRequested(QString *)), this, SLOT(slotFileNameRequested(QString *))); + m_savePart = new QAction(tr("Save this message part..."), this); + connect(m_savePart, SIGNAL(triggered()), this, SLOT(slotDownloadPart())); + this->addAction(m_savePart); - saveAction = new QAction(tr("Save..."), this); - connect(saveAction, SIGNAL(triggered()), fileDownloadManager, SLOT(downloadMessage())); - this->addAction(saveAction); + m_saveMessage = new QAction(tr("Save whole message..."), this); + connect(m_saveMessage, SIGNAL(triggered()), this, SLOT(slotDownloadMessage())); + this->addAction(m_saveMessage); m_findAction = new QAction(tr("Search..."), this); m_findAction->setShortcut(tr("Ctrl+F")); @@ -173,7 +176,7 @@ void SimplePartWidget::reloadContents() QList<QAction *> SimplePartWidget::contextMenuSpecificActions() const { - return QList<QAction*>() << saveAction << m_findAction; + return QList<QAction*>() << m_savePart << m_saveMessage << m_findAction; } /** @short Connect various signals which require a certain reaction from the rest of the GUI */ @@ -190,5 +193,36 @@ void SimplePartWidget::connectGuiInteractionEvents(QObject *guiInteractionTarget connect(this, SIGNAL(searchDialogRequested()), guiInteractionTarget, SLOT(triggerSearchDialog())); } +void SimplePartWidget::slotDownloadPart() +{ + Imap::Network::FileDownloadManager *manager = new Imap::Network::FileDownloadManager(this, m_netAccessManager, m_partIndex); + connect(manager, SIGNAL(fileNameRequested(QString *)), this, SLOT(slotFileNameRequested(QString *))); + connect(manager, SIGNAL(transferError(QString)), this, SLOT(slotTransferError(QString))); + connect(manager, SIGNAL(transferError(QString)), manager, SLOT(deleteLater())); + connect(manager, SIGNAL(succeeded()), manager, SLOT(deleteLater())); + manager->downloadPart(); +} + +void SimplePartWidget::slotDownloadMessage() +{ + QModelIndex index; + if (m_partIndex.isValid()) { + const Imap::Mailbox::Model *model = 0; + Imap::Mailbox::TreeItem *item = Imap::Mailbox::Model::realTreeItem(m_partIndex, &model); + Q_ASSERT(model); + Q_ASSERT(item); + Imap::Mailbox::TreeItemMessage *messagePtr = dynamic_cast<Imap::Mailbox::TreeItemPart*>(item)->message(); + Q_ASSERT(messagePtr); + index = messagePtr->toIndex(const_cast<Imap::Mailbox::Model*>(model)); + } + + Imap::Network::FileDownloadManager *manager = new Imap::Network::FileDownloadManager(this, m_netAccessManager, index); + connect(manager, SIGNAL(fileNameRequested(QString *)), this, SLOT(slotFileNameRequested(QString *))); + connect(manager, SIGNAL(transferError(QString)), this, SLOT(slotTransferError(QString))); + connect(manager, SIGNAL(transferError(QString)), manager, SLOT(deleteLater())); + connect(manager, SIGNAL(succeeded()), manager, SLOT(deleteLater())); + manager->downloadMessage(); +} + } diff --git a/src/Gui/SimplePartWidget.h b/src/Gui/SimplePartWidget.h index ee25246..3eb9cae 100644 --- a/src/Gui/SimplePartWidget.h +++ b/src/Gui/SimplePartWidget.h @@ -27,6 +27,7 @@ #include "Composer/PlainTextFormatter.h" #include <QAction> #include <QFile> +#include <QPersistentModelIndex> class QModelIndex; class QNetworkReply; @@ -35,7 +36,6 @@ namespace Imap { namespace Network { -class FileDownloadManager; class MsgPartNetAccessManager; } } @@ -62,13 +62,17 @@ private slots: void slotTransferError(const QString &errorString); void slotFileNameRequested(QString *fileName); void slotMarkupPlainText(); + void slotDownloadPart(); + void slotDownloadMessage(); signals: void linkHovered(const QString &link, const QString &title, const QString &textContent); void searchDialogRequested(); private: - QAction *saveAction; + QPersistentModelIndex m_partIndex; + QAction *m_savePart; + QAction *m_saveMessage; QAction *m_findAction; - Imap::Network::FileDownloadManager *fileDownloadManager; + Imap::Network::MsgPartNetAccessManager *m_netAccessManager; Composer::Util::FlowedFormat flowedFormat; SimplePartWidget(const SimplePartWidget &); // don't implement
