Subversion Repositories Scribus

Rev

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