Stellarium 0.15.2
StelFileMgr.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2008 Stellarium Developers
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program 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 General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18  */
19 
20 #ifndef _STELFILEMGR_HPP_
21 #define _STELFILEMGR_HPP_
22 
23 #define CHECK_FILE "data/ssystem.ini"
24 
25 #include <stdexcept>
26 #include <QSet>
27 #include <QString>
28 #include <QStringList>
29 
30 class QFileInfo;
31 
43 {
44 public:
46  enum Flags {
47  RemovableMedia = 0x00000001,
48  Writable = 0x00000002,
49  Directory = 0x00000004,
51  File = 0x00000008,
52  New = 0x00000010
53  };
54 
60  static void init();
61 
76  static QString findFile(const QString& path, Flags flags=(Flags)0);
77 
83  static QStringList findFileInAllPaths(const QString& path, const Flags& flags=(Flags)0);
84 
92  static QSet<QString> listContents(const QString& path, const Flags& flags=(Flags)0, bool recursive=false);
93 
96  static const QStringList& getSearchPaths(void) {return fileLocations;}
97 
100  static void setSearchPaths(const QStringList& paths);
101 
104  static void makeSureDirExistsAndIsWritable(const QString& dirFullPath);
105 
108  static bool exists(const QString& path);
109 
112  static bool isAbsolute(const QString& path);
113 
117  static bool isReadable(const QString& path);
118 
126  static bool isWritable(const QString& path);
127 
130  static bool isDirectory(const QString& path);
131 
134  static qint64 size(const QString& path);
135 
139  static bool mkDir(const QString& path);
140 
144  static QString dirName(const QString& path);
145 
149  static QString baseName(const QString& path);
150 
155  static QString getDesktopDir();
156 
163  static QString getUserDir();
164 
169  static QString getInstallationDir();
170 
172  static QString getCacheDir();
173 
177  static void setUserDir(const QString& newDir);
178 
184  static QString getScreenshotDir();
185 
191  static void setScreenshotDir(const QString& newDir);
192 
195  static QString getLocaleDir();
196 
197 private:
198 
200  StelFileMgr() {;}
201 
207  static bool fileFlagsCheck(const QFileInfo& thePath, const Flags& flags=(Flags)0);
208 
209  static QStringList fileLocations;
210 
212  static QString userDir;
213 
215  static QString screenshotDir;
216 
218  static QString installDir;
219 
220 #ifdef Q_OS_WIN
221  static QString getWin32SpecialDirPath(int csidlId);
224 #endif
225 
226 };
227 
228 #endif // _STELFILEMGR_HPP_
static QString getScreenshotDir()
This is the directory into which screenshots will be saved.
Flags
used as named bitfield flags as specifiers to filter results of StelFileMgr methods.
Definition: StelFileMgr.hpp:46
Exclude non-directories.
Definition: StelFileMgr.hpp:50
static void init()
Initialize the directories.
static void setUserDir(const QString &newDir)
Sets the user directory.
static bool isAbsolute(const QString &path)
Check if a path is absolute.
static bool isWritable(const QString &path)
Check if a path is writable For files, true is returned if the file exists and is writable or if the ...
static bool isReadable(const QString &path)
Check if a path is readable.
static QString baseName(const QString &path)
Convenience function to find the basename of a given path May return relative paths if the parameter ...
static QString getLocaleDir()
get the directory for locate files (i18n)
static qint64 size(const QString &path)
Return the size of the file at the path.
static bool exists(const QString &path)
Check if a path exists.
static void setSearchPaths(const QStringList &paths)
Set the search paths.
static QSet< QString > listContents(const QString &path, const Flags &flags=(Flags) 0, bool recursive=false)
Set a set of all possible files/directories in any Stellarium search directory.
Provides utilities for locating and handling files.
Definition: StelFileMgr.hpp:42
static QString dirName(const QString &path)
Convenience function to find the parent directory of a given path May return relative paths if the pa...
Exclude existing paths.
Definition: StelFileMgr.hpp:52
static bool isDirectory(const QString &path)
Check if a path exists and is a directory.
static bool mkDir(const QString &path)
Make a directory.
static const QStringList & getSearchPaths(void)
Get a vector of strings which describes the current search paths.
Definition: StelFileMgr.hpp:96
Exclude non-files.
Definition: StelFileMgr.hpp:51
Search on removable media if present (default is not to).
Definition: StelFileMgr.hpp:47
static void setScreenshotDir(const QString &newDir)
Sets the screenshot directory.
static QString getCacheDir()
Returns the path to the cache directory. Note that subdirectories may need to be created for specific...
static QString getInstallationDir()
Returns the path to the installation directory.
static void makeSureDirExistsAndIsWritable(const QString &dirFullPath)
Make sure the passed directory path exist and is writable.
static QString getDesktopDir()
Get the user&#39;s Desktop directory.
static QString getUserDir()
Returns the path to the user directory.
Only return writable paths.
Definition: StelFileMgr.hpp:48
static QStringList findFileInAllPaths(const QString &path, const Flags &flags=(Flags) 0)
List all paths within the search paths that match the argument.
static QString findFile(const QString &path, Flags flags=(Flags) 0)
Search for a path within the search paths, for example "textures/fog.png".