25 #include <KLocalizedString>
40 qDeleteAll( mPerViewConfigGroups );
41 mPerViewConfigGroups.
clear();
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()
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 )
118 if (
name() ==
"year" ) {
120 }
else if (
name() ==
"month" ) {
122 }
else if (
name() ==
"day" ) {
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 )
159 readElement( v, year, month, day );
164 void ThemeImporter::readUnknownElement()
168 kWarning() <<
"Unknown element found at line" <<
lineNumber()
180 readUnknownElement();
187 void ThemeImporter::readCalendarItems(
const QString &viewType,
const int year,
188 const int month,
const int day )
203 if ( stack.
count() > 1 ) {
212 if ( stack.
count() == 1 &&
name() ==
"events" ) {
214 QString(
"CalendarItems Events" ) ) );
215 }
else if ( stack.
count() == 1 &&
name() ==
"to-dos" ) {
217 QString(
"CalendarItems ToDos" ) ) );
219 }
else if ( stack.
count() == 2 && stack.
last().first ==
"to-dos" &&
220 name() ==
"overdue" ) {
222 QString(
"CalendarItems ToDos Overdue" ) ) );
223 }
else if ( stack.
count() == 2 && stack.
last().first ==
"to-dos" &&
224 name() ==
"due-today" ) {
226 QString(
"CalendarItems ToDos DueToday" ) ) );
228 }
else if ( stack.
count() == 1 &&
name() ==
"categories" ) {
232 QString(
"CalendarItems" ) ) );
233 }
else if ( stack.
count() == 1 &&
name() ==
"resources" ) {
237 QString(
"CalendarItems" ) ) );
240 else if ( stack.
count() == 2 && stack.
last().first ==
"categories" &&
241 name() ==
"category" ) {
244 QString(
"CalendarItems Categories " + n ) ) );
245 }
else if ( stack.
count() == 2 && stack.
last().first ==
"resources" &&
246 name() ==
"resource" ) {
249 QString(
"CalendarItems Resources " + n ) ) );
252 else if (
name() ==
"background" ) {
253 setColor( viewType, year, month, day,
254 stack.
last().second +
" Background Color",
256 setPath( viewType, year, month, day,
257 stack.
last().second +
" Background Image",
260 }
else if (
name() ==
"font" ) {
261 setFont( viewType, year, month, day,
262 stack.
last().second +
" Font",
270 }
else if (
name() ==
"frame" ) {
271 setColor( viewType, year, month, day,
272 stack.
last().second +
" Frame Color",
275 }
else if (
name() ==
"icon" ) {
276 setString( viewType, year, month, day,
277 stack.
last().second +
" Icon",
279 setPath( viewType, year, month, day,
280 stack.
last().second +
" IconFile",
284 readUnknownElement();
290 void ThemeImporter::readGrid(
const QString &viewType,
const int year,
291 const int month,
const int day )
305 if (
name() ==
"background" ) {
306 setColor( viewType, year, month, day,
307 cfg +
" Background Color",
309 setPath( viewType, year, month, day,
310 cfg +
" Background Image",
313 }
else if (
name() ==
"highlight" ) {
314 setColor( viewType, year, month, day,
315 cfg +
" Highlight Color",
318 }
else if (
name() ==
"work-hours" ) {
327 if (
name() ==
"background" ) {
328 setColor( viewType, year, month, day,
329 cfg +
" WorkHours Background Color",
331 setPath( viewType, year, month, day,
332 cfg +
" WorkHours Background Image",
336 readUnknownElement();
341 readUnknownElement();
347 void ThemeImporter::readHolidays(
const QString &viewType,
const int year,
348 const int month,
const int day )
362 if (
name() ==
"background" ) {
363 setColor( viewType, year, month, day,
364 cfg +
" Background Color",
366 setPath( viewType, year, month, day,
367 cfg +
" Background Image",
371 readUnknownElement();
377 void ThemeImporter::readMarcusBainsLine(
const QString &viewType,
const int year,
378 const int month,
const int day )
382 QString cfg =
"MarcusBainsLine";
392 if (
name() ==
"font" ) {
393 setFont( viewType, year, month, day,
402 }
else if (
name() ==
"line" ) {
403 setColor( viewType, year, month, day,
408 readUnknownElement();
414 void ThemeImporter::readTimeLabels(
const QString &viewType,
const int year,
415 const int month,
const int day )
429 if (
name() ==
"font" ) {
430 setFont( viewType, year, month, day,
440 readUnknownElement();
448 void ThemeImporter::setColor(
const QString &viewType,
const int year,
449 const int month,
const int day,
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,
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,
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,
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 )
581 it = mPerViewConfigGroups.
constFind( viewType );
582 if ( it == mPerViewConfigGroups.
constEnd() ) {
583 g = registerPerViewConfigGroup( createPerViewConfigGroup( viewType ), viewType );
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" );
qint64 columnNumber() const
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.
const_iterator constFind(const Key &key) const
QStringRef value(const QString &namespaceUri, const QString &name) const
void setDevice(QIODevice *device)
void raiseError(const QString &message)
int count(const T &value) const
void append(const T &value)
int toInt(bool *ok, int base) const
const_iterator constEnd() const
bool isStartElement() const
QString mid(int position, int n) const
char * toString(const T &value)
QXmlStreamAttributes attributes() const
iterator insert(const Key &key, const T &value)
qint64 lineNumber() const
bool isEndElement() const