2
Copyright (c) 2011 Volker Krause <vkrause@kde.org>
4
This library is free software; you can redistribute it and/or modify it
5
under the terms of the GNU Library General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or (at your
7
option) any later version.
9
This library is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12
License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to the
16
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20
#include "akstandarddirs.h"
21
#include "akapplication.h"
23
#include <libs/xdgbasedirs_p.h>
27
using namespace Akonadi;
29
QString AkStandardDirs::configFile(const QString& configFile, Akonadi::XdgBaseDirs::FileAccessMode openMode)
31
const QString savePath = AkStandardDirs::saveDir( "config" ) + QLatin1Char( '/' ) + configFile;
33
if ( openMode == XdgBaseDirs::WriteOnly )
36
QString path = XdgBaseDirs::findResourceFile( "config", QLatin1String("akonadi/") + configFile );
37
// HACK: when using instance namespaces, ignore the non-namespaced file
38
if ( !AkApplication::instanceIdentifier().isEmpty() && path.startsWith( XdgBaseDirs::homePath("config") ) )
41
if ( path.isEmpty() ) {
43
} else if ( openMode == XdgBaseDirs::ReadOnly || path == savePath ) {
47
// file found in system paths and mode is ReadWrite, thus
48
// we copy to the home path location and return this path
49
QFile systemFile( path );
51
systemFile.copy( savePath );
56
QString AkStandardDirs::serverConfigFile(XdgBaseDirs::FileAccessMode openMode)
58
return configFile( QLatin1String("akonadiserverrc"), openMode );
61
QString AkStandardDirs::connectionConfigFile(XdgBaseDirs::FileAccessMode openMode)
63
return configFile( QLatin1String("akonadiconnectionrc"), openMode );
66
QString AkStandardDirs::agentConfigFile(XdgBaseDirs::FileAccessMode openMode)
68
return configFile( QLatin1String("agentsrc"), openMode );
71
QString AkStandardDirs::saveDir(const char* resource, const QString& relPath)
73
QString fullRelPath = QLatin1String("akonadi");
74
if ( !AkApplication::instanceIdentifier().isEmpty() )
75
fullRelPath += QLatin1String("/instance/") + AkApplication::instanceIdentifier();
76
if ( !relPath.isEmpty() )
77
fullRelPath += QLatin1Char('/') + relPath;
78
return XdgBaseDirs::saveDir( resource, fullRelPath );