tuchulcha  0.10.1
Graphical Workflow Configuration Editor
FileManager.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2009 Jens-Malte Gottfried
2 
3  This file is part of Tuchulcha.
4 
5  Tuchulcha is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  Tuchulcha is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with Tuchulcha. If not, see <http://www.gnu.org/licenses/>.
17  */
24 #include "FileManager.h"
25 #include <QTextStream>
26 
27 #ifndef TUCHULCHA_DIR
28 
33 #define TUCHULCHA_DIR ".tuchulcha"
34 #endif
35 
37 
38 QWidget* FileManager::dialogParent = 0;
39 
40 FileManager::FileManager() {
41  // set up tuchulcha dir and path structure
42  if (!QDir::home().exists(TUCHULCHA_DIR)) {
43  QDir::home().mkdir(TUCHULCHA_DIR);
44  }
45  QString configPath = QDir::homePath() + "/" + TUCHULCHA_DIR;
46  QFileInfo configPathInfo(configPath);
47  if (!configPathInfo.exists()) {
48  qFatal("%s",
49  (tr("Tuchulcha configuration directory \"%1\" "
50  "could not be created. Are permissions set correctly?")
51  .arg(configPath))
52  .toLocal8Bit().constData());
53  }
54  else if (!configPathInfo.isDir()) {
55  qFatal("%s",
56  (tr("Tuchulcha configuration directory \"%1\" "
57  "exists, but is not a directory. Please delete "
58  "\"%1\".")
59  .arg(configPath))
60  .toLocal8Bit().constData());
61  }
62  else if (!QFileInfo(configPath+"/metadata").exists()) {
63  QDir::home().mkpath(TUCHULCHA_DIR "/metadata");
64  }
65 }
66 
68 }
69 
71  if (!_inst) {
72  _inst = new FileManager();
73  }
74  return *_inst;
75 }
76 
77 QDir FileManager::configDir() const {
78  QDir ret = QDir::home();
79  bool ok = ret.cd(TUCHULCHA_DIR);
80  if (!ok)
81  qFatal("%s", (tr("Failed to change to directory \"%1\".")
82  .arg(QDir::homePath() + "/" + TUCHULCHA_DIR))
83  .toLocal8Bit().constData());
84  return ret;
85 }
86 
87 QString FileManager::classesFile() const {
88  return QDir::homePath() + "/" + TUCHULCHA_DIR + "/classes.wrp";
89 }
Declaration of class FileManager.
static const FileManager & instance()
get a reference to the file Manager instance
Definition: FileManager.cpp:70
static QWidget * dialogParent
parent widget for operation result dialogs
Definition: FileManager.h:46
QDir configDir() const
get config directory
Definition: FileManager.cpp:77
bool charon_core_DLL_PUBLIC exists(const std::string &file)
virtual ~FileManager()
forbid copying
Definition: FileManager.cpp:67
Common config file information and handling.
Definition: FileManager.h:37
QString classesFile() const
get the path of the classes file
Definition: FileManager.cpp:87
static FileManager * _inst
pointer to FileManager instance
Definition: FileManager.h:61
#define TUCHULCHA_DIR
Tuchulcha config path.
Definition: FileManager.cpp:33