File indexing completed on 2023-11-26 08:16:44

0001 /*
0002  * Model of all accounts with inbuilt grouping and filtering
0003  *
0004  * Copyright (C) 2013 David Edmundson <kde@davidedmundson.co.uk>
0005  *
0006  * This library is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU Lesser General Public
0008  * License as published by the Free Software Foundation; either
0009  * version 2.1 of the License, or (at your option) any later version.
0010  *
0011  * This library is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014  * Lesser General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU Lesser General Public
0017  * License along with this library; if not, write to the Free Software
0018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
0019  */
0020 
0021 #ifndef KTP_CONTACTS_MODEL_H
0022 #define KTP_CONTACTS_MODEL_H
0023 
0024 #include <KTp/Models/contacts-filter-model.h>
0025 #include <KTp/types.h>
0026 #include <KTp/Models/ktpmodels_export.h>
0027 
0028 namespace KTp
0029 {
0030 
0031 /** This class combines the list model and all the relevant filtering into a simple to use class
0032     In most cases you should use this as the entry point to the models in your application
0033  */
0034 
0035 class KTPMODELS_EXPORT ContactsModel : public KTp::ContactsFilterModel
0036 {
0037     Q_OBJECT
0038     Q_PROPERTY(GroupMode groupMode READ groupMode WRITE setGroupMode NOTIFY groupModeChanged)
0039     Q_PROPERTY(bool trackUnreadMessages READ trackUnreadMessages WRITE setTrackUnreadMessages NOTIFY trackUnreadMessagesChanged)
0040 
0041     Q_PROPERTY(Tp::AccountManagerPtr accountManager READ accountManager WRITE setAccountManager)
0042 
0043     Q_ENUMS(GroupMode)
0044 
0045 public:
0046     enum GroupMode {
0047         /** Contacts are not grouped and are a simple flat list*/
0048         NoGrouping,
0049         /** Contacts are grouped by their account using AccountsTreeProxyModel*/
0050         AccountGrouping,
0051         /** Contacts are grouped by their group name using GroupsTreeProxyModel*/
0052         GroupGrouping
0053     };
0054 
0055     ContactsModel(QObject *parent=nullptr);
0056 
0057     ~ContactsModel() override;
0058 
0059     /** Sets the accounts manager to be used for the KTp::ContactListModel*/
0060     void setAccountManager(const Tp::AccountManagerPtr &accountManager);
0061 
0062     /** Returns account manager currently used by the model */
0063     Tp::AccountManagerPtr accountManager() const;
0064 
0065     /** Specify how the contacts should be grouped together*/
0066     void setGroupMode(GroupMode mode);
0067 
0068     /** The currently specified grouping model*/
0069     GroupMode groupMode() const;
0070 
0071     /** Specify whether to track unread messages or not. Note this adds additional overhead, so only use it if you're going to show the information
0072       * Default is False
0073     */
0074     void setTrackUnreadMessages(bool trackUnread);
0075     bool trackUnreadMessages() const;
0076     QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
0077 
0078 Q_SIGNALS:
0079     void modelInitialized(bool success);
0080     void groupModeChanged();
0081     void trackUnreadMessagesChanged();
0082 
0083 private:
0084     class Private;
0085     Private *d;
0086 
0087     void updateGroupProxyModels();
0088 };
0089 
0090 }
0091 
0092 #endif // KTP_CONTACTS_MODEL_H