File indexing completed on 2024-05-05 04:49:20
0001 /**************************************************************************************** 0002 * Copyright (c) 2012 Matěj Laitl <matej@laitl.cz> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #ifndef STATSYNCING_CONFIG_H 0018 #define STATSYNCING_CONFIG_H 0019 0020 #include <QModelIndex> 0021 #include <QSet> 0022 0023 class QIcon; 0024 0025 namespace StatSyncing 0026 { 0027 struct ProviderData; 0028 0029 /** 0030 * Class holding configuration for statistics synchronization, mainly a list of known 0031 * and enabled providers. 0032 */ 0033 class Config : public QAbstractListModel 0034 { 0035 Q_OBJECT 0036 0037 public: 0038 enum { 0039 ProviderIdRole = Qt::UserRole 0040 }; 0041 ~Config() override; 0042 0043 // QAbstractListModel methods: 0044 int rowCount( const QModelIndex &parent = QModelIndex() ) const override; 0045 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override; 0046 bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override; 0047 Qt::ItemFlags flags( const QModelIndex &index ) const override; 0048 0049 // own methods: 0050 /** 0051 * Register a new provider or tell Config that provider has become 0052 * online/offline. 0053 */ 0054 void updateProvider( const QString &id, const QString &name, const QIcon &icon, 0055 bool online, bool enabled ); 0056 // convenience overload 0057 void updateProvider( const QString &id, const QString &name, const QIcon &icon, 0058 bool online ); 0059 0060 /** 0061 * @return true if successfully removed, false if it didn't exist in first 0062 * place or vas rejected because it is online. 0063 */ 0064 bool forgetProvider( const QString &id ); 0065 0066 /** 0067 * @return true if provider with id @param id was already registered sometime 0068 * in the past (and not forgotten). 0069 */ 0070 bool providerKnown( const QString &id ) const; 0071 0072 /** 0073 * @return true if provider with id @param id is enabled. Returns 0074 * @param aDefault when such provider is not known. 0075 */ 0076 bool providerEnabled( const QString &id, bool aDefault = false ) const; 0077 0078 /** 0079 * @return true if provider with id @param id is online. Returns 0080 * @param aDefault when such provider is not known. 0081 */ 0082 bool providerOnline( const QString &id, bool aDefault = false ) const; 0083 0084 QIcon providerIcon( const QString &id ) const; 0085 0086 /** 0087 * Binary OR of Meta::val* fields that should be synchronized in automatic 0088 * synchronization. 0089 */ 0090 qint64 checkedFields() const; 0091 0092 /** 0093 * Set binary OR of Meta::val* fields to synchronize. 0094 */ 0095 void setCheckedFields( qint64 fields ); 0096 0097 /** 0098 * Get a list of labels that are black-listed from synchronization (not 0099 * touched at all). 0100 */ 0101 QSet<QString> excludedLabels() const; 0102 0103 /** 0104 * Set which labels to exclude from synchronization. 0105 */ 0106 void setExcludedLabels( const QSet<QString> &labels ); 0107 0108 /** 0109 * Return true if configuration has changed since last saving or reading data. 0110 */ 0111 bool hasChanged() const; 0112 0113 /** 0114 * Reads config from disk. Discards any possible unsaved changes. 0115 */ 0116 void read(); 0117 0118 /** 0119 * Saves the config back to disk. 0120 */ 0121 void save(); 0122 0123 Q_SIGNALS: 0124 void providerForgotten( const QString &id ); 0125 0126 private: 0127 friend class Controller; 0128 0129 // Only StatSyncing::Controller can construct config 0130 Config( QObject *parent = nullptr ); 0131 0132 QList<ProviderData> m_providerData; 0133 qint64 m_checkedFields; 0134 QSet<QString> m_excludedLabels; 0135 bool m_hasChanged; 0136 }; 0137 } 0138 0139 #endif // STATSYNCING_CONFIG_H