File indexing completed on 2023-12-03 08:28:36
0001 /* 0002 * Presence Model - A model of settable presences. 0003 * 0004 * Copyright (C) 2016 James D. Smith <smithjd15@gmail.com> 0005 * Copyright (C) 2011 David Edmundson <kde@davidedmundson.co.uk> 0006 * 0007 * This library is free software; you can redistribute it and/or 0008 * modify it under the terms of the GNU Lesser General Public 0009 * License as published by the Free Software Foundation; either 0010 * version 2.1 of the License, or (at your option) any later version. 0011 * 0012 * This library is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 * Lesser General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU Lesser General Public 0018 * License along with this library; if not, write to the Free Software 0019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 0020 */ 0021 0022 #ifndef PRESENCEMODEL_H 0023 #define PRESENCEMODEL_H 0024 0025 #include <QAbstractListModel> 0026 #include <QVariant> 0027 0028 #include <KConfigGroup> 0029 0030 #include <KTp/presence.h> 0031 #include "ktpmodels_export.h" 0032 0033 namespace KTp 0034 { 0035 0036 class KTPMODELS_EXPORT PresenceModel : public QAbstractListModel 0037 { 0038 Q_OBJECT 0039 Q_PROPERTY(int count READ rowCount) 0040 0041 public: 0042 explicit PresenceModel(QObject *parent = nullptr); 0043 ~PresenceModel() override; 0044 0045 enum Roles { 0046 //Also supplies Qt::DisplayRole and Qt::DecorationRole 0047 PresenceRole = Qt::UserRole, 0048 IconNameRole 0049 }; 0050 0051 /** Adds a custom presence to the model, writes it to the config file, and 0052 * propagates it to other models. 0053 * @return the newly added item 0054 */ 0055 QModelIndex addPresence(const KTp::Presence &presence); 0056 0057 void removePresence(const KTp::Presence &presence); 0058 0059 /** Load all presences from disk */ 0060 void loadPresences(); 0061 0062 /** Write all presences to disk */ 0063 void syncCustomPresencesToDisk(); 0064 0065 Q_SCRIPTABLE QVariant get(int row, const QByteArray& role) const; 0066 0067 //protected: 0068 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0069 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0070 QModelIndexList match(const QModelIndex &start, int role, const QVariant &value, int hits = 1, Qt::MatchFlags flags = Qt::MatchFlags(Qt::MatchStartsWith | Qt::MatchWrap)) const override; 0071 QHash<int, QByteArray> roleNames() const override; 0072 0073 public Q_SLOTS: 0074 /** Incoming changes from other models */ 0075 void propagationChange(const QVariantList modelChange); 0076 0077 private: 0078 void modifyModel(const KTp::Presence &presence); 0079 void propagateChange(const KTp::Presence &presence); 0080 0081 /** Loads standard presences (online, away etc) into the model */ 0082 void loadDefaultPresences(); 0083 0084 /** Loads any user custom presences into the model */ 0085 void loadCustomPresences(); 0086 0087 QList<KTp::Presence> m_presences; 0088 0089 //this is wrong, KConfigGroup is a sharedptr.. 0090 KConfigGroup m_presenceGroup; 0091 }; 0092 0093 } 0094 0095 #endif // PRESENCEMODEL_H