Subversion Repositories Scribus

Rev

Rev 4602 | Rev 4805 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4430 cbradney 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
1693 craig 7
#include "scpaths.h"
2673 cbradney 8
#include <qapplication.h>
3096 fschmid 9
#include <qdir.h>
1693 craig 10
 
2688 craig 11
#include "scconfig.h"
2673 cbradney 12
 
1693 craig 13
// On Qt/Mac we need CoreFoundation to discover the location
14
// of the app bundle.
2673 cbradney 15
#ifdef BUILD_MAC_BUNDLE
1693 craig 16
#include <CoreFoundation/CoreFoundation.h>
17
#endif
18
 
3096 fschmid 19
#ifdef _WIN32
20
#include <windows.h>
21
#include <shlobj.h>
22
#endif
23
 
4194 fschmid 24
#ifdef _WIN32
25
const char ScPaths::envPathSeparator = ';';
26
#else
27
const char ScPaths::envPathSeparator = ':';
28
#endif
29
 
1693 craig 30
// Init the singleton's "self" address to NULL
31
ScPaths* ScPaths::m_instance = NULL;
32
 
33
// Singleton's public constructor
34
const ScPaths& ScPaths::instance()
35
{
36
        if (!ScPaths::m_instance)
37
                ScPaths::m_instance = new ScPaths();
38
        return *ScPaths::m_instance;
39
}
40
 
41
// Singleton's public destructor
42
void ScPaths::destroy()
43
{
44
        if (ScPaths::m_instance)
45
                delete ScPaths::m_instance;
46
}
47
 
48
// Protected "real" constructor
49
// All paths are initialized to compile-time defaults passed in
50
// as preprocessor macros and set by autoconf.
51
ScPaths::ScPaths() :
52
        m_docDir(DOCDIR),
53
        m_iconDir(ICONDIR),
54
        m_libDir(LIBDIR),
55
        m_pluginDir(PLUGINDIR),
56
        m_sampleScriptDir(SAMPLESDIR),
57
        m_scriptDir(SCRIPTSDIR),
2707 subik 58
        m_templateDir(TEMPLATEDIR),
59
        m_shareDir(SHAREDIR)
1693 craig 60
{
61
// On MacOS/X, override the compile-time settings with a location
62
// obtained from the system.
2673 cbradney 63
#ifdef BUILD_MAC_BUNDLE
1693 craig 64
        // Set up the various app paths to look inside the app bundle
65
        CFURLRef pluginRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
66
        CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef,
67
                                               kCFURLPOSIXPathStyle);
68
        const char *pathPtr = CFStringGetCStringPtr(macPath,
69
                                               CFStringGetSystemEncoding());
3546 avox 70
 
71
        // make sure we get the Scribus.app directory, not some subdir
72
 
73
        // strip trailing '/':
3459 avox 74
        char *p = const_cast<char*>(pathPtr + strlen(pathPtr) - 1);
2673 cbradney 75
        while (*p == '/')
76
                --p;
77
        ++p;
78
        *p = '\0';
79
        if (strcmp("/bin", p-4) == 0) {
80
                p -= 4;
81
                *p = '\0';
82
        }
83
        if (strcmp("/MacOS", p-6) == 0) {
84
                p -= 6;
85
                *p = '\0';
86
        }
87
        if (strcmp("/Contents", p-9) == 0) {
88
                p -= 9;
89
                *p = '\0';
90
        }
2707 subik 91
 
3546 avox 92
        qDebug(QString("scpaths: bundle at %1:").arg(pathPtr));
3794 cbradney 93
        m_shareDir = QString("%1/Contents/share/scribus/").arg(pathPtr);
94
        m_docDir = QString("%1/Contents/share/scribus/doc/").arg(pathPtr);
95
        m_iconDir = QString("%1/Contents/share/scribus/icons/").arg(pathPtr);
96
        m_sampleScriptDir = QString("%1/Contents/share/scribus/samples/").arg(pathPtr);
97
        m_scriptDir = QString("%1/Contents/share/scribus/scripts/").arg(pathPtr);
98
        m_templateDir = QString("%1/Contents/share/scribus/templates/").arg(pathPtr);
99
        m_libDir = QString("%1/Contents/lib/scribus/").arg(pathPtr);
100
        m_pluginDir = QString("%1/Contents/lib/scribus/plugins/").arg(pathPtr);
2673 cbradney 101
        QApplication::setLibraryPaths(QString("%1/Contents/lib/qtplugins/").arg(pathPtr));
1693 craig 102
        CFRelease(pluginRef);
103
        CFRelease(macPath);
3546 avox 104
 
105
        // on OSX this goes to the sys console, so user only sees it when they care -- AV
2673 cbradney 106
        qDebug(QString("scpaths: doc dir=%1").arg(m_docDir));
107
        qDebug(QString("scpaths: icon dir=%1").arg(m_iconDir));
3831 cbradney 108
        qDebug(QString("scpaths: font dir=%1").arg(m_fontDir));
2673 cbradney 109
        qDebug(QString("scpaths: sample dir=%1").arg(m_sampleScriptDir));
110
        qDebug(QString("scpaths: script dir=%1").arg(m_scriptDir));
111
        qDebug(QString("scpaths: template dir=%1").arg(m_templateDir));
112
        qDebug(QString("scpaths: lib dir=%1").arg(m_libDir));
113
        qDebug(QString("scpaths: plugin dir=%1").arg(m_pluginDir));
114
        qDebug(QString("scpaths: qtplugins=%1").arg(QApplication::libraryPaths().join(":")));
3546 avox 115
 
3096 fschmid 116
#elif defined(_WIN32)
117
        QString appPath = qApp->applicationDirPath();
3794 cbradney 118
        m_shareDir = QString("%1/share/").arg(appPath);
119
        m_docDir = QString("%1/share/doc/").arg(appPath);
120
        m_fontDir = QString("%1/share/fonts/").arg(appPath);
121
        m_iconDir = QString("%1/share/icons/").arg(appPath);
122
        m_sampleScriptDir = QString("%1/share/samples/").arg(appPath);
123
        m_scriptDir = QString("%1/share/scripts/").arg(appPath);
124
        m_templateDir = QString("%1/share/templates/").arg(appPath);
125
        m_libDir = QString("%1/libs/").arg(appPath);
126
        m_pluginDir = QString("%1/plugins/").arg(appPath);
4169 mrdocs 127
        QApplication::setLibraryPaths(QString("%1/qtplugins/").arg(appPath));
3096 fschmid 128
#endif
1693 craig 129
}
130
 
131
ScPaths::~ScPaths() {};
132
 
133
const QString&  ScPaths::docDir() const
134
{
135
        return m_docDir;
136
}
137
 
138
const QString&  ScPaths::iconDir() const
139
{
140
        return m_iconDir;
141
}
142
 
3794 cbradney 143
const QString&  ScPaths::fontDir() const
144
{
145
        return m_fontDir;
146
}
147
 
1693 craig 148
const QString&  ScPaths::libDir() const
149
{
150
        return m_libDir;
151
}
152
 
153
const QString&  ScPaths::pluginDir() const
154
{
155
        return m_pluginDir;
156
}
157
 
158
const QString&  ScPaths::sampleScriptDir() const
159
{
160
        return m_sampleScriptDir;
161
}
162
 
163
const QString&  ScPaths::scriptDir() const
164
{
165
        return m_scriptDir;
166
}
167
 
168
const QString&  ScPaths::templateDir() const
169
{
170
        return m_templateDir;
171
}
172
 
2707 subik 173
const QString&  ScPaths::shareDir() const
174
{
175
        return m_shareDir;
176
}
3096 fschmid 177
 
178
QStringList ScPaths::getSystemFontDirs(void)
179
{
180
        QStringList fontDirs;
3102 avox 181
#ifdef Q_OS_MAC
3096 fschmid 182
        fontDirs.append(QDir::homeDirPath() + "/Library/Fonts/");
183
        fontDirs.append("/Library/Fonts/");
184
        fontDirs.append("/Network/Library/Fonts/");
185
        fontDirs.append("/System/Library/Fonts/");
186
#elif defined(_WIN32)
187
        fontDirs.append( getSpecialDir(CSIDL_FONTS) );
188
#endif
189
        return fontDirs;
190
}
191
 
192
QStringList ScPaths::getSystemProfilesDirs(void)
193
{
194
        QStringList iccProfDirs;
3102 avox 195
#ifdef Q_OS_MAC
3096 fschmid 196
        iccProfDirs.append(QDir::homeDirPath()+"/Library/ColorSync/Profiles/");
197
        iccProfDirs.append("/System/Library/ColorSync/Profiles/");
198
        iccProfDirs.append("/Library/ColorSync/Profiles/");
199
#elif defined(Q_WS_X11)
200
        iccProfDirs.append(QDir::homeDirPath()+"/color/icc/");
201
        iccProfDirs.append(QDir::homeDirPath()+"/.color/icc/");
202
        iccProfDirs.append("/usr/share/color/icc/");
3961 mrdocs 203
        iccProfDirs.append("/usr/local/share/color/icc/");
3096 fschmid 204
#elif defined(_WIN32)
205
        // On Windows it's more complicated, profiles location depends on OS version
206
        char sysDir[MAX_PATH + 1];
207
        OSVERSIONINFO osVersion;
208
        ZeroMemory( &osVersion, sizeof(OSVERSIONINFO));
209
        osVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); // Necessary for GetVersionEx to succeed
210
        GetVersionEx(&osVersion);  // Get Windows version infos
211
        GetSystemDirectory( sysDir, MAX_PATH ); // getSpecialDir(CSIDL_SYSTEM) fails on Win9x
212
        QString winSysDir = QString(sysDir).replace('\\','/');
213
        if( osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT     ) // Windows NT/2k/XP
214
        {
215
                if( osVersion.dwMajorVersion >= 5 ) // for 2k and XP dwMajorVersion == 5 
216
                        iccProfDirs.append( winSysDir + "/Spool/Drivers/Color/");
217
        }
218
        else if( osVersion.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS ) // Windows 9x/Me 
219
        {
220
                if( osVersion.dwMajorVersion >= 4 && osVersion.dwMinorVersion >= 10) // Win98 or WinMe
221
                        iccProfDirs.append( winSysDir + "/Color/");
222
        }
223
#endif
224
        return iccProfDirs;
225
}
226
 
4602 cbradney 227
QStringList ScPaths::getSystemCreateDirs(void)
228
{
229
        QStringList createDirs;
230
#ifdef Q_OS_MAC
231
#elif defined(Q_WS_X11)
232
        createDirs.append(QDir::homeDirPath()+"/create/swatches/");
233
        createDirs.append(QDir::homeDirPath()+"/.create/swatches/");
234
        createDirs.append("/usr/share/create/swatches/");
235
        createDirs.append("/usr/local/share/create/swatches/");
236
#elif defined(_WIN32)
4689 mrdocs 237
        QString localAppData = getSpecialDir(CSIDL_LOCAL_APPDATA);
238
        QString commonAppData = getSpecialDir(CSIDL_COMMON_APPDATA);
239
        QString programFilesCommon = getSpecialDir(CSIDL_PROGRAM_FILES_COMMON);
240
        createDirs.append(getSpecialDir(CSIDL_APPDATA) + "create/swatches/");
241
        if ( !localAppData.isEmpty() )
242
                createDirs.append(localAppData + "create/swatches/");
243
        if ( !commonAppData.isEmpty() )
244
                createDirs.append(commonAppData + "create/swatches/");
245
        if ( !programFilesCommon.isEmpty() )
246
                createDirs.append(programFilesCommon + "create/swatches/");
4602 cbradney 247
#endif
248
        return createDirs;
249
}
250
 
4169 mrdocs 251
QString ScPaths::getSpecialDir(int folder)
3096 fschmid 252
{
253
        QString qstr;
254
#if defined(_WIN32)
255
        char dir[256];
4689 mrdocs 256
        if ( SHGetSpecialFolderPath(NULL, dir, folder , false) )
257
        {
258
                qstr = dir;
259
                if( !qstr.endsWith("\\") )
260
                        qstr += "\\";
261
                qstr.replace( '\\', '/' );
262
        }
3096 fschmid 263
#else
264
        Q_ASSERT(false);
265
#endif
266
        return qstr;
267
}