File indexing completed on 2024-04-21 04:04:44
0001 /* 0002 * privacymanager.h 0003 * Copyright (C) 2006 Remko Troncon 0004 * 0005 * This program is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU General Public License 0007 * as published by the Free Software Foundation; either version 2 0008 * of the License, or (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with this library; if not, write to the Free Software 0017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 0018 * 02110-1301, USA 0019 * 0020 */ 0021 0022 #ifndef PRIVACYMANAGER_H 0023 #define PRIVACYMANAGER_H 0024 0025 #include <QObject> 0026 #include <QStringList> 0027 #include <QDomElement> 0028 0029 #include "xmpp_task.h" 0030 #include "privacylist.h" 0031 0032 class QString; 0033 0034 namespace XMPP { 0035 0036 class PrivacyListListener : public Task 0037 { 0038 Q_OBJECT 0039 0040 public: 0041 PrivacyListListener ( Task* parent ); 0042 0043 bool take ( const QDomElement &e ) override; 0044 }; 0045 0046 class GetPrivacyListsTask : public Task 0047 { 0048 Q_OBJECT 0049 0050 private: 0051 QDomElement iq_; 0052 QStringList lists_; 0053 QString default_, active_; 0054 0055 public: 0056 GetPrivacyListsTask ( Task* parent ); 0057 0058 void onGo() override; 0059 bool take ( const QDomElement &x ) override; 0060 const QStringList& lists(); 0061 const QString& defaultList(); 0062 const QString& activeList(); 0063 }; 0064 0065 class SetPrivacyListsTask : public Task 0066 { 0067 Q_OBJECT 0068 0069 private: 0070 bool changeDefault_, changeActive_, changeList_; 0071 PrivacyList list_; 0072 QString value_; 0073 0074 public: 0075 SetPrivacyListsTask ( Task* parent ); 0076 0077 void onGo() override; 0078 void setActive ( const QString& active ); 0079 void setDefault ( const QString& d ); 0080 void setList ( const PrivacyList& list ); 0081 bool take ( const QDomElement &x ) override; 0082 }; 0083 0084 class GetPrivacyListTask : public Task 0085 { 0086 Q_OBJECT 0087 0088 private: 0089 QDomElement iq_; 0090 QString name_; 0091 PrivacyList list_; 0092 0093 public: 0094 GetPrivacyListTask ( Task* parent, const QString& name ); 0095 0096 void onGo() override; 0097 bool take ( const QDomElement &x ) override; 0098 const PrivacyList& list(); 0099 0100 }; 0101 0102 class PrivacyManager : public QObject 0103 { 0104 Q_OBJECT 0105 0106 public: 0107 PrivacyManager ( XMPP::Task* rootTask ); 0108 ~PrivacyManager() override; 0109 0110 void requestListNames(); 0111 0112 void changeDefaultList ( const QString& name ); 0113 void changeActiveList ( const QString& name ); 0114 void changeList ( const PrivacyList& list ); 0115 void getDefaultList(); 0116 void requestList ( const QString& name ); 0117 0118 // Convenience 0119 void block ( const QString& ); 0120 0121 protected: 0122 static QStringList blockedContacts ( const PrivacyList&, bool* allBlocked ); 0123 0124 private slots: 0125 void receiveLists(); 0126 void receiveList(); 0127 void changeDefaultList_finished(); 0128 void changeActiveList_finished(); 0129 void changeList_finished(); 0130 void getDefault_listsReceived ( const QString&, const QString&, const QStringList& ); 0131 void getDefault_listsError(); 0132 void getDefault_listReceived ( const PrivacyList& ); 0133 void getDefault_listError(); 0134 0135 void block_getDefaultList_success ( const PrivacyList& ); 0136 void block_getDefaultList_error(); 0137 0138 signals: 0139 void changeDefaultList_success(); 0140 void changeDefaultList_error(); 0141 void changeActiveList_success(); 0142 void changeActiveList_error(); 0143 void changeList_success(); 0144 void changeList_error(); 0145 void defaultListAvailable ( const PrivacyList& ); 0146 void defaultListError(); 0147 void listChangeSuccess(); 0148 void listChangeError(); 0149 void listReceived ( const PrivacyList& p ); 0150 void listError(); 0151 void listsReceived ( const QString& defaultList, const QString& activeList, const QStringList& lists ); 0152 void listsError(); 0153 0154 private: 0155 XMPP::Task* rootTask_; 0156 PrivacyListListener* listener_; 0157 0158 bool getDefault_waiting_; 0159 QString getDefault_default_; 0160 0161 QStringList block_targets_; 0162 bool block_waiting_; 0163 }; 0164 0165 } // namespace XMPP 0166 0167 #endif