• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • superkaramba
 

superkaramba

  • superkaramba
  • src
karambaapp.cpp
1/***************************************************************************
2 * Copyright (C) 2003-2004 Adam Geitgey <adam@rootnode.org> *
3 * Copyright (C) 2003 Hans Karlsson <karlsson.h@home.se> *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 ***************************************************************************/
10
11#include <tqstring.h>
12#include <tqstringlist.h>
13#include <tqdir.h>
14#include <tdefiledialog.h>
15#include <tdecmdlineargs.h>
16#include <fcntl.h>
17#include <tdelocale.h>
18#include <tdemessagebox.h>
19#include <kdebug.h>
20#include <khelpmenu.h>
21
22#include <tqtooltip.h>
23
24#include "themesdlg.h"
25#include "karambainterface.h"
26#include "karambaapp.h"
27#include "dcopinterface_stub.h"
28#include "karamba.h"
29#include "superkarambasettings.h"
30#include "tqwidgetlist.h"
31
32int KarambaApplication::fd = -1;
33
34KarambaApplication::KarambaApplication() :
35 m_helpMenu(0), iface(0), themeListWindow(0), dcopIfaceStub(0),
36 karambaList(0), sysTrayIcon(0)
37{
38 iface = new KarambaIface();
39 karambaList = new TQObjectList();
40 // register ourselves as a dcop client
41 dcopClient()->registerAs(name());
42 dcopClient()->setDefaultObject(dcopIface()->objId());
43}
44
45KarambaApplication::~KarambaApplication()
46{
47 delete iface;
48 delete karambaList;
49 delete themeListWindow;
50 delete dcopIfaceStub;
51 //delete m_helpMenu;
52}
53
54void KarambaApplication::initDcopStub(TQCString app)
55{
56 if(app.isEmpty())
57 app = dcopClient()->appId();
58 dcopIfaceStub = new dcopIface_stub(app, iface->objId());
59}
60
61TQString KarambaApplication::getMainKaramba()
62{
63 TQStringList karambas = getKarambas();
64 TQStringList::Iterator it;
65
66 for (it = karambas.begin(); it != karambas.end(); ++it)
67 {
68 if((*it).ascii() == dcopClient()->appId())
69 continue;
70 dcopIface_stub dcop((*it).ascii(), iface->objId());
71 if (dcop.isMainKaramba())
72 return *it;
73 }
74 return TQString();
75}
76
77bool KarambaApplication::themeExists(TQString pretty_name)
78{
79 TQWidgetList *list = TQApplication::allWidgets();
80 TQWidgetListIt it( *list ); // iterate over the widgets
81 TQWidget * w;
82 while ( (w=it.current()) != 0 ) // for each widget...
83 {
84 ++it;
85 if (TQString(w->name()).startsWith("karamba"))
86 {
87 karamba* k = (karamba*) w;
88 if (k->getPrettyName() == pretty_name)
89 return true;
90 }
91 }
92 delete list; // delete the list, not the widgets
93 return false;
94}
95
96TQStringList KarambaApplication::getKarambas()
97{
98 QCStringList applst = dcopClient()->registeredApplications();
99 QCStringList::Iterator it;
100 TQCString s;
101 TQStringList result;
102
103 for (it = applst.begin(); (s = *it) != 0; ++it)
104 {
105 if (s.left(strlen(name())) == name())
106 result.append(s);
107 }
108 return result;
109}
110
111void KarambaApplication::checkSuperKarambaDir()
112{
113 // Create ~/.superkaramba if necessary
114 TQDir configDir(TQDir::home().absPath() + "/.superkaramba");
115 if (!configDir.exists())
116 {
117 tqWarning("~/.superkaramba doesn't exist");
118 if(!configDir.mkdir(TQDir::home().absPath() + "/.superkaramba"))
119 {
120 tqWarning("Couldn't create Directory ~/.superkaramba");
121 }
122 else
123 {
124 tqWarning("created ~/.superkaramba");
125 }
126 }
127}
128
129void KarambaApplication::setUpSysTray(TDEAboutData* about)
130{
131 //kdDebug() << k_funcinfo << endl;
132 TDEAction* action;
133
134 //Create theme list window.
135 //This will function as the main window for the tray icon
136 themeListWindow = new ThemesDlg();
137
138 //Set up systray icon
139 sysTrayIcon = new KSystemTray(themeListWindow);
140
141 TDEPopupMenu *menu = sysTrayIcon->contextMenu();
142 menu->insertItem(SmallIconSet("superkaramba"),
143 i18n("Hide System Tray Icon"), this,
144 TQ_SLOT(globalHideSysTray()));
145 menu->insertSeparator();
146
147 m_helpMenu = new KHelpMenu(themeListWindow, about);
148 action = KStdAction::help(m_helpMenu, TQ_SLOT(appHelpActivated()),
149 sysTrayIcon->actionCollection());
150 action->plug(menu);
151 action = KStdAction::aboutApp(m_helpMenu, TQ_SLOT(aboutApplication()),
152 sysTrayIcon->actionCollection());
153 action->plug(menu);
154 action = KStdAction::aboutKDE(m_helpMenu, TQ_SLOT(aboutKDE()),
155 sysTrayIcon->actionCollection());
156 action->plug(menu);
157
158 sysTrayIcon->setPixmap(sysTrayIcon->loadIcon("superkaramba"));
159 setToolTip();
160
161 if(SuperKarambaSettings::showSysTray())
162 sysTrayIcon->show();
163 else
164 sysTrayIcon->hide();
165
166 //Connect Systray icon's quit event
167 TQObject::connect(sysTrayIcon, TQ_SIGNAL(quitSelected()),
168 this, TQ_SLOT(globalQuitSuperKaramba()));
169}
170
171void KarambaApplication::showKarambaMenuExtension(bool show)
172{
173 TQObject *k;
174
175 if(show)
176 {
177 for (k = karambaList->first(); k; k = karambaList->next())
178 {
179 ((karamba*)k)->showMenuExtension();
180 }
181 }
182 else
183 {
184 for (k = karambaList->first(); k; k = karambaList->next())
185 {
186 ((karamba*)k)->hideMenuExtension();
187 }
188 }
189}
190
191void KarambaApplication::setToolTip(const TQString &tip)
192{
193 TQToolTip::remove(sysTrayIcon);
194 if(tip.isNull())
195 TQToolTip::add(sysTrayIcon, i18n("SuperKaramba"));
196 else
197 TQToolTip::add(sysTrayIcon, tip);
198}
199
200void KarambaApplication::buildToolTip()
201{
202 if(!sysTrayIcon || !themeListWindow)
203 return;
204
205 TQStringList list = themeListWindow->runningThemes();
206
207 if(list.isEmpty())
208 {
209 setToolTip();
210 return;
211 }
212
213 TQString toolTip("<b><center>" + i18n("SuperKaramba") + "</center></b>");
214 toolTip += "<table width=300>";
215
216 bool firstRun = true;
217 for(TQStringList::Iterator it = list.begin(); it != list.end(); ++it )
218 {
219 if(firstRun)
220 {
221 toolTip +=
222 "<tr><td align=right>" +
223 i18n("1 Running Theme:", "%n Running Themes:", list.count()) +
224 "</td><td align=left>" + (*it) + "</td></tr>";
225 firstRun = false;
226 }
227 else
228 {
229 toolTip += "<tr><td></td><td align=left>" + (*it) + "</td></tr>";
230 }
231 }
232
233 toolTip += "</table>";
234
235 setToolTip(toolTip);
236}
237
238void KarambaApplication::checkPreviousSession(TDEApplication &app,
239 TQStringList &lst)
240{
241 /******
242 Try to restore a previous session if applicable.
243 */
244 if (app.isSessionRestored())
245 {
246 TDEConfig* config = app.sessionConfig();
247 config->setGroup("General Options");
248 TQString restartThemes = config->readEntry("OpenThemes");
249
250 //Get themes that were running
251 lst = TQStringList::split(TQString(";"), restartThemes);
252 }
253}
254
255void KarambaApplication::checkCommandLine(TDECmdLineArgs *args, TQStringList &lst)
256{
257 /******
258 Not a saved session - check for themes given on command line
259 */
260 if(args->count() > 0)
261 {
262 for(int i = 0; i < (args->count()); i++)
263 {
264 if( args->arg(i) && *args->arg(i) )
265 {
266 KURL url = args->url(i);
267
268 lst.push_back(url.path());
269 }
270 }
271 }
272}
273
274bool KarambaApplication::startThemes(TQStringList &lst)
275{
276 bool result = false;
277
278 for(TQStringList::Iterator it = lst.begin(); it != lst.end(); ++it )
279 {
280 karamba *mainWin = 0;
281
282 mainWin = new karamba(*it , TQString());
283 mainWin->show();
284 result = true;
285 }
286
287 buildToolTip();
288 return result;
289}
290
291void KarambaApplication::addKaramba(karamba* k, bool reloading)
292{
293 if(!reloading && karambaApp->dcopStub())
294 {
295 int instance = karambaApp->dcopStub()->themeAdded(
296 karambaApp->dcopClient()->appId(), k->theme().file());
297 k->setInstance(instance);
298 }
299 karambaList->append(k);
300}
301
302void KarambaApplication::deleteKaramba(karamba* k, bool reloading)
303{
304 if(!reloading && karambaApp->dcopStub())
305 karambaApp->dcopStub()->themeClosed(
306 karambaApp->dcopClient()->appId(), k->theme().file(), k->instance());
307 karambaList->removeRef(k);
308}
309
310bool KarambaApplication::hasKaramba(karamba* k)
311{
312 return karambaList->containsRef(k) > 0;
313}
314
315// XXX: I guess this should be made with mutex/semaphores
316// but this is good for now...
317
318bool KarambaApplication::lockKaramba()
319{
320 TQString file = TQDir::home().absPath() + "/.superkaramba/.lock";
321 mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
322
323 fd = open(file.ascii(), O_CREAT | O_RDWR | O_TRUNC, mode);
324 if (fd < 0)
325 {
326 tqWarning("Open failed in lock.");
327 return false;
328 }
329 //tqDebug("lock %d", getpid());
330 if(lockf(fd, F_LOCK, 0))
331 {
332 tqWarning("Lock failed.");
333 return false;
334 }
335 return true;
336}
337
338void KarambaApplication::unlockKaramba()
339{
340 if(fd > 0)
341 {
342 lockf(fd, F_ULOCK, 0);
343 //tqDebug("Unlock %d", getpid());
344 close(fd);
345 fd = -1;
346 }
347}
348
349void KarambaApplication::hideSysTray(bool hide)
350{
351 //kdDebug() << k_funcinfo << endl;
352 if(hide)
353 {
354 if(sysTrayIcon)
355 {
356 KMessageBox::information(0,
357 i18n("<qt>Hiding the system tray icon will keep SuperKaramba running "
358 "in background. To show it again use the theme menu.</qt>"),
359 i18n("Hiding System Tray Icon"), "hideIcon");
360 sysTrayIcon->hide();
361 }
362 showKarambaMenuExtension();
363 }
364 else
365 {
366 showKarambaMenuExtension(false);
367 if(sysTrayIcon)
368 sysTrayIcon->show();
369 }
370}
371
372void KarambaApplication::showThemeDialog()
373{
374 //kdDebug() << k_funcinfo << endl;
375 if(themeListWindow)
376 themeListWindow->show();
377}
378
379void KarambaApplication::quitSuperKaramba()
380{
381 if(themeListWindow)
382 themeListWindow->saveUserAddedThemes();
383 tqApp->closeAllWindows();
384 tqApp->quit();
385}
386
387void KarambaApplication::globalQuitSuperKaramba()
388{
389 TQStringList apps = getKarambas();
390 TQStringList::Iterator it;
391
392 for (it = apps.begin(); it != apps.end(); ++it)
393 {
394 dcopIface_stub dcop((*it).ascii(), dcopIface()->objId());
395 dcop.quit();
396 }
397}
398
399void KarambaApplication::globalShowThemeDialog()
400{
401 TQStringList apps = getKarambas();
402 TQStringList::Iterator it;
403
404 for (it = apps.begin(); it != apps.end(); ++it)
405 {
406 dcopIface_stub dcop((*it).ascii(), dcopIface()->objId());
407 dcop.showThemeDialog();
408 }
409}
410
411void KarambaApplication::globalHideSysTray(bool hide)
412{
413 //kdDebug() << k_funcinfo << endl;
414 TQStringList apps = getKarambas();
415 TQStringList::Iterator it;
416
417 SuperKarambaSettings::setShowSysTray(!hide);
418 SuperKarambaSettings::writeConfig();
419
420 for (it = apps.begin(); it != apps.end(); ++it)
421 {
422 dcopIface_stub dcop((*it).ascii(), dcopIface()->objId());
423 dcop.hideSystemTray(hide);
424 }
425}
426
427#include "karambaapp.moc"

superkaramba

Skip menu "superkaramba"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members

superkaramba

Skip menu "superkaramba"
  • kcalc
  •   knumber
  • superkaramba
Generated for superkaramba by doxygen 1.9.4
This website is maintained by Timothy Pearson.