[SCM] ktp-common-internals packaging branch, master, updated. debian/15.12.1-2-1839-gf0635e9

Maximiliano Curia maxy at moszumanska.debian.org
Mon May 9 09:06:21 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=6f15963

The following commit has been merged in the master branch:
commit 6f15963252a65cc0d853a3dca81612457b5d56b9
Author: David Edmundson <kde at davidedmundson.co.uk>
Date:   Wed Feb 6 22:02:19 2013 +0000

    Add a class to instantly access the grouped, filtered contacts list model without having to handle proxies manually.
    This was previously used in ktp-contact-list during porting.
    
    Longer term this will also handle including the MessageModelSource proxy, and possible KPeople.
    
    REVIEW: 108790
---
 KTp/Models/CMakeLists.txt     |   2 +
 KTp/Models/contacts-model.cpp | 108 ++++++++++++++++++++++++++++++++++++++++++
 KTp/Models/contacts-model.h   |  78 ++++++++++++++++++++++++++++++
 KTp/types.h                   |   4 +-
 4 files changed, 190 insertions(+), 2 deletions(-)

diff --git a/KTp/Models/CMakeLists.txt b/KTp/Models/CMakeLists.txt
index 59888f6..0d305e6 100644
--- a/KTp/Models/CMakeLists.txt
+++ b/KTp/Models/CMakeLists.txt
@@ -9,6 +9,7 @@ set (ktp_models_private_SRCS
     accounts-tree-proxy-model.cpp
     contacts-filter-model.cpp
     contacts-list-model.cpp
+    contacts-model.cpp
     groups-tree-proxy-model.cpp
     rooms-model.cpp
 )
@@ -19,6 +20,7 @@ set (ktp_models_private_HDRS
     accounts-tree-proxy-model.h
     contacts-filter-model.h
     contacts-list-model.h
+    contacts-model.h
     groups-tree-proxy-model.h
     rooms-model.h
 )
diff --git a/KTp/Models/contacts-model.cpp b/KTp/Models/contacts-model.cpp
new file mode 100644
index 0000000..dd633f5
--- /dev/null
+++ b/KTp/Models/contacts-model.cpp
@@ -0,0 +1,108 @@
+/*
+ * Model of all accounts with inbuilt grouping and filtering
+ *
+ * Copyright (C) 2013 David Edmundson <kde at davidedmundson.co.uk>
+ *
+ * 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 "contacts-model.h"
+
+#include "contacts-list-model.h"
+#include "accounts-tree-proxy-model.h"
+#include "groups-tree-proxy-model.h"
+
+namespace KTp
+{
+class ContactsModel::Private
+{
+public:
+    GroupMode groupMode;
+    QWeakPointer<KTp::AbstractGroupingProxyModel> proxy;
+    KTp::ContactsListModel *source;
+    Tp::AccountManagerPtr accountManager;
+};
+}
+
+
+KTp::ContactsModel::ContactsModel(QObject *parent)
+    : KTp::ContactsFilterModel(parent),
+      d(new Private)
+{
+    d->groupMode = NoGrouping;
+    d->source = new KTp::ContactsListModel(this);
+}
+
+KTp::ContactsModel::~ContactsModel()
+{
+    delete d;
+}
+
+
+void KTp::ContactsModel::setAccountManager(const Tp::AccountManagerPtr &accountManager)
+{
+    d->accountManager = accountManager;
+
+    updateGroupProxyModels();
+
+    //set the account manager after we've reloaded the groups so that we don't send a list to the view, only to replace it with a grouped tree
+    d->source->setAccountManager(accountManager);
+}
+
+void KTp::ContactsModel::setGroupMode(KTp::ContactsModel::GroupMode mode)
+{
+    if (mode == d->groupMode) {
+        //if nothing has changed, do nothing.
+        return;
+    }
+
+    d->groupMode = mode;
+
+    updateGroupProxyModels();
+
+    Q_EMIT groupModeChanged();
+}
+
+void KTp::ContactsModel::updateGroupProxyModels()
+{
+    //if there no account manager there's not a lot point doing anything
+    if (!d->accountManager) {
+        return;
+    }
+
+    //delete any previous proxy
+    if (d->proxy) {
+        d->proxy.data()->deleteLater();
+    }
+
+    switch (d->groupMode) {
+    case NoGrouping:
+        setSourceModel(d->source);
+        break;
+    case AccountGrouping:
+        d->proxy = new KTp::AccountsTreeProxyModel(d->source, d->accountManager);
+        setSourceModel(d->proxy.data());
+        break;
+    case GroupGrouping:
+        d->proxy = new KTp::GroupsTreeProxyModel(d->source);
+        setSourceModel(d->proxy.data());
+        break;
+    }
+}
+
+KTp::ContactsModel::GroupMode KTp::ContactsModel::groupMode() const
+{
+    return d->groupMode;
+}
diff --git a/KTp/Models/contacts-model.h b/KTp/Models/contacts-model.h
new file mode 100644
index 0000000..ad3205c
--- /dev/null
+++ b/KTp/Models/contacts-model.h
@@ -0,0 +1,78 @@
+/*
+ * Model of all accounts with inbuilt grouping and filtering
+ *
+ * Copyright (C) 2013 David Edmundson <kde at davidedmundson.co.uk>
+ *
+ * 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 KTP_CONTACTS_MODEL_H
+#define KTP_CONTACTS_MODEL_H
+
+#include <KTp/Models/contacts-filter-model.h>
+#include <KTp/types.h>
+#include <KTp/ktp-export.h>
+
+namespace KTp
+{
+
+/** This class combines the list model and all the relevant filtering into a simple to use class
+    In most cases you should use this as the entry point to the models in your application
+ */
+
+class KTP_EXPORT ContactsModel : public KTp::ContactsFilterModel
+{
+    Q_OBJECT
+    Q_PROPERTY(GroupMode groupMode READ groupMode WRITE setGroupMode NOTIFY groupModeChanged)
+    Q_PROPERTY(Tp::AccountManagerPtr accountManager WRITE setAccountManager)
+
+    Q_ENUMS(GroupMode)
+
+public:
+    enum GroupMode {
+        /** Contacts are not grouped and are a simple flat list*/
+        NoGrouping,
+        /** Contacts are grouped by their account using AccountsTreeProxyModel*/
+        AccountGrouping,
+        /** Contacts are grouped by their group name using GroupsTreeProxyModel*/
+        GroupGrouping
+    };
+
+    ContactsModel(QObject *parent);
+
+    virtual ~ContactsModel();
+
+    /** Sets the accounts manager to be used for the KTp::ContactListModel*/
+    void setAccountManager(const Tp::AccountManagerPtr &accountManager);
+
+    /** Specify how the contacts should be grouped together*/
+    void setGroupMode(GroupMode mode);
+
+    /** The currently specified grouping model*/
+    GroupMode groupMode() const;
+
+Q_SIGNALS:
+    void groupModeChanged();
+
+private:
+    class Private;
+    Private *d;
+
+    void updateGroupProxyModels();
+};
+
+}
+
+#endif // KTP_CONTACTS_MODEL_H
diff --git a/KTp/types.h b/KTp/types.h
index 9d76328..4ef0002 100644
--- a/KTp/types.h
+++ b/KTp/types.h
@@ -52,12 +52,12 @@ namespace KTp
         ContactClientTypesRole = Qt::UserRole + 2000, ///< stringlist. See Tp::Contact::ClientTypes
         ContactAvatarPathRole, ///<string. path to avatar file
         ContactGroupsRole, ///< stringlist. of all groups contact is in
-        
+
         ContactPresenceNameRole,
         ContactPresenceMessageRole,
         ContactPresenceTypeRole,
         ContactPresenceIconRole,
-        
+
         ContactSubscriptionStateRole, ///< enum of type Tp::Contact::PresenceState
         ContactPublishStateRole, ///< enum of type Tp::Contact::PresenceState
         ContactIsBlockedRole, ///< bool, true if contact is blocked

-- 
ktp-common-internals packaging



More information about the pkg-kde-commits mailing list