Rev 3096 | Rev 3459 | 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" |
2673 | cbradney | 2 | #include <qapplication.h> |
3096 | fschmid | 3 | #include <qdir.h> |
1693 | craig | 4 | |
2688 | craig | 5 | #include "scconfig.h" |
2673 | cbradney | 6 | |
1693 | craig | 7 | // On Qt/Mac we need CoreFoundation to discover the location |
8 | // of the app bundle. |
||
2673 | cbradney | 9 | #ifdef BUILD_MAC_BUNDLE |
1693 | craig | 10 | #include <CoreFoundation/CoreFoundation.h> |
11 | #endif |
||
12 | |||
3096 | fschmid | 13 | #ifdef _WIN32 |
14 | #include <windows.h> |
||
15 | #include <shlobj.h> |
||
16 | #endif |
||
17 | |||
1693 | craig | 18 | // Init the singleton's "self" address to NULL |
19 | ScPaths* ScPaths::m_instance = NULL; |
||
20 | |||
21 | // Singleton's public constructor |
||
22 | const ScPaths& ScPaths::instance() |
||
23 | { |
||
24 | if (!ScPaths::m_instance) |
||
25 | ScPaths::m_instance = new ScPaths(); |
||
26 | return *ScPaths::m_instance; |
||
27 | } |
||
28 | |||
29 | // Singleton's public destructor |
||
30 | void ScPaths::destroy() |
||
31 | { |
||
32 | if (ScPaths::m_instance) |
||
33 | delete ScPaths::m_instance; |
||
34 | } |
||
35 | |||
36 | // Protected "real" constructor |
||
37 | // All paths are initialized to compile-time defaults passed in |
||
38 | // as preprocessor macros and set by autoconf. |
||
39 | ScPaths::ScPaths() : |
||
40 | m_docDir(DOCDIR), |
||
41 | m_iconDir(ICONDIR), |
||
42 | m_libDir(LIBDIR), |
||
43 | m_pluginDir(PLUGINDIR), |
||
44 | m_sampleScriptDir(SAMPLESDIR), |
||
45 | m_scriptDir(SCRIPTSDIR), |
||
2707 | subik | 46 | m_templateDir(TEMPLATEDIR), |
47 | m_shareDir(SHAREDIR) |
||
1693 | craig | 48 | { |
49 | // On MacOS/X, override the compile-time settings with a location |
||
50 | // obtained from the system. |
||
2673 | cbradney | 51 | #ifdef BUILD_MAC_BUNDLE |
1693 | craig | 52 | // Set up the various app paths to look inside the app bundle |
53 | CFURLRef pluginRef = CFBundleCopyBundleURL(CFBundleGetMainBundle()); |
||
54 | CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef, |
||
55 | kCFURLPOSIXPathStyle); |
||
56 | const char *pathPtr = CFStringGetCStringPtr(macPath, |
||
57 | CFStringGetSystemEncoding()); |
||
2673 | cbradney | 58 | char *p = pathPtr + strlen(pathPtr) -1; |
59 | while (*p == '/') |
||
60 | --p; |
||
61 | ++p; |
||
62 | *p = '\0'; |
||
63 | if (strcmp("/bin", p-4) == 0) { |
||
64 | p -= 4; |
||
65 | *p = '\0'; |
||
66 | } |
||
67 | if (strcmp("/MacOS", p-6) == 0) { |
||
68 | p -= 6; |
||
69 | *p = '\0'; |
||
70 | } |
||
71 | if (strcmp("/Contents", p-9) == 0) { |
||
72 | p -= 9; |
||
73 | *p = '\0'; |
||
74 | } |
||
2707 | subik | 75 | |
2673 | cbradney | 76 | // qDebug(QString("scpaths: bundle at %1:").arg(pathPtr)); |
2707 | subik | 77 | m_shareDir = strdup(QString("%1/Contents/share/scribus/").arg(pathPtr)); |
2673 | cbradney | 78 | m_docDir = strdup(QString("%1/Contents/share/scribus/doc/").arg(pathPtr)); |
79 | m_iconDir = strdup(QString("%1/Contents/share/scribus/icons/").arg(pathPtr)); |
||
80 | m_sampleScriptDir = strdup(QString("%1/Contents/share/scribus/samples/").arg(pathPtr)); |
||
81 | m_scriptDir = strdup(QString("%1/Contents/share/scribus/scripts/").arg(pathPtr)); |
||
82 | m_templateDir = strdup(QString("%1/Contents/share/scribus/templates/").arg(pathPtr)); |
||
83 | m_libDir = strdup(QString("%1/Contents/lib/scribus/").arg(pathPtr)); |
||
84 | m_pluginDir = strdup(QString("%1/Contents/lib/scribus/plugins/").arg(pathPtr)); |
||
85 | QApplication::setLibraryPaths(QString("%1/Contents/lib/qtplugins/").arg(pathPtr)); |
||
1693 | craig | 86 | CFRelease(pluginRef); |
87 | CFRelease(macPath); |
||
2673 | cbradney | 88 | /* |
89 | qDebug(QString("scpaths: doc dir=%1").arg(m_docDir)); |
||
90 | qDebug(QString("scpaths: icon dir=%1").arg(m_iconDir)); |
||
91 | qDebug(QString("scpaths: sample dir=%1").arg(m_sampleScriptDir)); |
||
92 | qDebug(QString("scpaths: script dir=%1").arg(m_scriptDir)); |
||
93 | qDebug(QString("scpaths: template dir=%1").arg(m_templateDir)); |
||
94 | qDebug(QString("scpaths: lib dir=%1").arg(m_libDir)); |
||
95 | qDebug(QString("scpaths: plugin dir=%1").arg(m_pluginDir)); |
||
96 | qDebug(QString("scpaths: qtplugins=%1").arg(QApplication::libraryPaths().join(":"))); |
||
97 | */ |
||
3096 | fschmid | 98 | #elif defined(_WIN32) |
99 | QString appPath = qApp->applicationDirPath(); |
||
100 | m_shareDir = strdup(QString("%1/share/").arg(appPath)); |
||
101 | m_docDir = strdup(QString("%1/share/doc/").arg(appPath)); |
||
102 | m_iconDir = strdup(QString("%1/share/icons/").arg(appPath)); |
||
103 | m_sampleScriptDir = strdup(QString("%1/share/samples/").arg(appPath)); |
||
104 | m_scriptDir = strdup(QString("%1/share/scripts/").arg(appPath)); |
||
105 | m_templateDir = strdup(QString("%1/share/templates/").arg(appPath)); |
||
106 | m_libDir = strdup(QString("%1/libs/").arg(appPath)); |
||
107 | m_pluginDir = strdup(QString("%1/plugins/").arg(appPath)); |
||
108 | #endif |
||
1693 | craig | 109 | } |
110 | |||
111 | ScPaths::~ScPaths() {}; |
||
112 | |||
113 | const QString& ScPaths::docDir() const |
||
114 | { |
||
115 | return m_docDir; |
||
116 | } |
||
117 | |||
118 | const QString& ScPaths::iconDir() const |
||
119 | { |
||
120 | return m_iconDir; |
||
121 | } |
||
122 | |||
123 | const QString& ScPaths::libDir() const |
||
124 | { |
||
125 | return m_libDir; |
||
126 | } |
||
127 | |||
128 | const QString& ScPaths::pluginDir() const |
||
129 | { |
||
130 | return m_pluginDir; |
||
131 | } |
||
132 | |||
133 | const QString& ScPaths::sampleScriptDir() const |
||
134 | { |
||
135 | return m_sampleScriptDir; |
||
136 | } |
||
137 | |||
138 | const QString& ScPaths::scriptDir() const |
||
139 | { |
||
140 | return m_scriptDir; |
||
141 | } |
||
142 | |||
143 | const QString& ScPaths::templateDir() const |
||
144 | { |
||
145 | return m_templateDir; |
||
146 | } |
||
147 | |||
2707 | subik | 148 | const QString& ScPaths::shareDir() const |
149 | { |
||
150 | return m_shareDir; |
||
151 | } |
||
3096 | fschmid | 152 | |
153 | QStringList ScPaths::getSystemFontDirs(void) |
||
154 | { |
||
155 | QStringList fontDirs; |
||
3102 | avox | 156 | #ifdef Q_OS_MAC |
3096 | fschmid | 157 | fontDirs.append(QDir::homeDirPath() + "/Library/Fonts/"); |
158 | fontDirs.append("/Library/Fonts/"); |
||
159 | fontDirs.append("/Network/Library/Fonts/"); |
||
160 | fontDirs.append("/System/Library/Fonts/"); |
||
161 | #elif defined(_WIN32) |
||
162 | fontDirs.append( getSpecialDir(CSIDL_FONTS) ); |
||
163 | #endif |
||
164 | return fontDirs; |
||
165 | } |
||
166 | |||
167 | QStringList ScPaths::getSystemProfilesDirs(void) |
||
168 | { |
||
169 | QStringList iccProfDirs; |
||
3102 | avox | 170 | #ifdef Q_OS_MAC |
3096 | fschmid | 171 | iccProfDirs.append(QDir::homeDirPath()+"/Library/ColorSync/Profiles/"); |
172 | iccProfDirs.append("/System/Library/ColorSync/Profiles/"); |
||
173 | iccProfDirs.append("/Library/ColorSync/Profiles/"); |
||
174 | #elif defined(Q_WS_X11) |
||
175 | iccProfDirs.append(QDir::homeDirPath()+"/color/icc/"); |
||
176 | iccProfDirs.append(QDir::homeDirPath()+"/.color/icc/"); |
||
177 | iccProfDirs.append("/usr/share/color/icc/"); |
||
178 | #elif defined(_WIN32) |
||
179 | // On Windows it's more complicated, profiles location depends on OS version |
||
180 | char sysDir[MAX_PATH + 1]; |
||
181 | OSVERSIONINFO osVersion; |
||
182 | ZeroMemory( &osVersion, sizeof(OSVERSIONINFO)); |
||
183 | osVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); // Necessary for GetVersionEx to succeed |
||
184 | GetVersionEx(&osVersion); // Get Windows version infos |
||
185 | GetSystemDirectory( sysDir, MAX_PATH ); // getSpecialDir(CSIDL_SYSTEM) fails on Win9x |
||
186 | QString winSysDir = QString(sysDir).replace('\\','/'); |
||
187 | if( osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT ) // Windows NT/2k/XP |
||
188 | { |
||
189 | if( osVersion.dwMajorVersion >= 5 ) // for 2k and XP dwMajorVersion == 5 |
||
190 | iccProfDirs.append( winSysDir + "/Spool/Drivers/Color/"); |
||
191 | } |
||
192 | else if( osVersion.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS ) // Windows 9x/Me |
||
193 | { |
||
194 | if( osVersion.dwMajorVersion >= 4 && osVersion.dwMinorVersion >= 10) // Win98 or WinMe |
||
195 | iccProfDirs.append( winSysDir + "/Color/"); |
||
196 | } |
||
197 | #endif |
||
198 | return iccProfDirs; |
||
199 | } |
||
200 | |||
201 | QString ScPaths::getSpecialDir(int folder) |
||
202 | { |
||
203 | QString qstr; |
||
204 | #if defined(_WIN32) |
||
205 | char dir[256]; |
||
206 | SHGetSpecialFolderPath(NULL, dir, folder , false); |
||
207 | qstr = dir; |
||
208 | if( !qstr.endsWith("\\") ) |
||
209 | qstr += "\\"; |
||
210 | qstr.replace( '\\', '/' ); |
||
211 | #else |
||
212 | Q_ASSERT(false); |
||
213 | #endif |
||
214 | return qstr; |
||
215 | } |