2
Copyright (C) 2010 Michael Zanetti <michael_zanetti@gmx.net>
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 along
15
with this program; if not, write to the Free Software Foundation, Inc.,
16
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
#include "remotelist.h"
21
#include "profileaction.h"
26
#include <QtCore/QList>
29
RemoteList::RemoteList() {
32
bool RemoteList::contains(const QString& remoteName) const {
33
for(QVector<Remote*>::const_iterator i = constBegin(); i != constEnd(); ++i){
34
if((*i)->name() == remoteName){
41
// Save everything to config File in the format [Remote][modeIndex][actionIndex]
42
void RemoteList::saveToConfig(const QString& configName) {
43
KConfig config(configName);
44
// Clear out all old remotes settings. We will sync the whole tree to disk now
45
config.deleteGroup("Remotes");
46
KConfigGroup remotesGroup(&config, "Remotes");
47
for(QVector<Remote*>::const_iterator remoteIterator = constBegin(); remoteIterator != constEnd(); ++remoteIterator){
48
KConfigGroup remoteGroup(&remotesGroup, (*remoteIterator)->name());
49
// Save Remote properties here
50
remoteGroup.writeEntry("DefaultMode", (*remoteIterator)->defaultMode()->name());
51
remoteGroup.writeEntry("ModeChangeMode", (*remoteIterator)->modeChangeMode() == Remote::Group ? "Group" : "Cycle");
52
remoteGroup.writeEntry("NextModeButton", (*remoteIterator)->nextModeButton());
53
remoteGroup.writeEntry("PreviousModeButton", (*remoteIterator)->previousModeButton());
56
foreach(const Mode *mode, (*remoteIterator)->allModes()){
57
KConfigGroup modeGroup(&remoteGroup, QString::number(modeIndex++));
58
// Save Mode properties here
59
modeGroup.writeEntry("Name", mode->name());
60
modeGroup.writeEntry("IconName", mode->iconName());
61
modeGroup.writeEntry("Button", mode->button());
64
foreach(Action *action, mode->actions()){
65
KConfigGroup actionGroup(&modeGroup, QString::number(actionIndex++));
66
// Actions need to save themselves...
67
action->saveToConfig(actionGroup);
73
void RemoteList::loadFromConfig(const QString& configName) {
74
clear(); //Drop old entries
75
KConfig config(configName, KConfig::NoGlobals);
76
KConfigGroup remotesGroup(&config, "Remotes");
78
foreach(const QString &remoteGroupName, remotesGroup.groupList()){
79
Remote *remote = new Remote(remoteGroupName);
80
KConfigGroup remoteGroup(&remotesGroup, remoteGroupName);
81
QStringList modeGroupList = remoteGroup.groupList();
83
foreach(const QString &modeIndex, modeGroupList){
84
KConfigGroup modeGroup(&remoteGroup, modeIndex);
86
QString modeName = modeGroup.readEntry("Name");
87
if(modeName == "Master") { // A Remote always has a Master Mode... Adding a second one will not work
88
mode = remote->masterMode();
89
mode->setIconName(modeGroup.readEntry("IconName"));
91
mode = new Mode(modeName, modeGroup.readEntry("IconName"));
93
QStringList actionGroupList = modeGroup.groupList();
94
actionGroupList.sort();
95
foreach(const QString &actionId, actionGroupList){
96
KConfigGroup actionGroup(&modeGroup, actionId);
97
// Read Action properties here
99
Action::ActionType actionType = (Action::ActionType) actionGroup.readEntry("Type", 0);
101
case Action::DBusAction:
102
action = new DBusAction();
104
case Action::ProfileAction:
105
action = new ProfileAction();
111
action->loadFromConfig(actionGroup);
113
mode->addAction(action);
115
// Read Mode properties here
116
mode->setIconName(modeGroup.readEntry("IconName", "infrared-remote"));
117
mode->setButton(modeGroup.readEntry("Button"));
119
remote->addMode(mode);
121
// Read Remote properties here
122
remote->setDefaultMode(remoteGroup.readEntry("DefaultMode"));
123
remote->setModeChangeMode(remoteGroup.readEntry("ModeChangeMode", "Group") == "Group" ? Remote::Group : Remote::Cycle);
124
remote->setNextModeButton(remoteGroup.readEntry("NextModeButton"));
125
remote->setPreviousModeButton(remoteGroup.readEntry("PreviousModeButton"));
131
Remote* RemoteList::remote ( const QString& remoteName ){
132
for(QVector<Remote*>::const_iterator i = constBegin(); i != constEnd(); ++i){
133
if((*i)->name() == remoteName){