libqutim  0.3.2.0
settingslayer.h
Go to the documentation of this file.
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 <qglobal.h>
00030 #include "localizedstring.h"
00031 #include "objectgenerator.h"
00032 #include <QPointer>
00033 #include <QWidget>
00034 #include <QGraphicsObject>
00035 #include <QIcon>
00036 #include <QComboBox>
00037 
00038 namespace qutim_sdk_0_3
00039 {
00040 class SettingsWidget;
00041 class SettingsItem;
00042 class SettingsItemPrivate;
00043 class MenuController;
00044 class DataItem;
00045 
00046 typedef QList<SettingsItem *> SettingsItemList;
00047 
00048 namespace Settings
00049 {
00050     enum Type
00051     {
00052         Invalid = 0,
00053         General,
00054         Protocol,
00055         Appearance,
00056         Plugin,
00057         Special
00058     };
00059 
00060 //      struct TypeEntry
00061 //      {
00062 //          TypeEntry(const QIcon &icon,const LocalizedString &title,const LocalizedString &description = LocalizedString());
00063 //          TypeEntry() {}
00064 //          LocalizedString text;
00065 //          QIcon icon;
00066 //      };
00067 
00068 //      typedef QMap<Settings::Type,TypeEntry> TypeEntryMap;
00069 
00070     // Exmample of usage:
00071     // Settings::registerItem(new SettingsWidget<MyCoolPopupSettings>(
00072     //                        Settings::Appearance,
00073     //                        QIcon(":/icons/mycoolicon"),
00074     //                        QT_TRANSLATE_NOOP_UTF8("Settings", "Popup theme")));
00075 
00076     LIBQUTIM_EXPORT void registerItem(SettingsItem *item);
00077     LIBQUTIM_EXPORT void removeItem(SettingsItem *item);
00078     LIBQUTIM_EXPORT void showWidget();
00079     LIBQUTIM_EXPORT void closeWidget();
00080     LIBQUTIM_EXPORT LocalizedString getTypeTitle(Type type);
00081     LIBQUTIM_EXPORT QIcon getTypeIcon(Type type);
00085     LIBQUTIM_EXPORT void registerItem(SettingsItem *item, const QMetaObject *meta);
00089     template <typename T>
00090     Q_INLINE_TEMPLATE void registerItem(SettingsItem *item) { registerItem(item,&T::staticMetaObject); }
00091     
00095     SettingsItemList items(const QMetaObject *meta);
00096     template <typename T>
00097     Q_INLINE_TEMPLATE SettingsItemList items() { return items(&T::staticMetaObject); }
00098     //TODO,
00099 //      LIBQUTIM_EXPORT TypeEntryMap *entries();
00100 //      LIBQUTIM_EXPORT quint16 registerType(const char *id,
00101 //                                                  const QIcon &icon,
00102 //                                                  const LocalizedString &text,
00103 //                                                  const LocalizedString &description = LocalizedString());
00104 }
00105 
00106 class LIBQUTIM_EXPORT SettingsItem
00107 {
00108     Q_DISABLE_COPY(SettingsItem)
00109     Q_DECLARE_PRIVATE(SettingsItem)
00110 public:
00111     SettingsItem(SettingsItemPrivate &d);
00112     SettingsItem(Settings::Type type, const QIcon &icon, const LocalizedString &text);
00113     SettingsItem(Settings::Type type, const LocalizedString &text);
00114     virtual ~SettingsItem();
00115     Settings::Type type() const;
00116     QIcon icon() const;
00117     LocalizedString text() const;
00118     SettingsWidget *widget() const;
00119     QGraphicsObject *graphicsObject() const;
00120     QObject *object() const;
00121     bool isWidget() const;
00122     void clearWidget();
00123     void connect(const char *signal, QObject *receiver, const char *member);
00124     int order() const;
00125     void setOrder(int order);
00126     int priority() const;
00127     void setPriority(int priority);
00128 protected:
00129     virtual const ObjectGenerator *generator() const = 0;
00130     QScopedPointer<SettingsItemPrivate> d_ptr;
00131 };
00132 
00133 template<typename T>
00134 class GeneralSettingsItem : public SettingsItem
00135 {
00136 public:
00137     GeneralSettingsItem(Settings::Type type, const QIcon &icon, const LocalizedString &text)
00138             : SettingsItem(type, icon, text) {}
00139     GeneralSettingsItem(Settings::Type type, const LocalizedString &text)
00140             : SettingsItem(type, text) {}
00141     virtual ~GeneralSettingsItem() {}
00142 protected:
00143     virtual const ObjectGenerator *generator() const
00144     {
00145         // T must be based on SettingsWidget
00146         SettingsWidget *widget = reinterpret_cast<T *>(0);
00147         Q_UNUSED(widget);
00148         return new GeneralGenerator<T>();
00149     }
00150 };
00151 
00152 class AutoSettingsItemPrivate;
00153 class LIBQUTIM_EXPORT AutoSettingsItem : public SettingsItem
00154 {
00155     Q_DECLARE_PRIVATE(AutoSettingsItem)
00156 public:
00157     class EntryPrivate;
00158     class LIBQUTIM_EXPORT Entry
00159     {
00160     public:
00161         Entry(const LocalizedString &text, const ObjectGenerator *gen);
00162         virtual ~Entry();
00163         Entry *setProperty(const char *name, QVariant value);
00164         Entry *setName(const QString &name);
00165         const LocalizedString &text() const;
00166         const ObjectGenerator *generator() const;
00167         QWidget *widget(QWidget *parent = 0) const;
00168         const QString &name() const;
00169     private:
00170         QScopedPointer<EntryPrivate> p;
00171     };
00172     AutoSettingsItem(Settings::Type type, const QIcon &icon, const LocalizedString &text);
00173     AutoSettingsItem(Settings::Type type, const LocalizedString &text);
00174     virtual ~AutoSettingsItem();
00175     void setConfig(const QString &config, const QString &group);
00176     Entry *addEntry(const LocalizedString &text, const ObjectGenerator *gen);
00177     template <typename T>
00178     Entry *addEntry(const LocalizedString &text)
00179     {
00180         QWidget *widget = reinterpret_cast<T *>(0);
00181         Q_UNUSED(widget);
00182         return addEntry(text, new GeneralGenerator<T>());
00183     }
00184 private:
00185     virtual const ObjectGenerator *generator() const;
00186 };
00187 
00188 class LIBQUTIM_EXPORT AutoSettingsComboBox : public QComboBox
00189 {
00190     Q_PROPERTY(QStringList items READ items WRITE setItems)
00191     Q_OBJECT
00192 public:
00193     inline AutoSettingsComboBox() {}
00194     QStringList items() const;
00195     void setItems(const QStringList &ls);
00196 };
00197 
00198 class AutoSettingsFileChooserPrivate;
00199 class LIBQUTIM_EXPORT AutoSettingsFileChooser : public QWidget
00200 {
00201     Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged USER true)
00202     Q_OBJECT
00203     Q_DECLARE_PRIVATE(AutoSettingsFileChooser)
00204 public:
00205     AutoSettingsFileChooser(QWidget *parent = 0);
00206     ~AutoSettingsFileChooser();
00207     QString path() const;
00208     void setPath(const QString &p);
00209 signals:
00210     void pathChanged(const QString &path);
00211 private:
00212     QScopedPointer<AutoSettingsFileChooserPrivate> d_ptr;
00213 };
00214 
00215 class LIBQUTIM_EXPORT SettingsLayer : public QObject
00216 {
00217     Q_OBJECT
00218     Q_CLASSINFO("Service", "SettingsLayer")
00219 public:
00220     virtual void show(const SettingsItemList &settings, QObject *controller = 0) = 0;
00221     virtual void close(QObject* controller = 0) = 0;
00222     virtual void update(const SettingsItemList &settings, QObject *controller = 0) = 0;
00223     void show (MenuController *controller);
00224 protected:
00225     SettingsLayer();
00226     virtual ~SettingsLayer();
00227     virtual void virtual_hook(int id, void *data);
00228 };
00229 }
00230 
00231 Q_DECLARE_METATYPE(qutim_sdk_0_3::SettingsItem*)
00232 
00233 #endif // SETTINGSLAYER_H
00234