summaryrefslogtreecommitdiffabout
path: root/microkde/kdecore/kstandarddirs.cpp
Unidiff
Diffstat (limited to 'microkde/kdecore/kstandarddirs.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdecore/kstandarddirs.cpp24
1 files changed, 13 insertions, 11 deletions
diff --git a/microkde/kdecore/kstandarddirs.cpp b/microkde/kdecore/kstandarddirs.cpp
index d5bfefd..f10934b 100644
--- a/microkde/kdecore/kstandarddirs.cpp
+++ b/microkde/kdecore/kstandarddirs.cpp
@@ -16,97 +16,99 @@
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22 * Author: Stephan Kulow <coolo@kde.org> and Sirtaj Singh Kang <taj@kde.org> 22 * Author: Stephan Kulow <coolo@kde.org> and Sirtaj Singh Kang <taj@kde.org>
23 * Version:$Id$ 23 * Version:$Id$
24 * Generated:Thu Mar 5 16:05:28 EST 1998 24 * Generated:Thu Mar 5 16:05:28 EST 1998
25 */ 25 */
26 26
27//US #include "config.h" 27//US #include "config.h"
28 28
29#include <stdlib.h> 29#include <stdlib.h>
30#include <assert.h> 30#include <assert.h>
31//US#include <errno.h> 31//US#include <errno.h>
32//US #ifdef HAVE_SYS_STAT_H 32//US #ifdef HAVE_SYS_STAT_H
33//US #include <sys/stat.h> 33//US #include <sys/stat.h>
34//US #endif 34//US #endif
35//US#include <sys/types.h> 35//US#include <sys/types.h>
36//US#include <dirent.h> 36//US#include <dirent.h>
37//US#include <pwd.h> 37//US#include <pwd.h>
38 38
39#include <qregexp.h> 39#include <qregexp.h>
40#include <qasciidict.h> 40#include <q3asciidict.h>
41#include <qdict.h> 41#include <q3dict.h>
42#include <qdir.h> 42#include <qdir.h>
43#include <qfileinfo.h> 43#include <qfileinfo.h>
44#include <qstring.h> 44#include <qstring.h>
45#include <qmessagebox.h> 45#include <qmessagebox.h>
46#include <qapplication.h> 46#include <qapplication.h>
47 47
48#include <qstringlist.h> 48#include <qstringlist.h>
49//Added by qt3to4:
50#include <Q3CString>
49 51
50#include "kstandarddirs.h" 52#include "kstandarddirs.h"
51#include "kconfig.h" 53#include "kconfig.h"
52#include "kdebug.h" 54#include "kdebug.h"
53//US #include "kinstance.h" 55//US #include "kinstance.h"
54#include "kshell.h" 56#include "kshell.h"
55//US#include <sys/param.h> 57//US#include <sys/param.h>
56//US#include <unistd.h> 58//US#include <unistd.h>
57 59
58//US 60//US
59QString KStandardDirs::mAppDir = QString::null; 61QString KStandardDirs::mAppDir = QString::null;
60 62
61 63
62template class QDict<QStringList>; 64template class Q3Dict<QStringList>;
63 65
64#if 0 66#if 0
65#include <qtextedit.h> 67#include <q3textedit.h>
66void ddd( QString op ) 68void ddd( QString op )
67{ 69{
68 static QTextEdit * dot = 0; 70 static Q3TextEdit * dot = 0;
69 if ( ! dot ) 71 if ( ! dot )
70 dot = new QTextEdit(); 72 dot = new Q3TextEdit();
71 73
72 dot->show(); 74 dot->show();
73 75
74 dot->append( op ); 76 dot->append( op );
75 77
76} 78}
77#endif 79#endif
78class KStandardDirs::KStandardDirsPrivate 80class KStandardDirs::KStandardDirsPrivate
79{ 81{
80public: 82public:
81 KStandardDirsPrivate() 83 KStandardDirsPrivate()
82 : restrictionsActive(false), 84 : restrictionsActive(false),
83 dataRestrictionActive(false) 85 dataRestrictionActive(false)
84 { } 86 { }
85 87
86 bool restrictionsActive; 88 bool restrictionsActive;
87 bool dataRestrictionActive; 89 bool dataRestrictionActive;
88 QAsciiDict<bool> restrictions; 90 Q3AsciiDict<bool> restrictions;
89 QStringList xdgdata_prefixes; 91 QStringList xdgdata_prefixes;
90 QStringList xdgconf_prefixes; 92 QStringList xdgconf_prefixes;
91}; 93};
92 94
93static const char* const types[] = {"html", "icon", "apps", "sound", 95static const char* const types[] = {"html", "icon", "apps", "sound",
94 "data", "locale", "services", "mime", 96 "data", "locale", "services", "mime",
95 "servicetypes", "config", "exe", "tmp", 97 "servicetypes", "config", "exe", "tmp",
96 "wallpaper", "lib", "pixmap", "templates", 98 "wallpaper", "lib", "pixmap", "templates",
97 "module", "qtplugins", 99 "module", "qtplugins",
98 "xdgdata-apps", "xdgdata-dirs", "xdgconf-menu", 0 }; 100 "xdgdata-apps", "xdgdata-dirs", "xdgconf-menu", 0 };
99 101
100static int tokenize( QStringList& token, const QString& str, 102static int tokenize( QStringList& token, const QString& str,
101 const QString& delim ); 103 const QString& delim );
102 104
103KStandardDirs::KStandardDirs( ) : addedCustoms(false) 105KStandardDirs::KStandardDirs( ) : addedCustoms(false)
104{ 106{
105 d = new KStandardDirsPrivate; 107 d = new KStandardDirsPrivate;
106 dircache.setAutoDelete(true); 108 dircache.setAutoDelete(true);
107 relatives.setAutoDelete(true); 109 relatives.setAutoDelete(true);
108 absolutes.setAutoDelete(true); 110 absolutes.setAutoDelete(true);
109 savelocations.setAutoDelete(true); 111 savelocations.setAutoDelete(true);
110 addKDEDefaults(); 112 addKDEDefaults();
111} 113}
112 114
@@ -424,86 +426,86 @@ static void lookupDirectory(const QString& path, const QString &relPart,
424 QString _dot("."); 426 QString _dot(".");
425 QString _dotdot(".."); 427 QString _dotdot("..");
426 428
427//US while( ( ep = readdir( dp ) ) != 0L ) 429//US while( ( ep = readdir( dp ) ) != 0L )
428 QStringList direntries = dp.entryList(); 430 QStringList direntries = dp.entryList();
429 QStringList::Iterator it = direntries.begin(); 431 QStringList::Iterator it = direntries.begin();
430 432
431 while ( it != list.end() ) // for each file... 433 while ( it != list.end() ) // for each file...
432 { 434 {
433 435
434//US QString fn( QFile::decodeName(ep->d_name)); 436//US QString fn( QFile::decodeName(ep->d_name));
435 QString fn = (*it); // dp.entryList already decodes 437 QString fn = (*it); // dp.entryList already decodes
436 it++; 438 it++;
437 if ( fn.isNull() ) 439 if ( fn.isNull() )
438 break; 440 break;
439 441
440 if (fn == _dot || fn == _dotdot || fn.at(fn.length() - 1).latin1() == '~' ) 442 if (fn == _dot || fn == _dotdot || fn.at(fn.length() - 1).latin1() == '~' )
441 continue; 443 continue;
442 444
443/*US 445/*US
444 if (!recursive && !regexp.exactMatch(fn)) 446 if (!recursive && !regexp.exactMatch(fn))
445 continue; // No match 447 continue; // No match
446*/ 448*/
447//US this should do the same: 449//US this should do the same:
448 int pos = regexp.match(fn); 450 int pos = regexp.exactMatch(fn);
449 if (!recursive && !pos == 0) 451 if (!recursive && !pos == 0)
450 continue; // No match 452 continue; // No match
451 453
452 QString pathfn = path + fn; 454 QString pathfn = path + fn;
453/*US 455/*US
454 if ( stat( QFile::encodeName(pathfn), &buff ) != 0 ) { 456 if ( stat( QFile::encodeName(pathfn), &buff ) != 0 ) {
455 kdDebug() << "Error stat'ing " << pathfn << " : " << perror << endl; 457 kdDebug() << "Error stat'ing " << pathfn << " : " << perror << endl;
456 continue; // Couldn't stat (e.g. no read permissions) 458 continue; // Couldn't stat (e.g. no read permissions)
457 } 459 }
458 460
459 if ( recursive ) 461 if ( recursive )
460 { 462 {
461 if ( S_ISDIR( buff.st_mode )) { 463 if ( S_ISDIR( buff.st_mode )) {
462 lookupDirectory(pathfn + '/', relPart + fn + '/', regexp, list, relList, recursive, uniq); 464 lookupDirectory(pathfn + '/', relPart + fn + '/', regexp, list, relList, recursive, uniq);
463 } 465 }
464*/ 466*/
465//US replacement: 467//US replacement:
466 QFileInfo pathfnInfo(QFile::encodeName(pathfn)); 468 QFileInfo pathfnInfo(QFile::encodeName(pathfn));
467 if ( pathfnInfo.isReadable() == false ) 469 if ( pathfnInfo.isReadable() == false )
468 { 470 {
469//US kdDebug() << "Error stat'ing " << pathfn << " : " << perror << endl; 471//US kdDebug() << "Error stat'ing " << pathfn << " : " << perror << endl;
470 continue; // Couldn't stat (e.g. no read permissions) 472 continue; // Couldn't stat (e.g. no read permissions)
471 } 473 }
472 474
473 if ( recursive ) 475 if ( recursive )
474 { 476 {
475 if ( pathfnInfo.isDir()) { 477 if ( pathfnInfo.isDir()) {
476 lookupDirectory(pathfn + '/', relPart + fn + '/', regexp, list, relList, recursive, uniq); 478 lookupDirectory(pathfn + '/', relPart + fn + '/', regexp, list, relList, recursive, uniq);
477 } 479 }
478 480
479 481
480/*US 482/*US
481 if (!regexp.exactMatch(fn)) 483 if (!regexp.exactMatch(fn))
482 continue; // No match 484 continue; // No match
483*/ 485*/
484//US this should do the same: 486//US this should do the same:
485 pos = regexp.match(fn); 487 pos = regexp.exactMatch(fn);
486 if (!pos == 0) 488 if (!pos == 0)
487 continue; // No match 489 continue; // No match
488 } 490 }
489 491
490//US if ( S_ISREG( buff.st_mode)) 492//US if ( S_ISREG( buff.st_mode))
491 if ( pathfnInfo.isFile()) 493 if ( pathfnInfo.isFile())
492 { 494 {
493 if (!uniq || !relList.contains(relPart + fn)) 495 if (!uniq || !relList.contains(relPart + fn))
494 { 496 {
495 list.append( pathfn ); 497 list.append( pathfn );
496 relList.append( relPart + fn ); 498 relList.append( relPart + fn );
497 } 499 }
498 } 500 }
499 } 501 }
500//US closedir( dp ); 502//US closedir( dp );
501 } 503 }
502 else 504 else
503 { 505 {
504 // We look for a single file. 506 // We look for a single file.
505 QString fn = pattern; 507 QString fn = pattern;
506 QString pathfn = path + fn; 508 QString pathfn = path + fn;
507//US struct stat buff; 509//US struct stat buff;
508 QFileInfo pathfnInfo(QFile::encodeName(pathfn)); 510 QFileInfo pathfnInfo(QFile::encodeName(pathfn));
509 511
@@ -1087,49 +1089,49 @@ bool KStandardDirs::makeDir(const QString& dir2, int mode)
1087{ 1089{
1088 QString dir = QDir::convertSeparators( dir2 ); 1090 QString dir = QDir::convertSeparators( dir2 );
1089#if 0 1091#if 0
1090 //LR 1092 //LR
1091 1093
1092 // we want an absolute path 1094 // we want an absolute path
1093 if (dir.at(0) != '/') 1095 if (dir.at(0) != '/')
1094 return false; 1096 return false;
1095 1097
1096 QString target = dir; 1098 QString target = dir;
1097 uint len = target.length(); 1099 uint len = target.length();
1098 1100
1099 // append trailing slash if missing 1101 // append trailing slash if missing
1100 if (dir.at(len - 1) != '/') 1102 if (dir.at(len - 1) != '/')
1101 target += '/'; 1103 target += '/';
1102 1104
1103 QString base(""); 1105 QString base("");
1104 uint i = 1; 1106 uint i = 1;
1105 1107
1106 while( i < len ) 1108 while( i < len )
1107 { 1109 {
1108//US struct stat st; 1110//US struct stat st;
1109 int pos = target.find('/', i); 1111 int pos = target.find('/', i);
1110 base += target.mid(i - 1, pos - i + 1); 1112 base += target.mid(i - 1, pos - i + 1);
1111 QCString baseEncoded = QFile::encodeName(base); 1113 Q3CString baseEncoded = QFile::encodeName(base);
1112 // bail out if we encountered a problem 1114 // bail out if we encountered a problem
1113//US if (stat(baseEncoded, &st) != 0) 1115//US if (stat(baseEncoded, &st) != 0)
1114 QFileInfo baseEncodedInfo(baseEncoded); 1116 QFileInfo baseEncodedInfo(baseEncoded);
1115 if (!baseEncodedInfo.exists()) 1117 if (!baseEncodedInfo.exists())
1116 { 1118 {
1117 // Directory does not exist.... 1119 // Directory does not exist....
1118 // Or maybe a dangling symlink ? 1120 // Or maybe a dangling symlink ?
1119//US if (lstat(baseEncoded, &st) == 0) 1121//US if (lstat(baseEncoded, &st) == 0)
1120 if (baseEncodedInfo.isSymLink()) { 1122 if (baseEncodedInfo.isSymLink()) {
1121//US (void)unlink(baseEncoded); // try removing 1123//US (void)unlink(baseEncoded); // try removing
1122 QFile(baseEncoded).remove(); 1124 QFile(baseEncoded).remove();
1123 } 1125 }
1124 1126
1125 //US if ( mkdir(baseEncoded, (mode_t) mode) != 0) 1127 //US if ( mkdir(baseEncoded, (mode_t) mode) != 0)
1126 QDir dirObj; 1128 QDir dirObj;
1127 if ( dirObj.mkdir(baseEncoded) != true ) 1129 if ( dirObj.mkdir(baseEncoded) != true )
1128 { 1130 {
1129 //US perror("trying to create local folder"); 1131 //US perror("trying to create local folder");
1130 return false; // Couldn't create it :-( 1132 return false; // Couldn't create it :-(
1131 } 1133 }
1132 } 1134 }
1133 i = pos + 1; 1135 i = pos + 1;
1134 } 1136 }
1135 return true; 1137 return true;
@@ -1187,49 +1189,49 @@ bool KStandardDirs::makeDir(const QString& dir2, int mode)
1187 } 1189 }
1188*/ 1190*/
1189 1191
1190 if (dirObj.exists(base) == false) 1192 if (dirObj.exists(base) == false)
1191 { 1193 {
1192 //qDebug("KStandardDirs::makeDir try to create : %s" , base.latin1()); 1194 //qDebug("KStandardDirs::makeDir try to create : %s" , base.latin1());
1193 if (dirObj.mkdir(base) != true) 1195 if (dirObj.mkdir(base) != true)
1194 { 1196 {
1195 qDebug("KStandardDirs::makeDir could not create: %s" , base.latin1()); 1197 qDebug("KStandardDirs::makeDir could not create: %s" , base.latin1());
1196 return false; 1198 return false;
1197 } 1199 }
1198 } 1200 }
1199 1201
1200 i = pos + 1; 1202 i = pos + 1;
1201 } 1203 }
1202 return true; 1204 return true;
1203 1205
1204} 1206}
1205 1207
1206QString readEnvPath(const char *env) 1208QString readEnvPath(const char *env)
1207{ 1209{
1208 //#ifdef _WIN32_ 1210 //#ifdef _WIN32_
1209 // return ""; 1211 // return "";
1210 //#else 1212 //#else
1211 QCString c_path; 1213 Q3CString c_path;
1212 if ( getenv(env) != NULL ) 1214 if ( getenv(env) != NULL )
1213 c_path = QString ( getenv(env) ); 1215 c_path = QString ( getenv(env) );
1214 if (c_path.isEmpty()) 1216 if (c_path.isEmpty())
1215 return QString::null; 1217 return QString::null;
1216 return QFile::decodeName(c_path); 1218 return QFile::decodeName(c_path);
1217 //#endif 1219 //#endif
1218 1220
1219} 1221}
1220 1222
1221void KStandardDirs::addKDEDefaults() 1223void KStandardDirs::addKDEDefaults()
1222{ 1224{
1223 1225
1224 //qDebug("ERROR: KStandardDirs::addKDEDefaults() called "); 1226 //qDebug("ERROR: KStandardDirs::addKDEDefaults() called ");
1225 //return; 1227 //return;
1226 QStringList kdedirList; 1228 QStringList kdedirList;
1227 1229
1228 // begin KDEDIRS 1230 // begin KDEDIRS
1229 QString kdedirs = readEnvPath("MICROKDEDIRS"); 1231 QString kdedirs = readEnvPath("MICROKDEDIRS");
1230 if (!kdedirs.isEmpty()) 1232 if (!kdedirs.isEmpty())
1231 { 1233 {
1232 tokenize(kdedirList, kdedirs, ":"); 1234 tokenize(kdedirList, kdedirs, ":");
1233 } 1235 }
1234 else 1236 else
1235 { 1237 {