~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to ksplash/kcm/installer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright Ravikiran Rajagopal 2003                                    *
 
3
 *   ravi@ee.eng.ohio-state.edu                                            *
 
4
 *   Copyright (c) 1998 Stefan Taferner <taferner@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
 ***************************************************************************/
 
11
 
 
12
#include <unistd.h>
 
13
#include <stdlib.h>
 
14
 
 
15
#include <QDir>
 
16
#include <QLabel>
 
17
#include <QLayout>
 
18
#include <QTextEdit>
 
19
#include <QPixmap>
 
20
#include <QFrame>
 
21
#include <QHBoxLayout>
 
22
#include <QDropEvent>
 
23
#include <QVBoxLayout>
 
24
#include <QDragEnterEvent>
 
25
#include <QMouseEvent>
 
26
#include <QScrollArea>
 
27
 
 
28
#include "installer.h"
 
29
 
 
30
#include <kdebug.h>
 
31
#include <kfiledialog.h>
 
32
#include <kglobalsettings.h>
 
33
#include <klocale.h>
 
34
#include <kmessagebox.h>
 
35
#include <kprocess.h>
 
36
#include <kpushbutton.h>
 
37
#include <kstandarddirs.h>
 
38
#include <ktar.h>
 
39
#include <kservicetypetrader.h>
 
40
#include <kio/netaccess.h>
 
41
#include <knewstuff3/downloaddialog.h>
 
42
 
 
43
ThemeListBox::ThemeListBox(QWidget *parent)
 
44
  : KListWidget(parent)
 
45
{
 
46
   setAcceptDrops(true);
 
47
}
 
48
 
 
49
void ThemeListBox::dragEnterEvent(QDragEnterEvent* event)
 
50
{
 
51
   event->setAccepted((event->source() != this) && KUrl::List::canDecode(event->mimeData()));
 
52
}
 
53
 
 
54
void ThemeListBox::dragMoveEvent(QDragMoveEvent* event)
 
55
{
 
56
   event->setAccepted((event->source() != this) && KUrl::List::canDecode(event->mimeData()));
 
57
}
 
58
 
 
59
void ThemeListBox::dropEvent(QDropEvent* event)
 
60
{
 
61
   KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
 
62
   if (!urls.isEmpty())
 
63
   {
 
64
      emit filesDropped(urls);
 
65
   }
 
66
}
 
67
 
 
68
void ThemeListBox::mousePressEvent(QMouseEvent *e)
 
69
{
 
70
   if ((e->buttons() & Qt::LeftButton) != 0)
 
71
   {
 
72
      mOldPos = e->globalPos();;
 
73
      mDragFile.clear();
 
74
      int cur = row(itemAt(e->pos()));
 
75
      if (cur >= 0)
 
76
         mDragFile = text2path[item(cur)->text()];
 
77
   }
 
78
   KListWidget::mousePressEvent(e);
 
79
}
 
80
 
 
81
void ThemeListBox::mouseMoveEvent(QMouseEvent *e)
 
82
{
 
83
   if (((e->buttons() & Qt::LeftButton) != 0) && !mDragFile.isEmpty())
 
84
   {
 
85
      int delay = KGlobalSettings::dndEventDelay();
 
86
      QPoint newPos = e->globalPos();
 
87
      if(newPos.x() > mOldPos.x()+delay || newPos.x() < mOldPos.x()-delay ||
 
88
         newPos.y() > mOldPos.y()+delay || newPos.y() < mOldPos.y()-delay)
 
89
      {
 
90
         KUrl url;
 
91
         url.setPath(mDragFile);
 
92
         KUrl::List urls;
 
93
         urls.append(url);
 
94
         QDrag *drag = new QDrag(this);
 
95
         QMimeData *mime = new QMimeData();
 
96
         urls.populateMimeData(mime);
 
97
         drag->setMimeData(mime);
 
98
         drag->start();
 
99
      }
 
100
   }
 
101
   KListWidget::mouseMoveEvent(e);
 
102
}
 
103
 
 
104
//-----------------------------------------------------------------------------
 
105
SplashInstaller::SplashInstaller (QWidget *aParent, const char *aName, bool aInit)
 
106
  : QWidget(aParent), mGui(!aInit)
 
107
{
 
108
  setObjectName(aName);
 
109
  KGlobal::dirs()->addResourceType("ksplashthemes", "data", "ksplash/Themes");
 
110
 
 
111
  if (!mGui)
 
112
    return;
 
113
 
 
114
  QHBoxLayout* hbox = new QHBoxLayout( this );
 
115
  hbox->setMargin( 0 );
 
116
 
 
117
  QVBoxLayout* leftbox = new QVBoxLayout(  );
 
118
  hbox->addLayout( leftbox );
 
119
  hbox->setStretchFactor( leftbox, 1 );
 
120
 
 
121
  mThemesList = new ThemeListBox(this);
 
122
  mThemesList->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Expanding );
 
123
  connect(mThemesList, SIGNAL(currentRowChanged(int)), SLOT(slotSetTheme(int)));
 
124
  connect(mThemesList, SIGNAL(filesDropped(const KUrl::List&)), SLOT(slotFilesDropped(const KUrl::List&)));
 
125
  leftbox->addWidget(mThemesList);
 
126
 
 
127
  mBtnNew = new KPushButton( KIcon("get-hot-new-stuff"), i18n("Get New Themes..."), this );
 
128
  mBtnNew->setToolTip(i18n("Get new themes from the Internet"));
 
129
  mBtnNew->setWhatsThis(i18n("You need to be connected to the Internet to use this action. A dialog will display a list of themes from the http://www.kde.org website. Clicking the Install button associated with a theme will install this theme locally."));
 
130
  leftbox->addWidget( mBtnNew );
 
131
  connect(mBtnNew, SIGNAL(clicked()), SLOT(slotNew()));
 
132
 
 
133
  mBtnAdd = new KPushButton( KIcon("document-import"), i18n("Install Theme File..."), this );
 
134
  mBtnAdd->setToolTip(i18n("Install a theme archive file you already have locally"));
 
135
  mBtnAdd->setWhatsThis(i18n("If you already have a theme archive locally, this button will unpack it and make it available for KDE applications"));
 
136
  leftbox->addWidget( mBtnAdd );
 
137
  connect(mBtnAdd, SIGNAL(clicked()), SLOT(slotAdd()));
 
138
 
 
139
  mBtnRemove = new KPushButton( KIcon("edit-delete"), i18n("Remove Theme"), this );
 
140
  mBtnRemove->setToolTip(i18n("Remove the selected theme from your disk"));
 
141
  mBtnRemove->setWhatsThis(i18n("This will remove the selected theme from your disk."));
 
142
  mBtnRemove->setEnabled( false );
 
143
  leftbox->addWidget( mBtnRemove );
 
144
  connect(mBtnRemove, SIGNAL(clicked()), SLOT(slotRemove()));
 
145
 
 
146
  mBtnTest = new KPushButton( KIcon("document-preview"), i18n("Test Theme"), this );
 
147
  mBtnTest->setToolTip(i18n("Test the selected theme"));
 
148
  mBtnTest->setWhatsThis(i18n("This will test the selected theme."));
 
149
  mBtnTest->setEnabled( false );
 
150
  leftbox->addWidget( mBtnTest );
 
151
  connect(mBtnTest, SIGNAL(clicked()), SLOT(slotTest()));
 
152
 
 
153
  QVBoxLayout* rightbox = new QVBoxLayout(  );
 
154
  hbox->addLayout( rightbox );
 
155
  hbox->setStretchFactor( rightbox, 3 );
 
156
 
 
157
  QScrollArea* scrollarea = new QScrollArea(this);
 
158
  scrollarea->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
 
159
  mPreview = new QLabel(this);
 
160
  scrollarea->setWidget(mPreview);
 
161
  mPreview->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
 
162
  mPreview->setMinimumSize(QSize(320,240));
 
163
  mPreview->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
 
164
  rightbox->addWidget(scrollarea);
 
165
  rightbox->setStretchFactor( scrollarea, 3 );
 
166
 
 
167
  mText = new QTextEdit(this);
 
168
  mText->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
 
169
  mText->setMinimumSize(mText->sizeHint().width(), 7 * mText->fontMetrics().height());
 
170
  mText->setReadOnly(true);
 
171
  rightbox->addWidget(mText);
 
172
  rightbox->setStretchFactor( mText, 1 );
 
173
 
 
174
 
 
175
  readThemesList();
 
176
  load();
 
177
}
 
178
 
 
179
 
 
180
//-----------------------------------------------------------------------------
 
181
SplashInstaller::~SplashInstaller()
 
182
{
 
183
}
 
184
 
 
185
int SplashInstaller::addTheme(const QString &path, const QString &name)
 
186
{
 
187
  //kDebug() << "SplashInstaller::addTheme: " << path << " " << name;
 
188
  QString tmp(i18n( name.toUtf8() ));
 
189
  int i = mThemesList->count();
 
190
  while((i > 0) && (mThemesList->item(i-1)->text() > tmp))
 
191
    i--;
 
192
  if ((i > 0) && (mThemesList->item(i-1)->text() == tmp))
 
193
    return i-1;
 
194
  mThemesList->insertItem(i , tmp);
 
195
  mThemesList->text2path.insert( tmp, path+'/'+name );
 
196
  return i;
 
197
}
 
198
 
 
199
// Copy theme package into themes directory
 
200
void SplashInstaller::addNewTheme(const KUrl &srcURL)
 
201
{
 
202
  const QString dir = KGlobal::dirs()->saveLocation("ksplashthemes");
 
203
 
 
204
  KUrl url;
 
205
  QStringList themeNames;
 
206
  QString filename = srcURL.fileName();
 
207
  int i = filename.lastIndexOf('.');
 
208
  // Convert extension to lower case.
 
209
  if (i >= 0)
 
210
     filename = filename.left(i)+filename.mid(i).toLower();
 
211
  url.setPath(KStandardDirs::locateLocal("tmp",filename));
 
212
 
 
213
  // Remove file from temporary directory if it aleady exists - usually the result of a failed install.
 
214
  if ( KIO::NetAccess::exists( url, KIO::NetAccess::SourceSide, 0 ) )
 
215
    KIO::NetAccess::del( url, 0 );
 
216
 
 
217
  if (srcURL.fileName().toLower() == "theme.rc" ) // uncompressed theme selected
 
218
  {
 
219
    QString themeName;
 
220
    // Get the name of the Theme from the theme.rc file
 
221
    KConfig _cnf(srcURL.path());
 
222
    KConfigGroup cnf(&_cnf, QString("KSplash Theme: %1").arg(themeName) );
 
223
 
 
224
    // copy directory of theme.rc to ThemesDir
 
225
    KIO::NetAccess::dircopy(KUrl(srcURL.directory()), KUrl(dir + themeName));
 
226
 
 
227
    themeNames << themeName;
 
228
  }
 
229
  else
 
230
  {
 
231
    bool rc = KIO::NetAccess::file_copy(srcURL, url, 0);
 
232
    if (!rc)
 
233
    {
 
234
      kWarning() << "Failed to copy theme " << srcURL.fileName()
 
235
          << " into temporary directory " << url.path() << endl;
 
236
      return;
 
237
    }
 
238
 
 
239
    // Extract into theme directory: we may have multiple themes in one tarball!
 
240
    KTar tarFile(url.path());
 
241
    if (!tarFile.open(QIODevice::ReadOnly))
 
242
    {
 
243
      kWarning() << "Unable to open archive: " << url.path();
 
244
      KIO::NetAccess::del( url, 0 );
 
245
      return;
 
246
    }
 
247
    KArchiveDirectory const *ad = tarFile.directory();
 
248
 
 
249
    // Find first directory entry.
 
250
    const QStringList entries = ad->entries();
 
251
    foreach(const QString& s, entries)
 
252
    {
 
253
      if( ad->entry(s)->isDirectory() )
 
254
      {
 
255
        // each directory may contain one theme
 
256
        themeNames << s;
 
257
      }
 
258
    }
 
259
    if (themeNames.count() < 1)
 
260
    {
 
261
      kWarning() << "No directory in archive: " << url.path();
 
262
      tarFile.close();
 
263
      KIO::NetAccess::del( url, 0 );
 
264
      return;
 
265
    }
 
266
 
 
267
    // copy the theme into the "ksplashthemes" directory
 
268
    ad->copyTo(dir);
 
269
 
 
270
    tarFile.close();
 
271
    KIO::NetAccess::del( url, 0 );
 
272
 
 
273
  }
 
274
 
 
275
  readThemesList();
 
276
  mThemesList->setCurrentRow(findTheme(themeNames.first()));
 
277
  if (mThemesList->currentItem())
 
278
  {
 
279
    mThemesList->currentItem()->setSelected(true);
 
280
  }
 
281
}
 
282
 
 
283
//-----------------------------------------------------------------------------
 
284
void SplashInstaller::readThemesList()
 
285
{
 
286
  mThemesList->clear();
 
287
 
 
288
  // Read local themes
 
289
  const QStringList entryList = KGlobal::dirs()->resourceDirs("ksplashthemes");
 
290
  //kDebug() << "readThemesList: " << entryList;
 
291
  QDir dir;
 
292
  QStringList subdirs;
 
293
  QStringList::ConstIterator name;
 
294
  for(name = entryList.constBegin(); name != entryList.constEnd(); name++)
 
295
  {
 
296
    dir = *name;
 
297
    if (!dir.exists())
 
298
      continue;
 
299
    subdirs = dir.entryList( QDir::Dirs );
 
300
    // kDebug() << "readThemesList: " << subdirs;
 
301
    // TODO: Make sure it contains a *.rc file.
 
302
    for (QStringList::const_iterator l = subdirs.constBegin(); l != subdirs.constEnd(); l++ )
 
303
      if ( !(*l).startsWith(QString(".")) )
 
304
      {
 
305
        mThemesList->blockSignals( true ); // Don't activate any theme until all themes are loaded.
 
306
        addTheme(dir.path(),*l);
 
307
        mThemesList->blockSignals( false );
 
308
      }
 
309
  }
 
310
}
 
311
 
 
312
//-----------------------------------------------------------------------------
 
313
void SplashInstaller::defaults()
 
314
{
 
315
  mThemesList->setCurrentRow(findTheme("Default"));
 
316
  emit changed( true );
 
317
}
 
318
 
 
319
void SplashInstaller::load()
 
320
{
 
321
  KConfig _cnf( "ksplashrc" );
 
322
  KConfigGroup cnf(&_cnf, "KSplash");
 
323
  QString curTheme = cnf.readEntry("Theme","Default");
 
324
  mThemesList->setCurrentRow(findTheme(curTheme));
 
325
  emit changed( false );
 
326
}
 
327
 
 
328
//-----------------------------------------------------------------------------
 
329
void SplashInstaller::save()
 
330
{
 
331
  KConfig _cnf( "ksplashrc" );
 
332
  KConfigGroup cnf(&_cnf, "KSplash");
 
333
  int cur = mThemesList->currentRow();
 
334
  if (cur < 0)
 
335
    return;
 
336
  QString path = mThemesList->item(cur)->text();
 
337
  if ( mThemesList->text2path.contains( path ) )
 
338
    path = mThemesList->text2path[path];
 
339
  cur = path.lastIndexOf('/');
 
340
  cnf.writeEntry("Theme", path.mid(cur+1) );
 
341
  // save also the engine, so that it's known at KDE startup which splash implementation to use
 
342
  cnf.writeEntry("Engine", mEngineOfSelected );
 
343
  cnf.sync();
 
344
  emit changed( false );
 
345
}
 
346
 
 
347
//-----------------------------------------------------------------------------
 
348
void SplashInstaller::slotRemove()
 
349
{
 
350
  int cur = mThemesList->currentRow();
 
351
  if (cur < 0)
 
352
    return;
 
353
 
 
354
  bool rc = false;
 
355
  const QString themeName = mThemesList->item(cur)->text();
 
356
  const QString themeDir = mThemesList->text2path[themeName];
 
357
  if (!themeDir.isEmpty())
 
358
  {
 
359
     KUrl url;
 
360
     url.setPath(themeDir);
 
361
     if (KMessageBox::warningContinueCancel(this,i18n("Delete folder %1 and its contents?", themeDir),"",KGuiItem(i18n("&Delete"),"edit-delete"))==KMessageBox::Continue)
 
362
       rc = KIO::NetAccess::del(url,this);
 
363
     else
 
364
       return;
 
365
  }
 
366
  if (!rc)
 
367
  {
 
368
    KMessageBox::sorry(this, i18n("Failed to remove theme '%1'", themeName));
 
369
    return;
 
370
  }
 
371
  //mThemesList->removeItem(cur);
 
372
  readThemesList();
 
373
  cur = (cur >= mThemesList->count())?mThemesList->count()-1:cur;
 
374
  mThemesList->setCurrentRow(cur);
 
375
}
 
376
 
 
377
 
 
378
//-----------------------------------------------------------------------------
 
379
void SplashInstaller::slotSetTheme(int id)
 
380
{
 
381
  bool enabled;
 
382
  QString path = QString();
 
383
  QString infoTxt;
 
384
 
 
385
  if (id < 0)
 
386
  {
 
387
    mPreview->setText(QString());
 
388
    mText->setText(QString());
 
389
    enabled = false;
 
390
  }
 
391
  else
 
392
  {
 
393
    QString error = i18n("(Could not load theme)");
 
394
    path = mThemesList->item(id)->text();
 
395
    if ( mThemesList->text2path.contains( path ) )
 
396
        path = mThemesList->text2path[path];
 
397
    enabled = false;
 
398
    KUrl url;
 
399
    QString themeName;
 
400
    if (!path.isEmpty())
 
401
    {
 
402
      // Make sure the correct plugin is installed.
 
403
      int i = path.lastIndexOf('/');
 
404
      if (i >= 0)
 
405
        themeName = path.mid(i+1);
 
406
      url.setPath( path + "/Theme.rc" );
 
407
      if (!KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, 0))
 
408
      {
 
409
        url.setPath( path + "/Theme.RC" );
 
410
        if (!KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, 0))
 
411
        {
 
412
          url.setPath( path + "/theme.rc" );
 
413
          if (!KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, 0))
 
414
            url.setPath( path + '/' + themeName + ".rc" );
 
415
        }
 
416
      }
 
417
      if (KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, 0))
 
418
      {
 
419
        KConfig _cnf(url.path());
 
420
        KConfigGroup cnf(&_cnf, QString("KSplash Theme: %1").arg(themeName) );
 
421
 
 
422
        // Get theme information.
 
423
        infoTxt = "<qt>";
 
424
        if ( cnf.hasKey( "Name" ) )
 
425
          infoTxt += i18n( "<b>Name:</b> %1", cnf.readEntry( "Name", i18nc( "Unknown name", "Unknown" ) ) ) + "<br />";
 
426
        if ( cnf.hasKey( "Description" ) )
 
427
          infoTxt += i18n( "<b>Description:</b> %1", cnf.readEntry( "Description", i18nc( "Unknown description", "Unknown" ) ) ) + "<br />";
 
428
        if ( cnf.hasKey( "Version" ) )
 
429
          infoTxt += i18n( "<b>Version:</b> %1", cnf.readEntry( "Version", i18nc( "Unknown version", "Unknown" ) ) ) + "<br />";
 
430
        if ( cnf.hasKey( "Author" ) )
 
431
          infoTxt += i18n( "<b>Author:</b> %1", cnf.readEntry( "Author", i18nc( "Unknown author", "Unknown" ) ) ) + "<br />";
 
432
        if ( cnf.hasKey( "Homepage" ) )
 
433
          infoTxt += i18n( "<b>Homepage:</b> %1", cnf.readEntry( "Homepage", i18nc( "Unknown homepage", "Unknown" ) ) ) + "<br />";
 
434
        infoTxt += "</qt>";
 
435
 
 
436
        QString pluginName( cnf.readEntry( "Engine", "KSplashX" ).trimmed() );
 
437
        if( pluginName == "Simple" || pluginName == "None" || pluginName == "KSplashX" )
 
438
            enabled = true; // these are not plugins
 
439
        else if ((KServiceTypeTrader::self()->query("KSplash/Plugin", QString("[X-KSplash-PluginName] == '%1'").arg(pluginName))).isEmpty())
 
440
        {
 
441
          enabled = false;
 
442
          error = i18n("This theme requires the plugin %1 which is not installed.", pluginName);
 
443
        }
 
444
        else
 
445
          enabled = true; // Hooray, there is at least one plugin which can handle this theme.
 
446
        mEngineOfSelected = pluginName;
 
447
      }
 
448
      else
 
449
      {
 
450
        error = i18n("Could not load theme configuration file.");
 
451
      }
 
452
    }
 
453
    mBtnTest->setEnabled(enabled && themeName != "None" );
 
454
    mText->setHtml(infoTxt);
 
455
    if (!enabled)
 
456
    {
 
457
      url.setPath( path + '/' + "Preview.png" );
 
458
      if (KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, 0))
 
459
        mPreview->setPixmap(QPixmap(url.path()));
 
460
      else
 
461
        mPreview->setText(i18n("(Could not load theme)"));
 
462
      KMessageBox::sorry(this, error);
 
463
    }
 
464
    else
 
465
    {
 
466
      url.setPath( path + '/' + "Preview.png" );
 
467
      if (KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, 0))
 
468
        mPreview->setPixmap(QPixmap(url.path()));
 
469
      else
 
470
        mPreview->setText(i18n("No preview available."));
 
471
      emit changed(true);
 
472
    }
 
473
  }
 
474
  mBtnRemove->setEnabled( !path.isEmpty() && QFileInfo(path).isWritable());
 
475
}
 
476
 
 
477
//-----------------------------------------------------------------------------
 
478
void SplashInstaller::slotNew()
 
479
{
 
480
  KNS3::DownloadDialog dialog("ksplash.knsrc", this);
 
481
  dialog.exec();
 
482
  if (!dialog.changedEntries().isEmpty())
 
483
    readThemesList();
 
484
}
 
485
 
 
486
//-----------------------------------------------------------------------------
 
487
void SplashInstaller::slotAdd()
 
488
{
 
489
  static QString path;
 
490
  if (path.isEmpty()) path = QDir::homePath();
 
491
 
 
492
  KFileDialog dlg(path, "*.tgz *.tar.gz *.tar.bz2 theme.rc|" + i18n( "KSplash Theme Files" ), this);
 
493
  dlg.setCaption(i18n("Add Theme"));
 
494
  if (!dlg.exec())
 
495
    return;
 
496
 
 
497
  path = dlg.baseUrl().url();
 
498
  addNewTheme(dlg.selectedUrl());
 
499
}
 
500
 
 
501
//-----------------------------------------------------------------------------
 
502
void SplashInstaller::slotFilesDropped(const KUrl::List &urls)
 
503
{
 
504
  for(KUrl::List::ConstIterator it = urls.constBegin();
 
505
      it != urls.end();
 
506
      ++it)
 
507
      addNewTheme(*it);
 
508
}
 
509
 
 
510
//-----------------------------------------------------------------------------
 
511
int SplashInstaller::findTheme( const QString &theme )
 
512
{
 
513
  // theme is untranslated, but the listbox contains translated items
 
514
  QString tmp(i18n( theme.toUtf8() ));
 
515
  int id = mThemesList->count()-1;
 
516
 
 
517
  while (id >= 0)
 
518
  {
 
519
    if (mThemesList->item(id)->text() == tmp)
 
520
      return id;
 
521
    id--;
 
522
  }
 
523
 
 
524
  return 0;
 
525
}
 
526
 
 
527
//-----------------------------------------------------------------------------
 
528
void SplashInstaller::slotTest()
 
529
{
 
530
  int i = mThemesList->currentRow();
 
531
  if (i < 0)
 
532
    return;
 
533
  QString themeName = mThemesList->text2path[mThemesList->item(i)->text()];
 
534
  int r = themeName.lastIndexOf('/');
 
535
  if (r >= 0)
 
536
    themeName = themeName.mid(r+1);
 
537
 
 
538
  // special handling for none and simple splashscreens
 
539
  if( mEngineOfSelected == "None" )
 
540
    return;
 
541
  else if( mEngineOfSelected == "Simple" )
 
542
  {
 
543
    KProcess proc;
 
544
    proc << "ksplashsimple" << themeName << "--test";
 
545
    if (proc.execute())
 
546
      KMessageBox::error(this,i18n("Failed to successfully test the splash screen."));
 
547
    return;
 
548
  }
 
549
  else if( mEngineOfSelected == "KSplashX" )
 
550
  {
 
551
    KProcess proc;
 
552
    proc << "ksplashx" << themeName << "--test";
 
553
    if (proc.execute())
 
554
      KMessageBox::error(this,i18n("Failed to successfully test the splash screen."));
 
555
    return;
 
556
  }
 
557
  else // KSplashML engines
 
558
  {
 
559
    KProcess proc;
 
560
    proc << "ksplash" << "--test" << "--theme" << themeName;
 
561
    if (proc.execute())
 
562
      KMessageBox::error(this,i18n("Failed to successfully test the splash screen."));
 
563
  }
 
564
}
 
565
 
 
566
//-----------------------------------------------------------------------------
 
567
#include "installer.moc"