1 /*****************************************************************************
2  *   Copyright 2003 - 2010 Craig Drummond <craig.p.drummond@gmail.com>       *
3  *   Copyright 2013 - 2015 Yichao Yu <yyc1992@gmail.com>                     *
4  *                                                                           *
5  *   This program is free software; you can redistribute it and/or modify    *
6  *   it under the terms of the GNU Lesser General Public License as          *
7  *   published by the Free Software Foundation; either version 2.1 of the    *
8  *   License, or (at your option) version 3, or any later version accepted   *
9  *   by the membership of KDE e.V. (or its successor approved by the         *
10  *   membership of KDE e.V.), which shall act as a proxy defined in          *
11  *   Section 6 of version 3 of the license.                                  *
12  *                                                                           *
13  *   This program is distributed in the hope that it will be useful,         *
14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       *
16  *   Lesser General Public License for more details.                         *
17  *                                                                           *
18  *   You should have received a copy of the GNU Lesser General Public        *
19  *   License along with this library. If not,                                *
20  *   see <http://www.gnu.org/licenses/>.                                     *
21  *****************************************************************************/
22 
23 #include <qtcurve-utils/dirs.h>
24 #include <qtcurve-utils/color.h>
25 #include "common.h"
26 #include "config_file.h"
27 
28 #include <qglobal.h>
29 #include <QMap>
30 #include <QFile>
31 #include <QTextStream>
32 #include <QSvgRenderer>
33 #include <QPainter>
34 #include <QDebug>
35 
36 //
37 // NB!
38 // This file is built twice (for targets kstyle_qtcurve5_config and qtcurve-qt5),
39 // and the CONFIG_WRITE and CONFIG_DIALOG tokens are likely to have different values
40 // each time.
41 //
42 
43 #define CONFIG_FILE "stylerc"
44 #define OLD_CONFIG_FILE "qtcurvestylerc"
45 #define VERSION_KEY "version"
46 
47 #define TO_LATIN1(A) A.toLatin1().constData()
48 static QString
determineFileName(const QString & file)49 determineFileName(const QString &file)
50 {
51     if (file.startsWith("/"))
52         return file;
53     return QtCurve::getConfDir() + file;
54 }
55 
c2h(char ch)56 static int c2h(char ch)
57 {
58     return ((ch >= '0' && ch <= '9') ? ch - '0' :
59             (ch >= 'a' && ch <= 'f') ? 10 + (ch - 'a') :
60             (ch >= 'A' && ch <= 'F') ? 10 + (ch - 'A') : 0);
61 }
62 
63 #define ATOH(str) ((c2h(*str) << 4) + c2h(*(str + 1)))
64 
65 void
qtcSetRgb(QColor * col,const char * str)66 qtcSetRgb(QColor *col, const char *str)
67 {
68     if (str && strlen(str) > 6) {
69         int offset = '#' == str[0] ? 1 : 0;
70         col->setRgb(ATOH(&str[offset]), ATOH(&str[offset + 2]),
71                     ATOH(&str[offset + 4]));
72     } else {
73         col->setRgb(0, 0, 0);
74     }
75 }
76 
77 static bool
loadImage(const QString & file,QtCPixmap * pixmap)78 loadImage(const QString &file, QtCPixmap *pixmap)
79 {
80     // Need to store filename for config dialog!
81     QString f(determineFileName(file));
82     pixmap->file = f;
83     return pixmap->img.load(f);
84 }
85 
86 static EDefBtnIndicator
toInd(const char * str,EDefBtnIndicator def)87 toInd(const char *str, EDefBtnIndicator def)
88 {
89     if (str && str[0]) {
90         if(0==strncmp(str, "fontcolor", 9) || 0==strncmp(str, "border", 6))
91             return IND_FONT_COLOR;
92         if(0==strncmp(str, "none", 4))
93             return IND_NONE;
94         if(0==strncmp(str, "corner", 6))
95             return IND_CORNER;
96         if(0==strncmp(str, "colored", 7))
97             return IND_COLORED;
98         if(0==strncmp(str, "tint", 4))
99             return IND_TINT;
100         if(0==strncmp(str, "glow", 4))
101             return IND_GLOW;
102         if(0==strncmp(str, "darken", 6))
103             return IND_DARKEN;
104         if(0==strncmp(str, "origselected", 12))
105             return IND_SELECTED;
106     }
107     return def;
108 }
109 
110 static ELine
toLine(const char * str,ELine def)111 toLine(const char *str, ELine def)
112 {
113     if (str && str[0]) {
114         if(0==strncmp(str, "dashes", 6))
115             return LINE_DASHES;
116         if(0==strncmp(str, "none", 4))
117             return LINE_NONE;
118         if(0==strncmp(str, "sunken", 6))
119             return LINE_SUNKEN;
120         if(0==strncmp(str, "dots", 4))
121             return LINE_DOTS;
122         if(0==strncmp(str, "flat", 4))
123             return LINE_FLAT;
124         if(0==strncmp(str, "1dot", 5))
125             return LINE_1DOT;
126     }
127     return def;
128 }
129 
130 static ETBarBorder
toTBarBorder(const char * str,ETBarBorder def)131 toTBarBorder(const char *str, ETBarBorder def)
132 {
133     if (str && str[0]) {
134         if(0==strncmp(str, "dark", 4))
135             return 0==strncmp(&str[4], "-all", 4) ? TB_DARK_ALL : TB_DARK;
136         if(0==strncmp(str, "none", 4))
137             return TB_NONE;
138         if(0==strncmp(str, "light", 5))
139             return 0==strncmp(&str[5], "-all", 4) ? TB_LIGHT_ALL : TB_LIGHT;
140     }
141     return def;
142 }
143 
144 static EMouseOver
toMouseOver(const char * str,EMouseOver def)145 toMouseOver(const char *str, EMouseOver def)
146 {
147     if (str && str[0]) {
148         if(0==strncmp(str, "true", 4) || 0==strncmp(str, "colored", 7))
149             return MO_COLORED;
150         if(0==strncmp(str, "thickcolored", 12))
151             return MO_COLORED_THICK;
152         if(0==strncmp(str, "plastik", 7))
153             return MO_PLASTIK;
154         if(0==strncmp(str, "glow", 4))
155             return MO_GLOW;
156         if(0==strncmp(str, "false", 4) || 0==strncmp(str, "none", 4))
157             return MO_NONE;
158     }
159     return def;
160 }
161 
162 static EAppearance
toAppearance(const char * str,EAppearance def,EAppAllow allow,QtCPixmap * pix,bool checkImage)163 toAppearance(const char *str, EAppearance def, EAppAllow allow,
164              QtCPixmap *pix, bool checkImage)
165 {
166     if (str && str[0]) {
167         if(0==strncmp(str, "flat", 4))
168             return APPEARANCE_FLAT;
169         if(0==strncmp(str, "raised", 6))
170             return APPEARANCE_RAISED;
171         if(0==strncmp(str, "dullglass", 9))
172             return APPEARANCE_DULL_GLASS;
173         if(0==strncmp(str, "glass", 5) || 0==strncmp(str, "shinyglass", 10))
174             return APPEARANCE_SHINY_GLASS;
175         if(0==strncmp(str, "agua", 4))
176             return APPEARANCE_AGUA;
177         if(0==strncmp(str, "soft", 4))
178             return APPEARANCE_SOFT_GRADIENT;
179         if(0==strncmp(str, "gradient", 8) || 0==strncmp(str, "lightgradient", 13))
180             return APPEARANCE_GRADIENT;
181         if(0==strncmp(str, "harsh", 5))
182             return APPEARANCE_HARSH_GRADIENT;
183         if(0==strncmp(str, "inverted", 8))
184             return APPEARANCE_INVERTED;
185         if(0==strncmp(str, "darkinverted", 12))
186             return APPEARANCE_DARK_INVERTED;
187         if(0==strncmp(str, "splitgradient", 13))
188             return APPEARANCE_SPLIT_GRADIENT;
189         if(0==strncmp(str, "bevelled", 8))
190             return APPEARANCE_BEVELLED;
191         if(APP_ALLOW_FADE==allow && 0==strncmp(str, "fade", 4))
192             return APPEARANCE_FADE;
193         if(APP_ALLOW_STRIPED==allow && 0==strncmp(str, "striped", 7))
194             return APPEARANCE_STRIPED;
195         if(APP_ALLOW_NONE==allow && 0==strncmp(str, "none", 4))
196             return APPEARANCE_NONE;
197         if (pix && APP_ALLOW_STRIPED==allow && 0==strncmp(str, "file", 4) && strlen(str)>9)
198             return loadImage(&str[5], pix) || !checkImage ? APPEARANCE_FILE : def;
199 
200         if(0==strncmp(str, "customgradient", 14) && strlen(str)>14)
201         {
202             int i=atoi(&str[14]);
203 
204             i--;
205             if(i>=0 && i<NUM_CUSTOM_GRAD)
206                 return (EAppearance)(APPEARANCE_CUSTOM1+i);
207         }
208     }
209     return def;
210 }
211 
212 static EShade
toShade(const char * str,bool allowMenu,EShade def,bool menuShade,QColor * col)213 toShade(const char *str, bool allowMenu, EShade def,
214         bool menuShade, QColor *col)
215 {
216     if (str && str[0]) {
217         /* true/false is from 0.25... */
218         if((!menuShade && 0==strncmp(str, "true", 4)) || 0==strncmp(str, "selected", 8))
219             return SHADE_BLEND_SELECTED;
220         if(0==strncmp(str, "origselected", 12))
221             return SHADE_SELECTED;
222         if(allowMenu && (0==strncmp(str, "darken", 6) || (menuShade && 0==strncmp(str, "true", 4))))
223             return SHADE_DARKEN;
224         if(allowMenu && 0==strncmp(str, "wborder", 7))
225             return SHADE_WINDOW_BORDER;
226         if(0==strncmp(str, "custom", 6))
227             return SHADE_CUSTOM;
228         if('#'==str[0] && col)
229         {
230             qtcSetRgb(col, str);
231             return SHADE_CUSTOM;
232         }
233         if(0==strncmp(str, "none", 4))
234             return SHADE_NONE;
235     }
236 
237     return def;
238 }
239 
240 /* Prior to 0.42 round was a bool - so need to read 'false' as 'none' */
241 static ERound
toRound(const char * str,ERound def)242 toRound(const char *str, ERound def)
243 {
244     if (str && str[0]) {
245         if(0==strncmp(str, "none", 4) || 0==strncmp(str, "false", 5))
246             return ROUND_NONE;
247         if(0==strncmp(str, "slight", 6))
248             return ROUND_SLIGHT;
249         if(0==strncmp(str, "full", 4))
250             return ROUND_FULL;
251         if(0==strncmp(str, "extra", 5))
252             return ROUND_EXTRA;
253         if(0==strncmp(str, "max", 3))
254             return ROUND_MAX;
255     }
256     return def;
257 }
258 
259 static EScrollbar
toScrollbar(const char * str,EScrollbar def)260 toScrollbar(const char *str, EScrollbar def)
261 {
262     return QtCurve::Config::loadValue<EScrollbar>(str, def);
263 }
264 
265 static EFrame
toFrame(const char * str,EFrame def)266 toFrame(const char *str, EFrame def)
267 {
268     return QtCurve::Config::loadValue<EFrame>(str, def);
269 }
270 
271 static EEffect
toEffect(const char * str,EEffect def)272 toEffect(const char *str, EEffect def)
273 {
274     if (str && str[0]) {
275         if(0==strncmp(str, "none", 4))
276             return EFFECT_NONE;
277         if(0==strncmp(str, "shadow", 6))
278             return EFFECT_SHADOW;
279         if(0==strncmp(str, "etch", 4))
280             return EFFECT_ETCH;
281     }
282 
283     return def;
284 }
285 
286 static Shading
toShading(const char * str,Shading def)287 toShading(const char *str, Shading def)
288 {
289     return QtCurve::Config::loadValue<Shading>(str, def);
290 }
291 
292 static EStripe
toStripe(const char * str,EStripe def)293 toStripe(const char *str, EStripe def)
294 {
295     if (str && str[0]) {
296         if(0==strncmp(str, "plain", 5) || 0==strncmp(str, "true", 4))
297             return STRIPE_PLAIN;
298         if(0==strncmp(str, "none", 4) || 0==strncmp(str, "false", 5))
299             return STRIPE_NONE;
300         if(0==strncmp(str, "diagonal", 8))
301             return STRIPE_DIAGONAL;
302         if(0==strncmp(str, "fade", 4))
303             return STRIPE_FADE;
304     }
305 
306     return def;
307 }
308 
toSlider(const char * str,ESliderStyle def)309 static ESliderStyle toSlider(const char *str, ESliderStyle def)
310 {
311     if(str && 0!=str[0])
312     {
313         if(0==strncmp(str, "round", 5))
314             return SLIDER_ROUND;
315         if(0==strncmp(str, "plain", 5))
316             return SLIDER_PLAIN;
317         if(0==strncmp(str, "r-round", 7))
318             return SLIDER_ROUND_ROTATED;
319         if(0==strncmp(str, "r-plain", 7))
320             return SLIDER_PLAIN_ROTATED;
321         if(0==strncmp(str, "triangular", 10))
322             return SLIDER_TRIANGULAR;
323         if(0==strncmp(str, "circular", 8))
324             return SLIDER_CIRCULAR;
325     }
326 
327     return def;
328 }
329 
toEColor(const char * str,EColor def)330 static EColor toEColor(const char *str, EColor def)
331 {
332     if(str && 0!=str[0])
333     {
334         if(0==strncmp(str, "base", 4))
335             return ECOLOR_BASE;
336         if(0==strncmp(str, "dark", 4))
337             return ECOLOR_DARK;
338         if(0==strncmp(str, "background", 10))
339             return ECOLOR_BACKGROUND;
340     }
341 
342     return def;
343 }
344 
toFocus(const char * str,EFocus def)345 static EFocus toFocus(const char *str, EFocus def)
346 {
347     if(str && 0!=str[0])
348     {
349         if(0==strncmp(str, "standard", 8))
350             return FOCUS_STANDARD;
351         if(0==strncmp(str, "rect", 4) || 0==strncmp(str, "highlight", 9))
352             return FOCUS_RECTANGLE;
353         if(0==strncmp(str, "filled", 6))
354             return FOCUS_FILLED;
355         if(0==strncmp(str, "full", 4))
356             return FOCUS_FULL;
357         if(0==strncmp(str, "line", 4))
358             return FOCUS_LINE;
359         if(0==strncmp(str, "glow", 4))
360             return FOCUS_GLOW;
361         if(0==strncmp(str, "none", 4))
362             return FOCUS_NONE;
363     }
364 
365     return def;
366 }
367 
toTabMo(const char * str,ETabMo def)368 static ETabMo toTabMo(const char *str, ETabMo def)
369 {
370     if(str && 0!=str[0])
371     {
372         if(0==strncmp(str, "top", 3))
373             return TAB_MO_TOP;
374         if(0==strncmp(str, "bot", 3))
375             return TAB_MO_BOTTOM;
376         if(0==strncmp(str, "glow", 4))
377             return TAB_MO_GLOW;
378     }
379 
380     return def;
381 }
382 
toGradType(const char * str,EGradType def)383 static EGradType toGradType(const char *str, EGradType def)
384 {
385     if(str && 0!=str[0])
386     {
387         if(0==strncmp(str, "horiz", 5))
388             return GT_HORIZ;
389         if(0==strncmp(str, "vert", 4))
390             return GT_VERT;
391     }
392     return def;
393 }
394 
toLvLines(const char * str,bool def)395 static bool toLvLines(const char *str, bool def)
396 {
397     if(str && 0!=str[0])
398     {
399 #if 0
400         if(0==strncmp(str, "true", 4) || 0==strncmp(str, "new", 3))
401             return LV_NEW;
402         if(0==strncmp(str, "old", 3))
403             return LV_OLD;
404         if(0==strncmp(str, "false", 5) || 0==strncmp(str, "none", 4))
405             return LV_NONE;
406 #else
407         return 0!=strncmp(str, "false", 5);
408 #endif
409     }
410     return def;
411 }
412 
toGradientBorder(const char * str,bool * haveAlpha)413 static EGradientBorder toGradientBorder(const char *str, bool *haveAlpha)
414 {
415     if (str && str[0]) {
416         *haveAlpha = strstr(str, "-alpha") ? true : false;
417         if(0==strncmp(str, "light", 5) || 0==strncmp(str, "true", 4))
418             return GB_LIGHT;
419         if(0==strncmp(str, "none", 4))
420             return GB_NONE;
421         if(0==strncmp(str, "3dfull", 6))
422             return GB_3D_FULL;
423         if(0==strncmp(str, "3d", 2) || 0==strncmp(str, "false", 5))
424             return GB_3D;
425         if(0==strncmp(str, "shine", 5))
426             return GB_SHINE;
427     }
428     return GB_3D;
429 }
430 
toAlign(const char * str,EAlign def)431 static EAlign toAlign(const char *str, EAlign def)
432 {
433     if(str && 0!=str[0])
434     {
435         if(0==strncmp(str, "left", 4))
436             return ALIGN_LEFT;
437         if(0==strncmp(str, "center-full", 11))
438             return ALIGN_FULL_CENTER;
439         if(0==strncmp(str, "center", 6))
440             return ALIGN_CENTER;
441         if(0==strncmp(str, "right", 5))
442             return ALIGN_RIGHT;
443     }
444     return def;
445 }
446 
toTitlebarIcon(const char * str,ETitleBarIcon def)447 static ETitleBarIcon toTitlebarIcon(const char *str, ETitleBarIcon def)
448 {
449     if(str && 0!=str[0])
450     {
451         if(0==strncmp(str, "none", 4))
452             return TITLEBAR_ICON_NONE;
453         if(0==strncmp(str, "menu", 4))
454             return TITLEBAR_ICON_MENU_BUTTON;
455         if(0==strncmp(str, "title", 5))
456             return TITLEBAR_ICON_NEXT_TO_TITLE;
457     }
458     return def;
459 }
460 
toImageType(const char * str,EImageType def)461 static EImageType toImageType(const char *str, EImageType def)
462 {
463     if(str && 0!=str[0])
464     {
465         if(0==strncmp(str, "none", 4))
466             return IMG_NONE;
467         if(0==strncmp(str, "plainrings", 10))
468             return IMG_PLAIN_RINGS;
469         if(0==strncmp(str, "rings", 5))
470             return IMG_BORDERED_RINGS;
471         if(0==strncmp(str, "squarerings", 11))
472             return IMG_SQUARE_RINGS;
473         if(0==strncmp(str, "file", 4))
474             return IMG_FILE;
475     }
476     return def;
477 }
478 
toGlow(const char * str,EGlow def)479 static EGlow toGlow(const char *str, EGlow def)
480 {
481     if(str && 0!=str[0])
482     {
483         if(0==strncmp(str, "none", 4))
484             return GLOW_NONE;
485         if(0==strncmp(str, "start", 5))
486             return GLOW_START;
487         if(0==strncmp(str, "middle", 6))
488             return GLOW_MIDDLE;
489         if(0==strncmp(str, "end", 3))
490             return GLOW_END;
491     }
492     return def;
493 }
494 
toTBarBtn(const char * str,ETBarBtn def)495 static ETBarBtn toTBarBtn(const char *str, ETBarBtn def)
496 {
497     if(str && 0!=str[0])
498     {
499         if(0==strncmp(str, "standard", 8))
500             return TBTN_STANDARD;
501         if(0==strncmp(str, "raised", 6))
502             return TBTN_RAISED;
503         if(0==strncmp(str, "joined", 6))
504             return TBTN_JOINED;
505     }
506     return def;
507 }
508 
qtcGetWindowBorderSize(bool force)509 WindowBorders qtcGetWindowBorderSize(bool force)
510 {
511     static WindowBorders def={24, 18, 4, 4};
512     static WindowBorders sizes={-1, -1, -1, -1};
513 
514     if(-1==sizes.titleHeight || force)
515     {
516         QFile f(QtCurve::getConfDir()+QString(BORDER_SIZE_FILE));
517 
518         if(f.open(QIODevice::ReadOnly)) {
519             QTextStream stream(&f);
520             QString     line;
521 
522             sizes.titleHeight=stream.readLine().toInt();
523             sizes.toolTitleHeight=stream.readLine().toInt();
524             sizes.bottom=stream.readLine().toInt();
525             sizes.sides=stream.readLine().toInt();
526             f.close();
527         }
528     }
529 
530     return sizes.titleHeight<12 ? def : sizes;
531 }
532 
533 #ifndef CONFIG_DIALOG
534 
qtcBarHidden(const QString & app,const char * prefix)535 bool qtcBarHidden(const QString &app, const char *prefix)
536 {
537     return QFile::exists(QFile::decodeName(QtCurve::getConfDir())+prefix+app);
538 }
539 
qtcSetBarHidden(const QString & app,bool hidden,const char * prefix)540 void qtcSetBarHidden(const QString &app, bool hidden, const char *prefix)
541 {
542     if(!hidden)
543         QFile::remove(QFile::decodeName(QtCurve::getConfDir())+prefix+app);
544     else
545         QFile(QFile::decodeName(QtCurve::getConfDir())+prefix+app).open(QIODevice::WriteOnly);
546 }
547 
qtcLoadBgndImage(QtCImage * img)548 void qtcLoadBgndImage(QtCImage *img)
549 {
550     if(!img->loaded &&
551         ( (img->width>16 && img->width<1024 && img->height>16 && img->height<1024) || (0==img->width && 0==img->height)) )
552     {
553         img->loaded=true;
554         img->pixmap.img=QPixmap();
555         QString file(determineFileName(img->pixmap.file));
556 
557         if(!file.isEmpty())
558         {
559             bool loaded=false;
560             if(0!=img->width && (file.endsWith(".svg", Qt::CaseInsensitive) || file.endsWith(".svgz", Qt::CaseInsensitive)))
561             {
562                 QSvgRenderer svg(file);
563 
564                 if(svg.isValid())
565                 {
566                     img->pixmap.img=QPixmap(img->width, img->height);
567                     img->pixmap.img.fill(Qt::transparent);
568                     QPainter painter(&img->pixmap.img);
569                     svg.render(&painter);
570                     painter.end();
571                     loaded=true;
572                 }
573             }
574             if(!loaded && img->pixmap.img.load(file) && 0!=img->width &&
575                (img->pixmap.img.height()!=img->height || img->pixmap.img.width()!=img->width))
576                 img->pixmap.img=img->pixmap.img.scaled(img->width, img->height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
577         }
578     }
579 }
580 
581 #endif
582 
583 static void
checkColor(EShade * s,QColor * c)584 checkColor(EShade *s, QColor *c)
585 {
586     if (*s == SHADE_CUSTOM && QtCurve::isBlack(*c)) {
587         *s = SHADE_NONE;
588     }
589 }
590 
591 class QtCConfig {
592 public:
593     QtCConfig(const QString &filename);
594 
ok() const595     bool ok() const {return values.count() > 0;}
hasKey(const QString & key)596     bool hasKey(const QString &key) {return values.contains(key);}
597     QString readEntry(const QString &key, const QString &def=QString::null);
598 private:
599     QMap<QString, QString> values;
600 };
601 
QtCConfig(const QString & filename)602 QtCConfig::QtCConfig(const QString &filename)
603 {
604     QFile f(filename);
605 
606     if (f.open(QIODevice::ReadOnly)) {
607         QTextStream stream(&f);
608         QString     line;
609 
610         while(!stream.atEnd())
611         {
612             line = stream.readLine();
613             int pos=line.indexOf('=');
614             if(-1!=pos)
615                 values[line.left(pos)]=line.mid(pos+1);
616         }
617         f.close();
618     }
619 }
620 
621 inline QString
readEntry(const QString & key,const QString & def)622 QtCConfig::readEntry(const QString &key, const QString &def)
623 {
624     return values.contains(key) ? values[key] : def;
625 }
626 
readStringEntry(QtCConfig & cfg,const QString & key)627 inline QString readStringEntry(QtCConfig &cfg, const QString &key)
628 {
629     return cfg.readEntry(key);
630 }
631 
readNumEntry(QtCConfig & cfg,const QString & key,int def)632 static int readNumEntry(QtCConfig &cfg, const QString &key, int def)
633 {
634     const QString &val(readStringEntry(cfg, key));
635 
636     return val.isEmpty() ? def : val.toInt();
637 }
638 
readVersionEntry(QtCConfig & cfg,const QString & key)639 static int readVersionEntry(QtCConfig &cfg, const QString &key)
640 {
641     const QString &val(readStringEntry(cfg, key));
642     int           major, minor, patch;
643 
644     return !val.isEmpty() && 3==sscanf(TO_LATIN1(val), "%d.%d.%d", &major, &minor, &patch)
645             ? qtcMakeVersion(major, minor, patch)
646             : 0;
647 }
648 
readBoolEntry(QtCConfig & cfg,const QString & key,bool def)649 static bool readBoolEntry(QtCConfig &cfg, const QString &key, bool def)
650 {
651     const QString &val(readStringEntry(cfg, key));
652 
653     return val.isEmpty() ? def : (val==QLatin1String("true") ? true : false);
654 }
655 
readDoubleList(QtCConfig & cfg,const char * key,double * list,int count)656 static void readDoubleList(QtCConfig &cfg, const char *key, double *list, int count)
657 {
658     QStringList strings(readStringEntry(cfg, key).split(',', QString::SkipEmptyParts));
659     bool ok(count==strings.size());
660 
661     if(ok)
662     {
663         QStringList::ConstIterator it(strings.begin());
664         int                        i;
665 
666         for(i=0; i<count && ok; ++i, ++it)
667             list[i]=(*it).toDouble(&ok);
668     }
669 
670     if(!ok && strings.size())
671         list[0]=0;
672 }
673 
674 #define CFG_READ_COLOR(ENTRY) do {                      \
675         QString sVal(cfg.readEntry(#ENTRY));            \
676         if (sVal.isEmpty()) {                           \
677             opts->ENTRY = def->ENTRY;                   \
678         } else {                                        \
679             qtcSetRgb(&opts->ENTRY, TO_LATIN1(sVal));   \
680         }                                               \
681     } while (0)
682 
683 #define CFG_READ_IMAGE(ENTRY) do {                                      \
684         opts->ENTRY.type =                                              \
685             toImageType(TO_LATIN1(readStringEntry(cfg, #ENTRY)),        \
686                         def->ENTRY.type);                               \
687         opts->ENTRY.loaded = false;                                     \
688         opts->ENTRY.width = opts->ENTRY.height = 0;                     \
689         opts->ENTRY.onBorder = false;                                   \
690         opts->ENTRY.pos = PP_TR;                                        \
691         if (opts->ENTRY.type == IMG_FILE) {                             \
692             QString file(cfg.readEntry(#ENTRY ".file"));                \
693             if (!file.isEmpty()) {                                      \
694                 opts->ENTRY.pixmap.file = file;                         \
695                 opts->ENTRY.width = readNumEntry(cfg, #ENTRY ".width", 0); \
696                 opts->ENTRY.height = readNumEntry(cfg, #ENTRY ".height", 0); \
697                 opts->ENTRY.onBorder = readBoolEntry(cfg, #ENTRY ".onBorder", \
698                                                      false);            \
699                 opts->ENTRY.pos = (EPixPos)readNumEntry(cfg, #ENTRY ".pos", \
700                                                         (int)PP_TR);    \
701             } else {                                                    \
702                 opts->ENTRY.type = IMG_NONE;                            \
703             }                                                           \
704         }                                                               \
705     } while (0)
706 
707 #define CFG_READ_STRING_LIST(ENTRY) do {                                \
708         QString val = readStringEntry(cfg, #ENTRY);                     \
709         Strings set = val.isEmpty() ? Strings() :                       \
710             Strings::fromList(val.split(",", QString::SkipEmptyParts)); \
711         opts->ENTRY = set.count() || cfg.hasKey(#ENTRY) ? set : def->ENTRY; \
712     } while (0)
713 
714 #define CFG_READ_BOOL(ENTRY) do {                               \
715         opts->ENTRY = readBoolEntry(cfg, #ENTRY, def->ENTRY);   \
716     } while (0)
717 
718 #define CFG_READ_ROUND(ENTRY) do {                                      \
719         opts->ENTRY = toRound(TO_LATIN1(readStringEntry(cfg, #ENTRY)),  \
720                               def->ENTRY);                              \
721     } while (0)
722 
723 #define CFG_READ_INT(ENTRY) do {                                \
724         opts->ENTRY = readNumEntry(cfg, #ENTRY, def->ENTRY);    \
725     } while (0)
726 
727 #define CFG_READ_INT_BOOL(ENTRY, DEF) do {                              \
728         if (readBoolEntry(cfg, #ENTRY, false)) {                        \
729             opts->ENTRY = DEF;                                          \
730         } else {                                                        \
731             opts->ENTRY = readNumEntry(cfg, #ENTRY, def->ENTRY);        \
732         }                                                               \
733     } while (0)
734 
735 #define CFG_READ_TB_BORDER(ENTRY) do {                                  \
736         opts->ENTRY = toTBarBorder(TO_LATIN1(readStringEntry(cfg, #ENTRY)), \
737                                    def->ENTRY);                         \
738     } while (0)
739 
740 #define CFG_READ_MOUSE_OVER(ENTRY) do {                                 \
741         opts->ENTRY = toMouseOver(TO_LATIN1(readStringEntry(cfg, #ENTRY)), \
742                                   def->ENTRY);                          \
743     } while (0)
744 
745 #define CFG_READ_APPEARANCE(ENTRY, ALLOW) do {                          \
746         opts->ENTRY = toAppearance(TO_LATIN1(readStringEntry(cfg, #ENTRY)), \
747                                    def->ENTRY, ALLOW, nullptr, false);     \
748     } while (0)
749 
750 #define CFG_READ_APPEARANCE_PIXMAP(ENTRY, ALLOW, PIXMAP, CHECK) do {    \
751         opts->ENTRY = toAppearance(TO_LATIN1(readStringEntry(cfg, #ENTRY)), \
752                                    def->ENTRY, ALLOW, PIXMAP, CHECK);   \
753     } while (0)
754 
755 #define CFG_READ_STRIPE(ENTRY) do {                                     \
756         opts->ENTRY=toStripe(TO_LATIN1(readStringEntry(cfg, #ENTRY)),   \
757                              def->ENTRY);                               \
758     } while (0)
759 
760 #define CFG_READ_SLIDER(ENTRY) do {                                     \
761         opts->ENTRY = toSlider(TO_LATIN1(readStringEntry(cfg, #ENTRY)), \
762                              def->ENTRY);                               \
763     } while (0)
764 
765 #define CFG_READ_DEF_BTN(ENTRY) do {                                    \
766         opts->ENTRY = toInd(TO_LATIN1(readStringEntry(cfg, #ENTRY)),    \
767                             def->ENTRY);                                \
768     } while (0)
769 
770 #define CFG_READ_LINE(ENTRY) do {                                       \
771         opts->ENTRY = toLine(TO_LATIN1(readStringEntry(cfg, #ENTRY)),   \
772                              def->ENTRY);                               \
773     } while (0)
774 
775 #define CFG_READ_SHADE(ENTRY, AD, MENU_STRIPE, COL) do {                \
776         opts->ENTRY = toShade(TO_LATIN1(readStringEntry(cfg, #ENTRY)), AD, \
777                               def->ENTRY, MENU_STRIPE, COL);            \
778     } while (0)
779 
780 #define CFG_READ_SCROLLBAR(ENTRY) do {                                  \
781         opts->ENTRY = toScrollbar(TO_LATIN1(readStringEntry(cfg, #ENTRY)), \
782                                   def->ENTRY);                          \
783     } while (0)
784 
785 #define CFG_READ_FRAME(ENTRY) do {                                      \
786         opts->ENTRY = toFrame(TO_LATIN1(readStringEntry(cfg, #ENTRY)),  \
787                               def->ENTRY);                              \
788     } while (0)
789 
790 #define CFG_READ_EFFECT(ENTRY) do {                                     \
791         opts->ENTRY = toEffect(TO_LATIN1(readStringEntry(cfg, #ENTRY)), \
792                                def->ENTRY);                             \
793     } while (0)
794 
795 #define CFG_READ_SHADING(ENTRY) do {                                    \
796         opts->ENTRY = toShading(TO_LATIN1(readStringEntry(cfg, #ENTRY)), \
797                                 def->ENTRY);                            \
798     } while (0)
799 
800 #define CFG_READ_ECOLOR(ENTRY) do {                                     \
801         opts->ENTRY = toEColor(TO_LATIN1(readStringEntry(cfg, #ENTRY)), \
802                                def->ENTRY);                             \
803     } while (0)
804 
805 #define CFG_READ_FOCUS(ENTRY) do {                                      \
806         opts->ENTRY = toFocus(TO_LATIN1(readStringEntry(cfg, #ENTRY)),  \
807                               def->ENTRY);                              \
808     } while (0)
809 
810 #define CFG_READ_TAB_MO(ENTRY) do {                                     \
811         opts->ENTRY = toTabMo(TO_LATIN1(readStringEntry(cfg, #ENTRY)),  \
812                               def->ENTRY);                              \
813     } while (0)
814 
815 #define CFG_READ_GRAD_TYPE(ENTRY) do {                                  \
816         opts->ENTRY = toGradType(TO_LATIN1(readStringEntry(cfg, #ENTRY)), \
817                                  def->ENTRY);                           \
818     } while (0)
819 
820 #define CFG_READ_LV_LINES(ENTRY) do {                                   \
821         opts->ENTRY = toLvLines(TO_LATIN1(readStringEntry(cfg, #ENTRY)), \
822                                 def->ENTRY);                            \
823     } while (0)
824 
825 #define CFG_READ_ALIGN(ENTRY) do {                                      \
826         opts->ENTRY = toAlign(TO_LATIN1(readStringEntry(cfg, #ENTRY)),  \
827                               def->ENTRY);                              \
828     } while (0)
829 
830 #define CFG_READ_TB_ICON(ENTRY) do {                                    \
831         opts->ENTRY = toTitlebarIcon(TO_LATIN1(readStringEntry(cfg, #ENTRY)), \
832                                      def->ENTRY);                       \
833     } while (0)
834 
835 #define CFG_READ_GLOW(ENTRY) do {                                       \
836         opts->ENTRY = toGlow(TO_LATIN1(readStringEntry(cfg, #ENTRY)),   \
837                              def->ENTRY);                               \
838     } while (0)
839 
840 #define CFG_READ_TBAR_BTN(ENTRY) do {                                   \
841         opts->ENTRY = toTBarBtn(TO_LATIN1(readStringEntry(cfg, #ENTRY)), \
842                                 def->ENTRY);                            \
843     } while (0)
844 
checkAppearance(EAppearance * ap,Options * opts)845 static void checkAppearance(EAppearance *ap, Options *opts)
846 {
847     if(*ap>=APPEARANCE_CUSTOM1 && *ap<(APPEARANCE_CUSTOM1+NUM_CUSTOM_GRAD))
848     {
849         if(opts->customGradient.end()==opts->customGradient.find(*ap)) {
850             if(ap==&opts->appearance)
851                 *ap=APPEARANCE_FLAT;
852             else
853                 *ap=opts->appearance;
854         }
855     }
856 }
857 
858 void qtcDefaultSettings(Options *opts);
859 
qtcCheckConfig(Options * opts)860 void qtcCheckConfig(Options *opts)
861 {
862     /* **Must** check appearance first, as the rest will default to this */
863     checkAppearance(&opts->appearance, opts);
864     checkAppearance(&opts->bgndAppearance, opts);
865     checkAppearance(&opts->menuBgndAppearance, opts);
866     checkAppearance(&opts->menubarAppearance, opts);
867     checkAppearance(&opts->menuitemAppearance, opts);
868     checkAppearance(&opts->toolbarAppearance, opts);
869     checkAppearance(&opts->lvAppearance, opts);
870     checkAppearance(&opts->tabAppearance, opts);
871     checkAppearance(&opts->activeTabAppearance, opts);
872     checkAppearance(&opts->sliderAppearance, opts);
873     checkAppearance(&opts->selectionAppearance, opts);
874     checkAppearance(&opts->titlebarAppearance, opts);
875     checkAppearance(&opts->inactiveTitlebarAppearance, opts);
876     checkAppearance(&opts->titlebarButtonAppearance, opts);
877     checkAppearance(&opts->selectionAppearance, opts);
878     checkAppearance(&opts->dwtAppearance, opts);
879     checkAppearance(&opts->menuStripeAppearance, opts);
880     checkAppearance(&opts->progressAppearance, opts);
881     checkAppearance(&opts->progressGrooveAppearance, opts);
882     checkAppearance(&opts->grooveAppearance, opts);
883     checkAppearance(&opts->sunkenAppearance, opts);
884     checkAppearance(&opts->sbarBgndAppearance, opts);
885     checkAppearance(&opts->sliderFill, opts);
886     checkAppearance(&opts->tooltipAppearance, opts);
887 
888     if(SHADE_BLEND_SELECTED==opts->shadeCheckRadio)
889         opts->shadeCheckRadio=SHADE_SELECTED;
890 
891     checkColor(&opts->shadeMenubars, &opts->customMenubarsColor);
892     checkColor(&opts->shadeSliders, &opts->customSlidersColor);
893     checkColor(&opts->shadeCheckRadio, &opts->customCheckRadioColor);
894     checkColor(&opts->menuStripe, &opts->customMenuStripeColor);
895     checkColor(&opts->comboBtn, &opts->customComboBtnColor);
896     checkColor(&opts->sortedLv, &opts->customSortedLvColor);
897     if(APPEARANCE_BEVELLED==opts->toolbarAppearance)
898         opts->toolbarAppearance=APPEARANCE_GRADIENT;
899     else if(APPEARANCE_RAISED==opts->toolbarAppearance)
900         opts->toolbarAppearance=APPEARANCE_FLAT;
901 
902     if(APPEARANCE_BEVELLED==opts->menubarAppearance)
903         opts->menubarAppearance=APPEARANCE_GRADIENT;
904     else if(APPEARANCE_RAISED==opts->menubarAppearance)
905         opts->menubarAppearance=APPEARANCE_FLAT;
906 
907     if(APPEARANCE_BEVELLED==opts->sliderAppearance)
908         opts->sliderAppearance=APPEARANCE_GRADIENT;
909 
910     if(APPEARANCE_BEVELLED==opts->tabAppearance)
911         opts->tabAppearance=APPEARANCE_GRADIENT;
912 
913     if(APPEARANCE_BEVELLED==opts->activeTabAppearance)
914         opts->activeTabAppearance=APPEARANCE_GRADIENT;
915 
916     if(APPEARANCE_RAISED==opts->selectionAppearance)
917         opts->selectionAppearance=APPEARANCE_FLAT;
918     else if(APPEARANCE_BEVELLED==opts->selectionAppearance)
919         opts->selectionAppearance=APPEARANCE_GRADIENT;
920 
921     if(APPEARANCE_RAISED==opts->menuStripeAppearance)
922         opts->menuStripeAppearance=APPEARANCE_FLAT;
923     else if(APPEARANCE_BEVELLED==opts->menuStripeAppearance)
924         opts->menuStripeAppearance=APPEARANCE_GRADIENT;
925 
926     if(opts->highlightFactor<MIN_HIGHLIGHT_FACTOR || opts->highlightFactor>MAX_HIGHLIGHT_FACTOR)
927         opts->highlightFactor=DEFAULT_HIGHLIGHT_FACTOR;
928 
929     if(opts->crHighlight<MIN_HIGHLIGHT_FACTOR || opts->crHighlight>MAX_HIGHLIGHT_FACTOR)
930         opts->crHighlight=DEFAULT_CR_HIGHLIGHT_FACTOR;
931 
932     if(opts->splitterHighlight<MIN_HIGHLIGHT_FACTOR || opts->splitterHighlight>MAX_HIGHLIGHT_FACTOR)
933         opts->splitterHighlight=DEFAULT_SPLITTER_HIGHLIGHT_FACTOR;
934 
935 #if defined CONFIG_DIALOG
936     if(opts->expanderHighlight<MIN_HIGHLIGHT_FACTOR || opts->expanderHighlight>MAX_HIGHLIGHT_FACTOR)
937         opts->expanderHighlight=DEFAULT_EXPANDER_HIGHLIGHT_FACTOR;
938 #endif
939 
940     if(0==opts->menuDelay) /* Qt seems to have issues if delay is 0 - so set this to 1 :-) */
941         opts->menuDelay=MIN_MENU_DELAY;
942     else if(opts->menuDelay<MIN_MENU_DELAY || opts->menuDelay>MAX_MENU_DELAY)
943         opts->menuDelay=DEFAULT_MENU_DELAY;
944 
945     if(opts->menuCloseDelay<MIN_MENU_CLOSE_DELAY || opts->menuCloseDelay>MAX_MENU_CLOSE_DELAY)
946         opts->menuCloseDelay=DEFAULT_MENU_CLOSE_DELAY;
947 
948     if(0==opts->sliderWidth%2)
949         opts->sliderWidth++;
950 
951     if(opts->sliderWidth<MIN_SLIDER_WIDTH || opts->sliderWidth>MAX_SLIDER_WIDTH)
952         opts->sliderWidth=DEFAULT_SLIDER_WIDTH;
953 
954     if(opts->sliderWidth<MIN_SLIDER_WIDTH_ROUND)
955         opts->square|=SQUARE_SB_SLIDER;
956 
957     if(opts->sliderWidth<MIN_SLIDER_WIDTH_THIN_GROOVE)
958         opts->thinSbarGroove=false;
959 
960     if(opts->sliderWidth<DEFAULT_SLIDER_WIDTH)
961         opts->sliderThumbs=LINE_NONE;
962 
963     if(opts->lighterPopupMenuBgnd<MIN_LIGHTER_POPUP_MENU || opts->lighterPopupMenuBgnd>MAX_LIGHTER_POPUP_MENU)
964         opts->lighterPopupMenuBgnd=DEF_POPUPMENU_LIGHT_FACTOR;
965 
966     if(opts->tabBgnd<MIN_TAB_BGND || opts->tabBgnd>MAX_TAB_BGND)
967         opts->tabBgnd=DEF_TAB_BGND;
968 
969     if(opts->animatedProgress && !opts->stripedProgress)
970         opts->animatedProgress=false;
971 
972     if(0==opts->gbFactor && FRAME_SHADED==opts->groupBox)
973         opts->groupBox=FRAME_PLAIN;
974 
975     if(opts->gbFactor<MIN_GB_FACTOR || opts->gbFactor>MAX_GB_FACTOR)
976         opts->gbFactor=DEF_GB_FACTOR;
977 
978     if(!opts->gtkComboMenus)
979         opts->doubleGtkComboArrow=false;
980 
981     /* For now, only 2 sizes... */
982     if(opts->crSize!=CR_SMALL_SIZE && opts->crSize!=CR_LARGE_SIZE)
983         opts->crSize=CR_SMALL_SIZE;
984 
985 /*
986 ??
987     if(SHADE_CUSTOM==opts->shadeMenubars || SHADE_BLEND_SELECTED==opts->shadeMenubars || !opts->borderMenuitems)
988         opts->colorMenubarMouseOver=true;
989 */
990 
991 #ifndef CONFIG_DIALOG
992     if(MO_GLOW==opts->coloredMouseOver && EFFECT_NONE==opts->buttonEffect)
993         opts->coloredMouseOver=MO_COLORED_THICK;
994 
995     if(IND_GLOW==opts->defBtnIndicator && EFFECT_NONE==opts->buttonEffect)
996         opts->defBtnIndicator=IND_TINT;
997 
998     if(opts->round>ROUND_EXTRA && FOCUS_GLOW!=opts->focus)
999         opts->focus=FOCUS_LINE;
1000 
1001     if(EFFECT_NONE==opts->buttonEffect)
1002     {
1003         opts->etchEntry=false;
1004         if(FOCUS_GLOW==opts->focus)
1005             opts->focus=FOCUS_FULL;
1006     }
1007 
1008 //     if(opts->squareScrollViews)
1009 //         opts->highlightScrollViews=false;
1010 
1011     if(SHADE_WINDOW_BORDER==opts->shadeMenubars)
1012         opts->shadeMenubarOnlyWhenActive=true;
1013 
1014     if(MO_GLOW==opts->coloredMouseOver)
1015         opts->coloredTbarMo=true;
1016 
1017     if(ROUND_NONE==opts->round)
1018         opts->square=SQUARE_ALL;
1019 #endif
1020 
1021     if(opts->bgndOpacity<0 || opts->bgndOpacity>100)
1022         opts->bgndOpacity=100;
1023     if(opts->dlgOpacity<0 || opts->dlgOpacity>100)
1024         opts->dlgOpacity=100;
1025     if(opts->menuBgndOpacity<0 || opts->menuBgndOpacity>100)
1026         opts->menuBgndOpacity=100;
1027 
1028 #ifndef CONFIG_DIALOG
1029     opts->bgndAppearance=MODIFY_AGUA(opts->bgndAppearance);
1030     opts->selectionAppearance=MODIFY_AGUA(opts->selectionAppearance);
1031     opts->lvAppearance=MODIFY_AGUA_X(opts->lvAppearance, APPEARANCE_LV_AGUA);
1032     opts->sbarBgndAppearance=MODIFY_AGUA(opts->sbarBgndAppearance);
1033     opts->tooltipAppearance=MODIFY_AGUA(opts->tooltipAppearance);
1034     opts->progressGrooveAppearance=MODIFY_AGUA(opts->progressGrooveAppearance);
1035     opts->menuBgndAppearance=MODIFY_AGUA(opts->menuBgndAppearance);
1036     opts->menuStripeAppearance=MODIFY_AGUA(opts->menuStripeAppearance);
1037     opts->grooveAppearance=MODIFY_AGUA(opts->grooveAppearance);
1038     opts->progressAppearance=MODIFY_AGUA(opts->progressAppearance);
1039     opts->sliderFill=MODIFY_AGUA(opts->sliderFill);
1040     opts->tabAppearance=MODIFY_AGUA(opts->tabAppearance);
1041     opts->activeTabAppearance=MODIFY_AGUA(opts->activeTabAppearance);
1042     opts->menuitemAppearance=MODIFY_AGUA(opts->menuitemAppearance);
1043 
1044     if(!opts->borderProgress && (!opts->fillProgress || !(opts->square&SQUARE_PROGRESS)))
1045         opts->borderProgress=true;
1046 
1047     opts->titlebarAppearance=MODIFY_AGUA(opts->titlebarAppearance);
1048     opts->inactiveTitlebarAppearance=MODIFY_AGUA(opts->inactiveTitlebarAppearance);
1049 
1050     if(opts->shadePopupMenu && SHADE_NONE==opts->shadeMenubars)
1051         opts->shadePopupMenu=false;
1052 
1053     if(!(opts->titlebarButtons&TITLEBAR_BUTTON_ROUND))
1054         opts->titlebarButtonAppearance=MODIFY_AGUA(opts->titlebarButtonAppearance);
1055     opts->dwtAppearance=MODIFY_AGUA(opts->dwtAppearance);
1056     if(opts->windowBorder&WINDOW_BORDER_USE_MENUBAR_COLOR_FOR_TITLEBAR &&
1057         (opts->windowBorder&WINDOW_BORDER_BLEND_TITLEBAR || SHADE_WINDOW_BORDER==opts->shadeMenubars))
1058         opts->windowBorder-=WINDOW_BORDER_USE_MENUBAR_COLOR_FOR_TITLEBAR;
1059 
1060     if(APPEARANCE_FLAT==opts->tabAppearance)
1061         opts->tabAppearance=APPEARANCE_RAISED;
1062     if(EFFECT_NONE==opts->buttonEffect)
1063         opts->etchEntry=false;
1064     if(opts->colorSliderMouseOver &&
1065         (SHADE_NONE==opts->shadeSliders || SHADE_DARKEN==opts->shadeSliders))
1066         opts->colorSliderMouseOver=false;
1067 #endif /* ndef CONFIG_DIALOG */
1068 
1069     if(LINE_1DOT==opts->toolbarSeparators)
1070         opts->toolbarSeparators=LINE_DOTS;
1071 }
1072 
qtcReadConfig(const QString & file,Options * opts,Options * defOpts,bool checkImages)1073 bool qtcReadConfig(const QString &file, Options *opts, Options *defOpts, bool checkImages)
1074 {
1075     if (file.isEmpty()) {
1076         const char *env=getenv("QTCURVE_CONFIG_FILE");
1077 
1078         if (nullptr != env) {
1079             return qtcReadConfig(env, opts, defOpts);
1080         } else {
1081             const char *cfgDir=QtCurve::getConfDir();
1082             if(cfgDir) {
1083                 QString filename(QFile::decodeName(cfgDir) + CONFIG_FILE);
1084 
1085                 if(!QFile::exists(filename))
1086                     filename = QFile::decodeName(cfgDir) + "../" OLD_CONFIG_FILE;
1087                 return qtcReadConfig(filename, opts, defOpts);
1088             }
1089         }
1090     } else {
1091         QtCConfig cfg(file);
1092         if (cfg.ok()) {
1093             int i;
1094             opts->version = readVersionEntry(cfg, VERSION_KEY);
1095             Options newOpts;
1096 
1097             if(defOpts)
1098                 newOpts=*defOpts;
1099             else
1100                 qtcDefaultSettings(&newOpts);
1101 
1102             Options *def=&newOpts;
1103 
1104             if(opts!=def)
1105                 opts->customGradient=def->customGradient;
1106             /* Check if the config file expects old default values... */
1107             if(opts->version<qtcMakeVersion(1, 6))
1108             {
1109                 bool framelessGroupBoxes=readBoolEntry(cfg, "framelessGroupBoxes", true),
1110                      groupBoxLine=readBoolEntry(cfg, "groupBoxLine", true);
1111                 opts->groupBox=framelessGroupBoxes ? (groupBoxLine ? FRAME_LINE : FRAME_NONE) : FRAME_PLAIN;
1112                 opts->gbLabel=framelessGroupBoxes ? GB_LBL_BOLD : 0;
1113                 opts->gbFactor=0;
1114                 def->focus=FOCUS_LINE;
1115                 def->crHighlight=3;
1116             } else {
1117                 CFG_READ_FRAME(groupBox);
1118                 CFG_READ_INT(gbLabel);
1119             }
1120 
1121             if(opts->version<qtcMakeVersion(1, 5))
1122             {
1123                 opts->windowBorder=
1124                     (readBoolEntry(cfg, "colorTitlebarOnly", def->windowBorder&WINDOW_BORDER_COLOR_TITLEBAR_ONLY)
1125                                                                 ? WINDOW_BORDER_COLOR_TITLEBAR_ONLY : 0)+
1126                     (readBoolEntry(cfg, "titlebarBorder", def->windowBorder&WINDOW_BORDER_ADD_LIGHT_BORDER)
1127                                                                 ? WINDOW_BORDER_ADD_LIGHT_BORDER : 0)+
1128                     (readBoolEntry(cfg, "titlebarBlend", def->windowBorder&WINDOW_BORDER_BLEND_TITLEBAR)
1129                                                                 ? WINDOW_BORDER_BLEND_TITLEBAR : 0);
1130             }
1131             else
1132                 CFG_READ_INT(windowBorder);
1133 
1134             if(opts->version<qtcMakeVersion(1, 7))
1135             {
1136                 opts->windowBorder|=WINDOW_BORDER_FILL_TITLEBAR;
1137                 def->square=SQUARE_POPUP_MENUS;
1138             }
1139 
1140             if(opts->version<qtcMakeVersion(1, 4))
1141             {
1142                 opts->square=
1143                     (readBoolEntry(cfg, "squareLvSelection", def->square&SQUARE_LISTVIEW_SELECTION) ? SQUARE_LISTVIEW_SELECTION : SQUARE_NONE)+
1144                     (readBoolEntry(cfg, "squareScrollViews", def->square&SQUARE_SCROLLVIEW) ? SQUARE_SCROLLVIEW : SQUARE_NONE)+
1145                     (readBoolEntry(cfg, "squareProgress", def->square&SQUARE_PROGRESS) ? SQUARE_PROGRESS : SQUARE_NONE)+
1146                     (readBoolEntry(cfg, "squareEntry", def->square&SQUARE_ENTRY)? SQUARE_ENTRY : SQUARE_NONE);
1147             }
1148             else
1149                 CFG_READ_INT(square);
1150             if(opts->version<qtcMakeVersion(1, 7))
1151             {
1152                 def->tbarBtns=TBTN_STANDARD;
1153                 opts->thin=(readBoolEntry(cfg, "thinnerMenuItems", def->thin&THIN_MENU_ITEMS) ? THIN_MENU_ITEMS : 0)+
1154                            (readBoolEntry(cfg, "thinnerBtns", def->thin&THIN_BUTTONS) ? THIN_BUTTONS : 0);
1155             }
1156             else
1157             {
1158                 CFG_READ_INT(thin);
1159             }
1160             if(opts->version<qtcMakeVersion(1, 6))
1161                 opts->square|=SQUARE_TOOLTIPS;
1162             if(opts->version<qtcMakeVersion(1, 6, 1))
1163                 opts->square|=SQUARE_POPUP_MENUS;
1164             if(opts->version<qtcMakeVersion(1, 2))
1165                 def->crSize=CR_SMALL_SIZE;
1166             if(opts!=def)
1167             {
1168                 opts->customShades[0]=0;
1169                 opts->customAlphas[0]=0;
1170                 if(USE_CUSTOM_SHADES(*def))
1171                     memcpy(opts->customShades, def->customShades, sizeof(double)*QTC_NUM_STD_SHADES);
1172             }
1173 
1174             CFG_READ_INT(gbFactor);
1175             CFG_READ_INT(passwordChar);
1176             CFG_READ_ROUND(round);
1177             CFG_READ_INT(highlightFactor);
1178             CFG_READ_INT(menuDelay);
1179             CFG_READ_INT(menuCloseDelay);
1180             CFG_READ_INT(sliderWidth);
1181             CFG_READ_INT(tabBgnd);
1182             CFG_READ_TB_BORDER(toolbarBorders);
1183             CFG_READ_APPEARANCE(appearance, APP_ALLOW_BASIC);
1184             if(opts->version<qtcMakeVersion(1, 8))
1185             {
1186                 opts->tbarBtnAppearance=APPEARANCE_NONE;
1187                 opts->tbarBtnEffect=EFFECT_NONE;
1188             }
1189             else
1190             {
1191                 CFG_READ_APPEARANCE(tbarBtnAppearance, APP_ALLOW_NONE);
1192                 CFG_READ_EFFECT(tbarBtnEffect);
1193             }
1194             CFG_READ_APPEARANCE_PIXMAP(bgndAppearance, APP_ALLOW_STRIPED,
1195                                        &opts->bgndPixmap, checkImages);
1196             CFG_READ_GRAD_TYPE(bgndGrad);
1197             CFG_READ_GRAD_TYPE(menuBgndGrad);
1198             CFG_READ_INT_BOOL(lighterPopupMenuBgnd, def->lighterPopupMenuBgnd);
1199             CFG_READ_APPEARANCE_PIXMAP(menuBgndAppearance, APP_ALLOW_STRIPED,
1200                                        &opts->menuBgndPixmap, checkImages);
1201 
1202             if(APPEARANCE_FLAT==opts->menuBgndAppearance && 0==opts->lighterPopupMenuBgnd && opts->version<qtcMakeVersion(1, 7))
1203                 opts->menuBgndAppearance=APPEARANCE_RAISED;
1204 
1205             CFG_READ_STRIPE(stripedProgress);
1206             CFG_READ_SLIDER(sliderStyle);
1207             CFG_READ_BOOL(animatedProgress);
1208             CFG_READ_BOOL(embolden);
1209             CFG_READ_DEF_BTN(defBtnIndicator);
1210             CFG_READ_LINE(sliderThumbs);
1211             CFG_READ_LINE(handles);
1212             CFG_READ_BOOL(highlightTab);
1213             CFG_READ_INT_BOOL(colorSelTab, DEF_COLOR_SEL_TAB_FACTOR);
1214             CFG_READ_BOOL(roundAllTabs);
1215             CFG_READ_TAB_MO(tabMouseOver);
1216             CFG_READ_SHADE(shadeSliders, true, false, &opts->customSlidersColor);
1217             CFG_READ_SHADE(shadeMenubars, true, false, &opts->customMenubarsColor);
1218             CFG_READ_SHADE(shadeCheckRadio, false, false, &opts->customCheckRadioColor);
1219             CFG_READ_SHADE(sortedLv, true, false, &opts->customSortedLvColor);
1220             CFG_READ_SHADE(crColor,  true, false, &opts->customCrBgndColor);
1221             CFG_READ_SHADE(progressColor, false, false, &opts->customProgressColor);
1222             CFG_READ_APPEARANCE(menubarAppearance, APP_ALLOW_BASIC);
1223             CFG_READ_APPEARANCE(menuitemAppearance, APP_ALLOW_FADE);
1224             CFG_READ_APPEARANCE(toolbarAppearance, APP_ALLOW_BASIC);
1225             CFG_READ_APPEARANCE(selectionAppearance, APP_ALLOW_BASIC);
1226             CFG_READ_APPEARANCE(dwtAppearance, APP_ALLOW_BASIC);
1227             CFG_READ_LINE(toolbarSeparators);
1228             CFG_READ_LINE(splitters);
1229             CFG_READ_BOOL(customMenuTextColor);
1230             CFG_READ_MOUSE_OVER(coloredMouseOver);
1231             CFG_READ_BOOL(menubarMouseOver);
1232             CFG_READ_BOOL(useHighlightForMenu);
1233             CFG_READ_BOOL(shadeMenubarOnlyWhenActive);
1234             CFG_READ_TBAR_BTN(tbarBtns);
1235             CFG_READ_COLOR(customMenuSelTextColor);
1236             CFG_READ_COLOR(customMenuNormTextColor);
1237             CFG_READ_SCROLLBAR(scrollbarType);
1238             CFG_READ_EFFECT(buttonEffect);
1239             CFG_READ_APPEARANCE(lvAppearance, APP_ALLOW_BASIC);
1240             CFG_READ_APPEARANCE(tabAppearance, APP_ALLOW_BASIC);
1241             CFG_READ_APPEARANCE(activeTabAppearance, APP_ALLOW_BASIC);
1242             CFG_READ_APPEARANCE(sliderAppearance, APP_ALLOW_BASIC);
1243             CFG_READ_APPEARANCE(progressAppearance, APP_ALLOW_BASIC);
1244             CFG_READ_APPEARANCE(progressGrooveAppearance, APP_ALLOW_BASIC);
1245             CFG_READ_APPEARANCE(grooveAppearance, APP_ALLOW_BASIC);
1246             CFG_READ_APPEARANCE(sunkenAppearance, APP_ALLOW_BASIC);
1247             CFG_READ_APPEARANCE(sbarBgndAppearance, APP_ALLOW_BASIC);
1248             if (opts->version < qtcMakeVersion(1, 6)) {
1249                 opts->tooltipAppearance = APPEARANCE_FLAT;
1250             } else {
1251                 CFG_READ_APPEARANCE(tooltipAppearance, APP_ALLOW_BASIC);
1252             }
1253 
1254             CFG_READ_APPEARANCE(sliderFill, APP_ALLOW_BASIC);
1255             CFG_READ_ECOLOR(progressGrooveColor);
1256             CFG_READ_FOCUS(focus);
1257             CFG_READ_BOOL(lvButton);
1258             CFG_READ_LV_LINES(lvLines);
1259             CFG_READ_BOOL(drawStatusBarFrames);
1260             CFG_READ_BOOL(fillSlider);
1261             CFG_READ_BOOL(roundMbTopOnly);
1262             CFG_READ_BOOL(borderMenuitems);
1263             CFG_READ_BOOL(darkerBorders);
1264             CFG_READ_BOOL(vArrows);
1265             CFG_READ_BOOL(xCheck);
1266             CFG_READ_BOOL(fadeLines);
1267             CFG_READ_GLOW(glowProgress);
1268             CFG_READ_BOOL(colorMenubarMouseOver);
1269             CFG_READ_INT_BOOL(crHighlight, opts->highlightFactor);
1270             CFG_READ_BOOL(crButton);
1271             CFG_READ_BOOL(smallRadio);
1272             CFG_READ_BOOL(fillProgress);
1273             CFG_READ_BOOL(comboSplitter);
1274             CFG_READ_BOOL(highlightScrollViews);
1275             CFG_READ_BOOL(etchEntry);
1276             CFG_READ_INT_BOOL(splitterHighlight, opts->highlightFactor);
1277             CFG_READ_INT(crSize);
1278             CFG_READ_BOOL(flatSbarButtons);
1279             CFG_READ_BOOL(borderSbarGroove);
1280             CFG_READ_BOOL(borderProgress);
1281             CFG_READ_BOOL(popupBorder);
1282             CFG_READ_BOOL(unifySpinBtns);
1283             CFG_READ_BOOL(unifySpin);
1284             CFG_READ_BOOL(unifyCombo);
1285             CFG_READ_BOOL(borderTab);
1286             CFG_READ_BOOL(borderInactiveTab);
1287             CFG_READ_BOOL(thinSbarGroove);
1288             CFG_READ_BOOL(colorSliderMouseOver);
1289             CFG_READ_BOOL(menuIcons);
1290             CFG_READ_BOOL(onlyTicksInMenu);
1291             CFG_READ_BOOL(buttonStyleMenuSections);
1292             CFG_READ_BOOL(forceAlternateLvCols);
1293             CFG_READ_BOOL(invertBotTab);
1294             CFG_READ_INT_BOOL(menubarHiding, HIDE_KEYBOARD);
1295             CFG_READ_INT_BOOL(statusbarHiding, HIDE_KEYBOARD);
1296             CFG_READ_BOOL(boldProgress);
1297             CFG_READ_BOOL(coloredTbarMo);
1298             CFG_READ_BOOL(borderSelection);
1299             CFG_READ_BOOL(stripedSbar);
1300             CFG_READ_INT_BOOL(windowDrag, WM_DRAG_MENUBAR);
1301             CFG_READ_BOOL(shadePopupMenu);
1302             CFG_READ_BOOL(hideShortcutUnderline);
1303 
1304             CFG_READ_BOOL(stdBtnSizes);
1305             CFG_READ_INT(titlebarButtons);
1306             CFG_READ_TB_ICON(titlebarIcon);
1307             CFG_READ_INT(dwtSettings);
1308             CFG_READ_INT(bgndOpacity);
1309             CFG_READ_INT(menuBgndOpacity);
1310             CFG_READ_INT(dlgOpacity);
1311             CFG_READ_INT(shadowSize);
1312             qtcX11SetShadowSize(opts->shadowSize);
1313             CFG_READ_SHADE(menuStripe, true, true, &opts->customMenuStripeColor);
1314             CFG_READ_APPEARANCE(menuStripeAppearance, APP_ALLOW_BASIC);
1315             CFG_READ_SHADE(comboBtn, true, false, &opts->customComboBtnColor);
1316             CFG_READ_BOOL(gtkScrollViews);
1317             CFG_READ_BOOL(doubleGtkComboArrow);
1318             CFG_READ_BOOL(stdSidebarButtons);
1319             CFG_READ_BOOL(toolbarTabs);
1320             CFG_READ_BOOL(gtkComboMenus);
1321             CFG_READ_ALIGN(titlebarAlignment);
1322             CFG_READ_EFFECT(titlebarEffect);
1323             CFG_READ_BOOL(centerTabText);
1324 // #if defined CONFIG_DIALOG
1325             CFG_READ_INT(expanderHighlight);
1326             CFG_READ_BOOL(mapKdeIcons);
1327 // #endif
1328             CFG_READ_BOOL(gtkButtonOrder);
1329 // #if defined CONFIG_DIALOG
1330             CFG_READ_BOOL(reorderGtkButtons);
1331 // #endif
1332             CFG_READ_APPEARANCE(titlebarAppearance, APP_ALLOW_NONE);
1333             CFG_READ_APPEARANCE(inactiveTitlebarAppearance, APP_ALLOW_NONE);
1334 
1335             if(APPEARANCE_BEVELLED==opts->titlebarAppearance)
1336                 opts->titlebarAppearance=APPEARANCE_GRADIENT;
1337             else if(APPEARANCE_RAISED==opts->titlebarAppearance)
1338                 opts->titlebarAppearance=APPEARANCE_FLAT;
1339             if((opts->windowBorder&WINDOW_BORDER_BLEND_TITLEBAR) && !(opts->windowBorder&WINDOW_BORDER_COLOR_TITLEBAR_ONLY))
1340                 opts->windowBorder-=WINDOW_BORDER_BLEND_TITLEBAR;
1341             if(APPEARANCE_BEVELLED==opts->inactiveTitlebarAppearance)
1342                 opts->inactiveTitlebarAppearance=APPEARANCE_GRADIENT;
1343             else if(APPEARANCE_RAISED==opts->inactiveTitlebarAppearance)
1344                 opts->inactiveTitlebarAppearance=APPEARANCE_FLAT;
1345             CFG_READ_APPEARANCE(titlebarButtonAppearance, APP_ALLOW_BASIC);
1346             CFG_READ_SHADING(shading);
1347             CFG_READ_IMAGE(bgndImage);
1348             CFG_READ_IMAGE(menuBgndImage);
1349             CFG_READ_STRING_LIST(noMenuStripeApps);
1350             CFG_READ_STRING_LIST(noBgndGradientApps);
1351             CFG_READ_STRING_LIST(noBgndOpacityApps);
1352             CFG_READ_STRING_LIST(noMenuBgndOpacityApps);
1353             CFG_READ_STRING_LIST(noBgndImageApps);
1354             if (opts->version < qtcMakeVersion(1, 7, 2))
1355                 opts->noMenuBgndOpacityApps << "gtk";
1356             CFG_READ_STRING_LIST(menubarApps);
1357             CFG_READ_STRING_LIST(statusbarApps);
1358             CFG_READ_STRING_LIST(useQtFileDialogApps);
1359             CFG_READ_STRING_LIST(nonnativeMenubarApps);
1360             CFG_READ_STRING_LIST(windowDragWhiteList);
1361             CFG_READ_STRING_LIST(windowDragBlackList);
1362             readDoubleList(cfg, "customShades", opts->customShades, QTC_NUM_STD_SHADES);
1363             readDoubleList(cfg, "customAlphas", opts->customAlphas, NUM_STD_ALPHAS);
1364 
1365             // as with saving, we should always read the titleButtonColor values
1366             // so that they can be saved again without losing the information.
1367             QStringList cols(readStringEntry(cfg, "titlebarButtonColors")
1368                              .split(',', QString::SkipEmptyParts));
1369             if (cols.count() &&
1370                 0 == (cols.count() % NUM_TITLEBAR_BUTTONS) &&
1371                 cols.count() <= (NUM_TITLEBAR_BUTTONS * 3)) {
1372                 QStringList::ConstIterator it(cols.begin());
1373                 QStringList::ConstIterator end(cols.end());
1374 
1375                 for (int i = 0;it != end;++it, ++i) {
1376                     QColor col;
1377                     qtcSetRgb(&col, TO_LATIN1((*it)));
1378                     opts->titlebarButtonColors[i]=col;
1379                 }
1380                 if (cols.count() < (NUM_TITLEBAR_BUTTONS + 1)) {
1381                     opts->titlebarButtons &= ~TITLEBAR_BUTTON_ICON_COLOR;
1382                 }
1383             } else {
1384                 opts->titlebarButtons &= ~TITLEBAR_BUTTON_COLOR;
1385                 opts->titlebarButtons &= ~TITLEBAR_BUTTON_ICON_COLOR;
1386             }
1387 
1388             for(i=APPEARANCE_CUSTOM1; i<(APPEARANCE_CUSTOM1+NUM_CUSTOM_GRAD); ++i)
1389             {
1390                 QString gradKey;
1391 
1392                 gradKey.sprintf("customgradient%d", (i-APPEARANCE_CUSTOM1)+1);
1393 
1394                 QStringList vals(readStringEntry(cfg, gradKey)
1395                                  .split(',', QString::SkipEmptyParts));
1396 
1397                 if(vals.size())
1398                     opts->customGradient.erase((EAppearance)i);
1399 
1400                 if(vals.size()>=5)
1401                 {
1402                     QStringList::ConstIterator it(vals.begin()),
1403                                                end(vals.end());
1404                     bool                       ok(true),
1405                                                haveAlpha(false);
1406                     Gradient                   grad;
1407                     int                        j;
1408 
1409                     grad.border=toGradientBorder(TO_LATIN1((*it)), &haveAlpha);
1410                     ok=vals.size()%(haveAlpha ? 3 : 2);
1411 
1412                     for(++it, j=0; it!=end && ok; ++it, ++j)
1413                     {
1414                         double pos=(*it).toDouble(&ok),
1415                                val=ok ? (*(++it)).toDouble(&ok) : 0.0,
1416                                alpha=haveAlpha && ok ? (*(++it)).toDouble(&ok) : 1.0;
1417 
1418                         ok=ok && (pos>=0 && pos<=1.0) && (val>=0.0 && val<=2.0) && (alpha>=0.0 && alpha<=1.0);
1419 
1420                         if(ok)
1421                             grad.stops.insert(GradientStop(pos, val, alpha));
1422                     }
1423 
1424                     if(ok)
1425                     {
1426                         opts->customGradient[(EAppearance)i]=grad;
1427                         opts->customGradient[(EAppearance)i].stops=grad.stops.fix();
1428                     }
1429                 }
1430             }
1431             qtcCheckConfig(opts);
1432             return true;
1433         } else {
1434             if(defOpts)
1435                 *opts=*defOpts;
1436             else
1437                 qtcDefaultSettings(opts);
1438             return true;
1439         }
1440     }
1441     return false;
1442 }
1443 
getSystemConfigFile()1444 static const char * getSystemConfigFile()
1445 {
1446     static const char * constFiles[]={
1447         /*"/etc/qt4/" OLD_CONFIG_FILE,
1448           "/etc/qt/" OLD_CONFIG_FILE,
1449         */
1450         "/etc/" OLD_CONFIG_FILE,
1451         nullptr
1452     };
1453 
1454     int i;
1455 
1456     for(i=0; constFiles[i]; ++i)
1457         if(QtCurve::isRegFile(constFiles[i]))
1458             return constFiles[i];
1459     return nullptr;
1460 }
1461 
qtcDefaultSettings(Options * opts)1462 void qtcDefaultSettings(Options *opts)
1463 {
1464     /* Set hard-coded defaults... */
1465     // Setup titlebar gradients...
1466     qtcSetupGradient(&opts->customGradient[APPEARANCE_CUSTOM1], GB_3D, 3,
1467                      0.0, 1.2, 0.5, 1.0, 1.0, 1.0);
1468     qtcSetupGradient(&opts->customGradient[APPEARANCE_CUSTOM2], GB_3D, 3,
1469                      0.0, 0.9, 0.5, 1.0, 1.0, 1.0);
1470     opts->customShades[0] = 1.16;
1471     opts->customShades[1] = 1.07;
1472     opts->customShades[2] = 0.9;
1473     opts->customShades[3] = 0.78;
1474     opts->customShades[4] = 0.84;
1475     opts->customShades[5] = 0.75;
1476     opts->customAlphas[0] = 0;
1477     opts->contrast = 7;
1478     opts->passwordChar = 0x25CF;
1479     opts->gbFactor = DEF_GB_FACTOR;
1480     opts->highlightFactor=DEFAULT_HIGHLIGHT_FACTOR;
1481     opts->crHighlight=DEFAULT_CR_HIGHLIGHT_FACTOR;
1482     opts->splitterHighlight=DEFAULT_SPLITTER_HIGHLIGHT_FACTOR;
1483     opts->crSize=CR_LARGE_SIZE;
1484     opts->menuDelay=DEFAULT_MENU_DELAY;
1485     opts->menuCloseDelay=DEFAULT_MENU_CLOSE_DELAY;
1486     opts->sliderWidth=DEFAULT_SLIDER_WIDTH;
1487     opts->selectionAppearance=APPEARANCE_HARSH_GRADIENT;
1488     opts->fadeLines=true;
1489     opts->glowProgress=GLOW_NONE;
1490     opts->round=ROUND_EXTRA;
1491     opts->gtkButtonOrder=false;
1492     opts->dwtAppearance=APPEARANCE_CUSTOM1;
1493     opts->reorderGtkButtons=false;
1494     opts->bgndImage.type=IMG_NONE;
1495     opts->bgndImage.width=opts->bgndImage.height=0;
1496     opts->bgndImage.onBorder=false;
1497     opts->bgndImage.pos=PP_TR;
1498     opts->menuBgndImage.type=IMG_NONE;
1499     opts->menuBgndImage.width=opts->menuBgndImage.height=0;
1500     opts->menuBgndImage.onBorder=false;
1501     opts->menuBgndImage.pos=PP_TR;
1502     opts->lighterPopupMenuBgnd=DEF_POPUPMENU_LIGHT_FACTOR;
1503     opts->tabBgnd=DEF_TAB_BGND;
1504     opts->animatedProgress=false;
1505     opts->stripedProgress=STRIPE_NONE;
1506     opts->sliderStyle=SLIDER_PLAIN;
1507     opts->highlightTab=false;
1508     opts->colorSelTab=0;
1509     opts->roundAllTabs=true;
1510     opts->tabMouseOver=TAB_MO_GLOW;
1511     opts->embolden=false;
1512     opts->bgndGrad=GT_HORIZ;
1513     opts->menuBgndGrad=GT_HORIZ;
1514     opts->appearance=APPEARANCE_SOFT_GRADIENT;
1515     opts->tbarBtnAppearance=APPEARANCE_NONE;
1516     opts->tbarBtnEffect=EFFECT_NONE;
1517     opts->bgndAppearance=APPEARANCE_FLAT;
1518     opts->menuBgndAppearance=APPEARANCE_FLAT;
1519     opts->lvAppearance=APPEARANCE_BEVELLED;
1520     opts->tabAppearance=APPEARANCE_SOFT_GRADIENT;
1521     opts->activeTabAppearance=APPEARANCE_SOFT_GRADIENT;
1522     opts->sliderAppearance=APPEARANCE_SOFT_GRADIENT;
1523     opts->menubarAppearance=APPEARANCE_FLAT;
1524     opts->menuitemAppearance=APPEARANCE_FADE;
1525     opts->toolbarAppearance=APPEARANCE_FLAT;
1526     opts->progressAppearance=APPEARANCE_DULL_GLASS;
1527     opts->progressGrooveAppearance=APPEARANCE_INVERTED;
1528     opts->progressGrooveColor=ECOLOR_DARK;
1529     opts->grooveAppearance=APPEARANCE_INVERTED;
1530     opts->sunkenAppearance=APPEARANCE_SOFT_GRADIENT;
1531     opts->sbarBgndAppearance=APPEARANCE_FLAT;
1532     opts->tooltipAppearance=APPEARANCE_GRADIENT;
1533     opts->sliderFill=APPEARANCE_GRADIENT;
1534     opts->defBtnIndicator=IND_GLOW;
1535     opts->sliderThumbs=LINE_FLAT;
1536     opts->handles=LINE_1DOT;
1537     opts->shadeSliders=SHADE_NONE;
1538     opts->shadeMenubars=SHADE_NONE;
1539     opts->shadeCheckRadio=SHADE_NONE;
1540     opts->sortedLv=SHADE_NONE;
1541     opts->toolbarBorders=TB_NONE;
1542     opts->toolbarSeparators=LINE_SUNKEN;
1543     opts->splitters=LINE_1DOT;
1544     opts->customMenuTextColor=false;
1545     opts->coloredMouseOver=MO_GLOW;
1546     opts->menubarMouseOver=true;
1547     opts->useHighlightForMenu=false;
1548     opts->shadeMenubarOnlyWhenActive=false;
1549     opts->thin=THIN_BUTTONS;
1550     opts->tbarBtns=TBTN_STANDARD;
1551     opts->scrollbarType=SCROLLBAR_KDE;
1552     opts->buttonEffect=EFFECT_SHADOW;
1553     opts->focus=FOCUS_GLOW;
1554     opts->lvButton=false;
1555     opts->lvLines=false; /*LV_NONE;*/
1556     opts->drawStatusBarFrames=false;
1557     opts->fillSlider=true;
1558     opts->roundMbTopOnly=true;
1559     opts->borderMenuitems=false;
1560     opts->darkerBorders=false;
1561     opts->vArrows=true;
1562     opts->xCheck=false;
1563     opts->colorMenubarMouseOver=true;
1564     opts->crButton=true;
1565     opts->crColor=SHADE_NONE;
1566     opts->progressColor=SHADE_SELECTED;
1567     opts->smallRadio=true;
1568     opts->fillProgress=true;
1569     opts->comboSplitter=false;
1570     opts->highlightScrollViews=false;
1571     opts->etchEntry=false;
1572     opts->flatSbarButtons=true;
1573     opts->borderSbarGroove=true;
1574     opts->borderProgress=true;
1575     opts->popupBorder=true;
1576     opts->unifySpinBtns=false;
1577     opts->unifySpin=true;
1578     opts->unifyCombo=true;
1579     opts->borderTab=true;
1580     opts->borderInactiveTab=false;
1581     opts->thinSbarGroove=true;
1582     opts->colorSliderMouseOver=false;
1583     opts->menuIcons=true;
1584     opts->forceAlternateLvCols=false;
1585     opts->invertBotTab=true;
1586     opts->menubarHiding=HIDE_NONE;
1587     opts->statusbarHiding=HIDE_NONE;
1588     opts->boldProgress=true;
1589     opts->coloredTbarMo=false;
1590     opts->borderSelection=false;
1591     opts->square=SQUARE_POPUP_MENUS|SQUARE_TOOLTIPS;
1592     opts->stripedSbar=false;
1593     opts->windowDrag=WM_DRAG_NONE;
1594     opts->shadePopupMenu=false;
1595     opts->hideShortcutUnderline=false;
1596     opts->windowBorder=WINDOW_BORDER_ADD_LIGHT_BORDER|WINDOW_BORDER_FILL_TITLEBAR;
1597     opts->groupBox=FRAME_FADED;
1598     opts->gbFactor=DEF_GB_FACTOR;
1599     opts->gbLabel=GB_LBL_BOLD|GB_LBL_OUTSIDE;
1600     opts->stdBtnSizes=false;
1601     opts->titlebarButtons=TITLEBAR_BUTTON_ROUND|TITLEBAR_BUTTON_HOVER_SYMBOL;
1602     opts->titlebarIcon=TITLEBAR_ICON_NEXT_TO_TITLE;
1603     opts->menuStripe=SHADE_NONE;
1604     opts->menuStripeAppearance=APPEARANCE_DARK_INVERTED;
1605     opts->shading=Shading::HSL;
1606     opts->gtkScrollViews=true;
1607     opts->comboBtn=SHADE_NONE;
1608     opts->doubleGtkComboArrow=true;
1609     opts->stdSidebarButtons=false;
1610     opts->toolbarTabs=false;
1611     opts->bgndOpacity=opts->dlgOpacity=opts->menuBgndOpacity=100;
1612     opts->shadowSize = qtcX11ShadowSize();
1613     opts->gtkComboMenus=false;
1614     opts->customMenubarsColor.setRgb(0, 0, 0);
1615     opts->customSlidersColor.setRgb(0, 0, 0);
1616     opts->customMenuNormTextColor.setRgb(0, 0, 0);
1617     opts->customMenuSelTextColor.setRgb(0, 0, 0);
1618     opts->customCheckRadioColor.setRgb(0, 0, 0);
1619     opts->customComboBtnColor.setRgb(0, 0, 0);
1620     opts->customMenuStripeColor.setRgb(0, 0, 0);
1621     opts->customProgressColor.setRgb(0, 0, 0);
1622     opts->titlebarAlignment=ALIGN_FULL_CENTER;
1623     opts->titlebarEffect=EFFECT_SHADOW;
1624     opts->centerTabText=false;
1625     opts->dwtSettings=DWT_BUTTONS_AS_PER_TITLEBAR|DWT_ROUND_TOP_ONLY;
1626     opts->menubarApps << "smplayer" << "VirtualBox";
1627     opts->statusbarApps << "kde";
1628     opts->noMenuBgndOpacityApps << "sonata" << "totem" << "vmware"
1629                                 << "vmplayer" << "gtk";
1630     opts->noBgndOpacityApps << "smplayer" << "sonata" << "totem" << "vmware"
1631                             << "vmplayer";
1632     opts->noMenuStripeApps << "gtk" << "soffice.bin";
1633 
1634     opts->mapKdeIcons=true;
1635     opts->expanderHighlight=DEFAULT_EXPANDER_HIGHLIGHT_FACTOR;
1636     opts->titlebarAppearance=APPEARANCE_CUSTOM1;
1637     opts->inactiveTitlebarAppearance=APPEARANCE_CUSTOM1;
1638     opts->titlebarButtonAppearance=APPEARANCE_GRADIENT;
1639 #ifdef Q_OS_MACOS
1640     opts->onlyTicksInMenu=true;
1641     opts->buttonStyleMenuSections=false;
1642 #else
1643     opts->onlyTicksInMenu=false;
1644     opts->buttonStyleMenuSections=true;
1645 #endif
1646 
1647     /* Read system config file... */
1648     {
1649     static const char * systemFilename=nullptr;
1650 
1651     if(!systemFilename)
1652         systemFilename=getSystemConfigFile();
1653 
1654     if(systemFilename)
1655         qtcReadConfig(systemFilename, opts, opts);
1656     }
1657 }
1658 
1659 #ifdef CONFIG_WRITE
1660 #include <KDE/KConfig>
1661 #include <KDE/KConfigGroup>
1662 
1663 static const char*
toStr(EDefBtnIndicator ind)1664 toStr(EDefBtnIndicator ind)
1665 {
1666     switch (ind) {
1667     case IND_NONE:
1668         return "none";
1669     case IND_FONT_COLOR:
1670         return "fontcolor";
1671     case IND_CORNER:
1672         return "corner";
1673     case IND_TINT:
1674         return "tint";
1675     case IND_GLOW:
1676         return "glow";
1677     case IND_DARKEN:
1678         return "darken";
1679     case IND_SELECTED:
1680         return "origselected";
1681     default:
1682         return "colored";
1683     }
1684 }
1685 
toStr(ELine ind,bool dashes)1686 static const char *toStr(ELine ind, bool dashes)
1687 {
1688     switch(ind)
1689     {
1690         case LINE_1DOT:
1691             return "1dot";
1692         case LINE_DOTS:
1693             return "dots";
1694         case LINE_DASHES:
1695             return dashes ? "dashes" : "none";
1696         case LINE_NONE:
1697             return "none";
1698         case LINE_FLAT:
1699             return "flat";
1700         default:
1701             return "sunken";
1702     }
1703 }
1704 
toStr(ETBarBorder ind)1705 static const char *toStr(ETBarBorder ind)
1706 {
1707     switch(ind)
1708     {
1709         case TB_DARK:
1710             return "dark";
1711         case TB_DARK_ALL:
1712             return "dark-all";
1713         case TB_LIGHT_ALL:
1714             return "light-all";
1715         case TB_NONE:
1716             return "none";
1717         default:
1718             return "light";
1719     }
1720 }
1721 
toStr(EMouseOver mo)1722 static const char *toStr(EMouseOver mo)
1723 {
1724     switch(mo)
1725     {
1726         case MO_COLORED:
1727             return "colored";
1728         case MO_COLORED_THICK:
1729             return "thickcolored";
1730         case MO_NONE:
1731             return "none";
1732         case MO_GLOW:
1733             return "glow";
1734         default:
1735             return "plastik";
1736     }
1737 }
1738 
toStr(EAppearance exp,EAppAllow allow,const QtCPixmap * pix)1739 static QString toStr(EAppearance exp, EAppAllow allow, const QtCPixmap *pix)
1740 {
1741     switch(exp)
1742     {
1743         case APPEARANCE_FLAT:
1744             return "flat";
1745         case APPEARANCE_RAISED:
1746             return "raised";
1747         case APPEARANCE_DULL_GLASS:
1748             return "dullglass";
1749         case APPEARANCE_SHINY_GLASS:
1750             return "shinyglass";
1751         case APPEARANCE_AGUA:
1752             return "agua";
1753         case APPEARANCE_SOFT_GRADIENT:
1754             return "soft";
1755         case APPEARANCE_GRADIENT:
1756             return "gradient";
1757         case APPEARANCE_HARSH_GRADIENT:
1758             return "harsh";
1759         case APPEARANCE_INVERTED:
1760             return "inverted";
1761         case APPEARANCE_DARK_INVERTED:
1762             return "darkinverted";
1763         case APPEARANCE_SPLIT_GRADIENT:
1764             return "splitgradient";
1765         case APPEARANCE_BEVELLED:
1766             return "bevelled";
1767         case APPEARANCE_FILE:
1768             // When savng, strip users config dir from location.
1769             return QLatin1String("file:")+
1770                     (pix->file.startsWith(QtCurve::getConfDir())
1771                         ? pix->file.mid(strlen(QtCurve::getConfDir())+1)
1772                         : pix->file);
1773         case APPEARANCE_FADE:
1774             switch(allow)
1775             {
1776                 case APP_ALLOW_BASIC: // Should not get here!
1777                 case APP_ALLOW_FADE:
1778                     return "fade";
1779                 case APP_ALLOW_STRIPED:
1780                     return "striped";
1781                 case APP_ALLOW_NONE:
1782                     return "none";
1783             }
1784         default:
1785         {
1786             QString app;
1787 
1788             app.sprintf("customgradient%d", (exp-APPEARANCE_CUSTOM1)+1);
1789             return app;
1790         }
1791     }
1792 }
1793 
toStr(const QColor & col)1794 static QString toStr(const QColor &col)
1795 {
1796     QString colorStr;
1797 
1798     colorStr.sprintf("#%02X%02X%02X", col.red(), col.green(), col.blue());
1799     return colorStr;
1800 }
1801 
toStr(EShade exp,const QColor & col)1802 static QString toStr(EShade exp, const QColor &col)
1803 {
1804     switch(exp)
1805     {
1806         default:
1807         case SHADE_NONE:
1808             return "none";
1809         case SHADE_BLEND_SELECTED:
1810             return "selected";
1811         case SHADE_CUSTOM:
1812             return toStr(col);
1813         case SHADE_SELECTED:
1814             return "origselected";
1815         case SHADE_DARKEN:
1816             return "darken";
1817         case SHADE_WINDOW_BORDER:
1818             return "wborder";
1819     }
1820 }
1821 
toStr(ERound exp)1822 static const char *toStr(ERound exp)
1823 {
1824     switch(exp)
1825     {
1826         case ROUND_NONE:
1827             return "none";
1828         case ROUND_SLIGHT:
1829             return "slight";
1830         case ROUND_EXTRA:
1831             return "extra";
1832         case ROUND_MAX:
1833             return "max";
1834         default:
1835         case ROUND_FULL:
1836             return "full";
1837     }
1838 }
1839 
toStr(EScrollbar sb)1840 static const char *toStr(EScrollbar sb)
1841 {
1842     switch(sb)
1843     {
1844         case SCROLLBAR_KDE:
1845             return "kde";
1846         default:
1847         case SCROLLBAR_WINDOWS:
1848             return "windows";
1849         case SCROLLBAR_PLATINUM:
1850             return "platinum";
1851         case SCROLLBAR_NEXT:
1852             return "next";
1853         case SCROLLBAR_NONE:
1854             return "none";
1855     }
1856 }
1857 
toStr(EFrame sb)1858 static const char *toStr(EFrame sb)
1859 {
1860     switch(sb)
1861     {
1862         case FRAME_NONE:
1863             return "none";
1864         case FRAME_PLAIN:
1865             return "plain";
1866         case FRAME_LINE:
1867             return "line";
1868         case FRAME_SHADED:
1869             return "shaded";
1870         case FRAME_FADED:
1871         default:
1872             return "faded";
1873     }
1874 }
1875 
toStr(EEffect e)1876 static const char *toStr(EEffect e)
1877 {
1878     switch(e)
1879     {
1880         case EFFECT_NONE:
1881             return "none";
1882         default:
1883         case EFFECT_SHADOW:
1884             return "shadow";
1885         case EFFECT_ETCH:
1886             return "etch";
1887     }
1888 }
1889 
toStr(bool b)1890 inline const char * toStr(bool b) { return b ? "true" : "false"; }
1891 
toStr(Shading s)1892 static const char *toStr(Shading s)
1893 {
1894     switch (s) {
1895     case Shading::Simple:
1896         return "simple";
1897     default:
1898     case Shading::HSL:
1899         return "hsl";
1900     case Shading::HSV:
1901         return "hsv";
1902     case Shading::HCY:
1903         return "hcy";
1904     }
1905 }
1906 
toStr(EStripe s)1907 static const char *toStr(EStripe s)
1908 {
1909     switch(s)
1910     {
1911         default:
1912         case STRIPE_PLAIN:
1913             return "plain";
1914         case STRIPE_NONE:
1915             return "none";
1916         case STRIPE_DIAGONAL:
1917             return "diagonal";
1918         case STRIPE_FADE:
1919             return "fade";
1920     }
1921 }
1922 
toStr(ESliderStyle s)1923 static const char *toStr(ESliderStyle s)
1924 {
1925     switch(s)
1926     {
1927         case SLIDER_PLAIN:
1928             return "plain";
1929         case SLIDER_TRIANGULAR:
1930             return "triangular";
1931         case SLIDER_ROUND_ROTATED:
1932             return "r-round";
1933         case SLIDER_PLAIN_ROTATED:
1934             return "r-plain";
1935         case SLIDER_CIRCULAR:
1936             return "circular";
1937         default:
1938         case SLIDER_ROUND:
1939             return "round";
1940     }
1941 }
1942 
toStr(EColor s)1943 static const char *toStr(EColor s)
1944 {
1945     switch(s)
1946     {
1947         case ECOLOR_BACKGROUND:
1948             return "background";
1949         case ECOLOR_DARK:
1950             return "dark";
1951         default:
1952         case ECOLOR_BASE:
1953             return "base";
1954     }
1955 }
1956 
toStr(EFocus f)1957 static const char *toStr(EFocus f)
1958 {
1959     switch(f)
1960     {
1961         default:
1962         case FOCUS_STANDARD:
1963             return "standard";
1964         case FOCUS_RECTANGLE:
1965             return "rect";
1966         case FOCUS_FILLED:
1967             return "filled";
1968         case FOCUS_FULL:
1969             return "full";
1970         case FOCUS_LINE:
1971             return "line";
1972         case FOCUS_GLOW:
1973             return "glow";
1974         case FOCUS_NONE:
1975             return "none";
1976     }
1977 }
1978 
toStr(ETabMo f)1979 static const char *toStr(ETabMo f)
1980 {
1981     switch(f)
1982     {
1983         default:
1984         case TAB_MO_BOTTOM:
1985             return "bot";
1986         case TAB_MO_TOP:
1987             return "top";
1988         case TAB_MO_GLOW:
1989             return "glow";
1990     }
1991 }
1992 
toStr(EGradientBorder g)1993 static const char *toStr(EGradientBorder g)
1994 {
1995     switch(g)
1996     {
1997         case GB_NONE:
1998             return "none";
1999         case GB_LIGHT:
2000             return "light";
2001         case GB_3D_FULL:
2002             return "3dfull";
2003         case GB_SHINE:
2004             return "shine";
2005         default:
2006         case GB_3D:
2007             return "3d";
2008     }
2009 }
2010 
toStr(EAlign ind)2011 static const char *toStr(EAlign ind)
2012 {
2013     switch(ind)
2014     {
2015         default:
2016         case ALIGN_LEFT:
2017             return "left";
2018         case ALIGN_CENTER:
2019             return "center";
2020         case ALIGN_FULL_CENTER:
2021             return "center-full";
2022         case ALIGN_RIGHT:
2023             return "right";
2024     }
2025 }
2026 
toStr(ETitleBarIcon icn)2027 static const char * toStr(ETitleBarIcon icn)
2028 {
2029     switch(icn)
2030     {
2031         case TITLEBAR_ICON_NONE:
2032             return "none";
2033         default:
2034         case TITLEBAR_ICON_MENU_BUTTON:
2035             return "menu";
2036         case TITLEBAR_ICON_NEXT_TO_TITLE:
2037             return "title";
2038     }
2039 }
2040 
toStr(EGradType gt)2041 static const char * toStr(EGradType gt)
2042 {
2043     switch(gt)
2044     {
2045         case GT_VERT:
2046             return "vert";
2047         default:
2048         case GT_HORIZ:
2049             return "horiz";
2050     }
2051 }
2052 
2053 #if 0
2054 static const char * toStr(ELvLines lv)
2055 {
2056     switch(lv)
2057     {
2058         case LV_NEW:
2059             return "new";
2060         case LV_OLD:
2061             return "old";
2062         default:
2063         case LV_NONE:
2064             return "none";
2065     }
2066 }
2067 #endif
2068 
toStr(EImageType lv)2069 static const char * toStr(EImageType lv)
2070 {
2071     switch(lv)
2072     {
2073         default:
2074         case IMG_NONE:
2075             return "none";
2076         case IMG_PLAIN_RINGS:
2077             return "plainrings";
2078         case IMG_BORDERED_RINGS:
2079             return "rings";
2080         case IMG_SQUARE_RINGS:
2081             return "squarerings";
2082         case IMG_FILE:
2083             return "file";
2084     }
2085 }
2086 
toStr(EGlow lv)2087 static const char * toStr(EGlow lv)
2088 {
2089     switch(lv)
2090     {
2091         default:
2092         case GLOW_NONE:
2093             return "none";
2094         case GLOW_START:
2095             return "start";
2096         case GLOW_MIDDLE:
2097             return "middle";
2098         case GLOW_END:
2099             return "end";
2100     }
2101 }
2102 
toStr(ETBarBtn tb)2103 static const char * toStr(ETBarBtn tb)
2104 {
2105     switch(tb)
2106     {
2107         default:
2108         case TBTN_STANDARD:
2109             return "standard";
2110         case TBTN_RAISED:
2111             return "raised";
2112         case TBTN_JOINED:
2113             return "joined";
2114     }
2115 }
2116 
2117 #define CFG config
2118 
2119 #define CFG_WRITE_ENTRY(ENTRY) do {                     \
2120         if (!exportingStyle && def.ENTRY == opts.ENTRY) \
2121             CFG.deleteEntry(#ENTRY);                    \
2122         else                                            \
2123             CFG.writeEntry(#ENTRY, toStr(opts.ENTRY));  \
2124     } while (0)
2125 
2126 #define CFG_WRITE_APPEARANCE_ENTRY(ENTRY, ALLOW) \
2127     if (!exportingStyle && def.ENTRY==opts.ENTRY) \
2128         CFG.deleteEntry(#ENTRY); \
2129     else \
2130         CFG.writeEntry(#ENTRY, toStr(opts.ENTRY, ALLOW, nullptr));
2131 
2132 #define CFG_WRITE_APPEARANCE_ENTRY_PIXMAP(ENTRY, ALLOW, PIXMAP) \
2133     if (!exportingStyle && def.ENTRY==opts.ENTRY) \
2134         CFG.deleteEntry(#ENTRY); \
2135     else \
2136         CFG.writeEntry(#ENTRY, toStr(opts.ENTRY, ALLOW, &opts.PIXMAP));
2137 
2138 #define CFG_WRITE_ENTRY_B(ENTRY, B) \
2139     if (!exportingStyle && def.ENTRY==opts.ENTRY) \
2140         CFG.deleteEntry(#ENTRY); \
2141     else \
2142         CFG.writeEntry(#ENTRY, toStr(opts.ENTRY, B));
2143 
2144 #define CFG_WRITE_ENTRY_NUM(ENTRY) \
2145     if (!exportingStyle && def.ENTRY==opts.ENTRY) \
2146         CFG.deleteEntry(#ENTRY); \
2147     else \
2148         CFG.writeEntry(#ENTRY, opts.ENTRY);
2149 
2150 #define CFG_WRITE_SHADE_ENTRY(ENTRY, COL) \
2151     if (!exportingStyle && def.ENTRY==opts.ENTRY) \
2152         CFG.deleteEntry(#ENTRY); \
2153     else \
2154         CFG.writeEntry(#ENTRY, toStr(opts.ENTRY, opts.COL));
2155 
2156 #define CFG_WRITE_IMAGE_ENTRY(ENTRY) \
2157     if (!exportingStyle && def.ENTRY.type==opts.ENTRY.type) \
2158         CFG.deleteEntry(#ENTRY); \
2159     else \
2160         CFG.writeEntry(#ENTRY, toStr(opts.ENTRY.type)); \
2161     if(IMG_FILE!=opts.ENTRY.type) \
2162     { \
2163         CFG.deleteEntry(#ENTRY ".file"); \
2164         CFG.deleteEntry(#ENTRY ".width"); \
2165         CFG.deleteEntry(#ENTRY ".height"); \
2166         CFG.deleteEntry(#ENTRY ".onBorder"); \
2167         CFG.deleteEntry(#ENTRY ".pos"); \
2168     } \
2169     else \
2170     { \
2171         CFG.writeEntry(#ENTRY ".file", opts.ENTRY.pixmap.file); \
2172         CFG.writeEntry(#ENTRY ".width", opts.ENTRY.width); \
2173         CFG.writeEntry(#ENTRY ".height", opts.ENTRY.height); \
2174         CFG.writeEntry(#ENTRY ".onBorder", opts.ENTRY.onBorder); \
2175         CFG.writeEntry(#ENTRY ".pos", (int)(opts.ENTRY.pos)); \
2176     }
2177 
2178 #define CFG_WRITE_STRING_LIST_ENTRY(ENTRY) \
2179     if (!exportingStyle && def.ENTRY==opts.ENTRY) \
2180         CFG.deleteEntry(#ENTRY); \
2181     else \
2182         CFG.writeEntry(#ENTRY, QStringList(opts.ENTRY.toList()).join(",")); \
2183 
qtcWriteConfig(KConfig * cfg,const Options & opts,const Options & def,bool exportingStyle)2184 bool qtcWriteConfig(KConfig *cfg, const Options &opts, const Options &def, bool exportingStyle)
2185 {
2186     if (!cfg) {
2187         const char *cfgDir=QtCurve::getConfDir();
2188 
2189         if (cfgDir) {
2190             KConfig defCfg(QFile::decodeName(cfgDir) +
2191                            CONFIG_FILE, KConfig::SimpleConfig);
2192 
2193             if (qtcWriteConfig(&defCfg, opts, def, exportingStyle)) {
2194                 const char *oldFiles[]={ OLD_CONFIG_FILE, "qtcurve.gtk-icons", 0};
2195 
2196                 for(int i=0; oldFiles[i]; ++i)
2197                 {
2198                     QString oldFileName(QFile::decodeName(cfgDir)+QString("../")+oldFiles[i]);
2199 
2200                     if(QFile::exists(oldFileName))
2201                         QFile::remove(oldFileName);
2202                 }
2203             }
2204         }
2205     }
2206     else
2207     {
2208         KConfigGroup config(cfg, SETTINGS_GROUP);
2209         CFG.writeEntry(VERSION_KEY, qtcVersion());
2210         CFG_WRITE_ENTRY_NUM(passwordChar);
2211         CFG_WRITE_ENTRY_NUM(gbFactor);
2212         CFG_WRITE_ENTRY(round);
2213         CFG_WRITE_ENTRY_NUM(highlightFactor);
2214         CFG_WRITE_ENTRY_NUM(menuDelay);
2215         CFG_WRITE_ENTRY_NUM(menuCloseDelay);
2216         CFG_WRITE_ENTRY_NUM(sliderWidth);
2217         CFG_WRITE_ENTRY(toolbarBorders);
2218         CFG_WRITE_APPEARANCE_ENTRY(appearance, APP_ALLOW_BASIC);
2219         CFG_WRITE_APPEARANCE_ENTRY(tbarBtnAppearance, APP_ALLOW_NONE);
2220         CFG_WRITE_ENTRY(tbarBtnEffect);
2221         CFG_WRITE_APPEARANCE_ENTRY_PIXMAP(bgndAppearance, APP_ALLOW_STRIPED,
2222                                           bgndPixmap);
2223         CFG_WRITE_ENTRY(bgndGrad);
2224         CFG_WRITE_ENTRY(menuBgndGrad);
2225         CFG_WRITE_APPEARANCE_ENTRY_PIXMAP(menuBgndAppearance, APP_ALLOW_STRIPED,
2226                                           menuBgndPixmap);
2227         CFG_WRITE_ENTRY(stripedProgress);
2228         CFG_WRITE_ENTRY(sliderStyle);
2229         CFG_WRITE_ENTRY(animatedProgress);
2230         CFG_WRITE_ENTRY_NUM(lighterPopupMenuBgnd);
2231         CFG_WRITE_ENTRY_NUM(tabBgnd);
2232         CFG_WRITE_ENTRY(embolden);
2233         CFG_WRITE_ENTRY(defBtnIndicator);
2234         CFG_WRITE_ENTRY_B(sliderThumbs, false);
2235         CFG_WRITE_ENTRY_B(handles, true);
2236         CFG_WRITE_ENTRY(highlightTab);
2237         CFG_WRITE_ENTRY_NUM(colorSelTab);
2238         CFG_WRITE_ENTRY(roundAllTabs);
2239         CFG_WRITE_ENTRY(tabMouseOver);
2240         CFG_WRITE_APPEARANCE_ENTRY(menubarAppearance, APP_ALLOW_BASIC);
2241         CFG_WRITE_APPEARANCE_ENTRY(menuitemAppearance, APP_ALLOW_FADE);
2242         CFG_WRITE_APPEARANCE_ENTRY(toolbarAppearance, APP_ALLOW_BASIC);
2243         CFG_WRITE_APPEARANCE_ENTRY(selectionAppearance, APP_ALLOW_BASIC);
2244         CFG_WRITE_APPEARANCE_ENTRY(dwtAppearance, APP_ALLOW_BASIC);
2245         CFG_WRITE_ENTRY(titlebarEffect);
2246         CFG_WRITE_APPEARANCE_ENTRY(menuStripeAppearance, APP_ALLOW_BASIC);
2247         CFG_WRITE_ENTRY_B(toolbarSeparators, false);
2248         CFG_WRITE_ENTRY_B(splitters, true);
2249         CFG_WRITE_ENTRY(customMenuTextColor);
2250         CFG_WRITE_ENTRY(coloredMouseOver);
2251         CFG_WRITE_ENTRY(menubarMouseOver);
2252         CFG_WRITE_ENTRY(useHighlightForMenu);
2253         CFG_WRITE_ENTRY(shadeMenubarOnlyWhenActive);
2254         CFG_WRITE_ENTRY_NUM(thin);
2255         CFG_WRITE_SHADE_ENTRY(shadeSliders, customSlidersColor);
2256         CFG_WRITE_SHADE_ENTRY(shadeMenubars, customMenubarsColor);
2257         CFG_WRITE_SHADE_ENTRY(sortedLv, customSortedLvColor);
2258         CFG_WRITE_ENTRY(customMenuSelTextColor);
2259         CFG_WRITE_ENTRY(customMenuNormTextColor);
2260         CFG_WRITE_SHADE_ENTRY(shadeCheckRadio, customCheckRadioColor);
2261         CFG_WRITE_ENTRY(scrollbarType);
2262         CFG_WRITE_ENTRY(buttonEffect);
2263         CFG_WRITE_APPEARANCE_ENTRY(lvAppearance, APP_ALLOW_BASIC);
2264         CFG_WRITE_APPEARANCE_ENTRY(tabAppearance, APP_ALLOW_BASIC);
2265         CFG_WRITE_APPEARANCE_ENTRY(activeTabAppearance, APP_ALLOW_BASIC);
2266         CFG_WRITE_APPEARANCE_ENTRY(sliderAppearance, APP_ALLOW_BASIC);
2267         CFG_WRITE_APPEARANCE_ENTRY(progressAppearance, APP_ALLOW_BASIC);
2268         CFG_WRITE_APPEARANCE_ENTRY(progressGrooveAppearance, APP_ALLOW_BASIC);
2269         CFG_WRITE_APPEARANCE_ENTRY(grooveAppearance, APP_ALLOW_BASIC);
2270         CFG_WRITE_APPEARANCE_ENTRY(sunkenAppearance, APP_ALLOW_BASIC);
2271         CFG_WRITE_APPEARANCE_ENTRY(sbarBgndAppearance, APP_ALLOW_BASIC);
2272         CFG_WRITE_APPEARANCE_ENTRY(tooltipAppearance, APP_ALLOW_BASIC);
2273         CFG_WRITE_ENTRY(sliderFill);
2274         CFG_WRITE_ENTRY(progressGrooveColor);
2275         CFG_WRITE_ENTRY(focus);
2276         CFG_WRITE_ENTRY(lvButton);
2277         CFG_WRITE_ENTRY(lvLines);
2278         CFG_WRITE_ENTRY(drawStatusBarFrames);
2279         CFG_WRITE_ENTRY(fillSlider);
2280         CFG_WRITE_ENTRY(roundMbTopOnly);
2281         CFG_WRITE_ENTRY(borderMenuitems);
2282         CFG_WRITE_ENTRY(darkerBorders);
2283         CFG_WRITE_ENTRY(vArrows);
2284         CFG_WRITE_ENTRY(xCheck);
2285         CFG_WRITE_ENTRY(groupBox);
2286         CFG_WRITE_ENTRY_NUM(gbLabel);
2287         CFG_WRITE_ENTRY(fadeLines);
2288         CFG_WRITE_ENTRY(glowProgress);
2289         CFG_WRITE_IMAGE_ENTRY(bgndImage);
2290         CFG_WRITE_IMAGE_ENTRY(menuBgndImage);
2291         CFG_WRITE_ENTRY(colorMenubarMouseOver);
2292         CFG_WRITE_ENTRY_NUM(crHighlight);
2293         CFG_WRITE_ENTRY(crButton);
2294         CFG_WRITE_SHADE_ENTRY(crColor, customCrBgndColor);
2295         CFG_WRITE_SHADE_ENTRY(progressColor, customProgressColor);
2296         CFG_WRITE_ENTRY(smallRadio);
2297         CFG_WRITE_ENTRY(fillProgress);
2298         CFG_WRITE_ENTRY(comboSplitter);
2299         CFG_WRITE_ENTRY(highlightScrollViews);
2300         CFG_WRITE_ENTRY(etchEntry);
2301         CFG_WRITE_ENTRY_NUM(splitterHighlight);
2302         CFG_WRITE_ENTRY_NUM(expanderHighlight);
2303         CFG_WRITE_ENTRY_NUM(crSize);
2304         CFG_WRITE_ENTRY(flatSbarButtons);
2305         CFG_WRITE_ENTRY(borderSbarGroove);
2306         CFG_WRITE_ENTRY(borderProgress);
2307         CFG_WRITE_ENTRY(popupBorder);
2308         CFG_WRITE_ENTRY(unifySpinBtns);
2309         CFG_WRITE_ENTRY(unifySpin);
2310         CFG_WRITE_ENTRY(unifyCombo);
2311         CFG_WRITE_ENTRY(borderTab);
2312         CFG_WRITE_ENTRY(borderInactiveTab);
2313         CFG_WRITE_ENTRY(thinSbarGroove);
2314         CFG_WRITE_ENTRY(colorSliderMouseOver);
2315         CFG_WRITE_ENTRY(menuIcons);
2316         CFG_WRITE_ENTRY(onlyTicksInMenu);
2317         CFG_WRITE_ENTRY(buttonStyleMenuSections);
2318         CFG_WRITE_ENTRY(forceAlternateLvCols);
2319         CFG_WRITE_ENTRY_NUM(square);
2320         CFG_WRITE_ENTRY(invertBotTab);
2321         CFG_WRITE_ENTRY_NUM(menubarHiding);
2322         CFG_WRITE_ENTRY_NUM(statusbarHiding);
2323         CFG_WRITE_ENTRY(boldProgress);
2324         CFG_WRITE_ENTRY(coloredTbarMo);
2325         CFG_WRITE_ENTRY(borderSelection);
2326         CFG_WRITE_ENTRY(stripedSbar);
2327         CFG_WRITE_ENTRY_NUM(windowDrag);
2328         CFG_WRITE_ENTRY(shadePopupMenu);
2329         CFG_WRITE_ENTRY(hideShortcutUnderline);
2330         CFG_WRITE_ENTRY_NUM(windowBorder);
2331         CFG_WRITE_ENTRY(tbarBtns);
2332         CFG_WRITE_ENTRY_NUM(dwtSettings);
2333         CFG_WRITE_ENTRY_NUM(bgndOpacity);
2334         CFG_WRITE_ENTRY_NUM(menuBgndOpacity);
2335         CFG_WRITE_ENTRY_NUM(dlgOpacity);
2336         CFG_WRITE_ENTRY_NUM(shadowSize);
2337         CFG_WRITE_ENTRY(stdBtnSizes);
2338         CFG_WRITE_ENTRY_NUM(titlebarButtons);
2339         CFG_WRITE_ENTRY(titlebarIcon);
2340 
2341         // Why would we only write the button colours when the info is actually being used? This
2342         // makes it impossible to deactivate the feature and then reactivate it without losing
2343         // custom colours.
2344         if (opts.titlebarButtonColors.size() && 0==(opts.titlebarButtonColors.size()%NUM_TITLEBAR_BUTTONS)) {
2345             QString     val;
2346             QTextStream str(&val);
2347             for(unsigned int i=0; i<opts.titlebarButtonColors.size(); ++i)
2348             {
2349                 TBCols::const_iterator c(opts.titlebarButtonColors.find((ETitleBarButtons)i));
2350 
2351                 if(c!=opts.titlebarButtonColors.end())
2352                 {
2353                     if(i)
2354                         str << ',';
2355                     str << toStr((*c).second);
2356                 }
2357             }
2358             CFG.writeEntry("titlebarButtonColors", val);
2359         }
2360         else
2361             CFG.deleteEntry("titlebarButtonColors");
2362         CFG_WRITE_SHADE_ENTRY(menuStripe, customMenuStripeColor);
2363         CFG_WRITE_SHADE_ENTRY(comboBtn, customComboBtnColor);
2364         CFG_WRITE_ENTRY(stdSidebarButtons);
2365         CFG_WRITE_ENTRY(toolbarTabs);
2366         CFG_WRITE_APPEARANCE_ENTRY(titlebarAppearance, APP_ALLOW_NONE);
2367         CFG_WRITE_APPEARANCE_ENTRY(inactiveTitlebarAppearance, APP_ALLOW_NONE);
2368         CFG_WRITE_APPEARANCE_ENTRY(titlebarButtonAppearance, APP_ALLOW_BASIC);
2369         CFG_WRITE_ENTRY(gtkScrollViews);
2370         CFG_WRITE_ENTRY(gtkComboMenus);
2371         CFG_WRITE_ENTRY(doubleGtkComboArrow);
2372         CFG_WRITE_ENTRY(gtkButtonOrder);
2373         CFG_WRITE_ENTRY(reorderGtkButtons);
2374         CFG_WRITE_ENTRY(mapKdeIcons);
2375         CFG_WRITE_ENTRY(shading);
2376         CFG_WRITE_ENTRY(titlebarAlignment);
2377         CFG_WRITE_ENTRY(centerTabText);
2378         CFG_WRITE_STRING_LIST_ENTRY(noBgndGradientApps);
2379         CFG_WRITE_STRING_LIST_ENTRY(noBgndOpacityApps);
2380         CFG_WRITE_STRING_LIST_ENTRY(noMenuBgndOpacityApps);
2381         CFG_WRITE_STRING_LIST_ENTRY(noBgndImageApps);
2382         CFG_WRITE_STRING_LIST_ENTRY(noMenuStripeApps);
2383         CFG_WRITE_STRING_LIST_ENTRY(menubarApps);
2384         CFG_WRITE_STRING_LIST_ENTRY(statusbarApps);
2385         CFG_WRITE_STRING_LIST_ENTRY(useQtFileDialogApps);
2386         CFG_WRITE_STRING_LIST_ENTRY(nonnativeMenubarApps);
2387 
2388         for(int i=APPEARANCE_CUSTOM1; i<(APPEARANCE_CUSTOM1+NUM_CUSTOM_GRAD); ++i)
2389         {
2390             GradientCont::const_iterator cg(opts.customGradient.find((EAppearance)i));
2391             QString                      gradKey;
2392 
2393             gradKey.sprintf("customgradient%d", (i-APPEARANCE_CUSTOM1)+1);
2394 
2395             if(cg==opts.customGradient.end())
2396                 CFG.deleteEntry(gradKey);
2397             else
2398             {
2399                 GradientCont::const_iterator d;
2400 
2401                 if(exportingStyle || (d=def.customGradient.find((EAppearance)i))==def.customGradient.end() || !((*d)==(*cg)))
2402                 {
2403                     QString     gradVal;
2404                     QTextStream str(&gradVal);
2405                     GradientStopCont                 stops((*cg).second.stops.fix());
2406                     GradientStopCont::const_iterator it(stops.begin()),
2407                                                      end(stops.end());
2408                     bool                             haveAlpha(false);
2409 
2410                     for(; it!=end && !haveAlpha; ++it)
2411                         if((*it).alpha<1.0)
2412                             haveAlpha=true;
2413 
2414                     str << toStr((*cg).second.border);
2415                     if(haveAlpha)
2416                         str << "-alpha";
2417 
2418                     for(it=stops.begin(); it!=end; ++it)
2419                         if(haveAlpha)
2420                             str << ',' << (*it).pos << ',' << (*it).val << ',' << (*it).alpha;
2421                         else
2422                             str << ',' << (*it).pos << ',' << (*it).val;
2423                     CFG.writeEntry(gradKey, gradVal);
2424                 }
2425                 else
2426                     CFG.deleteEntry(gradKey);
2427             }
2428         }
2429 
2430         if(opts.customShades[0]==0 ||
2431            exportingStyle ||
2432            opts.customShades[0]!=def.customShades[0] ||
2433            opts.customShades[1]!=def.customShades[1] ||
2434            opts.customShades[2]!=def.customShades[2] ||
2435            opts.customShades[3]!=def.customShades[3] ||
2436            opts.customShades[4]!=def.customShades[4] ||
2437            opts.customShades[5]!=def.customShades[5])
2438         {
2439             QString     shadeVal;
2440             QTextStream str(&shadeVal);
2441             if(0==opts.customShades[0])
2442                  str << 0;
2443             else
2444                 for(int i=0; i<QTC_NUM_STD_SHADES; ++i)
2445                     if(0==i)
2446                         str << opts.customShades[i];
2447                     else
2448                         str << ',' << opts.customShades[i];
2449             CFG.writeEntry("customShades", shadeVal);
2450         }
2451         else
2452             CFG.deleteEntry("customShades");
2453 
2454         if(opts.customAlphas[0]==0 ||
2455            exportingStyle ||
2456            opts.customAlphas[0]!=def.customAlphas[0] ||
2457            opts.customAlphas[1]!=def.customAlphas[1])
2458         {
2459             QString     shadeVal;
2460             QTextStream str(&shadeVal);
2461             if(0==opts.customAlphas[0])
2462                  str << 0;
2463             else
2464                 for(int i=0; i<NUM_STD_ALPHAS; ++i)
2465                     if(0==i)
2466                         str << opts.customAlphas[i];
2467                     else
2468                         str << ',' << opts.customAlphas[i];
2469             CFG.writeEntry("customAlphas", shadeVal);
2470         }
2471         else
2472             CFG.deleteEntry("customAlphas");
2473 
2474         // Removed from 1.5 onwards...
2475         CFG.deleteEntry("colorTitlebarOnly");
2476         CFG.deleteEntry("titlebarBorder");
2477         CFG.deleteEntry("titlebarBlend");
2478         // Removed from 1.4 onwards..
2479         CFG.deleteEntry("squareLvSelection");
2480         CFG.deleteEntry("squareScrollViews");
2481         CFG.deleteEntry("squareProgress");
2482         CFG.deleteEntry("squareEntry");
2483 
2484         cfg->sync();
2485         return true;
2486     }
2487     return false;
2488 }
2489 #endif
2490