libqutim 0.3.1.0
|
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 <QWeakPointer> 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 order() const; 00120 void setOrder(int order); 00121 int priority() const; 00122 void setPriority(int priority); 00123 protected: 00124 virtual const ObjectGenerator *generator() const = 0; 00125 QScopedPointer<SettingsItemPrivate> d_ptr; 00126 }; 00127 00128 template<typename T> 00129 class GeneralSettingsItem : public SettingsItem 00130 { 00131 public: 00132 GeneralSettingsItem(Settings::Type type, const QIcon &icon, const LocalizedString &text) 00133 : SettingsItem(type, icon, text) {} 00134 GeneralSettingsItem(Settings::Type type, const LocalizedString &text) 00135 : SettingsItem(type, text) {} 00136 virtual ~GeneralSettingsItem() {} 00137 protected: 00138 virtual const ObjectGenerator *generator() const 00139 { 00140 // T must be based on SettingsWidget 00141 register SettingsWidget *widget = reinterpret_cast<T *>(0); 00142 Q_UNUSED(widget); 00143 return new GeneralGenerator<T>(); 00144 } 00145 }; 00146 00147 class AutoSettingsItemPrivate; 00148 class LIBQUTIM_EXPORT AutoSettingsItem : public SettingsItem 00149 { 00150 Q_DECLARE_PRIVATE(AutoSettingsItem) 00151 public: 00152 class EntryPrivate; 00153 class LIBQUTIM_EXPORT Entry 00154 { 00155 public: 00156 Entry(const LocalizedString &text, const ObjectGenerator *gen); 00157 virtual ~Entry(); 00158 Entry *setProperty(const char *name, QVariant value); 00159 Entry *setName(const QString &name); 00160 const LocalizedString &text() const; 00161 const ObjectGenerator *generator() const; 00162 QWidget *widget(QWidget *parent = 0) const; 00163 const QString &name() const; 00164 private: 00165 QScopedPointer<EntryPrivate> p; 00166 }; 00167 AutoSettingsItem(Settings::Type type, const QIcon &icon, const LocalizedString &text); 00168 AutoSettingsItem(Settings::Type type, const LocalizedString &text); 00169 virtual ~AutoSettingsItem(); 00170 void setConfig(const QString &config, const QString &group); 00171 Entry *addEntry(const LocalizedString &text, const ObjectGenerator *gen); 00172 template <typename T> 00173 Entry *addEntry(const LocalizedString &text) 00174 { 00175 register QWidget *widget = reinterpret_cast<T *>(0); 00176 Q_UNUSED(widget); 00177 return addEntry(text, new GeneralGenerator<T>()); 00178 } 00179 private: 00180 virtual const ObjectGenerator *generator() const; 00181 }; 00182 00183 class LIBQUTIM_EXPORT AutoSettingsComboBox : public QComboBox 00184 { 00185 Q_PROPERTY(QStringList items READ items WRITE setItems) 00186 Q_OBJECT 00187 public: 00188 inline AutoSettingsComboBox() {} 00189 QStringList items() const; 00190 void setItems(const QStringList &ls); 00191 }; 00192 00193 class AutoSettingsFileChooserPrivate; 00194 class LIBQUTIM_EXPORT AutoSettingsFileChooser : public QWidget 00195 { 00196 Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged USER true) 00197 Q_OBJECT 00198 Q_DECLARE_PRIVATE(AutoSettingsFileChooser) 00199 public: 00200 AutoSettingsFileChooser(QWidget *parent = 0); 00201 ~AutoSettingsFileChooser(); 00202 QString path() const; 00203 void setPath(const QString &p); 00204 signals: 00205 void pathChanged(const QString &path); 00206 private: 00207 QScopedPointer<AutoSettingsFileChooserPrivate> d_ptr; 00208 }; 00209 00210 class DataSettingsItemPrivate; 00211 class LIBQUTIM_EXPORT DataSettingsItem : public SettingsItem 00212 { 00213 Q_DECLARE_PRIVATE(DataSettingsItem) 00214 public: 00215 DataSettingsItem(Settings::Type type, const QIcon &icon, const LocalizedString &text); 00216 DataSettingsItem(Settings::Type type, const LocalizedString &text); 00217 virtual ~DataSettingsItem(); 00218 void setConfig(const QString &config, const QString &group); 00219 void setDataItem(const DataItem &item); 00220 private: 00221 virtual const ObjectGenerator *generator() const; 00222 }; 00223 00224 class LIBQUTIM_EXPORT SettingsLayer : public QObject 00225 { 00226 Q_OBJECT 00227 Q_CLASSINFO("Service", "SettingsLayer") 00228 public: 00229 virtual void show(const SettingsItemList &settings, QObject *controller = 0) = 0; 00230 virtual void close(QObject* controller = 0) = 0; 00231 virtual void update(const SettingsItemList &settings, QObject *controller = 0) = 0; 00232 void show (MenuController *controller); 00233 protected: 00234 SettingsLayer(); 00235 virtual ~SettingsLayer(); 00236 virtual void virtual_hook(int id, void *data); 00237 }; 00238 } 00239 00240 #endif // SETTINGSLAYER_H 00241