Subversion Repositories Scribus

Rev

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