1
/***************************************************************************
2
* Copyright (C) 2010 by Dario Freddi <drf@kde.org> *
4
* This program is free software; you can redistribute it and/or modify *
5
* it under the terms of the GNU General Public License as published by *
6
* the Free Software Foundation; either version 2 of the License, or *
7
* (at your option) any later version. *
9
* This program is distributed in the hope that it will be useful, *
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12
* GNU General Public License for more details. *
14
* You should have received a copy of the GNU General Public License *
15
* along with this program; if not, write to the *
16
* Free Software Foundation, Inc., *
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
18
***************************************************************************/
21
#ifndef POWERDEVIL_POWERDEVILACTIONCONFIG_H
22
#define POWERDEVIL_POWERDEVILACTIONCONFIG_H
24
#include <QtGui/QWidget>
26
#include <KConfigGroup>
28
#include <kdemacros.h>
30
namespace PowerDevil {
33
* @brief The base class for Action's config interfaces
35
* This class should be reimplemented when creating a new Action. It is used to generate
36
* a configuration UI for your action and integrate it into KDE Power Management System's
37
* config module seamlessly.
39
* @par Creating an ActionConfig
41
* If you already have been through creating an Action, you have seen that Action's desktop
42
* file contains already all the needed information for loading its respective ActionConfig. For this
43
* reason, despite ActionConfig being a plugin, you do not need to create a desktop file for it -
44
* you just have to write the correct info into the Action's one.
46
* @par The key/value pair rationale
48
* The config UI works in a key/value fashion, where value is a generic QWidget. This is done
49
* to keep the UI consistent without hurting the flexibility of the implementation.
50
* Please remember to keep the configuration as easy and essential as possible: if you have gone
51
* beyond 2 rows, you might be doing something wrong.
53
* @par Loading and saving configuration
55
* Of course, you should also be providing the logic for saving and loading your action's configuration.
56
* This is done through KConfigGroup: your action has a KConfigGroup assigned by KDE Power Management System
57
* which can be accessed through configGroup or overwritten through setConfigGroup. The very same group
58
* you are loading/saving here will be the one passed to Action::loadAction.
64
class KDE_EXPORT ActionConfig : public QObject
67
Q_DISABLE_COPY(ActionConfig)
73
ActionConfig(QObject *parent);
77
virtual ~ActionConfig();
80
* @returns The KConfigGroup associated to this action, where data should be saved (and loaded)
82
* @note You should not track this KConfigGroup, as it might change from profile to profile.
83
* Always use this function to access it.
85
KConfigGroup configGroup() const;
87
* Overwrites the config group associated with this Action with @c group.
89
* @param group A KConfigGroup carrying the settings for this Action.
91
void setConfigGroup(const KConfigGroup &group);
94
* This function should return the key/value pairs containing your Action's configuration UI.
96
* @returns A list of QString, QWidget pairs representing your Action's configuration UI
98
virtual QList< QPair< QString, QWidget* > > buildUi() = 0;
101
* This function gets called whenever the parent module requires to load a specific configuration. This
102
* usually occurs when @c configGroup is updated, for example due to the fact that the user wants to modify
103
* a different profile. In this function, you should update the info contained in the widgets generated
104
* by @c buildUi accordingly.
106
virtual void load() = 0;
108
* This function gets called whenever the parent module requires to save the configuration. Usually, you
109
* want to read values from the widgets generated with @c buildUi and call @c setConfigGroup to update the
110
* Action's configuration.
112
virtual void save() = 0;
116
* Call this slot whenever the user makes some changes to the widgets.
122
* This signal gets emitted every time the user changes the (unsaved) configuration. Do not emit this signal
123
* directly: call setChanged instead.
136
#endif // POWERDEVIL_POWERDEVILACTIONCONFIG_H