summaryrefslogtreecommitdiff
path: root/library
authoralwin <alwin>2004-02-24 13:25:40 (UTC)
committer alwin <alwin>2004-02-24 13:25:40 (UTC)
commit6b6ba7aa1bf21647a804c7e5e7e1654112c3ee38 (patch) (side-by-side diff)
tree6d202c80e470686ec72680e3371d15e0fb987c3b /library
parent911473db35a9fce5f3589f03c27210456faaba86 (diff)
downloadopie-6b6ba7aa1bf21647a804c7e5e7e1654112c3ee38.zip
opie-6b6ba7aa1bf21647a804c7e5e7e1654112c3ee38.tar.gz
opie-6b6ba7aa1bf21647a804c7e5e7e1654112c3ee38.tar.bz2
use Config for checking if the medium should be checked
Diffstat (limited to 'library') (more/less context) (ignore whitespace changes)
-rw-r--r--library/global.cpp246
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
@@ -47,44 +47,24 @@
#include <qwindowsystem_qws.h> // for qwsServer
#include <qdatetime.h>
#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"
class Emitter : public QObject {
Q_OBJECT
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&)));
}
signals:
void setDocument(const QString&);
};
@@ -107,41 +87,41 @@ StartingAppList* StartingAppList::appl = 0;
StartingAppList::StartingAppList( QObject *parent, const char* name )
:QObject( parent, 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 );
}
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();
appl->dict.insert( "QPE/Application/" + name, t );
#endif
}
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
return FALSE;
}
void StartingAppList::handleNewChannel( const QString & name )
@@ -235,45 +215,45 @@ Global::Global()
\sa addedDawg()
*/
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);
+ }
}
return *fixed_dawg;
}
/*!
@@ -294,21 +274,21 @@ const QDawg& Global::addedDawg()
\a name should not contain "/".
*/
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;
}
/*!
\overload
@@ -337,14 +317,14 @@ void Global::addWords(const QString& dictname, const QStringList& wordlist)
QStringList all = d.allWords() + wordlist;
d.createFromWords(all);
QString dawgfilename = applicationFileName("Dictionary", dictname) + ".dawg";
QFile dawgfile(dawgfilename);
if ( dawgfile.open(IO_WriteOnly) ) {
- d.write(&dawgfile);
- dawgfile.close();
+ d.write(&dawgfile);
+ dawgfile.close();
}
// #### Re-read the dawg here if we use mmap().
// #### Signal other processes to re-read.
}
@@ -360,30 +340,30 @@ void Global::addWords(const QString& dictname, const QStringList& wordlist)
QString Global::applicationFileName(const QString& appname, const QString& filename)
{
QDir d;
QString r = getenv("HOME");
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;
}
/*!
\internal
*/
void Global::createDocDir()
{
if ( !docDirCreated ) {
- docDirCreated = TRUE;
- mkdir( QPEApplication::documentDir().latin1(), 0755 );
+ docDirCreated = TRUE;
+ mkdir( QPEApplication::documentDir().latin1(), 0755 );
}
}
/*!
Displays a status \a message to the user. This usually appears
@@ -467,17 +447,17 @@ void Global::hideInputMethod()
/*!
\internal
*/
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;
}
Global::Command* Global::builtin=0;
QGuardedPtr<QWidget> *Global::running=0;
@@ -491,20 +471,20 @@ QGuardedPtr<QWidget> *Global::running=0;
/*!
\internal
*/
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 ];
}
/*!
\internal
@@ -517,18 +497,18 @@ void Global::setDocument( QWidget* receiver, const QString& document )
/*!
\internal
*/
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;
}
/*!
\internal
@@ -537,13 +517,13 @@ void Global::terminate( const AppLnk* app )
{
//if ( terminateBuiltin(app->exec()) ) return; // maybe? haven't tried this
#ifndef QT_NO_COP
QCString channel = "QPE/Application/" + app->exec().utf8();
if ( QCopChannel::isRegistered(channel) ) {
- QCopEnvelope e(channel, "quit()");
+ QCopEnvelope e(channel, "quit()");
}
#endif
}
/*!
Low-level function to run command \a c.
@@ -559,46 +539,46 @@ void Global::invoke(const QString &c)
#if !defined(QT_NO_COP)
QString ap=list[0];
// see if the application is already running
// 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
//see if it is being started
if ( StartingAppList::isStarting( ap ) ) {
// FIXME take it out for now, since it leads to a much to short showing of wait if
// some entry is clicked.
// Real cause is that ::execute is called twice for document tab. But it would need some larger changes
// 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;
}
#endif
#ifdef QT_NO_QWS_MULTIPROCESS
QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 );
#else
QStrList slist;
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;
#if !defined(QT_NO_COP)
// an attempt to show a wait...
// more logic should be used, but this will be fine for the moment...
QCopEnvelope ( "QPE/System", "busy()" );
@@ -609,14 +589,14 @@ void Global::invoke(const QString &c)
QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".dylib";
#else
QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so";
#endif
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
{
bool success = false;
int pfd [2];
if ( ::pipe ( pfd ) < 0 )
@@ -680,13 +660,13 @@ void Global::invoke(const QString &c)
Note that a better approach might be to send a QCop message to the
application's QPE/Application/\e{appname} channel.
*/
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() ) {
QCopEnvelope e( "QPE/System", "execute(QString)" );
e << c;
} else {
QCopEnvelope e( "QPE/System", "execute(QString,QString)" );
@@ -703,18 +683,18 @@ void Global::execute( const QString &c, const QString& document )
\sa stringQuote()
*/
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 += "\"";
return r;
}
/*!
@@ -724,18 +704,18 @@ QString Global::shellQuote(const QString& s)
\sa shellQuote()
*/
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 += "\"";
return r;
}
/*!
@@ -766,15 +746,17 @@ void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter)
const QList<FileSystem> &fs = storage.fileSystems();
QListIterator<FileSystem> it ( fs );
for ( ; it.current(); ++it ) {
if ( (*it)->isRemovable() ) { // let's find out if we should search on it
// 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)) {
DocLnkSet ide( path,mimefilter);
folder->appendFrom(ide);
} else {
QStringList subDirs = conf.readListEntry("subdirs",':');
@@ -784,42 +766,42 @@ void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter)
for (unsigned c = 0; c < subDirs.count();++c) {
DocLnkSet ide( path+"/"+subDirs[c], mimefilter );
folder->appendFrom(ide);
}
}
} 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);
}
}
}
QStringList Global::languageList()
{
QString lang = getenv("LANG");
QStringList langs;
langs.append(lang);
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;
}
QStringList Global::helpPath()
{
QString qpeDir = QPEApplication::qpeDir();
QStringList path;
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";
path += qpeDir + "/help/html";
/* we even put english into the en dir so try it as fallback as well for opie */
path += qpeDir + "/help/en/html";
path += qpeDir + "/docs";