Subversion Repositories Scribus

Rev

Rev 4166 | Rev 4194 | 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());
3546 avox 58
 
59
        // make sure we get the Scribus.app directory, not some subdir
60
 
61
        // strip trailing '/':
3459 avox 62
        char *p = const_cast<char*>(pathPtr + strlen(pathPtr) - 1);
2673 cbradney 63
        while (*p == '/')
64
                --p;
65
        ++p;
66
        *p = '\0';
67
        if (strcmp("/bin", p-4) == 0) {
68
                p -= 4;
69
                *p = '\0';
70
        }
71
        if (strcmp("/MacOS", p-6) == 0) {
72
                p -= 6;
73
                *p = '\0';
74
        }
75
        if (strcmp("/Contents", p-9) == 0) {
76
                p -= 9;
77
                *p = '\0';
78
        }
2707 subik 79
 
3546 avox 80
        qDebug(QString("scpaths: bundle at %1:").arg(pathPtr));
3794 cbradney 81
        m_shareDir = QString("%1/Contents/share/scribus/").arg(pathPtr);
82
        m_docDir = QString("%1/Contents/share/scribus/doc/").arg(pathPtr);
83
        m_iconDir = QString("%1/Contents/share/scribus/icons/").arg(pathPtr);
84
        m_sampleScriptDir = QString("%1/Contents/share/scribus/samples/").arg(pathPtr);
85
        m_scriptDir = QString("%1/Contents/share/scribus/scripts/").arg(pathPtr);
86
        m_templateDir = QString("%1/Contents/share/scribus/templates/").arg(pathPtr);
87
        m_libDir = QString("%1/Contents/lib/scribus/").arg(pathPtr);
88
        m_pluginDir = QString("%1/Contents/lib/scribus/plugins/").arg(pathPtr);
2673 cbradney 89
        QApplication::setLibraryPaths(QString("%1/Contents/lib/qtplugins/").arg(pathPtr));
1693 craig 90
        CFRelease(pluginRef);
91
        CFRelease(macPath);
3546 avox 92
 
93
        // on OSX this goes to the sys console, so user only sees it when they care -- AV
2673 cbradney 94
        qDebug(QString("scpaths: doc dir=%1").arg(m_docDir));
95
        qDebug(QString("scpaths: icon dir=%1").arg(m_iconDir));
3831 cbradney 96
        qDebug(QString("scpaths: font dir=%1").arg(m_fontDir));
2673 cbradney 97
        qDebug(QString("scpaths: sample dir=%1").arg(m_sampleScriptDir));
98
        qDebug(QString("scpaths: script dir=%1").arg(m_scriptDir));
99
        qDebug(QString("scpaths: template dir=%1").arg(m_templateDir));
100
        qDebug(QString("scpaths: lib dir=%1").arg(m_libDir));
101
        qDebug(QString("scpaths: plugin dir=%1").arg(m_pluginDir));
102
        qDebug(QString("scpaths: qtplugins=%1").arg(QApplication::libraryPaths().join(":")));
3546 avox 103
 
3096 fschmid 104
#elif defined(_WIN32)
105
        QString appPath = qApp->applicationDirPath();
3794 cbradney 106
        m_shareDir = QString("%1/share/").arg(appPath);
107
        m_docDir = QString("%1/share/doc/").arg(appPath);
108
        m_fontDir = QString("%1/share/fonts/").arg(appPath);
109
        m_iconDir = QString("%1/share/icons/").arg(appPath);
110
        m_sampleScriptDir = QString("%1/share/samples/").arg(appPath);
111
        m_scriptDir = QString("%1/share/scripts/").arg(appPath);
112
        m_templateDir = QString("%1/share/templates/").arg(appPath);
113
        m_libDir = QString("%1/libs/").arg(appPath);
114
        m_pluginDir = QString("%1/plugins/").arg(appPath);
4169 mrdocs 115
        QApplication::setLibraryPaths(QString("%1/qtplugins/").arg(appPath));
3096 fschmid 116
#endif
1693 craig 117
}
118
 
119
ScPaths::~ScPaths() {};
120
 
121
const QString&  ScPaths::docDir() const
122
{
123
        return m_docDir;
124
}
125
 
126
const QString&  ScPaths::iconDir() const
127
{
128
        return m_iconDir;
129
}
130
 
3794 cbradney 131
const QString&  ScPaths::fontDir() const
132
{
133
        return m_fontDir;
134
}
135
 
1693 craig 136
const QString&  ScPaths::libDir() const
137
{
138
        return m_libDir;
139
}
140
 
141
const QString&  ScPaths::pluginDir() const
142
{
143
        return m_pluginDir;
144
}
145
 
146
const QString&  ScPaths::sampleScriptDir() const
147
{
148
        return m_sampleScriptDir;
149
}
150
 
151
const QString&  ScPaths::scriptDir() const
152
{
153
        return m_scriptDir;
154
}
155
 
156
const QString&  ScPaths::templateDir() const
157
{
158
        return m_templateDir;
159
}
160
 
2707 subik 161
const QString&  ScPaths::shareDir() const
162
{
163
        return m_shareDir;
164
}
3096 fschmid 165
 
166
QStringList ScPaths::getSystemFontDirs(void)
167
{
168
        QStringList fontDirs;
3102 avox 169
#ifdef Q_OS_MAC
3096 fschmid 170
        fontDirs.append(QDir::homeDirPath() + "/Library/Fonts/");
171
        fontDirs.append("/Library/Fonts/");
172
        fontDirs.append("/Network/Library/Fonts/");
173
        fontDirs.append("/System/Library/Fonts/");
174
#elif defined(_WIN32)
175
        fontDirs.append( getSpecialDir(CSIDL_FONTS) );
176
#endif
177
        return fontDirs;
178
}
179
 
180
QStringList ScPaths::getSystemProfilesDirs(void)
181
{
182
        QStringList iccProfDirs;
3102 avox 183
#ifdef Q_OS_MAC
3096 fschmid 184
        iccProfDirs.append(QDir::homeDirPath()+"/Library/ColorSync/Profiles/");
185
        iccProfDirs.append("/System/Library/ColorSync/Profiles/");
186
        iccProfDirs.append("/Library/ColorSync/Profiles/");
187
#elif defined(Q_WS_X11)
188
        iccProfDirs.append(QDir::homeDirPath()+"/color/icc/");
189
        iccProfDirs.append(QDir::homeDirPath()+"/.color/icc/");
190
        iccProfDirs.append("/usr/share/color/icc/");
3961 mrdocs 191
        iccProfDirs.append("/usr/local/share/color/icc/");
3096 fschmid 192
#elif defined(_WIN32)
193
        // On Windows it's more complicated, profiles location depends on OS version
194
        char sysDir[MAX_PATH + 1];
195
        OSVERSIONINFO osVersion;
196
        ZeroMemory( &osVersion, sizeof(OSVERSIONINFO));
197
        osVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); // Necessary for GetVersionEx to succeed
198
        GetVersionEx(&osVersion);  // Get Windows version infos
199
        GetSystemDirectory( sysDir, MAX_PATH ); // getSpecialDir(CSIDL_SYSTEM) fails on Win9x
200
        QString winSysDir = QString(sysDir).replace('\\','/');
201
        if( osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT     ) // Windows NT/2k/XP
202
        {
203
                if( osVersion.dwMajorVersion >= 5 ) // for 2k and XP dwMajorVersion == 5 
204
                        iccProfDirs.append( winSysDir + "/Spool/Drivers/Color/");
205
        }
206
        else if( osVersion.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS ) // Windows 9x/Me 
207
        {
208
                if( osVersion.dwMajorVersion >= 4 && osVersion.dwMinorVersion >= 10) // Win98 or WinMe
209
                        iccProfDirs.append( winSysDir + "/Color/");
210
        }
211
#endif
212
        return iccProfDirs;
213
}
214
 
4169 mrdocs 215
QString ScPaths::getSpecialDir(int folder)
3096 fschmid 216
{
217
        QString qstr;
218
#if defined(_WIN32)
219
        char dir[256];
220
        SHGetSpecialFolderPath(NULL, dir, folder , false);
221
        qstr = dir;
222
        if( !qstr.endsWith("\\") )
223
                qstr += "\\";
224
        qstr.replace( '\\', '/' );
225
#else
226
        Q_ASSERT(false);
227
#endif
228
        return qstr;
229
}