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
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
|
//
// C++ Implementation: setupdialogprg
//
// Description:
//
//
// Author: KoolDock team <radix@kde.cl>, (C) 2004
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include <kfiledialog.h>
#include <kimageio.h>
#include <kicondialog.h>
#include <klocale.h>
#include <ksimpleconfig.h>
#include <kmessagebox.h>
#include <kstandarddirs.h>
#include <kpushbutton.h>
#include <keditlistbox.h>
#include <klineedit.h>
#include <qlistbox.h>
#include <krun.h>
#include <qiconview.h>
#include <qdir.h>
#include <qstringlist.h>
#include <qtabwidget.h>
#include "setupdialog.h"
#include "setupdialogprg.h"
#include "apppropprg.h"
#include "appProp.h"
#include "kooldock.h"
SetupDialogPrg::SetupDialogPrg(QWidget *parent, const char *name)
: SetupDialog(parent, name)
{
//Ignore list handlers
grabbing=0;
gwm=new KWinModule();
connect(gwm, SIGNAL(activeWindowChanged(WId)), SLOT(activeWindowChanged(WId)));
gwm->blockSignals(true);
in=ignoreBox->lineEdit();
//Remove useless buttons from widget
up=ignoreBox->upButton();
down=ignoreBox->downButton();
up->hide();
down->hide();
//End ignore list handlers
// some configuration variables
progPath = locateLocal("data", "kooldock");
menuPath = progPath + QString("/menu/");
KConfig *config = KGlobal::config();
config->setGroup("kooldock");
appdlg=new appPropPrg();
appdlg->user->setEnabled(false);
appdlg->cuser->setChecked(false);
appdlg->terminal->setChecked(false);
appdlg->tclose->setChecked(false);
appdlg->tclose->setEnabled(false);
connect(appdlg, SIGNAL(apply()), SLOT(appRestart()));
//Lets load the theme List
KStandardDirs sys;
QStringList bgPath = sys.findDirs("data", "kooldock/backgrounds");
for(unsigned int i=0; i<bgPath.count();i++)
{
QDir tmpdir(bgPath[i]);
QStringList theme_tmp(tmpdir.entryList(QDir::Dirs, QDir::Name));
//We do it like this to avoid showing "." and ".." instead of copying QDir::entryList directly into "theme"
for(unsigned int j=2; j<theme_tmp.count(); j++) theme->insertItem(theme_tmp[j]);
}
}
void SetupDialogPrg::appRestart()
{
if(!appdlg) return;
iconsChanged();
kdDebug(0) << "Refresh applist" << endl;
appClear();
appFill();
}
SetupDialogPrg::~SetupDialogPrg()
{
if(appdlg) delete(appdlg);
if(in) delete(in);
kdDebug(0) << "Destroying..." << endl;
}
// Setup dialog implementation
void SetupDialogPrg::iconsChanged()
{
toReloadIcons->setChecked(TRUE);
}
void SetupDialogPrg::configOK()
{
this->hide();
configApply();
}
void SetupDialogPrg::configApply()
{
int fShowTaskbar=0;
int fMinimizedOnly=0;
int fShowNotification=0;
int fShowBorders=0;
int fShowKMenu=0;
int fUseKBFX=0;
int fHidden=0;
int showNames=0;
int fCleaner=0;
int fHideOnClick=0;
int fStayBelow = 0;
int fSteppy=0;
int xinerama=0;
int fhideTimer=5;
int fShowNav=0;
int fSystray=0;
int fCurrent=0;
int fPriority=0;
int fpercentPos=0;
int fOrientation=0;
int fClipping=0;
int fClipIcons=0;
int fSpeed=0;
//Stop grabbing window
gwm->blockSignals(true);
grabbing=0;
grabWin->setText(i18n("Grab Window"));
if (chk5->isChecked() == true) fShowTaskbar = 1;
if (cbMinimizedOnly->isChecked() == true) fMinimizedOnly = 1;
if (chk6->isChecked() == true) fShowNotification = 1;
if (chk4->isChecked() == true) fShowBorders = 1;
if (chk7->isChecked() == true) fShowKMenu = 1;
if (chkUseKBFX->isChecked() == true) fUseKBFX = 1;
if (chk1->isChecked() == true)
{
fHidden = 1;
}
fhideTimer = hideTimer->value();
if (chk2->isChecked() == true) showNames = 1;
if (cbCleaner->isChecked() == true) fCleaner = 1;
if (hideOnClick->isChecked() == true) fHideOnClick = 1;
if (cbStayBelow->isChecked() == true) fStayBelow = 1;
if (Steppy->isChecked() == true) fSteppy = 1;
if (xrma->isChecked() == true) xinerama=1;
if (nav->isChecked()==true) fShowNav=1;
if (systray->isChecked()==true) fSystray=1;
if (currentDesk->isChecked()==true) fCurrent=1;
if (chClipping->isChecked()==true) fClipping=1;
if (chClipIcons->isChecked()==true) fClipIcons=1;
if (chkSpeed->isChecked()==true) fSpeed=1;
fPriority=Priority->value();
fpercentPos=percentPos->value();
kdDebug(0) << "Saving preferences..." << endl;
KConfig *config = KGlobal::config();
config->setGroup("kooldock");
config->writeEntry("ShowTaskbar", fShowTaskbar);
config->writeEntry("MinimizedOnly", fMinimizedOnly);
config->writeEntry("ShowNotification", fShowNotification);
config->writeEntry("BorderColor", kColorCombo3->color().name());
config->writeEntry("SmallIconSize", iwSmall->value());
config->writeEntry("BigIconSize", iwBig->value());
config->writeEntry("BigIconAmount", fAmount->value());
config->writeEntry("iSpace", sbSpace->value());
config->writeEntry("BackgroundColor", kColorCombo2->color().name());
config->writeEntry("SeparatorColor", kColorCombo4->color().name());
config->writeEntry("ShowKMenu", fShowKMenu);
config->writeEntry("KBFX", fUseKBFX);
config->writeEntry("Hidden", fHidden);
config->writeEntry("HideOnClick", fHideOnClick);
config->writeEntry("StayBelow", fStayBelow);
config->writeEntry("fSteppy", fSteppy);
config->writeEntry("Xinerama", xinerama);
config->writeEntry("nWideBg", nWideBg->isChecked());
config->writeEntry("scaleMax", opScale2->isChecked());
if(xinerama==1) {config->writeEntry("leftRes", SleftRes->value()); config->writeEntry("XinDesiredHeight", SHeight->value()); config->writeEntry("XinPreviousWidth", PWidth->value());}
config->writeEntry("hideTimer", fhideTimer);
config->writeEntry("Navigator", fShowNav);
config->writeEntry("Systray", fSystray);
config->writeEntry("currentDesktop", fCurrent);
config->writeEntry("Priority", fPriority);
config->writeEntry("Clipping", fClipping);
config->writeEntry("ClipIconArea", fClipIcons);
config->writeEntry("percentPos", fpercentPos);
if (op1->isChecked()) fOrientation=1;
if (op2->isChecked()) fOrientation=2;
if (op3->isChecked()) fOrientation=3;
config->writeEntry("fOrientation", fOrientation);
config->writeEntry("zoomSpeed", zoomSpeed->value());
config->writeEntry("speedControl", fSpeed);
// kosd config
config->writeEntry("showNames", showNames);
config->writeEntry("Cleaner", fCleaner);
config->writeEntry("xosdFont", xosdFont->currentText());
config->writeEntry("xosdColor", kColorCombo1->color().name());
config->writeEntry("xosdShadowColor", kColorCombo_shadow->color().name());
config->writeEntry("xosdShadowOffset", spinBox2->value());
config->writeEntry("xosdSize", xosdSize->value());
if (xosdBold->isChecked())
{
config->writeEntry("xosdBold", 1);
}
else
{
config->writeEntry("xosdBold", 0);
}
if (xosdItalic->isChecked())
{
config->writeEntry("xosdItalic", 1);
}
else
{
config->writeEntry("xosdItalic", 0);
}
config->writeEntry("ShowSShot", chkSshot->isChecked());
config->writeEntry("iconGrouping", chkGrouping->isChecked());
// save background configurations
if (chkImg->isChecked())
{
//Lets find exactly where the selected theme is
KStandardDirs sys;
QString theme_dir="kooldock/backgrounds/"+theme->currentText();
QStringList bgPath = sys.findDirs("data", theme_dir);
//Lets set the images and write the config
QString LeftImg=(QString)bgPath[0]+"background-left.png";
QString CenterImg=(QString)bgPath[0]+"background-center.png";
QString RightImg=(QString)bgPath[0]+"background-right.png";
// background image enabled
config->writeEntry("Solid", 0);
config->writeEntry("Theme", theme->currentText());
config->writeEntry("LeftImg", LeftImg);
config->writeEntry("RightImg", RightImg);
config->writeEntry("CenterImg", CenterImg);
config->writeEntry("ShowBorders", 0);
config->writeEntry("DockOpacity", 0);
}
else
{
// background image disabled
config->writeEntry("Solid", 1);
config->writeEntry("Theme", "");
config->writeEntry("LeftImg", "");
config->writeEntry("RightImg", "");
config->writeEntry("CenterImg", "");
config->writeEntry("ShowBorders", fShowBorders);
config->writeEntry("DockOpacity", spinBox1->value());
}
config->sync();
// write ignore list to file
QString progPath = locateLocal("data", "kooldock");
QString menuPath = progPath + QString("/menu/");
filepath = QString(progPath + "/ignorelist.conf");
if(ignoreBox->count()>0)
{
QFile out(filepath);
if (out.open(IO_WriteOnly))
{
QTextStream out_s(&out);
for(int i=0; i<ignoreBox->count(); i++)
{
out_s << ignoreBox->text(i) << "\n";
}
out.close();
}
}
else
{
QFile::remove(filepath);
}
emit apply();
}
void SetupDialogPrg::configCancel()
{
//Stop grabbing Windows
gwm->blockSignals(true);
grabWin->setText(i18n("Grab Window"));
grabbing=0;
this->hide();
}
void SetupDialogPrg::closeEvent( QCloseEvent *e )
{
e->ignore();
configCancel();
}
void SetupDialogPrg::chkFont()
{
bool tmp; //just to save some code
if(chk2->isChecked())
{
tmp=true;
}
else
{
tmp=false;
}
xosdBold->setEnabled(tmp);
xosdItalic->setEnabled(tmp);
xosdSize->setEnabled(tmp);
spinBox2->setEnabled(tmp);
kColorCombo1->setEnabled(tmp);
kColorCombo_shadow->setEnabled(tmp);
xosdFont->setEnabled(tmp);
cbCleaner->setEnabled(tmp);
}
void SetupDialogPrg::xrma_clicked()
{
if(xrma->isChecked()==true) {SleftRes->setEnabled(true); SHeight->setEnabled(true); PWidth->setEnabled(true);}
if(xrma->isChecked()==false) {SleftRes->setEnabled(false); SHeight->setEnabled(false); PWidth->setEnabled(false);}
}
void SetupDialogPrg::chkTask()
{
iconsChanged();
bool tmp;
if(chk5->isChecked())
{
tmp=true;
}
else
{
tmp=false;
}
chk6->setEnabled(tmp);
currentDesk->setEnabled(tmp);
chkSshot->setEnabled(tmp);
chkGrouping->setEnabled(tmp);
cbMinimizedOnly->setEnabled(tmp);
}
void SetupDialogPrg::chkHidden()
{
bool tmp;
if(chk1->isChecked())
{
tmp=true;
}
else
{
tmp=false;
}
hideTimer->setEnabled(tmp);
hideOnClick->setEnabled(tmp);
cbStayBelow->setEnabled(!tmp);
}
void SetupDialogPrg::applist_dropped(QDropEvent*e,const QValueList<QIconDragItem>&)
{
KIconLoader icon_obj;
QStringList lst;
QString name;
int pos;
QUriDrag::decodeLocalFiles(e, lst);
name=lst[0];
//Lets see if it is a desktop file
pos=name.findRev(".desktop", -1);
if(pos!=-1)
{
KSimpleConfig *desktopfile;
kdDebug(0) << "Desktop file dropped!" << endl;
desktopfile = new KSimpleConfig(lst[0], TRUE);
desktopfile->setGroup("Desktop Entry");
appdlg->cmdname->setText(desktopfile->readEntry("Name"));
appdlg->cmdpath->setText(desktopfile->readEntry("Exec"));
appdlg->iconbutton->setIcon(desktopfile->readEntry("Icon"));
delete(desktopfile);
}
else
{
//It was not a dekstop file, so lets create a new entry
//Lets set a default name based on the program name
pos=name.findRev("/", -1);
if(pos!=-1)
{
name.remove(1, pos);
name.remove("/", TRUE);
}
//Now we create and show the appProp dialog
//appdlg=new appPropPrg();
appdlg->cmdname->setText(name);
appdlg->cmdpath->setText(lst[0]);
//Based on the program name, lets try to set an icon; if it does
//not exists, the system will set the "default" icon
appdlg->iconbutton->setIcon(name);
}
appdlg->show();
}
void SetupDialogPrg::removeLauncher()
{
if(fileName!=NULL)
{
QString question=i18n("Do you want to remove ") + fileName + QString("?");
int remove = KMessageBox::questionYesNo(0, question, i18n("Remove Launcher"));
if(remove!=KMessageBox::Yes) return;
KSimpleConfig *desktopfile;
QDir homeDir = QDir::home();
if (homeDir.exists(progPath))
{
QDir dir(menuPath);
QStringList fileListRemove;
fileListRemove = dir.entryList("*.desktop");
for ( QStringList::Iterator it = fileListRemove.begin(); it != fileListRemove.end(); ++it )
{
if ( ((*it) != ".") && ((*it) != "..") )
{
desktopfile = new KSimpleConfig( menuPath + (*it), TRUE);
desktopfile->setGroup("Desktop Entry");
if(desktopfile->readEntry("Name")==fileName)
{
kdDebug(0) << "Removing " << menuPath + (*it) << endl;
delete(desktopfile);
if(QFile::remove(menuPath+(*it))==TRUE)
{
kdDebug(0) << "Item removed!" << endl;
//Lets update the launchers index
QString preffix;
fileListRemove.clear();
fileListRemove=dir.entryList("*.desktop");
QStringList fileListRemove2=fileListRemove;
//Not really sure why I couldn't do this within the other for, something like fileListRemove[i].remove(0,2).prepend(preffix), but hell it works
for(unsigned int i=0; i<fileListRemove2.count(); i++)
{
fileListRemove2[i].remove(0,2);
}
//Rename the files so they reflect their new position
for(unsigned int i=0; i<fileListRemove.count(); i++)
{
if(i<10) preffix=QString("0%1").arg(i);
if(i>=10) preffix=QString("%1").arg(i);
dir.rename(fileListRemove[i], QString("%1%2").arg(preffix).arg(fileListRemove2[i]));
}
//End updating
appClear();
appFill();
iconsChanged();
}
else
{
kdDebug(0) << "Unable to remove file!" << endl;
}
return;
}
delete(desktopfile);
}
}
}
}
}
void SetupDialogPrg::grabWin_clicked()
{
if(grabbing==0)
{
grabbing=1;
grabWin->setText(i18n("Grabbing..."));
gwm->blockSignals(false);
}
else
{
grabbing=0;
grabWin->setText(i18n("Grab Window"));
gwm->blockSignals(true);
}
}
void SetupDialogPrg::activeWindowChanged(WId id)
{
KWin::WindowInfo winfo;
winfo=KWin::windowInfo(id);
QString ninfo=winfo.visibleName();
if(ninfo!=caption())
{
in->setText(ninfo);
}
}
void SetupDialogPrg::buttonadd_clicked()
{
appdlg->cmdpath->setText("");
appdlg->cmdname->setText("");
appdlg->iconbutton->setIcon("unknown");
appdlg->show();
}
void SetupDialogPrg::showEvent(QShowEvent *)
{
//Here we fill the applist
appFill();
}
void SetupDialogPrg::appFill()
{
// fill the application list.
KSimpleConfig *desktopfile;
QDir homeDir = QDir::home();
KIconLoader icon_obj;
QPixmap pixm;
if(homeDir.exists(progPath))
{
QDir dir(menuPath);
fileList.clear();
fileList = dir.entryList("*.desktop");
for ( QStringList::Iterator it = fileList.begin(); it != fileList.end(); ++it )
{
if ( ((*it) != ".") && ((*it) != "..") )
{
desktopfile = new KSimpleConfig( menuPath + (*it), TRUE);
desktopfile->setGroup("Desktop Entry");
QPixmap pixm=icon_obj.loadIcon(desktopfile->readEntry("Icon") ,KIcon::Desktop,0,KIcon::DefaultState,0L,false);
new KIconViewItem(applist, desktopfile->readEntry("Name"), pixm);
delete(desktopfile);
}
}
}
}
void SetupDialogPrg::hideEvent ( QHideEvent * )
{
// the application list is erased here.
appClear();
}
void SetupDialogPrg::appClear()
{
applist->clear();
}
void SetupDialogPrg::left()
{
if (oldPos>0) {setnewpos(oldPos-1); oldPos--;iconsChanged();}
}
void SetupDialogPrg::right()
{
if (oldPos!=-1 && oldPos < (int)fileList.count()-1) {setnewpos(oldPos+1); oldPos++;iconsChanged();}
}
void SetupDialogPrg::applist_clicked(QIconViewItem *e, const QPoint&)
{
if(e!=NULL)
{oldPos=e->index();}
else
{oldPos=-1;}
}
void SetupDialogPrg::applist_contextMenuRequested(QIconViewItem *e,const QPoint&)
{
if(e!=NULL)
{
KPopupMenu *popup=new KPopupMenu();
KPopupMenu *setpos=new KPopupMenu();
fileName=e->text();
oldPos=e->index();
connect(setpos, SIGNAL(activated(int)), this, SLOT(setnewpos(int)));
//Load desktop data
KSimpleConfig *desktopfile;
QDir dir(menuPath);
fileList.clear();
fileList = dir.entryList("*.desktop");
int i=0;
for ( QStringList::Iterator it = fileList.begin(); it != fileList.end(); ++it )
{
if ( ((*it) != ".") && ((*it) != "..") )
{
desktopfile = new KSimpleConfig( menuPath + (*it), TRUE);
desktopfile->setGroup("Desktop Entry");
int menustate=setpos->insertItem(QString("%1").arg(desktopfile->readEntry("Name")),i);
if(i==oldPos) {setpos->setItemEnabled(menustate, false);filepath=menuPath + (*it);}
delete(desktopfile);
i++;
}
}
//End Load
popup->insertTitle(e->text());
popup->insertItem(i18n("Swap with"), setpos);
popup->insertItem(i18n("&Edit item"), this, SLOT(editItem()));
popup->insertItem(i18n("Remove"), this, SLOT(removeLauncher()));
popup->exec(QCursor::pos());
if(popup) delete(popup);
if(setpos) delete(setpos);
}
else
{
oldPos=-1;
}
}
void SetupDialogPrg::editItem()
{
KRun::runCommand("kfmclient openProperties " + filepath, "kfmclient", "");
}
void SetupDialogPrg::setnewpos(int newpos)
{
kdDebug(0) << "New pos " << QString("0%1").arg(newpos) << "requested for: " << fileName<< endl;
if(newpos==oldPos) return; //Nothing to be done
computeNewPos(newpos);
}
void SetupDialogPrg::computeNewPos(int pos)
{
QString preffix, preffix2;
QDir dir(menuPath);
fileList.clear();
fileList = dir.entryList("*.desktop");
//Lets remove the preffix of the files from fileList
for(unsigned int i=0; i<fileList.count(); i++)
{
fileList[i]=fileList[i].remove(0,2);
}
//Preffix for old position
if(oldPos<10) preffix=QString("0%1").arg(oldPos);
if(oldPos>=10) preffix=QString("%1").arg(oldPos);
//Preffix for new position
if(pos<10) preffix2=QString("0%1").arg(pos);
if(pos>=10) preffix2=QString("%1").arg(pos);
kdDebug(0) << "Old Position: " << oldPos << endl;
kdDebug(0) << "New Position: " << pos << endl;
dir.rename(QString("%1%2").arg(preffix).arg(fileList[oldPos]), QString("%1%2").arg(preffix2).arg(fileList[oldPos]));
dir.rename(QString("%1%2").arg(preffix2).arg(fileList[pos]), QString("%1%2").arg(preffix).arg(fileList[pos]));
appClear();
appFill();
}
void SetupDialogPrg::chkImgSlot()
{
if (chkImg->isChecked())
{
chkSolid->setChecked(false);
}
else
{
chkSolid->setChecked(true);
}
}
void SetupDialogPrg::chkSolidSlot()
{
if (chkSolid->isChecked())
{
chkImg->setChecked(false);
}
else
{
chkImg->setChecked(true);
}}
#include "setupdialogprg.moc"
|