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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
|
/*
*
* $Id$
* Copyright (C) 2003 Sebastian Trueg <trueg@k3b.org>
*
* This file is part of the K3b project.
* Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.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.
* See the file "COPYING" for the exact licensing terms.
*/
#include "k3bthememanager.h"
#include <k3bversion.h>
#include <kstandarddirs.h>
#include <tdeglobalsettings.h>
#include <ksimpleconfig.h>
#include <kdebug.h>
#include <tdeglobal.h>
#include <tqpixmap.h>
#include <tqfile.h>
#include <tqfileinfo.h>
#include <tqdir.h>
#include <tqstringlist.h>
#include <tqvaluelist.h>
K3bTheme::K3bTheme()
: m_bgMode(BG_TILE)
{
}
TQColor K3bTheme::backgroundColor() const
{
if( m_bgColor.isValid() )
return m_bgColor;
else
return TDEGlobalSettings::activeTitleColor();
}
TQColor K3bTheme::foregroundColor() const
{
if( m_fgColor.isValid() )
return m_fgColor;
else
return TDEGlobalSettings::activeTextColor();
}
const TQPixmap& K3bTheme::pixmap( const TQString& name ) const
{
TQMap<TQString, TQPixmap>::const_iterator it = m_pixmapMap.find( name );
if( it != m_pixmapMap.end() )
return *it;
// try loading the image
if( TQFile::exists( m_path + name ) )
return *m_pixmapMap.insert( name, TQPixmap( m_path + name ) );
kdDebug() << "(K3bTheme) " << m_name << ": could not load image " << name << endl;
return m_emptyPixmap;
}
const TQPixmap& K3bTheme::pixmap( K3bTheme::PixmapType t ) const
{
return pixmap( filenameForPixmapType( t ) );
}
TQString K3bTheme::filenameForPixmapType( PixmapType t )
{
TQString name;
switch( t ) {
case MEDIA_AUDIO:
name = "media_audio";
break;
case MEDIA_DATA:
name = "media_data";
break;
case MEDIA_VIDEO:
name = "media_video";
break;
case MEDIA_EMPTY:
name = "media_empty";
break;
case MEDIA_MIXED:
name = "media_mixed";
break;
case MEDIA_NONE:
name = "media_none";
break;
case MEDIA_LEFT:
name = "media_left";
break;
case PROGRESS_WORKING:
name = "progress_working";
break;
case PROGRESS_SUCCESS:
name = "progress_success";
break;
case PROGRESS_FAIL:
name = "progress_fail";
break;
case PROGRESS_RIGHT:
name = "progress_right";
break;
case DIALOG_LEFT:
name = "dialog_left";
break;
case DIALOG_RIGHT:
name = "dialog_right";
break;
case SPLASH:
name = "splash";
break;
case PROJECT_LEFT:
name = "project_left";
break;
case PROJECT_RIGHT:
name = "project_right";
break;
case WELCOME_BG:
name = "welcome_bg";
break;
default:
break;
}
name.append( ".png" );
return name;
}
K3bTheme::BackgroundMode K3bTheme::backgroundMode() const
{
return m_bgMode;
}
class K3bThemeManager::Private
{
public:
Private()
: currentTheme(&emptyTheme) {
}
TQValueList<K3bTheme*> themes;
K3bTheme* currentTheme;
TQString currentThemeName;
K3bTheme emptyTheme;
};
K3bThemeManager::K3bThemeManager( TQObject* parent, const char* name )
: TQObject( parent, name )
{
d = new Private();
d->emptyTheme.m_name = "Empty Theme";
}
K3bThemeManager::~K3bThemeManager()
{
delete d;
}
const TQValueList<K3bTheme*>& K3bThemeManager::themes() const
{
return d->themes;
}
K3bTheme* K3bThemeManager::currentTheme() const
{
return d->currentTheme;
}
void K3bThemeManager::readConfig( TDEConfigBase* c )
{
TDEConfigGroup generalOptions( c, "General Options" );
// allow to override the default theme by packaging a default config file
TQString defaultTheme = generalOptions.readEntry( "default theme", "quant" );
K3bVersion configVersion( generalOptions.readEntry( "config version", "0.1" ) );
if( configVersion >= K3bVersion("0.98") )
setCurrentTheme( generalOptions.readEntry( "current theme", defaultTheme ) );
else
setCurrentTheme( defaultTheme );
}
void K3bThemeManager::saveConfig( TDEConfigBase* c )
{
if( !d->currentThemeName.isEmpty() )
TDEConfigGroup( c, "General Options" ).writeEntry( "current theme", d->currentThemeName );
}
void K3bThemeManager::setCurrentTheme( const TQString& name )
{
if( name != d->currentThemeName ) {
if( K3bTheme* theme = findTheme( name ) )
setCurrentTheme( theme );
}
}
void K3bThemeManager::setCurrentTheme( K3bTheme* theme )
{
if( !theme )
theme = d->themes.first();
if( theme ) {
if( theme != d->currentTheme ) {
d->currentTheme = theme;
d->currentThemeName = theme->name();
emit themeChanged();
emit themeChanged( theme );
}
}
}
K3bTheme* K3bThemeManager::findTheme( const TQString& name ) const
{
for( TQValueList<K3bTheme*>::iterator it = d->themes.begin(); it != d->themes.end(); ++it )
if( (*it)->name() == name )
return *it;
return 0;
}
void K3bThemeManager::loadThemes()
{
// first we cleanup the loaded themes
for( TQValueList<K3bTheme*>::iterator it = d->themes.begin(); it != d->themes.end(); ++it )
delete *it;
d->themes.clear();
TQStringList dirs = TDEGlobal::dirs()->findDirs( "data", "k3b/pics" );
// now search for themes. As there may be multiple themes with the same name
// we only use the names from this list and then use findResourceDir to make sure
// the local is preferred over the global stuff (like testing a theme by copying it
// to the .kde dir)
TQStringList themeNames;
for( TQStringList::const_iterator dirIt = dirs.begin(); dirIt != dirs.end(); ++dirIt ) {
TQDir dir( *dirIt );
TQStringList entries = dir.entryList( TQDir::Dirs );
entries.remove( "." );
entries.remove( ".." );
// every theme dir needs to contain a k3b.theme file
for( TQStringList::const_iterator entryIt = entries.begin(); entryIt != entries.end(); ++entryIt ) {
TQString themeDir = *dirIt + *entryIt + "/";
if( !themeNames.contains( *entryIt ) && TQFile::exists( themeDir + "k3b.theme" ) ) {
bool themeValid = true;
// check for all nessessary pixmaps (this is a little evil hacking)
for( int i = 0; i <= K3bTheme::WELCOME_BG; ++i ) {
if( !TQFile::exists( themeDir + K3bTheme::filenameForPixmapType( (K3bTheme::PixmapType)i ) ) ) {
kdDebug() << "(K3bThemeManager) theme misses pixmap: " << K3bTheme::filenameForPixmapType( (K3bTheme::PixmapType)i ) << endl;
themeValid = false;
break;
}
}
if( themeValid )
themeNames.append( *entryIt );
}
}
}
// now load the themes
for( TQStringList::const_iterator themeIt = themeNames.begin(); themeIt != themeNames.end(); ++themeIt )
loadTheme( *themeIt );
// load the current theme
setCurrentTheme( findTheme(d->currentThemeName) );
}
void K3bThemeManager::loadTheme( const TQString& name )
{
TQString path = TDEGlobal::dirs()->findResource( "data", "k3b/pics/" + name + "/k3b.theme" );
if( !path.isEmpty() ) {
K3bTheme* t = new K3bTheme();
t->m_name = name;
t->m_path = path.left( path.length() - 9 );
TQFileInfo fi( t->m_path );
t->m_local = fi.isWritable();
// load the stuff
KSimpleConfig cfg( path, true );
t->m_author = cfg.readEntry( "Author" );
t->m_comment = cfg.readEntry( "Comment" );
t->m_version = cfg.readEntry( "Version" );
t->m_bgColor = cfg.readColorEntry( "Backgroundcolor" );
t->m_fgColor = cfg.readColorEntry( "Foregroundcolor" );
t->m_bgMode = ( cfg.readEntry( "BackgroundMode" ) == "Scaled" ? K3bTheme::BG_SCALE : K3bTheme::BG_TILE );
d->themes.append( t );
}
}
#include "k3bthememanager.moc"
|