dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
pathutils.cpp
Go to the documentation of this file.
1 
13 /*
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  * for more details.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, see <http://www.gnu.org/licenses/>
26  */
27 
28 #include "pathutils.h"
29 #include "xmlconfig.h"
30 #include <qglobal.h>
31 #include <QDebug>
32 
33 
34 namespace Utils {
35 
36 QString PathUtils::settingsFilename = "";
37 
39 {
40 
41 }
42 
48 {
49  // This routine works with "/" as the standard:
50  // Figure out root: Up one from 'bin'
51  QDir rootDir = QApplication::applicationDirPath();
52  rootDir.cdUp();
53  const QString rootDirPath = rootDir.canonicalPath();
54  QString dataPath = rootDirPath;
55  dataPath += QLatin1Char('/');
56  dataPath += QLatin1String(GCS_DATA_BASENAME);
57  dataPath += QLatin1Char('/');
58  return dataPath;
59 }
60 
67 QString PathUtils::RemoveDataPath(QString path)
68 {
69  // Depending on the platform, we might get either "/" or "\"
70  // so we need to go to the standard ("/")
71  QString goodPath = QDir::fromNativeSeparators(path);
72  if (goodPath.startsWith(GetDataPath())) {
73  int i = goodPath.length()- GetDataPath().length();
74  return QString("%%DATAPATH%%") + goodPath.right(i);
75  } else
76  return goodPath;
77 }
78 
84 QString PathUtils::InsertDataPath(QString path)
85 {
86  if (path.startsWith(QString("%%DATAPATH%%")))
87  {
88  QString newPath = GetDataPath();
89  newPath += path.right(path.length()-12);
90  return QDir::toNativeSeparators(newPath);
91  }
92  return QDir::toNativeSeparators(path);
93 }
94 
99 {
100  // This routine works with "/" as the standard:
101  // Work out where the settings are stored on the machine
102  QFileInfo f;
103  if(!getSettingsFilename().isEmpty())
104  f.setFile(getSettingsFilename());
105  else {
106  QSettings set(XmlConfig::XmlSettingsFormat, QSettings::UserScope,QLatin1String(GCS_PROJECT_BRANDING), QLatin1String(GCS_PROJECT_BRANDING "_config"));
107  f.setFile(set.fileName());
108  }
109  QDir dir(f.absoluteDir());
110 
111  const QString homeDirPath = dir.canonicalPath();
112  QString storagePath = homeDirPath;
113  storagePath += QLatin1Char('/');
114  return storagePath;
115 }
116 
120 QString PathUtils::RemoveStoragePath(QString path)
121 {
122  // Depending on the platform, we might get either "/" or "\"
123  // so we need to go to the standard ("/")
124  QString goodPath = QDir::fromNativeSeparators(path);
125  if (goodPath.startsWith(GetStoragePath())) {
126  int i = goodPath.length()- GetStoragePath().length();
127  return QString("%%STOREPATH%%") + goodPath.right(i);
128  } else
129  return goodPath;
130 }
131 
135 QString PathUtils::InsertStoragePath(QString path)
136 {
137  if (path.startsWith(QString("%%STOREPATH%%")))
138  {
139  QString newPath = GetStoragePath();
140  newPath += path.right(path.length()-13);
141  return QDir::toNativeSeparators(newPath);
142  }
143  return QDir::toNativeSeparators(path);
144 
145 }
146 
148 {
149  return PathUtils::settingsFilename;
150 }
151 
152 void PathUtils::setSettingsFilename(QString filename)
153 {
154  PathUtils::settingsFilename = filename;
155 }
156 
157 }
void setSettingsFilename(QString filename)
Definition: pathutils.cpp:152
QString getSettingsFilename()
Definition: pathutils.cpp:147
for i
Definition: OPPlots.m:140
static QString GetDataPath()
Definition: pathutils.cpp:47
QString RemoveStoragePath(QString path)
Definition: pathutils.cpp:120
static QString RemoveDataPath(QString path)
Definition: pathutils.cpp:67
QString GetStoragePath()
Definition: pathutils.cpp:98
static const QSettings::Format XmlSettingsFormat
Definition: xmlconfig.h:43
QString InsertStoragePath(QString path)
Definition: pathutils.cpp:135
static QString InsertDataPath(QString path)
Definition: pathutils.cpp:84