libqutim 0.2.80.1
|
00001 /**************************************************************************** 00002 ** 00003 ** qutIM - instant messenger 00004 ** 00005 ** Copyright © 2011 Ruslan Nigmatullin <euroelessar@yandex.ru> 00006 ** 00007 ***************************************************************************** 00008 ** 00009 ** $QUTIM_BEGIN_LICENSE$ 00010 ** This program is free software: you can redistribute it and/or modify 00011 ** it under the terms of the GNU General Public License as published by 00012 ** the Free Software Foundation, either version 3 of the License, or 00013 ** (at your option) any later version. 00014 ** 00015 ** This program is distributed in the hope that it will be useful, 00016 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00018 ** See the GNU General Public License for more details. 00019 ** 00020 ** You should have received a copy of the GNU General Public License 00021 ** along with this program. If not, see http://www.gnu.org/licenses/. 00022 ** $QUTIM_END_LICENSE$ 00023 ** 00024 ****************************************************************************/ 00025 00026 #ifndef SETTINGSLAYER_H 00027 #define SETTINGSLAYER_H 00028 00029 #include "localizedstring.h" 00030 #include "objectgenerator.h" 00031 #include <QPointer> 00032 #include <QWidget> 00033 #include <QIcon> 00034 #include <QComboBox> 00035 00036 namespace qutim_sdk_0_3 00037 { 00038 class SettingsWidget; 00039 class SettingsItem; 00040 class SettingsItemPrivate; 00041 class MenuController; 00042 class DataItem; 00043 00044 typedef QList<SettingsItem *> SettingsItemList; 00045 00046 namespace Settings 00047 { 00048 enum Type 00049 { 00050 Invalid = 0, 00051 General, 00052 Protocol, 00053 Appearance, 00054 Plugin, 00055 Special 00056 }; 00057 00058 // struct TypeEntry 00059 // { 00060 // TypeEntry(const QIcon &icon,const LocalizedString &title,const LocalizedString &description = LocalizedString()); 00061 // TypeEntry() {} 00062 // LocalizedString text; 00063 // QIcon icon; 00064 // }; 00065 00066 // typedef QMap<Settings::Type,TypeEntry> TypeEntryMap; 00067 00068 // Exmample of usage: 00069 // Settings::registerItem(new SettingsWidget<MyCoolPopupSettings>( 00070 // Settings::Appearance, 00071 // QIcon(":/icons/mycoolicon"), 00072 // QT_TRANSLATE_NOOP_UTF8("Settings", "Popup theme"))); 00073 00074 LIBQUTIM_EXPORT void registerItem(SettingsItem *item); 00075 LIBQUTIM_EXPORT void removeItem(SettingsItem *item); 00076 LIBQUTIM_EXPORT void showWidget(); 00077 LIBQUTIM_EXPORT void closeWidget(); 00078 LIBQUTIM_EXPORT LocalizedString getTypeTitle(Type type); 00079 LIBQUTIM_EXPORT QIcon getTypeIcon(Type type); 00083 LIBQUTIM_EXPORT void registerItem(SettingsItem *item, const QMetaObject *meta); 00087 template <typename T> 00088 Q_INLINE_TEMPLATE void registerItem(SettingsItem *item) { registerItem(item,&T::staticMetaObject); } 00089 00093 SettingsItemList items(const QMetaObject *meta); 00094 template <typename T> 00095 Q_INLINE_TEMPLATE SettingsItemList items() { return items(&T::staticMetaObject); } 00096 //TODO, 00097 // LIBQUTIM_EXPORT TypeEntryMap *entries(); 00098 // LIBQUTIM_EXPORT quint16 registerType(const char *id, 00099 // const QIcon &icon, 00100 // const LocalizedString &text, 00101 // const LocalizedString &description = LocalizedString()); 00102 } 00103 00104 class LIBQUTIM_EXPORT SettingsItem 00105 { 00106 Q_DISABLE_COPY(SettingsItem) 00107 Q_DECLARE_PRIVATE(SettingsItem) 00108 public: 00109 SettingsItem(SettingsItemPrivate &d); 00110 SettingsItem(Settings::Type type, const QIcon &icon, const LocalizedString &text); 00111 SettingsItem(Settings::Type type, const LocalizedString &text); 00112 virtual ~SettingsItem(); 00113 Settings::Type type() const; 00114 QIcon icon() const; 00115 LocalizedString text() const; 00116 SettingsWidget *widget() const; 00117 void clearWidget(); 00118 void connect(const char *signal, QObject *receiver, const char *member); 00119 int priority() const; 00120 void setPriority(int priority); 00121 protected: 00122 virtual const ObjectGenerator *generator() const = 0; 00123 QScopedPointer<SettingsItemPrivate> d_ptr; 00124 }; 00125 00126 template<typename T> 00127 class GeneralSettingsItem : public SettingsItem 00128 { 00129 public: 00130 GeneralSettingsItem(Settings::Type type, const QIcon &icon, const LocalizedString &text) 00131 : SettingsItem(type, icon, text) {} 00132 GeneralSettingsItem(Settings::Type type, const LocalizedString &text) 00133 : SettingsItem(type, text) {} 00134 virtual ~GeneralSettingsItem() {} 00135 protected: 00136 virtual const ObjectGenerator *generator() const 00137 { 00138 // T must be based on SettingsWidget 00139 register SettingsWidget *widget = reinterpret_cast<T *>(0); 00140 Q_UNUSED(widget); 00141 return new GeneralGenerator<T>(); 00142 } 00143 }; 00144 00145 class AutoSettingsItemPrivate; 00146 class LIBQUTIM_EXPORT AutoSettingsItem : public SettingsItem 00147 { 00148 Q_DECLARE_PRIVATE(AutoSettingsItem) 00149 public: 00150 class EntryPrivate; 00151 class LIBQUTIM_EXPORT Entry 00152 { 00153 public: 00154 Entry(const LocalizedString &text, const ObjectGenerator *gen); 00155 virtual ~Entry(); 00156 Entry *setProperty(const char *name, QVariant value); 00157 Entry *setName(const QString &name); 00158 const LocalizedString &text() const; 00159 const ObjectGenerator *generator() const; 00160 QWidget *widget(QWidget *parent = 0) const; 00161 const QString &name() const; 00162 private: 00163 QScopedPointer<EntryPrivate> p; 00164 }; 00165 AutoSettingsItem(Settings::Type type, const QIcon &icon, const LocalizedString &text); 00166 AutoSettingsItem(Settings::Type type, const LocalizedString &text); 00167 virtual ~AutoSettingsItem(); 00168 void setConfig(const QString &config, const QString &group); 00169 Entry *addEntry(const LocalizedString &text, const ObjectGenerator *gen); 00170 template <typename T> 00171 Entry *addEntry(const LocalizedString &text) 00172 { 00173 register QWidget *widget = reinterpret_cast<T *>(0); 00174 Q_UNUSED(widget); 00175 return addEntry(text, new GeneralGenerator<T>()); 00176 } 00177 private: 00178 virtual const ObjectGenerator *generator() const; 00179 }; 00180 00181 class LIBQUTIM_EXPORT AutoSettingsComboBox : public QComboBox 00182 { 00183 Q_PROPERTY(QStringList items READ items WRITE setItems) 00184 Q_OBJECT 00185 public: 00186 inline AutoSettingsComboBox() {} 00187 QStringList items() const; 00188 void setItems(const QStringList &ls); 00189 }; 00190 00191 class AutoSettingsFileChooserPrivate; 00192 class LIBQUTIM_EXPORT AutoSettingsFileChooser : public QWidget 00193 { 00194 Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged USER true) 00195 Q_OBJECT 00196 Q_DECLARE_PRIVATE(AutoSettingsFileChooser) 00197 public: 00198 AutoSettingsFileChooser(QWidget *parent = 0); 00199 ~AutoSettingsFileChooser(); 00200 QString path() const; 00201 void setPath(const QString &p); 00202 signals: 00203 void pathChanged(const QString &path); 00204 private: 00205 QScopedPointer<AutoSettingsFileChooserPrivate> d_ptr; 00206 }; 00207 00208 class DataSettingsItemPrivate; 00209 class LIBQUTIM_EXPORT DataSettingsItem : public SettingsItem 00210 { 00211 Q_DECLARE_PRIVATE(DataSettingsItem) 00212 public: 00213 DataSettingsItem(Settings::Type type, const QIcon &icon, const LocalizedString &text); 00214 DataSettingsItem(Settings::Type type, const LocalizedString &text); 00215 virtual ~DataSettingsItem(); 00216 void setConfig(const QString &config, const QString &group); 00217 void setDataItem(const DataItem &item); 00218 private: 00219 virtual const ObjectGenerator *generator() const; 00220 }; 00221 00222 class LIBQUTIM_EXPORT SettingsLayer : public QObject 00223 { 00224 Q_OBJECT 00225 Q_CLASSINFO("Service", "SettingsLayer") 00226 public: 00227 virtual void show(const SettingsItemList &settings, QObject *controller = 0) = 0; 00228 virtual void close(QObject* controller = 0) = 0; 00229 virtual void update(const SettingsItemList &settings, QObject *controller = 0) = 0; 00230 void show (MenuController *controller); 00231 protected: 00232 SettingsLayer(); 00233 virtual ~SettingsLayer(); 00234 virtual void virtual_hook(int id, void *data); 00235 }; 00236 } 00237 00238 #endif // SETTINGSLAYER_H 00239