[SCM] ktp-accounts-kcm packaging branch, master, updated. debian/15.12.1-1-1157-gc4589c5

Maximiliano Curia maxy at moszumanska.debian.org
Sat May 28 00:02:48 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-accounts-kcm.git;a=commitdiff;h=8285c52

The following commit has been merged in the master branch:
commit 8285c526a000b6efe8d8cf6a9fca23b8817ea817
Author: David Edmundson <kde at davidedmundson.co.uk>
Date:   Tue Oct 2 19:29:12 2012 +0100

    Remove somewhat pointless AccountItem class.
    
    This should result in a simpler, faster AccountsModel.
---
 src/CMakeLists.txt          |   1 -
 src/account-item.cpp        | 177 --------------------------------------------
 src/account-item.h          |  69 -----------------
 src/accounts-list-model.cpp | 100 ++++++++++++++++++++-----
 src/accounts-list-model.h   |   7 +-
 5 files changed, 89 insertions(+), 265 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ee82fd0..fd55553 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -13,7 +13,6 @@ set (kcm_ktp_accounts_SRCS
      salut-message-widget.cpp
      kcm-telepathy-accounts.cpp
      accounts-list-model.cpp
-     account-item.cpp
      add-account-assistant.cpp
      edit-account-dialog.cpp
      account-identity-dialog.cpp
diff --git a/src/account-item.cpp b/src/account-item.cpp
deleted file mode 100644
index 0c8e73e..0000000
--- a/src/account-item.cpp
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * This file is part of telepathy-accounts-kcm
- *
- * Copyright (C) 2009 Collabora Ltd. <info at collabora.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-#include "account-item.h"
-
-#include "accounts-list-model.h"
-#include "edit-account-dialog.h"
-
-#include <KTp/error-dictionary.h>
-#include <KTp/wallet-utils.h>
-
-#include <KApplication>
-#include <KDebug>
-#include <KIcon>
-#include <KLocalizedString>
-#include <KPixmapSequence>
-
-#include <QtCore/QTimer>
-#include <QtGui/QPainter>
-
-#include <TelepathyQt/PendingOperation>
-#include <TelepathyQt/PendingReady>
-#include <TelepathyQt/PendingComposite>
-
-
-AccountItem::AccountItem(const Tp::AccountPtr &account, AccountsListModel *parent)
- : QObject(parent),
-   m_account(account),
-   m_icon(new KIcon())
-{
-    //connect AccountPtr signals to AccountItem signals
-    connect(m_account.data(),
-            SIGNAL(stateChanged(bool)),
-            SIGNAL(updated()));
-    connect(m_account.data(),
-            SIGNAL(displayNameChanged(QString)),
-            SIGNAL(updated()));
-    connect(m_account.data(),
-            SIGNAL(connectionStatusChanged(Tp::ConnectionStatus)),
-            SIGNAL(updated()));
-    connect(m_account.data(),
-            SIGNAL(iconNameChanged(QString)),
-            SLOT(generateIcon()));
-    connect(m_account.data(),
-            SIGNAL(removed()),
-            SIGNAL(removed()));
-    connect(m_account.data(),
-            SIGNAL(stateChanged(bool)),
-            SLOT(generateIcon()));
-
-    generateIcon();
-}
-
-AccountItem::~AccountItem()
-{
-    delete m_icon;
-}
-
-Tp::AccountPtr AccountItem::account() const
-{
-    return m_account;
-}
-
-const KIcon& AccountItem::icon() const
-{
-    Q_ASSERT(m_icon != 0);
-
-    return *m_icon;
-}
-
-const QString AccountItem::connectionStateString() const
-{
-    if (m_account->isEnabled()) {
-        switch (m_account->connectionStatus()) {
-        case Tp::ConnectionStatusConnected:
-            return i18n("Online");
-        case Tp::ConnectionStatusConnecting:
-            return i18nc("This is a connection state", "Connecting");
-        case Tp::ConnectionStatusDisconnected:
-            return i18nc("This is a connection state", "Disconnected");
-        default:
-            return i18nc("This is an unknown connection state", "Unknown");
-        }
-    } else {
-        return i18nc("This is a disabled account", "Disabled");
-    }
-}
-
-const KIcon AccountItem::connectionStateIcon() const
-{
-    if (m_account->isEnabled()) {
-        switch (m_account->connectionStatus()) {
-        case Tp::ConnectionStatusConnected:
-            return KIcon(QLatin1String("user-online"));
-        case Tp::ConnectionStatusConnecting:
-            //imho this is not really worth animating, but feel free to play around..
-            return KIcon(KPixmapSequence(QLatin1String("process-working"), 22).frameAt(0));
-        case Tp::ConnectionStatusDisconnected:
-            return KIcon(QLatin1String("user-offline"));
-        default:
-            return KIcon(QLatin1String("user-offline"));
-        }
-    } else {
-        return KIcon();
-    }
-}
-
-const QString AccountItem::connectionStatusReason() const
-{
-    if (!m_account->isEnabled()) {
-        return i18n("Click checkbox to enable");
-    }
-    else if (m_account->connectionStatusReason() == Tp::ConnectionStatusReasonRequested) {
-        return QString();
-    }
-    else {
-        return KTp::ErrorDictionary::displayShortErrorMessage(m_account->connectionError());
-    }
-}
-
-const QString AccountItem::connectionProtocolName() const
-{
-    return m_account->protocolName();
-}
-
-void AccountItem::generateIcon()
-{
-    QString iconPath = account()->iconName();
-
-    //if the icon has not been set, we use the protocol icon
-    if (iconPath.isEmpty()) {
-        iconPath = QString::fromLatin1("im-%1").arg(account()->protocolName());
-    }
-
-    delete m_icon;
-    if (m_account->isEnabled()) {
-        m_icon = new KIcon(iconPath);
-    } else {
-        m_icon = new KIcon(KIconLoader::global()->loadIcon(iconPath, KIconLoader::Desktop, 32, KIconLoader::DisabledState));
-    }
-
-    if (!account()->isValid()) {
-        //we paint a warning symbol in the right-bottom corner
-        QPixmap pixmap = m_icon->pixmap(32, 32);
-        QPainter painter(&pixmap);
-        KIcon(QLatin1String("dialog-error")).paint(&painter, 15, 15, 16, 16);
-
-        delete m_icon;
-        m_icon = new KIcon(pixmap);
-    }
-
-    Q_EMIT(updated());
-}
-
-Tp::ConnectionStatus AccountItem::connectionStatus() const
-{
-    return m_account->connectionStatus();
-}
-
-#include "account-item.moc"
diff --git a/src/account-item.h b/src/account-item.h
deleted file mode 100644
index c8ff9a0..0000000
--- a/src/account-item.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * This file is part of telepathy-accounts-kcm
- *
- * Copyright (C) 2009 Collabora Ltd. <info at collabora.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-#ifndef TELEPATHY_ACCOUNTS_KCM_ACCOUNT_ITEM_H
-#define TELEPATHY_ACCOUNTS_KCM_ACCOUNT_ITEM_H
-
-#include <QtCore/QObject>
-
-#include <TelepathyQt/Account>
-
-class KIcon;
-
-class AccountsListModel;
-
-namespace Tp {
-    class PendingOperation;
-}
-
-class AccountItem : public QObject
-{
-    Q_OBJECT
-    Q_DISABLE_COPY(AccountItem);
-
-public:
-    explicit AccountItem(const Tp::AccountPtr &account, AccountsListModel *parent = 0);
-    virtual ~AccountItem();
-    Tp::AccountPtr account() const;
-    const KIcon& icon() const;
-    Tp::ConnectionStatus connectionStatus() const;
-    const QString connectionStateString() const;
-    const KIcon connectionStateIcon() const;
-    const QString connectionStatusReason() const;
-    const QString connectionProtocolName() const;
-
-Q_SIGNALS:
-    void ready();
-    void removed();
-    void updated();
-    void protocolSelected(QString, QString);
-
-private Q_SLOTS:
-    void generateIcon();
-
-private:
-    Tp::AccountPtr m_account;
-    KIcon* m_icon;
-};
-
-Q_DECLARE_METATYPE(AccountItem*);
-
-#endif // header guard
-
diff --git a/src/accounts-list-model.cpp b/src/accounts-list-model.cpp
index 1073882..b9c4b85 100644
--- a/src/accounts-list-model.cpp
+++ b/src/accounts-list-model.cpp
@@ -24,6 +24,10 @@
 
 #include <KDebug>
 #include <KIcon>
+#include <KLocalizedString>
+#include <KPixmapSequence>
+
+#include <KTp/error-dictionary.h>
 
 #include <TelepathyQt/Account>
 
@@ -65,7 +69,7 @@ QVariant AccountsListModel::data(const QModelIndex &index, int role) const
     }
 
     QVariant data;
-    Tp::AccountPtr account = m_accounts.at(index.row())->account();
+    Tp::AccountPtr account = m_accounts.at(index.row());
 
     switch (role) {
     case Qt::DisplayRole:
@@ -73,7 +77,7 @@ QVariant AccountsListModel::data(const QModelIndex &index, int role) const
         break;
 
     case Qt::DecorationRole:
-        data = QVariant(m_accounts.at(index.row())->icon());
+        data = QVariant(KIcon(account->iconName()));
         break;
 
     case Qt::CheckStateRole:
@@ -85,23 +89,23 @@ QVariant AccountsListModel::data(const QModelIndex &index, int role) const
         break;
 
     case AccountsListModel::ConnectionStateRole:
-        data = QVariant(m_accounts.at(index.row())->connectionStatus());
+        data = QVariant(account->connectionStatus());
         break;
 
     case AccountsListModel::ConnectionStateDisplayRole:
-        data = QVariant(m_accounts.at(index.row())->connectionStateString());
+        data = QVariant(connectionStateString(account));
         break;
 
     case AccountsListModel::ConnectionStateIconRole:
-        data = QVariant(m_accounts.at(index.row())->connectionStateIcon());
+        data = QVariant(connectionStateIcon(account));
         break;
 
     case AccountsListModel::ConnectionErrorMessageDisplayRole:
-        data = QVariant(m_accounts.at(index.row())->connectionStatusReason());
+        data = QVariant(connectionStatusReason(account));
         break;
 
     case AccountsListModel::ConnectionProtocolNameRole:
-        data = QVariant(m_accounts.at(index.row())->connectionProtocolName());
+        data = QVariant(account->protocolName());
         break;
 
     case AccountsListModel::AccountRole:
@@ -159,8 +163,8 @@ void AccountsListModel::addAccount(const Tp::AccountPtr &account)
     bool found = false;
 
     if (!found) {
-        Q_FOREACH (const AccountItem *ai, m_accounts) {
-            if (ai->account() == account) {
+        Q_FOREACH (const Tp::AccountPtr &ai, m_accounts) {
+            if (ai == account) {
                 found = true;
                 break;
             }
@@ -175,20 +179,33 @@ void AccountsListModel::addAccount(const Tp::AccountPtr &account)
         kDebug() << "Account not already in model. Create new AccountItem from account:"
                  << account.data();
 
-        AccountItem *item = new AccountItem(account, this);
-
         beginInsertRows(QModelIndex(), m_accounts.size(), m_accounts.size());
-        m_accounts.append(item);
+        m_accounts.append(account);
         endInsertRows();
 
-        connect(item, SIGNAL(removed()), SLOT(onAccountItemRemoved()));
-        connect(item, SIGNAL(updated()), SLOT(onAccountItemUpdated()));
+        connect(account.data(), SIGNAL(removed()), SLOT(onAccountItemRemoved()));
+
+        connect(account.data(),
+                SIGNAL(stateChanged(bool)),
+                SLOT(onAccountItemUpdated()));
+        connect(account.data(),
+                SIGNAL(displayNameChanged(QString)),
+                SLOT(onAccountItemUpdated()));
+        connect(account.data(),
+                SIGNAL(connectionStatusChanged(Tp::ConnectionStatus)),
+                SLOT(onAccountItemUpdated()));
+        connect(account.data(),
+                SIGNAL(iconNameChanged(QString)),
+                SLOT(onAccountItemUpdated()));
+        connect(account.data(),
+                SIGNAL(stateChanged(bool)),
+                SLOT(onAccountItemUpdated()));
     }
 }
 
 void AccountsListModel::onAccountItemRemoved()
 {
-    AccountItem *item = qobject_cast<AccountItem*>(sender());
+    Tp::AccountPtr item = Tp::AccountPtr(qobject_cast<Tp::Account*>(sender()));
 
     Q_ASSERT(item);
     if (!item) {
@@ -204,12 +221,11 @@ void AccountsListModel::onAccountItemRemoved()
 
     // FIXME: Workaround until the KWidgetItemDelegate gets fixed (probably KDE 4.7)
     //reset();
-    delete item;
 }
 
 void AccountsListModel::onAccountItemUpdated()
 {
-    AccountItem *item = qobject_cast<AccountItem*>(sender());
+    Tp::AccountPtr item = Tp::AccountPtr(qobject_cast<Tp::Account*>(sender()));
 
     Q_ASSERT(item);
     if (!item) {
@@ -221,4 +237,54 @@ void AccountsListModel::onAccountItemUpdated()
     Q_EMIT dataChanged(index, index);
 }
 
+const QString AccountsListModel::connectionStateString(const Tp::AccountPtr &account) const
+{
+    if (account->isEnabled()) {
+        switch (account->connectionStatus()) {
+        case Tp::ConnectionStatusConnected:
+            return i18n("Online");
+        case Tp::ConnectionStatusConnecting:
+            return i18nc("This is a connection state", "Connecting");
+        case Tp::ConnectionStatusDisconnected:
+            return i18nc("This is a connection state", "Disconnected");
+        default:
+            return i18nc("This is an unknown connection state", "Unknown");
+        }
+    } else {
+        return i18nc("This is a disabled account", "Disabled");
+    }
+}
+
+const KIcon AccountsListModel::connectionStateIcon(const Tp::AccountPtr &account) const
+{
+    if (account->isEnabled()) {
+        switch (account->connectionStatus()) {
+        case Tp::ConnectionStatusConnected:
+            return KIcon(QLatin1String("user-online"));
+        case Tp::ConnectionStatusConnecting:
+            //imho this is not really worth animating, but feel free to play around..
+            return KIcon(KPixmapSequence(QLatin1String("process-working"), 22).frameAt(0));
+        case Tp::ConnectionStatusDisconnected:
+            return KIcon(QLatin1String("user-offline"));
+        default:
+            return KIcon(QLatin1String("user-offline"));
+        }
+    } else {
+        return KIcon();
+    }
+}
+
+const QString AccountsListModel::connectionStatusReason(const Tp::AccountPtr &account) const
+{
+    if (!account->isEnabled()) {
+        return i18n("Click checkbox to enable");
+    }
+    else if (account->connectionStatusReason() == Tp::ConnectionStatusReasonRequested) {
+        return QString();
+    }
+    else {
+        return KTp::ErrorDictionary::displayShortErrorMessage(account->connectionError());
+    }
+}
+
 #include "accounts-list-model.moc"
diff --git a/src/accounts-list-model.h b/src/accounts-list-model.h
index ee8ce22..66b84ef 100644
--- a/src/accounts-list-model.h
+++ b/src/accounts-list-model.h
@@ -26,6 +26,7 @@
 #include <TelepathyQt/Account>
 
 class AccountItem;
+class KIcon;
 
 class AccountsListModel : public QAbstractListModel
 {
@@ -57,7 +58,11 @@ private Q_SLOTS:
     void onAccountItemUpdated();
 
 private:
-    QList<AccountItem*> m_accounts;
+    QList<Tp::AccountPtr> m_accounts;
+
+    const QString connectionStateString(const Tp::AccountPtr &account) const;
+    const KIcon connectionStateIcon(const Tp::AccountPtr &account) const;
+    const QString connectionStatusReason(const Tp::AccountPtr &account) const;
 };
 
 Q_DECLARE_METATYPE(Tp::AccountPtr)

-- 
ktp-accounts-kcm packaging



More information about the pkg-kde-commits mailing list