summaryrefslogtreecommitdiffstats
path: root/src/config/config.cpp
blob: 7372eb75dc4a8da5e42ec4d730327ba529367176 (plain)
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/* SUSE2 KWin window decoration
  Copyright (C) 2005 Gerd Fleischer <gerdfleischer@web.de>

  based on the window decoration "Plastik"
  Copyright (C) 2003 Sandro Giessl <ceebx@users.sourceforge.net>

  based on the window decoration "Web":
  Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org>

  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public
  License as published by the Free Software Foundation; either
  version 2 of the License, or (at your option) any later version.

  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
  General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; see the file COPYING.  If not, write to
  the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  Boston, MA  02110-1301  USA.
*/

//#include <kdebug.h>

#include <tqbuttongroup.h>
#include <tqcheckbox.h>
#include <tqradiobutton.h>
#include <tqslider.h>
#include <tqspinbox.h>
#include <tqwhatsthis.h>
#include <tqimage.h>
#include <tqlabel.h>
#include <tqcombobox.h>

#include <tdeversion.h>
#include <tdeconfig.h>
#include <tdelocale.h>
#include <tdeglobal.h>
#include <kurlrequester.h>
#include <kstandarddirs.h>
#include <kurl.h>
#include <tdefiledialog.h>
#include <knuminput.h>
#include <tdefileitem.h>
#include <kcolorbutton.h>

#include "config.h"
#include "configdialog.h"

SUSE2Config::SUSE2Config(TDEConfig *config, TQWidget *parent)
    : TQObject(parent), m_config(0), m_dialog(0)
{
    m_parent = parent;
    // create the configuration object
    m_config = new TDEConfig("twinSUSE2rc");
    TDEGlobal::locale()->insertCatalogue("twin_clients");
    TDEGlobal::locale()->insertCatalogue("twin-style-suse2");

    // create and show the configuration dialog
    m_dialog = new ConfigDialog(parent);

    m_dialog->show();

    // load the configuration
    load(config);
    toggleIconSettings(m_dialog->useTitleProps->isChecked());

    // setup the connections
    connect(m_dialog->titleAlign, TQ_SIGNAL(clicked(int)), TQ_SIGNAL(changed()));
    connect(m_dialog->roundCorners, TQ_SIGNAL(clicked(int)), TQ_SIGNAL(changed()));
    connect(m_dialog->menuClose, TQ_SIGNAL(toggled(bool)), TQ_SIGNAL(changed()));
    connect(m_dialog->titleShadow, TQ_SIGNAL(toggled(bool)), TQ_SIGNAL(changed()));
    connect(m_dialog->addSpace, TQ_SIGNAL(valueChanged(int)), TQ_SIGNAL(changed()));
    connect(m_dialog->titlebarStyle, TQ_SIGNAL(activated(int)), TQ_SIGNAL(changed()));

    connect(m_dialog->buttonType, TQ_SIGNAL(activated(int)), TQ_SIGNAL(changed()));
    connect(m_dialog->customColors, TQ_SIGNAL(toggled(bool)), TQ_SIGNAL(changed()));
    connect(m_dialog->useTitleProps, TQ_SIGNAL(toggled(bool)), TQ_SIGNAL(changed()));
    connect(m_dialog->animateButtons, TQ_SIGNAL(toggled(bool)), TQ_SIGNAL(changed()));
    connect(m_dialog->redCloseButton, TQ_SIGNAL(toggled(bool)), TQ_SIGNAL(changed()));
    connect(m_dialog->iconSize, TQ_SIGNAL(valueChanged(int)), TQ_SIGNAL(changed()));
    connect(m_dialog->customIconColors, TQ_SIGNAL(toggled(bool)), TQ_SIGNAL(changed()));
    connect(m_dialog->activeFgColor, TQ_SIGNAL(changed(const TQColor &)), TQ_SIGNAL(changed()));
    connect(m_dialog->activeBgColor, TQ_SIGNAL(changed(const TQColor &)), TQ_SIGNAL(changed()));
    connect(m_dialog->inactiveFgColor, TQ_SIGNAL(changed(const TQColor &)), TQ_SIGNAL(changed()));
    connect(m_dialog->inactiveBgColor, TQ_SIGNAL(changed(const TQColor &)), TQ_SIGNAL(changed()));
    connect(m_dialog->iconShadow, TQ_SIGNAL(toggled(bool)), TQ_SIGNAL(changed()));

    connect(m_dialog->titleBarLogo, TQ_SIGNAL(toggled(bool)), TQ_SIGNAL(changed()));
    connect(m_dialog->titleBarLogoOffset, TQ_SIGNAL(valueChanged(int)), TQ_SIGNAL(changed()));

    connect(m_dialog->useTitleProps, TQ_SIGNAL(toggled(bool)), TQ_SLOT(toggleIconSettings(bool)));
    connect(m_dialog->selectButton, TQ_SIGNAL(clicked()), TQ_SLOT(selectImage()));
}

SUSE2Config::~SUSE2Config()
{
    if (m_dialog) delete m_dialog;
    if (m_config) delete m_config;
}

void SUSE2Config::load(TDEConfig *)
{
    m_config->setGroup("General");

    TQString alignValue = m_config->readEntry("TitleAlignment", "AlignLeft");
    TQRadioButton *alignButton = (TQRadioButton*)m_dialog->titleAlign->child(alignValue.latin1());
    if (alignButton) alignButton->setChecked(true);

    TQString roundValue = m_config->readEntry("RoundCorners", "NotMaximized");
    TQRadioButton *roundButton = (TQRadioButton*)m_dialog->roundCorners->child(roundValue.latin1());
    if (roundButton) roundButton->setChecked(true);

    bool menuClose = m_config->readBoolEntry("CloseOnMenuDoubleClick", false);
    m_dialog->menuClose->setChecked(menuClose);

    bool titleShadow = m_config->readBoolEntry("TitleShadow", true);
    m_dialog->titleShadow->setChecked(titleShadow);

    int addSpace = m_config->readNumEntry("AddSpace", 4);
    m_dialog->addSpace->setValue(addSpace);

    int titlebarStyle = m_config->readNumEntry("TitleBarStyle", 0);
    m_dialog->titlebarStyle->setCurrentItem(titlebarStyle);

    int titleButtonType = m_config->readNumEntry("TitleBarButtonType", 2);
    m_dialog->buttonType->setCurrentItem(titleButtonType);

    bool customColors = m_config->readBoolEntry("CustomColors", false);
    m_dialog->customColors->setChecked(customColors);

    bool useTitleProps = m_config->readBoolEntry("UseTitleProps", true);
    m_dialog->useTitleProps->setChecked(useTitleProps);

    bool animateButtons = m_config->readBoolEntry("AnimateButtons", true);
    m_dialog->animateButtons->setChecked(animateButtons);

    bool redCloseButton = m_config->readBoolEntry("RedCloseButton", false);
    m_dialog->redCloseButton->setChecked(redCloseButton);

    int iconSize = m_config->readNumEntry("IconSize", 45);
    m_dialog->iconSize->setValue(iconSize);

    bool customIconColors = m_config->readBoolEntry("CustomIconColors", false);
    m_dialog->customIconColors->setChecked(customIconColors);

    TQColor afgcolor = TQColor(10, 20, 40);
    TQColor aFgColor = m_config->readColorEntry("AFgColor", &afgcolor);
    m_dialog->activeFgColor->setColor(aFgColor);

    TQColor abgcolor = TQColor(210, 220, 240);
    TQColor aBgColor = m_config->readColorEntry("ABgColor", &abgcolor);
    m_dialog->activeBgColor->setColor(aBgColor);

    TQColor ifgcolor = TQColor(40, 40, 40);
    TQColor iFgColor = m_config->readColorEntry("IFgColor", &ifgcolor);
    m_dialog->inactiveFgColor->setColor(iFgColor);

    TQColor ibgcolor = TQColor(240, 240, 240);
    TQColor iBgColor = m_config->readColorEntry("AFgColor", &ibgcolor);
    m_dialog->inactiveBgColor->setColor(iBgColor);

    bool iconShadow = m_config->readBoolEntry("IconShadow", true);
    m_dialog->iconShadow->setChecked(iconShadow);

    bool titleBarLogo = m_config->readBoolEntry("TitleBarLogo", false);
    m_dialog->titleBarLogo->setChecked(titleBarLogo);

    int titleBarLogoOffset = m_config->readNumEntry("TitleBarLogoOffset", 3);
    m_dialog->titleBarLogoOffset->setValue(titleBarLogoOffset);

    TQString titleBarImage = locate("data", "twin/pics/titlebar_decor.png");
    titlebarLogoURL = m_config->readEntry("TitleBarLogoURL", titleBarImage);
    TQImage tmpLogo(titlebarLogoURL);
    m_dialog->logoImage->setPixmap(TQPixmap(tmpLogo.smoothScale(120, 20, TQImage::ScaleMin)));

}

void SUSE2Config::save(TDEConfig *) const
{
    m_config->setGroup("General");

    TQRadioButton *alignButton = (TQRadioButton*)m_dialog->titleAlign->selected();
    if (alignButton) m_config->writeEntry("TitleAlignment", TQString(alignButton->name()));
    TQRadioButton *roundButton = (TQRadioButton*)m_dialog->roundCorners->selected();
    if (roundButton) m_config->writeEntry("RoundCorners", TQString(roundButton->name()));
    m_config->writeEntry("CloseOnMenuDoubleClick", m_dialog->menuClose->isChecked());
    m_config->writeEntry("TitleShadow", m_dialog->titleShadow->isChecked());
    m_config->writeEntry("AddSpace", m_dialog->addSpace->value());
    m_config->writeEntry("TitleBarStyle", m_dialog->titlebarStyle->currentItem());

    m_config->writeEntry("TitleBarButtonType", m_dialog->buttonType->currentItem());
    m_config->writeEntry("CustomColors", m_dialog->customColors->isChecked());
    m_config->writeEntry("UseTitleProps", m_dialog->useTitleProps->isChecked());
    m_config->writeEntry("AnimateButtons", m_dialog->animateButtons->isChecked());
    m_config->writeEntry("RedCloseButton", m_dialog->redCloseButton->isChecked());
    m_config->writeEntry("IconSize", m_dialog->iconSize->value());
    m_config->writeEntry("CustomIconColors", m_dialog->customIconColors->isChecked());
    m_config->writeEntry("AFgColor", m_dialog->activeFgColor->color());
    m_config->writeEntry("ABgColor", m_dialog->activeBgColor->color());
    m_config->writeEntry("IFgColor", m_dialog->inactiveFgColor->color());
    m_config->writeEntry("IBgColor", m_dialog->inactiveBgColor->color());
    m_config->writeEntry("IconShadow", m_dialog->iconShadow->isChecked());

    m_config->writeEntry("TitleBarLogo", m_dialog->titleBarLogo->isChecked());
    m_config->writeEntry("TitleBarLogoOffset", m_dialog->titleBarLogoOffset->value());
    m_config->writeEntry("TitleBarLogoURL", TQString(titlebarLogoURL));
    m_config->sync();
}

void SUSE2Config::defaults()
{
    TQRadioButton *alignButton = (TQRadioButton*)m_dialog->titleAlign->child("AlignLeft");
    if (alignButton) alignButton->setChecked(true);
    TQRadioButton *roundButton = (TQRadioButton*)m_dialog->roundCorners->child("NotMaximized");
    if (roundButton) roundButton->setChecked(true);
    m_dialog->menuClose->setChecked(false);
    m_dialog->titleShadow->setChecked(true);
    m_dialog->addSpace->setValue(4);
    m_dialog->titlebarStyle->setCurrentItem(0);

    m_dialog->buttonType->setCurrentItem(2);
    m_dialog->customColors->setChecked(false);
    m_dialog->useTitleProps->setChecked(true);
    m_dialog->animateButtons->setChecked(true);
    m_dialog->redCloseButton->setChecked(false);
    m_dialog->iconSize->setValue(45);
    m_dialog->customIconColors->setChecked(false);
    m_dialog->activeFgColor->setColor(TQColor(10, 20, 40));
    m_dialog->activeBgColor->setColor(TQColor(210, 220, 240));
    m_dialog->inactiveFgColor->setColor(TQColor(40, 40, 40));
    m_dialog->inactiveBgColor->setColor(TQColor(240, 240, 240));
    m_dialog->iconShadow->setChecked(true);

    m_dialog->titleBarLogo->setChecked(false);
    m_dialog->titleBarLogoOffset->setValue(3);
    titlebarLogoURL = locate("data", "twin/pics/SUSE2/titlebar_decor.png");
    TQImage tmpLogo(titlebarLogoURL);
    m_dialog->logoImage->setPixmap(TQPixmap(tmpLogo.smoothScale(120, 20, TQImage::ScaleMin)));
}

void SUSE2Config::toggleIconSettings(bool checked) const
{
    m_dialog->customIconColors->setEnabled(!checked);
    m_dialog->activeLbl->setEnabled(!checked);
    m_dialog->activeDownLbl->setEnabled(!checked);
    m_dialog->inactiveLbl->setEnabled(!checked);
    m_dialog->inactiveDownLbl->setEnabled(!checked);
    m_dialog->activeFgColor->setEnabled(!checked);
    m_dialog->activeBgColor->setEnabled(!checked);
    m_dialog->inactiveFgColor->setEnabled(!checked);
    m_dialog->inactiveBgColor->setEnabled(!checked);
    m_dialog->iconShadow->setEnabled(!checked);
}

void SUSE2Config::selectImage()
{
    KURL logoURL = KFileDialog::getImageOpenURL(titlebarLogoURL, m_parent, i18n("Select Logo Image"));
    KFileItem tmpFileItem = KFileItem(KFileItem::Unknown, KFileItem::Unknown, logoURL);
    if (!logoURL.isEmpty() && tmpFileItem.isFile() && tmpFileItem.isReadable()) {
        titlebarLogoURL = logoURL.path();
        TQImage tmpLogo(titlebarLogoURL);
        m_dialog->logoImage->setPixmap(TQPixmap(tmpLogo.smoothScale(120, 20, TQImage::ScaleMin)));
        emit changed();
    }
}

//////////////////////////////////////////////////////////////////////////////
// Plugin Stuff                                                             //
//////////////////////////////////////////////////////////////////////////////

extern "C"
{
    KDE_EXPORT TQObject *allocate_config(TDEConfig *config, TQWidget *parent) {
        return (new SUSE2Config(config, parent));
    }
}

#include "config.moc"