Torc  0.1
torcdirectories.cpp
Go to the documentation of this file.
1 /* TorcDirectories
2 *
3 * This file is part of the Torc project.
4 *
5 * Copyright (C) Mark Kendall 2012-18
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 * USA.
21 */
22 
23 // Qt
24 #include <QDir>
25 
26 // Torc
27 #include "torclogging.h"
28 #include "torclocaldefs.h"
29 #include "torcdirectories.h"
30 
31 static QString gInstallDir = QStringLiteral("");
32 static QString gShareDir = QStringLiteral("");
33 static QString gConfDir = QStringLiteral("");
34 static QString gTransDir = QStringLiteral("");
35 static QString gContentDir = QStringLiteral("");
36 
51 {
52  static bool initialised = false;
53  if (initialised)
54  return;
55 
56  initialised = true;
57 
58  gInstallDir = QStringLiteral("%1/").arg(QStringLiteral(PREFIX));
59  gShareDir = QStringLiteral("%1/share/%2").arg(QStringLiteral(RUNPREFIX), TORC_TORC);
60  // override shared directory
61  QString sharedir = CommandLine ? CommandLine->GetValue(QStringLiteral("share")).toString() : QStringLiteral();
62  if (!sharedir.isEmpty())
63  gShareDir = sharedir;
64 
65  gTransDir = gShareDir + QStringLiteral("/i18n/");
66  // override translation directory - which may be done independantly of shared directory
67  QString transdir = CommandLine ? CommandLine->GetValue(QStringLiteral("trans")).toString() : QStringLiteral();
68  if (!transdir.isEmpty())
69  gTransDir = transdir;
70 
71  gConfDir = QDir::homePath() + "/." + TORC_TORC;
72  // override config directory - and by implication the content directory
73  QString confdir = CommandLine ? CommandLine->GetValue(QStringLiteral("config")).toString() : QStringLiteral();
74  if (!confdir.isEmpty())
75  gConfDir = confdir;
77 }
78 
83 QString GetTorcConfigDir(void)
84 {
85  return gConfDir;
86 }
87 
92 QString GetTorcShareDir(void)
93 {
94  return gShareDir;
95 }
96 
98 QString GetTorcTransDir(void)
99 {
100  return gTransDir;
101 }
102 
104 QString GetTorcContentDir(void)
105 {
106  return gContentDir;
107 }
#define TORC_CONTENT_DIR
Definition: torclocaldefs.h:19
QString GetTorcShareDir(void)
Return the path to the installed Torc shared resources.
Torc command line handler.
static QString gShareDir
static QString gTransDir
static QString gContentDir
#define TORC_TORC
Definition: torclocaldefs.h:8
QString GetTorcContentDir(void)
brief Return the path to generated content
void InitialiseTorcDirectories(TorcCommandLine *CommandLine)
Statically initialise the various directories that Torc uses.
static QString gConfDir
static QString gInstallDir
QString GetTorcTransDir(void)
brief Return the path to installed translation files
QVariant GetValue(const QString &Key)
Return the value associated with Key or an invalid QVariant if the option is not present.
QString GetTorcConfigDir(void)
Return the path to the application configuration directory.