summaryrefslogtreecommitdiffstats
path: root/superkaramba/src/karambainterface.cpp
blob: 7a201d8a3f634b08f978c1e05bac1024c14f2f74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/***************************************************************************
 *   Copyright (C) 2004 by Petri Damsten                                   *
 *   petri.damsten@iki.fi                                                  *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/

#include "karamba.h"
#include "karambainterface.h"
#include <kdebug.h>
#include "qwidgetlist.h"
#include "themesdlg.h"

KarambaIface::KarambaIface(): DCOPObject("KarambaIface")
{
}

KarambaIface::~KarambaIface()
{
}

karamba* KarambaIface::getKaramba(QString name)
{
  QWidgetList *list = QApplication::allWidgets();
  QWidgetListIt it(*list);  // iterate over the widgets
  QWidget* w;
  karamba* result = 0;

  while ( (w=it.current()) != 0 )  // for each widget...
  {
    ++it;
    if (QString(w->name()).startsWith("karamba"))
    {
      karamba* k = (karamba*) w;
      //if(k->prettyName == name)
      if(k->theme().name() == name)
      {
        result = k;
        break;
      }
    }
  }
  delete list;
  return result;
}

ThemesDlg* KarambaIface::getThemeWnd()
{
  QWidgetList  *list = QApplication::allWidgets();
  QWidgetListIt it( *list );         // iterate over the widgets
  QWidget* w;
  ThemesDlg* result = 0;

  while ( (w=it.current()) != 0 ) // for each widget...
  {
    ++it;
    if (QString(w->name()) == "ThemesLayout")
    {
      result = (ThemesDlg*) w;
      break;
    }
  }
  delete list;                      // delete the list, not the widgets
  return result;
}

void KarambaIface::openTheme(QString filename)
{
  QFileInfo file(filename);
  if(file.exists())
  {
    (new karamba(filename, QString()))->show();
  }
}

void KarambaIface::openNamedTheme(QString filename, QString name, bool is_sub_theme)
{
	QFileInfo file(filename);
	if(file.exists())
	{
		(new karamba(filename, name, false, -1, is_sub_theme))->show();
	}
}

void KarambaIface::closeTheme(QString name)
{
  kdDebug() << "KarambaIface::closeTheme: " << name << endl;
  karamba* k;

  while((k = getKaramba(name)))
  {
    k->writeConfigData();
    k->close(true);
  }
}

int KarambaIface::themeAdded(QString appId, QString file)
{
  ThemesDlg* tw = getThemeWnd();
  if(tw)
    return tw->addTheme(appId, file);
  return -1;
}

void KarambaIface::themeNotify(QString name, QString text)
{
  karamba* k = getKaramba(name);
  if(k)
  {
    k->themeNotify(name, text);
  }
}

void KarambaIface::setIncomingData(QString name, QString text)
{
  karamba* k = getKaramba(name);
  if(k)
  {
    k->_setIncomingData(text);
  }
}

void KarambaIface::themeClosed(QString appId, QString file, int instance)
{
  ThemesDlg* tw = getThemeWnd();
  if(tw)
    tw->removeTheme(appId, file, instance);
}

bool KarambaIface::isMainKaramba()
{
  if(getThemeWnd())
    return true;
  return false;
}

void KarambaIface::quit()
{
  karambaApp->quitSuperKaramba();
}

void KarambaIface::hideSystemTray(bool hide)
{
  karambaApp->hideSysTray(hide);
}

void KarambaIface::showThemeDialog()
{
  karambaApp->showThemeDialog();
}