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

List:       kde-commits
Subject:    playground/network/kcall
From:       George Kiagiadakis <gkiagiad () csd ! uoc ! gr>
Date:       2009-08-01 17:31:40
Message-ID: 1249147900.508818.18371.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1005659 by gkiagia:

- Add an AccountManager class in libkcallprivate that will handle internally \
                everything related to accounts and connections.
- Remove the ContactsModel and use the new AccountManager to provide models for \
                accounts and contacts.
- Do some extra refactoring/cleanup in most libkcallprivate classes.

 M  +1 -1      contactlistcontroller.cpp  
 M  +5 -31     kcallapplication.cpp  
 M  +2 -6      kcallapplication.h  
 M  +1 -1      libkcallprivate/CMakeLists.txt  
 M  +31 -6     libkcallprivate/accountitem.cpp  
 M  +6 -4      libkcallprivate/accountitem.h  
 A             libkcallprivate/accountmanager.cpp   [License: LGPL (v2.1+)]
 A             libkcallprivate/accountmanager.h   \
libkcallprivate/contactsmodel.h#1004729 [License: LGPL (v2.1+)]  A             \
libkcallprivate/constants.h   libkcallprivate/contactitem.h#1004729 [License: LGPL \
(v2.1+)]  M  +30 -3     libkcallprivate/contactitem.cpp  
 M  +9 -3      libkcallprivate/contactitem.h  
 D             libkcallprivate/contactsmodel.cpp  
 D             libkcallprivate/contactsmodel.h  
 M  +3 -3      libkcallprivate/groupmembersmodel.cpp  
 M  +1 -0      libkcallprivate/groupmembersmodel.h  
 M  +12 -3     libkcallprivate/treemodel.cpp  
 M  +2 -19     libkcallprivate/treemodel.h  
 M  +7 -7      mainwindow.cpp  


--- trunk/playground/network/kcall/contactlistcontroller.cpp #1005658:1005659
@@ -15,7 +15,7 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 #include "contactlistcontroller.h"
-#include "libkcallprivate/contactsmodel.h"
+#include "libkcallprivate/constants.h"
 #include <QtGui/QAbstractItemView>
 #include <KDebug>
 #include <KIcon>
--- trunk/playground/network/kcall/kcallapplication.cpp #1005658:1005659
@@ -18,17 +18,14 @@
 #include "mainwindow.h"
 #include "systrayicon.h"
 #include "knotifyapprover.h"
-#include "libkcallprivate/contactsmodel.h"
+#include "libkcallprivate/accountmanager.h"
 #include <KDebug>
-#include <TelepathyQt4/AccountManager>
-#include <TelepathyQt4/PendingReady>
 #include <TelepathyQt4/ClientRegistrar>
 
 struct KCallApplication::Private
 {
     QPointer<MainWindow> mainWindow;
-    ContactsModel *contactsModel;
-    Tp::AccountManagerPtr accountManager;
+    AccountManager *accountManager;
     Tp::ClientRegistrarPtr registrar;
     Tp::SharedPtr<SystrayIcon> systrayIcon;
     Tp::SharedPtr<KNotifyApprover> knotifyApprover;
@@ -38,11 +35,7 @@
     : KUniqueApplication(), d(new Private)
 {
     d->mainWindow = NULL;
-    d->contactsModel = new ContactsModel(this);
-    d->accountManager = Tp::AccountManager::create();
-    connect(d->accountManager->becomeReady(),
-            SIGNAL(finished(Tp::PendingOperation *)),
-            SLOT(onAccountManagerReady(Tp::PendingOperation *)));
+    d->accountManager = new AccountManager(this);
 
     d->registrar = Tp::ClientRegistrar::create();
     d->systrayIcon = Tp::SharedPtr<SystrayIcon>(new SystrayIcon());
@@ -65,9 +58,9 @@
     return 0;
 }
 
-ContactsModel *KCallApplication::contactsModel() const
+AccountManager *KCallApplication::accountManager() const
 {
-    return d->contactsModel;
+    return d->accountManager;
 }
 
 void KCallApplication::showHideMainWindow()
@@ -80,23 +73,4 @@
     }
 }
 
-void KCallApplication::onAccountManagerReady(Tp::PendingOperation *op)
-{
-    if ( op->isError() ) {
-        kError() << "Account manager failed to become ready:" << op->errorMessage();
-        return; //TODO handle this error
-    }
-
-    foreach(const QString & a, d->accountManager->validAccountPaths()) {
-        d->contactsModel->addAccount(d->accountManager->busName(), a);
-    }
-
-    connect(d->accountManager.data(), SIGNAL(accountCreated(QString)), \
                SLOT(onAccountCreated(QString)));
-}
-
-void KCallApplication::onAccountCreated(const QString & path)
-{
-    d->contactsModel->addAccount(d->accountManager->busName(), path);
-}
-
 #include "kcallapplication.moc"
--- trunk/playground/network/kcall/kcallapplication.h #1005658:1005659
@@ -19,7 +19,7 @@
 
 #include <KUniqueApplication>
 namespace Tp { class PendingOperation; }
-class ContactsModel;
+class AccountManager;
 
 class KCallApplication : public KUniqueApplication
 {
@@ -29,7 +29,7 @@
     virtual ~KCallApplication();
 
     virtual int newInstance();
-    ContactsModel *contactsModel() const;
+    AccountManager *accountManager() const;
 
     static inline KCallApplication *instance()
     { return static_cast<KCallApplication*>(QCoreApplication::instance()); }
@@ -37,10 +37,6 @@
 public slots:
     void showHideMainWindow();
 
-private slots:
-    void onAccountManagerReady(Tp::PendingOperation *op);
-    void onAccountCreated(const QString & path);
-
 private:
     struct Private;
     Private *const d;
--- trunk/playground/network/kcall/libkcallprivate/CMakeLists.txt #1005658:1005659
@@ -3,7 +3,7 @@
 
 set(libkcallprivate_SRCS
     treemodel.cpp
-    contactsmodel.cpp
+    accountmanager.cpp
     pendingcontacts.cpp
     accountitem.cpp
     contactitem.cpp
--- trunk/playground/network/kcall/libkcallprivate/accountitem.cpp #1005658:1005659
@@ -17,15 +17,16 @@
 #include "accountitem.h"
 #include "pendingcontacts.h"
 #include "contactitem.h"
+#include "constants.h"
 #include <KLocalizedString>
+#include <KIcon>
 #include <KDebug>
 #include <TelepathyQt4/PendingReady>
 
-AccountItem::AccountItem(const QString & busName, const QString & path,
-                         TreeModelItem *parent, TreeModel *model)
-    : ContactsModelItem(parent, model)
+AccountItem::AccountItem(const Tp::AccountPtr & account, TreeModelItem *parent)
+    : QObject(), TreeModelItem(parent)
 {
-    m_account = Tp::Account::create(busName, path);
+    m_account = account;
     connect(m_account->becomeReady(), SIGNAL(finished(Tp::PendingOperation*)),
             SLOT(onAccountReady(Tp::PendingOperation*)));
 }
@@ -49,7 +50,10 @@
                              m_account->protocol(), m_account->displayName());
             }
         case Qt::DecorationRole:
-            return iconForPresence((Tp::ConnectionPresenceType)data(KCall::PresenceRole).value<Tp::SimplePresence>().type);
 +        {
+            uint presenceType = \
data(KCall::PresenceRole).value<Tp::SimplePresence>().type; +            return \
KIcon(iconForPresence(presenceType)); +        }
         case KCall::PresenceRole:
         {
             Tp::SimplePresence presence = m_account->currentPresence();
@@ -146,9 +150,30 @@
 
     QVector<TreeModelItem*> contactItems;
     foreach(const Tp::ContactPtr & contact, pc->contacts()) {
-        contactItems.append(new ContactItem(contact, this, model()));
+        contactItems.append(new ContactItem(contact, this));
     }
     appendChildren(contactItems);
 }
 
+QString AccountItem::iconForPresence(uint presenceType) const
+{
+    switch (presenceType) {
+    case Tp::ConnectionPresenceTypeOffline:
+        return QLatin1String("user-offline");
+    case Tp::ConnectionPresenceTypeAvailable:
+        return QLatin1String("user-online");
+    case Tp::ConnectionPresenceTypeAway:
+        return QLatin1String("user-away");
+    case Tp::ConnectionPresenceTypeExtendedAway:
+        return QLatin1String("user-away-extended");
+    case Tp::ConnectionPresenceTypeHidden:
+        return QLatin1String("user-invisible");
+    case Tp::ConnectionPresenceTypeBusy:
+        return QLatin1String("user-busy");
+    default:
+        kWarning() << "presence type is unset/unknown/invalid. value:" << \
presenceType; +        return QString();
+    }
+}
+
 #include "accountitem.moc"
--- trunk/playground/network/kcall/libkcallprivate/accountitem.h #1005658:1005659
@@ -17,15 +17,14 @@
 #ifndef ACCOUNTITEM_H
 #define ACCOUNTITEM_H
 
-#include "contactsmodel.h"
+#include "treemodel.h"
 #include <TelepathyQt4/Account>
 
-class AccountItem : public ContactsModelItem
+class AccountItem : public QObject, public TreeModelItem
 {
     Q_OBJECT
 public:
-    AccountItem(const QString & busName, const QString & path,
-                TreeModelItem *parent, TreeModel *model);
+    AccountItem(const Tp::AccountPtr & account, TreeModelItem *parent);
 
     virtual QVariant data(int role) const;
 
@@ -35,8 +34,11 @@
     void onContactsReady(Tp::PendingOperation*);
     void onAccountInvalidated(Tp::DBusProxy *proxy, const QString & errorName,
                               const QString & errorMessage);
+    //make emitDataChange available as a slot
+    inline void emitDataChange() { TreeModelItem::emitDataChange(); }
 
 private:
+    QString iconForPresence(uint presenceType) const;
     Tp::AccountPtr m_account;
 };
 
--- trunk/playground/network/kcall/libkcallprivate/contactitem.cpp #1005658:1005659
@@ -15,9 +15,13 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 #include "contactitem.h"
+#include "constants.h"
+#include <KIcon>
+#include <KDebug>
+#include <TelepathyQt4/Constants>
 
-ContactItem::ContactItem(const Tp::ContactPtr & contact, TreeModelItem *parent, \
                TreeModel *model)
-    : ContactsModelItem(parent, model), m_contact(contact)
+ContactItem::ContactItem(const Tp::ContactPtr & contact, TreeModelItem *parent)
+    : QObject(), TreeModelItem(parent), m_contact(contact)
 {
     connect(m_contact.data(), SIGNAL(aliasChanged(QString)), \
                SLOT(emitDataChange()));
     connect(m_contact.data(), SIGNAL(simplePresenceChanged(QString, uint, QString)),
@@ -30,7 +34,7 @@
     case Qt::DisplayRole:
         return m_contact->alias();
     case Qt::DecorationRole:
-        return iconForPresence((Tp::ConnectionPresenceType)m_contact->presenceType());
 +        return KIcon(iconForPresence(m_contact->presenceType()));
     case KCall::ItemTypeRole:
         return QByteArray("contact");
     case KCall::ObjectPtrRole:
@@ -39,3 +43,26 @@
         return QVariant();
     }
 }
+
+QString ContactItem::iconForPresence(uint presenceType) const
+{
+    switch (presenceType) {
+    case Tp::ConnectionPresenceTypeOffline:
+        return QLatin1String("user-offline");
+    case Tp::ConnectionPresenceTypeAvailable:
+        return QLatin1String("user-online");
+    case Tp::ConnectionPresenceTypeAway:
+        return QLatin1String("user-away");
+    case Tp::ConnectionPresenceTypeExtendedAway:
+        return QLatin1String("user-away-extended");
+    case Tp::ConnectionPresenceTypeHidden:
+        return QLatin1String("user-invisible");
+    case Tp::ConnectionPresenceTypeBusy:
+        return QLatin1String("user-busy");
+    default:
+        kWarning() << "presence type is unset/unknown/invalid. value:" << \
presenceType; +        return QString();
+    }
+}
+
+#include "contactitem.moc"
--- trunk/playground/network/kcall/libkcallprivate/contactitem.h #1005658:1005659
@@ -17,17 +17,23 @@
 #ifndef CONTACTITEM_H
 #define CONTACTITEM_H
 
-#include "contactsmodel.h"
+#include "treemodel.h"
 #include <TelepathyQt4/Contact>
 
-class ContactItem : public ContactsModelItem
+class ContactItem : public QObject, public TreeModelItem
 {
+    Q_OBJECT
 public:
-    ContactItem(const Tp::ContactPtr & contact, TreeModelItem *parent, TreeModel \
*model); +    ContactItem(const Tp::ContactPtr & contact, TreeModelItem *parent);
 
     virtual QVariant data(int role) const;
 
+protected slots:
+    //make emitDataChange available as a slot
+    inline void emitDataChange() { TreeModelItem::emitDataChange(); }
+
 private:
+    QString iconForPresence(uint presenceType) const;
     Tp::ContactPtr m_contact;
 };
 
--- trunk/playground/network/kcall/libkcallprivate/groupmembersmodel.cpp \
#1005658:1005659 @@ -21,8 +21,8 @@
 {
 public:
     inline GroupContactItem(const Tp::ContactPtr & contact, \
                KCall::GroupMembersListType listType,
-                            TreeModelItem *parent, TreeModel *model)
-        : ContactItem(contact, parent, model), m_listType(listType)
+                            TreeModelItem *parent)
+        : ContactItem(contact, parent), m_listType(listType)
     {
     }
 
@@ -90,7 +90,7 @@
     if ( d->contactItems.contains(contact->id()) ) {
         d->contactItems[contact->id()]->setListType(listType);
     } else {
-        GroupContactItem *item = new GroupContactItem(contact, listType, root(), \
this); +        GroupContactItem *item = new GroupContactItem(contact, listType, \
root());  d->contactItems[contact->id()] = item;
         root()->appendChild(item);
     }
--- trunk/playground/network/kcall/libkcallprivate/groupmembersmodel.h \
#1005658:1005659 @@ -18,6 +18,7 @@
 #define GROUPMEMBERSMODEL_H
 
 #include "treemodel.h"
+#include "constants.h"
 #include <TelepathyQt4/Channel>
 
 class KCALLPRIVATE_EXPORT GroupMembersModel : public TreeModel
--- trunk/playground/network/kcall/libkcallprivate/treemodel.cpp #1005658:1005659
@@ -26,13 +26,22 @@
     QList<TreeModelItem*> children;
 };
 
-TreeModelItem::TreeModelItem(TreeModelItem *parent, TreeModel *model)
+TreeModelItem::TreeModelItem(TreeModel *model)
     : d(new Private)
 {
-    d->parent = parent;
+    Q_ASSERT(model);
+    d->parent = NULL;
     d->model = model;
 }
 
+TreeModelItem::TreeModelItem(TreeModelItem *parent)
+    : d(new Private)
+{
+    Q_ASSERT(parent && parent->model());
+    d->parent = parent;
+    d->model = parent->model();
+}
+
 TreeModelItem::~TreeModelItem()
 {
     qDeleteAll(d->children);
@@ -143,7 +152,7 @@
 TreeModel::TreeModel(QObject *parent)
     : QAbstractItemModel(parent)
 {
-    m_root = new TreeModelItem(NULL, this);
+    m_root = new TreeModelItem(this);
 }
 
 TreeModel::~TreeModel()
--- trunk/playground/network/kcall/libkcallprivate/treemodel.h #1005658:1005659
@@ -25,7 +25,8 @@
 {
     Q_DISABLE_COPY(TreeModelItem);
 public:
-    TreeModelItem(TreeModelItem *parent, TreeModel *model);
+    TreeModelItem(TreeModel *model);
+    TreeModelItem(TreeModelItem *parent);
     virtual ~TreeModelItem();
 
     virtual QVariant data(int role) const;
@@ -75,22 +76,4 @@
     TreeModelItem *m_root;
 };
 
-namespace KCall
-{
-    enum ExtraModelRoles {
-        ItemTypeRole = Qt::UserRole,
-        ObjectPtrRole,
-        GroupMembersListTypeRole,
-        PresenceRole
-    };
-
-    enum GroupMembersListType {
-        CurrentMembers,
-        LocalPendingMembers,
-        RemotePendingMembers
-    };
-}
-
-Q_DECLARE_METATYPE(KCall::GroupMembersListType)
-
 #endif
--- trunk/playground/network/kcall/mainwindow.cpp #1005658:1005659
@@ -18,7 +18,8 @@
 #include "ui_mainwindow.h"
 #include "kcallapplication.h"
 #include "contactlistcontroller.h"
-#include "libkcallprivate/contactsmodel.h"
+#include "libkcallprivate/accountmanager.h"
+#include "libkcallprivate/constants.h"
 #include <KStatusBar>
 #include <KAction>
 #include <KActionCollection>
@@ -37,10 +38,11 @@
     ui->setupUi(centralWidget);
     setCentralWidget(centralWidget);
 
-    ui->contactsTreeView->setModel(KCallApplication::instance()->contactsModel());
-    new ContactListController(ui->contactsTreeView, \
KCallApplication::instance()->contactsModel()); +    QAbstractItemModel *model = \
KCallApplication::instance()->accountManager()->contactsModel(); +    \
ui->contactsTreeView->setModel(model); +    new \
ContactListController(ui->contactsTreeView, model);  
-    ui->accountComboBox->setModel(KCallApplication::instance()->contactsModel());
+    ui->accountComboBox->setModel(model);
     connect(ui->dialAudioButton, SIGNAL(clicked()), \
                SLOT(onDialAudioButtonClicked()));
     connect(ui->dialVideoButton, SIGNAL(clicked()), \
SLOT(onDialVideoButtonClicked()));  
@@ -85,9 +87,7 @@
         return;
     }
 
-    TreeModel *model = qobject_cast<TreeModel*>(ui->accountComboBox->model());
-    Q_ASSERT(model);
-
+    QAbstractItemModel *model = ui->accountComboBox->model();
     Tp::AccountPtr account = model->index(row, \
0).data(KCall::ObjectPtrRole).value<Tp::AccountPtr>();  Q_ASSERT( !account.isNull() \
);  


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

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