[kde-doc-english] [trojita] src: GUI: toggle between showing "From" and "To" columns based on whether we're showing the "Sent" mailbox

Jan Kundrát jkt at flaska.net
Fri Mar 15 10:28:37 UTC 2013


Git commit 7d93083c99664bc79c80a2063aa22cf27e40cdce by Jan Kundrát.
Committed on 15/03/2013 at 10:46.
Pushed by jkt into branch 'master'.

GUI: toggle between showing "From" and "To" columns based on whether we're showing the "Sent" mailbox

This feature was suggested by "serpentine" on IRC. I've always wanted to do that :).

M  +24   -0    src/Gui/Window.cpp
M  +1    -0    src/Gui/Window.h
M  +1    -1    src/Imap/Model/MsgListModel.cpp
M  +1    -1    src/Imap/Model/MsgListModel.h

http://commits.kde.org/trojita/7d93083c99664bc79c80a2063aa22cf27e40cdce

diff --git a/src/Gui/Window.cpp b/src/Gui/Window.cpp
index 7746ba5..7e3c24f 100644
--- a/src/Gui/Window.cpp
+++ b/src/Gui/Window.cpp
@@ -655,6 +655,7 @@ void MainWindow::setupModels()
     connect(msgListModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), msgListWidget, SLOT(slotAutoEnableDisableSearch()));
     connect(msgListModel, SIGNAL(layoutChanged()), msgListWidget, SLOT(slotAutoEnableDisableSearch()));
     connect(msgListModel, SIGNAL(modelReset()), msgListWidget, SLOT(slotAutoEnableDisableSearch()));
+    connect(msgListModel, SIGNAL(mailboxChanged(QModelIndex)), this, SLOT(slotMailboxChanged(QModelIndex)));
 
     connect(model, SIGNAL(alertReceived(const QString &)), this, SLOT(alertReceived(const QString &)));
     connect(model, SIGNAL(connectionError(const QString &)), this, SLOT(connectionError(const QString &)));
@@ -1351,6 +1352,29 @@ void MainWindow::slotMailboxCreateFailed(const QString &mailbox, const QString &
                          tr("Creating mailbox \"%1\" failed with the following message:\n%2").arg(mailbox, msg));
 }
 
+void MainWindow::slotMailboxChanged(const QModelIndex &mailbox)
+{
+    using namespace Imap::Mailbox;
+    QString mailboxName = mailbox.data(RoleMailboxName).toString();
+    bool isSentMailbox = mailbox.isValid() && !mailboxName.isEmpty() &&
+            QSettings().value(Common::SettingsNames::composerSaveToImapKey).toBool() &&
+            mailboxName == QSettings().value(Common::SettingsNames::composerImapSentKey).toString();
+    QTreeView *tree = msgListWidget->tree;
+
+    // Automatically trigger visibility of the TO and FROM columns
+    if (isSentMailbox) {
+        if (tree->isColumnHidden(MsgListModel::TO) && !tree->isColumnHidden(MsgListModel::FROM)) {
+            tree->hideColumn(MsgListModel::FROM);
+            tree->showColumn(MsgListModel::TO);
+        }
+    } else {
+        if (tree->isColumnHidden(MsgListModel::FROM) && !tree->isColumnHidden(MsgListModel::TO)) {
+            tree->hideColumn(MsgListModel::TO);
+            tree->showColumn(MsgListModel::FROM);
+        }
+    }
+}
+
 void MainWindow::showConnectionStatus(QObject *parser, Imap::ConnectionState state)
 {
     Q_UNUSED(parser);
diff --git a/src/Gui/Window.h b/src/Gui/Window.h
index 0e8aa54..c849bfe 100644
--- a/src/Gui/Window.h
+++ b/src/Gui/Window.h
@@ -153,6 +153,7 @@ private slots:
 
     void slotMailboxDeleteFailed(const QString &mailbox, const QString &msg);
     void slotMailboxCreateFailed(const QString &mailbox, const QString &msg);
+    void slotMailboxChanged(const QModelIndex &mailbox);
 
     void slotDownloadMessageTransferError(const QString &errorString);
     void slotDownloadMessageFileNameRequested(QString *fileName);
diff --git a/src/Imap/Model/MsgListModel.cpp b/src/Imap/Model/MsgListModel.cpp
index b909f2c..98e287d 100644
--- a/src/Imap/Model/MsgListModel.cpp
+++ b/src/Imap/Model/MsgListModel.cpp
@@ -485,7 +485,7 @@ void MsgListModel::setMailbox(const QModelIndex &index)
         msgList = msgListPtr->toIndex(const_cast<Model*>(model));
         msgListPtr->resetWasUnreadState();
         RESET_MODEL;
-        emit mailboxChanged();
+        emit mailboxChanged(index);
         // We want to tell the Model that it should consider starting the IDLE command.
         const_cast<Model *>(model)->switchToMailbox(index);
     }
diff --git a/src/Imap/Model/MsgListModel.h b/src/Imap/Model/MsgListModel.h
index ad858b3..150ae48 100644
--- a/src/Imap/Model/MsgListModel.h
+++ b/src/Imap/Model/MsgListModel.h
@@ -83,7 +83,7 @@ public slots:
 
 signals:
     void messageRemoved(void *);
-    void mailboxChanged();
+    void mailboxChanged(const QModelIndex &mailbox);
 
     /** @short Messages are available for the first time after selecting new mailbox */
     void messagesAvailable();



More information about the kde-doc-english mailing list