2
* kate: space-indent on; indent-width 4; indent-mode cstyle;
4
* This file is part of the KDE project, module kdesktop.
5
* Copyright (C) 1999 Geert Jansen <g.t.jansen@stud.tue.nl>
7
* You can Freely distribute this program under the GNU Library General
8
* Public License. See the file "COPYING.LIB" for the exact licensing terms.
16
// Clean up after X.h/Xlib.h
23
#include <dcopclient.h>
24
#include <kapplication.h>
26
#include <kglobalsettings.h>
27
#include <ksimpleconfig.h>
28
#include <kstandarddirs.h>
29
#include <krandomsequence.h>
30
#include <konq_defaults.h>
32
#include "bgdefaults.h"
34
#include "bgsettings.h"
37
/**** KBackgroundPattern ****/
40
KBackgroundPattern::KBackgroundPattern(QString name)
45
m_pDirs = KGlobal::dirs();
46
m_pDirs->addResourceType("dtop_pattern", m_pDirs->kde_default("data") +
59
KBackgroundPattern::~KBackgroundPattern()
64
void KBackgroundPattern::copyConfig(const KBackgroundPattern *settings)
66
dirty = hashdirty = true;
67
m_Name = settings->m_Name;
68
m_Comment = settings->m_Comment;
69
m_Pattern = settings->m_Pattern;
70
m_File = settings->m_File;
73
void KBackgroundPattern::load(QString name)
81
void KBackgroundPattern::init(bool force_rw)
85
m_File = m_pDirs->findResource("dtop_pattern", m_Name + ".desktop");
86
if (force_rw || m_File.isEmpty()) {
87
m_File = m_pDirs->saveLocation("dtop_pattern") + m_Name + ".desktop";
88
m_pConfig = new KSimpleConfig(m_File);
90
m_pConfig = new KSimpleConfig(m_File);
92
m_pConfig->setGroup("KDE Desktop Pattern");
95
m_bReadOnly = !fi.isWritable();
99
void KBackgroundPattern::setComment(const QString &comment)
101
if (m_Comment == comment)
108
void KBackgroundPattern::setPattern(QString pattern)
110
if (m_Pattern == pattern)
112
dirty = hashdirty = true;
117
void KBackgroundPattern::readSettings()
122
m_Pattern = m_pConfig->readPathEntry("File");
123
m_Comment = m_pConfig->readEntry("Comment");
124
if (m_Comment.isEmpty())
125
m_Comment = m_File.mid(m_File.findRev('/')+1);
129
void KBackgroundPattern::writeSettings()
137
return; // better safe than sorry
139
m_pConfig->writePathEntry("File", m_Pattern);
140
m_pConfig->writeEntry("Comment", m_Comment);
146
bool KBackgroundPattern::isAvailable()
148
if (m_Pattern.isEmpty())
150
QString file = m_Pattern;
151
if (file.at(0) != '/')
152
file = m_pDirs->findResource("dtop_pattern", file);
154
return (fi.exists());
158
bool KBackgroundPattern::remove()
162
return !unlink(QFile::encodeName(m_File));
166
QString KBackgroundPattern::fingerprint()
172
int KBackgroundPattern::hash()
175
m_Hash = QHash(fingerprint());
183
QStringList KBackgroundPattern::list()
185
KStandardDirs *dirs = KGlobal::dirs();
186
dirs->addResourceType("dtop_pattern", dirs->kde_default("data") +
187
"kdesktop/patterns");
188
QStringList lst = dirs->findAllResources("dtop_pattern", "*.desktop",
190
QStringList::Iterator it;
191
for (it=lst.begin(); it!=lst.end(); ++it) {
192
// Strip path and suffix
193
int pos = (*it).findRev('/');
195
(*it) = (*it).mid(pos+1);
196
pos = (*it).findRev('.');
198
(*it) = (*it).left(pos);
204
/**** KBackgroundProgram ****/
207
KBackgroundProgram::KBackgroundProgram(QString name)
212
m_pDirs = KGlobal::dirs();
213
m_pDirs->addResourceType("dtop_program", m_pDirs->kde_default("data") +
214
"kdesktop/programs");
217
// prevent updates when just constructed.
218
m_LastChange = (int) time(0L);
221
if (m_Name.isEmpty())
229
KBackgroundProgram::~KBackgroundProgram()
234
void KBackgroundProgram::copyConfig(const KBackgroundProgram *settings)
236
dirty = hashdirty = true;
237
m_Refresh = settings->m_Refresh;
238
m_LastChange = settings->m_LastChange;
239
m_Name = settings->m_Name;
240
m_Command = settings->m_Command;
241
m_PreviewCommand = settings->m_PreviewCommand;
242
m_Comment = settings->m_Comment;
243
m_Executable = settings->m_Executable;
244
m_File = settings->m_File;
248
void KBackgroundProgram::init(bool force_rw)
252
m_File = m_pDirs->findResource("dtop_program", m_Name + ".desktop");
253
if (force_rw || m_File.isEmpty()) {
254
m_File = m_pDirs->saveLocation("dtop_program") + m_Name + ".desktop";
255
m_pConfig = new KSimpleConfig(m_File);
258
m_pConfig = new KSimpleConfig(m_File);
259
m_bReadOnly = (m_File != locateLocal("dtop_program", m_Name + ".desktop"));
261
m_pConfig->setGroup("KDE Desktop Program");
265
void KBackgroundProgram::load(const QString &name)
273
void KBackgroundProgram::setComment(const QString &comment)
275
if (m_Comment == comment)
282
void KBackgroundProgram::setExecutable(const QString &executable)
284
if (m_Executable == executable)
287
m_Executable = executable;
291
void KBackgroundProgram::setCommand(const QString &command)
293
if (m_Command == command)
295
dirty = hashdirty = true;
300
void KBackgroundProgram::setPreviewCommand(const QString &command)
302
if (m_PreviewCommand == command)
305
m_PreviewCommand = command;
309
void KBackgroundProgram::setRefresh(int refresh)
311
if (m_Refresh == refresh)
313
dirty = hashdirty = true;
318
void KBackgroundProgram::readSettings()
323
m_Comment = m_pConfig->readEntry("Comment");
324
m_Executable = m_pConfig->readPathEntry("Executable");
325
m_Command = m_pConfig->readPathEntry("Command");
326
m_PreviewCommand = m_pConfig->readPathEntry("PreviewCommand", m_Command);
327
m_Refresh = m_pConfig->readNumEntry("Refresh", 300);
331
void KBackgroundProgram::writeSettings()
339
return; // better safe than sorry
341
m_pConfig->writeEntry("Comment", m_Comment);
342
m_pConfig->writePathEntry("Executable", m_Executable);
343
m_pConfig->writePathEntry("Command", m_Command);
344
m_pConfig->writeEntry("PreviewCommand", m_PreviewCommand);
345
m_pConfig->writeEntry("Refresh", m_Refresh);
351
bool KBackgroundProgram::isAvailable()
353
return !m_pDirs->findExe(m_Executable).isEmpty();
357
bool KBackgroundProgram::remove()
361
return !unlink(QFile::encodeName(m_File));
365
bool KBackgroundProgram::needUpdate()
367
return (m_LastChange + 60*m_Refresh <= time(0L));
371
void KBackgroundProgram::update()
373
m_LastChange = (int) time(0L);
377
QString KBackgroundProgram::fingerprint()
379
return QString("co:%1;re:%2").arg(m_Command).arg(m_Refresh);
383
int KBackgroundProgram::hash()
386
m_Hash = QHash(fingerprint());
394
QStringList KBackgroundProgram::list()
396
KStandardDirs *dirs = KGlobal::dirs();
397
dirs->addResourceType("dtop_program", dirs->kde_default("data") +
398
"kdesktop/programs");
399
QStringList lst = dirs->findAllResources("dtop_program", "*.desktop",
401
QStringList::Iterator it;
402
for (it=lst.begin(); it!=lst.end(); ++it) {
403
// Strip path and suffix
404
int pos = (*it).findRev('/');
406
(*it) = (*it).mid(pos+1);
407
pos = (*it).findRev('.');
409
(*it) = (*it).left(pos);
415
/**** KBackgroundSettings ****/
418
KBackgroundSettings::KBackgroundSettings(int desk, int screen, bool drawBackgroundPerScreen, KConfig *config)
419
: KBackgroundPattern(),
422
dirty = false; hashdirty = true;
423
m_bDrawBackgroundPerScreen = drawBackgroundPerScreen;
429
defColorA = _defColorA;
430
defColorB = _defColorB;
431
if (QPixmap::defaultDepth() > 8)
432
defBackgroundMode = _defBackgroundMode;
434
defBackgroundMode = Flat;
435
defWallpaperMode = _defWallpaperMode;
436
defMultiMode = _defMultiMode;
437
defBlendMode = _defBlendMode;
438
defBlendBalance = _defBlendBalance;
439
defReverseBlending = _defReverseBlending;
441
m_MinOptimizationDepth = _defMinOptimizationDepth;
445
#define ADD_STRING(ID) m_BMMap[#ID] = ID; m_BMRevMap[ID] = (char *) #ID;
449
ADD_STRING(HorizontalGradient)
450
ADD_STRING(VerticalGradient)
451
ADD_STRING(PyramidGradient)
452
ADD_STRING(PipeCrossGradient)
453
ADD_STRING(EllipticGradient)
457
#define ADD_STRING(ID) m_BlMMap[#ID] = ID; m_BlMRevMap[ID] = (char *) #ID;
458
ADD_STRING(NoBlending)
459
ADD_STRING(FlatBlending)
460
ADD_STRING(HorizontalBlending)
461
ADD_STRING(VerticalBlending)
462
ADD_STRING(PyramidBlending)
463
ADD_STRING(PipeCrossBlending)
464
ADD_STRING(EllipticBlending)
465
ADD_STRING(IntensityBlending)
466
ADD_STRING(SaturateBlending)
467
ADD_STRING(ContrastBlending)
468
ADD_STRING(HueShiftBlending)
472
#define ADD_STRING(ID) m_WMMap[#ID] = ID; m_WMRevMap[ID] = (char *) #ID;
473
ADD_STRING(NoWallpaper)
476
ADD_STRING(CenterTiled)
477
ADD_STRING(CentredMaxpect)
478
ADD_STRING(TiledMaxpect)
480
ADD_STRING(CentredAutoFit)
481
ADD_STRING(ScaleAndCrop)
484
// Multiple wallpaper modes
485
#define ADD_STRING(ID) m_MMMap[#ID] = ID; m_MMRevMap[ID] = (char *) #ID;
489
ADD_STRING(NoMultiRandom)
492
m_pDirs = KGlobal::dirs();
495
int screen_number = 0;
497
screen_number = DefaultScreen(qt_xdisplay());
499
if (screen_number == 0)
500
configname = "kdesktoprc";
502
configname.sprintf("kdesktop-screen-%drc", screen_number);
504
m_pConfig = new KConfig(configname, false, false);
505
m_bDeleteConfig = true;
508
m_bDeleteConfig = false;
518
KBackgroundSettings::~KBackgroundSettings()
524
void KBackgroundSettings::copyConfig(const KBackgroundSettings *settings)
529
m_ColorA = settings->m_ColorA;
530
m_ColorB = settings->m_ColorB;
531
m_Wallpaper = settings->m_Wallpaper;
532
m_WallpaperList = settings->m_WallpaperList;
533
m_WallpaperFiles = settings->m_WallpaperFiles;
535
m_BackgroundMode = settings->m_BackgroundMode;
536
m_WallpaperMode = settings->m_WallpaperMode;
537
m_BlendMode = settings->m_BlendMode;
538
m_BlendBalance = settings->m_BlendBalance;
539
m_ReverseBlending = settings->m_ReverseBlending;
540
m_MinOptimizationDepth = settings->m_MinOptimizationDepth;
541
m_bShm = settings->m_bShm;
542
m_MultiMode = settings->m_MultiMode;
543
m_Interval = settings->m_Interval;
544
m_CurrentWallpaper = settings->m_CurrentWallpaper;
545
m_CurrentWallpaperName = settings->m_CurrentWallpaperName;
547
KBackgroundPattern::copyConfig(settings);
548
KBackgroundProgram::copyConfig(settings);
552
void KBackgroundSettings::load(int desk, int screen, bool drawBackgroundPerScreen, bool reparseConfig)
556
m_bDrawBackgroundPerScreen = drawBackgroundPerScreen;
557
readSettings(reparseConfig);
561
void KBackgroundSettings::setColorA(const QColor& color)
563
if (m_ColorA == color)
565
dirty = hashdirty = true;
570
void KBackgroundSettings::setColorB(const QColor& color)
572
if (m_ColorB == color)
574
dirty = hashdirty = true;
579
void KBackgroundSettings::setPatternName(QString name)
581
int ohash = KBackgroundPattern::hash();
582
KBackgroundPattern::load(name);
583
if (ohash == KBackgroundPattern::hash())
586
dirty = hashdirty = true;
591
void KBackgroundSettings::setProgram(QString name)
593
int ohash = KBackgroundProgram::hash();
594
KBackgroundProgram::load(name);
595
if (ohash == KBackgroundProgram::hash())
598
dirty = hashdirty = true;
603
void KBackgroundSettings::setBackgroundMode(int mode)
605
if (m_BackgroundMode == mode)
607
dirty = hashdirty = true;
608
m_BackgroundMode = mode;
611
void KBackgroundSettings::setBlendMode(int mode)
613
if (m_BlendMode == mode)
615
dirty = hashdirty = true;
619
void KBackgroundSettings::setBlendBalance(int value)
621
if (m_BlendBalance == value)
623
dirty = hashdirty = true;
624
m_BlendBalance = value;
627
void KBackgroundSettings::setReverseBlending(bool value)
629
if (m_ReverseBlending == value)
631
dirty = hashdirty = true;
632
m_ReverseBlending = value;
636
void KBackgroundSettings::setWallpaper(QString wallpaper)
638
dirty = hashdirty = true;
639
m_Wallpaper = wallpaper;
643
void KBackgroundSettings::setWallpaperMode(int mode)
645
if (m_WallpaperMode == mode)
647
dirty = hashdirty = true;
648
m_WallpaperMode = mode;
652
void KBackgroundSettings::setWallpaperList(QStringList list)
654
KStandardDirs *d = KGlobal::dirs();
655
if (m_WallpaperList == list)
658
dirty = hashdirty = true;
659
m_WallpaperList.clear();
660
for(QStringList::ConstIterator it = list.begin();
661
it != list.end(); ++it)
663
QString rpath = d->relativeLocation("wallpaper", *it);
664
m_WallpaperList.append( !rpath.isEmpty() ? rpath : *it );
666
updateWallpaperFiles();
667
// Try to keep the current wallpaper (-1 to set position to one before it)
668
m_CurrentWallpaper = m_WallpaperFiles.findIndex(m_CurrentWallpaperName) - 1;
669
changeWallpaper(m_CurrentWallpaper < 0);
673
void KBackgroundSettings::setWallpaperChangeInterval(int interval)
675
if (m_Interval == interval)
677
dirty = hashdirty = true;
678
m_Interval = interval;
682
void KBackgroundSettings::setMultiWallpaperMode(int mode)
684
if (m_MultiMode == mode)
686
dirty = hashdirty = true;
688
changeWallpaper(true);
692
void KBackgroundSettings::setMinOptimizationDepth(int mode)
694
if (m_MinOptimizationDepth == mode)
696
dirty = hashdirty = true;
697
m_MinOptimizationDepth = mode;
700
bool KBackgroundSettings::optimize() const
702
switch( m_MinOptimizationDepth )
707
return QPixmap::defaultDepth() >= 16;
709
return QPixmap::defaultDepth() >= 15;
716
void KBackgroundSettings::setUseShm(bool use)
720
dirty = hashdirty = true;
724
QString KBackgroundSettings::configGroupName() const
727
if (m_bDrawBackgroundPerScreen)
728
screenName = QString("Screen%1").arg(QString::number(m_Screen));
729
return QString("Desktop%1%2").arg(m_Desk).arg(screenName);
732
void KBackgroundSettings::readSettings(bool reparse)
735
m_pConfig->reparseConfiguration();
737
m_pConfig->setGroup(configGroupName());
739
// Background mode (Flat, div. Gradients, Pattern or Program)
740
m_ColorA = m_pConfig->readColorEntry("Color1", &defColorA);
741
m_ColorB = m_pConfig->readColorEntry("Color2", &defColorB);
743
QString s = m_pConfig->readPathEntry("Pattern");
745
KBackgroundPattern::load(s);
747
s = m_pConfig->readPathEntry("Program");
749
KBackgroundProgram::load(s);
751
m_BackgroundMode = defBackgroundMode;
752
s = m_pConfig->readEntry("BackgroundMode", "invalid");
754
if (m_BMMap.contains(s)) {
755
int mode = m_BMMap[s];
757
if ( ((mode != Pattern) && (mode != Program)) ||
758
((mode == Pattern) && !pattern().isEmpty()) ||
759
((mode == Program) && !command().isEmpty())
761
m_BackgroundMode = mode;
764
m_BlendMode = defBlendMode;
765
s = m_pConfig->readEntry("BlendMode", "invalid");
766
if (m_BlMMap.contains(s)) {
767
m_BlendMode = m_BlMMap[s];
770
m_BlendBalance = defBlendBalance;
771
int value = m_pConfig->readNumEntry( "BlendBalance", defBlendBalance);
772
if (value > -201 && value < 201)
773
m_BlendBalance = value;
775
m_ReverseBlending = m_pConfig->readBoolEntry( "ReverseBlending", defReverseBlending);
777
// Multiple wallpaper config
778
m_WallpaperList = m_pConfig->readPathListEntry("WallpaperList");
780
m_Interval = m_pConfig->readNumEntry("ChangeInterval", 60);
781
m_LastChange = m_pConfig->readNumEntry("LastChange", 0);
782
m_CurrentWallpaper = m_pConfig->readNumEntry("CurrentWallpaper", 0);
783
m_CurrentWallpaperName = m_pConfig->readEntry("CurrentWallpaperName");
785
m_MultiMode = defMultiMode;
786
s = m_pConfig->readEntry("MultiWallpaperMode");
787
if (m_MMMap.contains(s)) {
788
int mode = m_MMMap[s];
792
updateWallpaperFiles();
793
if( !m_CurrentWallpaperName.isEmpty())
794
m_CurrentWallpaper = m_WallpaperFiles.findIndex(m_CurrentWallpaperName);
795
if(m_CurrentWallpaper < 0)
796
m_CurrentWallpaper = 0;
798
// Wallpaper mode (NoWallpaper, div. tilings)
799
m_WallpaperMode = defWallpaperMode;
800
m_Wallpaper = m_pConfig->readPathEntry("Wallpaper");
801
s = m_pConfig->readEntry("WallpaperMode", "invalid");
802
if (m_WMMap.contains(s)) {
803
int mode = m_WMMap[s];
804
// consistency check.
805
if ((mode == NoWallpaper) || !m_Wallpaper.isEmpty() || (m_MultiMode == InOrder || m_MultiMode == Random))
806
m_WallpaperMode = mode;
809
m_MinOptimizationDepth = m_pConfig->readNumEntry( "MinOptimizationDepth",
810
_defMinOptimizationDepth );
811
m_bShm = m_pConfig->readBoolEntry( "UseSHM", _defShm );
813
dirty = reparse; hashdirty = true;
817
void KBackgroundSettings::writeSettings()
819
KBackgroundPattern::writeSettings();
820
KBackgroundProgram::writeSettings();
825
m_pConfig->setGroup(configGroupName());
826
m_pConfig->writeEntry("Color1", m_ColorA);
827
m_pConfig->writeEntry("Color2", m_ColorB);
828
m_pConfig->writePathEntry("Pattern", KBackgroundPattern::name());
829
m_pConfig->writeEntry("Program", KBackgroundProgram::name());
830
m_pConfig->writeEntry("BackgroundMode", m_BMRevMap[m_BackgroundMode]);
831
m_pConfig->writePathEntry("Wallpaper", m_Wallpaper);
832
m_pConfig->writeEntry("WallpaperMode", m_WMRevMap[m_WallpaperMode]);
833
m_pConfig->writeEntry("MultiWallpaperMode", m_MMRevMap[m_MultiMode]);
834
m_pConfig->writeEntry("BlendMode", m_BlMRevMap[m_BlendMode]);
835
m_pConfig->writeEntry("BlendBalance", m_BlendBalance);
836
m_pConfig->writeEntry("ReverseBlending", m_ReverseBlending);
837
m_pConfig->writeEntry("MinOptimizationDepth", m_MinOptimizationDepth);
838
m_pConfig->writeEntry("UseSHM", m_bShm);
840
m_pConfig->writePathEntry("WallpaperList", m_WallpaperList);
841
m_pConfig->writeEntry("ChangeInterval", m_Interval);
842
m_pConfig->writeEntry("LastChange", m_LastChange);
843
m_pConfig->deleteEntry("CurrentWallpaper"); // obsolete, remember name
844
m_pConfig->writeEntry("CurrentWallpaperName", m_CurrentWallpaperName);
852
* (re)Build m_WallpaperFiles from m_WallpaperList
854
void KBackgroundSettings::updateWallpaperFiles()
856
QStringList::Iterator it;
857
m_WallpaperFiles.clear();
858
for (it=m_WallpaperList.begin(); it!=m_WallpaperList.end(); ++it) {
859
QString file = locate("wallpaper", *it);
865
if (fi.isFile() && fi.isReadable())
866
m_WallpaperFiles.append(file);
869
QStringList lst = dir.entryList(QDir::Files | QDir::Readable);
870
QStringList::Iterator it;
871
for (it=lst.begin(); it!=lst.end(); ++it)
873
file = dir.absFilePath(*it);
875
if (fi.isFile() && fi.isReadable())
876
m_WallpaperFiles.append(file);
881
if (m_MultiMode == Random)
882
randomizeWallpaperFiles();
885
// Randomize the m_WallpaperFiles in a non-repeating method.
886
void KBackgroundSettings::randomizeWallpaperFiles()
888
if (m_WallpaperFiles.count() < 4)
891
KRandomSequence rseq;
892
QStringList tmpList = m_WallpaperFiles;
893
QStringList randomList;
894
randomList.append(tmpList.front());
896
while(tmpList.count())
898
randomList.insert(randomList.at(
899
rseq.getLong(randomList.count()+1)),
904
m_WallpaperFiles = randomList;
907
QStringList KBackgroundSettings::wallpaperList() const
909
if ( m_WallpaperMode == NoWallpaper )
910
return QStringList();
911
if ( m_MultiMode == NoMulti || m_MultiMode == NoMultiRandom )
912
return QStringList(m_Wallpaper);
913
return m_WallpaperList;
916
QStringList KBackgroundSettings::wallpaperFiles() const
918
if ( m_WallpaperMode == NoWallpaper )
919
return QStringList();
920
if ( m_MultiMode == NoMulti || m_MultiMode == NoMultiRandom )
921
return QStringList(m_Wallpaper);
922
return m_WallpaperFiles;
926
* Select a new wallpaper from the list.
928
void KBackgroundSettings::changeWallpaper(bool init)
930
if (m_WallpaperFiles.count() == 0) {
932
m_CurrentWallpaper = 0;
933
m_CurrentWallpaperName = QString();
938
switch (m_MultiMode) {
940
m_CurrentWallpaper++;
941
if (init || (m_CurrentWallpaper >= (int) m_WallpaperFiles.count()))
942
m_CurrentWallpaper = 0;
946
// Random: m_WallpaperFiles is randomized in a non-repeating
947
// method. Hence we just increment the index.
948
m_CurrentWallpaper++;
949
if (init || (m_CurrentWallpaper >= (int) m_WallpaperFiles.count())) {
950
m_CurrentWallpaper = 0;
951
randomizeWallpaperFiles(); // Get a new random-ordered list.
958
m_CurrentWallpaperName = m_WallpaperFiles[ m_CurrentWallpaper ];
959
m_LastChange = (int) time(0L);
960
m_pConfig->setGroup(configGroupName());
961
m_pConfig->deleteEntry("CurrentWallpaper"); // obsolete, remember name
962
m_pConfig->writeEntry("CurrentWallpaperName", m_CurrentWallpaperName);
963
m_pConfig->writeEntry("LastChange", m_LastChange);
970
QString KBackgroundSettings::currentWallpaper() const
972
if ( m_WallpaperMode == NoWallpaper )
973
return QString::null;
974
if (m_MultiMode == NoMulti || m_MultiMode == NoMultiRandom)
977
if (m_CurrentWallpaper >= 0 && m_CurrentWallpaper < (int) m_WallpaperFiles.count())
978
return m_WallpaperFiles[m_CurrentWallpaper];
979
return QString::null;
982
bool KBackgroundSettings::discardCurrentWallpaper()
984
if (m_MultiMode == NoMulti || m_MultiMode == NoMultiRandom)
988
m_WallpaperFiles.remove(m_WallpaperFiles.at(m_CurrentWallpaper));
989
--m_CurrentWallpaper;
996
bool KBackgroundSettings::needWallpaperChange()
998
if (m_MultiMode == NoMulti || m_MultiMode == NoMultiRandom)
1001
return ((m_LastChange + 60*m_Interval) <= time(0L));
1006
* Create a fingerprint string for this config. Be somewhat (overly) carefull
1007
* that only a different final result will give a different fingerprint.
1010
QString KBackgroundSettings::fingerprint()
1012
QString s = QString("bm:%1;en:%2").arg(m_BackgroundMode).arg(m_bEnabled);
1013
switch (m_BackgroundMode) {
1015
s += QString("ca:%1;").arg(m_ColorA.rgb());
1018
s += QString("pr:%1;").arg(KBackgroundProgram::hash());
1021
s += QString("ca:%1;cb:%2;pt:%3;").arg(m_ColorA.rgb())
1022
.arg(m_ColorB.rgb()).arg(KBackgroundPattern::hash());
1025
s += QString("ca:%1;cb:%2;").arg(m_ColorA.rgb()).arg(m_ColorB.rgb());
1029
s += QString("wm:%1;").arg(m_WallpaperMode);
1030
if (m_WallpaperMode != NoWallpaper)
1032
Q_UINT32 rh = KGlobal::dirs()->calcResourceHash("wallpaper", currentWallpaper(), false);
1033
s += QString("wp:%2:%1;").arg(rh).arg(currentWallpaper());
1036
s += QString("blm:%1;").arg(m_BlendMode);
1037
if (m_BlendMode != NoBlending) {
1038
s += QString("blb:%1;").arg(m_BlendBalance);
1039
s += QString("rbl:%1;").arg(int(m_ReverseBlending));
1041
s += QString::number( m_bShm );
1042
s += QString::number( m_MinOptimizationDepth );
1048
int KBackgroundSettings::hash()
1051
m_Hash = QHash(fingerprint());
1057
void KBackgroundSettings::setEnabled(const bool enable)
1059
if (m_bEnabled == enable)
1066
/**** KGlobalBackgroundSettings ****/
1068
KGlobalBackgroundSettings::KGlobalBackgroundSettings(KConfig *_config)
1070
m_pConfig = _config;
1076
QString KGlobalBackgroundSettings::deskName(int desk)
1078
return m_Names[desk];
1083
void KGlobalBackgroundSettings::setDeskName(int desk, QString name)
1085
if (name == m_Names[desk])
1088
m_Names[desk] = name;
1093
void KGlobalBackgroundSettings::setCacheSize(int size)
1095
if (size == m_CacheSize)
1102
void KGlobalBackgroundSettings::setLimitCache(bool limit)
1104
if (limit == m_bLimitCache)
1107
m_bLimitCache = limit;
1111
bool KGlobalBackgroundSettings::drawBackgroundPerScreen(int desk) const
1113
if ( desk > int(m_bDrawBackgroundPerScreen.size()) )
1114
return _defDrawBackgroundPerScreen;
1115
return m_bDrawBackgroundPerScreen[desk];
1119
void KGlobalBackgroundSettings::setDrawBackgroundPerScreen(int desk, bool perScreen)
1121
if ( desk >= int(m_bDrawBackgroundPerScreen.size()) )
1124
if ( m_bDrawBackgroundPerScreen[desk] == perScreen )
1128
m_bDrawBackgroundPerScreen[desk] = perScreen;
1132
void KGlobalBackgroundSettings::setCommonScreenBackground(bool common)
1134
if (common == m_bCommonScreen)
1137
m_bCommonScreen = common;
1141
void KGlobalBackgroundSettings::setCommonDeskBackground(bool common)
1143
if (common == m_bCommonDesk)
1146
m_bCommonDesk = common;
1150
void KGlobalBackgroundSettings::setDockPanel(bool dock)
1152
if (dock == m_bDock)
1159
void KGlobalBackgroundSettings::setExportBackground(bool _export)
1161
if (_export == m_bExport)
1164
m_bExport = _export;
1167
void KGlobalBackgroundSettings::setTextColor(QColor _color)
1169
if (_color == m_TextColor)
1172
m_TextColor = _color;
1175
void KGlobalBackgroundSettings::setTextBackgroundColor(QColor _color)
1177
if (_color == m_TextBackgroundColor)
1180
m_TextBackgroundColor = _color;
1183
void KGlobalBackgroundSettings::setShadowEnabled(bool enabled)
1185
if (enabled == m_shadowEnabled)
1188
m_shadowEnabled = enabled;
1191
void KGlobalBackgroundSettings::setTextLines(int lines)
1193
if (lines == m_textLines)
1196
m_textLines = lines;
1199
void KGlobalBackgroundSettings::setTextWidth(int width)
1201
if (width == m_textWidth)
1204
m_textWidth = width;
1207
void KGlobalBackgroundSettings::readSettings()
1209
m_pConfig->setGroup("Background Common");
1210
m_bCommonScreen = m_pConfig->readBoolEntry("CommonScreen", _defCommonScreen);
1211
m_bCommonDesk = m_pConfig->readBoolEntry("CommonDesktop", _defCommonDesk);
1212
m_bDock = m_pConfig->readBoolEntry("Dock", _defDock);
1213
m_bExport = m_pConfig->readBoolEntry("Export", _defExport);
1214
m_bLimitCache = m_pConfig->readBoolEntry("LimitCache", _defLimitCache);
1215
m_CacheSize = m_pConfig->readNumEntry("CacheSize", _defCacheSize);
1218
NETRootInfo info( qt_xdisplay(), NET::DesktopNames | NET::NumberOfDesktops );
1219
m_bDrawBackgroundPerScreen.resize(info.numberOfDesktops());
1220
for ( int i = 0 ; i < info.numberOfDesktops() ; ++i )
1221
m_bDrawBackgroundPerScreen[i] = m_pConfig->readBoolEntry( QString("DrawBackgroundPerScreen_%1").arg(i), _defDrawBackgroundPerScreen );
1223
m_TextColor = KGlobalSettings::textColor();
1224
m_pConfig->setGroup("FMSettings");
1225
m_TextColor = m_pConfig->readColorEntry("NormalTextColor", &m_TextColor);
1226
m_TextBackgroundColor = m_pConfig->readColorEntry("ItemTextBackground");
1227
m_shadowEnabled = m_pConfig->readBoolEntry("ShadowEnabled", true);
1228
m_textLines = m_pConfig->readNumEntry("TextHeight", DEFAULT_TEXTHEIGHT);
1229
m_textWidth = m_pConfig->readNumEntry("TextWidth", DEFAULT_TEXTWIDTH);
1231
for ( int i = 0 ; i < info.numberOfDesktops() ; ++i )
1232
m_Names.append( QString::fromUtf8(info.desktopName(i+1)) );
1237
void KGlobalBackgroundSettings::writeSettings()
1242
m_pConfig->setGroup("Background Common");
1243
m_pConfig->writeEntry("CommonScreen", m_bCommonScreen);
1244
m_pConfig->writeEntry("CommonDesktop", m_bCommonDesk);
1245
m_pConfig->writeEntry("Dock", m_bDock);
1246
m_pConfig->writeEntry("Export", m_bExport);
1247
m_pConfig->writeEntry("LimitCache", m_bLimitCache);
1248
m_pConfig->writeEntry("CacheSize", m_CacheSize);
1250
for ( unsigned i = 0 ; i < m_bDrawBackgroundPerScreen.size() ; ++i )
1251
m_pConfig->writeEntry(QString("DrawBackgroundPerScreen_%1").arg(i), m_bDrawBackgroundPerScreen[i] );
1253
m_pConfig->setGroup("FMSettings");
1254
m_pConfig->writeEntry("NormalTextColor", m_TextColor);
1255
m_pConfig->writeEntry("ItemTextBackground", m_TextBackgroundColor);
1256
m_pConfig->writeEntry("ShadowEnabled", m_shadowEnabled);
1257
m_pConfig->writeEntry("TextHeight", m_textLines);
1258
m_pConfig->writeEntry("TextWidth", m_textWidth);
1263
// tell kdesktop to get it's butt in gear and pick up the new settings
1265
kapp->dcopClient()->send("kdesktop", "KDesktopIface", "configure()", data);