Rev 1693 | Rev 2673 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1693 | craig | 1 | #include "scpaths.h" |
2 | #include "qstring.h" |
||
3 | |||
4 | // On Qt/Mac we need CoreFoundation to discover the location |
||
5 | // of the app bundle. |
||
6 | #ifdef QT_MAC |
||
7 | #include <CoreFoundation/CoreFoundation.h> |
||
8 | #endif |
||
9 | |||
10 | // Init the singleton's "self" address to NULL |
||
11 | ScPaths* ScPaths::m_instance = NULL; |
||
12 | |||
13 | // Singleton's public constructor |
||
14 | const ScPaths& ScPaths::instance() |
||
15 | { |
||
16 | if (!ScPaths::m_instance) |
||
17 | ScPaths::m_instance = new ScPaths(); |
||
18 | return *ScPaths::m_instance; |
||
19 | } |
||
20 | |||
21 | // Singleton's public destructor |
||
22 | void ScPaths::destroy() |
||
23 | { |
||
24 | if (ScPaths::m_instance) |
||
25 | delete ScPaths::m_instance; |
||
26 | } |
||
27 | |||
28 | // Protected "real" constructor |
||
29 | // All paths are initialized to compile-time defaults passed in |
||
30 | // as preprocessor macros and set by autoconf. |
||
31 | ScPaths::ScPaths() : |
||
32 | m_docDir(DOCDIR), |
||
33 | m_iconDir(ICONDIR), |
||
34 | m_libDir(LIBDIR), |
||
35 | m_pluginDir(PLUGINDIR), |
||
36 | m_sampleScriptDir(SAMPLESDIR), |
||
37 | m_scriptDir(SCRIPTSDIR), |
||
38 | m_templateDir(TEMPLATEDIR) |
||
39 | { |
||
40 | // On MacOS/X, override the compile-time settings with a location |
||
41 | // obtained from the system. |
||
1695 | craig | 42 | #if defined(QT_MAC) && defined(BUILD_MAC_BUNDLE) |
1693 | craig | 43 | // Set up the various app paths to look inside the app bundle |
44 | CFURLRef pluginRef = CFBundleCopyBundleURL(CFBundleGetMainBundle()); |
||
45 | CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef, |
||
46 | kCFURLPOSIXPathStyle); |
||
47 | const char *pathPtr = CFStringGetCStringPtr(macPath, |
||
48 | CFStringGetSystemEncoding()); |
||
49 | m_docDir = strdup(QString("%1/Resources/docs/").arg(pathPtr)); |
||
50 | m_iconDir = strdup(QString("%1/Resources/icons/").arg(pathPtr)); |
||
51 | m_sampleDir = strdup(QString("%1/Resources/samples/").arg(pathPtr)); |
||
52 | m_scriptDir = strdup(QString("%1/Resources/scripts/").arg(pathPtr)); |
||
53 | m_templateDir = strdup(QString("%1/Resources/templates/").arg(pathPtr)); |
||
54 | m_libDir = strdup(QString("%1/Resources/lib/").arg(pathPtr)); |
||
55 | m_pluginDir = strdup(QString("%1/Resources/plugins/").arg(pathPtr)); |
||
56 | CFRelease(pluginRef); |
||
57 | CFRelease(macPath); |
||
58 | #endif // defined(QT_MAC) |
||
59 | } |
||
60 | |||
61 | ScPaths::~ScPaths() {}; |
||
62 | |||
63 | const QString& ScPaths::docDir() const |
||
64 | { |
||
65 | return m_docDir; |
||
66 | } |
||
67 | |||
68 | const QString& ScPaths::iconDir() const |
||
69 | { |
||
70 | return m_iconDir; |
||
71 | } |
||
72 | |||
73 | const QString& ScPaths::libDir() const |
||
74 | { |
||
75 | return m_libDir; |
||
76 | } |
||
77 | |||
78 | const QString& ScPaths::pluginDir() const |
||
79 | { |
||
80 | return m_pluginDir; |
||
81 | } |
||
82 | |||
83 | const QString& ScPaths::sampleScriptDir() const |
||
84 | { |
||
85 | return m_sampleScriptDir; |
||
86 | } |
||
87 | |||
88 | const QString& ScPaths::scriptDir() const |
||
89 | { |
||
90 | return m_scriptDir; |
||
91 | } |
||
92 | |||
93 | const QString& ScPaths::templateDir() const |
||
94 | { |
||
95 | return m_templateDir; |
||
96 | } |
||
97 |