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

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