author | alwin <alwin> | 2004-02-24 13:25:40 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-02-24 13:25:40 (UTC) |
commit | 6b6ba7aa1bf21647a804c7e5e7e1654112c3ee38 (patch) (side-by-side diff) | |
tree | 6d202c80e470686ec72680e3371d15e0fb987c3b | |
parent | 911473db35a9fce5f3589f03c27210456faaba86 (diff) | |
download | opie-6b6ba7aa1bf21647a804c7e5e7e1654112c3ee38.zip opie-6b6ba7aa1bf21647a804c7e5e7e1654112c3ee38.tar.gz opie-6b6ba7aa1bf21647a804c7e5e7e1654112c3ee38.tar.bz2 |
use Config for checking if the medium should be checked
-rw-r--r-- | library/global.cpp | 246 |
1 files changed, 114 insertions, 132 deletions
diff --git a/library/global.cpp b/library/global.cpp index 4aca08b..a627348 100644 --- a/library/global.cpp +++ b/library/global.cpp @@ -51,24 +51,4 @@ #include <qfile.h> -namespace { - // checks if the storage should be searched - bool checkStorage(const QString &path ){ // this is a small Config replacement cause config is too limited -zecke - QFile file(path ); - if(!file.open(IO_ReadOnly ) ) - return true; - - QByteArray array = file.readAll(); - QStringList list = QStringList::split('\n', QString( array ) ); - for(QStringList::Iterator it = list.begin(); it != list.end(); ++it ){ - if( (*it).startsWith("check = 0" ) ){ - return false; - }else if( (*it).startsWith("check = 1" ) ){ - return true; - } - } - return true; - } -} - //#include "quickexec_p.h" @@ -78,9 +58,9 @@ public: Emitter( QWidget* receiver, const QString& document ) { - connect(this, SIGNAL(setDocument(const QString&)), - receiver, SLOT(setDocument(const QString&))); - emit setDocument(document); - disconnect(this, SIGNAL(setDocument(const QString&)), - receiver, SLOT(setDocument(const QString&))); + connect(this, SIGNAL(setDocument(const QString&)), + receiver, SLOT(setDocument(const QString&))); + emit setDocument(document); + disconnect(this, SIGNAL(setDocument(const QString&)), + receiver, SLOT(setDocument(const QString&))); } @@ -111,5 +91,5 @@ StartingAppList::StartingAppList( QObject *parent, const char* name ) #if QT_VERSION >= 232 && defined(QWS) connect( qwsServer, SIGNAL( newChannel(const QString&)), - this, SLOT( handleNewChannel(const QString&)) ); + this, SLOT( handleNewChannel(const QString&)) ); #endif dict.setAutoDelete( TRUE ); @@ -120,5 +100,5 @@ void StartingAppList::add( const QString& name ) #if QT_VERSION >= 232 && !defined(QT_NO_COP) if ( !appl ) - appl = new StartingAppList; + appl = new StartingAppList; QTime *t = new QTime; t->start(); @@ -131,13 +111,13 @@ bool StartingAppList::isStarting( const QString name ) #if QT_VERSION >= 232 && !defined(QT_NO_COP) if ( appl ) { - QTime *t = appl->dict.find( "QPE/Application/" + name ); - if ( !t ) - return FALSE; - if ( t->elapsed() > 10000 ) { - // timeout in case of crash or something - appl->dict.remove( "QPE/Application/" + name ); - return FALSE; - } - return TRUE; + QTime *t = appl->dict.find( "QPE/Application/" + name ); + if ( !t ) + return FALSE; + if ( t->elapsed() > 10000 ) { + // timeout in case of crash or something + appl->dict.remove( "QPE/Application/" + name ); + return FALSE; + } + return TRUE; } #endif @@ -239,37 +219,37 @@ const QDawg& Global::fixedDawg() { if ( !fixed_dawg ) { - if ( !docDirCreated ) - createDocDir(); - - fixed_dawg = new QDawg; - QString dawgfilename = dictDir() + "/dawg"; - QString words_lang; - QStringList langs = Global::languageList(); - for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { - QString lang = *it; - words_lang = dictDir() + "/words." + lang; - QString dawgfilename_lang = dawgfilename + "." + lang; - if ( QFile::exists(dawgfilename_lang) || - QFile::exists(words_lang) ) { - dawgfilename = dawgfilename_lang; - break; - } - } - QFile dawgfile(dawgfilename); - - if ( !dawgfile.exists() ) { - QString fn = dictDir() + "/words"; - if ( QFile::exists(words_lang) ) - fn = words_lang; - QFile in(fn); - if ( in.open(IO_ReadOnly) ) { - fixed_dawg->createFromWords(&in); - dawgfile.open(IO_WriteOnly); - fixed_dawg->write(&dawgfile); - dawgfile.close(); - } - } else { - fixed_dawg->readFile(dawgfilename); - } + if ( !docDirCreated ) + createDocDir(); + + fixed_dawg = new QDawg; + QString dawgfilename = dictDir() + "/dawg"; + QString words_lang; + QStringList langs = Global::languageList(); + for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { + QString lang = *it; + words_lang = dictDir() + "/words." + lang; + QString dawgfilename_lang = dawgfilename + "." + lang; + if ( QFile::exists(dawgfilename_lang) || + QFile::exists(words_lang) ) { + dawgfilename = dawgfilename_lang; + break; + } + } + QFile dawgfile(dawgfilename); + + if ( !dawgfile.exists() ) { + QString fn = dictDir() + "/words"; + if ( QFile::exists(words_lang) ) + fn = words_lang; + QFile in(fn); + if ( in.open(IO_ReadOnly) ) { + fixed_dawg->createFromWords(&in); + dawgfile.open(IO_WriteOnly); + fixed_dawg->write(&dawgfile); + dawgfile.close(); + } + } else { + fixed_dawg->readFile(dawgfilename); + } } @@ -298,13 +278,13 @@ const QDawg& Global::dawg(const QString& name) createDocDir(); if ( !named_dawg ) - named_dawg = new QDict<QDawg>; + named_dawg = new QDict<QDawg>; QDawg* r = named_dawg->find(name); if ( !r ) { - r = new QDawg; - named_dawg->insert(name,r); - QString dawgfilename = applicationFileName("Dictionary", name ) + ".dawg"; - QFile dawgfile(dawgfilename); - if ( dawgfile.open(IO_ReadOnly) ) - r->readFile(dawgfilename); + r = new QDawg; + named_dawg->insert(name,r); + QString dawgfilename = applicationFileName("Dictionary", name ) + ".dawg"; + QFile dawgfile(dawgfilename); + if ( dawgfile.open(IO_ReadOnly) ) + r->readFile(dawgfilename); } return *r; @@ -341,6 +321,6 @@ void Global::addWords(const QString& dictname, const QStringList& wordlist) QFile dawgfile(dawgfilename); if ( dawgfile.open(IO_WriteOnly) ) { - d.write(&dawgfile); - dawgfile.close(); + d.write(&dawgfile); + dawgfile.close(); } @@ -364,10 +344,10 @@ QString Global::applicationFileName(const QString& appname, const QString& filen r += "/Applications/"; if ( !QFile::exists( r ) ) - if ( d.mkdir(r) == false ) - return QString::null; + if ( d.mkdir(r) == false ) + return QString::null; r += appname; if ( !QFile::exists( r ) ) - if ( d.mkdir(r) == false ) - return QString::null; + if ( d.mkdir(r) == false ) + return QString::null; r += "/"; r += filename; return r; @@ -380,6 +360,6 @@ void Global::createDocDir() { if ( !docDirCreated ) { - docDirCreated = TRUE; - mkdir( QPEApplication::documentDir().latin1(), 0755 ); + docDirCreated = TRUE; + mkdir( QPEApplication::documentDir().latin1(), 0755 ); } } @@ -471,9 +451,9 @@ bool Global::isBuiltinCommand( const QString &name ) { if(!builtin) - return FALSE; // yes, it can happen + return FALSE; // yes, it can happen for (int i = 0; builtin[i].file; i++) { - if ( builtin[i].file == name ) { - return TRUE; - } + if ( builtin[i].file == name ) { + return TRUE; + } } return FALSE; @@ -495,12 +475,12 @@ void Global::setBuiltinCommands( Command* list ) { if ( running ) - delete [] running; + delete [] running; builtin = list; int count = 0; if (!builtin) - return; + return; while ( builtin[count].file ) - count++; + count++; running = new QGuardedPtr<QWidget> [ count ]; @@ -521,10 +501,10 @@ bool Global::terminateBuiltin( const QString& n ) { if (!builtin) - return FALSE; + return FALSE; for (int i = 0; builtin[i].file; i++) { - if ( builtin[i].file == n ) { - delete running[i]; - return TRUE; - } + if ( builtin[i].file == n ) { + delete running[i]; + return TRUE; + } } return FALSE; @@ -541,5 +521,5 @@ void Global::terminate( const AppLnk* app ) QCString channel = "QPE/Application/" + app->exec().utf8(); if ( QCopChannel::isRegistered(channel) ) { - QCopEnvelope e(channel, "quit()"); + QCopEnvelope e(channel, "quit()"); } #endif @@ -563,10 +543,10 @@ void Global::invoke(const QString &c) // XXX should lock file /tmp/qcop-msg-ap if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) { - // If the channel is already register, the app is already running, so show it. - { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } + // If the channel is already register, the app is already running, so show it. + { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } - //QCopEnvelope e("QPE/System", "notBusy(QString)" ); - //e << ap; - return; + //QCopEnvelope e("QPE/System", "notBusy(QString)" ); + //e << ap; + return; } // XXX should unlock file /tmp/qcop-msg-ap @@ -578,7 +558,7 @@ void Global::invoke(const QString &c) // to fix that, and with future syncs with qtopia 1.6 it will change anyway big time since somebody there // had the idea that an apploader belongs to the launcher ... - //QCopEnvelope e("QPE/System", "notBusy(QString)" ); - //e << ap; - return; + //QCopEnvelope e("QPE/System", "notBusy(QString)" ); + //e << ap; + return; } @@ -592,9 +572,9 @@ void Global::invoke(const QString &c) unsigned int j; for ( j = 0; j < list.count(); j++ ) - slist.append( list[j].utf8() ); + slist.append( list[j].utf8() ); const char **args = new (const char *)[slist.count() + 1]; for ( j = 0; j < slist.count(); j++ ) - args[j] = slist.at(j); + args[j] = slist.at(j); args[j] = NULL; @@ -613,6 +593,6 @@ void Global::invoke(const QString &c) qDebug("libfile = %s", libexe.latin1() ); if ( QFile::exists( libexe ) ) { - qDebug("calling quickexec %s", libexe.latin1() ); - quickexecv( libexe.utf8().data(), (const char **)args ); + qDebug("calling quickexec %s", libexe.latin1() ); + quickexecv( libexe.utf8().data(), (const char **)args ); } else #endif @@ -684,5 +664,5 @@ void Global::invoke(const QString &c) void Global::execute( const QString &c, const QString& document ) { - // ask the server to do the work + // ask the server to do the work #if !defined(QT_NO_COP) if ( document.isNull() ) { @@ -707,10 +687,10 @@ QString Global::shellQuote(const QString& s) QString r="\""; for (int i=0; i<(int)s.length(); i++) { - char c = s[i].latin1(); - switch (c) { - case '\\': case '"': case '$': - r+="\\"; - } - r += s[i]; + char c = s[i].latin1(); + switch (c) { + case '\\': case '"': case '$': + r+="\\"; + } + r += s[i]; } r += "\""; @@ -728,10 +708,10 @@ QString Global::stringQuote(const QString& s) QString r="\""; for (int i=0; i<(int)s.length(); i++) { - char c = s[i].latin1(); - switch (c) { - case '\\': case '"': - r+="\\"; - } - r += s[i]; + char c = s[i].latin1(); + switch (c) { + case '\\': case '"': + r+="\\"; + } + r += s[i]; } r += "\""; @@ -770,7 +750,9 @@ void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter) // this is a candidate look at the cf and see if we should search on it QString path = (*it)->path(); - if( !checkStorage((*it)->path() + "/.opiestorage.cf" ) ) - continue; Config conf((*it)->path() + "/.opiestorage.cf", Config::File ); + conf.setGroup("main"); + if (!conf.readBoolEntry("check",true)) { + continue; + } conf.setGroup("subdirs"); if (conf.readBoolEntry("wholemedia",true)) { @@ -788,7 +770,7 @@ void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter) } } else if ( (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) { - QString path = (*it)->path() + "/Documents"; - DocLnkSet ide( path, mimefilter ); - folder->appendFrom(ide); + QString path = (*it)->path() + "/Documents"; + DocLnkSet ide( path, mimefilter ); + folder->appendFrom(ide); } } @@ -802,8 +784,8 @@ QStringList Global::languageList() int i = lang.find("."); if ( i > 0 ) - lang = lang.left( i ); + lang = lang.left( i ); i = lang.find( "_" ); if ( i > 0 ) - langs.append(lang.left(i)); + langs.append(lang.left(i)); return langs; } @@ -815,7 +797,7 @@ QStringList Global::helpPath() QStringList langs = Global::languageList(); for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) { - QString lang = *it; - if ( !lang.isEmpty() ) - path += qpeDir + "/help/" + lang + "/html"; + QString lang = *it; + if ( !lang.isEmpty() ) + path += qpeDir + "/help/" + lang + "/html"; } path += qpeDir + "/pics"; |