File: qtcurveconfig.cpp

package info (click to toggle)
qtcurve 1.9-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,468 kB
  • sloc: cpp: 70,269; perl: 123; sh: 122; xml: 46; makefile: 14
file content (152 lines) | stat: -rw-r--r-- 5,805 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*****************************************************************************
 *   Copyright 2010 Craig Drummond <craig.p.drummond@gmail.com>              *
 *   Copyright 2013 - 2015 Yichao Yu <yyc1992@gmail.com>                     *
 *                                                                           *
 *   This program is free software; you can redistribute it and/or modify    *
 *   it under the terms of the GNU Lesser General Public License as          *
 *   published by the Free Software Foundation; either version 2.1 of the    *
 *   License, or (at your option) version 3, or any later version accepted   *
 *   by the membership of KDE e.V. (or its successor approved by the         *
 *   membership of KDE e.V.), which shall act as a proxy defined in          *
 *   Section 6 of version 3 of the license.                                  *
 *                                                                           *
 *   This program is distributed in the hope that it will be useful,         *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       *
 *   Lesser General Public License for more details.                         *
 *                                                                           *
 *   You should have received a copy of the GNU Lesser General Public        *
 *   License along with this library. If not,                                *
 *   see <http://www.gnu.org/licenses/>.                                     *
 *****************************************************************************/

#include "qtcurveconfig.h"
#include <KConfigCore/KConfig>
#include <KConfigCore/KConfigGroup>

namespace QtCurve {
namespace KWin {

#define GROUP "General"

void QtCurveConfig::defaults()
{
    m_borderSize=BORDER_NORMAL;
    m_roundBottom=true;
    m_outerBorder=SHADE_NONE;
    m_innerBorder=SHADE_NONE;
    m_borderlessMax=false;
    m_customShadows=false;
    m_grouping=true;
    m_titleBarPad=0;
    m_activeOpacity=m_inactiveOpacity=100;
    m_opaqueBorder=true;
    m_edgePad=0;
}

#define READ_ENTRY(name, field) do {                    \
        field = group.readEntry(name, def.field);       \
    } while (0)

static QtCurveConfig::Shade readShade(KConfigGroup &group, const char *key)
{
    QString entry=group.readEntry(key, QString());

    if(entry.isEmpty() || QLatin1String("false")==entry)
        return QtCurveConfig::SHADE_NONE;
    if(QLatin1String("true")==entry)
        return QtCurveConfig::SHADE_DARK;
    int val=entry.toInt();
    if(val>QtCurveConfig::SHADE_NONE && val<=QtCurveConfig::SHADE_SHADOW)
        return (QtCurveConfig::Shade)val;
    return QtCurveConfig::SHADE_NONE;
}

void QtCurveConfig::load(const KConfig *cfg, const char *grp)
{
    KConfigGroup  group(cfg, grp ? grp : GROUP);
    QtCurveConfig def;

    if(group.hasKey("BorderSize"))
        m_borderSize=(Size)group.readEntry("BorderSize", (int)def.borderSize());
    else
    {
        KConfig      kwin("kwinrc");
        KConfigGroup style(&kwin, "Style");
        int          size=style.readEntry("BorderSize", 1);

        if(0==size) // KDecorationDefines::BorderTiny
        {
            if(group.readEntry("DrawBottom", false))
                m_borderSize=BORDER_NO_SIDES;
            else
                m_borderSize=BORDER_NONE;
        }
        else
            m_borderSize=(Size)(size+2);
    }

    if(m_borderSize<BORDER_NONE || m_borderSize>BORDER_OVERSIZED)
        m_borderSize=BORDER_NORMAL;
    READ_ENTRY("BorderlessMax", m_borderlessMax);
    READ_ENTRY("CustomShadows", m_customShadows);
    READ_ENTRY("Grouping", m_grouping);
    READ_ENTRY("TitleBarPad", m_titleBarPad);
    READ_ENTRY("ActiveOpacity", m_activeOpacity);
    READ_ENTRY("InactiveOpacity", m_inactiveOpacity);
    READ_ENTRY("OpaqueBorder", m_opaqueBorder);
    READ_ENTRY("EdgePad", m_edgePad);

    if(m_titleBarPad<-5 || m_titleBarPad>10)
        m_titleBarPad=0;
    if(m_edgePad<0 || m_edgePad>10)
        m_edgePad=0;
    if(BORDER_NONE==m_borderSize)
        m_roundBottom=false;
    else
        READ_ENTRY("RoundBottom", m_roundBottom);

    m_outerBorder=readShade(group, "OuterBorder");
    if(m_borderSize<BORDER_TINY || SHADE_NONE==m_outerBorder)
        m_innerBorder=SHADE_NONE;
    else
        m_innerBorder=readShade(group, "InnerBorder");

    if(m_activeOpacity<0 || m_activeOpacity>100)
        m_activeOpacity=100;
    if(m_inactiveOpacity<0 || m_inactiveOpacity>100)
        m_inactiveOpacity=100;
}

#define WRITE_ENTRY(name, field) do {           \
        if (def.field == field) {               \
            group.deleteEntry(name);            \
        } else {                                \
            group.writeEntry(name, field);      \
        }                                       \
    } while (0)

void QtCurveConfig::save(KConfig *cfg, const char *grp)
{
    KConfigGroup  group(cfg, grp ? grp : GROUP);
    QtCurveConfig def;

    //WRITE_ENTRY("BorderSize", m_borderSize);
    // Have to write BorderSize, because if not found we read the kwin setting - to be
    // compatible with QtCurve<1.4
    group.writeEntry("BorderSize", m_borderSize);
    WRITE_ENTRY("RoundBottom", m_roundBottom);
    group.writeEntry("OuterBorder", (int)m_outerBorder);
    group.writeEntry("InnerBorder", (int)m_innerBorder);
    WRITE_ENTRY("BorderlessMax", m_borderlessMax);
    WRITE_ENTRY("CustomShadows", m_customShadows);
    WRITE_ENTRY("Grouping", m_grouping);
    WRITE_ENTRY("TitleBarPad", m_titleBarPad);
    WRITE_ENTRY("ActiveOpacity", m_activeOpacity);
    WRITE_ENTRY("InactiveOpacity", m_inactiveOpacity);
    WRITE_ENTRY("OpaqueBorder", m_opaqueBorder);
    WRITE_ENTRY("EdgePad", m_edgePad);
}

}
}