• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeutils API Reference
  • KDE Home
  • Contact Us
 

kremotecontrol

  • sources
  • kde-4.12
  • kdeutils
  • kremotecontrol
  • libkremotecontrol
remotelist.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 Michael Zanetti <michael_zanetti@gmx.net>
3 
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.
8 
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.
13 
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.
17 
18 */
19 
20 #include "remotelist.h"
21 #include "profileaction.h"
22 #include "keypressaction.h"
23 
24 #include <kglobal.h>
25 #include <kconfig.h>
26 
27 #include <QtCore/QList>
28 
29 
30 RemoteList::RemoteList() {
31 }
32 
33 bool RemoteList::contains(const QString& remoteName) const {
34  for(QVector<Remote*>::const_iterator i = constBegin(); i != constEnd(); ++i){
35  if((*i)->name() == remoteName){
36  return true;
37  }
38  }
39  return false;
40 }
41 
42 // Save everything to config File in the format [Remote][modeIndex][actionIndex]
43 void RemoteList::saveToConfig(const QString& configName) {
44  KConfig config(configName);
45  // Clear out all old remotes settings. We will sync the whole tree to disk now
46  config.deleteGroup("Remotes");
47  KConfigGroup remotesGroup(&config, "Remotes");
48  for(QVector<Remote*>::const_iterator remoteIterator = constBegin(); remoteIterator != constEnd(); ++remoteIterator){
49  KConfigGroup remoteGroup(&remotesGroup, (*remoteIterator)->name());
50  // Save Remote properties here
51  remoteGroup.writeEntry("DefaultMode", (*remoteIterator)->defaultMode()->name());
52  remoteGroup.writeEntry("ModeChangeMode", (*remoteIterator)->modeChangeMode() == Remote::Group ? "Group" : "Cycle");
53  remoteGroup.writeEntry("NextModeButton", (*remoteIterator)->nextModeButton());
54  remoteGroup.writeEntry("PreviousModeButton", (*remoteIterator)->previousModeButton());
55 
56  int modeIndex = 0;
57  foreach(const Mode *mode, (*remoteIterator)->allModes()){
58  KConfigGroup modeGroup(&remoteGroup, QString::number(modeIndex++));
59  // Save Mode properties here
60  modeGroup.writeEntry("Name", mode->name());
61  modeGroup.writeEntry("IconName", mode->iconName());
62  modeGroup.writeEntry("Button", mode->button());
63 
64  int actionIndex = 0;
65  foreach(Action *action, mode->actions()){
66  KConfigGroup actionGroup(&modeGroup, QString::number(actionIndex++));
67  // Actions need to save themselves...
68  action->saveToConfig(actionGroup);
69  }
70  }
71  }
72 }
73 
74 void RemoteList::loadFromConfig(const QString& configName) {
75  clear(); //Drop old entries
76  KConfig config(configName, KConfig::NoGlobals);
77  KConfigGroup remotesGroup(&config, "Remotes");
78 
79  foreach(const QString &remoteGroupName, remotesGroup.groupList()){
80  Remote *remote = new Remote(remoteGroupName);
81  KConfigGroup remoteGroup(&remotesGroup, remoteGroupName);
82  QStringList modeGroupList = remoteGroup.groupList();
83  modeGroupList.sort();
84  foreach(const QString &modeIndex, modeGroupList){
85  KConfigGroup modeGroup(&remoteGroup, modeIndex);
86  Mode *mode;
87  QString modeName = modeGroup.readEntry("Name");
88  if(modeName == QLatin1String( "Master" )) { // A Remote always has a Master Mode... Adding a second one will not work
89  mode = remote->masterMode();
90  mode->setIconName(modeGroup.readEntry("IconName"));
91  } else {
92  mode = new Mode(modeName, modeGroup.readEntry("IconName"));
93  }
94  QStringList actionGroupList = modeGroup.groupList();
95  actionGroupList.sort();
96  foreach(const QString &actionId, actionGroupList){
97  KConfigGroup actionGroup(&modeGroup, actionId);
98  // Read Action properties here
99  Action *action = 0;
100  Action::ActionType actionType = (Action::ActionType) actionGroup.readEntry("Type", 0);
101  switch(actionType){
102  case Action::DBusAction:
103  action = new DBusAction();
104  break;
105  case Action::ProfileAction:
106  action = new ProfileAction();
107  break;
108  case Action::KeypressAction:
109  action = new KeypressAction();
110  break;
111  }
112  if(!action){
113  continue;
114  }
115  action->loadFromConfig(actionGroup);
116 
117  mode->addAction(action);
118  }
119  // Read Mode properties here
120  mode->setIconName(modeGroup.readEntry("IconName", "infrared-remote"));
121  mode->setButton(modeGroup.readEntry("Button"));
122 
123  remote->addMode(mode);
124  }
125  // Read Remote properties here
126  remote->setDefaultMode(remoteGroup.readEntry("DefaultMode"));
127  remote->setModeChangeMode(remoteGroup.readEntry("ModeChangeMode", "Group") == QLatin1String( "Group" ) ? Remote::Group : Remote::Cycle);
128  remote->setNextModeButton(remoteGroup.readEntry("NextModeButton"));
129  remote->setPreviousModeButton(remoteGroup.readEntry("PreviousModeButton"));
130 
131  append(remote);
132  }
133 
134 }
135 Remote* RemoteList::remote ( const QString& remoteName ){
136  for(QVector<Remote*>::const_iterator i = constBegin(); i != constEnd(); ++i){
137  if((*i)->name() == remoteName){
138  return *i;
139  }
140  }
141  return 0;
142 }
143 
Mode::setButton
void setButton(const QString &button)
Definition: mode.cpp:56
RemoteList::remote
Remote * remote(const QString &remoteName)
Definition: remotelist.cpp:135
Remote::setNextModeButton
void setNextModeButton(const QString &button)
Definition: remote.cpp:400
Mode::actions
QVector< Action * > actions() const
Definition: mode.cpp:89
Action::ActionType
ActionType
Definition: action.h:33
Mode
Definition: mode.h:31
RemoteList::contains
bool contains(const QString &remoteName) const
Definition: remotelist.cpp:33
KeypressAction
Definition: keypressaction.h:27
keypressaction.h
QVector
Action::loadFromConfig
virtual void loadFromConfig(const KConfigGroup &config)
Definition: action.cpp:94
Action::KeypressAction
Definition: action.h:33
RemoteList::saveToConfig
void saveToConfig(const QString &configName)
Definition: remotelist.cpp:43
Action
Definition: action.h:30
remotelist.h
DBusAction
Definition: dbusaction.h:32
Remote::Cycle
Definition: remote.h:39
Mode::button
QString button() const
Definition: mode.cpp:44
RemoteList::loadFromConfig
void loadFromConfig(const QString &configName)
Definition: remotelist.cpp:74
Mode::setIconName
void setIconName(const QString &iconName)
Definition: mode.cpp:52
Action::DBusAction
Definition: action.h:33
Remote::setPreviousModeButton
void setPreviousModeButton(const QString &button)
Definition: remote.cpp:409
Action::ProfileAction
Definition: action.h:33
profileaction.h
Remote::addMode
void addMode(Mode *mode)
Add the given Mode to this Remote.
Definition: remote.cpp:273
Mode::addAction
void addAction(Action *action)
Add the given Action to the Mode.
Definition: mode.cpp:64
Action::saveToConfig
virtual void saveToConfig(KConfigGroup &config)
Definition: action.cpp:69
Remote::masterMode
Mode * masterMode() const
Definition: remote.cpp:300
Remote::setDefaultMode
void setDefaultMode(Mode *mode)
Definition: remote.cpp:317
Remote::setModeChangeMode
void setModeChangeMode(ModeChangeMode modeChangeMode)
Definition: remote.cpp:367
ProfileAction
Definition: profileaction.h:26
Mode::name
QString name() const
Definition: mode.cpp:36
Remote::Group
Definition: remote.h:39
Remote
Definition: remote.h:32
Mode::iconName
QString iconName() const
Definition: mode.cpp:40
RemoteList::RemoteList
RemoteList()
Definition: remotelist.cpp:30
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:07:43 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kremotecontrol

Skip menu "kremotecontrol"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeutils API Reference

Skip menu "kdeutils API Reference"
  • ark
  • filelight
  • kcalc
  • kcharselect
  • kdf
  • kfloppy
  • kgpg
  • kremotecontrol
  • ktimer
  • kwallet
  • superkaramba
  • sweeper

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal