summaryrefslogtreecommitdiffabout
path: root/microkde/kstandarddirs_old.cpp
Unidiff
Diffstat (limited to 'microkde/kstandarddirs_old.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kstandarddirs_old.cpp151
1 files changed, 151 insertions, 0 deletions
diff --git a/microkde/kstandarddirs_old.cpp b/microkde/kstandarddirs_old.cpp
new file mode 100644
index 0000000..ac2c085
--- a/dev/null
+++ b/microkde/kstandarddirs_old.cpp
@@ -0,0 +1,151 @@
1#include "kdebug.h"
2#include "kurl.h"
3
4#include "kstandarddirs.h"
5#ifdef DESKTOP_VERSION
6#include <qregexp.h>
7#include <qmessagebox.h>
8
9#endif
10
11
12#include <qfile.h>
13#include <qdir.h>
14
15QString KStandardDirs::mAppDir = QString::null;
16
17QString locate( const char *type, const QString& filename )
18{
19/*US why do we put all files into one directory. It is quit complicated.
20why not staying with the original directorystructure ?
21
22
23 QString escapedFilename = filename;
24 escapedFilename.replace( QRegExp( "/" ), "_" );
25
26 QString path = KStandardDirs::appDir() + type + "_" + escapedFilename;
27
28 kdDebug() << "locate: '" << path << "'" << endl;
29 qDebug("locate: %s" , path.latin1());
30 return path;
31*/
32//US so my proposal is this:
33
34// QString escapedFilename = filename;
35// escapedFilename.replace( QRegExp( "/" ), "_" );
36
37#ifdef _WIN32_
38 QString path = QDir::convertSeparators(KStandardDirs::appDir() + type + "/" + filename);
39#else
40 QString path = KStandardDirs::appDir() + type + "/" + filename;
41#endif
42
43 //US Create the containing dir if needed
44 KURL pathurl;
45 pathurl.setPath(path);
46 QString dir=pathurl.directory();
47 //QMessageBox::information( 0,"path", path, 1 );
48#ifdef _WIN32_
49 KStandardDirs::makeDir(path);
50#else
51 KStandardDirs::makeDir(dir);
52#endif
53
54 kdDebug() << "locate: '" << path << "'" << endl;
55 qDebug("locate: %s" , path.latin1());
56 return path;
57
58
59}
60
61QString locateLocal( const char *type, const QString& filename )
62{
63 return locate( type, filename );
64}
65
66QStringList KStandardDirs::findAllResources( const QString &, const QString &, bool, bool)
67{
68 return QStringList();
69}
70
71QString KStandardDirs::findResourceDir( const QString &, const QString & )
72{
73 return QString::null;
74}
75
76void KStandardDirs::setAppDir( const QString &appDir )
77{
78 mAppDir = appDir;
79
80 if ( mAppDir.right( 1 ) != "/" ) mAppDir += "/";
81}
82
83bool KStandardDirs::makeDir(const QString& dir, int mode)
84{
85 QDir dirObj;
86
87
88 // we want an absolute path
89#ifndef _WIN32_
90 if (dir.at(0) != '/')
91 return false;
92#endif
93
94
95
96 QString target = dir;
97 uint len = target.length();
98#ifndef _WIN32_
99 // append trailing slash if missing
100 if (dir.at(len - 1) != '/')
101 target += '/';
102#endif
103
104 QString base("");
105 uint i = 1;
106
107 while( i < len )
108 {
109//US struct stat st;
110#ifndef _WIN32_
111 int pos = target.find('/', i);
112#else
113 int pos = target.find('\\', i);
114#endif
115 if ( pos < 0 )
116 return true;
117 base += target.mid(i - 1, pos - i + 1);
118 //QMessageBox::information( 0,"cap111", base, 1 );
119/*US
120 QCString baseEncoded = QFile::encodeName(base);
121 // bail out if we encountered a problem
122 if (stat(baseEncoded, &st) != 0)
123 {
124 // Directory does not exist....
125 // Or maybe a dangling symlink ?
126 if (lstat(baseEncoded, &st) == 0)
127 (void)unlink(baseEncoded); // try removing
128
129
130 if ( mkdir(baseEncoded, (mode_t) mode) != 0) {
131 perror("trying to create local folder");
132 return false; // Couldn't create it :-(
133 }
134 }
135*/
136
137 if (dirObj.exists(base) == false)
138 {
139 qDebug("KStandardDirs::makeDir try to create : %s" , base.latin1());
140 if (dirObj.mkdir(base) != true)
141 {
142 qDebug("KStandardDirs::makeDir could not create: %s" , base.latin1());
143 return false;
144 }
145 }
146
147 i = pos + 1;
148 }
149 return true;
150}
151