[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/network/telepathy-accounts-kcm/src
From:       Matteo Nardi <91.matteo () gmail ! com>
Date:       2009-07-31 17:42:39
Message-ID: 1249062159.641973.24764.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1005262 by nardi:

Show a warning icon over invalid accounts in the account list.
BUG: 201399


 M  +41 -2     account-item.cpp  
 M  +5 -0      account-item.h  
 M  +1 -2      accounts-list-model.cpp  


--- trunk/playground/network/telepathy-accounts-kcm/src/account-item.cpp #1005261:1005262
@@ -23,15 +23,18 @@
 #include "accounts-list-model.h"
 
 #include <KDebug>
+#include <KIcon>
 
 #include <QtCore/QTimer>
+#include <QtGui/QPainter>
 
 #include <TelepathyQt4/PendingOperation>
 #include <TelepathyQt4/PendingReady>
 
 AccountItem::AccountItem(const Tp::AccountPtr &account, AccountsListModel *parent)
  : QObject(parent),
-   m_account(account)
+   m_account(account),
+   m_icon(new KIcon())
 {
     kDebug();
 
@@ -43,6 +46,9 @@
             SIGNAL(displayNameChanged(const QString&)),
             SIGNAL(updated()));
 
+    //initialize icon only when the account is ready
+    connect(this, SIGNAL(ready()), SLOT(generateIcon()));
+
     // We should look to see if the "account" instance we are passed is ready
     // yet. If not, we should get it ready now.
     // FIXME: What features should we check are ready?
@@ -60,7 +66,7 @@
 {
     kDebug();
 
-    // TODO: Implement me...
+    delete m_icon;
 }
 
 Tp::AccountPtr AccountItem::account() const
@@ -78,6 +84,39 @@
             SLOT(onAccountRemoved(Tp::PendingOperation*)));
 }
 
+const KIcon& AccountItem::icon() const
+{
+    Q_ASSERT(m_icon != 0);
+
+    return *m_icon;
+}
+
+void AccountItem::generateIcon()
+{
+    kDebug();
+
+    QString iconPath = account()->icon();
+    //if the icon has not been setted, we use the protocol icon
+    if(iconPath.isEmpty()) {
+        iconPath = QString("im-%1").arg(account()->protocol());
+    }
+
+    delete m_icon;
+    m_icon = new KIcon(iconPath);
+
+    if(!account()->isValid()) {
+        //we paint a warning symbol in the right-bottom corner
+        QPixmap pixmap = m_icon->pixmap(32, 32);
+        QPainter painter(&pixmap);
+        KIcon("dialog-error").paint(&painter, 15, 15, 16, 16);
+
+        delete m_icon;
+        m_icon = new KIcon(pixmap);
+    }
+
+    Q_EMIT(updated());
+}
+
 void AccountItem::onAccountReady(Tp::PendingOperation *op)
 {
     kDebug();
--- trunk/playground/network/telepathy-accounts-kcm/src/account-item.h #1005261:1005262
@@ -25,6 +25,8 @@
 
 #include <TelepathyQt4/Account>
 
+class KIcon;
+
 class AccountsListModel;
 
 namespace Tp {
@@ -41,8 +43,10 @@
     virtual ~AccountItem();
     Tp::AccountPtr account() const;
     void remove();
+    const KIcon& icon() const;
 
 private Q_SLOTS:
+    void generateIcon();
     void onAccountReady(Tp::PendingOperation *op);
     void onAccountRemoved(Tp::PendingOperation *op);
 
@@ -53,6 +57,7 @@
 
 private:
     Tp::AccountPtr m_account;
+    KIcon* m_icon;
 };
 
 
--- trunk/playground/network/telepathy-accounts-kcm/src/accounts-list-model.cpp #1005261:1005262
@@ -67,8 +67,7 @@
         break;
 
     case Qt::DecorationRole:
-        //FIXME: we need to move kopete protocol icons to oxygen..
-        data = QVariant(KIcon(account->icon()));
+        data = QVariant(m_readyAccounts.at(index.row())->icon());
         break;
 
     case Qt::CheckStateRole:
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic