KioskTool – tool to configure the TDE kiosk framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

307 lines
8.9KB

  1. /*
  2. * componentPage.cpp
  3. *
  4. * Copyright (C) 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 "componentPage.h"
  20. #include <tqcursor.h>
  21. #include <tqfileinfo.h>
  22. #include <tqlabel.h>
  23. #include <tqstylesheet.h>
  24. #include <tqtextedit.h>
  25. #include <tqpushbutton.h>
  26. #include <dcopref.h>
  27. #include <tdeapplication.h>
  28. #include <kdebug.h>
  29. #include <tdelistview.h>
  30. #include <tdelocale.h>
  31. #include <tdemessagebox.h>
  32. #include <kprocess.h>
  33. #include <kstdguiitem.h>
  34. #include "component.h"
  35. #include "kioskdata.h"
  36. #include "kioskrun.h"
  37. ComponentPage::ComponentPage( ComponentData *data, Component *component, TQWidget* parent, const char* name, WFlags fl )
  38. : ComponentPageUI(parent, name, fl), PageWidget(this), m_data(data), m_component(component)
  39. {
  40. m_process = 0;
  41. connect(pbSetup, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotSetup()));
  42. connect(pbPreview, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotPreview()));
  43. pbSetup->setText(i18n("&Setup %1").arg(m_data->caption));
  44. pbPreview->setText(i18n("&Preview %1").arg(m_data->caption));
  45. if (m_data->preview.exec.isEmpty())
  46. pbPreview->hide();
  47. if (m_data->setup.exec.isEmpty())
  48. pbSetup->hide();
  49. if (!pbPreview->isHidden() && !pbSetup->isHidden())
  50. {
  51. static bool firstTime = true;
  52. if (firstTime)
  53. {
  54. firstTime = false;
  55. TQTimer::singleShot(0, this, TQT_SLOT(slotShowNotice()));
  56. }
  57. }
  58. fillActionList(listComponentConfig, m_data);
  59. connect(listComponentConfig, TQT_SIGNAL(currentChanged(TQListViewItem *)),
  60. this, TQT_SLOT(slotShowAction(TQListViewItem *)));
  61. slotShowAction(listComponentConfig->currentItem());
  62. }
  63. ComponentPage::~ComponentPage()
  64. {
  65. delete m_component;
  66. }
  67. void ComponentPage::slotShowNotice()
  68. {
  69. KMessageBox::information(this,
  70. i18n("Selecting the Setup or Preview option may cause the panel and/or the desktop to be temporarily shut down. "
  71. "To prevent data loss please make sure you are not actively using these components."),
  72. i18n("Attention"), "shutdown_notice");
  73. }
  74. void ComponentPage::load()
  75. {
  76. }
  77. bool ComponentPage::save()
  78. {
  79. return saveActionListChanges(listComponentConfig);
  80. }
  81. void ComponentPage::setFocus()
  82. {
  83. listComponentConfig->setFocus();
  84. }
  85. TQString ComponentPage::subCaption()
  86. {
  87. return i18n("Setup %1").arg(m_data->caption);
  88. }
  89. void ComponentPage::slotSetup()
  90. {
  91. if (m_process)
  92. {
  93. m_process->kill();
  94. delete m_process;
  95. }
  96. TQCString dcopApp = m_data->setup.dcop.utf8();
  97. TQCString dcopObj = "qt/" + dcopApp;
  98. if (!dcopApp.isEmpty() && m_data->setup.hasOption("restart"))
  99. DCOPRef(dcopApp, dcopObj).call("quit");
  100. TQApplication::setOverrideCursor( TQCursor(TQt::WaitCursor) );
  101. if (!KioskRun::self()->prepare())
  102. {
  103. TQApplication::restoreOverrideCursor();
  104. KMessageBox::sorry(this,
  105. i18n("<qt>There was an unexpected problem with the runtime environment.</qt>"));
  106. return;
  107. }
  108. KioskRun::self()->makeMutable(true);
  109. if (!save())
  110. {
  111. TQApplication::restoreOverrideCursor();
  112. return;
  113. }
  114. if (m_component)
  115. m_component->slotSetupPrepare();
  116. KioskRun::self()->updateSycoca();
  117. TQApplication::restoreOverrideCursor();
  118. if (!dcopApp.isEmpty())
  119. {
  120. KioskRun::self()->dcopClient()->setNotifications(true);
  121. connect(KioskRun::self()->dcopClient(), TQT_SIGNAL(applicationRegistered( const TQCString& )),
  122. this, TQT_SLOT(slotSetupAppRegistered( const TQCString& )));
  123. }
  124. TQStringList args;
  125. if (m_data->setup.hasOption("nofork"))
  126. args << "--nofork";
  127. args += m_data->setup.args;
  128. m_process = KioskRun::self()->run(m_data->setup.exec, args);
  129. int result = KMessageBox::questionYesNo(this,
  130. i18n("<qt>You can now configure %1. "
  131. "When you are finished click <b>Save</b> to make the new configuration permanent.")
  132. .arg(m_data->caption), i18n("%1 Setup").arg(m_data->caption),
  133. KStdGuiItem::save(), KStdGuiItem::discard());
  134. m_saveSettings = (result == KMessageBox::Yes);
  135. if (!dcopApp.isEmpty())
  136. KioskRun::self()->dcopRef(dcopApp, dcopObj).call("quit");
  137. if (m_process->isRunning())
  138. {
  139. connect(m_process, TQT_SIGNAL(processExited(TDEProcess *)), this, TQT_SLOT(slotPreviewDone()));
  140. }
  141. else
  142. {
  143. slotSetupDone();
  144. }
  145. }
  146. void ComponentPage::slotSetupDone()
  147. {
  148. delete m_process;
  149. m_process = 0;
  150. KioskRun::self()->dcopClient()->setNotifications(false);
  151. disconnect(KioskRun::self()->dcopClient(), TQT_SIGNAL(applicationRegistered( const TQCString& )),
  152. this, TQT_SLOT(slotSetupAppRegistered( const TQCString& )));
  153. KioskRun::self()->makeMutable(false);
  154. if (m_saveSettings)
  155. {
  156. bool result = true;
  157. if (m_component)
  158. result = m_component->setupFinished();
  159. if (!result) return;
  160. // Find new config files.
  161. TQStringList newFiles = KioskRun::self()->newConfigFiles();
  162. for(TQStringList::ConstIterator it = newFiles.begin();
  163. it != newFiles.end(); ++it)
  164. {
  165. if (m_data->ignoreFiles.contains(*it))
  166. {
  167. kdDebug() << "Ignoring new config file " << (*it) << endl;
  168. continue;
  169. }
  170. KioskRun::self()->mergeConfigFile(*it);
  171. }
  172. }
  173. KioskRun::self()->flushConfigCache();
  174. if (m_data->setup.hasOption("restart"))
  175. TDEApplication::tdeinitExec(m_data->setup.exec);
  176. }
  177. void ComponentPage::slotSetupAppRegistered( const TQCString &appid)
  178. {
  179. TQCString dcopApp = m_data->setup.dcop.utf8();
  180. if (dcopApp == appid)
  181. {
  182. kdDebug() << appid << " is up and running" << endl;
  183. if (m_component)
  184. m_component->slotSetupStarted();
  185. }
  186. }
  187. void ComponentPage::slotPreview()
  188. {
  189. if (m_process)
  190. {
  191. m_process->kill();
  192. delete m_process;
  193. }
  194. TQCString dcopApp = m_data->preview.dcop.utf8();
  195. TQCString dcopObj = "qt/" + dcopApp;
  196. if (!dcopApp.isEmpty() && m_data->preview.hasOption("restart"))
  197. DCOPRef(dcopApp, dcopObj).call("quit");
  198. TQApplication::setOverrideCursor( TQCursor(TQt::WaitCursor) );
  199. KioskRun::self()->prepare();
  200. save();
  201. KioskRun::self()->updateSycoca();
  202. TQApplication::restoreOverrideCursor();
  203. if (!dcopApp.isEmpty())
  204. {
  205. KioskRun::self()->dcopClient()->setNotifications(true);
  206. connect(KioskRun::self()->dcopClient(), TQT_SIGNAL(applicationRegistered( const TQCString& )),
  207. this, TQT_SLOT(slotPreviewAppRegistered( const TQCString& )));
  208. }
  209. TQStringList args;
  210. if (m_data->preview.hasOption("nofork"))
  211. args << "--nofork";
  212. args += m_data->preview.args;
  213. m_process = KioskRun::self()->run(m_data->preview.exec, args);
  214. KMessageBox::information(this,
  215. i18n("<qt>This is how %1 will behave and look with the new settings. "
  216. "Any changes you now make to the settings will not be saved.<p>"
  217. "Click <b>Ok</b> to return to your own personal %2 configuration.")
  218. .arg(m_data->caption, m_data->caption), i18n("%1 Preview").arg(m_data->caption));
  219. if (!dcopApp.isEmpty())
  220. KioskRun::self()->dcopRef(dcopApp, dcopObj).call("quit");
  221. if (m_process->isRunning())
  222. {
  223. connect(m_process, TQT_SIGNAL(processExited(TDEProcess *)), this, TQT_SLOT(slotPreviewDone()));
  224. }
  225. else
  226. {
  227. slotPreviewDone();
  228. }
  229. }
  230. void ComponentPage::slotPreviewAppRegistered( const TQCString &appid)
  231. {
  232. TQCString dcopApp = m_data->preview.dcop.utf8();
  233. if (dcopApp == appid)
  234. {
  235. kdDebug() << appid << " is up and running" << endl;
  236. if (m_component)
  237. m_component->slotPreviewStarted();
  238. }
  239. }
  240. void ComponentPage::slotPreviewDone()
  241. {
  242. KioskRun::self()->dcopClient()->setNotifications(false);
  243. disconnect(KioskRun::self()->dcopClient(), TQT_SIGNAL(applicationRegistered( const TQCString& )),
  244. this, TQT_SLOT(slotPreviewAppRegistered( const TQCString& )));
  245. delete m_process;
  246. m_process = 0;
  247. if (m_data->preview.hasOption("restart"))
  248. TDEApplication::tdeinitExec(m_data->preview.exec);
  249. }
  250. void ComponentPage::slotShowAction(TQListViewItem *item)
  251. {
  252. ComponentActionItem *actionItem = dynamic_cast<ComponentActionItem*>(item);
  253. TQString description;
  254. if (actionItem)
  255. {
  256. description = "<h2>"+TQStyleSheet::escape(actionItem->action()->caption)+"</h2>\n";
  257. description += actionItem->action()->description;
  258. }
  259. componentDescription->setText(description);
  260. }
  261. #include "componentPage.moc"