40 qDeleteAll( mPerViewConfigGroups );
41 mPerViewConfigGroups.clear();
53 if ( isStartElement() ) {
54 if ( name( ) ==
"korganizer-theme" && attributes().value(
"version") ==
"1.0" ) {
57 raiseError( i18n(
"This file is not a KOrganizer theme file." ) );
65 void ThemeImporter::readThemeXml()
67 Q_ASSERT( isStartElement() && name() ==
"korganizer-theme" );
72 if ( isEndElement() ) {
76 if ( isStartElement() ) {
84 void ThemeImporter::readElement(
const QString &viewType,
const int year,
85 const int month,
const int day )
87 if ( name() ==
"view" ) {
88 readView( viewType, year, month, day );
94 }
else if ( name() ==
"grid" ) {
95 readGrid( viewType, year, month, day );
96 }
else if ( name() ==
"time-labels" ) {
97 readTimeLabels( viewType, year, month, day );
98 }
else if ( name() ==
"calendar-items" ) {
99 readCalendarItems( viewType, year, month, day );
100 }
else if ( name() ==
"marcus-bains-line" ) {
101 readMarcusBainsLine( viewType, year, month, day );
102 }
else if ( name() ==
"holidays" ) {
103 readHolidays( viewType, year, month, day );
105 readUnknownElement();
109 void ThemeImporter::readDate(
const QString &viewType,
const int year,
110 const int month,
const int day )
112 Q_ASSERT( isStartElement() && ( name() ==
"year" || name() ==
"month" || name() ==
"day" ) );
118 if ( name() ==
"year" ) {
119 y = attributes().value(
"value" ).toString().toInt();
120 }
else if ( name() ==
"month" ) {
121 m = attributes().value(
"value" ).toString().toInt();
122 }
else if ( name() ==
"day" ) {
123 d = attributes().value(
"value" ).toString().toInt();
129 if ( isEndElement() ) {
133 if ( isStartElement() ) {
134 if ( name() ==
"year" || name() ==
"month" || name() ==
"day" ) {
135 readDate( viewType, y, m, d );
137 readElement( viewType, y, m, d );
143 void ThemeImporter::readView(
const QString &viewType,
const int year,
144 const int month,
const int day )
146 Q_ASSERT( isStartElement() && name() ==
"view" );
148 QString v = viewType;
149 v = attributes().value(
"type" ).toString();
154 if ( isEndElement() ) {
158 if ( isStartElement() ) {
159 readElement( v, year, month, day );
164 void ThemeImporter::readUnknownElement()
166 Q_ASSERT( isStartElement() );
168 kWarning() <<
"Unknown element found at line" << lineNumber()
169 <<
", ending at column" << columnNumber()
170 <<
":" << name().toString();
175 if ( isEndElement() ) {
179 if ( isStartElement() ) {
180 readUnknownElement();
187 void ThemeImporter::readCalendarItems(
const QString &viewType,
const int year,
188 const int month,
const int day )
190 Q_ASSERT( isStartElement() && name() ==
"calendar-items" );
196 QList< QPair<QString, QString> > stack;
197 stack.append( qMakePair( QString(), QString(
"CalendarItems" ) ) );
202 if ( isEndElement() ) {
203 if ( stack.count() > 1 ) {
210 if ( isStartElement() ) {
212 if ( stack.count() == 1 && name() ==
"events" ) {
213 stack.append( qMakePair( QString(
"events" ),
214 QString(
"CalendarItems Events" ) ) );
215 }
else if ( stack.count() == 1 && name() ==
"to-dos" ) {
216 stack.append( qMakePair( QString(
"to-dos" ),
217 QString(
"CalendarItems ToDos" ) ) );
219 }
else if ( stack.count() == 2 && stack.last().first ==
"to-dos" &&
220 name() ==
"overdue" ) {
221 stack.append( qMakePair( QString(
"to-dos/overdue" ),
222 QString(
"CalendarItems ToDos Overdue" ) ) );
223 }
else if ( stack.count() == 2 && stack.last().first ==
"to-dos" &&
224 name() ==
"due-today" ) {
225 stack.append( qMakePair( QString(
"to-dos/due-today" ),
226 QString(
"CalendarItems ToDos DueToday" ) ) );
228 }
else if ( stack.count() == 1 && name() ==
"categories" ) {
229 stack.append( qMakePair( QString(
"categories" ),
232 QString(
"CalendarItems" ) ) );
233 }
else if ( stack.count() == 1 && name() ==
"resources" ) {
234 stack.append( qMakePair( QString(
"resources" ),
237 QString(
"CalendarItems" ) ) );
240 else if ( stack.count() == 2 && stack.last().first ==
"categories" &&
241 name() ==
"category" ) {
242 QString n = attributes().value(
"name" ).toString();
243 stack.append( qMakePair( QString(
"categories/" + n ),
244 QString(
"CalendarItems Categories " + n ) ) );
245 }
else if ( stack.count() == 2 && stack.last().first ==
"resources" &&
246 name() ==
"resource" ) {
247 QString n = attributes().value(
"name" ).toString();
248 stack.append( qMakePair( QString(
"resources/" + n ),
249 QString(
"CalendarItems Resources " + n ) ) );
252 else if ( name() ==
"background" ) {
253 setColor( viewType, year, month, day,
254 stack.last().second +
" Background Color",
255 attributes().value(
"color" ).toString() );
256 setPath( viewType, year, month, day,
257 stack.last().second +
" Background Image",
258 attributes().value(
"src" ).toString() );
260 }
else if ( name() ==
"font" ) {
261 setFont( viewType, year, month, day,
262 stack.last().second +
" Font",
263 attributes().value(
"family" ).toString(),
264 attributes().value(
"style-hint" ).toString(),
265 attributes().value(
"point-size" ).toString().toInt(),
266 attributes().value(
"weight" ).toString().toInt(),
267 attributes().value(
"style" ).toString(),
268 attributes().value(
"stretch-factor" ).toString().toInt() );
270 }
else if ( name() ==
"frame" ) {
271 setColor( viewType, year, month, day,
272 stack.last().second +
" Frame Color",
273 attributes().value(
"color" ).toString() );
275 }
else if ( name() ==
"icon" ) {
276 setString( viewType, year, month, day,
277 stack.last().second +
" Icon",
278 attributes().value(
"name" ).toString() );
279 setPath( viewType, year, month, day,
280 stack.last().second +
" IconFile",
281 attributes().value(
"src" ).toString() );
284 readUnknownElement();
290 void ThemeImporter::readGrid(
const QString &viewType,
const int year,
291 const int month,
const int day )
293 Q_ASSERT( isStartElement() && name() ==
"grid" );
295 QString cfg =
"Grid";
300 if ( isEndElement() ) {
304 if ( isStartElement() ) {
305 if ( name() ==
"background" ) {
306 setColor( viewType, year, month, day,
307 cfg +
" Background Color",
308 attributes().value(
"color" ).toString() );
309 setPath( viewType, year, month, day,
310 cfg +
" Background Image",
311 attributes().value(
"src" ).toString() );
313 }
else if ( name() ==
"highlight" ) {
314 setColor( viewType, year, month, day,
315 cfg +
" Highlight Color",
316 attributes().value(
"color" ).toString() );
318 }
else if ( name() ==
"work-hours" ) {
322 if ( isEndElement() ) {
326 if ( isStartElement() ) {
327 if ( name() ==
"background" ) {
328 setColor( viewType, year, month, day,
329 cfg +
" WorkHours Background Color",
330 attributes().value(
"color" ).toString() );
331 setPath( viewType, year, month, day,
332 cfg +
" WorkHours Background Image",
333 attributes().value(
"src" ).toString() );
336 readUnknownElement();
341 readUnknownElement();
347 void ThemeImporter::readHolidays(
const QString &viewType,
const int year,
348 const int month,
const int day )
350 Q_ASSERT( isStartElement() && name() ==
"holidays" );
352 QString cfg =
"Holidays";
357 if ( isEndElement() ) {
361 if ( isStartElement() ) {
362 if ( name() ==
"background" ) {
363 setColor( viewType, year, month, day,
364 cfg +
" Background Color",
365 attributes().value(
"color" ).toString() );
366 setPath( viewType, year, month, day,
367 cfg +
" Background Image",
368 attributes().value(
"src" ).toString() );
371 readUnknownElement();
377 void ThemeImporter::readMarcusBainsLine(
const QString &viewType,
const int year,
378 const int month,
const int day )
380 Q_ASSERT( isStartElement() && name() ==
"marcus-bains-line" );
382 QString cfg =
"MarcusBainsLine";
387 if ( isEndElement() ) {
391 if ( isStartElement() ) {
392 if ( name() ==
"font" ) {
393 setFont( viewType, year, month, day,
395 attributes().value(
"family" ).toString(),
396 attributes().value(
"style-hint" ).toString(),
397 attributes().value(
"point-size" ).toString().toInt(),
398 attributes().value(
"weight" ).toString().toInt(),
399 attributes().value(
"style" ).toString(),
400 attributes().value(
"stretch-factor" ).toString().toInt() );
402 }
else if ( name() ==
"line" ) {
403 setColor( viewType, year, month, day,
405 attributes().value(
"color" ).toString() );
408 readUnknownElement();
414 void ThemeImporter::readTimeLabels(
const QString &viewType,
const int year,
415 const int month,
const int day )
417 Q_ASSERT( isStartElement() && name() ==
"time-labels" );
419 QString cfg =
"TimeLabels";
424 if ( isEndElement() ) {
428 if ( isStartElement() ) {
429 if ( name() ==
"font" ) {
430 setFont( viewType, year, month, day,
432 attributes().value(
"family" ).toString(),
433 attributes().value(
"style-hint" ).toString(),
434 attributes().value(
"point-size" ).toString().toInt(),
435 attributes().value(
"weight" ).toString().toInt(),
436 attributes().value(
"style" ).toString(),
437 attributes().value(
"stretch-factor" ).toString().toInt() );
440 readUnknownElement();
448 void ThemeImporter::setColor(
const QString &viewType,
const int year,
449 const int month,
const int day,
450 const QString &key,
const QString &value )
452 QString htmlColor = value.toUpper();
453 if ( ( htmlColor.count( QRegExp(
"^#[0-9A-F]{6}$" ) ) == 1 ) ||
454 ( htmlColor.count( QRegExp(
"^#[0-9A-F]{8}$" ) ) == 1 ) ) {
456 int r = htmlColor.mid( 1, 2 ).toInt( 0, 16 );
457 int g = htmlColor.mid( 3, 2 ).toInt( 0, 16 );
458 int b = htmlColor.mid( 5, 2 ).toInt( 0, 16 );
460 if ( htmlColor.length() == 1+8 ) {
464 b = htmlColor.mid( 7, 2 ).toInt( 0, 16 );
466 QColor color( r, g, b, a );
469 if ( year == 0 && month == 0 && day == 0 ) {
470 configGroup( v )->writeEntry( v + key, color );
473 kWarning() <<
"feature not yet implemented";
474 kWarning() <<
"THEORICAL setting:" << year <<
"-" << month <<
"-" << day
475 <<
":" << v <<
":" << key <<
":" << value;
481 void ThemeImporter::setFont(
const QString &viewType,
const int year,
482 const int month,
const int day,
483 const QString &key,
const QString &family,
484 const QString &styleHint,
const int pointSize,
485 const int weight,
const QString &style,
486 const int stretchFactor )
488 QFont f( family, pointSize, weight );
490 QFont::StyleHint sh = QFont::AnyStyle;
491 if ( styleHint ==
"AnyStyle" ) {
492 sh = QFont::AnyStyle;
493 }
else if ( styleHint ==
"SansSerif" ) {
494 sh = QFont::SansSerif;
495 }
else if ( styleHint ==
"Helvetica" ) {
496 sh = QFont::Helvetica;
497 }
else if ( styleHint ==
"Serif" ) {
499 }
else if ( styleHint ==
"Times" ) {
501 }
else if ( styleHint ==
"TypeWriter" ) {
502 sh = QFont::TypeWriter;
503 }
else if ( styleHint ==
"Courier" ) {
505 }
else if ( styleHint ==
"OldEnglish" ) {
506 sh = QFont::OldEnglish;
507 }
else if ( styleHint ==
"Decorative" ) {
508 sh = QFont::Decorative;
509 }
else if ( styleHint ==
"System" ) {
512 f.setStyleHint( sh );
513 QFont::Style s = QFont::StyleNormal;
514 if ( style ==
"Normal" ) {
515 s = QFont::StyleNormal;
516 }
else if ( style ==
"Italic" ) {
517 s = QFont::StyleItalic;
518 }
else if ( style ==
"Oblique" ) {
519 s = QFont::StyleOblique;
522 int sf = ( stretchFactor < 1 ? 100 : stretchFactor );
526 if ( year == 0 && month == 0 && day == 0 ) {
527 configGroup( v )->writeEntry( v + key, f );
530 kWarning() <<
"feature not yet implemented";
531 kWarning() <<
"THEORICAL setting:" << year <<
"-" << month <<
"-" << day
532 <<
":" << v <<
":" << key <<
":" << family <<
"\t"
533 << styleHint <<
"\t" << pointSize <<
"\t" << weight <<
"\t"
534 << style <<
"\t" << sf;
539 void ThemeImporter::setPath(
const QString &viewType,
const int year,
540 const int month,
const int day,
541 const QString &key,
const QString &value )
543 if ( ! value.isEmpty() ) {
545 if ( year == 0 && month == 0 && day == 0 ) {
546 configGroup( v )->writePathEntry( v + key, value );
549 kWarning() <<
"feature not yet implemented";
550 kWarning() <<
"THEORICAL setting:" << year <<
"-" << month <<
"-" << day
551 <<
":" << v <<
":" << key <<
":" << value;
557 void ThemeImporter::setString(
const QString &viewType,
const int year,
558 const int month,
const int day,
559 const QString &key,
const QString &value )
561 if ( ! value.isEmpty() ) {
563 if ( year == 0 && month == 0 && day == 0 ) {
564 configGroup( v )->writeEntry( v + key, value );
567 kWarning() <<
"feature not yet implemented";
568 kWarning() <<
"THEORICAL setting:" << year <<
"-" << month <<
"-" << day
569 <<
":" << v <<
":" << key <<
":" << value;
577 KConfigGroup *ThemeImporter::configGroup(
const QString &viewType )
579 QMap<QString, KConfigGroup*>::ConstIterator it;
581 it = mPerViewConfigGroups.constFind( viewType );
582 if ( it == mPerViewConfigGroups.constEnd() ) {
583 g = registerPerViewConfigGroup( createPerViewConfigGroup( viewType ), viewType );
590 QList<KConfigGroup*> ThemeImporter::perViewConfigGroups()
592 QList<KConfigGroup*> l;
594 l.append( configGroup( v ) );
599 KConfigGroup *ThemeImporter::registerPerViewConfigGroup( KConfigGroup *g,
const QString &viewType )
601 mPerViewConfigGroups.insert( viewType, g );
605 KConfigGroup *ThemeImporter::createPerViewConfigGroup(
const QString &viewType )
const
607 return new KConfigGroup( KSharedConfig::openConfig(),
"Theme/" + viewType +
" view" );
static const QStringList themableViews(const QString &viewType=QString())
Return all themable views corresponding to the viewType.
bool read(QIODevice *device)
Read the XML stream from a device.