Subversion Repositories Scribus

Rev

Rev 2673 | Rev 2707 | 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>
1693 craig 3
 
2688 craig 4
#include "scconfig.h"
2673 cbradney 5
 
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
 
13
// Init the singleton's "self" address to NULL
14
ScPaths* ScPaths::m_instance = NULL;
15
 
16
// Singleton's public constructor
17
const ScPaths& ScPaths::instance()
18
{
19
        if (!ScPaths::m_instance)
20
                ScPaths::m_instance = new ScPaths();
21
        return *ScPaths::m_instance;
22
}
23
 
24
// Singleton's public destructor
25
void ScPaths::destroy()
26
{
27
        if (ScPaths::m_instance)
28
                delete ScPaths::m_instance;
29
}
30
 
31
// Protected "real" constructor
32
// All paths are initialized to compile-time defaults passed in
33
// as preprocessor macros and set by autoconf.
34
ScPaths::ScPaths() :
35
        m_docDir(DOCDIR),
36
        m_iconDir(ICONDIR),
37
        m_libDir(LIBDIR),
38
        m_pluginDir(PLUGINDIR),
39
        m_sampleScriptDir(SAMPLESDIR),
40
        m_scriptDir(SCRIPTSDIR),
41
        m_templateDir(TEMPLATEDIR)
42
{
43
// On MacOS/X, override the compile-time settings with a location
44
// obtained from the system.
2673 cbradney 45
#ifdef BUILD_MAC_BUNDLE
1693 craig 46
        // Set up the various app paths to look inside the app bundle
47
        CFURLRef pluginRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
48
        CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef,
49
                                               kCFURLPOSIXPathStyle);
50
        const char *pathPtr = CFStringGetCStringPtr(macPath,
51
                                               CFStringGetSystemEncoding());
2673 cbradney 52
        char *p = pathPtr + strlen(pathPtr) -1;
53
        while (*p == '/')
54
                --p;
55
        ++p;
56
        *p = '\0';
57
        if (strcmp("/bin", p-4) == 0) {
58
                p -= 4;
59
                *p = '\0';
60
        }
61
        if (strcmp("/MacOS", p-6) == 0) {
62
                p -= 6;
63
                *p = '\0';
64
        }
65
        if (strcmp("/Contents", p-9) == 0) {
66
                p -= 9;
67
                *p = '\0';
68
        }
69
 
70
//      qDebug(QString("scpaths: bundle at %1:").arg(pathPtr));
71
        m_docDir = strdup(QString("%1/Contents/share/scribus/doc/").arg(pathPtr));
72
        m_iconDir = strdup(QString("%1/Contents/share/scribus/icons/").arg(pathPtr));
73
        m_sampleScriptDir = strdup(QString("%1/Contents/share/scribus/samples/").arg(pathPtr));
74
        m_scriptDir = strdup(QString("%1/Contents/share/scribus/scripts/").arg(pathPtr));
75
        m_templateDir = strdup(QString("%1/Contents/share/scribus/templates/").arg(pathPtr));
76
        m_libDir = strdup(QString("%1/Contents/lib/scribus/").arg(pathPtr));
77
        m_pluginDir = strdup(QString("%1/Contents/lib/scribus/plugins/").arg(pathPtr));
78
        QApplication::setLibraryPaths(QString("%1/Contents/lib/qtplugins/").arg(pathPtr));
1693 craig 79
        CFRelease(pluginRef);
80
        CFRelease(macPath);
2673 cbradney 81
/*
82
        qDebug(QString("scpaths: doc dir=%1").arg(m_docDir));
83
        qDebug(QString("scpaths: icon dir=%1").arg(m_iconDir));
84
        qDebug(QString("scpaths: sample dir=%1").arg(m_sampleScriptDir));
85
        qDebug(QString("scpaths: script dir=%1").arg(m_scriptDir));
86
        qDebug(QString("scpaths: template dir=%1").arg(m_templateDir));
87
        qDebug(QString("scpaths: lib dir=%1").arg(m_libDir));
88
        qDebug(QString("scpaths: plugin dir=%1").arg(m_pluginDir));
89
        qDebug(QString("scpaths: qtplugins=%1").arg(QApplication::libraryPaths().join(":")));
90
*/
91
#endif // defined(BUILD_MAC_BUNDLE)
1693 craig 92
}
93
 
94
ScPaths::~ScPaths() {};
95
 
96
const QString&  ScPaths::docDir() const
97
{
98
        return m_docDir;
99
}
100
 
101
const QString&  ScPaths::iconDir() const
102
{
103
        return m_iconDir;
104
}
105
 
106
const QString&  ScPaths::libDir() const
107
{
108
        return m_libDir;
109
}
110
 
111
const QString&  ScPaths::pluginDir() const
112
{
113
        return m_pluginDir;
114
}
115
 
116
const QString&  ScPaths::sampleScriptDir() const
117
{
118
        return m_sampleScriptDir;
119
}
120
 
121
const QString&  ScPaths::scriptDir() const
122
{
123
        return m_scriptDir;
124
}
125
 
126
const QString&  ScPaths::templateDir() const
127
{
128
        return m_templateDir;
129
}
130