summaryrefslogtreecommitdiff
path: root/library/global.cpp
authoralwin <alwin>2004-02-24 13:25:40 (UTC)
committer alwin <alwin>2004-02-24 13:25:40 (UTC)
commit6b6ba7aa1bf21647a804c7e5e7e1654112c3ee38 (patch) (unidiff)
tree6d202c80e470686ec72680e3371d15e0fb987c3b /library/global.cpp
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/global.cpp') (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
@@ -50,26 +50,6 @@
50 50
51#include <qfile.h> 51#include <qfile.h>
52 52
53namespace {
54 // checks if the storage should be searched
55 bool checkStorage(const QString &path ){ // this is a small Config replacement cause config is too limited -zecke
56 QFile file(path );
57 if(!file.open(IO_ReadOnly ) )
58 return true;
59
60 QByteArray array = file.readAll();
61 QStringList list = QStringList::split('\n', QString( array ) );
62 for(QStringList::Iterator it = list.begin(); it != list.end(); ++it ){
63 if( (*it).startsWith("check = 0" ) ){
64 return false;
65 }else if( (*it).startsWith("check = 1" ) ){
66 return true;
67 }
68 }
69 return true;
70 }
71}
72
73//#include "quickexec_p.h" 53//#include "quickexec_p.h"
74 54
75class Emitter : public QObject { 55class Emitter : public QObject {
@@ -77,11 +57,11 @@ class Emitter : public QObject {
77public: 57public:
78 Emitter( QWidget* receiver, const QString& document ) 58 Emitter( QWidget* receiver, const QString& document )
79 { 59 {
80 connect(this, SIGNAL(setDocument(const QString&)), 60 connect(this, SIGNAL(setDocument(const QString&)),
81 receiver, SLOT(setDocument(const QString&))); 61 receiver, SLOT(setDocument(const QString&)));
82 emit setDocument(document); 62 emit setDocument(document);
83 disconnect(this, SIGNAL(setDocument(const QString&)), 63 disconnect(this, SIGNAL(setDocument(const QString&)),
84 receiver, SLOT(setDocument(const QString&))); 64 receiver, SLOT(setDocument(const QString&)));
85 } 65 }
86 66
87signals: 67signals:
@@ -110,7 +90,7 @@ StartingAppList::StartingAppList( QObject *parent, const char* name )
110{ 90{
111#if QT_VERSION >= 232 && defined(QWS) 91#if QT_VERSION >= 232 && defined(QWS)
112 connect( qwsServer, SIGNAL( newChannel(const QString&)), 92 connect( qwsServer, SIGNAL( newChannel(const QString&)),
113 this, SLOT( handleNewChannel(const QString&)) ); 93 this, SLOT( handleNewChannel(const QString&)) );
114#endif 94#endif
115 dict.setAutoDelete( TRUE ); 95 dict.setAutoDelete( TRUE );
116} 96}
@@ -119,7 +99,7 @@ void StartingAppList::add( const QString& name )
119{ 99{
120#if QT_VERSION >= 232 && !defined(QT_NO_COP) 100#if QT_VERSION >= 232 && !defined(QT_NO_COP)
121 if ( !appl ) 101 if ( !appl )
122 appl = new StartingAppList; 102 appl = new StartingAppList;
123 QTime *t = new QTime; 103 QTime *t = new QTime;
124 t->start(); 104 t->start();
125 appl->dict.insert( "QPE/Application/" + name, t ); 105 appl->dict.insert( "QPE/Application/" + name, t );
@@ -130,15 +110,15 @@ bool StartingAppList::isStarting( const QString name )
130{ 110{
131#if QT_VERSION >= 232 && !defined(QT_NO_COP) 111#if QT_VERSION >= 232 && !defined(QT_NO_COP)
132 if ( appl ) { 112 if ( appl ) {
133 QTime *t = appl->dict.find( "QPE/Application/" + name ); 113 QTime *t = appl->dict.find( "QPE/Application/" + name );
134 if ( !t ) 114 if ( !t )
135 return FALSE; 115 return FALSE;
136 if ( t->elapsed() > 10000 ) { 116 if ( t->elapsed() > 10000 ) {
137 // timeout in case of crash or something 117 // timeout in case of crash or something
138 appl->dict.remove( "QPE/Application/" + name ); 118 appl->dict.remove( "QPE/Application/" + name );
139 return FALSE; 119 return FALSE;
140 } 120 }
141 return TRUE; 121 return TRUE;
142 } 122 }
143#endif 123#endif
144 return FALSE; 124 return FALSE;
@@ -238,39 +218,39 @@ Global::Global()
238const QDawg& Global::fixedDawg() 218const QDawg& Global::fixedDawg()
239{ 219{
240 if ( !fixed_dawg ) { 220 if ( !fixed_dawg ) {
241 if ( !docDirCreated ) 221 if ( !docDirCreated )
242 createDocDir(); 222 createDocDir();
243 223
244 fixed_dawg = new QDawg; 224 fixed_dawg = new QDawg;
245 QString dawgfilename = dictDir() + "/dawg"; 225 QString dawgfilename = dictDir() + "/dawg";
246 QString words_lang; 226 QString words_lang;
247 QStringList langs = Global::languageList(); 227 QStringList langs = Global::languageList();
248 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { 228 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) {
249 QString lang = *it; 229 QString lang = *it;
250 words_lang = dictDir() + "/words." + lang; 230 words_lang = dictDir() + "/words." + lang;
251 QString dawgfilename_lang = dawgfilename + "." + lang; 231 QString dawgfilename_lang = dawgfilename + "." + lang;
252 if ( QFile::exists(dawgfilename_lang) || 232 if ( QFile::exists(dawgfilename_lang) ||
253 QFile::exists(words_lang) ) { 233 QFile::exists(words_lang) ) {
254 dawgfilename = dawgfilename_lang; 234 dawgfilename = dawgfilename_lang;
255 break; 235 break;
256 } 236 }
257 } 237 }
258 QFile dawgfile(dawgfilename); 238 QFile dawgfile(dawgfilename);
259 239
260 if ( !dawgfile.exists() ) { 240 if ( !dawgfile.exists() ) {
261 QString fn = dictDir() + "/words"; 241 QString fn = dictDir() + "/words";
262 if ( QFile::exists(words_lang) ) 242 if ( QFile::exists(words_lang) )
263 fn = words_lang; 243 fn = words_lang;
264 QFile in(fn); 244 QFile in(fn);
265 if ( in.open(IO_ReadOnly) ) { 245 if ( in.open(IO_ReadOnly) ) {
266 fixed_dawg->createFromWords(&in); 246 fixed_dawg->createFromWords(&in);
267 dawgfile.open(IO_WriteOnly); 247 dawgfile.open(IO_WriteOnly);
268 fixed_dawg->write(&dawgfile); 248 fixed_dawg->write(&dawgfile);
269 dawgfile.close(); 249 dawgfile.close();
270 } 250 }
271 } else { 251 } else {
272 fixed_dawg->readFile(dawgfilename); 252 fixed_dawg->readFile(dawgfilename);
273 } 253 }
274 } 254 }
275 255
276 return *fixed_dawg; 256 return *fixed_dawg;
@@ -297,15 +277,15 @@ const QDawg& Global::dawg(const QString& name)
297{ 277{
298 createDocDir(); 278 createDocDir();
299 if ( !named_dawg ) 279 if ( !named_dawg )
300 named_dawg = new QDict<QDawg>; 280 named_dawg = new QDict<QDawg>;
301 QDawg* r = named_dawg->find(name); 281 QDawg* r = named_dawg->find(name);
302 if ( !r ) { 282 if ( !r ) {
303 r = new QDawg; 283 r = new QDawg;
304 named_dawg->insert(name,r); 284 named_dawg->insert(name,r);
305 QString dawgfilename = applicationFileName("Dictionary", name ) + ".dawg"; 285 QString dawgfilename = applicationFileName("Dictionary", name ) + ".dawg";
306 QFile dawgfile(dawgfilename); 286 QFile dawgfile(dawgfilename);
307 if ( dawgfile.open(IO_ReadOnly) ) 287 if ( dawgfile.open(IO_ReadOnly) )
308 r->readFile(dawgfilename); 288 r->readFile(dawgfilename);
309 } 289 }
310 return *r; 290 return *r;
311} 291}
@@ -340,8 +320,8 @@ void Global::addWords(const QString& dictname, const QStringList& wordlist)
340 QString dawgfilename = applicationFileName("Dictionary", dictname) + ".dawg"; 320 QString dawgfilename = applicationFileName("Dictionary", dictname) + ".dawg";
341 QFile dawgfile(dawgfilename); 321 QFile dawgfile(dawgfilename);
342 if ( dawgfile.open(IO_WriteOnly) ) { 322 if ( dawgfile.open(IO_WriteOnly) ) {
343 d.write(&dawgfile); 323 d.write(&dawgfile);
344 dawgfile.close(); 324 dawgfile.close();
345 } 325 }
346 326
347 // #### Re-read the dawg here if we use mmap(). 327 // #### Re-read the dawg here if we use mmap().
@@ -363,12 +343,12 @@ QString Global::applicationFileName(const QString& appname, const QString& filen
363 QString r = getenv("HOME"); 343 QString r = getenv("HOME");
364 r += "/Applications/"; 344 r += "/Applications/";
365 if ( !QFile::exists( r ) ) 345 if ( !QFile::exists( r ) )
366 if ( d.mkdir(r) == false ) 346 if ( d.mkdir(r) == false )
367 return QString::null; 347 return QString::null;
368 r += appname; 348 r += appname;
369 if ( !QFile::exists( r ) ) 349 if ( !QFile::exists( r ) )
370 if ( d.mkdir(r) == false ) 350 if ( d.mkdir(r) == false )
371 return QString::null; 351 return QString::null;
372 r += "/"; r += filename; 352 r += "/"; r += filename;
373 return r; 353 return r;
374} 354}
@@ -379,8 +359,8 @@ QString Global::applicationFileName(const QString& appname, const QString& filen
379void Global::createDocDir() 359void Global::createDocDir()
380{ 360{
381 if ( !docDirCreated ) { 361 if ( !docDirCreated ) {
382 docDirCreated = TRUE; 362 docDirCreated = TRUE;
383 mkdir( QPEApplication::documentDir().latin1(), 0755 ); 363 mkdir( QPEApplication::documentDir().latin1(), 0755 );
384 } 364 }
385} 365}
386 366
@@ -470,11 +450,11 @@ void Global::hideInputMethod()
470bool Global::isBuiltinCommand( const QString &name ) 450bool Global::isBuiltinCommand( const QString &name )
471{ 451{
472 if(!builtin) 452 if(!builtin)
473 return FALSE; // yes, it can happen 453 return FALSE; // yes, it can happen
474 for (int i = 0; builtin[i].file; i++) { 454 for (int i = 0; builtin[i].file; i++) {
475 if ( builtin[i].file == name ) { 455 if ( builtin[i].file == name ) {
476 return TRUE; 456 return TRUE;
477 } 457 }
478 } 458 }
479 return FALSE; 459 return FALSE;
480} 460}
@@ -494,14 +474,14 @@ QGuardedPtr<QWidget> *Global::running=0;
494void Global::setBuiltinCommands( Command* list ) 474void Global::setBuiltinCommands( Command* list )
495{ 475{
496 if ( running ) 476 if ( running )
497 delete [] running; 477 delete [] running;
498 478
499 builtin = list; 479 builtin = list;
500 int count = 0; 480 int count = 0;
501 if (!builtin) 481 if (!builtin)
502 return; 482 return;
503 while ( builtin[count].file ) 483 while ( builtin[count].file )
504 count++; 484 count++;
505 485
506 running = new QGuardedPtr<QWidget> [ count ]; 486 running = new QGuardedPtr<QWidget> [ count ];
507} 487}
@@ -520,12 +500,12 @@ void Global::setDocument( QWidget* receiver, const QString& document )
520bool Global::terminateBuiltin( const QString& n ) 500bool Global::terminateBuiltin( const QString& n )
521{ 501{
522 if (!builtin) 502 if (!builtin)
523 return FALSE; 503 return FALSE;
524 for (int i = 0; builtin[i].file; i++) { 504 for (int i = 0; builtin[i].file; i++) {
525 if ( builtin[i].file == n ) { 505 if ( builtin[i].file == n ) {
526 delete running[i]; 506 delete running[i];
527 return TRUE; 507 return TRUE;
528 } 508 }
529 } 509 }
530 return FALSE; 510 return FALSE;
531} 511}
@@ -540,7 +520,7 @@ void Global::terminate( const AppLnk* app )
540#ifndef QT_NO_COP 520#ifndef QT_NO_COP
541 QCString channel = "QPE/Application/" + app->exec().utf8(); 521 QCString channel = "QPE/Application/" + app->exec().utf8();
542 if ( QCopChannel::isRegistered(channel) ) { 522 if ( QCopChannel::isRegistered(channel) ) {
543 QCopEnvelope e(channel, "quit()"); 523 QCopEnvelope e(channel, "quit()");
544 } 524 }
545#endif 525#endif
546} 526}
@@ -562,12 +542,12 @@ void Global::invoke(const QString &c)
562 // see if the application is already running 542 // see if the application is already running
563 // XXX should lock file /tmp/qcop-msg-ap 543 // XXX should lock file /tmp/qcop-msg-ap
564 if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) { 544 if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) {
565 // If the channel is already register, the app is already running, so show it. 545 // If the channel is already register, the app is already running, so show it.
566 { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } 546 { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); }
567 547
568 //QCopEnvelope e("QPE/System", "notBusy(QString)" ); 548 //QCopEnvelope e("QPE/System", "notBusy(QString)" );
569 //e << ap; 549 //e << ap;
570 return; 550 return;
571 } 551 }
572 // XXX should unlock file /tmp/qcop-msg-ap 552 // XXX should unlock file /tmp/qcop-msg-ap
573 //see if it is being started 553 //see if it is being started
@@ -577,9 +557,9 @@ void Global::invoke(const QString &c)
577 // Real cause is that ::execute is called twice for document tab. But it would need some larger changes 557 // Real cause is that ::execute is called twice for document tab. But it would need some larger changes
578 // to fix that, and with future syncs with qtopia 1.6 it will change anyway big time since somebody there 558 // to fix that, and with future syncs with qtopia 1.6 it will change anyway big time since somebody there
579 // had the idea that an apploader belongs to the launcher ... 559 // had the idea that an apploader belongs to the launcher ...
580 //QCopEnvelope e("QPE/System", "notBusy(QString)" ); 560 //QCopEnvelope e("QPE/System", "notBusy(QString)" );
581 //e << ap; 561 //e << ap;
582 return; 562 return;
583 } 563 }
584 564
585#endif 565#endif
@@ -591,11 +571,11 @@ void Global::invoke(const QString &c)
591 QStrList slist; 571 QStrList slist;
592 unsigned int j; 572 unsigned int j;
593 for ( j = 0; j < list.count(); j++ ) 573 for ( j = 0; j < list.count(); j++ )
594 slist.append( list[j].utf8() ); 574 slist.append( list[j].utf8() );
595 575
596 const char **args = new (const char *)[slist.count() + 1]; 576 const char **args = new (const char *)[slist.count() + 1];
597 for ( j = 0; j < slist.count(); j++ ) 577 for ( j = 0; j < slist.count(); j++ )
598 args[j] = slist.at(j); 578 args[j] = slist.at(j);
599 args[j] = NULL; 579 args[j] = NULL;
600 580
601#if !defined(QT_NO_COP) 581#if !defined(QT_NO_COP)
@@ -612,8 +592,8 @@ void Global::invoke(const QString &c)
612#endif 592#endif
613 qDebug("libfile = %s", libexe.latin1() ); 593 qDebug("libfile = %s", libexe.latin1() );
614 if ( QFile::exists( libexe ) ) { 594 if ( QFile::exists( libexe ) ) {
615 qDebug("calling quickexec %s", libexe.latin1() ); 595 qDebug("calling quickexec %s", libexe.latin1() );
616 quickexecv( libexe.utf8().data(), (const char **)args ); 596 quickexecv( libexe.utf8().data(), (const char **)args );
617 } else 597 } else
618#endif 598#endif
619 { 599 {
@@ -683,7 +663,7 @@ void Global::invoke(const QString &c)
683*/ 663*/
684void Global::execute( const QString &c, const QString& document ) 664void Global::execute( const QString &c, const QString& document )
685{ 665{
686 // ask the server to do the work 666 // ask the server to do the work
687#if !defined(QT_NO_COP) 667#if !defined(QT_NO_COP)
688 if ( document.isNull() ) { 668 if ( document.isNull() ) {
689 QCopEnvelope e( "QPE/System", "execute(QString)" ); 669 QCopEnvelope e( "QPE/System", "execute(QString)" );
@@ -706,12 +686,12 @@ QString Global::shellQuote(const QString& s)
706{ 686{
707 QString r="\""; 687 QString r="\"";
708 for (int i=0; i<(int)s.length(); i++) { 688 for (int i=0; i<(int)s.length(); i++) {
709 char c = s[i].latin1(); 689 char c = s[i].latin1();
710 switch (c) { 690 switch (c) {
711 case '\\': case '"': case '$': 691 case '\\': case '"': case '$':
712 r+="\\"; 692 r+="\\";
713 } 693 }
714 r += s[i]; 694 r += s[i];
715 } 695 }
716 r += "\""; 696 r += "\"";
717 return r; 697 return r;
@@ -727,12 +707,12 @@ QString Global::stringQuote(const QString& s)
727{ 707{
728 QString r="\""; 708 QString r="\"";
729 for (int i=0; i<(int)s.length(); i++) { 709 for (int i=0; i<(int)s.length(); i++) {
730 char c = s[i].latin1(); 710 char c = s[i].latin1();
731 switch (c) { 711 switch (c) {
732 case '\\': case '"': 712 case '\\': case '"':
733 r+="\\"; 713 r+="\\";
734 } 714 }
735 r += s[i]; 715 r += s[i];
736 } 716 }
737 r += "\""; 717 r += "\"";
738 return r; 718 return r;
@@ -769,9 +749,11 @@ void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter)
769 if ( (*it)->isRemovable() ) { // let's find out if we should search on it 749 if ( (*it)->isRemovable() ) { // let's find out if we should search on it
770 // this is a candidate look at the cf and see if we should search on it 750 // this is a candidate look at the cf and see if we should search on it
771 QString path = (*it)->path(); 751 QString path = (*it)->path();
772 if( !checkStorage((*it)->path() + "/.opiestorage.cf" ) )
773 continue;
774 Config conf((*it)->path() + "/.opiestorage.cf", Config::File ); 752 Config conf((*it)->path() + "/.opiestorage.cf", Config::File );
753 conf.setGroup("main");
754 if (!conf.readBoolEntry("check",true)) {
755 continue;
756 }
775 conf.setGroup("subdirs"); 757 conf.setGroup("subdirs");
776 if (conf.readBoolEntry("wholemedia",true)) { 758 if (conf.readBoolEntry("wholemedia",true)) {
777 DocLnkSet ide( path,mimefilter); 759 DocLnkSet ide( path,mimefilter);
@@ -787,9 +769,9 @@ void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter)
787 } 769 }
788 } 770 }
789 } else if ( (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) { 771 } else if ( (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) {
790 QString path = (*it)->path() + "/Documents"; 772 QString path = (*it)->path() + "/Documents";
791 DocLnkSet ide( path, mimefilter ); 773 DocLnkSet ide( path, mimefilter );
792 folder->appendFrom(ide); 774 folder->appendFrom(ide);
793 } 775 }
794 } 776 }
795} 777}
@@ -801,10 +783,10 @@ QStringList Global::languageList()
801 langs.append(lang); 783 langs.append(lang);
802 int i = lang.find("."); 784 int i = lang.find(".");
803 if ( i > 0 ) 785 if ( i > 0 )
804 lang = lang.left( i ); 786 lang = lang.left( i );
805 i = lang.find( "_" ); 787 i = lang.find( "_" );
806 if ( i > 0 ) 788 if ( i > 0 )
807 langs.append(lang.left(i)); 789 langs.append(lang.left(i));
808 return langs; 790 return langs;
809} 791}
810 792
@@ -814,9 +796,9 @@ QStringList Global::helpPath()
814 QStringList path; 796 QStringList path;
815 QStringList langs = Global::languageList(); 797 QStringList langs = Global::languageList();
816 for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) { 798 for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) {
817 QString lang = *it; 799 QString lang = *it;
818 if ( !lang.isEmpty() ) 800 if ( !lang.isEmpty() )
819 path += qpeDir + "/help/" + lang + "/html"; 801 path += qpeDir + "/help/" + lang + "/html";
820 } 802 }
821 path += qpeDir + "/pics"; 803 path += qpeDir + "/pics";
822 path += qpeDir + "/help/html"; 804 path += qpeDir + "/help/html";