1 | /* |
2 | This file is part of the kcal library. |
3 | |
4 | Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org> |
5 | |
6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. |
10 | |
11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. |
15 | |
16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 | Boston, MA 02110-1301, USA. |
20 | */ |
21 | /** |
22 | @file |
23 | This file is part of the API for handling calendar data and |
24 | defines the FreeBusyUrlStore class. |
25 | |
26 | @author Cornelius Schumacher \<schumacher@kde.org\> |
27 | */ |
28 | |
29 | #include "freebusyurlstore.h" |
30 | #include <kconfig.h> |
31 | #include <kstandarddirs.h> |
32 | #include <kconfiggroup.h> |
33 | #include <QtCore/QCoreApplication> |
34 | |
35 | using namespace KCal; |
36 | |
37 | //@cond PRIVATE |
38 | class FreeBusyUrlStore::Private |
39 | { |
40 | public: |
41 | Private() |
42 | : mConfig(0) |
43 | {} |
44 | ~Private() |
45 | { |
46 | qRemovePostRoutine(cleanupFreeBusyUrlStore); |
47 | } |
48 | KConfig *mConfig; |
49 | |
50 | static FreeBusyUrlStore *sSelf; |
51 | static void cleanupFreeBusyUrlStore() |
52 | { |
53 | delete sSelf; |
54 | sSelf = 0; |
55 | } |
56 | }; |
57 | FreeBusyUrlStore *FreeBusyUrlStore::Private::sSelf = 0; |
58 | //@endcond |
59 | |
60 | FreeBusyUrlStore *FreeBusyUrlStore::self() |
61 | { |
62 | static Private p; |
63 | if ( !p.sSelf ) { |
64 | p.sSelf = new FreeBusyUrlStore(); |
65 | qAddPostRoutine( Private::cleanupFreeBusyUrlStore ); |
66 | } |
67 | return p.sSelf; |
68 | } |
69 | |
70 | FreeBusyUrlStore::FreeBusyUrlStore() : d( new Private() ) |
71 | { |
72 | QString configFile = |
73 | KStandardDirs::locateLocal( "data" , "korganizer/freebusyurls" ); |
74 | d->mConfig = new KConfig( configFile ); |
75 | } |
76 | |
77 | FreeBusyUrlStore::~FreeBusyUrlStore() |
78 | { |
79 | delete d->mConfig; |
80 | delete d; |
81 | } |
82 | |
83 | void FreeBusyUrlStore::writeUrl( const QString &email, const QString &url ) |
84 | { |
85 | KConfigGroup group = d->mConfig->group( email ); |
86 | group.writeEntry( "url" , url ); |
87 | } |
88 | |
89 | QString FreeBusyUrlStore::readUrl( const QString &email ) |
90 | { |
91 | KConfigGroup group = d->mConfig->group( email ); |
92 | return group.readEntry( "url" ); |
93 | } |
94 | |
95 | void FreeBusyUrlStore::sync() |
96 | { |
97 | d->mConfig->sync(); |
98 | } |
99 | |