summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (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
@@ -49,40 +49,20 @@
#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&);
@@ -109,18 +89,18 @@ 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
@@ -129,17 +109,17 @@ void StartingAppList::add( const QString& name )
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;
}
@@ -237,41 +217,41 @@ Global::Global()
*/
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;
}
@@ -296,17 +276,17 @@ const QDawg& Global::addedDawg()
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;
}
@@ -339,10 +319,10 @@ void Global::addWords(const QString& dictname, const QStringList& wordlist)
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().
@@ -362,14 +342,14 @@ QString Global::applicationFileName(const QString& appname, const QString& filen
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;
}
@@ -378,10 +358,10 @@ QString Global::applicationFileName(const QString& appname, const QString& filen
*/
void Global::createDocDir()
{
if ( !docDirCreated ) {
- docDirCreated = TRUE;
- mkdir( QPEApplication::documentDir().latin1(), 0755 );
+ docDirCreated = TRUE;
+ mkdir( QPEApplication::documentDir().latin1(), 0755 );
}
}
@@ -469,13 +449,13 @@ void Global::hideInputMethod()
*/
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;
}
@@ -493,16 +473,16 @@ QGuardedPtr<QWidget> *Global::running=0;
*/
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 ];
}
@@ -519,14 +499,14 @@ void Global::setDocument( QWidget* receiver, const QString& document )
*/
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;
}
@@ -539,9 +519,9 @@ void Global::terminate( const AppLnk* app )
#ifndef QT_NO_COP
QCString channel = "QPE/Application/" + app->exec().utf8();
if ( QCopChannel::isRegistered(channel) ) {
- QCopEnvelope e(channel, "quit()");
+ QCopEnvelope e(channel, "quit()");
}
#endif
}
@@ -561,14 +541,14 @@ void Global::invoke(const QString &c)
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 ) ) {
@@ -576,11 +556,11 @@ void Global::invoke(const QString &c)
// 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
@@ -590,13 +570,13 @@ void Global::invoke(const QString &c)
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...
@@ -611,10 +591,10 @@ void Global::invoke(const QString &c)
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;
@@ -682,9 +662,9 @@ void Global::invoke(const QString &c)
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;
@@ -705,14 +685,14 @@ void Global::execute( const QString &c, const QString& document )
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;
}
@@ -726,14 +706,14 @@ QString Global::shellQuote(const QString& s)
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;
}
@@ -768,11 +748,13 @@ void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter)
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);
@@ -786,11 +768,11 @@ void Global::findDocuments(DocLnkSet* folder, const QString &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);
}
}
}
@@ -800,12 +782,12 @@ QStringList Global::languageList()
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()
@@ -813,11 +795,11 @@ 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 */