Changeset View
Changeset View
Standalone View
Standalone View
kcms/componentchooser/componentchooser.h
1 | /*************************************************************************** | 1 | /*************************************************************************** | ||
---|---|---|---|---|---|
2 | componentchooser.h - description | 2 | componentchooser.h - description | ||
3 | ------------------- | 3 | ------------------- | ||
4 | copyright : (C) 2002 by Joseph Wenninger | 4 | copyright : (C) 2002 by Joseph Wenninger <jowenn@kde.org> | ||
5 | email : jowenn@kde.org | 5 | copyright : (C) 2020 by Méven Car <meven.car@enioka.com> | ||
6 | ***************************************************************************/ | 6 | ***************************************************************************/ | ||
7 | 7 | | |||
8 | /*************************************************************************** | 8 | /*************************************************************************** | ||
9 | * * | 9 | * * | ||
10 | * This program is free software; you can redistribute it and/or modify * | 10 | * This program is free software; you can redistribute it and/or modify * | ||
11 | * it under the terms of the GNU General Public License version 2 as * | 11 | * it under the terms of the GNU General Public License version 2 as * | ||
12 | * published by the Free Software Foundationi * | 12 | * published by the Free Software Foundation * | ||
13 | * * | 13 | * * | ||
14 | ***************************************************************************/ | 14 | ***************************************************************************/ | ||
15 | 15 | | |||
16 | #ifndef _COMPONENTCHOOSER_H_ | 16 | #ifndef _COMPONENTCHOOSER_H_ | ||
17 | #define _COMPONENTCHOOSER_H_ | 17 | #define _COMPONENTCHOOSER_H_ | ||
18 | 18 | | |||
19 | #include "ui_componentchooser_ui.h" | 19 | #include "ui_componentchooser_ui.h" | ||
20 | #include "ui_componentconfig_ui.h" | | |||
21 | #include <QHash> | 20 | #include <QHash> | ||
22 | 21 | | |||
23 | 22 | #include <QComboBox> | |||
24 | #include <QVBoxLayout> | | |||
25 | 23 | | |||
26 | #include <kservice.h> | 24 | #include <kservice.h> | ||
27 | 25 | | |||
28 | class QListWidgetItem; | 26 | class QWidget; | ||
29 | class KConfig; | 27 | class KConfig; | ||
30 | 28 | | |||
31 | /* The CfgPlugin class is an exception. It is LGPL. It will be parted of the plugin interface | 29 | class CfgPlugin : public QComboBox | ||
32 | which I plan for KDE 3.2. | | |||
33 | */ | | |||
34 | class CfgPlugin | | |||
35 | { | 30 | { | ||
31 | Q_OBJECT | ||||
32 | | ||||
36 | public: | 33 | public: | ||
37 | CfgPlugin(){} | 34 | CfgPlugin(QWidget *parent): QComboBox(parent) {} | ||
38 | virtual ~CfgPlugin(){} | 35 | virtual ~CfgPlugin(){} | ||
39 | virtual void load(KConfig *cfg)=0; | 36 | virtual void load(KConfig *cfg)=0; | ||
40 | virtual void save(KConfig *cfg)=0; | 37 | virtual void save(KConfig *cfg)=0; | ||
41 | virtual void defaults()=0; | 38 | bool hasChanged() const | ||
42 | virtual bool isDefaults() const=0; | 39 | { | ||
43 | }; | 40 | return m_currentIndex != -1 && m_currentIndex != currentIndex(); | ||
41 | } | ||||
44 | 42 | | |||
45 | class CfgComponent: public QWidget, public Ui::ComponentConfig_UI, public CfgPlugin | 43 | void defaults() | ||
46 | { | 44 | { | ||
47 | Q_OBJECT | 45 | if (m_defaultIndex != -1) { | ||
48 | public: | 46 | setCurrentIndex(m_defaultIndex); | ||
49 | CfgComponent(QWidget *parent); | 47 | } | ||
50 | ~CfgComponent() override; | 48 | } | ||
51 | void load(KConfig *cfg) override; | | |||
52 | void save(KConfig *cfg) override; | | |||
53 | void defaults() override; | | |||
54 | bool isDefaults() const override; | | |||
55 | 49 | | |||
56 | protected: | 50 | bool isDefaults() const | ||
57 | QHash<QString, QString> m_lookupDict,m_revLookupDict; | 51 | { | ||
52 | return m_defaultIndex == -1 || m_defaultIndex == currentIndex(); | ||||
53 | } | ||||
58 | 54 | | |||
59 | protected Q_SLOTS: | | |||
60 | void slotComponentChanged(const QString&); | | |||
61 | Q_SIGNALS: | 55 | Q_SIGNALS: | ||
62 | void changed(bool); | 56 | void changed(bool); | ||
63 | void defaulted(bool); | 57 | | ||
58 | protected: | ||||
59 | // the currently saved selected option | ||||
60 | int m_currentIndex = -1; | ||||
61 | // the index default of the default option | ||||
62 | int m_defaultIndex = -1; | ||||
64 | }; | 63 | }; | ||
65 | 64 | | |||
66 | class ComponentChooser : public QWidget, public Ui::ComponentChooser_UI | 65 | class ComponentChooser : public QWidget, public Ui::ComponentChooser_UI | ||
67 | { | 66 | { | ||
68 | 67 | | |||
69 | Q_OBJECT | 68 | Q_OBJECT | ||
70 | 69 | | |||
71 | public: | 70 | public: | ||
72 | ComponentChooser(QWidget *parent=nullptr); | 71 | ComponentChooser(QWidget *parent=nullptr); | ||
73 | ~ComponentChooser() override; | 72 | ~ComponentChooser() override; | ||
74 | void load(); | 73 | void load(); | ||
75 | void save(); | 74 | void save(); | ||
76 | void restoreDefault(); | 75 | void restoreDefault(); | ||
77 | 76 | | |||
78 | private: | 77 | private: | ||
79 | QString latestEditedService; | 78 | QMap<QString, CfgPlugin*> configWidgetMap; | ||
80 | bool somethingChanged; | | |||
81 | QWidget *configWidget; | | |||
82 | QVBoxLayout *myLayout; | | |||
83 | QMap<QString, QWidget*> configWidgetMap; | | |||
84 | 79 | | |||
85 | void loadConfigWidget(const QString &, const QString &, const QString &); | 80 | CfgPlugin *loadConfigWidget(const QString &cfgType); | ||
86 | 81 | | |||
87 | protected Q_SLOTS: | 82 | protected Q_SLOTS: | ||
88 | void emitChanged(bool); | 83 | void emitChanged(); | ||
89 | void slotServiceSelected(QListWidgetItem *); | | |||
90 | 84 | | |||
91 | Q_SIGNALS: | 85 | Q_SIGNALS: | ||
92 | void changed(bool); | 86 | void changed(bool); | ||
93 | void defaulted(bool); | 87 | void defaulted(bool); | ||
94 | | ||||
95 | }; | 88 | }; | ||
96 | 89 | | |||
97 | 90 | | |||
98 | #endif | 91 | #endif |