KioskTool – tool to configure the TDE kiosk framework
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

310 lignes
6.9 KiB

  1. /*
  2. * kioskdata.cpp
  3. *
  4. * Copyright (C) 2003, 2004 Waldo Bastian <bastian@kde.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. #include "kioskdata.h"
  20. #include <tqdom.h>
  21. #include <tqfile.h>
  22. #include <tdeaction.h>
  23. #include <kdebug.h>
  24. #include <tdelocale.h>
  25. #include <kstandarddirs.h>
  26. #include <kstdaction.h>
  27. TQDict<TQString> *ComponentAction::s_stdActionCaptions = 0;
  28. ComponentAction::ComponentAction()
  29. {
  30. }
  31. ComponentAction::~ComponentAction()
  32. {
  33. }
  34. static TQDict<TQString> *readStdActionCaptions()
  35. {
  36. TQDict<TQString> *captions = new TQDict<TQString>;
  37. for(int i = KStdAction::ActionNone; true;)
  38. {
  39. i++;
  40. TDEAction *action = KStdAction::create((KStdAction::StdAction) i, 0, 0, 0, 0);
  41. if (!action)
  42. break;
  43. TQString caption = action->text();
  44. caption.replace("&","");
  45. captions->insert(TQString::fromLatin1(action->name()), new TQString(caption));
  46. }
  47. return captions;
  48. }
  49. TQString
  50. ComponentAction::expand(const TQString &s)
  51. {
  52. if (s.contains("%action"))
  53. {
  54. if (!s_stdActionCaptions)
  55. s_stdActionCaptions= readStdActionCaptions();
  56. TQString action = key;
  57. action.replace("action/", "");
  58. TQString *caption = s_stdActionCaptions->find(action);
  59. if (caption)
  60. {
  61. TQString result = s;
  62. result.replace("%action", *caption);
  63. return result;
  64. }
  65. }
  66. return s;
  67. }
  68. bool
  69. ComponentAction::load(const TQDomElement &docElem)
  70. {
  71. TQString _type = docElem.attribute("type");
  72. if (_type == "immutable")
  73. type = ActImmutable;
  74. else if (_type == "action restriction")
  75. type = ActRestrict;
  76. else if (_type == "resource restriction")
  77. type = ActResource;
  78. else if (_type == "module")
  79. type = ActModule;
  80. else if (_type == "custom")
  81. type = ActCustom;
  82. else if (_type == "config")
  83. type = ActConfig;
  84. else
  85. {
  86. #ifndef NDEBUG
  87. if (_type.isEmpty())
  88. kdFatal() << "'type' attribute missing or empty in action." << endl;
  89. else
  90. kdFatal() << "Unknown 'type' attribute '" << _type << "' in action." << endl;
  91. #endif
  92. return false;
  93. }
  94. file = docElem.attribute("file");
  95. group = docElem.attribute("group");
  96. key = docElem.attribute("key");
  97. defaultValue = (docElem.attribute("default").lower() == "true");
  98. TQDomNode n = docElem.firstChild();
  99. while( !n.isNull() )
  100. {
  101. TQDomElement e = n.toElement(); // try to convert the node to an element.
  102. if (e.tagName() == "caption")
  103. caption = expand(i18n(e.text().simplifyWhiteSpace().utf8()));
  104. else if (e.tagName() == "description")
  105. description = expand(i18n(e.text().simplifyWhiteSpace().utf8()));
  106. else if (e.tagName() == "action")
  107. {
  108. ComponentAction *subAction = new ComponentAction;
  109. if (subAction->load(e))
  110. {
  111. subActions.append(subAction);
  112. }
  113. else
  114. {
  115. delete subAction;
  116. }
  117. }
  118. n = n.nextSibling();
  119. }
  120. return true;
  121. }
  122. ComponentData::ComponentData()
  123. {
  124. actions.setAutoDelete(true);
  125. }
  126. ComponentData::~ComponentData()
  127. {
  128. }
  129. bool ComponentData::loadActions(const TQDomElement &docElem)
  130. {
  131. TQDomNode n = docElem.firstChild();
  132. while( !n.isNull() )
  133. {
  134. TQDomElement e = n.toElement(); // try to convert the node to an element.
  135. if (e.tagName() != "action")
  136. return false;
  137. ComponentAction *action = new ComponentAction;
  138. if (action->load(e))
  139. {
  140. actions.append(action);
  141. }
  142. else
  143. {
  144. delete action;
  145. }
  146. n = n.nextSibling();
  147. }
  148. return true;
  149. }
  150. void
  151. ComponentExecData::load(const TQDomElement &e)
  152. {
  153. exec = e.attribute("binary");
  154. dcop = e.attribute("dcop");
  155. options = TQStringList::split(',', e.attribute("options"));
  156. args = TQStringList::split(',', e.attribute("args"));
  157. }
  158. void
  159. ComponentData::loadSetup(const TQDomElement &docElem)
  160. {
  161. TQDomNode n = docElem.firstChild();
  162. while( !n.isNull() )
  163. {
  164. TQDomElement e = n.toElement(); // try to convert the node to an element.
  165. if (e.tagName() == "mutable")
  166. {
  167. TQString f = e.attribute("file");
  168. if (!f.isEmpty())
  169. mutableFiles.append(f);
  170. }
  171. else if (e.tagName() == "ignore")
  172. {
  173. TQString f = e.attribute("file");
  174. if (!f.isEmpty())
  175. ignoreFiles.append(f);
  176. }
  177. n = n.nextSibling();
  178. }
  179. }
  180. bool ComponentData::load(const TQDomElement &docElem)
  181. {
  182. id = docElem.attribute("name");
  183. icon = docElem.attribute("icon");
  184. if (id.isEmpty())
  185. return false;
  186. TQDomNode n = docElem.firstChild();
  187. while( !n.isNull() )
  188. {
  189. TQDomElement e = n.toElement(); // try to convert the node to an element.
  190. if (e.tagName() == "caption")
  191. {
  192. caption = i18n(e.text().simplifyWhiteSpace().utf8());
  193. }
  194. #if 0
  195. else if (e.tagName() == "description")
  196. {
  197. description = i18n(e.text().simplifyWhiteSpace().utf8());
  198. }
  199. #endif
  200. else if (e.tagName() == "actions")
  201. {
  202. loadActions(e);
  203. }
  204. else if (e.tagName() == "setup")
  205. {
  206. setup.load(e);
  207. loadSetup(e);
  208. }
  209. else if (e.tagName() == "preview")
  210. {
  211. preview.load(e);
  212. }
  213. n = n.nextSibling();
  214. }
  215. return true;
  216. }
  217. KioskData::KioskData()
  218. {
  219. m_componentData.setAutoDelete(true);
  220. }
  221. KioskData::~KioskData()
  222. {
  223. }
  224. bool KioskData::load()
  225. {
  226. TQString filename = locate("appdata", "kiosk_data.xml");
  227. if (filename.isEmpty())
  228. {
  229. m_errorMsg = i18n("<qt>Could not find <b>kiosk_data.xml</b></qt>");
  230. return false;
  231. }
  232. TQDomDocument doc;
  233. TQFile file( filename );
  234. if ( !file.open( IO_ReadOnly ) )
  235. {
  236. m_errorMsg = i18n("<qt>Could not open <b>%1</b></qt>").arg(filename);
  237. return false;
  238. }
  239. TQString errorMsg;
  240. int errorRow;
  241. int errorCol;
  242. if ( !doc.setContent( &file, &errorMsg, &errorRow, &errorCol ) )
  243. {
  244. m_errorMsg = i18n("<qt>Syntax error in <b>%1</b><br>Line %3, column %4: %2</qt>").arg(filename, errorMsg).arg(errorRow).arg(errorCol);
  245. file.close();
  246. return false;
  247. }
  248. file.close();
  249. TQDomElement docElem = doc.documentElement();
  250. TQDomNode n = docElem.firstChild();
  251. while( !n.isNull() )
  252. {
  253. TQDomElement e = n.toElement(); // try to convert the node to an element.
  254. if (e.tagName() == "group")
  255. {
  256. ComponentData *componentData = new ComponentData;
  257. if (componentData->load(e))
  258. {
  259. m_componentData.insert(componentData->id, componentData);
  260. m_componentList.append(componentData->id);
  261. }
  262. else
  263. {
  264. delete componentData;
  265. }
  266. }
  267. n = n.nextSibling();
  268. }
  269. return true;
  270. }