1 | /* |
---|---|
2 | * Copyright (c) 2009 Volker Krause <vkrause@kde.org> |
3 | * |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Lesser General Public |
6 | * License as published by the Free Software Foundation; either |
7 | * version 2.1 of the License, or (at your option) any later version. |
8 | * |
9 | * This library is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Lesser General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Lesser General Public |
15 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
16 | */ |
17 | |
18 | #include "global.h" |
19 | |
20 | #include <kglobal.h> |
21 | #include <QDir> |
22 | #include <kstandarddirs.h> |
23 | #include <KDebug> |
24 | |
25 | class GlobalPrivate |
26 | { |
27 | public: |
28 | GlobalPrivate() : parent( new QObject() ) {} |
29 | QString basePath; |
30 | QString vmPath; |
31 | QObject *parent; |
32 | }; |
33 | |
34 | K_GLOBAL_STATIC( GlobalPrivate, sInstance ) |
35 | |
36 | QString Global::basePath() |
37 | { |
38 | return sInstance->basePath; |
39 | } |
40 | |
41 | void Global::setBasePath(const QString& path) |
42 | { |
43 | sInstance->basePath = path; |
44 | if ( !path.endsWith( QDir::separator() ) ) |
45 | sInstance->basePath += QDir::separator(); |
46 | } |
47 | |
48 | QString Global::vmPath() |
49 | { |
50 | if ( sInstance->vmPath.isEmpty() ) |
51 | setVMPath( KStandardDirs::locateLocal( "cache", "akonadi-resourcetester/", true ) ); |
52 | return sInstance->vmPath; |
53 | } |
54 | |
55 | void Global::setVMPath(const QString& path) |
56 | { |
57 | kDebug() << path; |
58 | sInstance->vmPath = path; |
59 | if ( !path.endsWith( QDir::separator() ) ) |
60 | sInstance->vmPath += QDir::separator(); |
61 | const QDir dir( path ); |
62 | if ( !dir.exists() ) |
63 | QDir::root().mkpath( path ); |
64 | } |
65 | |
66 | QObject* Global::parent() |
67 | { |
68 | Q_ASSERT( sInstance->parent ); |
69 | return sInstance->parent; |
70 | } |
71 | |
72 | void Global::cleanup() |
73 | { |
74 | delete sInstance->parent; |
75 | sInstance->parent = 0; |
76 | } |
77 |