[trojita] src: GUI: Add support for setting per-account icons

Jan Kundrát jkt at kde.org
Mon Oct 24 13:11:16 UTC 2016


Git commit 2272b3b6faf5279902c60c13bb3b0caedecb105d by Jan Kundrát.
Committed on 16/10/2016 at 20:00.
Pushed by gerrit into branch 'master'.

GUI: Add support for setting per-account icons

I have several Trojita windows open at any given time, one for each
account that I use. Some of my virtual desktops therefore get a bit too
crowded, and it is hard to distinguish between the top-level windows
which belong to different e-mail accounts. This patch fixes it.

When we move to supporting several accounts within a single instance in
future, I do not expect any breakage caused by this change. The icon is
being tracked in the IMAP account level (and not per-identity, for
example). This will make it easy to e.g. add icons to the mailbox tree
with pretty decorators for each account, etc.

There's no fancy UI yet, patches are kindly welcome. A naive file-picker
is not enough, though, because there are (IMHO) valid use cases for
setting e.g. an RSS-like icon for that profile which is used exclusively
for reading of news feeds sent to e-mails, etc. In those situations,
specifying just "application-rss+xml" and relying on the icon engine to
do the trick might be a reasonable approach. Or maybe not, because
Plasma uses a bigger icon in the taskbar while kwin is happy with a
smaller sized one, and these are visually different in current
breeze-icons.

Change-Id: I021794cf4e5c21997a6da9c6091cc5b5b24a1e81

M  +1    -0    src/Common/SettingsNames.cpp
M  +2    -1    src/Common/SettingsNames.h
M  +3    -0    src/Gui/SettingsDialog.cpp
M  +17   -0    src/Gui/SettingsImapPage.ui
M  +10   -0    src/Gui/Window.cpp
M  +10   -0    src/Imap/Model/ImapAccess.cpp
M  +3    -0    src/Imap/Model/ImapAccess.h

http://commits.kde.org/trojita/2272b3b6faf5279902c60c13bb3b0caedecb105d

diff --git a/src/Common/SettingsNames.cpp b/src/Common/SettingsNames.cpp
index de4117d..70c3a5c 100644
--- a/src/Common/SettingsNames.cpp
+++ b/src/Common/SettingsNames.cpp
@@ -68,6 +68,7 @@ const QString SettingsNames::imapBlacklistedCapabilities = QStringLiteral("imap.
 const QString SettingsNames::imapUseSystemProxy = QStringLiteral("imap.proxy.system");
 const QString SettingsNames::imapNeedsNetwork = QStringLiteral("imap.needsNetwork");
 const QString SettingsNames::imapNumberRefreshInterval = QStringLiteral("imap.numberRefreshInterval");
+const QString SettingsNames::imapAccountIcon = QStringLiteral("imap.accountIcon");
 const QString SettingsNames::composerSaveToImapKey = QStringLiteral("composer/saveToImapEnabled");
 const QString SettingsNames::composerImapSentKey = QStringLiteral("composer/imapSentName");
 const QString SettingsNames::cacheMetadataKey = QStringLiteral("offline.metadataCache");
diff --git a/src/Common/SettingsNames.h b/src/Common/SettingsNames.h
index 45c3d9d..726e74b 100644
--- a/src/Common/SettingsNames.h
+++ b/src/Common/SettingsNames.h
@@ -36,7 +36,8 @@ struct SettingsNames {
     static const QString imapMethodKey, methodTCP, methodSSL, methodProcess, imapHostKey,
            imapPortKey, imapStartTlsKey, imapUserKey, imapProcessKey, imapStartMode, netOffline, netExpensive, netOnline,
            obsImapStartOffline, obsImapSslPemCertificate, imapSslPemPubKey,
-           imapBlacklistedCapabilities, imapUseSystemProxy, imapNeedsNetwork, imapNumberRefreshInterval;
+           imapBlacklistedCapabilities, imapUseSystemProxy, imapNeedsNetwork, imapNumberRefreshInterval,
+           imapAccountIcon;
     static const QString composerSaveToImapKey, composerImapSentKey, smtpUseBurlKey;
     static const QString cacheMetadataKey, cacheMetadataMemory,
            cacheOfflineKey, cacheOfflineNone, cacheOfflineXDays, cacheOfflineAll, cacheOfflineNumberDaysKey;
diff --git a/src/Gui/SettingsDialog.cpp b/src/Gui/SettingsDialog.cpp
index ae5e913..e384da8 100644
--- a/src/Gui/SettingsDialog.cpp
+++ b/src/Gui/SettingsDialog.cpp
@@ -568,6 +568,7 @@ ImapPage::ImapPage(SettingsDialog *parent, QSettings &s): QScrollArea(parent), U
     imapNeedsNetwork->setChecked(s.value(SettingsNames::imapNeedsNetwork, true).toBool());
     imapIdleRenewal->setValue(s.value(SettingsNames::imapIdleRenewal, QVariant(29)).toInt());
     imapNumberRefreshInterval->setValue(m_parent->imapAccess()->numberRefreshInterval());
+    accountIcon->setText(s.value(SettingsNames::imapAccountIcon).toString());
 
     m_imapPort = s.value(SettingsNames::imapPortKey, QString::number(defaultImapPort)).value<quint16>();
 
@@ -700,6 +701,8 @@ void ImapPage::save(QSettings &s)
     s.setValue(SettingsNames::imapIdleRenewal, imapIdleRenewal->value());
     m_parent->imapAccess()->setNumberRefreshInterval(imapNumberRefreshInterval->value());
 
+    s.setValue(SettingsNames::imapAccountIcon, accountIcon->text().isEmpty() ? QVariant() : QVariant(accountIcon->text()));
+
     if (m_pwWatcher->isPluginAvailable() && !m_pwWatcher->isWaitingForPlugin()) {
         m_pwWatcher->setPassword(imapPass->text());
     } else {
diff --git a/src/Gui/SettingsImapPage.ui b/src/Gui/SettingsImapPage.ui
index 788cfc7..c697326 100644
--- a/src/Gui/SettingsImapPage.ui
+++ b/src/Gui/SettingsImapPage.ui
@@ -319,6 +319,23 @@ The default value is 300 seconds (5 minutes).</string>
       </property>
      </widget>
     </item>
+    <item row="16" column="0">
+     <widget class="QLabel" name="accountIconLabel">
+      <property name="text">
+       <string>Account Icon</string>
+      </property>
+     </widget>
+    </item>
+    <item row="16" column="1">
+     <widget class="QLineEdit" name="accountIcon">
+      <property name="placeholderText">
+       <string>Default Trojitá icon</string>
+      </property>
+      <property name="clearButtonEnabled">
+       <bool>true</bool>
+      </property>
+     </widget>
+    </item>
    </layout>
   </widget>
  </widget>
diff --git a/src/Gui/Window.cpp b/src/Gui/Window.cpp
index 90e46c9..08365a1 100644
--- a/src/Gui/Window.cpp
+++ b/src/Gui/Window.cpp
@@ -887,6 +887,16 @@ void MainWindow::setupModels()
     connect(imapModel()->taskModel(), &QAbstractItemModel::rowsMoved, taskTree, &QTreeView::expandAll);
 
     busyParsersIndicator->setImapModel(imapModel());
+
+    auto accountIconName = m_settings->value(Common::SettingsNames::imapAccountIcon).toString();
+    if (accountIconName.isEmpty()) {
+        qApp->setWindowIcon(UiUtils::loadIcon(QStringLiteral("trojita")));
+    } else if (accountIconName.contains(QDir::separator())) {
+        // Absolute paths are OK for users, but unsupported by our icon loader
+        qApp->setWindowIcon(QIcon(accountIconName));
+    } else {
+        qApp->setWindowIcon(UiUtils::loadIcon(accountIconName));
+    }
 }
 
 void MainWindow::createSysTray()
diff --git a/src/Imap/Model/ImapAccess.cpp b/src/Imap/Model/ImapAccess.cpp
index b5ba8f6..4609d65 100644
--- a/src/Imap/Model/ImapAccess.cpp
+++ b/src/Imap/Model/ImapAccess.cpp
@@ -235,6 +235,16 @@ Imap::Mailbox::NetworkPolicy ImapAccess::preferredNetworkPolicy() const
     }
 }
 
+QString ImapAccess::accountIconName() const
+{
+    return m_settings->value(Common::SettingsNames::imapAccountIcon).toString();
+}
+
+void ImapAccess::setAccountIconName(const QString &iconName)
+{
+    m_settings->setValue(Common::SettingsNames::imapAccountIcon, iconName);
+}
+
 void ImapAccess::doConnect()
 {
     if (m_netWatcher) {
diff --git a/src/Imap/Model/ImapAccess.h b/src/Imap/Model/ImapAccess.h
index 179e129..78c7c86 100644
--- a/src/Imap/Model/ImapAccess.h
+++ b/src/Imap/Model/ImapAccess.h
@@ -108,6 +108,9 @@ public:
 
     QString accountName() const;
 
+    QString accountIconName() const;
+    void setAccountIconName(const QString &iconName);
+
     Common::ConnectionMethod connectionMethod() const;
     void setConnectionMethod(const Common::ConnectionMethod mode);
 



More information about the kde-doc-english mailing list