[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:47 UTC 2016


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

The following commit has been merged in the master branch:
commit 6b95b821a23acb82f6de0d476a5f63a1debd969c
Author: David Edmundson <kde at davidedmundson.co.uk>
Date:   Mon Oct 1 00:46:14 2012 +0100

    Make AccountsModelItem private and instead expose a role of just the AccountPtr
    
    This means AccountsItem can be private, ready for the move to extragear.
    Also fixes a potential crash if the account is removed whilst editing as EditAccountDialog stores the AccountPtr which is ref counted.
---
 src/account-item.cpp           |  8 --------
 src/account-item.h             |  1 -
 src/accounts-list-delegate.cpp |  2 +-
 src/accounts-list-model.cpp    |  6 +++---
 src/accounts-list-model.h      |  3 ++-
 src/edit-account-dialog.cpp    | 33 +++++++++++++++++----------------
 src/edit-account-dialog.h      |  2 +-
 src/kcm-telepathy-accounts.cpp | 35 ++++++++++++++++++++++++-----------
 8 files changed, 48 insertions(+), 42 deletions(-)

diff --git a/src/account-item.cpp b/src/account-item.cpp
index 8efc78f..f67ecf6 100644
--- a/src/account-item.cpp
+++ b/src/account-item.cpp
@@ -78,14 +78,6 @@ Tp::AccountPtr AccountItem::account() const
     return m_account;
 }
 
-Tp::PendingOperation* AccountItem::remove()
-{
-    QList<Tp::PendingOperation*> ops;
-    ops.append(KTp::WalletUtils::removeAccountPassword(m_account));
-    ops.append(m_account->remove());
-    return new Tp::PendingComposite(ops, m_account);
-}
-
 const KIcon& AccountItem::icon() const
 {
     Q_ASSERT(m_icon != 0);
diff --git a/src/account-item.h b/src/account-item.h
index a2fee83..b84adee 100644
--- a/src/account-item.h
+++ b/src/account-item.h
@@ -42,7 +42,6 @@ public:
     explicit AccountItem(const Tp::AccountPtr &account, AccountsListModel *parent = 0);
     virtual ~AccountItem();
     Tp::AccountPtr account() const;
-    Tp::PendingOperation* remove();
     const KIcon& icon() const;
     Tp::ConnectionStatus connectionStatus() const;
     const QString connectionStateString() const;
diff --git a/src/accounts-list-delegate.cpp b/src/accounts-list-delegate.cpp
index a233329..d157ce3 100644
--- a/src/accounts-list-delegate.cpp
+++ b/src/accounts-list-delegate.cpp
@@ -130,7 +130,7 @@ void AccountsListDelegate::updateItemWidgets(const QList<QWidget *> widgets, con
     QString statusText(index.data(AccountsListModel::ConnectionStateDisplayRole).toString());
     QString displayName(index.data(Qt::DisplayRole).toString());
     QString connectionError(index.data(AccountsListModel::ConnectionErrorMessageDisplayRole).toString());
-    Tp::AccountPtr account(index.data(AccountsListModel::AccountItemRole).value<AccountItem*>()->account());
+    Tp::AccountPtr account(index.data(AccountsListModel::AccountRole).value<Tp::AccountPtr>());
 
 
     QRect outerRect(0, 0, option.rect.width(), option.rect.height());
diff --git a/src/accounts-list-model.cpp b/src/accounts-list-model.cpp
index 4a015fa..345aaec 100644
--- a/src/accounts-list-model.cpp
+++ b/src/accounts-list-model.cpp
@@ -104,8 +104,8 @@ QVariant AccountsListModel::data(const QModelIndex &index, int role) const
         data = QVariant(m_accounts.at(index.row())->connectionProtocolName());
         break;
 
-    case AccountsListModel::AccountItemRole:
-        data = QVariant::fromValue<AccountItem*>(m_accounts.at(index.row()));
+    case AccountsListModel::AccountRole:
+        data = QVariant::fromValue<Tp::AccountPtr>(account);
         break;
 
     default:
@@ -122,7 +122,7 @@ bool AccountsListModel::setData(const QModelIndex &index, const QVariant &value,
     }
     if (role == Qt::CheckStateRole) {
         //this is index from QSortFilterProxyModel
-        index.data(AccountItemRole).value<AccountItem*>()->account()->setEnabled(value.toInt() == Qt::Checked);
+        index.data(AccountRole).value<Tp::AccountPtr>()->setEnabled(value.toInt() == Qt::Checked);
         return true;
     }
 
diff --git a/src/accounts-list-model.h b/src/accounts-list-model.h
index 1078667..8937354 100644
--- a/src/accounts-list-model.h
+++ b/src/accounts-list-model.h
@@ -39,7 +39,7 @@ public:
         ConnectionStateIconRole,
         ConnectionErrorMessageDisplayRole,
         ConnectionProtocolNameRole,
-        AccountItemRole
+        AccountRole
     };
 
     explicit AccountsListModel(QObject *parent = 0);
@@ -66,6 +66,7 @@ private:
     QList<AccountItem*> m_accounts;
 };
 
+Q_DECLARE_METATYPE(Tp::AccountPtr)
 
 #endif // header guard
 
diff --git a/src/edit-account-dialog.cpp b/src/edit-account-dialog.cpp
index 5982e06..7ae763f 100644
--- a/src/edit-account-dialog.cpp
+++ b/src/edit-account-dialog.cpp
@@ -39,6 +39,7 @@
 
 #include <QtCore/QList>
 
+#include <TelepathyQt/Account>
 #include <TelepathyQt/ConnectionManager>
 #include <TelepathyQt/PendingStringList>
 
@@ -46,21 +47,21 @@ class EditAccountDialog::Private
 {
 public:
     Private()
-            : item(0), widget(0), reconnectRequired(false), kwalletReady(false)
+        :  widget(0), reconnectRequired(false), kwalletReady(false)
     {
     }
 
-    AccountItem *item;
+    Tp::AccountPtr account;
     AccountEditWidget *widget;
     bool reconnectRequired;
     bool kwalletReady;
 };
 
-EditAccountDialog::EditAccountDialog(AccountItem *item, QWidget *parent)
+EditAccountDialog::EditAccountDialog(const Tp::AccountPtr &account, QWidget *parent)
         : KDialog(parent),
           d(new Private)
 {
-    d->item = item;
+    d->account = account;
 
     connect(KTp::WalletInterface::openWallet(), SIGNAL(finished(Tp::PendingOperation*)), SLOT(onWalletOpened(Tp::PendingOperation*)));
 
@@ -80,26 +81,26 @@ void EditAccountDialog::onWalletOpened(Tp::PendingOperation *op)
     KTp::WalletInterface *walletInterface = walletOp->walletInterface();
 
     // Get the protocol's parameters and values.
-    Tp::ProtocolInfo protocolInfo = d->item->account()->protocolInfo();
+    Tp::ProtocolInfo protocolInfo = d->account->protocolInfo();
     Tp::ProtocolParameterList parameters = protocolInfo.parameters();
-    QVariantMap parameterValues = d->item->account()->parameters();
+    QVariantMap parameterValues = d->account->parameters();
 
     // Add the parameters to the model.
     ParameterEditModel *parameterModel = new ParameterEditModel(this);
-    parameterModel->addItems(parameters, d->item->account()->profile()->parameters(), parameterValues);
+    parameterModel->addItems(parameters, d->account->profile()->parameters(), parameterValues);
 
     //update the parameter model with the password from kwallet (if applicable)
     Tp::ProtocolParameter passwordParameter = parameterModel->parameter(QLatin1String("password"));
 
-    if (passwordParameter.isValid() && walletInterface->hasPassword(d->item->account())) {
+    if (passwordParameter.isValid() && walletInterface->hasPassword(d->account)) {
         QModelIndex index = parameterModel->indexForParameter(passwordParameter);
-        QString password = walletInterface->password(d->item->account());
+        QString password = walletInterface->password(d->account);
         parameterModel->setData(index, password, Qt::EditRole);
     }
 
 
     // Set up the interface
-    d->widget = new AccountEditWidget(d->item->account()->profile(),
+    d->widget = new AccountEditWidget(d->account->profile(),
                                       parameterModel,
                                       doNotConnectOnAdd,
                                       this);
@@ -123,7 +124,7 @@ void EditAccountDialog::accept()
     //remove password from setParameters as this is now stored by kwallet instead
     setParameters.remove(QLatin1String("password"));
 
-    Tp::PendingStringList *psl = d->item->account()->updateParameters(setParameters, unsetParameters);
+    Tp::PendingStringList *psl = d->account->updateParameters(setParameters, unsetParameters);
 
     kDebug() << "Set parameters:" << setParameters;
     kDebug() << "Unset parameters:" << unsetParameters;
@@ -156,9 +157,9 @@ void EditAccountDialog::onParametersUpdated(Tp::PendingOperation *op)
     QVariantMap values = d->widget->parametersSet();
 
     if (values.contains(QLatin1String("password"))) {
-        KTp::WalletUtils::setAccountPassword(d->item->account(), values[QLatin1String("password")].toString());
+        KTp::WalletUtils::setAccountPassword(d->account, values[QLatin1String("password")].toString());
     } else {
-        KTp::WalletUtils::setAccountPassword(d->item->account(), QString());
+        KTp::WalletUtils::setAccountPassword(d->account, QString());
     }
 
 
@@ -168,10 +169,10 @@ void EditAccountDialog::onParametersUpdated(Tp::PendingOperation *op)
         displayName = values[QLatin1String("account")].toString();
     }
     else {
-        displayName = d->item->account()->profile()->protocolName();
+        displayName = d->account->profile()->protocolName();
     }
 
-    Tp::PendingOperation *dnop = d->item->account()->setDisplayName(displayName);
+    Tp::PendingOperation *dnop = d->account->setDisplayName(displayName);
 
     connect(dnop,
             SIGNAL(finished(Tp::PendingOperation*)),
@@ -189,7 +190,7 @@ void EditAccountDialog::onDisplayNameUpdated(Tp::PendingOperation *op)
     Q_EMIT finished();
 
     if (d->reconnectRequired) {
-        d->item->account()->reconnect();
+        d->account->reconnect();
     }
 
     // set the dialog as accepted and exit
diff --git a/src/edit-account-dialog.h b/src/edit-account-dialog.h
index d1c370d..37b51f6 100644
--- a/src/edit-account-dialog.h
+++ b/src/edit-account-dialog.h
@@ -30,7 +30,7 @@ class EditAccountDialog : public KDialog
     Q_OBJECT
 
 public:
-    explicit EditAccountDialog(AccountItem *item, QWidget *parent = 0);
+    explicit EditAccountDialog(const Tp::AccountPtr &account, QWidget *parent = 0);
     virtual ~EditAccountDialog();
 
     virtual void setVisible(bool visible);
diff --git a/src/kcm-telepathy-accounts.cpp b/src/kcm-telepathy-accounts.cpp
index 6389a67..c60d268 100644
--- a/src/kcm-telepathy-accounts.cpp
+++ b/src/kcm-telepathy-accounts.cpp
@@ -41,13 +41,17 @@
 #include <KPixmapSequenceOverlayPainter>
 #include <KDebug>
 
+#include <KTp/wallet-utils.h>
+
 #include <TelepathyQt/Account>
 #include <TelepathyQt/AccountFactory>
 #include <TelepathyQt/PendingOperation>
 #include <TelepathyQt/PendingReady>
 #include <TelepathyQt/Types>
+#include <TelepathyQt/PendingComposite>
 #include <TelepathyQt/ConnectionManager>
 
+
 #include "salut-enabler.h"
 #include <KPixmapSequence>
 
@@ -211,9 +215,9 @@ void KCMTelepathyAccounts::onAccountEnabledChanged(const QModelIndex &index, boo
 
     if (enabled) {
         // connect the account
-        AccountItem *item = index.data(AccountsListModel::AccountItemRole).value<AccountItem*>();
-        if (item) {
-            item->account()->setRequestedPresence(Tp::Presence::available());
+        Tp::AccountPtr account = index.data(AccountsListModel::AccountRole).value<Tp::AccountPtr>();
+        if (!account.isNull()) {
+            account->setRequestedPresence(Tp::Presence::available());
         }
     }
 }
@@ -298,13 +302,14 @@ void KCMTelepathyAccounts::onEditAccountClicked()
     if (!index.isValid()) {
         return;
     }
-    AccountItem *item = index.data(AccountsListModel::AccountItemRole).value<AccountItem*>();
+    Tp::AccountPtr account = index.data(AccountsListModel::AccountRole).value<Tp::AccountPtr>();
 
-    if (!item)
+    if (account.isNull()) {
         return;
+    }
 
     // Item is OK. Edit the item.
-    EditAccountDialog dialog(item, this);
+    EditAccountDialog dialog(account, this);
     dialog.exec();
 }
 
@@ -319,13 +324,13 @@ void KCMTelepathyAccounts::onEditIdentityClicked()
         return;
     }
 
-    AccountItem *item = index.data(AccountsListModel::AccountItemRole).value<AccountItem*>();
+    Tp::AccountPtr account = index.data(AccountsListModel::AccountRole).value<Tp::AccountPtr>();
 
-    if (!item) {
+    if (account.isNull()) {
         return;
     }
 
-    AccountIdentityDialog dialog(item->account(),this);
+    AccountIdentityDialog dialog(account,this);
     dialog.exec();
 }
 
@@ -338,8 +343,16 @@ void KCMTelepathyAccounts::onRemoveAccountClicked()
                                         i18n("Remove Account"), KGuiItem(i18n("Remove Account"), QLatin1String("edit-delete")), KStandardGuiItem::cancel(),
                                         QString(), KMessageBox::Notify | KMessageBox::Dangerous) == KMessageBox::Continue)
     {
-        AccountItem *item = index.data(AccountsListModel::AccountItemRole).value<AccountItem*>();
-        item->remove();
+         Tp::AccountPtr account = index.data(AccountsListModel::AccountRole).value<Tp::AccountPtr>();
+
+         if (account.isNull()) {
+             return;
+         }
+
+         QList<Tp::PendingOperation*> ops;
+         ops.append(KTp::WalletUtils::removeAccountPassword(account));
+         ops.append(account->remove());
+         new Tp::PendingComposite(ops, account);
      }
 }
 

-- 
ktp-accounts-kcm packaging



More information about the pkg-kde-commits mailing list