Subversion Repositories Scribus

Rev

Rev 22832 | Rev 23049 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4430 cbradney 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
1693 craig 7
#include "scpaths.h"
10223 cbradney 8
#include <QApplication>
10755 cbradney 9
#include <QDebug>
10223 cbradney 10
#include <QDir>
15483 craig 11
#include <QProcess>
21520 craig 12
#include <QStandardPaths>
1693 craig 13
 
21817 craig 14
#include "prefsmanager.h"
2688 craig 15
#include "scconfig.h"
21532 craig 16
#include "scribusapp.h"
2673 cbradney 17
 
21532 craig 18
extern ScribusQApp* ScQApp;
19
 
1693 craig 20
// On Qt/Mac we need CoreFoundation to discover the location
21
// of the app bundle.
18204 fschmid 22
#ifdef Q_OS_MAC
1693 craig 23
#include <CoreFoundation/CoreFoundation.h>
24
#endif
25
 
3096 fschmid 26
#ifdef _WIN32
27
#include <windows.h>
28
#include <shlobj.h>
29
#endif
30
 
22666 jghali 31
#if defined(Q_OS_WIN32) || defined (Q_OS_OS2)
4194 fschmid 32
const char ScPaths::envPathSeparator = ';';
33
#else
34
const char ScPaths::envPathSeparator = ':';
35
#endif
36
 
22534 craig 37
// Init the singleton's "self" address to nullptr
38
ScPaths* ScPaths::m_instance = nullptr;
1693 craig 39
 
40
// Singleton's public constructor
41
const ScPaths& ScPaths::instance()
42
{
43
        if (!ScPaths::m_instance)
44
                ScPaths::m_instance = new ScPaths();
45
        return *ScPaths::m_instance;
46
}
47
 
48
// Singleton's public destructor
49
void ScPaths::destroy()
50
{
22607 craig 51
        delete ScPaths::m_instance;
1693 craig 52
}
53
 
54
// Protected "real" constructor
23028 jghali 55
ScPaths::ScPaths()
56
{
57
// On *nix, all paths are initialized to compile-time defaults passed in
1693 craig 58
// as preprocessor macros and set by autoconf.
23028 jghali 59
#if !defined(Q_OS_MAC) && !defined(_WIN32) && defined(WANT_RELOCATABLE)
60
        QString appPath = qApp->applicationDirPath();
61
        m_docDir = appPath + "/../" + QString(DOCDIR);
62
        m_iconDir = appPath + "/../" + QString(ICONDIR);
63
        m_libDir = appPath + "/../" + QString(LIBDIR);
64
        m_pluginDir = appPath + "/../" + QString(PLUGINDIR);
65
        m_qmlDir = appPath + "/../" + QString(QMLDIR);
66
        m_sampleScriptDir = appPath + "/../" + QString(SAMPLESDIR);
67
        m_scriptDir = appPath + "/../" + QString(SCRIPTSDIR);
68
        m_shareDir = appPath + "/../" + QString(SHAREDIR);
69
        m_templateDir = appPath + "/../" + QString(TEMPLATEDIR);
70
#elif !defined(Q_OS_MAC) && !defined(_WIN32)
71
        m_docDir = QString(DOCDIR);
72
        m_iconDir = QString(ICONDIR);
73
        m_libDir = QString(LIBDIR);
74
        m_pluginDir = QString(PLUGINDIR);
75
        m_qmlDir = QString(QMLDIR);
76
        m_sampleScriptDir = QString(SAMPLESDIR);
77
        m_scriptDir = QString(SCRIPTSDIR);
78
        m_shareDir = QString(SHAREDIR);
79
        m_templateDir = QString(TEMPLATEDIR);
80
#endif
81
 
1693 craig 82
// On MacOS/X, override the compile-time settings with a location
83
// obtained from the system.
18204 fschmid 84
#ifdef Q_OS_MAC
13179 cbradney 85
        QString pathPtr(bundleDir());
15415 craig 86
        qDebug() << QString("scpaths: bundle at %1").arg(pathPtr);
3794 cbradney 87
        m_shareDir = QString("%1/Contents/share/scribus/").arg(pathPtr);
12543 cbradney 88
        m_docDir = QString("%1/Contents/share/doc/scribus/").arg(pathPtr);
19781 craig 89
        m_fontDir = QString("%1/Contents/share/scribus/fonts/").arg(pathPtr);
3794 cbradney 90
        m_iconDir = QString("%1/Contents/share/scribus/icons/").arg(pathPtr);
91
        m_sampleScriptDir = QString("%1/Contents/share/scribus/samples/").arg(pathPtr);
92
        m_scriptDir = QString("%1/Contents/share/scribus/scripts/").arg(pathPtr);
93
        m_templateDir = QString("%1/Contents/share/scribus/templates/").arg(pathPtr);
19674 craig 94
        m_libDir = QString("%1/Contents/lib/").arg(pathPtr);
95
        m_pluginDir = QString("%1/Contents/lib/").arg(pathPtr);
18758 craig 96
        m_qmlDir = QString("%1/Contents/share/scribus/qml/").arg(pathPtr);
97
        //QApplication::setLibraryPaths(QStringList(QString("%1/Contents/lib/qtplugins/").arg(pathPtr)));
19674 craig 98
        QApplication::addLibraryPath(QString("%1/Contents/PlugIns/").arg(pathPtr));
3546 avox 99
        // on OSX this goes to the sys console, so user only sees it when they care -- AV
10755 cbradney 100
        qDebug() << QString("scpaths: doc dir=%1").arg(m_docDir);
101
        qDebug() << QString("scpaths: icon dir=%1").arg(m_iconDir);
102
        qDebug() << QString("scpaths: font dir=%1").arg(m_fontDir);
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);
18758 craig 108
        qDebug() << QString("scpaths: QML dir=%1").arg(m_qmlDir);
10755 cbradney 109
        qDebug() << QString("scpaths: qtplugins=%1").arg(QApplication::libraryPaths().join(":"));
3546 avox 110
 
3096 fschmid 111
#elif defined(_WIN32)
22555 jghali 112
        QFileInfo appInfo(qApp->applicationDirPath());
3096 fschmid 113
        QString appPath = qApp->applicationDirPath();
22555 jghali 114
        QString cleanAppPath = appInfo.canonicalFilePath();
115
        if (!cleanAppPath.isEmpty())
116
                appPath = cleanAppPath;
117
 
3794 cbradney 118
        m_shareDir = QString("%1/share/").arg(appPath);
119
        m_docDir = QString("%1/share/doc/").arg(appPath);
120
        m_fontDir = QString("%1/share/fonts/").arg(appPath);
121
        m_iconDir = QString("%1/share/icons/").arg(appPath);
122
        m_sampleScriptDir = QString("%1/share/samples/").arg(appPath);
123
        m_scriptDir = QString("%1/share/scripts/").arg(appPath);
124
        m_templateDir = QString("%1/share/templates/").arg(appPath);
125
        m_libDir = QString("%1/libs/").arg(appPath);
126
        m_pluginDir = QString("%1/plugins/").arg(appPath);
18760 jghali 127
        m_qmlDir = QString("%1/share/qml/").arg(appPath);
18425 jghali 128
 
129
        QString qtpluginDir = QString("%1/qtplugins/").arg(appPath);
130
        if (QDir(qtpluginDir).exists())
131
                QApplication::setLibraryPaths( QStringList(qtpluginDir) );
3096 fschmid 132
#endif
7407 cbradney 133
 
22650 jghali 134
//      if (!m_shareDir.endsWith("/"))        m_shareDir += "/";
135
//      if (!m_docDir.endsWith("/"))          m_docDir += "/";
136
//      if (!m_fontDir.endsWith("/"))         m_fontDir += "/";
137
        if (!m_iconDir.endsWith("/"))         m_iconDir += "/";
138
//      if (!m_sampleScriptDir.endsWith("/")) m_sampleScriptDir += "/";
139
//      if (!m_scriptDir.endsWith("/"))       m_scriptDir += "/";
140
//      if (!m_templateDir.endsWith("/"))     m_templateDir += "/";
141
//      if (!m_libDir.endsWith("/"))          m_libDir += "/";
142
//      if (!m_pluginDir.endsWith("/"))       m_pluginDir += "/";
1693 craig 143
}
144
 
145
ScPaths::~ScPaths() {};
146
 
22598 craig 147
QString ScPaths::bundleDir() const
13179 cbradney 148
{
149
        // On MacOS/X, override the compile-time settings with a location
150
// obtained from the system.
18204 fschmid 151
#ifdef Q_OS_MAC
13179 cbradney 152
        // Set up the various app paths to look inside the app bundle
153
        CFURLRef pluginRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
15413 craig 154
        CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef, kCFURLPOSIXPathStyle);
155
        const char *pathPtr = CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding());
22534 craig 156
        if (pathPtr!=nullptr && strlen(pathPtr)>0)
15413 craig 157
        {
158
                // make sure we get the Scribus.app directory, not some subdir
159
                // strip trailing '/':
160
                qDebug("Path = %s", pathPtr);
161
                char *p = const_cast<char*>(pathPtr + strlen(pathPtr) - 1);
162
                while (*p == '/')
163
                        --p;
164
                ++p;
13179 cbradney 165
                *p = '\0';
15413 craig 166
                if (strcmp("/bin", p-4) == 0) {
167
                        p -= 4;
168
                        *p = '\0';
169
                }
170
                if (strcmp("/MacOS", p-6) == 0) {
171
                        p -= 6;
172
                        *p = '\0';
173
                }
174
                if (strcmp("/Contents", p-9) == 0) {
175
                        p -= 9;
176
                        *p = '\0';
177
                }
178
                CFRelease(pluginRef);
179
                CFRelease(macPath);
180
                return QString("%1").arg(pathPtr);
13179 cbradney 181
        }
22638 craig 182
        char buf[2048];
183
        CFStringGetCString (macPath, buf, 2048, kCFStringEncodingUTF8);
184
        QString q_pathPtr=QString::fromUtf8(buf);
185
        if (q_pathPtr.endsWith("/bin"))
186
                q_pathPtr.chop(4);
187
        if (q_pathPtr.endsWith("/MacOS"))
188
                q_pathPtr.chop(6);
189
        if (q_pathPtr.endsWith("/Contents"))
190
                q_pathPtr.chop(9);
191
        CFRelease(pluginRef);
192
        CFRelease(macPath);
193
        return q_pathPtr;
13179 cbradney 194
#endif
195
        return QString::null;
196
}
197
 
20383 craig 198
QString ScPaths::defaultImageEditorApp()
199
{
200
#ifdef Q_OS_MAC
201
        QString appName("/Applications/GIMP.app");
202
        QFile app(appName);
203
        if (app.exists())
204
                return appName;
205
#endif
206
        return "gimp";
207
}
208
 
1693 craig 209
const QString&  ScPaths::docDir() const
210
{
211
        return m_docDir;
212
}
213
 
214
const QString&  ScPaths::iconDir() const
215
{
216
        return m_iconDir;
217
}
218
 
3794 cbradney 219
const QString&  ScPaths::fontDir() const
220
{
221
        return m_fontDir;
222
}
223
 
1693 craig 224
const QString&  ScPaths::libDir() const
225
{
226
        return m_libDir;
227
}
228
 
229
const QString&  ScPaths::pluginDir() const
230
{
231
        return m_pluginDir;
232
}
233
 
234
const QString&  ScPaths::sampleScriptDir() const
235
{
236
        return m_sampleScriptDir;
237
}
238
 
22832 craig 239
const QString& ScPaths::scriptDir() const
1693 craig 240
{
241
        return m_scriptDir;
242
}
243
 
22832 craig 244
const QString& ScPaths::templateDir() const
1693 craig 245
{
246
        return m_templateDir;
247
}
248
 
22832 craig 249
const QString& ScPaths::shareDir() const
2707 subik 250
{
251
        return m_shareDir;
252
}
3096 fschmid 253
 
22832 craig 254
const QString& ScPaths::qmlDir() const
18758 craig 255
{
256
        return m_qmlDir;
257
}
258
 
10997 jghali 259
QString ScPaths::translationDir() const
260
{
261
        return (m_shareDir + "translations/");
262
}
263
 
11120 malex 264
QString ScPaths::dictDir() const
265
{
266
        return(m_shareDir + "dicts/");
267
}
268
 
17501 craig 269
QStringList ScPaths::spellDirs() const
270
{
271
        QDir d;
272
        QStringList spellDirs;
21526 craig 273
        spellDirs.append(userDictDir(ScPaths::Spell, false));
17501 craig 274
        spellDirs.append(m_shareDir + "dicts/spelling/");
275
#ifdef Q_OS_MAC
21934 craig 276
        QString macPortsPath("/opt/local/share/hunspell/");
277
        QString finkPath("/sw/share/hunspell/");
278
        QString osxLibreOfficePath("/Applications/LibreOffice.app/Contents/Resources/extensions");
279
        QString osxUserLibreOfficePath(QDir::homePath()+"/Applications/LibreOffice.app/Contents/Resources/extensions");
17501 craig 280
        d.setPath(macPortsPath);
281
        if (d.exists())
282
                spellDirs.append(macPortsPath);
283
        d.setPath(finkPath);
284
        if (d.exists())
285
                spellDirs.append(finkPath);
286
        d.setPath(osxLibreOfficePath);
287
        if (d.exists())
288
        {
289
                QStringList dictDirFilters("dict-*");
22669 jghali 290
                const QStringList dictDirList(d.entryList(dictDirFilters, QDir::Dirs, QDir::Name));
291
                for (const QString& dir : dictDirList)
17501 craig 292
                        spellDirs.append(osxLibreOfficePath + "/" + dir + "/");
293
        }
294
        d.setPath(osxUserLibreOfficePath);
295
        if (d.exists())
296
        {
297
                QStringList dictDirFilters("dict-*");
22669 jghali 298
                const QStringList dictDirList(d.entryList(dictDirFilters, QDir::Dirs, QDir::Name));
299
                for (const QString& dir : dictDirList)
17501 craig 300
                        spellDirs.append(osxUserLibreOfficePath + "/" + dir + "/");
301
        }
302
 
303
#elif defined(_WIN32)
21937 jghali 304
        QString windowsLOPath("LibreOffice 3.5/share/extensions");
21527 craig 305
        QString progFiles = windowsSpecialDir(CSIDL_PROGRAM_FILES);
17501 craig 306
        d.setPath(progFiles+windowsLOPath);
307
        if (d.exists())
308
        {
309
                QStringList dictDirFilters("dict-*");
22669 jghali 310
                const QStringList dictDirList(d.entryList(dictDirFilters, QDir::Dirs, QDir::Name));
311
                for (const QString& dir : dictDirList)
17501 craig 312
                        spellDirs.append(progFiles+windowsLOPath + "/" + dir + "/");
313
        }
18204 fschmid 314
#elif defined(Q_OS_LINUX)
21934 craig 315
        QString linuxLocalPath("/usr/local/share/hunspell/");
316
        QString linuxHunspellPath("/usr/share/hunspell/");
317
        QString linuxMyspellPath("/usr/share/myspell/");
17501 craig 318
        d.setPath(linuxHunspellPath);
319
        if (d.exists())
320
                spellDirs.append(linuxHunspellPath);
321
        d.setPath(linuxMyspellPath);
322
        if (d.exists())
323
                spellDirs.append(linuxMyspellPath);
324
        d.setPath(linuxLocalPath);
325
        if (d.exists())
326
                spellDirs.append(linuxLocalPath);
327
#endif
328
        return spellDirs;
329
}
330
 
19800 craig 331
QStringList ScPaths::hyphDirs() const
332
{
333
        QDir d;
334
        QStringList hyphDirs;
21526 craig 335
        hyphDirs.append(userDictDir(ScPaths::Hyph, false));
19800 craig 336
        hyphDirs.append(m_shareDir + "dicts/hyph/");
337
#ifdef Q_OS_MAC
21939 craig 338
        QString macPortsPath("/opt/local/share/hunspell/");
339
        QString finkPath("/sw/share/hunspell/");
340
        QString osxLibreOfficePath("/Applications/LibreOffice.app/Contents/Resources/extensions");
341
        QString osxUserLibreOfficePath(QDir::homePath()+"/Applications/LibreOffice.app/Contents/Resources/extensions");
19800 craig 342
        d.setPath(macPortsPath);
343
        if (d.exists())
344
                hyphDirs.append(macPortsPath);
345
        d.setPath(finkPath);
346
        if (d.exists())
347
                hyphDirs.append(finkPath);
348
        d.setPath(osxLibreOfficePath);
349
        if (d.exists())
350
        {
351
                QStringList dictDirFilters("dict-*");
22669 jghali 352
                const QStringList dictDirList(d.entryList(dictDirFilters, QDir::Dirs, QDir::Name));
353
                for (const QString& dir : dictDirList)
19800 craig 354
                        hyphDirs.append(osxLibreOfficePath + "/" + dir + "/");
355
        }
356
        d.setPath(osxUserLibreOfficePath);
357
        if (d.exists())
358
        {
359
                QStringList dictDirFilters("dict-*");
22669 jghali 360
                const QStringList dictDirList(d.entryList(dictDirFilters, QDir::Dirs, QDir::Name));
361
                for (const QString& dir : dictDirList)
19800 craig 362
                        hyphDirs.append(osxUserLibreOfficePath + "/" + dir + "/");
363
        }
364
 
365
#elif defined(_WIN32)
21939 craig 366
        QString windowsLOPath("LibreOffice 3.5/share/extensions");
21527 craig 367
        QString progFiles = windowsSpecialDir(CSIDL_PROGRAM_FILES);
19800 craig 368
        d.setPath(progFiles+windowsLOPath);
369
        if (d.exists())
370
        {
371
                QStringList dictDirFilters("dict-*");
22669 jghali 372
                const QStringList dictDirList(d.entryList(dictDirFilters, QDir::Dirs, QDir::Name));
373
                for (const QString& dir : dictDirList)
19805 craig 374
                        hyphDirs.append(progFiles+windowsLOPath + "/" + dir + "/");
19800 craig 375
        }
376
#elif defined(Q_OS_LINUX)
21939 craig 377
        QString linuxLocalPath("/usr/local/share/hunspell/");
378
        QString linuxHunspellPath("/usr/share/hunspell/");
379
        QString linuxMyspellPath("/usr/share/myspell/");
380
        QString linuxHyphen1Path("/usr/share/hyphen/");
21078 jghali 381
        d.setPath(linuxHyphen1Path);
21077 craig 382
        if (d.exists())
383
                hyphDirs.append(linuxHyphen1Path);
19800 craig 384
        d.setPath(linuxHunspellPath);
385
        if (d.exists())
19805 craig 386
                hyphDirs.append(linuxHunspellPath);
19800 craig 387
        d.setPath(linuxMyspellPath);
388
        if (d.exists())
19805 craig 389
                hyphDirs.append(linuxMyspellPath);
19800 craig 390
        d.setPath(linuxLocalPath);
391
        if (d.exists())
19805 craig 392
                hyphDirs.append(linuxLocalPath);
19800 craig 393
#endif
394
        return hyphDirs;
395
}
396
 
22598 craig 397
QStringList ScPaths::systemFontDirs()
3096 fschmid 398
{
399
        QStringList fontDirs;
3102 avox 400
#ifdef Q_OS_MAC
10398 cbradney 401
        fontDirs.append(QDir::homePath() + "/Library/Fonts/");
3096 fschmid 402
        fontDirs.append("/Library/Fonts/");
403
        fontDirs.append("/Network/Library/Fonts/");
404
        fontDirs.append("/System/Library/Fonts/");
405
#elif defined(_WIN32)
22824 jghali 406
        QDir d;
407
        QString localFontDir = windowsSpecialDir(CSIDL_LOCAL_APPDATA)+"Microsoft/Windows/Fonts"; // Added by Windows 10 1809
408
        QString roamingFontDir = windowsSpecialDir(CSIDL_APPDATA)+"Microsoft/Windows/Fonts"; // Added by Windows 10 1809
409
        d.setPath(localFontDir);
410
        if (d.exists())
411
                fontDirs.append(localFontDir);
412
        d.setPath(roamingFontDir);
413
        if (d.exists())
414
                fontDirs.append(roamingFontDir);
22650 jghali 415
        fontDirs.append(windowsSpecialDir(CSIDL_FONTS));
3096 fschmid 416
#endif
417
        return fontDirs;
418
}
419
 
22598 craig 420
QStringList ScPaths::systemProfilesDirs()
3096 fschmid 421
{
422
        QStringList iccProfDirs;
3102 avox 423
#ifdef Q_OS_MAC
10398 cbradney 424
        iccProfDirs.append(QDir::homePath()+"/Library/ColorSync/Profiles/");
3096 fschmid 425
        iccProfDirs.append("/System/Library/ColorSync/Profiles/");
426
        iccProfDirs.append("/Library/ColorSync/Profiles/");
18204 fschmid 427
#elif defined(Q_OS_LINUX)
10398 cbradney 428
        iccProfDirs.append(QDir::homePath()+"/color/icc/");
429
        iccProfDirs.append(QDir::homePath()+"/.color/icc/");
18953 jghali 430
        iccProfDirs.append(QDir::homePath()+"/.local/share/icc/");
17620 craig 431
        iccProfDirs.append(QDir::homePath()+"/.local/share/color/icc/");
3096 fschmid 432
        iccProfDirs.append("/usr/share/color/icc/");
3961 mrdocs 433
        iccProfDirs.append("/usr/local/share/color/icc/");
18953 jghali 434
        iccProfDirs.append("/var/lib/color/icc/");
3096 fschmid 435
#elif defined(_WIN32)
436
        // On Windows it's more complicated, profiles location depends on OS version
10293 jghali 437
        WCHAR sysDir[MAX_PATH + 1];
3096 fschmid 438
        OSVERSIONINFO osVersion;
22650 jghali 439
        ZeroMemory(&osVersion, sizeof(OSVERSIONINFO));
3096 fschmid 440
        osVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); // Necessary for GetVersionEx to succeed
441
        GetVersionEx(&osVersion);  // Get Windows version infos
22650 jghali 442
        GetSystemDirectoryW(sysDir, MAX_PATH); // windowsSpecialDir(CSIDL_SYSTEM) fails on Win9x
10293 jghali 443
        QString winSysDir = QString::fromUtf16((const ushort*) sysDir);
444
        winSysDir = winSysDir.replace('\\','/');
22650 jghali 445
        if (osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT) // Windows NT/2k/XP
3096 fschmid 446
        {
22650 jghali 447
                if (osVersion.dwMajorVersion >= 5) // for 2k and XP dwMajorVersion == 5 
448
                        iccProfDirs.append(winSysDir + "/Spool/Drivers/Color/");
3096 fschmid 449
        }
22650 jghali 450
        else if (osVersion.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) // Windows 9x/Me 
3096 fschmid 451
        {
22650 jghali 452
                if (osVersion.dwMajorVersion >= 4 && osVersion.dwMinorVersion >= 10) // Win98 or WinMe
453
                        iccProfDirs.append(winSysDir + "/Color/");
3096 fschmid 454
        }
455
#endif
456
        return iccProfDirs;
457
}
458
 
22607 craig 459
QStringList ScPaths::dirsFromEnvVar(const QString& envVar, const QString& dirToFind)
15483 craig 460
{
22669 jghali 461
        QChar sep(ScPaths::envPathSeparator);
15496 craig 462
        QStringList dirs;
16262 jghali 463
#if defined(Q_OS_MAC) || defined(Q_OS_UNIX)
22669 jghali 464
        const QStringList env(QProcess::systemEnvironment());
15496 craig 465
        QString path_data;
22669 jghali 466
        for (const QString& line : env)
15483 craig 467
        {
15496 craig 468
                if (line.indexOf(envVar) == 0)
469
                        path_data = line.mid(envVar.length()+1); //eg, Strip "XDG_DATA_DIRS="
15483 craig 470
        }
22669 jghali 471
        const QStringList splitpath_data(path_data.split(sep, QString::SkipEmptyParts));
472
        for (QString dir : splitpath_data)
15483 craig 473
        {
15496 craig 474
                QFileInfo info(dir+dirToFind);
15483 craig 475
                if (info.exists())
15496 craig 476
                        dirs.append(dir+dirToFind);
15483 craig 477
        }
478
#endif
15496 craig 479
        return dirs;
15483 craig 480
}
15496 craig 481
 
482
 
21526 craig 483
 
22598 craig 484
QStringList ScPaths::systemCreatePalettesDirs()
4602 cbradney 485
{
486
        QStringList createDirs;
487
#ifdef Q_OS_MAC
10398 cbradney 488
        createDirs.append(QDir::homePath()+"/create/swatches/");
489
        createDirs.append(QDir::homePath()+"/.create/swatches/");
18204 fschmid 490
#elif defined(Q_OS_LINUX)
10398 cbradney 491
        createDirs.append(QDir::homePath()+"/create/swatches/");
492
        createDirs.append(QDir::homePath()+"/.create/swatches/");
4602 cbradney 493
        createDirs.append("/usr/share/create/swatches/");
494
        createDirs.append("/usr/local/share/create/swatches/");
495
#elif defined(_WIN32)
21527 craig 496
        QString localAppData = windowsSpecialDir(CSIDL_LOCAL_APPDATA);
497
        QString commonAppData = windowsSpecialDir(CSIDL_COMMON_APPDATA);
498
        QString programFilesCommon = windowsSpecialDir(CSIDL_PROGRAM_FILES_COMMON);
499
        createDirs.append(windowsSpecialDir(CSIDL_APPDATA) + "create/swatches/");
22650 jghali 500
        if (!localAppData.isEmpty())
4689 mrdocs 501
                createDirs.append(localAppData + "create/swatches/");
22650 jghali 502
        if (!commonAppData.isEmpty())
4689 mrdocs 503
                createDirs.append(commonAppData + "create/swatches/");
22650 jghali 504
        if (!programFilesCommon.isEmpty())
4689 mrdocs 505
                createDirs.append(programFilesCommon + "create/swatches/");
4602 cbradney 506
#endif
507
        return createDirs;
508
}
509
 
22598 craig 510
QString ScPaths::oldApplicationDataDir()
21530 craig 511
{
512
#ifdef Q_OS_WIN32
513
        QString appData = windowsSpecialDir(CSIDL_APPDATA);
514
        if (QDir(appData).exists())
515
#ifdef APPLICATION_DATA_DIR
516
        return (appData + "/" + APPLICATION_DATA_DIR + "/");
517
#else
518
        return (appData + "/Scribus/");
519
#endif
520
#endif
521
 
522
#ifdef APPLICATION_DATA_DIR
523
        return QDir::homePath() + "/" + APPLICATION_DATA_DIR + "/";
524
#else
525
        #ifdef Q_OS_MAC
526
                return (QDir::homePath() + "/Library/Preferences/Scribus/");
527
        #else
528
                return (QDir::homePath() + "/.scribus/");
529
        #endif
530
#endif
531
}
532
 
21526 craig 533
QString ScPaths::applicationDataDir(bool createIfNotExists)
5917 jghali 534
{
21526 craig 535
        QString dataDir;
13066 subik 536
#ifdef APPLICATION_DATA_DIR
22160 jghali 537
        dataDir =  QDir::homePath() + "/" + APPLICATION_DATA_DIR + "/";
13066 subik 538
#else
21526 craig 539
        dataDir =  QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/";
5917 jghali 540
#endif
21526 craig 541
        QDir prefsDirectory(dataDir);
542
        if (createIfNotExists && !prefsDirectory.exists())
543
                prefsDirectory.mkpath(prefsDirectory.absolutePath());
544
        return dataDir;
545
}
13066 subik 546
 
21526 craig 547
QString ScPaths::preferencesDir(bool createIfNotExists)
548
{
21532 craig 549
        //If we have been passed a dir on cmd line, use this. Start up errors if it does not exist.
550
        if (!ScQApp->userPrefsDir().isEmpty())
551
                return ScQApp->userPrefsDir();
21526 craig 552
        QString prefsDir;
553
#ifdef APPLICATION_CONFIG_DIR
554
        prefsDir =  QDir::homePath() + "/" + APPLICATION_CONFIG_DIR + "/";
13066 subik 555
#else
21527 craig 556
        //Jean wants to make all prefs for Scribus be in the roaming directory on Windows so return the same as applicationDataDir
21526 craig 557
        #ifdef Q_OS_WIN32
558
                prefsDir =  QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/";
13171 cbradney 559
        #else
21526 craig 560
                prefsDir =  QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/";
13171 cbradney 561
        #endif
13066 subik 562
#endif
21526 craig 563
        QDir prefsDirectory(prefsDir);
564
        if (createIfNotExists && !prefsDirectory.exists())
565
                prefsDirectory.mkpath(prefsDirectory.absolutePath());
566
        return prefsDir;
5917 jghali 567
}
568
 
22598 craig 569
QString ScPaths::imageCacheDir()
14539 jghali 570
{
21526 craig 571
        return applicationDataDir() + "cache/img/";
14539 jghali 572
}
573
 
21526 craig 574
QString ScPaths::pluginDataDir(bool createIfNotExists)
13608 jghali 575
{
21526 craig 576
        QDir useFilesDirectory(applicationDataDir() + "plugins/");
22650 jghali 577
        if (createIfNotExists && !useFilesDirectory.exists())
21526 craig 578
                useFilesDirectory.mkpath(useFilesDirectory.absolutePath());
579
        return useFilesDirectory.absolutePath()+"/";
13608 jghali 580
}
581
 
21526 craig 582
QString ScPaths::userDictDir(ScPaths::DictType dictType, bool createIfNotExists)
17525 craig 583
{
20367 craig 584
        QString dictSuffix;
585
        if (dictType == ScPaths::Hyph)
586
                dictSuffix = "hyph/";
587
        if (dictType == ScPaths::Spell)
588
                dictSuffix = "spell/";
21526 craig 589
        QDir useFilesDirectory(applicationDataDir() + "dicts/" + dictSuffix);
22650 jghali 590
        if (createIfNotExists && !useFilesDirectory.exists())
21526 craig 591
                useFilesDirectory.mkpath(useFilesDirectory.absolutePath());
21081 craig 592
        return useFilesDirectory.absolutePath()+"/";
17525 craig 593
}
594
 
21526 craig 595
QString ScPaths::userFontDir(bool createIfNotExists)
19821 craig 596
{
21526 craig 597
        QDir useFilesDirectory(applicationDataDir() + "fonts/");
22650 jghali 598
        if (createIfNotExists && !useFilesDirectory.exists())
21526 craig 599
                useFilesDirectory.mkpath(useFilesDirectory.absolutePath());
21081 craig 600
        return useFilesDirectory.absolutePath()+"/";
19821 craig 601
}
602
 
21526 craig 603
QString ScPaths::userHelpFilesDir(bool createIfNotExists)
21028 craig 604
{
21526 craig 605
        QDir useFilesDirectory(applicationDataDir() + "helpfiles/");
22650 jghali 606
        if (createIfNotExists && !useFilesDirectory.exists())
21526 craig 607
                useFilesDirectory.mkpath(useFilesDirectory.absolutePath());
21081 craig 608
        return useFilesDirectory.absolutePath()+"/";
21028 craig 609
}
610
 
21526 craig 611
QString ScPaths::userPaletteFilesDir(bool createIfNotExists)
21081 craig 612
{
21526 craig 613
        QDir useFilesDirectory(applicationDataDir() + "palettes/");
22650 jghali 614
        if (createIfNotExists && !useFilesDirectory.exists())
21081 craig 615
        {
21526 craig 616
                useFilesDirectory.mkpath(useFilesDirectory.absolutePath());
617
                useFilesDirectory.mkpath(useFilesDirectory.absolutePath() + "/locked");
21081 craig 618
        }
619
        return useFilesDirectory.absolutePath()+"/";
620
}
621
 
21817 craig 622
QString ScPaths::userTemplateDir(bool createIfNotExists)
623
{
624
        if (PrefsManager::instance()->appPrefs.pathPrefs.documentTemplates.isEmpty())
625
                return QString();
626
        QDir useFilesDirectory(PrefsManager::instance()->appPrefs.pathPrefs.documentTemplates);
22650 jghali 627
        if (createIfNotExists && !useFilesDirectory.exists())
21817 craig 628
                useFilesDirectory.mkpath(useFilesDirectory.absolutePath());
629
        return useFilesDirectory.absolutePath()+"/";
630
}
631
 
22598 craig 632
QString ScPaths::userDocumentDir()
5917 jghali 633
{
21520 craig 634
        QString userDocs = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
635
        if (QDir(userDocs).exists())
21524 craig 636
                return userDocs + "/";
637
        return QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/";
5917 jghali 638
}
639
 
21526 craig 640
QString ScPaths::scrapbookDir(bool createIfNotExists)
5917 jghali 641
{
21526 craig 642
        QDir useFilesDirectory(applicationDataDir() + "scrapbook/");
22650 jghali 643
        if (createIfNotExists && !useFilesDirectory.exists())
21526 craig 644
        {
645
                useFilesDirectory.mkpath(useFilesDirectory.absolutePath());
646
                useFilesDirectory.mkpath(useFilesDirectory.absolutePath() + "/main");
647
                useFilesDirectory.mkpath(useFilesDirectory.absolutePath() + "/tmp");
648
        }
649
        return useFilesDirectory.absolutePath()+"/";
650
}
651
 
22598 craig 652
QString ScPaths::tempFileDir()
21526 craig 653
{
654
#ifdef Q_OS_WIN32
5917 jghali 655
        QString tempPath;
656
        WCHAR wTempPath[1024];
657
        DWORD result = GetTempPathW(1024, wTempPath);
22650 jghali 658
        if (result)
5917 jghali 659
        {
10293 jghali 660
                tempPath = QString::fromUtf16((const unsigned short*) wTempPath);
22650 jghali 661
                tempPath.replace('\\', '/');
5917 jghali 662
                tempPath += "/";
663
                // GetTempPath may return Windows directory, better not use this one
664
                // for temporary files
21527 craig 665
                if (QDir(tempPath).exists() && tempPath != windowsSpecialDir(CSIDL_WINDOWS))
5917 jghali 666
                        return tempPath;
667
        }
13265 cbradney 668
#endif
19969 craig 669
 
21526 craig 670
        QDir tempAppDirectory(applicationDataDir() + "temp/");
19969 craig 671
        if (!tempAppDirectory.exists())
672
                tempAppDirectory.mkpath(tempAppDirectory.absolutePath());
673
        return tempAppDirectory.absolutePath()+"/";
5917 jghali 674
}
675
 
17525 craig 676
QString ScPaths::downloadDir()
677
{
21526 craig 678
        QDir downloadDirectory(applicationDataDir() + "downloads/");
17525 craig 679
        if (!downloadDirectory.exists())
680
                downloadDirectory.mkpath(downloadDirectory.absolutePath());
681
        return downloadDirectory.absolutePath()+"/";
682
}
683
 
21526 craig 684
QString ScPaths::windowsSpecialDir(int folder)
3096 fschmid 685
{
686
        QString qstr;
21526 craig 687
#ifdef Q_OS_WIN32
10293 jghali 688
        WCHAR dir[256];
22650 jghali 689
        if (SHGetSpecialFolderPathW(nullptr, dir, folder , false))
4689 mrdocs 690
        {
10293 jghali 691
                qstr = QString::fromUtf16((const unsigned short*) dir);
22650 jghali 692
                if (!qstr.endsWith("\\"))
4689 mrdocs 693
                        qstr += "\\";
22650 jghali 694
                qstr.replace('\\', '/');
4689 mrdocs 695
        }
3096 fschmid 696
#else
697
        Q_ASSERT(false);
698
#endif
699
        return qstr;
700
}