[Pkg-owncloud-commits] [owncloud-client] 34/159: SslButton: Make menu creation lazy

Sandro Knauß hefee-guest at moszumanska.debian.org
Fri May 1 13:05:19 UTC 2015


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit e0ae34f01b8085c4930a4a1a3ca06ec2b4843e87
Author: Markus Goetz <markus at woboq.com>
Date:   Wed Mar 25 15:39:53 2015 +0100

    SslButton: Make menu creation lazy
    
    Saves ~200msec on my not-so-old MBP on OS X.
    For #3007 #2990
---
 src/gui/sslbutton.cpp | 42 ++++++++++++++++++++++++++++--------------
 src/gui/sslbutton.h   |  5 ++++-
 2 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/src/gui/sslbutton.cpp b/src/gui/sslbutton.cpp
index d7768b5..11b6288 100644
--- a/src/gui/sslbutton.cpp
+++ b/src/gui/sslbutton.cpp
@@ -31,6 +31,10 @@ SslButton::SslButton(QWidget *parent) :
 {
     setPopupMode(QToolButton::InstantPopup);
     setAutoRaise(true);
+
+    setMenu(new QMenu(this));
+    QObject::connect(menu(), SIGNAL(aboutToShow()),
+                     this, SLOT(slotUpdateMenu()));
 }
 
 QString SslButton::protoToString(QSsl::SslProtocol proto)
@@ -178,17 +182,31 @@ void SslButton::updateAccountState(AccountState *accountState)
     } else {
         setVisible(true);
     }
-    AccountPtr account = accountState->account();
-    if(QMenu *oldMenu = menu()) {
-        oldMenu->hide(); // Need to be hidden because the QToolButton would be left in invalid state if the menu is deleted while it is visible
-        setMenu(0);
-        oldMenu->deleteLater();  // setMenu do not delete the previous menu.
-    }
+    _accountState = accountState;
+
+    AccountPtr account = _accountState->account();
     if (account->url().scheme() == QLatin1String("https")) {
-        setIcon(QIcon(QPixmap(Theme::hidpiFileName(":/client/resources/lock-https.png"))));
+        QPixmap pm(Theme::hidpiFileName(":/client/resources/lock-https.png"));
+        setIcon(QIcon(pm));
         QSslCipher cipher = account->sslConfiguration().sessionCipher();
         setToolTip(tr("This connection is encrypted using %1 bit %2.\n").arg(cipher.usedBits()).arg(cipher.name()));
-        QMenu *menu = new QMenu(this);
+    } else {
+        setIcon(QIcon(QPixmap(Theme::hidpiFileName(":/client/resources/lock-http.png"))));
+        setToolTip(tr("This connection is NOT secure as it is not encrypted.\n"));
+    }
+}
+
+void SslButton::slotUpdateMenu() {
+    menu()->clear();
+
+    if (!_accountState) {
+        return;
+    }
+
+    AccountPtr account = _accountState->account();
+
+    if (account->url().scheme() == QLatin1String("https")) {
+
         QList<QSslCertificate> chain = account->sslConfiguration().peerCertificateChain();
 
         if (chain.isEmpty()) {
@@ -196,7 +214,7 @@ void SslButton::updateAccountState(AccountState *accountState)
             return;
         }
 
-        menu->addAction(tr("Certificate information:"))->setEnabled(false);
+        menu()->addAction(tr("Certificate information:"))->setEnabled(false);
 
         QList<QSslCertificate> tmpChain;
         foreach(QSslCertificate cert, chain) {
@@ -219,13 +237,9 @@ void SslButton::updateAccountState(AccountState *accountState)
         it.toBack();
         int i = 0;
         while (it.hasPrevious()) {
-            menu->addMenu(buildCertMenu(menu, it.previous(), account->approvedCerts(), i));
+            menu()->addMenu(buildCertMenu(menu(), it.previous(), account->approvedCerts(), i));
             i++;
         }
-        setMenu(menu);
-    } else {
-        setIcon(QIcon(QPixmap(Theme::hidpiFileName(":/client/resources/lock-http.png"))));
-        setToolTip(tr("This connection is NOT secure as it is not encrypted.\n"));
     }
 }
 
diff --git a/src/gui/sslbutton.h b/src/gui/sslbutton.h
index b969804..ef4014e 100644
--- a/src/gui/sslbutton.h
+++ b/src/gui/sslbutton.h
@@ -24,7 +24,6 @@ class QSslConfiguration;
 
 namespace OCC {
 
-class Account;
 class AccountState;
 
 class SslButton : public QToolButton
@@ -35,9 +34,13 @@ public:
     QString protoToString(QSsl::SslProtocol proto);
     void updateAccountState(AccountState *accountState);
 
+public slots:
+    void slotUpdateMenu();
+
 private:
     QMenu* buildCertMenu(QMenu *parent, const QSslCertificate& cert,
                          const QList<QSslCertificate>& userApproved, int pos);
+    QPointer<AccountState> _accountState;
 };
 
 } // namespace OCC

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list