Fix wrong connect
[kdepim.git] / calendarsupport / categoryconfig.cpp
blob186af119b778c05e7d6518d5d32608b415bc9766
1 /*
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 <KLocalizedString>
24 #include <KConfigGroup>
25 #include <KCoreConfigSkeleton>
26 #include <QColor>
28 using namespace CalendarSupport;
30 static QStringList categoryDefaults()
32 QStringList l;
33 l << i18nc("incidence category: appointment", "Appointment")
34 << i18nc("incidence category", "Business")
35 << i18nc("incidence category", "Meeting")
36 << i18nc("incidence category: phone call", "Phone Call")
37 << i18nc("incidence category", "Education")
38 << i18nc("incidence category: "
39 "official or unofficial observance of "
40 "religious/national/cultural/other significance, "
41 "often accompanied by celebrations or festivities", "Holiday")
42 << i18nc("incidence category: "
43 "a lengthy time away from work or school, a trip abroad, "
44 "or simply a pleasure trip away from home", "Vacation")
45 << i18nc("incidence category: "
46 "examples: anniversary of historical or personal event; "
47 "big date; remembrance, etc", "Special Occasion")
48 << i18nc("incidence category", "Personal")
49 << i18nc("incidence category: "
50 "typically associated with leaving home for business, "
51 "and not pleasure", "Travel")
52 << i18nc("incidence category", "Miscellaneous")
53 << i18nc("incidence category", "Birthday");
54 return l;
57 class CategoryConfig::Private
59 public:
60 explicit Private(KCoreConfigSkeleton *cfg) : config(cfg)
62 mDefaultCategoryColor = QColor(151, 235, 121);
65 QColor mDefaultCategoryColor;
66 KCoreConfigSkeleton *config;
69 QHash<QString, QColor> CategoryConfig::readColors() const
71 // Category colors
72 QHash<QString, QColor> categoryColors;
73 KConfigGroup colorsConfig(d->config->config(), "Category Colors2");
74 const QStringList cats = customCategories();
75 Q_FOREACH (const QString &category, cats) {
76 const QColor color = colorsConfig.readEntry(category, d->mDefaultCategoryColor);
77 if (color != d->mDefaultCategoryColor) {
78 categoryColors.insert(category, color);
82 return categoryColors;
85 void CategoryConfig::setColors(const QHash<QString, QColor> &colors)
87 KConfigGroup colorsConfig(d->config->config(), "Category Colors2");
88 QHash<QString, QColor>::const_iterator i = colors.constBegin();
89 QHash<QString, QColor>::const_iterator end = colors.constEnd();
90 while (i != end) {
91 colorsConfig.writeEntry(i.key(), i.value());
92 ++i;
96 CategoryConfig::CategoryConfig(KCoreConfigSkeleton *cfg, QObject *parent)
97 : QObject(parent), d(new Private(cfg))
101 CategoryConfig::~CategoryConfig()
103 delete d;
106 void CategoryConfig::writeConfig()
108 d->config->save();
111 QStringList CategoryConfig::customCategories() const
113 KConfigGroup group(d->config->config(), "General");
114 QStringList cats = group.readEntry("Custom Categories", QStringList());
116 if (cats.isEmpty()) {
117 cats = categoryDefaults();
119 cats.sort();
120 return cats;
123 void CategoryConfig::setCustomCategories(const QStringList &categories)
125 KConfigGroup group(d->config->config(), "General");
126 group.writeEntry("Custom Categories", categories);
129 const QString CategoryConfig::categorySeparator(QLatin1Char(':'));