Subversion Repositories Scribus

Rev

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