1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
/**
* Implements a singleton that maintains program resources.
* The single instance is (re)instantiated on demand like:
* Resources *res = Resources::Instance();
*
* 24-05-07,Nigel Brown(EMBL): created.
*/
#ifndef RESOURCES_H
#define RESOURCES_H
#include <QString>
#include <string>
enum ResourcePathType {
DefaultPath,
InstallPath,
ExecutablePath,
HomePath,
};
class Resources {
public:
/* return the Resources singleton */
static Resources *Instance();
/* setters */
void setPathToExecutable(QString pathToFiles);
/* getters */
QString getDefaultPath() { return defaultPath; }
QString getInstallPath() { return installPath; }
QString getExecutablePath() { return executablePath; }
QString getHomePath() { return homePath; }
std::string findFile(const char *file, const ResourcePathType where = DefaultPath) const;
std::string findFile(const std::string &file, const ResourcePathType where = DefaultPath) const;
std::string findFile(const QString &file, const ResourcePathType where = DefaultPath) const;
QString searchPathsForFile(const QString &fileName) const;
std::string searchPathsForFile(const std::string &fileName) const;
/* debug */
void dump();
protected:
/* hide the constructors */
Resources();
Resources(const Resources&);
Resources& operator= (const Resources&);
QString dirname(QString path);
private:
QString defaultPath;
QString installPath;
QString executablePath;
QString homePath;
};
#endif //RESOURCES_H
|