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

List:       kde-commits
Subject:    playground/network/telepathy-accounts-kcm/src
From:       George Goldberg <grundleborg () googlemail ! com>
Date:       2009-08-03 13:19:28
Message-ID: 1249305568.038520.19017.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1006317 by gberg:

When the Edit button is clicked, display the EditAccountDialog.

 M  +20 -1     account-item.cpp  
 M  +3 -0      account-item.h  
 M  +19 -0     accounts-list-model.cpp  
 M  +1 -0      accounts-list-model.h  
 M  +1 -1      edit-account-dialog.cpp  
 M  +3 -4      edit-account-dialog.h  
 M  +23 -0     kcm-telepathy-accounts.cpp  
 M  +1 -0      kcm-telepathy-accounts.h  


--- trunk/playground/network/telepathy-accounts-kcm/src/account-item.cpp #1006316:1006317
@@ -21,7 +21,9 @@
 #include "account-item.h"
 
 #include "accounts-list-model.h"
+#include "edit-account-dialog.h"
 
+#include <KApplication>
 #include <KDebug>
 #include <KIcon>
 
@@ -34,7 +36,8 @@
 AccountItem::AccountItem(const Tp::AccountPtr &account, AccountsListModel *parent)
  : QObject(parent),
    m_account(account),
-   m_icon(new KIcon())
+   m_icon(new KIcon()),
+   m_editAccountDialog(0)
 {
     kDebug();
 
@@ -74,6 +77,22 @@
     return m_account;
 }
 
+void AccountItem::edit()
+{
+    kDebug();
+
+    // If the edit dialog already exists, focus it.
+    if (m_editAccountDialog) {
+        m_editAccountDialog->focusWidget();
+        return;
+    }
+
+    // FIXME: There should be a driving test for those who want to become parents... :'(
+    QWidget *p = qobject_cast<QWidget*>(parent()->parent());
+    m_editAccountDialog = new EditAccountDialog(this, p); // FIXME: Argh I'm going to jump off a bridge
+    m_editAccountDialog->show();
+}
+
 void AccountItem::remove()
 {
     kDebug() << "Account about to be removed";
--- trunk/playground/network/telepathy-accounts-kcm/src/account-item.h #1006316:1006317
@@ -28,6 +28,7 @@
 class KIcon;
 
 class AccountsListModel;
+class EditAccountDialog;
 
 namespace Tp {
     class PendingOperation;
@@ -42,6 +43,7 @@
     explicit AccountItem(const Tp::AccountPtr &account, AccountsListModel *parent = 0);
     virtual ~AccountItem();
     Tp::AccountPtr account() const;
+    void edit();
     void remove();
     const KIcon& icon() const;
 
@@ -58,6 +60,7 @@
 private:
     Tp::AccountPtr m_account;
     KIcon* m_icon;
+    EditAccountDialog *m_editAccountDialog;
 };
 
 
--- trunk/playground/network/telepathy-accounts-kcm/src/accounts-list-model.cpp #1006316:1006317
@@ -140,6 +140,25 @@
    }
 }
 
+void AccountsListModel::editAccount(const QModelIndex &index)
+{
+    kDebug();
+
+    if(!index.isValid()) {
+        kWarning() << "Can't edit Account: Invalid index.";
+        return;
+    }
+
+    AccountItem *accountItem = m_readyAccounts.at(index.row());
+
+    if (!accountItem) {
+        kWarning() << "Account item is null.";
+        return;
+    }
+
+    accountItem->edit();
+}
+
 void AccountsListModel::removeAccount(const QModelIndex &index)
 {
     kDebug();
--- trunk/playground/network/telepathy-accounts-kcm/src/accounts-list-model.h #1006316:1006317
@@ -40,6 +40,7 @@
     virtual Qt::ItemFlags flags(const QModelIndex &index) const;
     virtual bool setData(const QModelIndex &index, const QVariant &value, int role);
     void addAccount(const Tp::AccountPtr &account);
+    void editAccount(const QModelIndex &index);
     void removeAccount(const QModelIndex &index);
 
 private Q_SLOTS:
--- trunk/playground/network/telepathy-accounts-kcm/src/edit-account-dialog.cpp #1006316:1006317
@@ -35,7 +35,7 @@
 };
 
 EditAccountDialog::EditAccountDialog(AccountItem *item, QWidget *parent)
-        : QWidget(parent),
+        : KDialog(parent),
           d(new Private)
 {
     kDebug();
--- trunk/playground/network/telepathy-accounts-kcm/src/edit-account-dialog.h #1006316:1006317
@@ -25,15 +25,14 @@
 
 #include <kdemacros.h>
 
-#include <QtGui/QWidget>
+#include <KDialog>
 
-class KDE_EXPORT EditAccountDialog : public QWidget
+class KDE_EXPORT EditAccountDialog : public KDialog
 {
     Q_OBJECT
 
 public:
-    explicit EditAccountDialog(AccountItem *item,
-                               QWidget *parent = 0);
+    explicit EditAccountDialog(AccountItem *item, QWidget *parent = 0);
     virtual ~EditAccountDialog();
 
 private:
--- trunk/playground/network/telepathy-accounts-kcm/src/kcm-telepathy-accounts.cpp #1006316:1006317
@@ -65,6 +65,9 @@
     connect(m_addAccountButton,
             SIGNAL(clicked()),
             SLOT(onAddAccountClicked()));
+    connect(m_editAccountButton,
+            SIGNAL(clicked()),
+            SLOT(onEditAccountClicked()));
     connect(m_removeAccountButton,
             SIGNAL(clicked()),
             SLOT(onRemoveAccountClicked()));
@@ -155,6 +158,26 @@
     kWarning() << "Cannot create a new AddAccountAssistant. One already exists.";
 }
 
+void KCMTelepathyAccounts::onEditAccountClicked()
+{
+    kDebug();
+
+    // Editing accounts is only possible if the Account Manager is ready.
+    if (!m_accountManager->isReady()) {
+        return;
+    }
+
+    QModelIndex index = m_accountsListView->currentIndex();
+
+    // A valid account must be selected in the list to allow editing
+    if (!index.isValid()) {
+        return;
+    }
+
+    // Item is OK. Edit the item.
+    m_accountsListModel->editAccount(index);
+}
+
 void KCMTelepathyAccounts::onRemoveAccountClicked()
 {
     kDebug();
--- trunk/playground/network/telepathy-accounts-kcm/src/kcm-telepathy-accounts.h #1006316:1006317
@@ -53,6 +53,7 @@
 
     void onSelectedItemChanged();
     void onAddAccountClicked();
+    void onEditAccountClicked();
     void onRemoveAccountClicked();
     void onAddAccountAssistantClosed();
 
[prev in list] [next in list] [prev in thread] [next in thread] 

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