Subversion Repositories Scribus

Rev

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