File indexing completed on 2023-11-26 08:16:43
0001 /* 0002 * This file is part of ktp-common-internals 0003 * 0004 * Copyright (C) 2009 Collabora Ltd. <info@collabora.com> 0005 * Copyright (C) 2012 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 KTP_ACCOUNTS_LIST_MODEL_H 0023 #define KTP_ACCOUNTS_LIST_MODEL_H 0024 0025 #include <QAbstractListModel> 0026 #include <QVariant> 0027 0028 #include <KTp/Models/ktpmodels_export.h> 0029 #include <KTp/types.h> 0030 0031 namespace KTp 0032 { 0033 0034 class KTPMODELS_EXPORT AccountsListModel : public QAbstractListModel 0035 { 0036 Q_OBJECT 0037 Q_PROPERTY(int count READ rowCount); 0038 Q_DISABLE_COPY(AccountsListModel); 0039 0040 public: 0041 enum Roles { 0042 ConnectionStateRole = Qt::UserRole, 0043 ConnectionStateDisplayRole = Qt::UserRole+1, 0044 ConnectionStateIconRole, 0045 ConnectionErrorMessageDisplayRole, 0046 ConnectionProtocolNameRole, 0047 StatusHandlerSessionPresenceRole, 0048 StatusHandlerPresenceRole, 0049 RequestedPresenceRole, 0050 IconNameRole, 0051 EnabledRole, 0052 AccountRole 0053 }; 0054 0055 explicit AccountsListModel(QObject *parent = nullptr); 0056 ~AccountsListModel() override; 0057 0058 QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE; 0059 void setAccountSet(const Tp::AccountSetPtr &accountSet); 0060 0061 Q_SCRIPTABLE QVariant get(int row, const QByteArray& role) const; 0062 0063 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0064 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0065 bool setData(const QModelIndex &index, const QVariant &value, int role) override; 0066 0067 private Q_SLOTS: 0068 void onAccountAdded(const Tp::AccountPtr &account); 0069 void onAccountRemoved(const Tp::AccountPtr &account); 0070 void onAccountUpdated(); 0071 0072 private: 0073 class Private; 0074 Private * const d; 0075 0076 const QString connectionStateString(const Tp::AccountPtr &account) const; 0077 const QIcon connectionStateIcon(const Tp::AccountPtr &account) const; 0078 const QString connectionStatusReason(const Tp::AccountPtr &account) const; 0079 }; 0080 0081 } 0082 0083 #endif // header guard 0084