~ubuntu-branches/ubuntu/lucid/kdebase/lucid

« back to all changes in this revision

Viewing changes to kcontrol/background/bgsettings.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ana Beatriz Guerrero Lopez
  • Date: 2009-04-05 05:22:13 UTC
  • mfrom: (0.4.2 experimental) (0.2.2 upstream)
  • mto: This revision was merged to the branch mainline in revision 235.
  • Revision ID: james.westby@ubuntu.com-20090405052213-39thr4l6p2ss07uj
Tags: 4:4.2.2-1
* New upstream release:
  - khtml fixes. (Closes: #290285, #359680)
  - Default konsole sessions can be deleted. (Closes: #286342)
  - Tag widget uses standard application palette. (Closes: #444800)
  - ... and surely many more but we have lost track...

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* vi: ts=8 sts=4 sw=4
2
 
 * kate: space-indent on; indent-width 4; indent-mode cstyle;
3
 
 *
4
 
 * This file is part of the KDE project, module kdesktop.
5
 
 * Copyright (C) 1999 Geert Jansen <g.t.jansen@stud.tue.nl>
6
 
 *
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.
9
 
 */
10
 
 
11
 
#include <netwm.h>
12
 
#include <time.h>
13
 
#include <stdlib.h>
14
 
#include <unistd.h>
15
 
 
16
 
// Clean up after X.h/Xlib.h
17
 
#undef Bool
18
 
#undef Unsorted
19
 
 
20
 
#include <qdir.h>
21
 
#include <qpixmap.h>
22
 
 
23
 
#include <dcopclient.h>
24
 
#include <kapplication.h>
25
 
#include <kdebug.h>
26
 
#include <kglobalsettings.h>
27
 
#include <ksimpleconfig.h>
28
 
#include <kstandarddirs.h>
29
 
#include <krandomsequence.h>
30
 
#include <konq_defaults.h>
31
 
 
32
 
#include "bgdefaults.h"
33
 
#include "bghash.h"
34
 
#include "bgsettings.h"
35
 
 
36
 
 
37
 
/**** KBackgroundPattern ****/
38
 
 
39
 
 
40
 
KBackgroundPattern::KBackgroundPattern(QString name)
41
 
{
42
 
    dirty = false;
43
 
    hashdirty = true;
44
 
 
45
 
    m_pDirs = KGlobal::dirs();
46
 
    m_pDirs->addResourceType("dtop_pattern", m_pDirs->kde_default("data") +
47
 
                             "kdesktop/patterns");
48
 
    m_pConfig = 0L;
49
 
 
50
 
    m_Name = name;
51
 
    if (m_Name.isEmpty())
52
 
        return;
53
 
 
54
 
    init();
55
 
    readSettings();
56
 
}
57
 
 
58
 
 
59
 
KBackgroundPattern::~KBackgroundPattern()
60
 
{
61
 
    delete m_pConfig;
62
 
}
63
 
 
64
 
void KBackgroundPattern::copyConfig(const KBackgroundPattern *settings)
65
 
{
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;
71
 
}
72
 
 
73
 
void KBackgroundPattern::load(QString name)
74
 
{
75
 
    m_Name = name;
76
 
    init();
77
 
    readSettings();
78
 
}
79
 
 
80
 
 
81
 
void KBackgroundPattern::init(bool force_rw)
82
 
{
83
 
    delete m_pConfig;
84
 
 
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);
89
 
    } else
90
 
        m_pConfig = new KSimpleConfig(m_File);
91
 
 
92
 
    m_pConfig->setGroup("KDE Desktop Pattern");
93
 
 
94
 
    QFileInfo fi(m_File);
95
 
    m_bReadOnly = !fi.isWritable();
96
 
}
97
 
 
98
 
 
99
 
void KBackgroundPattern::setComment(const QString &comment)
100
 
{
101
 
    if (m_Comment == comment)
102
 
        return;
103
 
    dirty = true;
104
 
    m_Comment = comment;
105
 
}
106
 
 
107
 
 
108
 
void KBackgroundPattern::setPattern(QString pattern)
109
 
{
110
 
    if (m_Pattern == pattern)
111
 
        return;
112
 
    dirty = hashdirty = true;
113
 
    m_Pattern = pattern;
114
 
}
115
 
 
116
 
 
117
 
void KBackgroundPattern::readSettings()
118
 
{
119
 
    dirty = false;
120
 
    hashdirty = true;
121
 
 
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);
126
 
}
127
 
 
128
 
 
129
 
void KBackgroundPattern::writeSettings()
130
 
{
131
 
    if (!dirty)
132
 
        return;
133
 
    if (m_bReadOnly)
134
 
        init(true);
135
 
 
136
 
    if ( !m_pConfig )
137
 
        return; // better safe than sorry
138
 
 
139
 
    m_pConfig->writePathEntry("File", m_Pattern);
140
 
    m_pConfig->writeEntry("Comment", m_Comment);
141
 
    m_pConfig->sync();
142
 
    dirty = false;
143
 
}
144
 
 
145
 
 
146
 
bool KBackgroundPattern::isAvailable()
147
 
{
148
 
    if (m_Pattern.isEmpty())
149
 
       return false;
150
 
    QString file = m_Pattern;
151
 
    if (file.at(0) != '/')
152
 
        file = m_pDirs->findResource("dtop_pattern", file);
153
 
    QFileInfo fi(file);
154
 
    return (fi.exists());
155
 
}
156
 
 
157
 
 
158
 
bool KBackgroundPattern::remove()
159
 
{
160
 
    if (m_bReadOnly)
161
 
        return false;
162
 
    return !unlink(QFile::encodeName(m_File));
163
 
}
164
 
 
165
 
 
166
 
QString KBackgroundPattern::fingerprint()
167
 
{
168
 
    return m_File;
169
 
}
170
 
 
171
 
 
172
 
int KBackgroundPattern::hash()
173
 
{
174
 
    if (hashdirty) {
175
 
        m_Hash = QHash(fingerprint());
176
 
        hashdirty = false;
177
 
    }
178
 
    return m_Hash;
179
 
}
180
 
 
181
 
 
182
 
/* static */
183
 
QStringList KBackgroundPattern::list()
184
 
{
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",
189
 
                                             false, true);
190
 
    QStringList::Iterator it;
191
 
    for (it=lst.begin(); it!=lst.end(); ++it) {
192
 
        // Strip path and suffix
193
 
        int pos = (*it).findRev('/');
194
 
        if (pos != -1)
195
 
            (*it) = (*it).mid(pos+1);
196
 
        pos = (*it).findRev('.');
197
 
        if (pos != -1)
198
 
            (*it) = (*it).left(pos);
199
 
    }
200
 
    return lst;
201
 
}
202
 
 
203
 
 
204
 
/**** KBackgroundProgram ****/
205
 
 
206
 
 
207
 
KBackgroundProgram::KBackgroundProgram(QString name)
208
 
{
209
 
    dirty = false;
210
 
    hashdirty = true;
211
 
 
212
 
    m_pDirs = KGlobal::dirs();
213
 
    m_pDirs->addResourceType("dtop_program", m_pDirs->kde_default("data") +
214
 
                             "kdesktop/programs");
215
 
    m_pConfig = 0L;
216
 
 
217
 
    // prevent updates when just constructed.
218
 
    m_LastChange = (int) time(0L);
219
 
 
220
 
    m_Name = name;
221
 
    if (m_Name.isEmpty())
222
 
        return;
223
 
 
224
 
    init();
225
 
    readSettings();
226
 
}
227
 
 
228
 
 
229
 
KBackgroundProgram::~KBackgroundProgram()
230
 
{
231
 
    delete m_pConfig;
232
 
}
233
 
 
234
 
void KBackgroundProgram::copyConfig(const KBackgroundProgram *settings)
235
 
{
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;
245
 
}
246
 
 
247
 
 
248
 
void KBackgroundProgram::init(bool force_rw)
249
 
{
250
 
    delete m_pConfig;
251
 
 
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);
256
 
        m_bReadOnly = false;
257
 
    } else {
258
 
        m_pConfig = new KSimpleConfig(m_File);
259
 
        m_bReadOnly = (m_File != locateLocal("dtop_program", m_Name + ".desktop"));
260
 
    }
261
 
    m_pConfig->setGroup("KDE Desktop Program");
262
 
}
263
 
 
264
 
 
265
 
void KBackgroundProgram::load(const QString &name)
266
 
{
267
 
    m_Name = name;
268
 
    init();
269
 
    readSettings();
270
 
}
271
 
 
272
 
 
273
 
void KBackgroundProgram::setComment(const QString &comment)
274
 
{
275
 
    if (m_Comment == comment)
276
 
        return;
277
 
    dirty = true;
278
 
    m_Comment = comment;
279
 
}
280
 
 
281
 
 
282
 
void KBackgroundProgram::setExecutable(const QString &executable)
283
 
{
284
 
    if (m_Executable == executable)
285
 
        return;
286
 
    dirty = true;
287
 
    m_Executable = executable;
288
 
}
289
 
 
290
 
 
291
 
void KBackgroundProgram::setCommand(const QString &command)
292
 
{
293
 
    if (m_Command == command)
294
 
        return;
295
 
    dirty = hashdirty = true;
296
 
    m_Command = command;
297
 
}
298
 
 
299
 
 
300
 
void KBackgroundProgram::setPreviewCommand(const QString &command)
301
 
{
302
 
    if (m_PreviewCommand == command)
303
 
        return;
304
 
    dirty = true;
305
 
    m_PreviewCommand = command;
306
 
}
307
 
 
308
 
 
309
 
void KBackgroundProgram::setRefresh(int refresh)
310
 
{
311
 
    if (m_Refresh == refresh)
312
 
        return;
313
 
    dirty = hashdirty = true;
314
 
    m_Refresh = refresh;
315
 
}
316
 
 
317
 
 
318
 
void KBackgroundProgram::readSettings()
319
 
{
320
 
    dirty = false;
321
 
    hashdirty = true;
322
 
 
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);
328
 
}
329
 
 
330
 
 
331
 
void KBackgroundProgram::writeSettings()
332
 
{
333
 
    if (!dirty)
334
 
        return;
335
 
    if (m_bReadOnly)
336
 
        init(true);
337
 
 
338
 
    if ( !m_pConfig )
339
 
        return; // better safe than sorry
340
 
 
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);
346
 
    m_pConfig->sync();
347
 
    dirty = false;
348
 
}
349
 
 
350
 
 
351
 
bool KBackgroundProgram::isAvailable()
352
 
{
353
 
    return !m_pDirs->findExe(m_Executable).isEmpty();
354
 
}
355
 
 
356
 
 
357
 
bool KBackgroundProgram::remove()
358
 
{
359
 
    if (m_bReadOnly)
360
 
        return false;
361
 
    return !unlink(QFile::encodeName(m_File));
362
 
}
363
 
 
364
 
 
365
 
bool KBackgroundProgram::needUpdate()
366
 
{
367
 
    return (m_LastChange + 60*m_Refresh <= time(0L));
368
 
}
369
 
 
370
 
 
371
 
void KBackgroundProgram::update()
372
 
{
373
 
    m_LastChange = (int) time(0L);
374
 
}
375
 
 
376
 
 
377
 
QString KBackgroundProgram::fingerprint()
378
 
{
379
 
    return QString("co:%1;re:%2").arg(m_Command).arg(m_Refresh);
380
 
}
381
 
 
382
 
 
383
 
int KBackgroundProgram::hash()
384
 
{
385
 
    if (hashdirty) {
386
 
        m_Hash = QHash(fingerprint());
387
 
        hashdirty = false;
388
 
    }
389
 
    return m_Hash;
390
 
}
391
 
 
392
 
 
393
 
/* static */
394
 
QStringList KBackgroundProgram::list()
395
 
{
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",
400
 
                                             false, true);
401
 
    QStringList::Iterator it;
402
 
    for (it=lst.begin(); it!=lst.end(); ++it) {
403
 
        // Strip path and suffix
404
 
        int pos = (*it).findRev('/');
405
 
        if (pos != -1)
406
 
            (*it) = (*it).mid(pos+1);
407
 
        pos = (*it).findRev('.');
408
 
        if (pos != -1)
409
 
            (*it) = (*it).left(pos);
410
 
    }
411
 
    return lst;
412
 
}
413
 
 
414
 
 
415
 
/**** KBackgroundSettings ****/
416
 
 
417
 
 
418
 
KBackgroundSettings::KBackgroundSettings(int desk, int screen, bool drawBackgroundPerScreen, KConfig *config)
419
 
    : KBackgroundPattern(),
420
 
      KBackgroundProgram()
421
 
{
422
 
    dirty = false; hashdirty = true;
423
 
        m_bDrawBackgroundPerScreen = drawBackgroundPerScreen;
424
 
    m_Desk = desk;
425
 
    m_Screen = screen;
426
 
    m_bEnabled = true;
427
 
 
428
 
    // Default values.
429
 
    defColorA = _defColorA;
430
 
    defColorB = _defColorB;
431
 
    if (QPixmap::defaultDepth() > 8)
432
 
        defBackgroundMode = _defBackgroundMode;
433
 
    else
434
 
        defBackgroundMode = Flat;
435
 
    defWallpaperMode = _defWallpaperMode;
436
 
    defMultiMode = _defMultiMode;
437
 
    defBlendMode = _defBlendMode;
438
 
    defBlendBalance = _defBlendBalance;
439
 
    defReverseBlending = _defReverseBlending;
440
 
 
441
 
    m_MinOptimizationDepth = _defMinOptimizationDepth;
442
 
    m_bShm = _defShm;
443
 
 
444
 
    // Background modes
445
 
    #define ADD_STRING(ID) m_BMMap[#ID] = ID; m_BMRevMap[ID] = (char *) #ID;
446
 
    ADD_STRING(Flat)
447
 
    ADD_STRING(Pattern)
448
 
    ADD_STRING(Program)
449
 
    ADD_STRING(HorizontalGradient)
450
 
    ADD_STRING(VerticalGradient)
451
 
    ADD_STRING(PyramidGradient)
452
 
    ADD_STRING(PipeCrossGradient)
453
 
    ADD_STRING(EllipticGradient)
454
 
    #undef ADD_STRING
455
 
 
456
 
    // Blend modes
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)
469
 
    #undef ADD_STRING
470
 
 
471
 
    // Wallpaper modes
472
 
    #define ADD_STRING(ID) m_WMMap[#ID] = ID; m_WMRevMap[ID] = (char *) #ID;
473
 
    ADD_STRING(NoWallpaper)
474
 
    ADD_STRING(Centred)
475
 
    ADD_STRING(Tiled)
476
 
    ADD_STRING(CenterTiled)
477
 
    ADD_STRING(CentredMaxpect)
478
 
    ADD_STRING(TiledMaxpect)
479
 
    ADD_STRING(Scaled)
480
 
    ADD_STRING(CentredAutoFit)
481
 
    ADD_STRING(ScaleAndCrop)
482
 
    #undef ADD_STRING
483
 
 
484
 
    // Multiple wallpaper modes
485
 
    #define ADD_STRING(ID) m_MMMap[#ID] = ID; m_MMRevMap[ID] = (char *) #ID;
486
 
    ADD_STRING(NoMulti)
487
 
    ADD_STRING(InOrder)
488
 
    ADD_STRING(Random)
489
 
    ADD_STRING(NoMultiRandom)
490
 
    #undef ADD_STRING
491
 
 
492
 
    m_pDirs = KGlobal::dirs();
493
 
 
494
 
    if (!config) {
495
 
        int screen_number = 0;
496
 
        if (qt_xdisplay())
497
 
            screen_number = DefaultScreen(qt_xdisplay());
498
 
        QCString configname;
499
 
        if (screen_number == 0)
500
 
            configname = "kdesktoprc";
501
 
        else
502
 
            configname.sprintf("kdesktop-screen-%drc", screen_number);
503
 
 
504
 
        m_pConfig = new KConfig(configname, false, false);
505
 
        m_bDeleteConfig = true;
506
 
    } else {
507
 
        m_pConfig = config;
508
 
        m_bDeleteConfig = false;
509
 
    }
510
 
 
511
 
    if (m_Desk == -1)
512
 
        return;
513
 
 
514
 
    readSettings();
515
 
}
516
 
 
517
 
 
518
 
KBackgroundSettings::~KBackgroundSettings()
519
 
{
520
 
    if (m_bDeleteConfig)
521
 
        delete m_pConfig;
522
 
}
523
 
 
524
 
void KBackgroundSettings::copyConfig(const KBackgroundSettings *settings)
525
 
{
526
 
    dirty = true;
527
 
    hashdirty = true;
528
 
 
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;
534
 
 
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;
546
 
 
547
 
    KBackgroundPattern::copyConfig(settings);
548
 
    KBackgroundProgram::copyConfig(settings);
549
 
}
550
 
 
551
 
 
552
 
void KBackgroundSettings::load(int desk, int screen, bool drawBackgroundPerScreen, bool reparseConfig)
553
 
{
554
 
    m_Desk = desk;
555
 
    m_Screen = screen;  
556
 
    m_bDrawBackgroundPerScreen = drawBackgroundPerScreen;
557
 
    readSettings(reparseConfig);
558
 
}
559
 
 
560
 
 
561
 
void KBackgroundSettings::setColorA(const QColor& color)
562
 
{
563
 
    if (m_ColorA == color)
564
 
        return;
565
 
    dirty = hashdirty = true;
566
 
    m_ColorA = color;
567
 
}
568
 
 
569
 
 
570
 
void KBackgroundSettings::setColorB(const QColor& color)
571
 
{
572
 
    if (m_ColorB == color)
573
 
        return;
574
 
    dirty = hashdirty = true;
575
 
    m_ColorB = color;
576
 
}
577
 
 
578
 
 
579
 
void KBackgroundSettings::setPatternName(QString name)
580
 
{
581
 
    int ohash = KBackgroundPattern::hash();
582
 
    KBackgroundPattern::load(name);
583
 
    if (ohash == KBackgroundPattern::hash())
584
 
        return;
585
 
 
586
 
    dirty = hashdirty = true;
587
 
    return;
588
 
}
589
 
 
590
 
 
591
 
void KBackgroundSettings::setProgram(QString name)
592
 
{
593
 
    int ohash = KBackgroundProgram::hash();
594
 
    KBackgroundProgram::load(name);
595
 
    if (ohash == KBackgroundProgram::hash())
596
 
        return;
597
 
 
598
 
    dirty = hashdirty = true;
599
 
    return;
600
 
}
601
 
 
602
 
 
603
 
void KBackgroundSettings::setBackgroundMode(int mode)
604
 
{
605
 
    if (m_BackgroundMode == mode)
606
 
        return;
607
 
    dirty = hashdirty = true;
608
 
    m_BackgroundMode = mode;
609
 
}
610
 
 
611
 
void KBackgroundSettings::setBlendMode(int mode)
612
 
{
613
 
    if (m_BlendMode == mode)
614
 
        return;
615
 
    dirty = hashdirty = true;
616
 
    m_BlendMode = mode;
617
 
}
618
 
 
619
 
void KBackgroundSettings::setBlendBalance(int value)
620
 
{
621
 
    if (m_BlendBalance == value)
622
 
        return;
623
 
    dirty = hashdirty = true;
624
 
    m_BlendBalance = value;
625
 
}
626
 
 
627
 
void KBackgroundSettings::setReverseBlending(bool value)
628
 
{
629
 
    if (m_ReverseBlending == value)
630
 
        return;
631
 
    dirty = hashdirty = true;
632
 
    m_ReverseBlending = value;
633
 
}
634
 
 
635
 
 
636
 
void KBackgroundSettings::setWallpaper(QString wallpaper)
637
 
{
638
 
    dirty = hashdirty = true;
639
 
    m_Wallpaper = wallpaper;
640
 
}
641
 
 
642
 
 
643
 
void KBackgroundSettings::setWallpaperMode(int mode)
644
 
{
645
 
    if (m_WallpaperMode == mode)
646
 
        return;
647
 
    dirty = hashdirty = true;
648
 
    m_WallpaperMode = mode;
649
 
}
650
 
 
651
 
 
652
 
void KBackgroundSettings::setWallpaperList(QStringList list)
653
 
{
654
 
    KStandardDirs *d = KGlobal::dirs();
655
 
    if (m_WallpaperList == list)
656
 
        return;
657
 
 
658
 
    dirty = hashdirty = true;
659
 
    m_WallpaperList.clear();
660
 
    for(QStringList::ConstIterator it = list.begin();
661
 
        it != list.end(); ++it)
662
 
    {
663
 
       QString rpath = d->relativeLocation("wallpaper", *it);
664
 
       m_WallpaperList.append( !rpath.isEmpty() ? rpath : *it );
665
 
    }
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);
670
 
}
671
 
 
672
 
 
673
 
void KBackgroundSettings::setWallpaperChangeInterval(int interval)
674
 
{
675
 
    if (m_Interval == interval)
676
 
        return;
677
 
    dirty = hashdirty = true;
678
 
    m_Interval = interval;
679
 
}
680
 
 
681
 
 
682
 
void KBackgroundSettings::setMultiWallpaperMode(int mode)
683
 
{
684
 
    if (m_MultiMode == mode)
685
 
        return;
686
 
    dirty = hashdirty = true;
687
 
    m_MultiMode = mode;
688
 
    changeWallpaper(true);
689
 
}
690
 
 
691
 
 
692
 
void KBackgroundSettings::setMinOptimizationDepth(int mode)
693
 
{
694
 
    if (m_MinOptimizationDepth == mode)
695
 
        return;
696
 
    dirty = hashdirty = true;
697
 
    m_MinOptimizationDepth = mode;
698
 
}
699
 
 
700
 
bool KBackgroundSettings::optimize() const
701
 
{
702
 
    switch( m_MinOptimizationDepth )
703
 
        {
704
 
        case AlwaysOpt :
705
 
            return true;
706
 
        case Opt16bpp :
707
 
            return QPixmap::defaultDepth() >= 16;
708
 
        case Opt15bpp :
709
 
            return QPixmap::defaultDepth() >= 15;
710
 
        case NeverOpt :
711
 
        default :
712
 
            return false;
713
 
        }
714
 
}
715
 
 
716
 
void KBackgroundSettings::setUseShm(bool use)
717
 
{
718
 
    if (m_bShm == use)
719
 
        return;
720
 
    dirty = hashdirty = true;
721
 
    m_bShm = use;
722
 
}
723
 
 
724
 
QString KBackgroundSettings::configGroupName() const
725
 
{
726
 
    QString screenName;
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);
730
 
}
731
 
 
732
 
void KBackgroundSettings::readSettings(bool reparse)
733
 
{
734
 
    if (reparse)
735
 
        m_pConfig->reparseConfiguration();
736
 
 
737
 
    m_pConfig->setGroup(configGroupName());
738
 
 
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);
742
 
 
743
 
    QString s = m_pConfig->readPathEntry("Pattern");
744
 
    if (!s.isEmpty())
745
 
        KBackgroundPattern::load(s);
746
 
 
747
 
    s = m_pConfig->readPathEntry("Program");
748
 
    if (!s.isEmpty())
749
 
        KBackgroundProgram::load(s);
750
 
 
751
 
    m_BackgroundMode = defBackgroundMode;
752
 
    s = m_pConfig->readEntry("BackgroundMode", "invalid");
753
 
 
754
 
    if (m_BMMap.contains(s)) {
755
 
        int mode = m_BMMap[s];
756
 
        // consistency check
757
 
        if  ( ((mode != Pattern) && (mode != Program)) ||
758
 
              ((mode == Pattern) && !pattern().isEmpty()) ||
759
 
              ((mode == Program) && !command().isEmpty())
760
 
            )
761
 
            m_BackgroundMode = mode;
762
 
    }
763
 
 
764
 
    m_BlendMode = defBlendMode;
765
 
    s = m_pConfig->readEntry("BlendMode", "invalid");
766
 
    if (m_BlMMap.contains(s)) {
767
 
      m_BlendMode = m_BlMMap[s];
768
 
    }
769
 
 
770
 
    m_BlendBalance = defBlendBalance;
771
 
    int value = m_pConfig->readNumEntry( "BlendBalance", defBlendBalance);
772
 
    if (value > -201 && value < 201)
773
 
      m_BlendBalance = value;
774
 
 
775
 
    m_ReverseBlending = m_pConfig->readBoolEntry( "ReverseBlending", defReverseBlending);
776
 
 
777
 
    // Multiple wallpaper config
778
 
    m_WallpaperList = m_pConfig->readPathListEntry("WallpaperList");
779
 
 
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");
784
 
 
785
 
    m_MultiMode = defMultiMode;
786
 
    s = m_pConfig->readEntry("MultiWallpaperMode");
787
 
    if (m_MMMap.contains(s)) {
788
 
        int mode = m_MMMap[s];
789
 
        m_MultiMode = mode;
790
 
    }
791
 
 
792
 
    updateWallpaperFiles();
793
 
    if( !m_CurrentWallpaperName.isEmpty())
794
 
        m_CurrentWallpaper = m_WallpaperFiles.findIndex(m_CurrentWallpaperName);
795
 
    if(m_CurrentWallpaper < 0)
796
 
        m_CurrentWallpaper = 0;
797
 
 
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;
807
 
    }
808
 
 
809
 
    m_MinOptimizationDepth = m_pConfig->readNumEntry( "MinOptimizationDepth",
810
 
        _defMinOptimizationDepth );
811
 
    m_bShm = m_pConfig->readBoolEntry( "UseSHM", _defShm );
812
 
 
813
 
    dirty = reparse; hashdirty = true;
814
 
}
815
 
 
816
 
 
817
 
void KBackgroundSettings::writeSettings()
818
 
{
819
 
    KBackgroundPattern::writeSettings();
820
 
    KBackgroundProgram::writeSettings();
821
 
 
822
 
    if (!dirty)
823
 
        return;
824
 
 
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);
839
 
 
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);
845
 
 
846
 
    m_pConfig->sync();
847
 
 
848
 
    dirty = false;
849
 
}
850
 
 
851
 
/*
852
 
 * (re)Build m_WallpaperFiles from m_WallpaperList
853
 
 */
854
 
void KBackgroundSettings::updateWallpaperFiles()
855
 
{
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);
860
 
        if (file.isEmpty())
861
 
            continue;
862
 
        QFileInfo fi(file);
863
 
        if (!fi.exists())
864
 
            continue;
865
 
        if (fi.isFile() && fi.isReadable())
866
 
            m_WallpaperFiles.append(file);
867
 
        if (fi.isDir()) {
868
 
            QDir dir(file);
869
 
            QStringList lst = dir.entryList(QDir::Files | QDir::Readable);
870
 
            QStringList::Iterator it;
871
 
            for (it=lst.begin(); it!=lst.end(); ++it)
872
 
            {
873
 
                file = dir.absFilePath(*it);
874
 
                QFileInfo fi(file);
875
 
                if (fi.isFile() && fi.isReadable())
876
 
                    m_WallpaperFiles.append(file);
877
 
            }
878
 
        }
879
 
    }
880
 
 
881
 
   if (m_MultiMode == Random)
882
 
       randomizeWallpaperFiles();
883
 
}
884
 
 
885
 
// Randomize the m_WallpaperFiles in a non-repeating method.
886
 
void KBackgroundSettings::randomizeWallpaperFiles()
887
 
{
888
 
   if (m_WallpaperFiles.count() < 4)
889
 
      return;
890
 
 
891
 
   KRandomSequence rseq;
892
 
   QStringList tmpList = m_WallpaperFiles;
893
 
   QStringList randomList;
894
 
   randomList.append(tmpList.front());
895
 
   tmpList.pop_front();
896
 
   while(tmpList.count())
897
 
   {
898
 
      randomList.insert(randomList.at(
899
 
         rseq.getLong(randomList.count()+1)),
900
 
         1, tmpList.front());
901
 
 
902
 
      tmpList.pop_front();
903
 
   }
904
 
   m_WallpaperFiles = randomList;
905
 
}
906
 
 
907
 
QStringList KBackgroundSettings::wallpaperList() const
908
 
{
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;
914
 
}
915
 
 
916
 
QStringList KBackgroundSettings::wallpaperFiles() const
917
 
{
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;
923
 
}
924
 
 
925
 
/*
926
 
 * Select a new wallpaper from the list.
927
 
 */
928
 
void KBackgroundSettings::changeWallpaper(bool init)
929
 
{
930
 
    if (m_WallpaperFiles.count() == 0) {
931
 
        if( init ) {
932
 
            m_CurrentWallpaper = 0;
933
 
            m_CurrentWallpaperName = QString();
934
 
        }
935
 
        return;
936
 
    }
937
 
 
938
 
    switch (m_MultiMode) {
939
 
    case InOrder:
940
 
        m_CurrentWallpaper++;
941
 
        if (init || (m_CurrentWallpaper >= (int) m_WallpaperFiles.count()))
942
 
            m_CurrentWallpaper = 0;
943
 
        break;
944
 
 
945
 
    case Random:
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.
952
 
      }
953
 
        break;
954
 
    default:
955
 
        break;
956
 
    }
957
 
 
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);
964
 
    m_pConfig->sync();
965
 
 
966
 
    hashdirty = true;
967
 
}
968
 
 
969
 
 
970
 
QString KBackgroundSettings::currentWallpaper() const
971
 
{
972
 
    if ( m_WallpaperMode == NoWallpaper )
973
 
        return QString::null;
974
 
    if (m_MultiMode == NoMulti || m_MultiMode == NoMultiRandom)
975
 
        return m_Wallpaper;
976
 
 
977
 
    if (m_CurrentWallpaper >= 0 && m_CurrentWallpaper < (int) m_WallpaperFiles.count())
978
 
        return m_WallpaperFiles[m_CurrentWallpaper];
979
 
    return QString::null;
980
 
}
981
 
 
982
 
bool KBackgroundSettings::discardCurrentWallpaper()
983
 
{
984
 
    if (m_MultiMode == NoMulti || m_MultiMode == NoMultiRandom)
985
 
    {
986
 
       return false;
987
 
    }
988
 
    m_WallpaperFiles.remove(m_WallpaperFiles.at(m_CurrentWallpaper));
989
 
    --m_CurrentWallpaper;
990
 
    changeWallpaper();
991
 
 
992
 
    return true;
993
 
}
994
 
 
995
 
 
996
 
bool KBackgroundSettings::needWallpaperChange()
997
 
{
998
 
    if (m_MultiMode == NoMulti || m_MultiMode == NoMultiRandom)
999
 
        return false;
1000
 
 
1001
 
    return ((m_LastChange + 60*m_Interval) <= time(0L));
1002
 
}
1003
 
 
1004
 
 
1005
 
/*
1006
 
 * Create a fingerprint string for this config. Be somewhat (overly) carefull
1007
 
 * that only a different final result will give a different fingerprint.
1008
 
 */
1009
 
 
1010
 
QString KBackgroundSettings::fingerprint()
1011
 
{
1012
 
    QString s = QString("bm:%1;en:%2").arg(m_BackgroundMode).arg(m_bEnabled);
1013
 
    switch (m_BackgroundMode) {
1014
 
    case Flat:
1015
 
        s += QString("ca:%1;").arg(m_ColorA.rgb());
1016
 
        break;
1017
 
    case Program:
1018
 
        s += QString("pr:%1;").arg(KBackgroundProgram::hash());
1019
 
        break;
1020
 
    case Pattern:
1021
 
        s += QString("ca:%1;cb:%2;pt:%3;").arg(m_ColorA.rgb())
1022
 
             .arg(m_ColorB.rgb()).arg(KBackgroundPattern::hash());
1023
 
        break;
1024
 
    default:
1025
 
        s += QString("ca:%1;cb:%2;").arg(m_ColorA.rgb()).arg(m_ColorB.rgb());
1026
 
        break;
1027
 
    }
1028
 
 
1029
 
    s += QString("wm:%1;").arg(m_WallpaperMode);
1030
 
    if (m_WallpaperMode != NoWallpaper)
1031
 
    {
1032
 
        Q_UINT32 rh = KGlobal::dirs()->calcResourceHash("wallpaper", currentWallpaper(), false);
1033
 
        s += QString("wp:%2:%1;").arg(rh).arg(currentWallpaper());
1034
 
        
1035
 
    }
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));
1040
 
    }
1041
 
    s += QString::number( m_bShm );
1042
 
    s += QString::number( m_MinOptimizationDepth );
1043
 
 
1044
 
    return s;
1045
 
}
1046
 
 
1047
 
 
1048
 
int KBackgroundSettings::hash()
1049
 
{
1050
 
    if (hashdirty) {
1051
 
        m_Hash = QHash(fingerprint());
1052
 
        hashdirty = false;
1053
 
    }
1054
 
    return m_Hash;
1055
 
}
1056
 
 
1057
 
void KBackgroundSettings::setEnabled(const bool enable)
1058
 
{
1059
 
  if (m_bEnabled == enable)
1060
 
    return;
1061
 
 
1062
 
  m_bEnabled= enable;
1063
 
  hashdirty = true;
1064
 
}
1065
 
 
1066
 
/**** KGlobalBackgroundSettings ****/
1067
 
 
1068
 
KGlobalBackgroundSettings::KGlobalBackgroundSettings(KConfig *_config)
1069
 
{
1070
 
    m_pConfig = _config;
1071
 
 
1072
 
    readSettings();
1073
 
}
1074
 
 
1075
 
 
1076
 
QString KGlobalBackgroundSettings::deskName(int desk)
1077
 
{
1078
 
    return m_Names[desk];
1079
 
}
1080
 
 
1081
 
 
1082
 
/*
1083
 
void KGlobalBackgroundSettings::setDeskName(int desk, QString name)
1084
 
{
1085
 
    if (name == m_Names[desk])
1086
 
        return;
1087
 
    dirty = true;
1088
 
    m_Names[desk] = name;
1089
 
}
1090
 
*/
1091
 
 
1092
 
 
1093
 
void KGlobalBackgroundSettings::setCacheSize(int size)
1094
 
{
1095
 
    if (size == m_CacheSize)
1096
 
        return;
1097
 
    dirty = true;
1098
 
    m_CacheSize = size;
1099
 
}
1100
 
 
1101
 
 
1102
 
void KGlobalBackgroundSettings::setLimitCache(bool limit)
1103
 
{
1104
 
    if (limit == m_bLimitCache)
1105
 
        return;
1106
 
    dirty = true;
1107
 
    m_bLimitCache = limit;
1108
 
}
1109
 
 
1110
 
 
1111
 
bool KGlobalBackgroundSettings::drawBackgroundPerScreen(int desk) const
1112
 
{
1113
 
    if ( desk > int(m_bDrawBackgroundPerScreen.size()) )
1114
 
        return _defDrawBackgroundPerScreen;
1115
 
    return m_bDrawBackgroundPerScreen[desk];
1116
 
}
1117
 
 
1118
 
 
1119
 
void KGlobalBackgroundSettings::setDrawBackgroundPerScreen(int desk, bool perScreen)
1120
 
{
1121
 
    if ( desk >= int(m_bDrawBackgroundPerScreen.size()) )
1122
 
        return;
1123
 
    
1124
 
    if ( m_bDrawBackgroundPerScreen[desk] == perScreen )
1125
 
        return;
1126
 
    
1127
 
    dirty = true;
1128
 
    m_bDrawBackgroundPerScreen[desk] = perScreen;
1129
 
}
1130
 
 
1131
 
 
1132
 
void KGlobalBackgroundSettings::setCommonScreenBackground(bool common)
1133
 
{
1134
 
    if (common == m_bCommonScreen)
1135
 
        return;
1136
 
    dirty = true;
1137
 
    m_bCommonScreen = common;
1138
 
}
1139
 
 
1140
 
 
1141
 
void KGlobalBackgroundSettings::setCommonDeskBackground(bool common)
1142
 
{
1143
 
    if (common == m_bCommonDesk)
1144
 
        return;
1145
 
    dirty = true;
1146
 
    m_bCommonDesk = common;
1147
 
}
1148
 
 
1149
 
 
1150
 
void KGlobalBackgroundSettings::setDockPanel(bool dock)
1151
 
{
1152
 
    if (dock == m_bDock)
1153
 
        return;
1154
 
    dirty = true;
1155
 
    m_bDock = dock;
1156
 
}
1157
 
 
1158
 
 
1159
 
void KGlobalBackgroundSettings::setExportBackground(bool _export)
1160
 
{
1161
 
    if (_export == m_bExport)
1162
 
        return;
1163
 
    dirty = true;
1164
 
    m_bExport = _export;
1165
 
}
1166
 
 
1167
 
void KGlobalBackgroundSettings::setTextColor(QColor _color)
1168
 
{
1169
 
    if (_color == m_TextColor)
1170
 
        return;
1171
 
    dirty = true;
1172
 
    m_TextColor = _color;
1173
 
}
1174
 
 
1175
 
void KGlobalBackgroundSettings::setTextBackgroundColor(QColor _color)
1176
 
{
1177
 
    if (_color == m_TextBackgroundColor)
1178
 
        return;
1179
 
    dirty = true;
1180
 
    m_TextBackgroundColor = _color;
1181
 
}
1182
 
 
1183
 
void KGlobalBackgroundSettings::setShadowEnabled(bool enabled)
1184
 
{
1185
 
    if (enabled == m_shadowEnabled)
1186
 
        return;
1187
 
    dirty = true;
1188
 
    m_shadowEnabled = enabled;
1189
 
}
1190
 
 
1191
 
void KGlobalBackgroundSettings::setTextLines(int lines)
1192
 
{
1193
 
    if (lines == m_textLines)
1194
 
        return;
1195
 
    dirty = true;
1196
 
    m_textLines = lines;
1197
 
}
1198
 
 
1199
 
void KGlobalBackgroundSettings::setTextWidth(int width)
1200
 
{
1201
 
    if (width == m_textWidth)
1202
 
        return;
1203
 
    dirty = true;
1204
 
    m_textWidth = width;
1205
 
}
1206
 
 
1207
 
void KGlobalBackgroundSettings::readSettings()
1208
 
{
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);
1216
 
    
1217
 
    m_Names.clear();
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 );
1222
 
 
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);
1230
 
 
1231
 
    for ( int i = 0 ; i < info.numberOfDesktops() ; ++i )
1232
 
      m_Names.append( QString::fromUtf8(info.desktopName(i+1)) );
1233
 
 
1234
 
    dirty = false;
1235
 
}
1236
 
 
1237
 
void KGlobalBackgroundSettings::writeSettings()
1238
 
{
1239
 
    if (!dirty)
1240
 
        return;
1241
 
 
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);
1249
 
 
1250
 
    for ( unsigned i = 0 ; i < m_bDrawBackgroundPerScreen.size() ; ++i )
1251
 
        m_pConfig->writeEntry(QString("DrawBackgroundPerScreen_%1").arg(i), m_bDrawBackgroundPerScreen[i] );
1252
 
 
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);
1259
 
    
1260
 
    m_pConfig->sync();
1261
 
    dirty = false;
1262
 
 
1263
 
    // tell kdesktop to get it's butt in gear and pick up the new settings
1264
 
    QByteArray data;
1265
 
    kapp->dcopClient()->send("kdesktop", "KDesktopIface", "configure()", data);
1266
 
}
1267