-rw-r--r-- | library/qpeapplication.cpp | 40 |
1 files changed, 11 insertions, 29 deletions
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp index 70ffec1..4dbfbd8 100644 --- a/library/qpeapplication.cpp +++ b/library/qpeapplication.cpp | |||
@@ -1,69 +1,70 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | ** $Id$ | 19 | ** $Id$ |
20 | ** | 20 | ** |
21 | **********************************************************************/ | 21 | **********************************************************************/ |
22 | #define QTOPIA_INTERNAL_LANGLIST | ||
22 | #include <stdlib.h> | 23 | #include <stdlib.h> |
23 | #include <unistd.h> | 24 | #include <unistd.h> |
24 | #include <qfile.h> | 25 | #include <qfile.h> |
25 | #ifdef Q_WS_QWS | 26 | #ifdef Q_WS_QWS |
26 | #ifndef QT_NO_COP | 27 | #ifndef QT_NO_COP |
27 | #if QT_VERSION <= 231 | 28 | #if QT_VERSION <= 231 |
28 | #define private public | 29 | #define private public |
29 | #define sendLocally processEvent | 30 | #define sendLocally processEvent |
30 | #include "qcopenvelope_qws.h" | 31 | #include "qcopenvelope_qws.h" |
31 | #undef private | 32 | #undef private |
32 | #else | 33 | #else |
33 | #include "qcopenvelope_qws.h" | 34 | #include "qcopenvelope_qws.h" |
34 | #endif | 35 | #endif |
35 | #endif | 36 | #endif |
36 | #include <qwindowsystem_qws.h> | 37 | #include <qwindowsystem_qws.h> |
37 | #endif | 38 | #endif |
38 | #include <qtextstream.h> | 39 | #include <qtextstream.h> |
39 | #include <qpalette.h> | 40 | #include <qpalette.h> |
40 | #include <qbuffer.h> | 41 | #include <qbuffer.h> |
41 | #include <qptrdict.h> | 42 | #include <qptrdict.h> |
42 | #include <qregexp.h> | 43 | #include <qregexp.h> |
43 | #include <qdir.h> | 44 | #include <qdir.h> |
44 | #include <qlabel.h> | 45 | #include <qlabel.h> |
45 | #include <qdialog.h> | 46 | #include <qdialog.h> |
46 | #include <qdragobject.h> | 47 | #include <qdragobject.h> |
47 | #include <qevent.h> | 48 | #include <qevent.h> |
48 | #include <qtooltip.h> | 49 | #include <qtooltip.h> |
49 | #include <qsignal.h> | 50 | #include <qsignal.h> |
50 | #include "qpeapplication.h" | 51 | #include "qpeapplication.h" |
51 | #include "qpestyle.h" | 52 | #include "qpestyle.h" |
52 | #if QT_VERSION >= 300 | 53 | #if QT_VERSION >= 300 |
53 | #include <qstylefactory.h> | 54 | #include <qstylefactory.h> |
54 | #else | 55 | #else |
55 | #include <qplatinumstyle.h> | 56 | #include <qplatinumstyle.h> |
56 | #include <qwindowsstyle.h> | 57 | #include <qwindowsstyle.h> |
57 | #include <qmotifstyle.h> | 58 | #include <qmotifstyle.h> |
58 | #include <qmotifplusstyle.h> | 59 | #include <qmotifplusstyle.h> |
59 | #include "lightstyle.h" | 60 | #include "lightstyle.h" |
60 | #endif | 61 | #endif |
61 | #include "global.h" | 62 | #include "global.h" |
62 | #include "resource.h" | 63 | #include "resource.h" |
63 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) | 64 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) |
64 | #include "qutfcodec.h" | 65 | #include "qutfcodec.h" |
65 | #endif | 66 | #endif |
66 | #include "config.h" | 67 | #include "config.h" |
67 | #include "network.h" | 68 | #include "network.h" |
68 | #include "fontmanager.h" | 69 | #include "fontmanager.h" |
69 | #include "power.h" | 70 | #include "power.h" |
@@ -92,112 +93,97 @@ public: | |||
92 | forceshow(FALSE), nomaximize(FALSE), qpe_main_widget(0), | 93 | forceshow(FALSE), nomaximize(FALSE), qpe_main_widget(0), |
93 | keep_running(TRUE) | 94 | keep_running(TRUE) |
94 | { | 95 | { |
95 | qcopq.setAutoDelete(TRUE); | 96 | qcopq.setAutoDelete(TRUE); |
96 | } | 97 | } |
97 | 98 | ||
98 | int presstimer; | 99 | int presstimer; |
99 | QWidget* presswidget; | 100 | QWidget* presswidget; |
100 | QPoint presspos; | 101 | QPoint presspos; |
101 | bool rightpressed; | 102 | bool rightpressed; |
102 | int kbgrabber; | 103 | int kbgrabber; |
103 | bool kbregrab; | 104 | bool kbregrab; |
104 | bool notbusysent; | 105 | bool notbusysent; |
105 | QString appName; | 106 | QString appName; |
106 | struct QCopRec { | 107 | struct QCopRec { |
107 | QCopRec(const QCString &ch, const QCString &msg, | 108 | QCopRec(const QCString &ch, const QCString &msg, |
108 | const QByteArray &d) : | 109 | const QByteArray &d) : |
109 | channel(ch), message(msg), data(d) { } | 110 | channel(ch), message(msg), data(d) { } |
110 | 111 | ||
111 | QCString channel; | 112 | QCString channel; |
112 | QCString message; | 113 | QCString message; |
113 | QByteArray data; | 114 | QByteArray data; |
114 | }; | 115 | }; |
115 | bool preloaded; | 116 | bool preloaded; |
116 | bool forceshow; | 117 | bool forceshow; |
117 | bool nomaximize; | 118 | bool nomaximize; |
118 | QWidget* qpe_main_widget; | 119 | QWidget* qpe_main_widget; |
119 | bool keep_running; | 120 | bool keep_running; |
120 | QList<QCopRec> qcopq; | 121 | QList<QCopRec> qcopq; |
121 | 122 | ||
122 | void enqueueQCop(const QCString &ch, const QCString &msg, | 123 | void enqueueQCop(const QCString &ch, const QCString &msg, |
123 | const QByteArray &data) | 124 | const QByteArray &data) |
124 | { | 125 | { |
125 | qcopq.append(new QCopRec(ch,msg,data)); | 126 | qcopq.append(new QCopRec(ch,msg,data)); |
126 | } | 127 | } |
127 | void sendQCopQ() | 128 | void sendQCopQ() |
128 | { | 129 | { |
129 | QCopRec* r; | 130 | QCopRec* r; |
130 | for (QListIterator<QCopRec> it(qcopq); (r=it.current()); ++it) | 131 | for (QListIterator<QCopRec> it(qcopq); (r=it.current()); ++it) |
131 | QCopChannel::sendLocally(r->channel,r->message,r->data); | 132 | QCopChannel::sendLocally(r->channel,r->message,r->data); |
132 | qcopq.clear(); | 133 | qcopq.clear(); |
133 | } | 134 | } |
134 | }; | 135 | }; |
135 | 136 | ||
136 | class ResourceMimeFactory : public QMimeSourceFactory { | 137 | class ResourceMimeFactory : public QMimeSourceFactory { |
137 | public: | 138 | public: |
138 | ResourceMimeFactory() | 139 | ResourceMimeFactory() |
139 | { | 140 | { |
140 | QStringList path; | 141 | setFilePath( Global::helpPath() ); |
141 | QString lang = getenv("LANG"); | ||
142 | if ( !lang.isEmpty() ) | ||
143 | path += QPEApplication::qpeDir() + "/help/" + lang + "/html"; | ||
144 | path += QPEApplication::qpeDir() + "/pics"; | ||
145 | path += QPEApplication::qpeDir() + "/help/en/html"; | ||
146 | path += QPEApplication::qpeDir() + "/docs"; | ||
147 | QString dir = QDir::current().canonicalPath(); | ||
148 | if ( dir == "/" ) | ||
149 | dir += "/docs"; | ||
150 | else { | ||
151 | path += dir + "/../pics"; | ||
152 | dir += "/../docs"; | ||
153 | path += dir; | ||
154 | } | ||
155 | setFilePath( path ); | ||
156 | setExtensionType("html","text/html;charset=UTF-8"); | 142 | setExtensionType("html","text/html;charset=UTF-8"); |
157 | } | 143 | } |
158 | 144 | ||
159 | const QMimeSource* data(const QString& abs_name) const | 145 | const QMimeSource* data(const QString& abs_name) const |
160 | { | 146 | { |
161 | const QMimeSource* r = QMimeSourceFactory::data(abs_name); | 147 | const QMimeSource* r = QMimeSourceFactory::data(abs_name); |
162 | if ( !r ) { | 148 | if ( !r ) { |
163 | int sl = abs_name.length(); | 149 | int sl = abs_name.length(); |
164 | do { | 150 | do { |
165 | sl = abs_name.findRev('/',sl-1); | 151 | sl = abs_name.findRev('/',sl-1); |
166 | QString name = sl>=0 ? abs_name.mid(sl+1) : abs_name; | 152 | QString name = sl>=0 ? abs_name.mid(sl+1) : abs_name; |
167 | int dot = name.findRev('.'); | 153 | int dot = name.findRev('.'); |
168 | if ( dot >= 0 ) | 154 | if ( dot >= 0 ) |
169 | name = name.left(dot); | 155 | name = name.left(dot); |
170 | QImage img = Resource::loadImage(name); | 156 | QImage img = Resource::loadImage(name); |
171 | if ( !img.isNull() ) | 157 | if ( !img.isNull() ) |
172 | r = new QImageDrag(img); | 158 | r = new QImageDrag(img); |
173 | } while (!r && sl>0); | 159 | } while (!r && sl>0); |
174 | } | 160 | } |
175 | return r; | 161 | return r; |
176 | } | 162 | } |
177 | }; | 163 | }; |
178 | 164 | ||
179 | static int muted=0; | 165 | static int muted=0; |
180 | 166 | ||
181 | static void setVolume(int t=0, int percent=-1) | 167 | static void setVolume(int t=0, int percent=-1) |
182 | { | 168 | { |
183 | switch (t) { | 169 | switch (t) { |
184 | case 0: { | 170 | case 0: { |
185 | Config cfg("Sound"); | 171 | Config cfg("Sound"); |
186 | cfg.setGroup("System"); | 172 | cfg.setGroup("System"); |
187 | if ( percent < 0 ) | 173 | if ( percent < 0 ) |
188 | percent = cfg.readNumEntry("Volume",50); | 174 | percent = cfg.readNumEntry("Volume",50); |
189 | int fd = 0; | 175 | int fd = 0; |
190 | if ((fd = open("/dev/mixer", O_RDWR))>=0) { | 176 | if ((fd = open("/dev/mixer", O_RDWR))>=0) { |
191 | int vol = muted ? 0 : percent; | 177 | int vol = muted ? 0 : percent; |
192 | // set both channels to same volume | 178 | // set both channels to same volume |
193 | vol |= vol << 8; | 179 | vol |= vol << 8; |
194 | ioctl(fd, MIXER_WRITE(0), &vol); | 180 | ioctl(fd, MIXER_WRITE(0), &vol); |
195 | ::close(fd); | 181 | ::close(fd); |
196 | } | 182 | } |
197 | } break; | 183 | } break; |
198 | } | 184 | } |
199 | } | 185 | } |
200 | 186 | ||
201 | int qpe_sysBrightnessSteps() | 187 | int qpe_sysBrightnessSteps() |
202 | { | 188 | { |
203 | #if defined(QT_QWS_IPAQ) | 189 | #if defined(QT_QWS_IPAQ) |
@@ -492,122 +478,118 @@ QPEApplication::QPEApplication( int& argc, char **argv, Type t ) | |||
492 | this, SLOT(systemMessage( const QCString &, const QByteArray &)) ); | 478 | this, SLOT(systemMessage( const QCString &, const QByteArray &)) ); |
493 | 479 | ||
494 | QCString channel = QCString(argv[0]); | 480 | QCString channel = QCString(argv[0]); |
495 | channel.replace(QRegExp(".*/"),""); | 481 | channel.replace(QRegExp(".*/"),""); |
496 | d->appName = channel; | 482 | d->appName = channel; |
497 | channel = "QPE/Application/" + channel; | 483 | channel = "QPE/Application/" + channel; |
498 | pidChannel = new QCopChannel( channel, this); | 484 | pidChannel = new QCopChannel( channel, this); |
499 | connect( pidChannel, SIGNAL(received(const QCString &, const QByteArray &)), | 485 | connect( pidChannel, SIGNAL(received(const QCString &, const QByteArray &)), |
500 | this, SLOT(pidMessage(const QCString &, const QByteArray &))); | 486 | this, SLOT(pidMessage(const QCString &, const QByteArray &))); |
501 | 487 | ||
502 | if ( f.isOpen() ) { | 488 | if ( f.isOpen() ) { |
503 | d->keep_running = FALSE; | 489 | d->keep_running = FALSE; |
504 | QDataStream ds(&f); | 490 | QDataStream ds(&f); |
505 | QCString channel, message; | 491 | QCString channel, message; |
506 | QByteArray data; | 492 | QByteArray data; |
507 | while(!ds.atEnd()) { | 493 | while(!ds.atEnd()) { |
508 | ds >> channel >> message >> data; | 494 | ds >> channel >> message >> data; |
509 | d->enqueueQCop(channel,message,data); | 495 | d->enqueueQCop(channel,message,data); |
510 | } | 496 | } |
511 | 497 | ||
512 | flock(f.handle(), LOCK_UN); | 498 | flock(f.handle(), LOCK_UN); |
513 | f.close(); | 499 | f.close(); |
514 | f.remove(); | 500 | f.remove(); |
515 | } | 501 | } |
516 | 502 | ||
517 | for (int a=0; a<argc; a++) { | 503 | for (int a=0; a<argc; a++) { |
518 | if ( qstrcmp(argv[a],"-preload")==0 ) { | 504 | if ( qstrcmp(argv[a],"-preload")==0 ) { |
519 | argv[a] = argv[a+1]; | 505 | argv[a] = argv[a+1]; |
520 | a++; | 506 | a++; |
521 | d->preloaded = TRUE; | 507 | d->preloaded = TRUE; |
522 | argc-=1; | 508 | argc-=1; |
523 | } else if ( qstrcmp(argv[a],"-preload-show")==0 ) { | 509 | } else if ( qstrcmp(argv[a],"-preload-show")==0 ) { |
524 | argv[a] = argv[a+1]; | 510 | argv[a] = argv[a+1]; |
525 | a++; | 511 | a++; |
526 | d->preloaded = TRUE; | 512 | d->preloaded = TRUE; |
527 | d->forceshow = TRUE; | 513 | d->forceshow = TRUE; |
528 | argc-=1; | 514 | argc-=1; |
529 | } | 515 | } |
530 | } | 516 | } |
531 | 517 | ||
532 | /* overide stored arguments */ | 518 | /* overide stored arguments */ |
533 | setArgs(argc, argv); | 519 | setArgs(argc, argv); |
534 | 520 | ||
535 | #endif | 521 | #endif |
536 | 522 | ||
537 | qwsSetDecoration( new QPEDecoration() ); | 523 | qwsSetDecoration( new QPEDecoration() ); |
538 | 524 | ||
539 | #ifndef QT_NO_TRANSLATION | 525 | #ifndef QT_NO_TRANSLATION |
540 | char *l = getenv( "LANG" ); | 526 | QStringList langs = Global::languageList(); |
541 | QString lang; | 527 | for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { |
542 | if ( l ) { | 528 | QString lang = *it; |
543 | lang = l; | ||
544 | 529 | ||
545 | /* | 530 | QTranslator * trans; |
546 | Config config("qpe"); | 531 | QString tfn; |
547 | config.setGroup( "Appearance" ); | ||
548 | lang = config.readEntry( "Language", lang ); | ||
549 | */ | ||
550 | 532 | ||
551 | QTranslator * trans = new QTranslator(this); | 533 | trans = new QTranslator(this); |
552 | QString tfn = qpeDir()+"/i18n/"+lang+"/"+d->appName+".qm"; | 534 | tfn = qpeDir()+"/i18n/"+lang+"/libqpe.qm"; |
553 | if ( trans->load( tfn )) | 535 | if ( trans->load( tfn )) |
554 | installTranslator( trans ); | 536 | installTranslator( trans ); |
555 | else | 537 | else |
556 | delete trans; | 538 | delete trans; |
557 | 539 | ||
558 | trans = new QTranslator(this); | 540 | trans = new QTranslator(this); |
559 | tfn = qpeDir()+"/i18n/"+lang+"/libqpe.qm"; | 541 | tfn = qpeDir()+"/i18n/"+lang+"/"+d->appName+".qm"; |
560 | if ( trans->load( tfn )) | 542 | if ( trans->load( tfn )) |
561 | installTranslator( trans ); | 543 | installTranslator( trans ); |
562 | else | 544 | else |
563 | delete trans; | 545 | delete trans; |
564 | 546 | ||
565 | //###language/font hack; should look it up somewhere | 547 | //###language/font hack; should look it up somewhere |
566 | if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { | 548 | if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { |
567 | QFont fn = FontManager::unicodeFont( FontManager::Proportional ); | 549 | QFont fn = FontManager::unicodeFont( FontManager::Proportional ); |
568 | setFont( fn ); | 550 | setFont( fn ); |
569 | } | 551 | } |
570 | } | 552 | } |
571 | #endif | 553 | #endif |
572 | 554 | ||
573 | applyStyle(); | 555 | applyStyle(); |
574 | 556 | ||
575 | if ( type() == GuiServer ) { | 557 | if ( type() == GuiServer ) { |
576 | setScreenSaverInterval(-1); | 558 | setScreenSaverInterval(-1); |
577 | setVolume(); | 559 | setVolume(); |
578 | QWSServer::setScreenSaver(new QPEScreenSaver); | 560 | QWSServer::setScreenSaver(new QPEScreenSaver); |
579 | } | 561 | } |
580 | 562 | ||
581 | installEventFilter( this ); | 563 | installEventFilter( this ); |
582 | 564 | ||
583 | QPEMenuToolFocusManager::initialize(); | 565 | QPEMenuToolFocusManager::initialize(); |
584 | 566 | ||
585 | #ifdef QT_NO_QWS_CURSOR | 567 | #ifdef QT_NO_QWS_CURSOR |
586 | // if we have no cursor, probably don't want tooltips | 568 | // if we have no cursor, probably don't want tooltips |
587 | QToolTip::setEnabled( FALSE ); | 569 | QToolTip::setEnabled( FALSE ); |
588 | #endif | 570 | #endif |
589 | } | 571 | } |
590 | 572 | ||
591 | static QPtrDict<void>* inputMethodDict=0; | 573 | static QPtrDict<void>* inputMethodDict=0; |
592 | static void createInputMethodDict() | 574 | static void createInputMethodDict() |
593 | { | 575 | { |
594 | if ( !inputMethodDict ) | 576 | if ( !inputMethodDict ) |
595 | inputMethodDict = new QPtrDict<void>; | 577 | inputMethodDict = new QPtrDict<void>; |
596 | } | 578 | } |
597 | 579 | ||
598 | /*! | 580 | /*! |
599 | Returns the currently set hint to the system as to whether | 581 | Returns the currently set hint to the system as to whether |
600 | \a w has any use for text input methods. | 582 | \a w has any use for text input methods. |
601 | 583 | ||
602 | \sa setInputMethodHint() | 584 | \sa setInputMethodHint() |
603 | */ | 585 | */ |
604 | QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget* w ) | 586 | QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget* w ) |
605 | { | 587 | { |
606 | if ( inputMethodDict && w ) | 588 | if ( inputMethodDict && w ) |
607 | return (InputMethodHint)(int)inputMethodDict->find(w); | 589 | return (InputMethodHint)(int)inputMethodDict->find(w); |
608 | return Normal; | 590 | return Normal; |
609 | } | 591 | } |
610 | 592 | ||
611 | /*! | 593 | /*! |
612 | \enum QPEApplication::InputMethodHint | 594 | \enum QPEApplication::InputMethodHint |
613 | 595 | ||