Subversion Repositories Scribus

Rev

Rev 2688 | Rev 3096 | 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),
2707 subik 41
        m_templateDir(TEMPLATEDIR),
42
        m_shareDir(SHAREDIR)
1693 craig 43
{
44
// On MacOS/X, override the compile-time settings with a location
45
// obtained from the system.
2673 cbradney 46
#ifdef BUILD_MAC_BUNDLE
1693 craig 47
        // Set up the various app paths to look inside the app bundle
48
        CFURLRef pluginRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
49
        CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef,
50
                                               kCFURLPOSIXPathStyle);
51
        const char *pathPtr = CFStringGetCStringPtr(macPath,
52
                                               CFStringGetSystemEncoding());
2673 cbradney 53
        char *p = pathPtr + strlen(pathPtr) -1;
54
        while (*p == '/')
55
                --p;
56
        ++p;
57
        *p = '\0';
58
        if (strcmp("/bin", p-4) == 0) {
59
                p -= 4;
60
                *p = '\0';
61
        }
62
        if (strcmp("/MacOS", p-6) == 0) {
63
                p -= 6;
64
                *p = '\0';
65
        }
66
        if (strcmp("/Contents", p-9) == 0) {
67
                p -= 9;
68
                *p = '\0';
69
        }
2707 subik 70
 
2673 cbradney 71
//      qDebug(QString("scpaths: bundle at %1:").arg(pathPtr));
2707 subik 72
        m_shareDir = strdup(QString("%1/Contents/share/scribus/").arg(pathPtr));
2673 cbradney 73
        m_docDir = strdup(QString("%1/Contents/share/scribus/doc/").arg(pathPtr));
74
        m_iconDir = strdup(QString("%1/Contents/share/scribus/icons/").arg(pathPtr));
75
        m_sampleScriptDir = strdup(QString("%1/Contents/share/scribus/samples/").arg(pathPtr));
76
        m_scriptDir = strdup(QString("%1/Contents/share/scribus/scripts/").arg(pathPtr));
77
        m_templateDir = strdup(QString("%1/Contents/share/scribus/templates/").arg(pathPtr));
78
        m_libDir = strdup(QString("%1/Contents/lib/scribus/").arg(pathPtr));
79
        m_pluginDir = strdup(QString("%1/Contents/lib/scribus/plugins/").arg(pathPtr));
80
        QApplication::setLibraryPaths(QString("%1/Contents/lib/qtplugins/").arg(pathPtr));
1693 craig 81
        CFRelease(pluginRef);
82
        CFRelease(macPath);
2673 cbradney 83
/*
84
        qDebug(QString("scpaths: doc dir=%1").arg(m_docDir));
85
        qDebug(QString("scpaths: icon dir=%1").arg(m_iconDir));
86
        qDebug(QString("scpaths: sample dir=%1").arg(m_sampleScriptDir));
87
        qDebug(QString("scpaths: script dir=%1").arg(m_scriptDir));
88
        qDebug(QString("scpaths: template dir=%1").arg(m_templateDir));
89
        qDebug(QString("scpaths: lib dir=%1").arg(m_libDir));
90
        qDebug(QString("scpaths: plugin dir=%1").arg(m_pluginDir));
91
        qDebug(QString("scpaths: qtplugins=%1").arg(QApplication::libraryPaths().join(":")));
92
*/
93
#endif // defined(BUILD_MAC_BUNDLE)
1693 craig 94
}
95
 
96
ScPaths::~ScPaths() {};
97
 
98
const QString&  ScPaths::docDir() const
99
{
100
        return m_docDir;
101
}
102
 
103
const QString&  ScPaths::iconDir() const
104
{
105
        return m_iconDir;
106
}
107
 
108
const QString&  ScPaths::libDir() const
109
{
110
        return m_libDir;
111
}
112
 
113
const QString&  ScPaths::pluginDir() const
114
{
115
        return m_pluginDir;
116
}
117
 
118
const QString&  ScPaths::sampleScriptDir() const
119
{
120
        return m_sampleScriptDir;
121
}
122
 
123
const QString&  ScPaths::scriptDir() const
124
{
125
        return m_scriptDir;
126
}
127
 
128
const QString&  ScPaths::templateDir() const
129
{
130
        return m_templateDir;
131
}
132
 
2707 subik 133
const QString&  ScPaths::shareDir() const
134
{
135
        return m_shareDir;
136
}