~ubuntu-branches/ubuntu/quantal/akonadi/quantal

« back to all changes in this revision

Viewing changes to shared/akstandarddirs.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2012-01-24 23:43:13 UTC
  • mto: (3.1.12 sid)
  • mto: This revision was merged to the branch mainline in revision 69.
  • Revision ID: package-import@ubuntu.com-20120124234313-ooald4uh9w8jilyw
Tags: upstream-1.7.0
ImportĀ upstreamĀ versionĀ 1.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (c) 2011 Volker Krause <vkrause@kde.org>
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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
 
17
    02110-1301, USA.
 
18
*/
 
19
 
 
20
#include "akstandarddirs.h"
 
21
#include "akapplication.h"
 
22
 
 
23
#include <libs/xdgbasedirs_p.h>
 
24
 
 
25
#include <QFile>
 
26
 
 
27
using namespace Akonadi;
 
28
 
 
29
QString AkStandardDirs::configFile(const QString& configFile, Akonadi::XdgBaseDirs::FileAccessMode openMode)
 
30
{
 
31
  const QString savePath = AkStandardDirs::saveDir( "config" ) + QLatin1Char( '/' ) + configFile;
 
32
 
 
33
  if ( openMode == XdgBaseDirs::WriteOnly )
 
34
    return savePath;
 
35
 
 
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") ) )
 
39
    path.clear();
 
40
 
 
41
  if ( path.isEmpty() ) {
 
42
    return savePath;
 
43
  } else if ( openMode == XdgBaseDirs::ReadOnly || path == savePath ) {
 
44
    return path;
 
45
  }
 
46
 
 
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 );
 
50
 
 
51
  systemFile.copy( savePath );
 
52
 
 
53
  return savePath;
 
54
}
 
55
 
 
56
QString AkStandardDirs::serverConfigFile(XdgBaseDirs::FileAccessMode openMode)
 
57
{
 
58
  return configFile( QLatin1String("akonadiserverrc"), openMode );
 
59
}
 
60
 
 
61
QString AkStandardDirs::connectionConfigFile(XdgBaseDirs::FileAccessMode openMode)
 
62
{
 
63
  return configFile( QLatin1String("akonadiconnectionrc"), openMode );
 
64
}
 
65
 
 
66
QString AkStandardDirs::agentConfigFile(XdgBaseDirs::FileAccessMode openMode)
 
67
{
 
68
  return configFile( QLatin1String("agentsrc"), openMode );
 
69
}
 
70
 
 
71
QString AkStandardDirs::saveDir(const char* resource, const QString& relPath)
 
72
{
 
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 );
 
79
}