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

superkaramba

  • superkaramba
  • src
themesdlg.cpp
1 /*
2  * Copyright (C) 2005 Petri Damstén <petri.damsten@iki.fi>
3  *
4  * This file is part of SuperKaramba.
5  *
6  * SuperKaramba is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * SuperKaramba is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with SuperKaramba; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  ****************************************************************************/
20 #include "karambaapp.h"
21 #include "dcopinterface_stub.h"
22 #include "karambainterface.h"
23 #include "themesdlg.h"
24 #include "themewidget.h"
25 #include "kwidgetlistbox.h"
26 #include "karamba.h"
27 
28 #ifdef HAVE_CONFIG_H
29  #include <config.h>
30 #endif
31 
32 #ifdef HAVE_TDENEWSTUFF
33  #include "sknewstuff.h"
34 #endif
35 
36 #include "superkarambasettings.h"
37 #include <karchive.h>
38 #include <kdebug.h>
39 #include <tdefiledialog.h>
40 #include <kpushbutton.h>
41 #include <tdestandarddirs.h>
42 #include <tdeapplication.h>
43 #include <kiconloader.h>
44 #include <tdelocale.h>
45 #include <tqlineedit.h>
46 #include <tqtable.h>
47 #include <tqdir.h>
48 #include <tqlabel.h>
49 #include <tqcombobox.h>
50 #include <tqptrlist.h>
51 #include <tdeio/job.h>
52 #include <kprotocolinfo.h>
53 
54 ThemesDlg::ThemesDlg(TQWidget *parent, const char *name)
55  : ThemesLayout(parent, name)
56 {
57  populateListbox();
58 #ifdef HAVE_TDENEWSTUFF
59  mNewStuff = 0;
60 #endif
61 }
62 
63 ThemesDlg::~ThemesDlg()
64 {
65  //kdDebug() << k_funcinfo << endl;
66  saveUserAddedThemes();
67 #ifdef HAVE_TDENEWSTUFF
68  if(mNewStuff)
69  {
70  delete mNewStuff;
71  }
72 #endif
73 }
74 
75 void ThemesDlg::saveUserAddedThemes()
76 {
77  TDEStandardDirs ksd;
78  TQStringList t = themes();
79  TQStringList dirs = ksd.findDirs("data", TQString(tdeApp->name()) + "/themes");
80  TQStringList::Iterator it = t.begin();
81  bool remove;
82 
83  while(it != t.end())
84  {
85  remove = false;
86  TQStringList::Iterator jtend( dirs.end() );
87  for(TQStringList::Iterator jt = dirs.begin(); jt != jtend; ++jt)
88  {
89  if(TQFileInfo(*it).dir().path() + "/" == *jt)
90  {
91  remove = true;
92  break;
93  }
94  }
95  if(remove)
96  it = t.remove(it);
97  else
98  ++it;
99  }
100  SuperKarambaSettings::setUserAddedThemes(t);
101  SuperKarambaSettings::writeConfig();
102 }
103 
104 TQStringList ThemesDlg::themes()
105 {
106  TQStringList result;
107  ThemeWidget* w;
108 
109  for(uint i = 2; i < tableThemes->count(); ++i)
110  {
111  w = static_cast<ThemeWidget*>(tableThemes->item(i));
112 
113  result.append(w->themeFile()->file());
114  }
115  return result;
116 }
117 
118 void ThemesDlg::populateListbox()
119 {
120  ThemeWidget* item;
121  TQDir dir;
122  TQStringList dirs;
123  TQStringList t;
124  TDEStandardDirs ksd;
125 
126  tableThemes->clear();
127 
128  item = new ThemeWidget;
129  item->icon->setPixmap(TDEGlobal::iconLoader()->loadIcon("knewstuff",
130  TDEIcon::NoGroup, TDEIcon::SizeHuge));
131  item->setHeaderText(i18n("Get New Stuff"));
132  item->setDescriptionText(i18n("Download new themes."));
133 
134  item->buttonGo->setText(i18n("New Stuff..."));
135 #ifdef HAVE_TDENEWSTUFF
136  item->buttonGo->setEnabled(true);
137  connect(item->buttonGo, TQ_SIGNAL(clicked()),
138  this, TQ_SLOT(getNewStuff()));
139 #else
140  item->buttonGo->setEnabled(false);
141 #endif
142  tableThemes->insertItem(item);
143 
144  item = new ThemeWidget;
145  item->icon->setPixmap(TDEGlobal::iconLoader()->loadIcon("ksysguard",
146  TDEIcon::NoGroup, TDEIcon::SizeHuge));
147  item->setHeaderText(i18n("Open Local Theme"));
148  item->setDescriptionText(i18n("Add local theme to the list."));
149  item->buttonGo->setProperty("stdItem", 18);
150  item->buttonGo->setText(i18n("Open..."));
151  connect(item->buttonGo, TQ_SIGNAL(clicked()),
152  this, TQ_SLOT(openLocalTheme()));
153  tableThemes->insertItem(item);
154 
155  dirs = ksd.findDirs("data", TQString(tdeApp->name()) + "/themes");
156  // Get custom dirs from config here?
157  TQStringList::Iterator itend( dirs.end() );
158  for(TQStringList::Iterator it = dirs.begin(); it != itend; ++it )
159  {
160  dir.setPath(*it);
161  t = dir.entryList("*.skz; *.theme");
162  for(TQStringList::Iterator it = t.begin(); it != t.end(); ++it )
163  {
164  item = new ThemeWidget(new ThemeFile(dir.filePath(*it)));
165  tableThemes->insertItem(item);
166  item->buttonGo->setText(i18n("Uninstall"));
167  connect(item->buttonGo, TQ_SIGNAL(clicked()),
168  this, TQ_SLOT(uninstall()));
169  }
170  }
171  t = SuperKarambaSettings::userAddedThemes();
172  for(TQStringList::Iterator it = t.begin(); it != t.end(); ++it )
173  {
174  ThemeFile* file = new ThemeFile(*it);
175 
176  if(file->isValid())
177  {
178  item = new ThemeWidget(file);
179  tableThemes->insertItem(item);
180  item->buttonGo->setText(i18n("Uninstall"));
181  connect(item->buttonGo, TQ_SIGNAL(clicked()),
182  this, TQ_SLOT(uninstall()));
183  }
184  else
185  delete file;
186  }
187  tableThemes->setSelected(0);
188 }
189 
190 void ThemesDlg::addToDesktop()
191 {
192  ThemeWidget* w = static_cast<ThemeWidget*>(tableThemes->selectedItem());
193  if(w)
194  {
195  ThemeFile* tf = w->themeFile();
196  if(tf)
197  {
198  (new karamba(tf->file(), TQString()))->show();
199  }
200  }
201 }
202 
203 void ThemesDlg::openLocalTheme()
204 {
205  TQStringList fileNames;
206  fileNames = KFileDialog::getOpenFileNames(":<themes>",
207  i18n("*.theme *.skz|Themes"),
208  this, i18n("Open Themes"));
209  for(TQStringList::Iterator it = fileNames.begin(); it != fileNames.end(); ++it)
210  {
211  ThemeFile file(*it);
212  if(file.isValid())
213  (new karamba(*it, TQString()))->show();
214  }
215 }
216 
217 void ThemesDlg::getNewStuff()
218 {
219 #ifdef HAVE_TDENEWSTUFF
220  TDEConfig* config = TDEGlobal::config();
221  config->setGroup("TDENewStuff");
222  config->writePathEntry("ProvidersUrl",
223  TQString::fromLatin1("https://www.trinitydesktop.org/ocs/karamba-providers.xml"));
224  config->sync();
225  m_newStuffStatus = config->entryMap("TDENewStuffStatus").keys();
226  //This check is b/c TDENewStuff will download, throw an error,
227  //and still have the entry in the config that it was successful
228  configSanityCheck();
229 
230  if ( !mNewStuff )
231  {
232  mNewStuff = new SKNewStuff(this);
233  }
234  mNewStuff->download();
235 #endif
236 }
237 
238 void ThemesDlg::selectionChanged(int index)
239 {
240  buttonAddToDesktop->setEnabled(index > 1);
241 
242  for(uint i=2; i < tableThemes->count(); ++i)
243  {
244  ThemeWidget* w = static_cast<ThemeWidget*>(tableThemes->item(i));
245  w->showButton(false);
246  }
247  ThemeWidget* w = static_cast<ThemeWidget*>(tableThemes->item(index));
248  ThemeFile* themeFile = w->themeFile();
249  if(themeFile && themeFile->canUninstall())
250  w->showButton(true);
251 }
252 
253 int ThemesDlg::themeIndex(TQString file)
254 {
255  ThemeWidget* w;
256  file = ThemeFile::canonicalFile(file);
257 
258  for(uint i = 2; i < tableThemes->count(); ++i)
259  {
260  w = static_cast<ThemeWidget*>(tableThemes->item(i));
261 
262  if(w->themeFile()->file() == file)
263  return i;
264  }
265  return -1;
266 }
267 
268 void ThemesDlg::addSkzThemeToDialog(const TQString &file)
269 {
270  kdDebug() << "addSkzThemeToDialog(): file = " << file << endl;
271  addThemeToList(file);
272  writeNewStuffConfig(file);
273 }
274 
275 void ThemesDlg::addThemeToDialog(const KArchiveDirectory *archiveDir,
276  const TQString& destDir)
277 {
278  kdDebug() << "addThemeToDialog(): destDir = " << destDir << endl;
279  TQStringList entries = archiveDir->entries();
280 
281  TQStringList::Iterator end( entries.end() );
282  for(TQStringList::Iterator it = entries.begin(); it != end; ++it)
283  {
284  if(archiveDir->entry(*it)->isDirectory())
285  {
286  addThemeToDialog(static_cast<const KArchiveDirectory*>(archiveDir->entry(*it)),
287  destDir + *it + "/");
288  }
289  else
290  {
291  TQFileInfo fi(*it);
292  if(fi.extension( FALSE ) == "theme")
293  {
294  addThemeToList(destDir + *it);
295  writeNewStuffConfig(destDir);
296  }
297  }
298  }
299 }
300 
301 void ThemesDlg::writeNewStuffConfig(const TQString &file)
302 {
303 #ifdef HAVE_TDENEWSTUFF
304  TDEConfig* config = TDEGlobal::config();
305  TQStringList keys = config->entryMap("TDENewStuffStatus").keys();
306 
307  for(TQStringList::Iterator it = m_newStuffStatus.begin();
308  it != m_newStuffStatus.end(); ++it)
309  {
310  keys.remove(*it);
311  }
312  if(!keys.isEmpty())
313  {
314  config->setGroup("TDENewStuffNames");
315  config->writeEntry(file, keys[0]);
316  config->sync();
317  }
318 #endif
319 }
320 
321 void ThemesDlg::configSanityCheck()
322 {
323 #ifdef HAVE_TDENEWSTUFF
324  TDEConfig* config = TDEGlobal::config();
325  TQStringList statusKeys = config->entryMap("TDENewStuffStatus").keys();
326  TQStringList nameKeys = config->entryMap("TDENewStuffNames").keys();
327  TQStringList removeList;
328 
329  for(TQStringList::Iterator it = statusKeys.begin();
330  it != statusKeys.end(); ++it)
331  {
332  TQString keyName(*it);
333  bool removeKey = true;
334  config->setGroup("TDENewStuffNames");
335  for(TQStringList::Iterator it2 = nameKeys.begin();
336  it2 != nameKeys.end(); ++it2)
337  {
338  TQString tempName(config->readEntry(*it2));
339  if( tempName.compare(keyName) == 0)
340  {
341  removeKey = false;
342  }
343 
344  }
345  if( removeKey )
346  {
347  kdDebug() << "sanityCheck() deleting entry " << keyName << endl;
348  config->setGroup("TDENewStuffStatus");
349  config->deleteEntry( keyName );
350  }
351  }
352  config->sync();
353 #endif
354 }
355 
356 int ThemesDlg::addThemeToList(const TQString &file)
357 {
358  kdDebug() << "addThemeToList() file: " << file << endl;
359  int i = themeIndex(file);
360  if(i < 0)
361  {
362  ThemeWidget* item = new ThemeWidget(new ThemeFile(file));
363 
364  i = tableThemes->insertItem(item);
365  item->buttonGo->setText(i18n("Uninstall"));
366  connect(item->buttonGo, TQ_SIGNAL(clicked()),
367  this, TQ_SLOT(uninstall()));
368  }
369  tableThemes->setSelected(i);
370  return i;
371 }
372 
373 int ThemesDlg::addTheme(const TQString& , const TQString &file)
374 {
375  int i = addThemeToList(file);
376  int result = -1;
377 
378  ThemeWidget* w = static_cast<ThemeWidget*>(tableThemes->item(i));
379  if(w)
380  result = w->addInstance();
381  karambaApp->buildToolTip();
382  return result;
383 }
384 
385 void ThemesDlg::removeTheme(const TQString&, const TQString& file, int instance)
386 {
387  int i = themeIndex(file);
388 
389  ThemeWidget* w = static_cast<ThemeWidget*>(tableThemes->item(i));
390  if(w)
391  w->removeInstance(instance);
392  karambaApp->buildToolTip();
393 }
394 
395 void ThemesDlg::search(const TQString&)
396 {
397  tableThemes->showItems(&filter, this);
398 }
399 
400 bool ThemesDlg::filter(int index, TQWidget* widget, void* data)
401 {
402  if(index < 2)
403  return true;
404 
405  ThemesDlg* dlg = static_cast<ThemesDlg*>(data);
406  ThemeWidget* w = static_cast<ThemeWidget*>(widget);
407 
408  if(dlg->comboShow->currentItem() == 1) // Running themes
409  if(w->instances() == 0)
410  return false;
411 
412  TQString searchText = dlg->editSearch->text().lower();
413  if(searchText.isEmpty())
414  {
415  return true;
416  }
417  else
418  {
419  if(w->themeName->text().lower().contains(searchText))
420  return true;
421  if(w->description->text().lower().contains(searchText))
422  return true;
423  }
424  return false;
425 }
426 
427 bool ThemesDlg::isDownloaded( const TQString& path )
428 {
429  kdDebug() << "isDownloaded path: " << path << endl;
430  TDEConfig* config = TDEGlobal::config();
431  config->setGroup("TDENewStuffNames");
432  return !config->readEntry(path).isEmpty();
433 }
434 
435 void ThemesDlg::uninstall()
436 {
437  ThemeWidget* w = static_cast<ThemeWidget*>(tableThemes->selectedItem());
438  ThemeFile* tf = w->themeFile();
439  KURL trash("trash:/");
440  KURL theme(tf->file());
441  TQString tempPath(tf->path());
442 
443  karambaApp->dcopIface()->closeTheme(tf->name());
444  if(!KProtocolInfo::isKnownProtocol(trash))
445  trash = TDEGlobalSettings::trashPath();
446 
447  if(!tf->isZipTheme())
448  {
449  kdDebug() << "encountered unpacked theme" << endl;
450  //Don't move it to the trash if it is a local theme
451  if(isDownloaded(tempPath))
452  {
453  TQFileInfo remPath(tf->path());
454  TQDir remDir(remPath.dir());
455  remDir.cdUp();
456  kdDebug() << "moving " << remDir.path() << " to the trash" << endl;
457  TDEIO::move(remDir.path(), trash);
458  }
459  tableThemes->removeItem(w);
460 
461  //some themes have multiple .theme files
462  //find all .themes that could be listed in the dialog for the directory removed
463  TQPtrList<ThemeWidget> list;
464  for(uint i = 2; i < tableThemes->count(); ++i)
465  {
466  ThemeWidget* tempW = static_cast<ThemeWidget*>(tableThemes->item(i));
467  ThemeFile* tempTf = tempW->themeFile();
468  if( tempTf->path().compare( tempPath ) == 0 )
469  {
470  list.append( tempW );
471  }
472  }
473  ThemeWidget *twPtr;
474  for ( twPtr = list.first(); twPtr; twPtr = list.next() )
475  {
476  karambaApp->dcopIface()->closeTheme(twPtr->themeFile()->name());
477  tableThemes->removeItem( twPtr );
478  }
479 #ifdef HAVE_TDENEWSTUFF
480  // Remove theme from TDENewStuffStatus
481  TDEConfig* config = TDEGlobal::config();
482  config->setGroup("TDENewStuffNames");
483  TQString name = config->readEntry(tempPath);
484  if(!name.isEmpty())
485  {
486  kdDebug() << "removing " << tempPath << " under TDENewStuffNames from superkarambarc"
487  << endl;
488  tdeApp->config()->deleteEntry(tempPath);
489  config->setGroup("TDENewStuffStatus");
490  kdDebug() << "removing " << name << " under TDENewStuffStatus from superkarambarc"
491  << endl;
492  tdeApp->config()->deleteEntry(name);
493  tdeApp->config()->sync();
494  }
495 #endif
496 
497  }
498  else
499  {
500  kdDebug() << "encountered skz theme" << endl;
501  if(isDownloaded(theme.path()))
502  {
503  TQFileInfo remPath(theme.path());
504  TQDir remDir(remPath.dir());
505  kdDebug() << "moving " << remDir.path() << " to the trash" << endl;
506  TDEIO::move(remDir.path(), trash);
507  }
508  tableThemes->removeItem(w);
509 #ifdef HAVE_TDENEWSTUFF
510  // Remove theme from TDENewStuffStatus
511  TDEConfig* config = TDEGlobal::config();
512  config->setGroup("TDENewStuffNames");
513  TQString name = config->readEntry(theme.path());
514  if(!name.isEmpty())
515  {
516  kdDebug() << "removing " << theme.path() << " from superkarambarc" << endl;
517  tdeApp->config()->deleteEntry(theme.path());
518  config->setGroup("TDENewStuffStatus");
519  kdDebug() << "removing " << name << " from superkarambarc" << endl;
520  tdeApp->config()->deleteEntry(name);
521  tdeApp->config()->sync();
522  }
523 #endif
524  }
525  selectionChanged(tableThemes->selected());
526 }
527 
528 TQStringList ThemesDlg::runningThemes()
529 {
530  TQStringList list;
531  ThemeWidget* w;
532 
533  for(uint i = 2; i < tableThemes->count(); ++i)
534  {
535  w = static_cast<ThemeWidget*>(tableThemes->item(i));
536 
537  if(w->instances() > 0)
538  list.append(w->themeFile()->name());
539  }
540  return list;
541 }
542 
543 #include "themesdlg.moc"
ThemeFile
Definition: themefile.h:42
ThemeWidget
Definition: themewidget.h:30

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.8.13
This website is maintained by Timothy Pearson.