File indexing completed on 2024-04-28 17:04:33

0001 /*****************************************************************************
0002  *   Copyright 2003 - 2010 Craig Drummond <craig.p.drummond@gmail.com>       *
0003  *   Copyright 2013 - 2015 Yichao Yu <yyc1992@gmail.com>                     *
0004  *                                                                           *
0005  *   This program is free software; you can redistribute it and/or modify    *
0006  *   it under the terms of the GNU Lesser General Public License as          *
0007  *   published by the Free Software Foundation; either version 2.1 of the    *
0008  *   License, or (at your option) version 3, or any later version accepted   *
0009  *   by the membership of KDE e.V. (or its successor approved by the         *
0010  *   membership of KDE e.V.), which shall act as a proxy defined in          *
0011  *   Section 6 of version 3 of the license.                                  *
0012  *                                                                           *
0013  *   This program is distributed in the hope that it will be useful,         *
0014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
0015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       *
0016  *   Lesser General Public License for more details.                         *
0017  *                                                                           *
0018  *   You should have received a copy of the GNU Lesser General Public        *
0019  *   License along with this library. If not,                                *
0020  *   see <http://www.gnu.org/licenses/>.                                     *
0021  *****************************************************************************/
0022 
0023 #include <qtcurve-utils/dirs.h>
0024 #include <qtcurve-utils/color.h>
0025 #include "common.h"
0026 #include "config_file.h"
0027 
0028 #include <qglobal.h>
0029 #include <QMap>
0030 #include <QFile>
0031 #include <QTextStream>
0032 #include <QSvgRenderer>
0033 #include <QPainter>
0034 #include <QDebug>
0035 
0036 //
0037 // NB!
0038 // This file is built twice (for targets kstyle_qtcurve5_config and qtcurve-qt5),
0039 // and the CONFIG_WRITE and CONFIG_DIALOG tokens are likely to have different values
0040 // each time.
0041 //
0042 
0043 #define CONFIG_FILE "stylerc"
0044 #define OLD_CONFIG_FILE "qtcurvestylerc"
0045 #define VERSION_KEY "version"
0046 
0047 #define TO_LATIN1(A) A.toLatin1().constData()
0048 static QString
0049 determineFileName(const QString &file)
0050 {
0051     if (file.startsWith("/"))
0052         return file;
0053     return QtCurve::getConfDir() + file;
0054 }
0055 
0056 static int c2h(char ch)
0057 {
0058     return ((ch >= '0' && ch <= '9') ? ch - '0' :
0059             (ch >= 'a' && ch <= 'f') ? 10 + (ch - 'a') :
0060             (ch >= 'A' && ch <= 'F') ? 10 + (ch - 'A') : 0);
0061 }
0062 
0063 #define ATOH(str) ((c2h(*str) << 4) + c2h(*(str + 1)))
0064 
0065 void
0066 qtcSetRgb(QColor *col, const char *str)
0067 {
0068     if (str && strlen(str) > 6) {
0069         int offset = '#' == str[0] ? 1 : 0;
0070         col->setRgb(ATOH(&str[offset]), ATOH(&str[offset + 2]),
0071                     ATOH(&str[offset + 4]));
0072     } else {
0073         col->setRgb(0, 0, 0);
0074     }
0075 }
0076 
0077 static bool
0078 loadImage(const QString &file, QtCPixmap *pixmap)
0079 {
0080     // Need to store filename for config dialog!
0081     QString f(determineFileName(file));
0082     pixmap->file = f;
0083     return pixmap->img.load(f);
0084 }
0085 
0086 static EDefBtnIndicator
0087 toInd(const char *str, EDefBtnIndicator def)
0088 {
0089     if (str && str[0]) {
0090         if(0==strncmp(str, "fontcolor", 9) || 0==strncmp(str, "border", 6))
0091             return IND_FONT_COLOR;
0092         if(0==strncmp(str, "none", 4))
0093             return IND_NONE;
0094         if(0==strncmp(str, "corner", 6))
0095             return IND_CORNER;
0096         if(0==strncmp(str, "colored", 7))
0097             return IND_COLORED;
0098         if(0==strncmp(str, "tint", 4))
0099             return IND_TINT;
0100         if(0==strncmp(str, "glow", 4))
0101             return IND_GLOW;
0102         if(0==strncmp(str, "darken", 6))
0103             return IND_DARKEN;
0104         if(0==strncmp(str, "origselected", 12))
0105             return IND_SELECTED;
0106     }
0107     return def;
0108 }
0109 
0110 static ELine
0111 toLine(const char *str, ELine def)
0112 {
0113     if (str && str[0]) {
0114         if(0==strncmp(str, "dashes", 6))
0115             return LINE_DASHES;
0116         if(0==strncmp(str, "none", 4))
0117             return LINE_NONE;
0118         if(0==strncmp(str, "sunken", 6))
0119             return LINE_SUNKEN;
0120         if(0==strncmp(str, "dots", 4))
0121             return LINE_DOTS;
0122         if(0==strncmp(str, "flat", 4))
0123             return LINE_FLAT;
0124         if(0==strncmp(str, "1dot", 5))
0125             return LINE_1DOT;
0126     }
0127     return def;
0128 }
0129 
0130 static ETBarBorder
0131 toTBarBorder(const char *str, ETBarBorder def)
0132 {
0133     if (str && str[0]) {
0134         if(0==strncmp(str, "dark", 4))
0135             return 0==strncmp(&str[4], "-all", 4) ? TB_DARK_ALL : TB_DARK;
0136         if(0==strncmp(str, "none", 4))
0137             return TB_NONE;
0138         if(0==strncmp(str, "light", 5))
0139             return 0==strncmp(&str[5], "-all", 4) ? TB_LIGHT_ALL : TB_LIGHT;
0140     }
0141     return def;
0142 }
0143 
0144 static EMouseOver
0145 toMouseOver(const char *str, EMouseOver def)
0146 {
0147     if (str && str[0]) {
0148         if(0==strncmp(str, "true", 4) || 0==strncmp(str, "colored", 7))
0149             return MO_COLORED;
0150         if(0==strncmp(str, "thickcolored", 12))
0151             return MO_COLORED_THICK;
0152         if(0==strncmp(str, "plastik", 7))
0153             return MO_PLASTIK;
0154         if(0==strncmp(str, "glow", 4))
0155             return MO_GLOW;
0156         if(0==strncmp(str, "false", 4) || 0==strncmp(str, "none", 4))
0157             return MO_NONE;
0158     }
0159     return def;
0160 }
0161 
0162 static EAppearance
0163 toAppearance(const char *str, EAppearance def, EAppAllow allow,
0164              QtCPixmap *pix, bool checkImage)
0165 {
0166     if (str && str[0]) {
0167         if(0==strncmp(str, "flat", 4))
0168             return APPEARANCE_FLAT;
0169         if(0==strncmp(str, "raised", 6))
0170             return APPEARANCE_RAISED;
0171         if(0==strncmp(str, "dullglass", 9))
0172             return APPEARANCE_DULL_GLASS;
0173         if(0==strncmp(str, "glass", 5) || 0==strncmp(str, "shinyglass", 10))
0174             return APPEARANCE_SHINY_GLASS;
0175         if(0==strncmp(str, "agua", 4))
0176             return APPEARANCE_AGUA;
0177         if(0==strncmp(str, "soft", 4))
0178             return APPEARANCE_SOFT_GRADIENT;
0179         if(0==strncmp(str, "gradient", 8) || 0==strncmp(str, "lightgradient", 13))
0180             return APPEARANCE_GRADIENT;
0181         if(0==strncmp(str, "harsh", 5))
0182             return APPEARANCE_HARSH_GRADIENT;
0183         if(0==strncmp(str, "inverted", 8))
0184             return APPEARANCE_INVERTED;
0185         if(0==strncmp(str, "darkinverted", 12))
0186             return APPEARANCE_DARK_INVERTED;
0187         if(0==strncmp(str, "splitgradient", 13))
0188             return APPEARANCE_SPLIT_GRADIENT;
0189         if(0==strncmp(str, "bevelled", 8))
0190             return APPEARANCE_BEVELLED;
0191         if(APP_ALLOW_FADE==allow && 0==strncmp(str, "fade", 4))
0192             return APPEARANCE_FADE;
0193         if(APP_ALLOW_STRIPED==allow && 0==strncmp(str, "striped", 7))
0194             return APPEARANCE_STRIPED;
0195         if(APP_ALLOW_NONE==allow && 0==strncmp(str, "none", 4))
0196             return APPEARANCE_NONE;
0197         if (pix && APP_ALLOW_STRIPED==allow && 0==strncmp(str, "file", 4) && strlen(str)>9)
0198             return loadImage(&str[5], pix) || !checkImage ? APPEARANCE_FILE : def;
0199 
0200         if(0==strncmp(str, "customgradient", 14) && strlen(str)>14)
0201         {
0202             int i=atoi(&str[14]);
0203 
0204             i--;
0205             if(i>=0 && i<NUM_CUSTOM_GRAD)
0206                 return (EAppearance)(APPEARANCE_CUSTOM1+i);
0207         }
0208     }
0209     return def;
0210 }
0211 
0212 static EShade
0213 toShade(const char *str, bool allowMenu, EShade def,
0214         bool menuShade, QColor *col)
0215 {
0216     if (str && str[0]) {
0217         /* true/false is from 0.25... */
0218         if((!menuShade && 0==strncmp(str, "true", 4)) || 0==strncmp(str, "selected", 8))
0219             return SHADE_BLEND_SELECTED;
0220         if(0==strncmp(str, "origselected", 12))
0221             return SHADE_SELECTED;
0222         if(allowMenu && (0==strncmp(str, "darken", 6) || (menuShade && 0==strncmp(str, "true", 4))))
0223             return SHADE_DARKEN;
0224         if(allowMenu && 0==strncmp(str, "wborder", 7))
0225             return SHADE_WINDOW_BORDER;
0226         if(0==strncmp(str, "custom", 6))
0227             return SHADE_CUSTOM;
0228         if('#'==str[0] && col)
0229         {
0230             qtcSetRgb(col, str);
0231             return SHADE_CUSTOM;
0232         }
0233         if(0==strncmp(str, "none", 4))
0234             return SHADE_NONE;
0235     }
0236 
0237     return def;
0238 }
0239 
0240 /* Prior to 0.42 round was a bool - so need to read 'false' as 'none' */
0241 static ERound
0242 toRound(const char *str, ERound def)
0243 {
0244     if (str && str[0]) {
0245         if(0==strncmp(str, "none", 4) || 0==strncmp(str, "false", 5))
0246             return ROUND_NONE;
0247         if(0==strncmp(str, "slight", 6))
0248             return ROUND_SLIGHT;
0249         if(0==strncmp(str, "full", 4))
0250             return ROUND_FULL;
0251         if(0==strncmp(str, "extra", 5))
0252             return ROUND_EXTRA;
0253         if(0==strncmp(str, "max", 3))
0254             return ROUND_MAX;
0255     }
0256     return def;
0257 }
0258 
0259 static EScrollbar
0260 toScrollbar(const char *str, EScrollbar def)
0261 {
0262     return QtCurve::Config::loadValue<EScrollbar>(str, def);
0263 }
0264 
0265 static EFrame
0266 toFrame(const char *str, EFrame def)
0267 {
0268     return QtCurve::Config::loadValue<EFrame>(str, def);
0269 }
0270 
0271 static EEffect
0272 toEffect(const char *str, EEffect def)
0273 {
0274     if (str && str[0]) {
0275         if(0==strncmp(str, "none", 4))
0276             return EFFECT_NONE;
0277         if(0==strncmp(str, "shadow", 6))
0278             return EFFECT_SHADOW;
0279         if(0==strncmp(str, "etch", 4))
0280             return EFFECT_ETCH;
0281     }
0282 
0283     return def;
0284 }
0285 
0286 static Shading
0287 toShading(const char *str, Shading def)
0288 {
0289     return QtCurve::Config::loadValue<Shading>(str, def);
0290 }
0291 
0292 static EStripe
0293 toStripe(const char *str, EStripe def)
0294 {
0295     if (str && str[0]) {
0296         if(0==strncmp(str, "plain", 5) || 0==strncmp(str, "true", 4))
0297             return STRIPE_PLAIN;
0298         if(0==strncmp(str, "none", 4) || 0==strncmp(str, "false", 5))
0299             return STRIPE_NONE;
0300         if(0==strncmp(str, "diagonal", 8))
0301             return STRIPE_DIAGONAL;
0302         if(0==strncmp(str, "fade", 4))
0303             return STRIPE_FADE;
0304     }
0305 
0306     return def;
0307 }
0308 
0309 static ESliderStyle toSlider(const char *str, ESliderStyle def)
0310 {
0311     if(str && 0!=str[0])
0312     {
0313         if(0==strncmp(str, "round", 5))
0314             return SLIDER_ROUND;
0315         if(0==strncmp(str, "plain", 5))
0316             return SLIDER_PLAIN;
0317         if(0==strncmp(str, "r-round", 7))
0318             return SLIDER_ROUND_ROTATED;
0319         if(0==strncmp(str, "r-plain", 7))
0320             return SLIDER_PLAIN_ROTATED;
0321         if(0==strncmp(str, "triangular", 10))
0322             return SLIDER_TRIANGULAR;
0323         if(0==strncmp(str, "circular", 8))
0324             return SLIDER_CIRCULAR;
0325     }
0326 
0327     return def;
0328 }
0329 
0330 static EColor toEColor(const char *str, EColor def)
0331 {
0332     if(str && 0!=str[0])
0333     {
0334         if(0==strncmp(str, "base", 4))
0335             return ECOLOR_BASE;
0336         if(0==strncmp(str, "dark", 4))
0337             return ECOLOR_DARK;
0338         if(0==strncmp(str, "background", 10))
0339             return ECOLOR_BACKGROUND;
0340     }
0341 
0342     return def;
0343 }
0344 
0345 static EFocus toFocus(const char *str, EFocus def)
0346 {
0347     if(str && 0!=str[0])
0348     {
0349         if(0==strncmp(str, "standard", 8))
0350             return FOCUS_STANDARD;
0351         if(0==strncmp(str, "rect", 4) || 0==strncmp(str, "highlight", 9))
0352             return FOCUS_RECTANGLE;
0353         if(0==strncmp(str, "filled", 6))
0354             return FOCUS_FILLED;
0355         if(0==strncmp(str, "full", 4))
0356             return FOCUS_FULL;
0357         if(0==strncmp(str, "line", 4))
0358             return FOCUS_LINE;
0359         if(0==strncmp(str, "glow", 4))
0360             return FOCUS_GLOW;
0361         if(0==strncmp(str, "none", 4))
0362             return FOCUS_NONE;
0363     }
0364 
0365     return def;
0366 }
0367 
0368 static ETabMo toTabMo(const char *str, ETabMo def)
0369 {
0370     if(str && 0!=str[0])
0371     {
0372         if(0==strncmp(str, "top", 3))
0373             return TAB_MO_TOP;
0374         if(0==strncmp(str, "bot", 3))
0375             return TAB_MO_BOTTOM;
0376         if(0==strncmp(str, "glow", 4))
0377             return TAB_MO_GLOW;
0378     }
0379 
0380     return def;
0381 }
0382 
0383 static EGradType toGradType(const char *str, EGradType def)
0384 {
0385     if(str && 0!=str[0])
0386     {
0387         if(0==strncmp(str, "horiz", 5))
0388             return GT_HORIZ;
0389         if(0==strncmp(str, "vert", 4))
0390             return GT_VERT;
0391     }
0392     return def;
0393 }
0394 
0395 static bool toLvLines(const char *str, bool def)
0396 {
0397     if(str && 0!=str[0])
0398     {
0399 #if 0
0400         if(0==strncmp(str, "true", 4) || 0==strncmp(str, "new", 3))
0401             return LV_NEW;
0402         if(0==strncmp(str, "old", 3))
0403             return LV_OLD;
0404         if(0==strncmp(str, "false", 5) || 0==strncmp(str, "none", 4))
0405             return LV_NONE;
0406 #else
0407         return 0!=strncmp(str, "false", 5);
0408 #endif
0409     }
0410     return def;
0411 }
0412 
0413 static EGradientBorder toGradientBorder(const char *str, bool *haveAlpha)
0414 {
0415     if (str && str[0]) {
0416         *haveAlpha = strstr(str, "-alpha") ? true : false;
0417         if(0==strncmp(str, "light", 5) || 0==strncmp(str, "true", 4))
0418             return GB_LIGHT;
0419         if(0==strncmp(str, "none", 4))
0420             return GB_NONE;
0421         if(0==strncmp(str, "3dfull", 6))
0422             return GB_3D_FULL;
0423         if(0==strncmp(str, "3d", 2) || 0==strncmp(str, "false", 5))
0424             return GB_3D;
0425         if(0==strncmp(str, "shine", 5))
0426             return GB_SHINE;
0427     }
0428     return GB_3D;
0429 }
0430 
0431 static EAlign toAlign(const char *str, EAlign def)
0432 {
0433     if(str && 0!=str[0])
0434     {
0435         if(0==strncmp(str, "left", 4))
0436             return ALIGN_LEFT;
0437         if(0==strncmp(str, "center-full", 11))
0438             return ALIGN_FULL_CENTER;
0439         if(0==strncmp(str, "center", 6))
0440             return ALIGN_CENTER;
0441         if(0==strncmp(str, "right", 5))
0442             return ALIGN_RIGHT;
0443     }
0444     return def;
0445 }
0446 
0447 static ETitleBarIcon toTitlebarIcon(const char *str, ETitleBarIcon def)
0448 {
0449     if(str && 0!=str[0])
0450     {
0451         if(0==strncmp(str, "none", 4))
0452             return TITLEBAR_ICON_NONE;
0453         if(0==strncmp(str, "menu", 4))
0454             return TITLEBAR_ICON_MENU_BUTTON;
0455         if(0==strncmp(str, "title", 5))
0456             return TITLEBAR_ICON_NEXT_TO_TITLE;
0457     }
0458     return def;
0459 }
0460 
0461 static EImageType toImageType(const char *str, EImageType def)
0462 {
0463     if(str && 0!=str[0])
0464     {
0465         if(0==strncmp(str, "none", 4))
0466             return IMG_NONE;
0467         if(0==strncmp(str, "plainrings", 10))
0468             return IMG_PLAIN_RINGS;
0469         if(0==strncmp(str, "rings", 5))
0470             return IMG_BORDERED_RINGS;
0471         if(0==strncmp(str, "squarerings", 11))
0472             return IMG_SQUARE_RINGS;
0473         if(0==strncmp(str, "file", 4))
0474             return IMG_FILE;
0475     }
0476     return def;
0477 }
0478 
0479 static EGlow toGlow(const char *str, EGlow def)
0480 {
0481     if(str && 0!=str[0])
0482     {
0483         if(0==strncmp(str, "none", 4))
0484             return GLOW_NONE;
0485         if(0==strncmp(str, "start", 5))
0486             return GLOW_START;
0487         if(0==strncmp(str, "middle", 6))
0488             return GLOW_MIDDLE;
0489         if(0==strncmp(str, "end", 3))
0490             return GLOW_END;
0491     }
0492     return def;
0493 }
0494 
0495 static ETBarBtn toTBarBtn(const char *str, ETBarBtn def)
0496 {
0497     if(str && 0!=str[0])
0498     {
0499         if(0==strncmp(str, "standard", 8))
0500             return TBTN_STANDARD;
0501         if(0==strncmp(str, "raised", 6))
0502             return TBTN_RAISED;
0503         if(0==strncmp(str, "joined", 6))
0504             return TBTN_JOINED;
0505     }
0506     return def;
0507 }
0508 
0509 WindowBorders qtcGetWindowBorderSize(bool force)
0510 {
0511     static WindowBorders def={24, 18, 4, 4};
0512     static WindowBorders sizes={-1, -1, -1, -1};
0513 
0514     if(-1==sizes.titleHeight || force)
0515     {
0516         QFile f(QtCurve::getConfDir()+QString(BORDER_SIZE_FILE));
0517 
0518         if(f.open(QIODevice::ReadOnly)) {
0519             QTextStream stream(&f);
0520             QString     line;
0521 
0522             sizes.titleHeight=stream.readLine().toInt();
0523             sizes.toolTitleHeight=stream.readLine().toInt();
0524             sizes.bottom=stream.readLine().toInt();
0525             sizes.sides=stream.readLine().toInt();
0526             f.close();
0527         }
0528     }
0529 
0530     return sizes.titleHeight<12 ? def : sizes;
0531 }
0532 
0533 #ifndef CONFIG_DIALOG
0534 
0535 bool qtcBarHidden(const QString &app, const char *prefix)
0536 {
0537     return QFile::exists(QFile::decodeName(QtCurve::getConfDir())+prefix+app);
0538 }
0539 
0540 void qtcSetBarHidden(const QString &app, bool hidden, const char *prefix)
0541 {
0542     if(!hidden)
0543         QFile::remove(QFile::decodeName(QtCurve::getConfDir())+prefix+app);
0544     else
0545         QFile(QFile::decodeName(QtCurve::getConfDir())+prefix+app).open(QIODevice::WriteOnly);
0546 }
0547 
0548 void qtcLoadBgndImage(QtCImage *img)
0549 {
0550     if(!img->loaded &&
0551         ( (img->width>16 && img->width<1024 && img->height>16 && img->height<1024) || (0==img->width && 0==img->height)) )
0552     {
0553         img->loaded=true;
0554         img->pixmap.img=QPixmap();
0555         QString file(determineFileName(img->pixmap.file));
0556 
0557         if(!file.isEmpty())
0558         {
0559             bool loaded=false;
0560             if(0!=img->width && (file.endsWith(".svg", Qt::CaseInsensitive) || file.endsWith(".svgz", Qt::CaseInsensitive)))
0561             {
0562                 QSvgRenderer svg(file);
0563 
0564                 if(svg.isValid())
0565                 {
0566                     img->pixmap.img=QPixmap(img->width, img->height);
0567                     img->pixmap.img.fill(Qt::transparent);
0568                     QPainter painter(&img->pixmap.img);
0569                     svg.render(&painter);
0570                     painter.end();
0571                     loaded=true;
0572                 }
0573             }
0574             if(!loaded && img->pixmap.img.load(file) && 0!=img->width &&
0575                (img->pixmap.img.height()!=img->height || img->pixmap.img.width()!=img->width))
0576                 img->pixmap.img=img->pixmap.img.scaled(img->width, img->height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
0577         }
0578     }
0579 }
0580 
0581 #endif
0582 
0583 static void
0584 checkColor(EShade *s, QColor *c)
0585 {
0586     if (*s == SHADE_CUSTOM && QtCurve::isBlack(*c)) {
0587         *s = SHADE_NONE;
0588     }
0589 }
0590 
0591 class QtCConfig {
0592 public:
0593     QtCConfig(const QString &filename);
0594 
0595     bool ok() const {return values.count() > 0;}
0596     bool hasKey(const QString &key) {return values.contains(key);}
0597     QString readEntry(const QString &key, const QString &def=QString());
0598 private:
0599     QMap<QString, QString> values;
0600 };
0601 
0602 QtCConfig::QtCConfig(const QString &filename)
0603 {
0604     QFile f(filename);
0605 
0606     if (f.open(QIODevice::ReadOnly)) {
0607         QTextStream stream(&f);
0608         QString     line;
0609 
0610         while(!stream.atEnd())
0611         {
0612             line = stream.readLine();
0613             int pos=line.indexOf('=');
0614             if(-1!=pos)
0615                 values[line.left(pos)]=line.mid(pos+1);
0616         }
0617         f.close();
0618     }
0619 }
0620 
0621 inline QString
0622 QtCConfig::readEntry(const QString &key, const QString &def)
0623 {
0624     return values.contains(key) ? values[key] : def;
0625 }
0626 
0627 inline QString readStringEntry(QtCConfig &cfg, const QString &key)
0628 {
0629     return cfg.readEntry(key);
0630 }
0631 
0632 static int readNumEntry(QtCConfig &cfg, const QString &key, int def)
0633 {
0634     const QString &val(readStringEntry(cfg, key));
0635 
0636     return val.isEmpty() ? def : val.toInt();
0637 }
0638 
0639 static int readVersionEntry(QtCConfig &cfg, const QString &key)
0640 {
0641     const QString &val(readStringEntry(cfg, key));
0642     int           major, minor, patch;
0643 
0644     return !val.isEmpty() && 3==sscanf(TO_LATIN1(val), "%d.%d.%d", &major, &minor, &patch)
0645             ? qtcMakeVersion(major, minor, patch)
0646             : 0;
0647 }
0648 
0649 static bool readBoolEntry(QtCConfig &cfg, const QString &key, bool def)
0650 {
0651     const QString &val(readStringEntry(cfg, key));
0652 
0653     return val.isEmpty() ? def : (val==QLatin1String("true") ? true : false);
0654 }
0655 
0656 static void readDoubleList(QtCConfig &cfg, const char *key, double *list, int count)
0657 {
0658     QStringList strings(readStringEntry(cfg, key).split(',', QString::SkipEmptyParts));
0659     bool ok(count==strings.size());
0660 
0661     if(ok)
0662     {
0663         QStringList::ConstIterator it(strings.begin());
0664         int                        i;
0665 
0666         for(i=0; i<count && ok; ++i, ++it)
0667             list[i]=(*it).toDouble(&ok);
0668     }
0669 
0670     if(!ok && strings.size())
0671         list[0]=0;
0672 }
0673 
0674 #define CFG_READ_COLOR(ENTRY) do {                      \
0675         QString sVal(cfg.readEntry(#ENTRY));            \
0676         if (sVal.isEmpty()) {                           \
0677             opts->ENTRY = def->ENTRY;                   \
0678         } else {                                        \
0679             qtcSetRgb(&opts->ENTRY, TO_LATIN1(sVal));   \
0680         }                                               \
0681     } while (0)
0682 
0683 #define CFG_READ_IMAGE(ENTRY) do {                                      \
0684         opts->ENTRY.type =                                              \
0685             toImageType(TO_LATIN1(readStringEntry(cfg, #ENTRY)),        \
0686                         def->ENTRY.type);                               \
0687         opts->ENTRY.loaded = false;                                     \
0688         opts->ENTRY.width = opts->ENTRY.height = 0;                     \
0689         opts->ENTRY.onBorder = false;                                   \
0690         opts->ENTRY.pos = PP_TR;                                        \
0691         if (opts->ENTRY.type == IMG_FILE) {                             \
0692             QString file(cfg.readEntry(#ENTRY ".file"));                \
0693             if (!file.isEmpty()) {                                      \
0694                 opts->ENTRY.pixmap.file = file;                         \
0695                 opts->ENTRY.width = readNumEntry(cfg, #ENTRY ".width", 0); \
0696                 opts->ENTRY.height = readNumEntry(cfg, #ENTRY ".height", 0); \
0697                 opts->ENTRY.onBorder = readBoolEntry(cfg, #ENTRY ".onBorder", \
0698                                                      false);            \
0699                 opts->ENTRY.pos = (EPixPos)readNumEntry(cfg, #ENTRY ".pos", \
0700                                                         (int)PP_TR);    \
0701             } else {                                                    \
0702                 opts->ENTRY.type = IMG_NONE;                            \
0703             }                                                           \
0704         }                                                               \
0705     } while (0)
0706 
0707 #define CFG_READ_STRING_LIST(ENTRY) do {                                \
0708         QString val = readStringEntry(cfg, #ENTRY);                     \
0709         Strings set = val.isEmpty() ? Strings() :                       \
0710             QtCurve::qSetFromList(val.split(",", QString::SkipEmptyParts)); \
0711         opts->ENTRY = set.count() || cfg.hasKey(#ENTRY) ? set : def->ENTRY; \
0712     } while (0)
0713 
0714 #define CFG_READ_BOOL(ENTRY) do {                               \
0715         opts->ENTRY = readBoolEntry(cfg, #ENTRY, def->ENTRY);   \
0716     } while (0)
0717 
0718 #define CFG_READ_ROUND(ENTRY) do {                                      \
0719         opts->ENTRY = toRound(TO_LATIN1(readStringEntry(cfg, #ENTRY)),  \
0720                               def->ENTRY);                              \
0721     } while (0)
0722 
0723 #define CFG_READ_INT(ENTRY) do {                                \
0724         opts->ENTRY = readNumEntry(cfg, #ENTRY, def->ENTRY);    \
0725     } while (0)
0726 
0727 #define CFG_READ_INT_BOOL(ENTRY, DEF) do {                              \
0728         if (readBoolEntry(cfg, #ENTRY, false)) {                        \
0729             opts->ENTRY = DEF;                                          \
0730         } else {                                                        \
0731             opts->ENTRY = readNumEntry(cfg, #ENTRY, def->ENTRY);        \
0732         }                                                               \
0733     } while (0)
0734 
0735 #define CFG_READ_TB_BORDER(ENTRY) do {                                  \
0736         opts->ENTRY = toTBarBorder(TO_LATIN1(readStringEntry(cfg, #ENTRY)), \
0737                                    def->ENTRY);                         \
0738     } while (0)
0739 
0740 #define CFG_READ_MOUSE_OVER(ENTRY) do {                                 \
0741         opts->ENTRY = toMouseOver(TO_LATIN1(readStringEntry(cfg, #ENTRY)), \
0742                                   def->ENTRY);                          \
0743     } while (0)
0744 
0745 #define CFG_READ_APPEARANCE(ENTRY, ALLOW) do {                          \
0746         opts->ENTRY = toAppearance(TO_LATIN1(readStringEntry(cfg, #ENTRY)), \
0747                                    def->ENTRY, ALLOW, nullptr, false);     \
0748     } while (0)
0749 
0750 #define CFG_READ_APPEARANCE_PIXMAP(ENTRY, ALLOW, PIXMAP, CHECK) do {    \
0751         opts->ENTRY = toAppearance(TO_LATIN1(readStringEntry(cfg, #ENTRY)), \
0752                                    def->ENTRY, ALLOW, PIXMAP, CHECK);   \
0753     } while (0)
0754 
0755 #define CFG_READ_STRIPE(ENTRY) do {                                     \
0756         opts->ENTRY=toStripe(TO_LATIN1(readStringEntry(cfg, #ENTRY)),   \
0757                              def->ENTRY);                               \
0758     } while (0)
0759 
0760 #define CFG_READ_SLIDER(ENTRY) do {                                     \
0761         opts->ENTRY = toSlider(TO_LATIN1(readStringEntry(cfg, #ENTRY)), \
0762                              def->ENTRY);                               \
0763     } while (0)
0764 
0765 #define CFG_READ_DEF_BTN(ENTRY) do {                                    \
0766         opts->ENTRY = toInd(TO_LATIN1(readStringEntry(cfg, #ENTRY)),    \
0767                             def->ENTRY);                                \
0768     } while (0)
0769 
0770 #define CFG_READ_LINE(ENTRY) do {                                       \
0771         opts->ENTRY = toLine(TO_LATIN1(readStringEntry(cfg, #ENTRY)),   \
0772                              def->ENTRY);                               \
0773     } while (0)
0774 
0775 #define CFG_READ_SHADE(ENTRY, AD, MENU_STRIPE, COL) do {                \
0776         opts->ENTRY = toShade(TO_LATIN1(readStringEntry(cfg, #ENTRY)), AD, \
0777                               def->ENTRY, MENU_STRIPE, COL);            \
0778     } while (0)
0779 
0780 #define CFG_READ_SCROLLBAR(ENTRY) do {                                  \
0781         opts->ENTRY = toScrollbar(TO_LATIN1(readStringEntry(cfg, #ENTRY)), \
0782                                   def->ENTRY);                          \
0783     } while (0)
0784 
0785 #define CFG_READ_FRAME(ENTRY) do {                                      \
0786         opts->ENTRY = toFrame(TO_LATIN1(readStringEntry(cfg, #ENTRY)),  \
0787                               def->ENTRY);                              \
0788     } while (0)
0789 
0790 #define CFG_READ_EFFECT(ENTRY) do {                                     \
0791         opts->ENTRY = toEffect(TO_LATIN1(readStringEntry(cfg, #ENTRY)), \
0792                                def->ENTRY);                             \
0793     } while (0)
0794 
0795 #define CFG_READ_SHADING(ENTRY) do {                                    \
0796         opts->ENTRY = toShading(TO_LATIN1(readStringEntry(cfg, #ENTRY)), \
0797                                 def->ENTRY);                            \
0798     } while (0)
0799 
0800 #define CFG_READ_ECOLOR(ENTRY) do {                                     \
0801         opts->ENTRY = toEColor(TO_LATIN1(readStringEntry(cfg, #ENTRY)), \
0802                                def->ENTRY);                             \
0803     } while (0)
0804 
0805 #define CFG_READ_FOCUS(ENTRY) do {                                      \
0806         opts->ENTRY = toFocus(TO_LATIN1(readStringEntry(cfg, #ENTRY)),  \
0807                               def->ENTRY);                              \
0808     } while (0)
0809 
0810 #define CFG_READ_TAB_MO(ENTRY) do {                                     \
0811         opts->ENTRY = toTabMo(TO_LATIN1(readStringEntry(cfg, #ENTRY)),  \
0812                               def->ENTRY);                              \
0813     } while (0)
0814 
0815 #define CFG_READ_GRAD_TYPE(ENTRY) do {                                  \
0816         opts->ENTRY = toGradType(TO_LATIN1(readStringEntry(cfg, #ENTRY)), \
0817                                  def->ENTRY);                           \
0818     } while (0)
0819 
0820 #define CFG_READ_LV_LINES(ENTRY) do {                                   \
0821         opts->ENTRY = toLvLines(TO_LATIN1(readStringEntry(cfg, #ENTRY)), \
0822                                 def->ENTRY);                            \
0823     } while (0)
0824 
0825 #define CFG_READ_ALIGN(ENTRY) do {                                      \
0826         opts->ENTRY = toAlign(TO_LATIN1(readStringEntry(cfg, #ENTRY)),  \
0827                               def->ENTRY);                              \
0828     } while (0)
0829 
0830 #define CFG_READ_TB_ICON(ENTRY) do {                                    \
0831         opts->ENTRY = toTitlebarIcon(TO_LATIN1(readStringEntry(cfg, #ENTRY)), \
0832                                      def->ENTRY);                       \
0833     } while (0)
0834 
0835 #define CFG_READ_GLOW(ENTRY) do {                                       \
0836         opts->ENTRY = toGlow(TO_LATIN1(readStringEntry(cfg, #ENTRY)),   \
0837                              def->ENTRY);                               \
0838     } while (0)
0839 
0840 #define CFG_READ_TBAR_BTN(ENTRY) do {                                   \
0841         opts->ENTRY = toTBarBtn(TO_LATIN1(readStringEntry(cfg, #ENTRY)), \
0842                                 def->ENTRY);                            \
0843     } while (0)
0844 
0845 static void checkAppearance(EAppearance *ap, Options *opts)
0846 {
0847     if(*ap>=APPEARANCE_CUSTOM1 && *ap<(APPEARANCE_CUSTOM1+NUM_CUSTOM_GRAD))
0848     {
0849         if(opts->customGradient.end()==opts->customGradient.find(*ap)) {
0850             if(ap==&opts->appearance)
0851                 *ap=APPEARANCE_FLAT;
0852             else
0853                 *ap=opts->appearance;
0854         }
0855     }
0856 }
0857 
0858 void qtcDefaultSettings(Options *opts);
0859 
0860 void qtcCheckConfig(Options *opts)
0861 {
0862     /* **Must** check appearance first, as the rest will default to this */
0863     checkAppearance(&opts->appearance, opts);
0864     checkAppearance(&opts->bgndAppearance, opts);
0865     checkAppearance(&opts->menuBgndAppearance, opts);
0866     checkAppearance(&opts->menubarAppearance, opts);
0867     checkAppearance(&opts->menuitemAppearance, opts);
0868     checkAppearance(&opts->toolbarAppearance, opts);
0869     checkAppearance(&opts->lvAppearance, opts);
0870     checkAppearance(&opts->tabAppearance, opts);
0871     checkAppearance(&opts->activeTabAppearance, opts);
0872     checkAppearance(&opts->sliderAppearance, opts);
0873     checkAppearance(&opts->selectionAppearance, opts);
0874     checkAppearance(&opts->titlebarAppearance, opts);
0875     checkAppearance(&opts->inactiveTitlebarAppearance, opts);
0876     checkAppearance(&opts->titlebarButtonAppearance, opts);
0877     checkAppearance(&opts->selectionAppearance, opts);
0878     checkAppearance(&opts->dwtAppearance, opts);
0879     checkAppearance(&opts->menuStripeAppearance, opts);
0880     checkAppearance(&opts->progressAppearance, opts);
0881     checkAppearance(&opts->progressGrooveAppearance, opts);
0882     checkAppearance(&opts->grooveAppearance, opts);
0883     checkAppearance(&opts->sunkenAppearance, opts);
0884     checkAppearance(&opts->sbarBgndAppearance, opts);
0885     checkAppearance(&opts->sliderFill, opts);
0886     checkAppearance(&opts->tooltipAppearance, opts);
0887 
0888     if(SHADE_BLEND_SELECTED==opts->shadeCheckRadio)
0889         opts->shadeCheckRadio=SHADE_SELECTED;
0890 
0891     checkColor(&opts->shadeMenubars, &opts->customMenubarsColor);
0892     checkColor(&opts->shadeSliders, &opts->customSlidersColor);
0893     checkColor(&opts->shadeCheckRadio, &opts->customCheckRadioColor);
0894     checkColor(&opts->menuStripe, &opts->customMenuStripeColor);
0895     checkColor(&opts->comboBtn, &opts->customComboBtnColor);
0896     checkColor(&opts->sortedLv, &opts->customSortedLvColor);
0897     if(APPEARANCE_BEVELLED==opts->toolbarAppearance)
0898         opts->toolbarAppearance=APPEARANCE_GRADIENT;
0899     else if(APPEARANCE_RAISED==opts->toolbarAppearance)
0900         opts->toolbarAppearance=APPEARANCE_FLAT;
0901 
0902     if(APPEARANCE_BEVELLED==opts->menubarAppearance)
0903         opts->menubarAppearance=APPEARANCE_GRADIENT;
0904     else if(APPEARANCE_RAISED==opts->menubarAppearance)
0905         opts->menubarAppearance=APPEARANCE_FLAT;
0906 
0907     if(APPEARANCE_BEVELLED==opts->sliderAppearance)
0908         opts->sliderAppearance=APPEARANCE_GRADIENT;
0909 
0910     if(APPEARANCE_BEVELLED==opts->tabAppearance)
0911         opts->tabAppearance=APPEARANCE_GRADIENT;
0912 
0913     if(APPEARANCE_BEVELLED==opts->activeTabAppearance)
0914         opts->activeTabAppearance=APPEARANCE_GRADIENT;
0915 
0916     if(APPEARANCE_RAISED==opts->selectionAppearance)
0917         opts->selectionAppearance=APPEARANCE_FLAT;
0918     else if(APPEARANCE_BEVELLED==opts->selectionAppearance)
0919         opts->selectionAppearance=APPEARANCE_GRADIENT;
0920 
0921     if(APPEARANCE_RAISED==opts->menuStripeAppearance)
0922         opts->menuStripeAppearance=APPEARANCE_FLAT;
0923     else if(APPEARANCE_BEVELLED==opts->menuStripeAppearance)
0924         opts->menuStripeAppearance=APPEARANCE_GRADIENT;
0925 
0926     if(opts->highlightFactor<MIN_HIGHLIGHT_FACTOR || opts->highlightFactor>MAX_HIGHLIGHT_FACTOR)
0927         opts->highlightFactor=DEFAULT_HIGHLIGHT_FACTOR;
0928 
0929     if(opts->crHighlight<MIN_HIGHLIGHT_FACTOR || opts->crHighlight>MAX_HIGHLIGHT_FACTOR)
0930         opts->crHighlight=DEFAULT_CR_HIGHLIGHT_FACTOR;
0931 
0932     if(opts->splitterHighlight<MIN_HIGHLIGHT_FACTOR || opts->splitterHighlight>MAX_HIGHLIGHT_FACTOR)
0933         opts->splitterHighlight=DEFAULT_SPLITTER_HIGHLIGHT_FACTOR;
0934 
0935 #if defined CONFIG_DIALOG
0936     if(opts->expanderHighlight<MIN_HIGHLIGHT_FACTOR || opts->expanderHighlight>MAX_HIGHLIGHT_FACTOR)
0937         opts->expanderHighlight=DEFAULT_EXPANDER_HIGHLIGHT_FACTOR;
0938 #endif
0939 
0940     if(0==opts->menuDelay) /* Qt seems to have issues if delay is 0 - so set this to 1 :-) */
0941         opts->menuDelay=MIN_MENU_DELAY;
0942     else if(opts->menuDelay<MIN_MENU_DELAY || opts->menuDelay>MAX_MENU_DELAY)
0943         opts->menuDelay=DEFAULT_MENU_DELAY;
0944 
0945     if(opts->menuCloseDelay<MIN_MENU_CLOSE_DELAY || opts->menuCloseDelay>MAX_MENU_CLOSE_DELAY)
0946         opts->menuCloseDelay=DEFAULT_MENU_CLOSE_DELAY;
0947 
0948     if(0==opts->sliderWidth%2)
0949         opts->sliderWidth++;
0950 
0951     if(opts->sliderWidth<MIN_SLIDER_WIDTH || opts->sliderWidth>MAX_SLIDER_WIDTH)
0952         opts->sliderWidth=DEFAULT_SLIDER_WIDTH;
0953 
0954     if(opts->sliderWidth<MIN_SLIDER_WIDTH_ROUND)
0955         opts->square|=SQUARE_SB_SLIDER;
0956 
0957     if(opts->sliderWidth<MIN_SLIDER_WIDTH_THIN_GROOVE)
0958         opts->thinSbarGroove=false;
0959 
0960     if(opts->sliderWidth<DEFAULT_SLIDER_WIDTH)
0961         opts->sliderThumbs=LINE_NONE;
0962 
0963     if(opts->lighterPopupMenuBgnd<MIN_LIGHTER_POPUP_MENU || opts->lighterPopupMenuBgnd>MAX_LIGHTER_POPUP_MENU)
0964         opts->lighterPopupMenuBgnd=DEF_POPUPMENU_LIGHT_FACTOR;
0965 
0966     if(opts->tabBgnd<MIN_TAB_BGND || opts->tabBgnd>MAX_TAB_BGND)
0967         opts->tabBgnd=DEF_TAB_BGND;
0968 
0969     if(opts->animatedProgress && !opts->stripedProgress)
0970         opts->animatedProgress=false;
0971 
0972     if(0==opts->gbFactor && FRAME_SHADED==opts->groupBox)
0973         opts->groupBox=FRAME_PLAIN;
0974 
0975     if(opts->gbFactor<MIN_GB_FACTOR || opts->gbFactor>MAX_GB_FACTOR)
0976         opts->gbFactor=DEF_GB_FACTOR;
0977 
0978     if(!opts->gtkComboMenus)
0979         opts->doubleGtkComboArrow=false;
0980 
0981     /* For now, only 2 sizes... */
0982     if(opts->crSize!=CR_SMALL_SIZE && opts->crSize!=CR_LARGE_SIZE)
0983         opts->crSize=CR_SMALL_SIZE;
0984 
0985 /*
0986 ??
0987     if(SHADE_CUSTOM==opts->shadeMenubars || SHADE_BLEND_SELECTED==opts->shadeMenubars || !opts->borderMenuitems)
0988         opts->colorMenubarMouseOver=true;
0989 */
0990 
0991 #ifndef CONFIG_DIALOG
0992     if(MO_GLOW==opts->coloredMouseOver && EFFECT_NONE==opts->buttonEffect)
0993         opts->coloredMouseOver=MO_COLORED_THICK;
0994 
0995     if(IND_GLOW==opts->defBtnIndicator && EFFECT_NONE==opts->buttonEffect)
0996         opts->defBtnIndicator=IND_TINT;
0997 
0998     if(opts->round>ROUND_EXTRA && FOCUS_GLOW!=opts->focus)
0999         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 
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                 QString gradKey;
1390                 QTextStream(&gradKey) << "customgradient" << i - APPEARANCE_CUSTOM1 + 1;
1391 
1392                 QStringList vals(readStringEntry(cfg, gradKey)
1393                                  .split(',', QString::SkipEmptyParts));
1394 
1395                 if(vals.size())
1396                     opts->customGradient.erase((EAppearance)i);
1397 
1398                 if(vals.size()>=5)
1399                 {
1400                     QStringList::ConstIterator it(vals.begin()),
1401                                                end(vals.end());
1402                     bool                       ok(true),
1403                                                haveAlpha(false);
1404                     Gradient                   grad;
1405                     int                        j;
1406 
1407                     grad.border=toGradientBorder(TO_LATIN1((*it)), &haveAlpha);
1408                     ok=vals.size()%(haveAlpha ? 3 : 2);
1409 
1410                     for(++it, j=0; it!=end && ok; ++it, ++j)
1411                     {
1412                         double pos=(*it).toDouble(&ok),
1413                                val=ok ? (*(++it)).toDouble(&ok) : 0.0,
1414                                alpha=haveAlpha && ok ? (*(++it)).toDouble(&ok) : 1.0;
1415 
1416                         ok=ok && (pos>=0 && pos<=1.0) && (val>=0.0 && val<=2.0) && (alpha>=0.0 && alpha<=1.0);
1417 
1418                         if(ok)
1419                             grad.stops.insert(GradientStop(pos, val, alpha));
1420                     }
1421 
1422                     if(ok)
1423                     {
1424                         opts->customGradient[(EAppearance)i]=grad;
1425                         opts->customGradient[(EAppearance)i].stops=grad.stops.fix();
1426                     }
1427                 }
1428             }
1429             qtcCheckConfig(opts);
1430             return true;
1431         } else {
1432             if(defOpts)
1433                 *opts=*defOpts;
1434             else
1435                 qtcDefaultSettings(opts);
1436             return true;
1437         }
1438     }
1439     return false;
1440 }
1441 
1442 static const char * getSystemConfigFile()
1443 {
1444     static const char * constFiles[]={
1445         /*"/etc/qt4/" OLD_CONFIG_FILE,
1446           "/etc/qt/" OLD_CONFIG_FILE,
1447         */
1448         "/etc/" OLD_CONFIG_FILE,
1449         nullptr
1450     };
1451 
1452     int i;
1453 
1454     for(i=0; constFiles[i]; ++i)
1455         if(QtCurve::isRegFile(constFiles[i]))
1456             return constFiles[i];
1457     return nullptr;
1458 }
1459 
1460 void qtcDefaultSettings(Options *opts)
1461 {
1462     /* Set hard-coded defaults... */
1463     // Setup titlebar gradients...
1464     qtcSetupGradient(&opts->customGradient[APPEARANCE_CUSTOM1], GB_3D, 3,
1465                      0.0, 1.2, 0.5, 1.0, 1.0, 1.0);
1466     qtcSetupGradient(&opts->customGradient[APPEARANCE_CUSTOM2], GB_3D, 3,
1467                      0.0, 0.9, 0.5, 1.0, 1.0, 1.0);
1468     opts->customShades[0] = 1.16;
1469     opts->customShades[1] = 1.07;
1470     opts->customShades[2] = 0.9;
1471     opts->customShades[3] = 0.78;
1472     opts->customShades[4] = 0.84;
1473     opts->customShades[5] = 0.75;
1474     opts->customAlphas[0] = 0;
1475     opts->contrast = 7;
1476     opts->passwordChar = 0x25CF;
1477     opts->gbFactor = DEF_GB_FACTOR;
1478     opts->highlightFactor=DEFAULT_HIGHLIGHT_FACTOR;
1479     opts->crHighlight=DEFAULT_CR_HIGHLIGHT_FACTOR;
1480     opts->splitterHighlight=DEFAULT_SPLITTER_HIGHLIGHT_FACTOR;
1481     opts->crSize=CR_LARGE_SIZE;
1482     opts->menuDelay=DEFAULT_MENU_DELAY;
1483     opts->menuCloseDelay=DEFAULT_MENU_CLOSE_DELAY;
1484     opts->sliderWidth=DEFAULT_SLIDER_WIDTH;
1485     opts->selectionAppearance=APPEARANCE_HARSH_GRADIENT;
1486     opts->fadeLines=true;
1487     opts->glowProgress=GLOW_NONE;
1488     opts->round=ROUND_EXTRA;
1489     opts->gtkButtonOrder=false;
1490     opts->dwtAppearance=APPEARANCE_CUSTOM1;
1491     opts->reorderGtkButtons=false;
1492     opts->bgndImage.type=IMG_NONE;
1493     opts->bgndImage.width=opts->bgndImage.height=0;
1494     opts->bgndImage.onBorder=false;
1495     opts->bgndImage.pos=PP_TR;
1496     opts->menuBgndImage.type=IMG_NONE;
1497     opts->menuBgndImage.width=opts->menuBgndImage.height=0;
1498     opts->menuBgndImage.onBorder=false;
1499     opts->menuBgndImage.pos=PP_TR;
1500     opts->lighterPopupMenuBgnd=DEF_POPUPMENU_LIGHT_FACTOR;
1501     opts->tabBgnd=DEF_TAB_BGND;
1502     opts->animatedProgress=false;
1503     opts->stripedProgress=STRIPE_NONE;
1504     opts->sliderStyle=SLIDER_PLAIN;
1505     opts->highlightTab=false;
1506     opts->colorSelTab=0;
1507     opts->roundAllTabs=true;
1508     opts->tabMouseOver=TAB_MO_GLOW;
1509     opts->embolden=false;
1510     opts->bgndGrad=GT_HORIZ;
1511     opts->menuBgndGrad=GT_HORIZ;
1512     opts->appearance=APPEARANCE_SOFT_GRADIENT;
1513     opts->tbarBtnAppearance=APPEARANCE_NONE;
1514     opts->tbarBtnEffect=EFFECT_NONE;
1515     opts->bgndAppearance=APPEARANCE_FLAT;
1516     opts->menuBgndAppearance=APPEARANCE_FLAT;
1517     opts->lvAppearance=APPEARANCE_BEVELLED;
1518     opts->tabAppearance=APPEARANCE_SOFT_GRADIENT;
1519     opts->activeTabAppearance=APPEARANCE_SOFT_GRADIENT;
1520     opts->sliderAppearance=APPEARANCE_SOFT_GRADIENT;
1521     opts->menubarAppearance=APPEARANCE_FLAT;
1522     opts->menuitemAppearance=APPEARANCE_FADE;
1523     opts->toolbarAppearance=APPEARANCE_FLAT;
1524     opts->progressAppearance=APPEARANCE_DULL_GLASS;
1525     opts->progressGrooveAppearance=APPEARANCE_INVERTED;
1526     opts->progressGrooveColor=ECOLOR_DARK;
1527     opts->grooveAppearance=APPEARANCE_INVERTED;
1528     opts->sunkenAppearance=APPEARANCE_SOFT_GRADIENT;
1529     opts->sbarBgndAppearance=APPEARANCE_FLAT;
1530     opts->tooltipAppearance=APPEARANCE_GRADIENT;
1531     opts->sliderFill=APPEARANCE_GRADIENT;
1532     opts->defBtnIndicator=IND_GLOW;
1533     opts->sliderThumbs=LINE_FLAT;
1534     opts->handles=LINE_1DOT;
1535     opts->shadeSliders=SHADE_NONE;
1536     opts->shadeMenubars=SHADE_NONE;
1537     opts->shadeCheckRadio=SHADE_NONE;
1538     opts->sortedLv=SHADE_NONE;
1539     opts->toolbarBorders=TB_NONE;
1540     opts->toolbarSeparators=LINE_SUNKEN;
1541     opts->splitters=LINE_1DOT;
1542     opts->customMenuTextColor=false;
1543     opts->coloredMouseOver=MO_GLOW;
1544     opts->menubarMouseOver=true;
1545     opts->useHighlightForMenu=false;
1546     opts->shadeMenubarOnlyWhenActive=false;
1547     opts->thin=THIN_BUTTONS;
1548     opts->tbarBtns=TBTN_STANDARD;
1549     opts->scrollbarType=SCROLLBAR_KDE;
1550     opts->buttonEffect=EFFECT_SHADOW;
1551     opts->focus=FOCUS_GLOW;
1552     opts->lvButton=false;
1553     opts->lvLines=false; /*LV_NONE;*/
1554     opts->drawStatusBarFrames=false;
1555     opts->fillSlider=true;
1556     opts->roundMbTopOnly=true;
1557     opts->borderMenuitems=false;
1558     opts->darkerBorders=false;
1559     opts->vArrows=true;
1560     opts->xCheck=false;
1561     opts->colorMenubarMouseOver=true;
1562     opts->crButton=true;
1563     opts->crColor=SHADE_NONE;
1564     opts->progressColor=SHADE_SELECTED;
1565     opts->smallRadio=true;
1566     opts->fillProgress=true;
1567     opts->comboSplitter=false;
1568     opts->highlightScrollViews=false;
1569     opts->etchEntry=false;
1570     opts->flatSbarButtons=true;
1571     opts->borderSbarGroove=true;
1572     opts->borderProgress=true;
1573     opts->popupBorder=true;
1574     opts->unifySpinBtns=false;
1575     opts->unifySpin=true;
1576     opts->unifyCombo=true;
1577     opts->borderTab=true;
1578     opts->borderInactiveTab=false;
1579     opts->thinSbarGroove=true;
1580     opts->colorSliderMouseOver=false;
1581     opts->menuIcons=true;
1582     opts->forceAlternateLvCols=false;
1583     opts->invertBotTab=true;
1584     opts->menubarHiding=HIDE_NONE;
1585     opts->statusbarHiding=HIDE_NONE;
1586     opts->boldProgress=true;
1587     opts->coloredTbarMo=false;
1588     opts->borderSelection=false;
1589     opts->square=SQUARE_POPUP_MENUS|SQUARE_TOOLTIPS;
1590     opts->stripedSbar=false;
1591     opts->windowDrag=WM_DRAG_NONE;
1592     opts->shadePopupMenu=false;
1593     opts->hideShortcutUnderline=false;
1594     opts->windowBorder=WINDOW_BORDER_ADD_LIGHT_BORDER|WINDOW_BORDER_FILL_TITLEBAR;
1595     opts->groupBox=FRAME_FADED;
1596     opts->gbFactor=DEF_GB_FACTOR;
1597     opts->gbLabel=GB_LBL_BOLD|GB_LBL_OUTSIDE;
1598     opts->stdBtnSizes=false;
1599     opts->titlebarButtons=TITLEBAR_BUTTON_ROUND|TITLEBAR_BUTTON_HOVER_SYMBOL;
1600     opts->titlebarIcon=TITLEBAR_ICON_NEXT_TO_TITLE;
1601     opts->menuStripe=SHADE_NONE;
1602     opts->menuStripeAppearance=APPEARANCE_DARK_INVERTED;
1603     opts->shading=Shading::HSL;
1604     opts->gtkScrollViews=true;
1605     opts->comboBtn=SHADE_NONE;
1606     opts->doubleGtkComboArrow=true;
1607     opts->stdSidebarButtons=false;
1608     opts->toolbarTabs=false;
1609     opts->bgndOpacity=opts->dlgOpacity=opts->menuBgndOpacity=100;
1610     opts->shadowSize = qtcX11ShadowSize();
1611     opts->gtkComboMenus=false;
1612     opts->customMenubarsColor.setRgb(0, 0, 0);
1613     opts->customSlidersColor.setRgb(0, 0, 0);
1614     opts->customMenuNormTextColor.setRgb(0, 0, 0);
1615     opts->customMenuSelTextColor.setRgb(0, 0, 0);
1616     opts->customCheckRadioColor.setRgb(0, 0, 0);
1617     opts->customComboBtnColor.setRgb(0, 0, 0);
1618     opts->customMenuStripeColor.setRgb(0, 0, 0);
1619     opts->customProgressColor.setRgb(0, 0, 0);
1620     opts->titlebarAlignment=ALIGN_FULL_CENTER;
1621     opts->titlebarEffect=EFFECT_SHADOW;
1622     opts->centerTabText=false;
1623     opts->dwtSettings=DWT_BUTTONS_AS_PER_TITLEBAR|DWT_ROUND_TOP_ONLY;
1624     opts->menubarApps << "smplayer" << "VirtualBox";
1625     opts->statusbarApps << "kde";
1626     opts->noMenuBgndOpacityApps << "sonata" << "totem" << "vmware"
1627                                 << "vmplayer" << "gtk";
1628     opts->noBgndOpacityApps << "smplayer" << "sonata" << "totem" << "vmware"
1629                             << "vmplayer";
1630     opts->noMenuStripeApps << "gtk" << "soffice.bin";
1631 
1632     opts->mapKdeIcons=true;
1633     opts->expanderHighlight=DEFAULT_EXPANDER_HIGHLIGHT_FACTOR;
1634     opts->titlebarAppearance=APPEARANCE_CUSTOM1;
1635     opts->inactiveTitlebarAppearance=APPEARANCE_CUSTOM1;
1636     opts->titlebarButtonAppearance=APPEARANCE_GRADIENT;
1637 #ifdef Q_OS_MACOS
1638     opts->onlyTicksInMenu=true;
1639     opts->buttonStyleMenuSections=false;
1640 #else
1641     opts->onlyTicksInMenu=false;
1642     opts->buttonStyleMenuSections=true;
1643 #endif
1644 
1645     /* Read system config file... */
1646     {
1647     static const char * systemFilename=nullptr;
1648 
1649     if(!systemFilename)
1650         systemFilename=getSystemConfigFile();
1651 
1652     if(systemFilename)
1653         qtcReadConfig(systemFilename, opts, opts);
1654     }
1655 }
1656 
1657 #ifdef CONFIG_WRITE
1658 #include <KConfigCore/KConfig>
1659 #include <KConfigCore/KConfigGroup>
1660 
1661 static const char*
1662 toStr(EDefBtnIndicator ind)
1663 {
1664     switch (ind) {
1665     case IND_NONE:
1666         return "none";
1667     case IND_FONT_COLOR:
1668         return "fontcolor";
1669     case IND_CORNER:
1670         return "corner";
1671     case IND_TINT:
1672         return "tint";
1673     case IND_GLOW:
1674         return "glow";
1675     case IND_DARKEN:
1676         return "darken";
1677     case IND_SELECTED:
1678         return "origselected";
1679     default:
1680         return "colored";
1681     }
1682 }
1683 
1684 static const char *toStr(ELine ind, bool dashes)
1685 {
1686     switch(ind)
1687     {
1688         case LINE_1DOT:
1689             return "1dot";
1690         case LINE_DOTS:
1691             return "dots";
1692         case LINE_DASHES:
1693             return dashes ? "dashes" : "none";
1694         case LINE_NONE:
1695             return "none";
1696         case LINE_FLAT:
1697             return "flat";
1698         default:
1699             return "sunken";
1700     }
1701 }
1702 
1703 static const char *toStr(ETBarBorder ind)
1704 {
1705     switch(ind)
1706     {
1707         case TB_DARK:
1708             return "dark";
1709         case TB_DARK_ALL:
1710             return "dark-all";
1711         case TB_LIGHT_ALL:
1712             return "light-all";
1713         case TB_NONE:
1714             return "none";
1715         default:
1716             return "light";
1717     }
1718 }
1719 
1720 static const char *toStr(EMouseOver mo)
1721 {
1722     switch(mo)
1723     {
1724         case MO_COLORED:
1725             return "colored";
1726         case MO_COLORED_THICK:
1727             return "thickcolored";
1728         case MO_NONE:
1729             return "none";
1730         case MO_GLOW:
1731             return "glow";
1732         default:
1733             return "plastik";
1734     }
1735 }
1736 
1737 static QString toStr(EAppearance exp, EAppAllow allow, const QtCPixmap *pix)
1738 {
1739     switch (exp) {
1740     case APPEARANCE_FLAT:
1741         return "flat";
1742     case APPEARANCE_RAISED:
1743         return "raised";
1744     case APPEARANCE_DULL_GLASS:
1745         return "dullglass";
1746     case APPEARANCE_SHINY_GLASS:
1747         return "shinyglass";
1748     case APPEARANCE_AGUA:
1749         return "agua";
1750     case APPEARANCE_SOFT_GRADIENT:
1751         return "soft";
1752     case APPEARANCE_GRADIENT:
1753         return "gradient";
1754     case APPEARANCE_HARSH_GRADIENT:
1755         return "harsh";
1756     case APPEARANCE_INVERTED:
1757         return "inverted";
1758     case APPEARANCE_DARK_INVERTED:
1759         return "darkinverted";
1760     case APPEARANCE_SPLIT_GRADIENT:
1761         return "splitgradient";
1762     case APPEARANCE_BEVELLED:
1763         return "bevelled";
1764     case APPEARANCE_FILE:
1765         // When savng, strip users config dir from location.
1766         return QLatin1String("file:")+
1767             (pix->file.startsWith(QtCurve::getConfDir())
1768              ? pix->file.mid(strlen(QtCurve::getConfDir())+1)
1769              : pix->file);
1770     case APPEARANCE_FADE:
1771         switch (allow) {
1772         case APP_ALLOW_BASIC: // Should not get here!
1773         case APP_ALLOW_FADE:
1774             return "fade";
1775         case APP_ALLOW_STRIPED:
1776             return "striped";
1777         case APP_ALLOW_NONE:
1778         default:
1779             return "none";
1780         }
1781     default: {
1782         QString app;
1783         QTextStream(&app) << "customgradient" << exp - APPEARANCE_CUSTOM1 + 1;
1784         return app;
1785     }
1786     }
1787 }
1788 
1789 static QString toStr(const QColor &col)
1790 {
1791     return QStringLiteral("#%1%2%3")
1792         .arg(col.red(), 2, 16, QLatin1Char('0'))
1793         .arg(col.green(), 2, 16, QLatin1Char('0'))
1794         .arg(col.blue(), 2, 16, QLatin1Char('0')).toUpper();
1795 }
1796 
1797 static QString toStr(EShade exp, const QColor &col)
1798 {
1799     switch(exp)
1800     {
1801         default:
1802         case SHADE_NONE:
1803             return "none";
1804         case SHADE_BLEND_SELECTED:
1805             return "selected";
1806         case SHADE_CUSTOM:
1807             return toStr(col);
1808         case SHADE_SELECTED:
1809             return "origselected";
1810         case SHADE_DARKEN:
1811             return "darken";
1812         case SHADE_WINDOW_BORDER:
1813             return "wborder";
1814     }
1815 }
1816 
1817 static const char *toStr(ERound exp)
1818 {
1819     switch(exp)
1820     {
1821         case ROUND_NONE:
1822             return "none";
1823         case ROUND_SLIGHT:
1824             return "slight";
1825         case ROUND_EXTRA:
1826             return "extra";
1827         case ROUND_MAX:
1828             return "max";
1829         default:
1830         case ROUND_FULL:
1831             return "full";
1832     }
1833 }
1834 
1835 static const char *toStr(EScrollbar sb)
1836 {
1837     switch(sb)
1838     {
1839         case SCROLLBAR_KDE:
1840             return "kde";
1841         default:
1842         case SCROLLBAR_WINDOWS:
1843             return "windows";
1844         case SCROLLBAR_PLATINUM:
1845             return "platinum";
1846         case SCROLLBAR_NEXT:
1847             return "next";
1848         case SCROLLBAR_NONE:
1849             return "none";
1850     }
1851 }
1852 
1853 static const char *toStr(EFrame sb)
1854 {
1855     switch(sb)
1856     {
1857         case FRAME_NONE:
1858             return "none";
1859         case FRAME_PLAIN:
1860             return "plain";
1861         case FRAME_LINE:
1862             return "line";
1863         case FRAME_SHADED:
1864             return "shaded";
1865         case FRAME_FADED:
1866         default:
1867             return "faded";
1868     }
1869 }
1870 
1871 static const char *toStr(EEffect e)
1872 {
1873     switch(e)
1874     {
1875         case EFFECT_NONE:
1876             return "none";
1877         default:
1878         case EFFECT_SHADOW:
1879             return "shadow";
1880         case EFFECT_ETCH:
1881             return "etch";
1882     }
1883 }
1884 
1885 inline const char * toStr(bool b) { return b ? "true" : "false"; }
1886 
1887 static const char *toStr(Shading s)
1888 {
1889     switch (s) {
1890     case Shading::Simple:
1891         return "simple";
1892     default:
1893     case Shading::HSL:
1894         return "hsl";
1895     case Shading::HSV:
1896         return "hsv";
1897     case Shading::HCY:
1898         return "hcy";
1899     }
1900 }
1901 
1902 static const char *toStr(EStripe s)
1903 {
1904     switch(s)
1905     {
1906         default:
1907         case STRIPE_PLAIN:
1908             return "plain";
1909         case STRIPE_NONE:
1910             return "none";
1911         case STRIPE_DIAGONAL:
1912             return "diagonal";
1913         case STRIPE_FADE:
1914             return "fade";
1915     }
1916 }
1917 
1918 static const char *toStr(ESliderStyle s)
1919 {
1920     switch(s)
1921     {
1922         case SLIDER_PLAIN:
1923             return "plain";
1924         case SLIDER_TRIANGULAR:
1925             return "triangular";
1926         case SLIDER_ROUND_ROTATED:
1927             return "r-round";
1928         case SLIDER_PLAIN_ROTATED:
1929             return "r-plain";
1930         case SLIDER_CIRCULAR:
1931             return "circular";
1932         default:
1933         case SLIDER_ROUND:
1934             return "round";
1935     }
1936 }
1937 
1938 static const char *toStr(EColor s)
1939 {
1940     switch(s)
1941     {
1942         case ECOLOR_BACKGROUND:
1943             return "background";
1944         case ECOLOR_DARK:
1945             return "dark";
1946         default:
1947         case ECOLOR_BASE:
1948             return "base";
1949     }
1950 }
1951 
1952 static const char *toStr(EFocus f)
1953 {
1954     switch(f)
1955     {
1956         default:
1957         case FOCUS_STANDARD:
1958             return "standard";
1959         case FOCUS_RECTANGLE:
1960             return "rect";
1961         case FOCUS_FILLED:
1962             return "filled";
1963         case FOCUS_FULL:
1964             return "full";
1965         case FOCUS_LINE:
1966             return "line";
1967         case FOCUS_GLOW:
1968             return "glow";
1969         case FOCUS_NONE:
1970             return "none";
1971     }
1972 }
1973 
1974 static const char *toStr(ETabMo f)
1975 {
1976     switch(f)
1977     {
1978         default:
1979         case TAB_MO_BOTTOM:
1980             return "bot";
1981         case TAB_MO_TOP:
1982             return "top";
1983         case TAB_MO_GLOW:
1984             return "glow";
1985     }
1986 }
1987 
1988 static const char *toStr(EGradientBorder g)
1989 {
1990     switch(g)
1991     {
1992         case GB_NONE:
1993             return "none";
1994         case GB_LIGHT:
1995             return "light";
1996         case GB_3D_FULL:
1997             return "3dfull";
1998         case GB_SHINE:
1999             return "shine";
2000         default:
2001         case GB_3D:
2002             return "3d";
2003     }
2004 }
2005 
2006 static const char *toStr(EAlign ind)
2007 {
2008     switch(ind)
2009     {
2010         default:
2011         case ALIGN_LEFT:
2012             return "left";
2013         case ALIGN_CENTER:
2014             return "center";
2015         case ALIGN_FULL_CENTER:
2016             return "center-full";
2017         case ALIGN_RIGHT:
2018             return "right";
2019     }
2020 }
2021 
2022 static const char * toStr(ETitleBarIcon icn)
2023 {
2024     switch(icn)
2025     {
2026         case TITLEBAR_ICON_NONE:
2027             return "none";
2028         default:
2029         case TITLEBAR_ICON_MENU_BUTTON:
2030             return "menu";
2031         case TITLEBAR_ICON_NEXT_TO_TITLE:
2032             return "title";
2033     }
2034 }
2035 
2036 static const char * toStr(EGradType gt)
2037 {
2038     switch(gt)
2039     {
2040         case GT_VERT:
2041             return "vert";
2042         default:
2043         case GT_HORIZ:
2044             return "horiz";
2045     }
2046 }
2047 
2048 #if 0
2049 static const char * toStr(ELvLines lv)
2050 {
2051     switch(lv)
2052     {
2053         case LV_NEW:
2054             return "new";
2055         case LV_OLD:
2056             return "old";
2057         default:
2058         case LV_NONE:
2059             return "none";
2060     }
2061 }
2062 #endif
2063 
2064 static const char * toStr(EImageType lv)
2065 {
2066     switch(lv)
2067     {
2068         default:
2069         case IMG_NONE:
2070             return "none";
2071         case IMG_PLAIN_RINGS:
2072             return "plainrings";
2073         case IMG_BORDERED_RINGS:
2074             return "rings";
2075         case IMG_SQUARE_RINGS:
2076             return "squarerings";
2077         case IMG_FILE:
2078             return "file";
2079     }
2080 }
2081 
2082 static const char * toStr(EGlow lv)
2083 {
2084     switch(lv)
2085     {
2086         default:
2087         case GLOW_NONE:
2088             return "none";
2089         case GLOW_START:
2090             return "start";
2091         case GLOW_MIDDLE:
2092             return "middle";
2093         case GLOW_END:
2094             return "end";
2095     }
2096 }
2097 
2098 static const char * toStr(ETBarBtn tb)
2099 {
2100     switch(tb)
2101     {
2102         default:
2103         case TBTN_STANDARD:
2104             return "standard";
2105         case TBTN_RAISED:
2106             return "raised";
2107         case TBTN_JOINED:
2108             return "joined";
2109     }
2110 }
2111 
2112 #define CFG config
2113 
2114 #define CFG_WRITE_ENTRY(ENTRY) do {                     \
2115         if (!exportingStyle && def.ENTRY == opts.ENTRY) \
2116             CFG.deleteEntry(#ENTRY);                    \
2117         else                                            \
2118             CFG.writeEntry(#ENTRY, toStr(opts.ENTRY));  \
2119     } while (0)
2120 
2121 #define CFG_WRITE_APPEARANCE_ENTRY(ENTRY, ALLOW) \
2122     if (!exportingStyle && def.ENTRY==opts.ENTRY) \
2123         CFG.deleteEntry(#ENTRY); \
2124     else \
2125         CFG.writeEntry(#ENTRY, toStr(opts.ENTRY, ALLOW, nullptr));
2126 
2127 #define CFG_WRITE_APPEARANCE_ENTRY_PIXMAP(ENTRY, ALLOW, PIXMAP) \
2128     if (!exportingStyle && def.ENTRY==opts.ENTRY) \
2129         CFG.deleteEntry(#ENTRY); \
2130     else \
2131         CFG.writeEntry(#ENTRY, toStr(opts.ENTRY, ALLOW, &opts.PIXMAP));
2132 
2133 #define CFG_WRITE_ENTRY_B(ENTRY, B) \
2134     if (!exportingStyle && def.ENTRY==opts.ENTRY) \
2135         CFG.deleteEntry(#ENTRY); \
2136     else \
2137         CFG.writeEntry(#ENTRY, toStr(opts.ENTRY, B));
2138 
2139 #define CFG_WRITE_ENTRY_NUM(ENTRY) \
2140     if (!exportingStyle && def.ENTRY==opts.ENTRY) \
2141         CFG.deleteEntry(#ENTRY); \
2142     else \
2143         CFG.writeEntry(#ENTRY, opts.ENTRY);
2144 
2145 #define CFG_WRITE_SHADE_ENTRY(ENTRY, COL) \
2146     if (!exportingStyle && def.ENTRY==opts.ENTRY) \
2147         CFG.deleteEntry(#ENTRY); \
2148     else \
2149         CFG.writeEntry(#ENTRY, toStr(opts.ENTRY, opts.COL));
2150 
2151 #define CFG_WRITE_IMAGE_ENTRY(ENTRY) \
2152     if (!exportingStyle && def.ENTRY.type==opts.ENTRY.type) \
2153         CFG.deleteEntry(#ENTRY); \
2154     else \
2155         CFG.writeEntry(#ENTRY, toStr(opts.ENTRY.type)); \
2156     if(IMG_FILE!=opts.ENTRY.type) \
2157     { \
2158         CFG.deleteEntry(#ENTRY ".file"); \
2159         CFG.deleteEntry(#ENTRY ".width"); \
2160         CFG.deleteEntry(#ENTRY ".height"); \
2161         CFG.deleteEntry(#ENTRY ".onBorder"); \
2162         CFG.deleteEntry(#ENTRY ".pos"); \
2163     } \
2164     else \
2165     { \
2166         CFG.writeEntry(#ENTRY ".file", opts.ENTRY.pixmap.file); \
2167         CFG.writeEntry(#ENTRY ".width", opts.ENTRY.width); \
2168         CFG.writeEntry(#ENTRY ".height", opts.ENTRY.height); \
2169         CFG.writeEntry(#ENTRY ".onBorder", opts.ENTRY.onBorder); \
2170         CFG.writeEntry(#ENTRY ".pos", (int)(opts.ENTRY.pos)); \
2171     }
2172 
2173 #define CFG_WRITE_STRING_LIST_ENTRY(ENTRY) \
2174     if (!exportingStyle && def.ENTRY==opts.ENTRY) \
2175         CFG.deleteEntry(#ENTRY); \
2176     else \
2177         CFG.writeEntry(#ENTRY, QStringList(opts.ENTRY.values()).join(",")); \
2178 
2179 bool qtcWriteConfig(KConfig *cfg, const Options &opts, const Options &def, bool exportingStyle)
2180 {
2181     if (!cfg) {
2182         const char *cfgDir=QtCurve::getConfDir();
2183 
2184         if (cfgDir) {
2185             KConfig defCfg(QFile::decodeName(cfgDir) +
2186                            CONFIG_FILE, KConfig::SimpleConfig);
2187 
2188             if (qtcWriteConfig(&defCfg, opts, def, exportingStyle)) {
2189                 const char *oldFiles[]={ OLD_CONFIG_FILE, "qtcurve.gtk-icons", 0};
2190 
2191                 for(int i=0; oldFiles[i]; ++i)
2192                 {
2193                     QString oldFileName(QFile::decodeName(cfgDir)+QString("../")+oldFiles[i]);
2194 
2195                     if(QFile::exists(oldFileName))
2196                         QFile::remove(oldFileName);
2197                 }
2198             }
2199         }
2200     }
2201     else
2202     {
2203         KConfigGroup config(cfg, SETTINGS_GROUP);
2204         CFG.writeEntry(VERSION_KEY, qtcVersion());
2205         CFG_WRITE_ENTRY_NUM(passwordChar);
2206         CFG_WRITE_ENTRY_NUM(gbFactor);
2207         CFG_WRITE_ENTRY(round);
2208         CFG_WRITE_ENTRY_NUM(highlightFactor);
2209         CFG_WRITE_ENTRY_NUM(menuDelay);
2210         CFG_WRITE_ENTRY_NUM(menuCloseDelay);
2211         CFG_WRITE_ENTRY_NUM(sliderWidth);
2212         CFG_WRITE_ENTRY(toolbarBorders);
2213         CFG_WRITE_APPEARANCE_ENTRY(appearance, APP_ALLOW_BASIC);
2214         CFG_WRITE_APPEARANCE_ENTRY(tbarBtnAppearance, APP_ALLOW_NONE);
2215         CFG_WRITE_ENTRY(tbarBtnEffect);
2216         CFG_WRITE_APPEARANCE_ENTRY_PIXMAP(bgndAppearance, APP_ALLOW_STRIPED,
2217                                           bgndPixmap);
2218         CFG_WRITE_ENTRY(bgndGrad);
2219         CFG_WRITE_ENTRY(menuBgndGrad);
2220         CFG_WRITE_APPEARANCE_ENTRY_PIXMAP(menuBgndAppearance, APP_ALLOW_STRIPED,
2221                                           menuBgndPixmap);
2222         CFG_WRITE_ENTRY(stripedProgress);
2223         CFG_WRITE_ENTRY(sliderStyle);
2224         CFG_WRITE_ENTRY(animatedProgress);
2225         CFG_WRITE_ENTRY_NUM(lighterPopupMenuBgnd);
2226         CFG_WRITE_ENTRY_NUM(tabBgnd);
2227         CFG_WRITE_ENTRY(embolden);
2228         CFG_WRITE_ENTRY(defBtnIndicator);
2229         CFG_WRITE_ENTRY_B(sliderThumbs, false);
2230         CFG_WRITE_ENTRY_B(handles, true);
2231         CFG_WRITE_ENTRY(highlightTab);
2232         CFG_WRITE_ENTRY_NUM(colorSelTab);
2233         CFG_WRITE_ENTRY(roundAllTabs);
2234         CFG_WRITE_ENTRY(tabMouseOver);
2235         CFG_WRITE_APPEARANCE_ENTRY(menubarAppearance, APP_ALLOW_BASIC);
2236         CFG_WRITE_APPEARANCE_ENTRY(menuitemAppearance, APP_ALLOW_FADE);
2237         CFG_WRITE_APPEARANCE_ENTRY(toolbarAppearance, APP_ALLOW_BASIC);
2238         CFG_WRITE_APPEARANCE_ENTRY(selectionAppearance, APP_ALLOW_BASIC);
2239         CFG_WRITE_APPEARANCE_ENTRY(dwtAppearance, APP_ALLOW_BASIC);
2240         CFG_WRITE_ENTRY(titlebarEffect);
2241         CFG_WRITE_APPEARANCE_ENTRY(menuStripeAppearance, APP_ALLOW_BASIC);
2242         CFG_WRITE_ENTRY_B(toolbarSeparators, false);
2243         CFG_WRITE_ENTRY_B(splitters, true);
2244         CFG_WRITE_ENTRY(customMenuTextColor);
2245         CFG_WRITE_ENTRY(coloredMouseOver);
2246         CFG_WRITE_ENTRY(menubarMouseOver);
2247         CFG_WRITE_ENTRY(useHighlightForMenu);
2248         CFG_WRITE_ENTRY(shadeMenubarOnlyWhenActive);
2249         CFG_WRITE_ENTRY_NUM(thin);
2250         CFG_WRITE_SHADE_ENTRY(shadeSliders, customSlidersColor);
2251         CFG_WRITE_SHADE_ENTRY(shadeMenubars, customMenubarsColor);
2252         CFG_WRITE_SHADE_ENTRY(sortedLv, customSortedLvColor);
2253         CFG_WRITE_ENTRY(customMenuSelTextColor);
2254         CFG_WRITE_ENTRY(customMenuNormTextColor);
2255         CFG_WRITE_SHADE_ENTRY(shadeCheckRadio, customCheckRadioColor);
2256         CFG_WRITE_ENTRY(scrollbarType);
2257         CFG_WRITE_ENTRY(buttonEffect);
2258         CFG_WRITE_APPEARANCE_ENTRY(lvAppearance, APP_ALLOW_BASIC);
2259         CFG_WRITE_APPEARANCE_ENTRY(tabAppearance, APP_ALLOW_BASIC);
2260         CFG_WRITE_APPEARANCE_ENTRY(activeTabAppearance, APP_ALLOW_BASIC);
2261         CFG_WRITE_APPEARANCE_ENTRY(sliderAppearance, APP_ALLOW_BASIC);
2262         CFG_WRITE_APPEARANCE_ENTRY(progressAppearance, APP_ALLOW_BASIC);
2263         CFG_WRITE_APPEARANCE_ENTRY(progressGrooveAppearance, APP_ALLOW_BASIC);
2264         CFG_WRITE_APPEARANCE_ENTRY(grooveAppearance, APP_ALLOW_BASIC);
2265         CFG_WRITE_APPEARANCE_ENTRY(sunkenAppearance, APP_ALLOW_BASIC);
2266         CFG_WRITE_APPEARANCE_ENTRY(sbarBgndAppearance, APP_ALLOW_BASIC);
2267         CFG_WRITE_APPEARANCE_ENTRY(tooltipAppearance, APP_ALLOW_BASIC);
2268         CFG_WRITE_ENTRY(sliderFill);
2269         CFG_WRITE_ENTRY(progressGrooveColor);
2270         CFG_WRITE_ENTRY(focus);
2271         CFG_WRITE_ENTRY(lvButton);
2272         CFG_WRITE_ENTRY(lvLines);
2273         CFG_WRITE_ENTRY(drawStatusBarFrames);
2274         CFG_WRITE_ENTRY(fillSlider);
2275         CFG_WRITE_ENTRY(roundMbTopOnly);
2276         CFG_WRITE_ENTRY(borderMenuitems);
2277         CFG_WRITE_ENTRY(darkerBorders);
2278         CFG_WRITE_ENTRY(vArrows);
2279         CFG_WRITE_ENTRY(xCheck);
2280         CFG_WRITE_ENTRY(groupBox);
2281         CFG_WRITE_ENTRY_NUM(gbLabel);
2282         CFG_WRITE_ENTRY(fadeLines);
2283         CFG_WRITE_ENTRY(glowProgress);
2284         CFG_WRITE_IMAGE_ENTRY(bgndImage);
2285         CFG_WRITE_IMAGE_ENTRY(menuBgndImage);
2286         CFG_WRITE_ENTRY(colorMenubarMouseOver);
2287         CFG_WRITE_ENTRY_NUM(crHighlight);
2288         CFG_WRITE_ENTRY(crButton);
2289         CFG_WRITE_SHADE_ENTRY(crColor, customCrBgndColor);
2290         CFG_WRITE_SHADE_ENTRY(progressColor, customProgressColor);
2291         CFG_WRITE_ENTRY(smallRadio);
2292         CFG_WRITE_ENTRY(fillProgress);
2293         CFG_WRITE_ENTRY(comboSplitter);
2294         CFG_WRITE_ENTRY(highlightScrollViews);
2295         CFG_WRITE_ENTRY(etchEntry);
2296         CFG_WRITE_ENTRY_NUM(splitterHighlight);
2297         CFG_WRITE_ENTRY_NUM(expanderHighlight);
2298         CFG_WRITE_ENTRY_NUM(crSize);
2299         CFG_WRITE_ENTRY(flatSbarButtons);
2300         CFG_WRITE_ENTRY(borderSbarGroove);
2301         CFG_WRITE_ENTRY(borderProgress);
2302         CFG_WRITE_ENTRY(popupBorder);
2303         CFG_WRITE_ENTRY(unifySpinBtns);
2304         CFG_WRITE_ENTRY(unifySpin);
2305         CFG_WRITE_ENTRY(unifyCombo);
2306         CFG_WRITE_ENTRY(borderTab);
2307         CFG_WRITE_ENTRY(borderInactiveTab);
2308         CFG_WRITE_ENTRY(thinSbarGroove);
2309         CFG_WRITE_ENTRY(colorSliderMouseOver);
2310         CFG_WRITE_ENTRY(menuIcons);
2311         CFG_WRITE_ENTRY(onlyTicksInMenu);
2312         CFG_WRITE_ENTRY(buttonStyleMenuSections);
2313         CFG_WRITE_ENTRY(forceAlternateLvCols);
2314         CFG_WRITE_ENTRY_NUM(square);
2315         CFG_WRITE_ENTRY(invertBotTab);
2316         CFG_WRITE_ENTRY_NUM(menubarHiding);
2317         CFG_WRITE_ENTRY_NUM(statusbarHiding);
2318         CFG_WRITE_ENTRY(boldProgress);
2319         CFG_WRITE_ENTRY(coloredTbarMo);
2320         CFG_WRITE_ENTRY(borderSelection);
2321         CFG_WRITE_ENTRY(stripedSbar);
2322         CFG_WRITE_ENTRY_NUM(windowDrag);
2323         CFG_WRITE_ENTRY(shadePopupMenu);
2324         CFG_WRITE_ENTRY(hideShortcutUnderline);
2325         CFG_WRITE_ENTRY_NUM(windowBorder);
2326         CFG_WRITE_ENTRY(tbarBtns);
2327         CFG_WRITE_ENTRY_NUM(dwtSettings);
2328         CFG_WRITE_ENTRY_NUM(bgndOpacity);
2329         CFG_WRITE_ENTRY_NUM(menuBgndOpacity);
2330         CFG_WRITE_ENTRY_NUM(dlgOpacity);
2331         CFG_WRITE_ENTRY_NUM(shadowSize);
2332         CFG_WRITE_ENTRY(stdBtnSizes);
2333         CFG_WRITE_ENTRY_NUM(titlebarButtons);
2334         CFG_WRITE_ENTRY(titlebarIcon);
2335 
2336         // Why would we only write the button colours when the info is actually being used? This
2337         // makes it impossible to deactivate the feature and then reactivate it without losing
2338         // custom colours.
2339         if (opts.titlebarButtonColors.size() && 0==(opts.titlebarButtonColors.size()%NUM_TITLEBAR_BUTTONS)) {
2340             QString     val;
2341             QTextStream str(&val);
2342             for(unsigned int i=0; i<opts.titlebarButtonColors.size(); ++i)
2343             {
2344                 TBCols::const_iterator c(opts.titlebarButtonColors.find((ETitleBarButtons)i));
2345 
2346                 if(c!=opts.titlebarButtonColors.end())
2347                 {
2348                     if(i)
2349                         str << ',';
2350                     str << toStr((*c).second);
2351                 }
2352             }
2353             CFG.writeEntry("titlebarButtonColors", val);
2354         }
2355         else
2356             CFG.deleteEntry("titlebarButtonColors");
2357         CFG_WRITE_SHADE_ENTRY(menuStripe, customMenuStripeColor);
2358         CFG_WRITE_SHADE_ENTRY(comboBtn, customComboBtnColor);
2359         CFG_WRITE_ENTRY(stdSidebarButtons);
2360         CFG_WRITE_ENTRY(toolbarTabs);
2361         CFG_WRITE_APPEARANCE_ENTRY(titlebarAppearance, APP_ALLOW_NONE);
2362         CFG_WRITE_APPEARANCE_ENTRY(inactiveTitlebarAppearance, APP_ALLOW_NONE);
2363         CFG_WRITE_APPEARANCE_ENTRY(titlebarButtonAppearance, APP_ALLOW_BASIC);
2364         CFG_WRITE_ENTRY(gtkScrollViews);
2365         CFG_WRITE_ENTRY(gtkComboMenus);
2366         CFG_WRITE_ENTRY(doubleGtkComboArrow);
2367         CFG_WRITE_ENTRY(gtkButtonOrder);
2368         CFG_WRITE_ENTRY(reorderGtkButtons);
2369         CFG_WRITE_ENTRY(mapKdeIcons);
2370         CFG_WRITE_ENTRY(shading);
2371         CFG_WRITE_ENTRY(titlebarAlignment);
2372         CFG_WRITE_ENTRY(centerTabText);
2373         CFG_WRITE_STRING_LIST_ENTRY(noBgndGradientApps);
2374         CFG_WRITE_STRING_LIST_ENTRY(noBgndOpacityApps);
2375         CFG_WRITE_STRING_LIST_ENTRY(noMenuBgndOpacityApps);
2376         CFG_WRITE_STRING_LIST_ENTRY(noBgndImageApps);
2377         CFG_WRITE_STRING_LIST_ENTRY(noMenuStripeApps);
2378         CFG_WRITE_STRING_LIST_ENTRY(menubarApps);
2379         CFG_WRITE_STRING_LIST_ENTRY(statusbarApps);
2380         CFG_WRITE_STRING_LIST_ENTRY(useQtFileDialogApps);
2381         CFG_WRITE_STRING_LIST_ENTRY(nonnativeMenubarApps);
2382 
2383         for (int i = APPEARANCE_CUSTOM1; i < APPEARANCE_CUSTOM1 + NUM_CUSTOM_GRAD; ++i) {
2384             GradientCont::const_iterator cg(opts.customGradient.find((EAppearance)i));
2385             QString gradKey;
2386 
2387             QTextStream(&gradKey) << "customgradient" << i - APPEARANCE_CUSTOM1 + 1;
2388 
2389             if (cg == opts.customGradient.end()) {
2390                 CFG.deleteEntry(gradKey);
2391             }
2392             else {
2393                 GradientCont::const_iterator d;
2394 
2395                 if(exportingStyle || (d=def.customGradient.find((EAppearance)i))==def.customGradient.end() || !((*d)==(*cg)))
2396                 {
2397                     QString     gradVal;
2398                     QTextStream str(&gradVal);
2399                     GradientStopCont                 stops((*cg).second.stops.fix());
2400                     GradientStopCont::const_iterator it(stops.begin()),
2401                                                      end(stops.end());
2402                     bool                             haveAlpha(false);
2403 
2404                     for(; it!=end && !haveAlpha; ++it)
2405                         if((*it).alpha<1.0)
2406                             haveAlpha=true;
2407 
2408                     str << toStr((*cg).second.border);
2409                     if(haveAlpha)
2410                         str << "-alpha";
2411 
2412                     for(it=stops.begin(); it!=end; ++it)
2413                         if(haveAlpha)
2414                             str << ',' << (*it).pos << ',' << (*it).val << ',' << (*it).alpha;
2415                         else
2416                             str << ',' << (*it).pos << ',' << (*it).val;
2417                     CFG.writeEntry(gradKey, gradVal);
2418                 }
2419                 else
2420                     CFG.deleteEntry(gradKey);
2421             }
2422         }
2423 
2424         if(opts.customShades[0]==0 ||
2425            exportingStyle ||
2426            opts.customShades[0]!=def.customShades[0] ||
2427            opts.customShades[1]!=def.customShades[1] ||
2428            opts.customShades[2]!=def.customShades[2] ||
2429            opts.customShades[3]!=def.customShades[3] ||
2430            opts.customShades[4]!=def.customShades[4] ||
2431            opts.customShades[5]!=def.customShades[5])
2432         {
2433             QString     shadeVal;
2434             QTextStream str(&shadeVal);
2435             if(0==opts.customShades[0])
2436                  str << 0;
2437             else
2438                 for(int i=0; i<QTC_NUM_STD_SHADES; ++i)
2439                     if(0==i)
2440                         str << opts.customShades[i];
2441                     else
2442                         str << ',' << opts.customShades[i];
2443             CFG.writeEntry("customShades", shadeVal);
2444         }
2445         else
2446             CFG.deleteEntry("customShades");
2447 
2448         if(opts.customAlphas[0]==0 ||
2449            exportingStyle ||
2450            opts.customAlphas[0]!=def.customAlphas[0] ||
2451            opts.customAlphas[1]!=def.customAlphas[1])
2452         {
2453             QString     shadeVal;
2454             QTextStream str(&shadeVal);
2455             if(0==opts.customAlphas[0])
2456                  str << 0;
2457             else
2458                 for(int i=0; i<NUM_STD_ALPHAS; ++i)
2459                     if(0==i)
2460                         str << opts.customAlphas[i];
2461                     else
2462                         str << ',' << opts.customAlphas[i];
2463             CFG.writeEntry("customAlphas", shadeVal);
2464         }
2465         else
2466             CFG.deleteEntry("customAlphas");
2467 
2468         // Removed from 1.5 onwards...
2469         CFG.deleteEntry("colorTitlebarOnly");
2470         CFG.deleteEntry("titlebarBorder");
2471         CFG.deleteEntry("titlebarBlend");
2472         // Removed from 1.4 onwards..
2473         CFG.deleteEntry("squareLvSelection");
2474         CFG.deleteEntry("squareScrollViews");
2475         CFG.deleteEntry("squareProgress");
2476         CFG.deleteEntry("squareEntry");
2477 
2478         cfg->sync();
2479         return true;
2480     }
2481     return false;
2482 }
2483 #endif