2 Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
3 Copyright (c) 2005 Rafal Rzepecki <divide@users.sourceforge.net>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 #include "categoryconfig.h"
23 #include <KConfigSkeleton>
24 #include <KLocalizedString>
26 using namespace CalendarSupport
;
28 static QStringList
categoryDefaults()
31 l
<< i18nc( "incidence category: appointment", "Appointment" )
32 << i18nc( "incidence category", "Business" )
33 << i18nc( "incidence category", "Meeting" )
34 << i18nc( "incidence category: phone call","Phone Call" )
35 << i18nc( "incidence category", "Education" )
36 << i18nc( "incidence category: "
37 "official or unofficial observance of "
38 "religious/national/cultural/other significance, "
39 "often accompanied by celebrations or festivities", "Holiday" )
40 << i18nc( "incidence category: "
41 "a lengthy time away from work or school, a trip abroad, "
42 "or simply a pleasure trip away from home", "Vacation" )
43 << i18nc( "incidence category: "
44 "examples: anniversary of historical or personal event; "
45 "big date; remembrance, etc", "Special Occasion" )
46 << i18nc( "incidence category", "Personal" )
47 << i18nc( "incidence category: "
48 "typically associated with leaving home for business, "
49 "and not pleasure", "Travel" )
50 << i18nc( "incidence category", "Miscellaneous" )
51 << i18nc( "incidence category", "Birthday" );
55 class CategoryConfig::Private
58 explicit Private( KCoreConfigSkeleton
*cfg
) : config( cfg
)
60 mDefaultCategoryColor
= QColor( 151, 235, 121 );
63 QColor mDefaultCategoryColor
;
64 KCoreConfigSkeleton
*config
;
67 QHash
<QString
,QColor
> CategoryConfig::readColors() const
70 QHash
<QString
,QColor
> categoryColors
;
71 KConfigGroup
colorsConfig( d
->config
->config(), "Category Colors2" );
72 const QStringList cats
= customCategories();
73 Q_FOREACH ( const QString
& category
, cats
) {
74 const QColor color
= colorsConfig
.readEntry( category
, d
->mDefaultCategoryColor
);
75 if ( color
!= d
->mDefaultCategoryColor
) {
76 categoryColors
.insert( category
, color
);
80 return categoryColors
;
83 void CategoryConfig::setColors( const QHash
<QString
,QColor
> &colors
)
85 KConfigGroup
colorsConfig( d
->config
->config(), "Category Colors2" );
86 QHash
<QString
, QColor
>::const_iterator i
= colors
.constBegin();
87 QHash
<QString
, QColor
>::const_iterator end
= colors
.constEnd();
89 colorsConfig
.writeEntry( i
.key(), i
.value() );
94 CategoryConfig::CategoryConfig( KCoreConfigSkeleton
*cfg
, QObject
*parent
)
95 : QObject( parent
), d( new Private( cfg
) )
99 CategoryConfig::~CategoryConfig()
104 void CategoryConfig::writeConfig()
106 d
->config
->writeConfig();
109 QStringList
CategoryConfig::customCategories() const
111 KConfigGroup
group( d
->config
->config(), "General" );
112 QStringList cats
= group
.readEntry( "Custom Categories", QStringList() );
114 if ( cats
.isEmpty() ) {
115 cats
= categoryDefaults();
121 void CategoryConfig::setCustomCategories( const QStringList
&categories
)
123 KConfigGroup
group( d
->config
->config(), "General" );
124 group
.writeEntry( "Custom Categories", categories
);
127 const QString
CategoryConfig::categorySeparator( ":" );
129 #include "categoryconfig.moc"