Subversion Repositories Scribus

Rev

Rev 3831 | Rev 4166 | 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);
3096 fschmid 115
#endif
1693 craig 116
}
117
 
118
ScPaths::~ScPaths() {};
119
 
120
const QString&  ScPaths::docDir() const
121
{
122
        return m_docDir;
123
}
124
 
125
const QString&  ScPaths::iconDir() const
126
{
127
        return m_iconDir;
128
}
129
 
3794 cbradney 130
const QString&  ScPaths::fontDir() const
131
{
132
        return m_fontDir;
133
}
134
 
1693 craig 135
const QString&  ScPaths::libDir() const
136
{
137
        return m_libDir;
138
}
139
 
140
const QString&  ScPaths::pluginDir() const
141
{
142
        return m_pluginDir;
143
}
144
 
145
const QString&  ScPaths::sampleScriptDir() const
146
{
147
        return m_sampleScriptDir;
148
}
149
 
150
const QString&  ScPaths::scriptDir() const
151
{
152
        return m_scriptDir;
153
}
154
 
155
const QString&  ScPaths::templateDir() const
156
{
157
        return m_templateDir;
158
}
159
 
2707 subik 160
const QString&  ScPaths::shareDir() const
161
{
162
        return m_shareDir;
163
}
3096 fschmid 164
 
165
QStringList ScPaths::getSystemFontDirs(void)
166
{
167
        QStringList fontDirs;
3102 avox 168
#ifdef Q_OS_MAC
3096 fschmid 169
        fontDirs.append(QDir::homeDirPath() + "/Library/Fonts/");
170
        fontDirs.append("/Library/Fonts/");
171
        fontDirs.append("/Network/Library/Fonts/");
172
        fontDirs.append("/System/Library/Fonts/");
173
#elif defined(_WIN32)
174
        fontDirs.append( getSpecialDir(CSIDL_FONTS) );
175
#endif
176
        return fontDirs;
177
}
178
 
179
QStringList ScPaths::getSystemProfilesDirs(void)
180
{
181
        QStringList iccProfDirs;
3102 avox 182
#ifdef Q_OS_MAC
3096 fschmid 183
        iccProfDirs.append(QDir::homeDirPath()+"/Library/ColorSync/Profiles/");
184
        iccProfDirs.append("/System/Library/ColorSync/Profiles/");
185
        iccProfDirs.append("/Library/ColorSync/Profiles/");
186
#elif defined(Q_WS_X11)
187
        iccProfDirs.append(QDir::homeDirPath()+"/color/icc/");
188
        iccProfDirs.append(QDir::homeDirPath()+"/.color/icc/");
189
        iccProfDirs.append("/usr/share/color/icc/");
3961 mrdocs 190
        iccProfDirs.append("/usr/local/share/color/icc/");
3096 fschmid 191
#elif defined(_WIN32)
192
        // On Windows it's more complicated, profiles location depends on OS version
193
        char sysDir[MAX_PATH + 1];
194
        OSVERSIONINFO osVersion;
195
        ZeroMemory( &osVersion, sizeof(OSVERSIONINFO));
196
        osVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); // Necessary for GetVersionEx to succeed
197
        GetVersionEx(&osVersion);  // Get Windows version infos
198
        GetSystemDirectory( sysDir, MAX_PATH ); // getSpecialDir(CSIDL_SYSTEM) fails on Win9x
199
        QString winSysDir = QString(sysDir).replace('\\','/');
200
        if( osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT     ) // Windows NT/2k/XP
201
        {
202
                if( osVersion.dwMajorVersion >= 5 ) // for 2k and XP dwMajorVersion == 5 
203
                        iccProfDirs.append( winSysDir + "/Spool/Drivers/Color/");
204
        }
205
        else if( osVersion.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS ) // Windows 9x/Me 
206
        {
207
                if( osVersion.dwMajorVersion >= 4 && osVersion.dwMinorVersion >= 10) // Win98 or WinMe
208
                        iccProfDirs.append( winSysDir + "/Color/");
209
        }
210
#endif
211
        return iccProfDirs;
212
}
213
 
214
QString ScPaths::getSpecialDir(int folder)
215
{
216
        QString qstr;
217
#if defined(_WIN32)
218
        char dir[256];
219
        SHGetSpecialFolderPath(NULL, dir, folder , false);
220
        qstr = dir;
221
        if( !qstr.endsWith("\\") )
222
                qstr += "\\";
223
        qstr.replace( '\\', '/' );
224
#else
225
        Q_ASSERT(false);
226
#endif
227
        return qstr;
228
}