6
#include <sys/stat.h> // chmod
14
#include <sys/stat.h> // chmod
15
#include <CoreServices/CoreServices.h>
18
#include "applicationinfo.h"
24
// Constants. These should be moved to a more 'dynamically changeable'
25
// place (like an external file loaded through the resources system)
26
// Should also be overridable through an optional file.
28
#define PROG_NAME "Psi"
29
//#define PROG_VERSION "0.11-dev" " (" __DATE__ ")"; //CVS Builds are dated
30
#define PROG_VERSION "0.11";
31
#define PROG_CAPS_NODE "http://psi-im.org/caps";
32
#define PROG_CAPS_VERSION "0.11-dev-rev8";
33
#define PROG_OPTIONS_NS "http://psi-im.org/options";
34
#define PROG_STORAGE_NS "http://psi-im.org/storage";
36
#if defined(Q_WS_X11) && !defined(PSI_DATADIR)
37
#define PSI_DATADIR "/usr/local/share/psi"
41
QString ApplicationInfo::name()
47
QString ApplicationInfo::version()
52
QString ApplicationInfo::capsNode()
54
return PROG_CAPS_NODE;
57
QString ApplicationInfo::capsVersion()
59
return PROG_CAPS_VERSION;
62
QString ApplicationInfo::optionsNS()
64
return PROG_OPTIONS_NS;
67
QString ApplicationInfo::storageNS()
69
return PROG_STORAGE_NS;
72
QString ApplicationInfo::resourcesDir()
76
#elif defined(Q_WS_WIN)
77
return qApp->applicationDirPath();
78
#elif defined(Q_WS_MAC)
79
// FIXME: Clean this up (remko)
80
// System routine locates resource files. We "know" that Psi.icns is
81
// in the Resources directory.
83
CFBundleRef mainBundle = CFBundleGetMainBundle();
84
CFStringRef resourceCFStringRef
85
= CFStringCreateWithCString( NULL, "application.icns",
86
kCFStringEncodingASCII );
87
CFURLRef resourceURLRef = CFBundleCopyResourceURL( mainBundle,
91
if ( resourceURLRef ) {
92
CFStringRef resourcePathStringRef =
93
CFURLCopyFileSystemPath( resourceURLRef, kCFURLPOSIXPathStyle );
94
const char* resourcePathCString =
95
CFStringGetCStringPtr( resourcePathStringRef, kCFStringEncodingASCII );
96
if ( resourcePathCString ) {
97
resourcePath.setLatin1( resourcePathCString );
98
} else { // CFStringGetCStringPtr failed; use fallback conversion
99
CFIndex bufferLength = CFStringGetLength( resourcePathStringRef ) + 1;
100
char* resourcePathCString = new char[ bufferLength ];
101
Boolean conversionSuccess =
102
CFStringGetCString( resourcePathStringRef,
103
resourcePathCString, bufferLength,
104
kCFStringEncodingASCII );
105
if ( conversionSuccess ) {
106
resourcePath = resourcePathCString;
108
delete [] resourcePathCString; // I own this
110
CFRelease( resourcePathStringRef ); // I own this
112
// Remove the tail component of the path
113
if ( ! resourcePath.isNull() ) {
114
QFileInfo fileInfo( resourcePath );
115
resourcePath = fileInfo.dirPath( true );
122
/** \brief return psi's private read write data directory
123
* unix+mac: $HOME/.psi
124
* environment variable "PSIDATADIR" overrides
126
QString ApplicationInfo::homeDir()
128
// Try the environment override first
129
char *p = getenv("PSIDATADIR");
133
#if defined(Q_WS_X11)
134
QDir proghome(QDir::homeDirPath() + "/.psi");
135
if(!proghome.exists()) {
136
QDir home = QDir::home();
138
chmod(QFile::encodeName(proghome.path()), 0700);
140
return proghome.path();
141
#elif defined(Q_WS_WIN)
145
if(QDir::homeDirPath() == QDir::rootDirPath())
147
// Windows NT/2K/XP variant
149
base = QDir::homeDirPath();
152
if(base.at(base.length()-1) == '/')
153
base.truncate(base.length()-1);
155
QDir proghome(base + "/PsiData");
156
if(!proghome.exists()) {
158
home.mkdir("PsiData");
161
return proghome.path();
162
#elif defined(Q_WS_MAC)
163
QDir proghome(QDir::homeDirPath() + "/.psi");
164
if(!proghome.exists()) {
165
QDir home = QDir::home();
167
chmod(QFile::encodeName(proghome.path()), 0700);
170
return proghome.path();
174
QString ApplicationInfo::historyDir()
176
QDir history(pathToProfile(activeProfile) + "/history");
177
if (!history.exists()) {
178
QDir profile(pathToProfile(activeProfile));
179
profile.mkdir("history");
182
return history.path();
185
QString ApplicationInfo::vCardDir()
187
QDir vcard(pathToProfile(activeProfile) + "/vcard");
188
if (!vcard.exists()) {
189
QDir profile(pathToProfile(activeProfile));
190
profile.mkdir("vcard");
196
QString ApplicationInfo::profilesDir()
198
QString profiles_dir(homeDir() + "/profiles");
199
QDir d(profiles_dir);