summaryrefslogtreecommitdiffstats
path: root/noatun/modules/kjofol-skin/kjprefs.cpp
blob: 9e3727b653fd473362a8af5a170bd6d8a37dc48b (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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
/***************************************************************************
	kjprefs.cpp  -  Preferences-Dialog for KJ�ol-Skinloader
	--------------------------------------------------------
	Maintainer: Stefan Gehn <sgehn@gmx.net>

 ***************************************************************************/

// local includes
#include "kjprefs.h"
#include "kjprefs.moc"
#include "kjloader.h"
#include "kjwidget.h"
#include "kjvis.h"
#include "parser.h"

// system includes
#include <tqcheckbox.h>
#include <tqcombobox.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqpushbutton.h>
#include <tqradiobutton.h>
#include <tqslider.h>
#include <tqpixmap.h>
#include <tqtabwidget.h>
#include <tqtextbrowser.h>
#include <tqfileinfo.h>
#include <tqstringlist.h>
#include <tqregexp.h>

#include <knuminput.h>
#include <kconfig.h>
#include <kdebug.h>
#include <kglobal.h>
#include <kio/job.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kmimemagic.h>
#include <knotifyclient.h>
#include <kprocess.h>
#include <kstandarddirs.h>
#include <kglobalsettings.h>
#include <kfontcombo.h>
#include <kcolorcombo.h>

static TQString expand(TQString s);

KJPrefs::KJPrefs(TQObject* tqparent)
	: CModule(i18n("K-Jöfol Skins"), i18n("Skin Selection For the K-Jöfol Plugin"), "style", tqparent)
{
	cfg = KGlobal::config();

	TQVBoxLayout *vbox = new TQVBoxLayout(this);
	vbox->setAutoAdd(true);
	vbox->setSpacing( 0 );
	vbox->setMargin( 0 );

	mTabWidget = new TQTabWidget( this, "mTabWidget" );

	mSkinselectorWidget = new KJSkinselector ( mTabWidget, "mSkinselectorWidget" );
	mGuiSettingsWidget = new KJGuiSettings ( mTabWidget, "mGuiSettingsWidget" );

	mTabWidget->insertTab( mSkinselectorWidget, i18n("&Skin Selector") );
	mTabWidget->insertTab( mGuiSettingsWidget, i18n("O&ther Settings") );

	connect ( mSkinselectorWidget->mSkins, TQT_SIGNAL(activated(const TQString&)), TQT_SLOT(showPreview(const TQString&)) );
	connect ( mSkinselectorWidget->installButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(installNewSkin()) );
	connect ( mSkinselectorWidget->mRemoveButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(removeSelectedSkin()) );

	reopen(); // fill the skinlist and draw a preview
}


void KJPrefs::reopen() // reload config and set stuff in dialog
{
//	kdDebug(66666) << "[KJPrefs] reopen()" << endl;

	cfg->setGroup("KJofol-Skins");

//	mGuiSettingsWidget->timeCountdown->setChecked( cfg->readBoolEntry("TimeCountMode", false) );
	mGuiSettingsWidget->displayTooltips->setChecked( cfg->readBoolEntry("DisplayTooltips", true) );
	mGuiSettingsWidget->displaySplash->setChecked( cfg->readBoolEntry("DisplaySplashScreen", true) );

	mGuiSettingsWidget->minPitch->setValue( cfg->readNumEntry("minimumPitch", 50) );
	mGuiSettingsWidget->maxPitch->setValue( cfg->readNumEntry("maximumPitch", 200) );
	mGuiSettingsWidget->visTimerValue->setValue( cfg->readNumEntry("VisualizationSpeed", 30) );

	mGuiSettingsWidget->useSysFont->setChecked( cfg->readBoolEntry("Use SysFont", false) );
	mGuiSettingsWidget->cmbSysFont->setCurrentFont(
		cfg->readEntry("SysFont Family", KGlobalSettings::generalFont().family()) );
	TQColor tmpColor = TQColor(255,255,255);
	mGuiSettingsWidget->cmbSysFontColor->setColor(
		cfg->readColorEntry("SysFont Color", &tmpColor));

	// TODO somehow honor both config-entries, I want a custom mode
	switch ( cfg->readNumEntry("TitleScrollSpeed", 400 ) )
	{
		case 800:
			mGuiSettingsWidget->titleScrollSpeed->setValue(1);
			break;
		case 400:
			mGuiSettingsWidget->titleScrollSpeed->setValue(2);
			break;
		case 200:
			mGuiSettingsWidget->titleScrollSpeed->setValue(3);
			break;
	}

	switch ( cfg->readNumEntry("AnalyzerType", KJVisScope::FFT ) )
	{
		case KJVisScope::Null:
			mGuiSettingsWidget->visNone->setChecked(true);
			mGuiSettingsWidget->visScope->setChecked(false);
			mGuiSettingsWidget->visAnalyzer->setChecked(false);
			break;

		case KJVisScope::FFT:
			mGuiSettingsWidget->visNone->setChecked(false);
			mGuiSettingsWidget->visScope->setChecked(false);
			mGuiSettingsWidget->visAnalyzer->setChecked(true);
			break;

		case KJVisScope::Mono:
			mGuiSettingsWidget->visNone->setChecked(false);
			mGuiSettingsWidget->visScope->setChecked(true);
			mGuiSettingsWidget->visAnalyzer->setChecked(false);
			break;
	}

	TQStringList skins;
	TQStringList skinLocations = KGlobal::dirs()->findDirs("data", "noatun/skins/kjofol");
	// iterate through all paths where Noatun is searching for kjofol-skins
	for (uint i = 0; i < skinLocations.count(); ++i )
	{
		TQStringList skinDirs = TQDir(skinLocations[i]).entryList();
		// iterate trough all dirs (normally, users can fsck every dir-struct *g*) containing a skin
		for (uint k = 2; k < skinDirs.count(); ++k )
		{
			TQDir skinDirCnt = TQDir ( skinLocations[i]+skinDirs[k], "*.rc", TQDir::Name|TQDir::IgnoreCase, TQDir::Files );
			// make a list of all .rc-files in a skindir
			TQStringList rcFiles = skinDirCnt.entryList();
			// iterate trough all those rc.-files in a skindir
			for (uint j = 0; j < rcFiles.count(); j++ )
			{
//				kdDebug(66666) << "found: " <<  rcFiles[j].latin1() << endl;
				skins += ( rcFiles[j] );
			}
		}
	}

	skins.sort();

	TQString loaded = cfg->readEntry("SkinResource", locate("data", "noatun/skins/kjofol/kjofol/kjofol.rc") );
	loaded = loaded.mid(loaded.findRev("/")+1);  // remove path
	loaded = loaded.left( loaded.length() - 3 ); // remove ".rc"

	mSkinselectorWidget->mSkins->clear();

	int index = 0;
	for (TQStringList::Iterator i=skins.begin(); i!=skins.end(); ++i)
	{
		*i = (*i).left( (*i).length() - 3 );
		mSkinselectorWidget->mSkins->insertItem(*i);
		if ( (*i) == loaded )
			index = mSkinselectorWidget->mSkins->count()-1; // save index no. to set active item later on
	}

	mSkinselectorWidget->mSkins->setCurrentItem(index);

	showPreview( mSkinselectorWidget->mSkins->currentText() );
}


void KJPrefs::save()
{
// 	kdDebug(66666) << k_funcinfo << "called." << endl;
	TQString skin=::expand ( mSkinselectorWidget->mSkins->currentText() );

	// first load skin and then save config to prevent
	// reloading a broken skin after a crash
	KJLoader *l=KJLoader::kjofol;
	if (l)
		l->loadSkin(skin);

	cfg->setGroup("KJofol-Skins");

	cfg->writeEntry("SkinResource", skin);
//	cfg->writeEntry("TimeCountMode", timeCountMode() );
	cfg->writeEntry("DisplayTooltips", displayTooltips() );
	cfg->writeEntry("DisplaySplashScreen", displaySplash() );

	cfg->writeEntry("TitleScrollSpeed", titleMovingUpdates() );
	cfg->writeEntry("TitleScrollAmount", titleMovingDistance() );
	cfg->writeEntry("AnalyzerType", (int)visType() );
	cfg->writeEntry("minimumPitch", minimumPitch() );
	cfg->writeEntry("maximumPitch", maximumPitch() );
	cfg->writeEntry("VisualizationSpeed", visTimerValue() );

	cfg->writeEntry("Use SysFont", mGuiSettingsWidget->useSysFont->isChecked());
	cfg->writeEntry("SysFont Family", mGuiSettingsWidget->cmbSysFont->currentFont());
// 	kdDebug(66666) << k_funcinfo << "currentfont=" << mGuiSettingsWidget->cmbSysFont->currentFont() << endl;
	cfg->writeEntry("SysFont Color", mGuiSettingsWidget->cmbSysFontColor->color());

	cfg->sync();

	emit configChanged();
}

TQString KJPrefs::skin( void ) const
{
	// return full path to currently loaded skin
	return ::expand( mSkinselectorWidget->mSkins->currentText() );
}

int KJPrefs::minimumPitch( void ) const
{
	return mGuiSettingsWidget->minPitch->value();
}

int KJPrefs::maximumPitch( void ) const
{
	return mGuiSettingsWidget->maxPitch->value();
}

int KJPrefs::visTimerValue ( void ) const
{
	return mGuiSettingsWidget->visTimerValue->value();
}

int KJPrefs::titleMovingUpdates ( void ) const
{
	switch ( mGuiSettingsWidget->titleScrollSpeed->value() )
	{
		case 1:
			return 800;
		case 2:
			return 400;
		case 3:
			return 200;
		default:
			return 400; // emergency exit :)
	}
}

float KJPrefs::titleMovingDistance ( void ) const
{
	switch ( mGuiSettingsWidget->titleScrollSpeed->value() )
	{
		case 1:
			return 0.2f;
		case 2:
			return 0.5f;
		case 3:
			return 1.0f;
		default:
			return 0.5f; // emergency exit :)
	}
}

int KJPrefs::visType ( void ) const
{
	if ( mGuiSettingsWidget->visNone->isChecked() ) // No Vis
		return KJVisScope::Null;
	else if ( mGuiSettingsWidget->visScope->isChecked() ) // MonoScope
		return KJVisScope::Mono;
	else if ( mGuiSettingsWidget->visAnalyzer->isChecked() ) // FFT Analyzer
		return KJVisScope::FFT;
	else
		return KJVisScope::StereoFFT; //Null; // emergency exit :)
}

void KJPrefs::setVisType ( int vis )
{
	switch ( vis )
	{
		case KJVisScope::Null:
			mGuiSettingsWidget->visNone->setChecked(true);
			mGuiSettingsWidget->visScope->setChecked(false);
			mGuiSettingsWidget->visAnalyzer->setChecked(false);
			break;

		case KJVisScope::FFT:
			mGuiSettingsWidget->visNone->setChecked(false);
			mGuiSettingsWidget->visScope->setChecked(false);
			mGuiSettingsWidget->visAnalyzer->setChecked(true);
			break;

		case KJVisScope::StereoFFT:
			mGuiSettingsWidget->visNone->setChecked(false);
			mGuiSettingsWidget->visScope->setChecked(false);
			mGuiSettingsWidget->visAnalyzer->setChecked(false);
			break;

		case KJVisScope::Mono:
			mGuiSettingsWidget->visNone->setChecked(false);
			mGuiSettingsWidget->visScope->setChecked(true);
			mGuiSettingsWidget->visAnalyzer->setChecked(false);
			break;
	}
	save(); // not sure if that's a good idea or doing saving by hand in here
}


bool KJPrefs::useSysFont( void ) const
{
	return mGuiSettingsWidget->useSysFont->isChecked();
}

void KJPrefs::setUseSysFont( bool mode )
{
	mGuiSettingsWidget->useSysFont->setChecked( mode );
	save(); // not sure if that's a good idea or doing saving by hand in here
}

TQFont KJPrefs::sysFont(void) const
{
	TQString family = mGuiSettingsWidget->cmbSysFont->currentFont();
//	kdDebug(66666) << k_funcinfo << "family=" << family << endl;
	return TQFont( family );
}

void KJPrefs::setSysFont(TQFont &fnt)
{
	mGuiSettingsWidget->cmbSysFont->setCurrentFont( fnt.family() );
}

TQColor KJPrefs::sysFontColor(void) const
{
	return mGuiSettingsWidget->cmbSysFontColor->color();
}

void KJPrefs::sysFontColor(TQColor &c)
{
	mGuiSettingsWidget->cmbSysFontColor->setColor( c );
}

bool KJPrefs::displayTooltips( void ) const
{
	return mGuiSettingsWidget->displayTooltips->isChecked();
}

bool KJPrefs::displaySplash( void ) const
{
	return mGuiSettingsWidget->displaySplash->isChecked();
}


void KJPrefs::showPreview(const TQString &_skin)
{
	Parser p;
	p.open( ::expand(_skin) );

	TQImage image = p.image(p["BackgroundImage"][1]);
	if (!image.isNull())
	{
		mPixmap.convertFromImage(image);
		mPixmap.setMask( KJWidget::getMask(image) );
	}
	else
		mPixmap=TQPixmap();

	mSkinselectorWidget->mPreview->setPixmap(mPixmap);
	mSkinselectorWidget->mAboutText->setText(p.about());
	mSkinselectorWidget->updateGeometry();
}


/* =================================================================================== */


void KJPrefs::installNewSkin( void )
{
	bool skinInstalled = false; // flag showing wether a skindir got installed
	KURL src, dst; // sourcedir and destinationdir for skin-installation

	KURL srcFile ( mSkinselectorWidget->mSkinRequester->url() );

	//kdDebug(66666) << "file to work on: " << srcFile.path().latin1() << endl;

	if ( !srcFile.isValid() || srcFile.isEmpty() ) // stop working on broken URLs
	{
		kdDebug(66666) << "srcFile is malformed or empty !!!" << endl;
		return;
	}

	if ( !srcFile.isLocalFile() )  // TODO: Download file into tmp dir + unpack afterwards
	{
		KMessageBox::sorry ( this, i18n("Non-Local files are not supported yet") );
		return;
	}

	// Determine file-format trough mimetype (no stupid .ext test)
	KMimeMagicResult * result = KMimeMagic::self()->findFileType( srcFile.path() );

	if ( !result->isValid() )
	{
		kdDebug(66666) << "Could not determine filetype of srcFile !!!" << endl;
		return;
	}

	if ( result->mimeType() != "application/x-zip" )
	{
		KMessageBox::error ( this, i18n("The selected file does not appear to be a valid zip-archive") );
		return;
	}

	// create a dir with name of the skinarchive
	// path to unpack to: pathToTmp/filename.ext/
	TQString tmpUnpackPath = locateLocal("tmp", srcFile.fileName()+"/" );
	kdDebug(66666) << "tmpUnpackPath: " << tmpUnpackPath.latin1() << endl;

	// Our extract-process, TODO: wanna have kio_(un)zip instead :)
	KShellProcess proc;

	// "unzip -d whereToUnpack whatToUnpack"
	proc << "unzip -d " << proc.quote(tmpUnpackPath) << " " << proc.quote(srcFile.path());
	kdDebug(66666) << "unzip -d " << tmpUnpackPath.latin1() << " " << srcFile.path().latin1() << endl;

	proc.start( KProcess::Block, KProcess::NoCommunication );

	// "unzip" spits out errorcodes > 0 only, 0 on success
	if ( proc.exitStatus() != 0 )
	{
		KMessageBox::error ( this, i18n("Extracting skin-archive failed") );
		// FIXME: Do I have to wait for the job to finish?
		// I'd say no because I don't care about the temp-dir
		// anyway after leaving this method :)
		KIO::del( tmpUnpackPath );
		return;
	}

	TQDir tmpCnt = TQDir ( tmpUnpackPath );
	tmpCnt.setFilter ( TQDir::Dirs );

	TQStringList dirList = tmpCnt.entryList();
	// Iterate trough all subdirs of tmpUnpackPath (including "."!)
	for ( unsigned int i = 0; i < dirList.count(); i++ )
	{
		// FIXME: is the following portable?
		if ( dirList[i] == ".." )
			continue;

		TQDir tmpSubCnt = TQDir( tmpUnpackPath + dirList[i], "*.rc;*.RC;*.Rc;*.rC", TQDir::Name|TQDir::IgnoreCase, TQDir::Files );
		kdDebug(66666) << "Searching for *.rc in " << TQString(tmpUnpackPath+dirList[i]).latin1() << endl;

		// oh, no .rc file in current dir, let's go to next dir in list
		if ( tmpSubCnt.count() == 0 )
			continue;

		src = KURL::encode_string(tmpUnpackPath+dirList[i]);
		dst = KURL::encode_string(locateLocal("data","noatun/skins/kjofol/")); // destination to copy skindir into

		if ( dirList[i] == "." ) // zip did not contain a subdir, we have to create one
		{
			// skindir is named like the archive without extension (FIXME: extension is not stripped from name)

			int dotPos = srcFile.fileName().findRev('.');
			if ( dotPos > 0 ) // found a dot -> (hopefully) strip the extension
			{
				dst.addPath( srcFile.fileName().left(dotPos) );
			}
			else // we don't seem to have any extension, just append the archivename
			{
				dst.addPath( srcFile.fileName() );
			}

			kdDebug(66666) << "want to create: " << dst.path().latin1() << endl;

			if ( !dst.isValid() )
			{
				KMessageBox::error ( this,
					i18n("Installing new skin failed: Destination path is invalid.\n"
						"Please report a bug to the K-Jöfol maintainer") );
				KIO::del( tmpUnpackPath );
				return;
			}
			KIO::mkdir( dst );
		}

		if ( !src.isValid() || !dst.isValid() )
		{
			KMessageBox::error ( this,
				i18n("Installing new skin failed: Either source or destination path is invalid.\n"
					"Please report a bug to the K-Jöfol maintainer") );
		}
		else
		{
			kdDebug(66666) << "src: " << src.path().latin1() << endl;
			kdDebug(66666) << "dst: " << dst.path().latin1() << endl;
			KIO::Job *job = KIO::copy(src,dst);
			connect ( job, TQT_SIGNAL(result(KIO::Job*)), this, TQT_SLOT(slotResult(KIO::Job*)) );
			skinInstalled = true;
		}
	} // END iterate trough dirList

	if ( !skinInstalled )
	{
		KMessageBox::sorry ( this, i18n("No new skin has been installed.\nMake sure the archive contains a valid K-Jöfol skin") );
	}
	else
	{
		KMessageBox::information ( this, i18n("The new skin has been successfully installed") );
	}

	KIO::del( tmpUnpackPath );
}


void KJPrefs::removeSelectedSkin( void )
{
	TQString question = i18n("Are you sure you want to remove %1?\n"
		"This will delete the files installed by this skin ").
		arg ( mSkinselectorWidget->mSkins->currentText() );

	cfg->setGroup("KJofol-Skins");
	TQString loadedSkin = cfg->readEntry("SkinResource", "kjofol");
//	kdDebug(66666) << "loaded Skin Name: " << TQFileInfo(loadedSkin).baseName().latin1() << endl;

        int r = KMessageBox::warningContinueCancel ( this, question, i18n("Confirmation"), KStdGuiItem::del() );
	if ( r != KMessageBox::Continue )
		return;

	bool deletingCurrentSkin = ( mSkinselectorWidget->mSkins->currentText() == TQFileInfo(loadedSkin).baseName() );

	// Now find the dir to delete !!!

	TQString dirToDelete = TQString ("");
	TQStringList skinLocations = KGlobal::dirs()->findDirs("data", "noatun/skins/kjofol");

	// iterate through all paths where Noatun is searching for kjofol-skins
	for (uint i = 0; i < skinLocations.count(); ++i )
	{
		TQStringList skinDirs = TQDir(skinLocations[i]).entryList();

		// iterate trough all dirs containing a skin
		for (uint k = 0; k < skinDirs.count(); ++k )
		{
			TQDir skinDirCnt = TQDir ( skinLocations[i]+skinDirs[k], "*.rc", TQDir::Name|TQDir::IgnoreCase, TQDir::Files );
			 // make a list of all .rc-files in a skindir
			TQStringList rcFiles = skinDirCnt.entryList();

			// iterate trough all those rc.-files in a skindir
			for (uint j = 0; j < rcFiles.count(); j++ )
			{
				if ( rcFiles[j].left(rcFiles[j].length()-3) == mSkinselectorWidget->mSkins->currentText() ) // found skinname.rc :)
				{
					dirToDelete = TQString ( skinLocations[i]+skinDirs[k] );
					kdDebug(66666) << "FOUND SKIN @ " << dirToDelete.latin1() << endl;
				}
			}
		}
	}

	if ( dirToDelete.length() != 0 )
	{
		kdDebug(66666) << "Deleting Skindir: " << dirToDelete.latin1() << endl;
		KIO::Job *job = KIO::del( dirToDelete, false, true );
		connect ( job, TQT_SIGNAL(result(KIO::Job*)), this, TQT_SLOT(slotResult(KIO::Job*)) );
	}

	int item = -1;
	// Fallback to kjofol-skin (the default one) if we've deleted the current skin
	if ( deletingCurrentSkin )
	{
		for ( int i = 0; i < mSkinselectorWidget->mSkins->count(); i++ )
		{ // FIXME: no check wether "kjofol" is ever found, well, it HAS to be in the list
			if ( mSkinselectorWidget->mSkins->text(i) == "kjofol" )
				item = i;
		}
	}
	else
		item = mSkinselectorWidget->mSkins->currentItem();

	if ( item != -1 )
		mSkinselectorWidget->mSkins->setCurrentItem( item );

	// update configuration
	if ( deletingCurrentSkin )
		save();
}

void KJPrefs::slotResult(KIO::Job *job )
{
	if ( job->error() )
	{
		job->showErrorDialog(this);
	}
	else
	{
		// Reload Skinlist
		reopen();
	}
}


/* =================================================================================== */


// takes name of rc-file without .rc at the end and returns full path to rc-file
static TQString expand(TQString s)
{
//	kdDebug(66666) << "expand( "<< s.latin1() << " )" << endl;

	TQStringList skinLocations = KGlobal::dirs()->findDirs("data", "noatun/skins/kjofol");

	// iterate through all paths where Noatun is searching for kjofol-skins
	for (uint i = 0; i < skinLocations.count(); ++i )
	{
		TQStringList skinDirs = TQDir(skinLocations[i]).entryList();

		// iterate trough all dirs containing a skin
		for (uint k = 0; k < skinDirs.count(); ++k )
		{
			TQDir skinDirCnt = TQDir ( skinLocations[i]+skinDirs[k], "*.rc", TQDir::Name|TQDir::IgnoreCase, TQDir::Files );
			// make a list of all .rc-files in a skindir
			TQStringList rcFiles = skinDirCnt.entryList();

			// iterate trough all those rc.-files in a skindir
			for (uint j = 0; j < rcFiles.count(); j++ )
			{
				if ( rcFiles[j].left(rcFiles[j].length()-3) == s ) // found $s.rc :)
				{
//					kdDebug(66666) << "expand() found: " << TQString(skinLocations[i]+skinDirs[k]+"/"+rcFiles[j]).latin1() << endl;
					return (skinLocations[i]+skinDirs[k]+"/"+rcFiles[j]);
				}
			}
		}
	}
	return TQString();
}

TQString filenameNoCase(const TQString &filename, int badNodes)
{
	TQStringList names=TQStringList::split('/', filename);
	TQString full;
	int number=(int)names.count();
	for (TQStringList::Iterator i=names.begin(); i!=names.end(); ++i)
	{
		full+="/";
		if (number<=badNodes)
		{
			TQDir d(full);
			TQStringList files=d.entryList();
			files=files.grep(TQRegExp("^"+ (*i) + "$", false));
			if (!files.count())
				return "";
			*i=files.grep(*i, false)[0];
		}

		full+=*i;

		number--;
	}

	if (filename.right(1)=="/")
		full+="/";
	return full;
}