-rw-r--r-- | x11/libqpe-x11/qpe/qpeapplication.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/x11/libqpe-x11/qpe/qpeapplication.cpp b/x11/libqpe-x11/qpe/qpeapplication.cpp index 0a98481..0fce355 100644 --- a/x11/libqpe-x11/qpe/qpeapplication.cpp +++ b/x11/libqpe-x11/qpe/qpeapplication.cpp | |||
@@ -1,533 +1,534 @@ | |||
1 | #define QTOPIA_INTERNAL_LANGLIST | 1 | #define QTOPIA_INTERNAL_LANGLIST |
2 | 2 | ||
3 | #include <stdio.h> | 3 | #include <stdio.h> |
4 | #include <stdlib.h> | 4 | #include <stdlib.h> |
5 | #include <unistd.h> | 5 | #include <unistd.h> |
6 | #include <sys/file.h> | 6 | #include <sys/file.h> |
7 | 7 | ||
8 | 8 | ||
9 | #include <qdir.h> | 9 | #include <qdir.h> |
10 | #include <qdialog.h> | 10 | #include <qdialog.h> |
11 | #include <qdragobject.h> | 11 | #include <qdragobject.h> |
12 | #include <qevent.h> | 12 | #include <qevent.h> |
13 | #include <qlabel.h> | 13 | #include <qlabel.h> |
14 | #include <qlist.h> | 14 | #include <qlist.h> |
15 | #include <qtextstream.h> | 15 | #include <qtextstream.h> |
16 | #include <qtextcodec.h> | 16 | #include <qtextcodec.h> |
17 | #include <qpalette.h> | 17 | #include <qpalette.h> |
18 | #include <qptrdict.h> | 18 | #include <qptrdict.h> |
19 | #include <qregexp.h> | 19 | #include <qregexp.h> |
20 | #include <qtimer.h> | 20 | #include <qtimer.h> |
21 | 21 | ||
22 | #include <qpe/custom.h> | ||
22 | #include <qpe/alarmserver.h> | 23 | #include <qpe/alarmserver.h> |
23 | #include <qpe/applnk.h> | 24 | #include <qpe/applnk.h> |
24 | #include <qpe/qpemenubar.h> | 25 | #include <qpe/qpemenubar.h> |
25 | #include <qpe/textcodecinterface.h> | 26 | #include <qpe/textcodecinterface.h> |
26 | #include <qpe/imagecodecinterface.h> | 27 | #include <qpe/imagecodecinterface.h> |
27 | #include <qpe/qlibrary.h> | 28 | #include <qpe/qlibrary.h> |
28 | #include <qpe/qpestyle.h> | 29 | #include <qpe/qpestyle.h> |
29 | #include <qpe/styleinterface.h> | 30 | #include <qpe/styleinterface.h> |
30 | #include <qpe/global.h> | 31 | #include <qpe/global.h> |
31 | #include <qpe/resource.h> | 32 | #include <qpe/resource.h> |
32 | #include <qpe/config.h> | 33 | #include <qpe/config.h> |
33 | #include <qpe/network.h> | 34 | #include <qpe/network.h> |
34 | 35 | ||
35 | #include <qpe/qpeapplication.h> | 36 | #include <qpe/qpeapplication.h> |
36 | #include <qpe/timestring.h> | 37 | #include <qpe/timestring.h> |
37 | #include <qpe/qcopenvelope_qws.h> | 38 | #include <qpe/qcopenvelope_qws.h> |
38 | 39 | ||
39 | 40 | ||
40 | #include <X11/Xlib.h> | 41 | #include <X11/Xlib.h> |
41 | #include <X11/Xutil.h> | 42 | #include <X11/Xutil.h> |
42 | 43 | ||
43 | const int XKeyPress = KeyPress; | 44 | const int XKeyPress = KeyPress; |
44 | const int XKeyRelease = KeyRelease; | 45 | const int XKeyRelease = KeyRelease; |
45 | #undef KeyPress | 46 | #undef KeyPress |
46 | #undef KeyRelease | 47 | #undef KeyRelease |
47 | 48 | ||
48 | namespace { | 49 | namespace { |
49 | struct QCopRec{ | 50 | struct QCopRec{ |
50 | QCopRec( const QCString& ch, const QCString& msg, const QByteArray& ar ) | 51 | QCopRec( const QCString& ch, const QCString& msg, const QByteArray& ar ) |
51 | : channel(ch), message(msg), data(ar) { | 52 | : channel(ch), message(msg), data(ar) { |
52 | 53 | ||
53 | } | 54 | } |
54 | QCString channel; | 55 | QCString channel; |
55 | QCString message; | 56 | QCString message; |
56 | QByteArray data; | 57 | QByteArray data; |
57 | }; | 58 | }; |
58 | }; | 59 | }; |
59 | 60 | ||
60 | 61 | ||
61 | class QPEApplication::Private { | 62 | class QPEApplication::Private { |
62 | public: | 63 | public: |
63 | Private(); | 64 | Private(); |
64 | ~Private(); | 65 | ~Private(); |
65 | void enqueueQCop( const QCString& ch, const QCString& msg, | 66 | void enqueueQCop( const QCString& ch, const QCString& msg, |
66 | const QByteArray& ); | 67 | const QByteArray& ); |
67 | void sendQCopQ(); | 68 | void sendQCopQ(); |
68 | static void show_mx(QWidget* mw, bool nomaximize ); | 69 | static void show_mx(QWidget* mw, bool nomaximize ); |
69 | void show( QWidget* mw, bool nomax ); | 70 | void show( QWidget* mw, bool nomax ); |
70 | void loadTextCodecs(); | 71 | void loadTextCodecs(); |
71 | void loadImageCodecs(); | 72 | void loadImageCodecs(); |
72 | 73 | ||
73 | int kbgrabber; | 74 | int kbgrabber; |
74 | int presstimer; | 75 | int presstimer; |
75 | 76 | ||
76 | bool rightpressed : 1; | 77 | bool rightpressed : 1; |
77 | bool kbregrab : 1; | 78 | bool kbregrab : 1; |
78 | bool notbusysent : 1; | 79 | bool notbusysent : 1; |
79 | bool preloaded : 1; | 80 | bool preloaded : 1; |
80 | bool forceshow : 1; | 81 | bool forceshow : 1; |
81 | bool nomaximize : 1; | 82 | bool nomaximize : 1; |
82 | bool keep_running : 1; | 83 | bool keep_running : 1; |
83 | 84 | ||
84 | QWidget* presswidget; | 85 | QWidget* presswidget; |
85 | QPoint presspos; | 86 | QPoint presspos; |
86 | QWidget* qpe_main_widget; | 87 | QWidget* qpe_main_widget; |
87 | QString appName; | 88 | QString appName; |
88 | QString styleName; | 89 | QString styleName; |
89 | QString decorationName; | 90 | QString decorationName; |
90 | Atom wm_delete_window; | 91 | Atom wm_delete_window; |
91 | Atom wm_take_focus; | 92 | Atom wm_take_focus; |
92 | Atom wm_context_help; | 93 | Atom wm_context_help; |
93 | Atom wm_context_accept; | 94 | Atom wm_context_accept; |
94 | Atom wm_protocols; | 95 | Atom wm_protocols; |
95 | 96 | ||
96 | private: | 97 | private: |
97 | QList<QCopRec> qcopq; | 98 | QList<QCopRec> qcopq; |
98 | }; | 99 | }; |
99 | QPEApplication::Private::~Private() { | 100 | QPEApplication::Private::~Private() { |
100 | } | 101 | } |
101 | QPEApplication::Private::Private() | 102 | QPEApplication::Private::Private() |
102 | : kbgrabber(0 ), presstimer(0 ), rightpressed( FALSE ), kbregrab( FALSE ), notbusysent( FALSE ), | 103 | : kbgrabber(0 ), presstimer(0 ), rightpressed( FALSE ), kbregrab( FALSE ), notbusysent( FALSE ), |
103 | preloaded( FALSE ), forceshow( FALSE ), nomaximize( FALSE ), keep_running( TRUE ), | 104 | preloaded( FALSE ), forceshow( FALSE ), nomaximize( FALSE ), keep_running( TRUE ), |
104 | presswidget( 0 ), qpe_main_widget(0 ) { | 105 | presswidget( 0 ), qpe_main_widget(0 ) { |
105 | 106 | ||
106 | qcopq.setAutoDelete( TRUE ); | 107 | qcopq.setAutoDelete( TRUE ); |
107 | } | 108 | } |
108 | void QPEApplication::Private::enqueueQCop( const QCString& chan, const QCString& msg, | 109 | void QPEApplication::Private::enqueueQCop( const QCString& chan, const QCString& msg, |
109 | const QByteArray& ar ) { | 110 | const QByteArray& ar ) { |
110 | qcopq.append( new QCopRec(chan, msg, ar ) ); | 111 | qcopq.append( new QCopRec(chan, msg, ar ) ); |
111 | } | 112 | } |
112 | void QPEApplication::Private::sendQCopQ() { | 113 | void QPEApplication::Private::sendQCopQ() { |
113 | QCopRec* r; | 114 | QCopRec* r; |
114 | for ( r = qcopq.first(); r; r = qcopq.next() ) { | 115 | for ( r = qcopq.first(); r; r = qcopq.next() ) { |
115 | QCopChannel::sendLocally( r->channel, r->message, r->data ); | 116 | QCopChannel::sendLocally( r->channel, r->message, r->data ); |
116 | } | 117 | } |
117 | qcopq.clear(); | 118 | qcopq.clear(); |
118 | } | 119 | } |
119 | void QPEApplication::Private::show_mx(QWidget* mw, bool nomaximize ) { | 120 | void QPEApplication::Private::show_mx(QWidget* mw, bool nomaximize ) { |
120 | if (mw->layout() && mw->inherits("QDialog") ) { | 121 | if (mw->layout() && mw->inherits("QDialog") ) { |
121 | QPEApplication::showDialog( (QDialog*)mw, nomaximize ); | 122 | QPEApplication::showDialog( (QDialog*)mw, nomaximize ); |
122 | }else { | 123 | }else { |
123 | if (!nomaximize ) | 124 | if (!nomaximize ) |
124 | mw->showMaximized(); | 125 | mw->showMaximized(); |
125 | else | 126 | else |
126 | mw->show(); | 127 | mw->show(); |
127 | } | 128 | } |
128 | } | 129 | } |
129 | void QPEApplication::Private::show( QWidget* mw, bool nomax ) { | 130 | void QPEApplication::Private::show( QWidget* mw, bool nomax ) { |
130 | nomaximize = nomax; | 131 | nomaximize = nomax; |
131 | qpe_main_widget = mw; | 132 | qpe_main_widget = mw; |
132 | 133 | ||
133 | sendQCopQ(); | 134 | sendQCopQ(); |
134 | 135 | ||
135 | if ( preloaded ) { | 136 | if ( preloaded ) { |
136 | if (forceshow ) | 137 | if (forceshow ) |
137 | show_mx(mw, nomax ); | 138 | show_mx(mw, nomax ); |
138 | }else if ( keep_running ) | 139 | }else if ( keep_running ) |
139 | show_mx( mw, nomax ); | 140 | show_mx( mw, nomax ); |
140 | } | 141 | } |
141 | void QPEApplication::Private::loadTextCodecs() { | 142 | void QPEApplication::Private::loadTextCodecs() { |
142 | QString path = QPEApplication::qpeDir() + "/plugins/textcodecs"; | 143 | QString path = QPEApplication::qpeDir() + "/plugins/textcodecs"; |
143 | QDir dir( path, "lib*.so" ); | 144 | QDir dir( path, "lib*.so" ); |
144 | QStringList list = dir.entryList(); | 145 | QStringList list = dir.entryList(); |
145 | QStringList::Iterator it; | 146 | QStringList::Iterator it; |
146 | for ( it = list.begin(); it != list.end(); ++it ) { | 147 | for ( it = list.begin(); it != list.end(); ++it ) { |
147 | TextCodecInterface *iface = 0; | 148 | TextCodecInterface *iface = 0; |
148 | QLibrary *lib = new QLibrary( path + "/" + *it ); | 149 | QLibrary *lib = new QLibrary( path + "/" + *it ); |
149 | if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { | 150 | if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { |
150 | QValueList<int> mibs = iface->mibEnums(); | 151 | QValueList<int> mibs = iface->mibEnums(); |
151 | for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) { | 152 | for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) { |
152 | (void)iface->createForMib(*i); | 153 | (void)iface->createForMib(*i); |
153 | // ### it exists now; need to remember if we can delete it | 154 | // ### it exists now; need to remember if we can delete it |
154 | } | 155 | } |
155 | } | 156 | } |
156 | else { | 157 | else { |
157 | lib->unload(); | 158 | lib->unload(); |
158 | delete lib; | 159 | delete lib; |
159 | } | 160 | } |
160 | } | 161 | } |
161 | } | 162 | } |
162 | void QPEApplication::Private::loadImageCodecs() { | 163 | void QPEApplication::Private::loadImageCodecs() { |
163 | QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs"; | 164 | QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs"; |
164 | QDir dir( path, "lib*.so" ); | 165 | QDir dir( path, "lib*.so" ); |
165 | QStringList list = dir.entryList(); | 166 | QStringList list = dir.entryList(); |
166 | QStringList::Iterator it; | 167 | QStringList::Iterator it; |
167 | for ( it = list.begin(); it != list.end(); ++it ) { | 168 | for ( it = list.begin(); it != list.end(); ++it ) { |
168 | ImageCodecInterface *iface = 0; | 169 | ImageCodecInterface *iface = 0; |
169 | QLibrary *lib = new QLibrary( path + "/" + *it ); | 170 | QLibrary *lib = new QLibrary( path + "/" + *it ); |
170 | if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { | 171 | if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { |
171 | QStringList formats = iface->keys(); | 172 | QStringList formats = iface->keys(); |
172 | for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) { | 173 | for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) { |
173 | (void)iface->installIOHandler(*i); | 174 | (void)iface->installIOHandler(*i); |
174 | // ### it exists now; need to remember if we can delete it | 175 | // ### it exists now; need to remember if we can delete it |
175 | } | 176 | } |
176 | } | 177 | } |
177 | else { | 178 | else { |
178 | lib->unload(); | 179 | lib->unload(); |
179 | delete lib; | 180 | delete lib; |
180 | } | 181 | } |
181 | } | 182 | } |
182 | } | 183 | } |
183 | 184 | ||
184 | // The Help System hook | 185 | // The Help System hook |
185 | namespace { | 186 | namespace { |
186 | class ResourceMimeFactory : public QMimeSourceFactory | 187 | class ResourceMimeFactory : public QMimeSourceFactory |
187 | { | 188 | { |
188 | public: | 189 | public: |
189 | ResourceMimeFactory(); | 190 | ResourceMimeFactory(); |
190 | ~ResourceMimeFactory(); | 191 | ~ResourceMimeFactory(); |
191 | const QMimeSource* data( const QString& abs_name )const; | 192 | const QMimeSource* data( const QString& abs_name )const; |
192 | }; | 193 | }; |
193 | ResourceMimeFactory::ResourceMimeFactory() | 194 | ResourceMimeFactory::ResourceMimeFactory() |
194 | { | 195 | { |
195 | setFilePath( Global::helpPath() ); | 196 | setFilePath( Global::helpPath() ); |
196 | setExtensionType( "html", "text/html;charset=UTF-8" ); | 197 | setExtensionType( "html", "text/html;charset=UTF-8" ); |
197 | } | 198 | } |
198 | ResourceMimeFactory::~ResourceMimeFactory() { | 199 | ResourceMimeFactory::~ResourceMimeFactory() { |
199 | } | 200 | } |
200 | 201 | ||
201 | const QMimeSource* ResourceMimeFactory::data( const QString& abs_name ) const | 202 | const QMimeSource* ResourceMimeFactory::data( const QString& abs_name ) const |
202 | { | 203 | { |
203 | const QMimeSource * r = QMimeSourceFactory::data( abs_name ); | 204 | const QMimeSource * r = QMimeSourceFactory::data( abs_name ); |
204 | if ( !r ) { | 205 | if ( !r ) { |
205 | int sl = abs_name.length(); | 206 | int sl = abs_name.length(); |
206 | do { | 207 | do { |
207 | sl = abs_name.findRev( '/', sl - 1 ); | 208 | sl = abs_name.findRev( '/', sl - 1 ); |
208 | QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name; | 209 | QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name; |
209 | int dot = name.findRev( '.' ); | 210 | int dot = name.findRev( '.' ); |
210 | if ( dot >= 0 ) | 211 | if ( dot >= 0 ) |
211 | name = name.left( dot ); | 212 | name = name.left( dot ); |
212 | QImage img = Resource::loadImage( name ); | 213 | QImage img = Resource::loadImage( name ); |
213 | if ( !img.isNull() ) | 214 | if ( !img.isNull() ) |
214 | r = new QImageDrag( img ); | 215 | r = new QImageDrag( img ); |
215 | } | 216 | } |
216 | while ( !r && sl > 0 ); | 217 | while ( !r && sl > 0 ); |
217 | } | 218 | } |
218 | return r; | 219 | return r; |
219 | }; | 220 | }; |
220 | }; | 221 | }; |
221 | // QPEApplication | 222 | // QPEApplication |
222 | QPEApplication::~QPEApplication() { | 223 | QPEApplication::~QPEApplication() { |
223 | qWarning("~QPEApplication"); | 224 | qWarning("~QPEApplication"); |
224 | ungrabKeyboard(); | 225 | ungrabKeyboard(); |
225 | qWarning("UngrabKeyboard"); | 226 | qWarning("UngrabKeyboard"); |
226 | 227 | ||
227 | // delete m_sys; | 228 | // delete m_sys; |
228 | // delete m_pid; | 229 | // delete m_pid; |
229 | 230 | ||
230 | delete d; | 231 | delete d; |
231 | } | 232 | } |
232 | QPEApplication::QPEApplication(int &arg, char** argv, Type t) | 233 | QPEApplication::QPEApplication(int &arg, char** argv, Type t) |
233 | : QApplication( arg, argv, t ) { | 234 | : QApplication( arg, argv, t ) { |
234 | d = new Private; | 235 | d = new Private; |
235 | d->loadTextCodecs(); | 236 | d->loadTextCodecs(); |
236 | d->loadImageCodecs(); | 237 | d->loadImageCodecs(); |
237 | 238 | ||
238 | // Init X-Atom | 239 | // Init X-Atom |
239 | Atom *atoms[5]; | 240 | Atom *atoms[5]; |
240 | Atom atoms_re[5]; | 241 | Atom atoms_re[5]; |
241 | char* names[5]; | 242 | char* names[5]; |
242 | int n = 0; | 243 | int n = 0; |
243 | atoms[n] = &d->wm_delete_window; | 244 | atoms[n] = &d->wm_delete_window; |
244 | names[n++] = "WM_DELETE_WINDOW"; | 245 | names[n++] = "WM_DELETE_WINDOW"; |
245 | 246 | ||
246 | atoms[n] = &d->wm_take_focus; | 247 | atoms[n] = &d->wm_take_focus; |
247 | names[n++] = "WM_TAKE_FOCUS"; | 248 | names[n++] = "WM_TAKE_FOCUS"; |
248 | 249 | ||
249 | atoms[n] = &d->wm_context_help; | 250 | atoms[n] = &d->wm_context_help; |
250 | names[n++] = "_NET_WM_CONTEXT_HELP"; | 251 | names[n++] = "_NET_WM_CONTEXT_HELP"; |
251 | 252 | ||
252 | atoms[n] = &d->wm_context_accept; | 253 | atoms[n] = &d->wm_context_accept; |
253 | names[n++] = "_NET_WM_CONTEXT_ACCEPT"; | 254 | names[n++] = "_NET_WM_CONTEXT_ACCEPT"; |
254 | 255 | ||
255 | atoms[n] = &d->wm_protocols; | 256 | atoms[n] = &d->wm_protocols; |
256 | names[n++] = "WM_PROTOCOLS"; | 257 | names[n++] = "WM_PROTOCOLS"; |
257 | 258 | ||
258 | XInternAtoms( qt_xdisplay(), names, n, FALSE, atoms_re); | 259 | XInternAtoms( qt_xdisplay(), names, n, FALSE, atoms_re); |
259 | // now copy the values over to the properties | 260 | // now copy the values over to the properties |
260 | for (int i = 0; i < n; i++ ) | 261 | for (int i = 0; i < n; i++ ) |
261 | *atoms[i] = atoms_re[i]; | 262 | *atoms[i] = atoms_re[i]; |
262 | // done with X11 Stuff | 263 | // done with X11 Stuff |
263 | 264 | ||
264 | int dw = desktop()->width(); | 265 | int dw = desktop()->width(); |
265 | if ( dw < 200 ) { | 266 | if ( dw < 200 ) { |
266 | setFont( QFont( "helvetica", 8 ) ); | 267 | setFont( QFont( "helvetica", 8 ) ); |
267 | AppLnk::setSmallIconSize( 10 ); | 268 | AppLnk::setSmallIconSize( 10 ); |
268 | AppLnk::setBigIconSize( 28 ); | 269 | AppLnk::setBigIconSize( 28 ); |
269 | }else if ( dw > 600 ) { | 270 | }else if ( dw > 600 ) { |
270 | setFont( QFont( "helvetica", 12 ) ); | 271 | setFont( QFont( "helvetica", 12 ) ); |
271 | AppLnk::setSmallIconSize( 24 ); | 272 | AppLnk::setSmallIconSize( 24 ); |
272 | AppLnk::setBigIconSize( 48 ); | 273 | AppLnk::setBigIconSize( 48 ); |
273 | }else if ( dw > 200 ) { | 274 | }else if ( dw > 200 ) { |
274 | setFont( QFont( "helvetica", 10 ) ); | 275 | setFont( QFont( "helvetica", 10 ) ); |
275 | AppLnk::setSmallIconSize( 16 ); | 276 | AppLnk::setSmallIconSize( 16 ); |
276 | AppLnk::setBigIconSize( 32 ); | 277 | AppLnk::setBigIconSize( 32 ); |
277 | } | 278 | } |
278 | QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory ); | 279 | QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory ); |
279 | 280 | ||
280 | connect( this, SIGNAL( lastWindowClosed() ), this, SLOT(hideOrQuit() ) ); | 281 | connect( this, SIGNAL( lastWindowClosed() ), this, SLOT(hideOrQuit() ) ); |
281 | 282 | ||
282 | QString qcopfn( "/tmp/qcop-msg-" ); | 283 | QString qcopfn( "/tmp/qcop-msg-" ); |
283 | qcopfn += QString( argv[0] ); // append command name to the QCOP name | 284 | qcopfn += QString( argv[0] ); // append command name to the QCOP name |
284 | QFile file( qcopfn ); | 285 | QFile file( qcopfn ); |
285 | if (file.open(IO_ReadOnly ) ) { | 286 | if (file.open(IO_ReadOnly ) ) { |
286 | flock( file.handle(), LOCK_EX ); | 287 | flock( file.handle(), LOCK_EX ); |
287 | } | 288 | } |
288 | 289 | ||
289 | /* Hmmm damn we need to make the parent 0l otherwise it get's deleted | 290 | /* Hmmm damn we need to make the parent 0l otherwise it get's deleted |
290 | * past the QApplication | 291 | * past the QApplication |
291 | */ | 292 | */ |
292 | m_sys = new QCopChannel( "QPE/System", 0l); | 293 | m_sys = new QCopChannel( "QPE/System", 0l); |
293 | connect(m_sys, SIGNAL( received( const QCString&, const QByteArray& ) ), | 294 | connect(m_sys, SIGNAL( received( const QCString&, const QByteArray& ) ), |
294 | this, SLOT(systemMessage( const QCString&, const QByteArray& ) ) ); | 295 | this, SLOT(systemMessage( const QCString&, const QByteArray& ) ) ); |
295 | 296 | ||
296 | // private channel QPE/Application/appname | 297 | // private channel QPE/Application/appname |
297 | QCString channel = QCString( argv[0] ); | 298 | QCString channel = QCString( argv[0] ); |
298 | channel.replace( QRegExp( ".*/"), "" ); | 299 | channel.replace( QRegExp( ".*/"), "" ); |
299 | d->appName = channel; | 300 | d->appName = channel; |
300 | channel = "QPE/Application/"+ channel; | 301 | channel = "QPE/Application/"+ channel; |
301 | m_pid = new QCopChannel( channel, 0l ); | 302 | m_pid = new QCopChannel( channel, 0l ); |
302 | connect(m_pid, SIGNAL( received( const QCString&, const QByteArray& ) ), | 303 | connect(m_pid, SIGNAL( received( const QCString&, const QByteArray& ) ), |
303 | this, SLOT( pidMessage( const QCString&, const QByteArray& ) ) ); | 304 | this, SLOT( pidMessage( const QCString&, const QByteArray& ) ) ); |
304 | 305 | ||
305 | // read the Pre QCOP Stuff from the file | 306 | // read the Pre QCOP Stuff from the file |
306 | if ( file.isOpen() ) { | 307 | if ( file.isOpen() ) { |
307 | d->keep_running = FALSE; | 308 | d->keep_running = FALSE; |
308 | QDataStream ds( &file ); | 309 | QDataStream ds( &file ); |
309 | QCString chanel, message; | 310 | QCString chanel, message; |
310 | QByteArray data; | 311 | QByteArray data; |
311 | while (!ds.atEnd() ) { | 312 | while (!ds.atEnd() ) { |
312 | ds >> chanel >> message >> data; | 313 | ds >> chanel >> message >> data; |
313 | d->enqueueQCop( chanel, message, data ); | 314 | d->enqueueQCop( chanel, message, data ); |
314 | } | 315 | } |
315 | flock( file.handle(), LOCK_UN ); | 316 | flock( file.handle(), LOCK_UN ); |
316 | file.close(); | 317 | file.close(); |
317 | file.remove(); | 318 | file.remove(); |
318 | } | 319 | } |
319 | 320 | ||
320 | // read in some stuff from the command line | 321 | // read in some stuff from the command line |
321 | // we do not have setArgs so we need to take | 322 | // we do not have setArgs so we need to take |
322 | // care of that | 323 | // care of that |
323 | for ( int a = 0; a < arg; a++ ) { | 324 | for ( int a = 0; a < arg; a++ ) { |
324 | if ( qstrcmp( argv[a], "-preload" ) == 0 ) { | 325 | if ( qstrcmp( argv[a], "-preload" ) == 0 ) { |
325 | d->preloaded = TRUE; | 326 | d->preloaded = TRUE; |
326 | }else if ( qstrcmp( argv[a ] , "-preload-show" ) == 0 ) { | 327 | }else if ( qstrcmp( argv[a ] , "-preload-show" ) == 0 ) { |
327 | d->preloaded = TRUE; | 328 | d->preloaded = TRUE; |
328 | d->forceshow = TRUE; | 329 | d->forceshow = TRUE; |
329 | } | 330 | } |
330 | } | 331 | } |
331 | initTranslations(); | 332 | initTranslations(); |
332 | applyStyle(); | 333 | applyStyle(); |
333 | 334 | ||
334 | if ( type() == GuiServer ) | 335 | if ( type() == GuiServer ) |
335 | ; | 336 | ; |
336 | 337 | ||
337 | installEventFilter( this ); | 338 | installEventFilter( this ); |
338 | QPEMenuToolFocusManager::initialize(); | 339 | QPEMenuToolFocusManager::initialize(); |
339 | } | 340 | } |
340 | void QPEApplication::initTranslations() { | 341 | void QPEApplication::initTranslations() { |
341 | // Translations add it | 342 | // Translations add it |
342 | QStringList langs = Global::languageList(); | 343 | QStringList langs = Global::languageList(); |
343 | for ( QStringList::ConstIterator it = langs.begin(); it != langs.end(); ++it ) { | 344 | for ( QStringList::ConstIterator it = langs.begin(); it != langs.end(); ++it ) { |
344 | QString lang = *it; | 345 | QString lang = *it; |
345 | 346 | ||
346 | QTranslator * trans; | 347 | QTranslator * trans; |
347 | QString tfn; | 348 | QString tfn; |
348 | 349 | ||
349 | trans = new QTranslator( this ); | 350 | trans = new QTranslator( this ); |
350 | tfn = qpeDir() + "/i18n/" + lang + "/libqpe.qm"; | 351 | tfn = qpeDir() + "/i18n/" + lang + "/libqpe.qm"; |
351 | if ( trans->load( tfn ) ) | 352 | if ( trans->load( tfn ) ) |
352 | installTranslator( trans ); | 353 | installTranslator( trans ); |
353 | else | 354 | else |
354 | delete trans; | 355 | delete trans; |
355 | 356 | ||
356 | trans = new QTranslator( this ); | 357 | trans = new QTranslator( this ); |
357 | tfn = qpeDir() + "/i18n/" + lang + "/" + d->appName + ".qm"; | 358 | tfn = qpeDir() + "/i18n/" + lang + "/" + d->appName + ".qm"; |
358 | if ( trans->load( tfn ) ) | 359 | if ( trans->load( tfn ) ) |
359 | installTranslator( trans ); | 360 | installTranslator( trans ); |
360 | else | 361 | else |
361 | delete trans; | 362 | delete trans; |
362 | } | 363 | } |
363 | } | 364 | } |
364 | QString QPEApplication::qpeDir() { | 365 | QString QPEApplication::qpeDir() { |
365 | const char * base = getenv( "OPIEDIR" ); | 366 | const char * base = getenv( "OPIEDIR" ); |
366 | if ( base ) | 367 | if ( base ) |
367 | return QString( base ) + "/"; | 368 | return QString( base ) + "/"; |
368 | 369 | ||
369 | return QString( "../" ); | 370 | return QString( "../" ); |
370 | } | 371 | } |
371 | QString QPEApplication::documentDir() { | 372 | QString QPEApplication::documentDir() { |
372 | const char* base = getenv( "HOME"); | 373 | const char* base = getenv( "HOME"); |
373 | if ( base ) | 374 | if ( base ) |
374 | return QString( base ) + "/Documents"; | 375 | return QString( base ) + "/Documents"; |
375 | 376 | ||
376 | return QString( "../Documents" ); | 377 | return QString( "../Documents" ); |
377 | } | 378 | } |
378 | void QPEApplication::applyStyle() { | 379 | void QPEApplication::applyStyle() { |
379 | Config config( "qpe" ); | 380 | Config config( "qpe" ); |
380 | 381 | ||
381 | config.setGroup( "Appearance" ); | 382 | config.setGroup( "Appearance" ); |
382 | 383 | ||
383 | // Widget style | 384 | // Widget style |
384 | QString style = config.readEntry( "Style", "Light" ); | 385 | QString style = config.readEntry( "Style", "Light" ); |
385 | internalSetStyle( style ); | 386 | internalSetStyle( style ); |
386 | 387 | ||
387 | // Colors | 388 | // Colors |
388 | QColor bgcolor( config.readEntry( "Background", "#E5E1D5" ) ); | 389 | QColor bgcolor( config.readEntry( "Background", "#E5E1D5" ) ); |
389 | QColor btncolor( config.readEntry( "Button", "#D6CDBB" ) ); | 390 | QColor btncolor( config.readEntry( "Button", "#D6CDBB" ) ); |
390 | QPalette pal( btncolor, bgcolor ); | 391 | QPalette pal( btncolor, bgcolor ); |
391 | QString color = config.readEntry( "Highlight", "#800000" ); | 392 | QString color = config.readEntry( "Highlight", "#800000" ); |
392 | pal.setColor( QColorGroup::Highlight, QColor( color ) ); | 393 | pal.setColor( QColorGroup::Highlight, QColor( color ) ); |
393 | color = config.readEntry( "HighlightedText", "#FFFFFF" ); | 394 | color = config.readEntry( "HighlightedText", "#FFFFFF" ); |
394 | pal.setColor( QColorGroup::HighlightedText, QColor( color ) ); | 395 | pal.setColor( QColorGroup::HighlightedText, QColor( color ) ); |
395 | color = config.readEntry( "Text", "#000000" ); | 396 | color = config.readEntry( "Text", "#000000" ); |
396 | pal.setColor( QColorGroup::Text, QColor( color ) ); | 397 | pal.setColor( QColorGroup::Text, QColor( color ) ); |
397 | color = config.readEntry( "ButtonText", "#000000" ); | 398 | color = config.readEntry( "ButtonText", "#000000" ); |
398 | pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor( color ) ); | 399 | pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor( color ) ); |
399 | color = config.readEntry( "Base", "#FFFFFF" ); | 400 | color = config.readEntry( "Base", "#FFFFFF" ); |
400 | pal.setColor( QColorGroup::Base, QColor( color ) ); | 401 | pal.setColor( QColorGroup::Base, QColor( color ) ); |
401 | 402 | ||
402 | pal.setColor( QPalette::Disabled, QColorGroup::Text, | 403 | pal.setColor( QPalette::Disabled, QColorGroup::Text, |
403 | pal.color( QPalette::Active, QColorGroup::Background ).dark() ); | 404 | pal.color( QPalette::Active, QColorGroup::Background ).dark() ); |
404 | 405 | ||
405 | setPalette( pal, TRUE ); | 406 | setPalette( pal, TRUE ); |
406 | 407 | ||
407 | 408 | ||
408 | 409 | ||
409 | // Font | 410 | // Font |
410 | QString ff = config.readEntry( "FontFamily", font().family() ); | 411 | QString ff = config.readEntry( "FontFamily", font().family() ); |
411 | int fs = config.readNumEntry( "FontSize", font().pointSize() ); | 412 | int fs = config.readNumEntry( "FontSize", font().pointSize() ); |
412 | setFont( QFont(ff, fs) ); | 413 | setFont( QFont(ff, fs) ); |
413 | } | 414 | } |
414 | int QPEApplication::defaultRotation() { | 415 | int QPEApplication::defaultRotation() { |
415 | return 0; | 416 | return 0; |
416 | } | 417 | } |
417 | void QPEApplication::setDefaultRotation(int r ) { | 418 | void QPEApplication::setDefaultRotation(int r ) { |
418 | 419 | ||
419 | } | 420 | } |
420 | void QPEApplication::grabKeyboard() { | 421 | void QPEApplication::grabKeyboard() { |
421 | QPEApplication::Private * d = ( ( QPEApplication* ) qApp ) ->d; | 422 | QPEApplication::Private * d = ( ( QPEApplication* ) qApp ) ->d; |
422 | if ( qApp->type() == QApplication::GuiServer ) | 423 | if ( qApp->type() == QApplication::GuiServer ) |
423 | d->kbgrabber = 0; | 424 | d->kbgrabber = 0; |
424 | else { | 425 | else { |
425 | QCopEnvelope e( "QPE/System", "grabKeyboard(QString)" ); | 426 | QCopEnvelope e( "QPE/System", "grabKeyboard(QString)" ); |
426 | e << d->appName; | 427 | e << d->appName; |
427 | 428 | ||
428 | d->kbgrabber = 2; // me | 429 | d->kbgrabber = 2; // me |
429 | } | 430 | } |
430 | } | 431 | } |
431 | void QPEApplication::ungrabKeyboard() { | 432 | void QPEApplication::ungrabKeyboard() { |
432 | QPEApplication::Private * d = ( ( QPEApplication* ) qApp ) ->d; | 433 | QPEApplication::Private * d = ( ( QPEApplication* ) qApp ) ->d; |
433 | if ( d->kbgrabber == 2 ) { | 434 | if ( d->kbgrabber == 2 ) { |
434 | QCopEnvelope e( "QPE/System", "grabKeyboard(QString)" ); | 435 | QCopEnvelope e( "QPE/System", "grabKeyboard(QString)" ); |
435 | e << QString::null; | 436 | e << QString::null; |
436 | 437 | ||
437 | d->kbregrab = FALSE; | 438 | d->kbregrab = FALSE; |
438 | d->kbgrabber = 0; | 439 | d->kbgrabber = 0; |
439 | } | 440 | } |
440 | } | 441 | } |
441 | void QPEApplication::showMainWidget( QWidget* wid, bool b) { | 442 | void QPEApplication::showMainWidget( QWidget* wid, bool b) { |
442 | d->show(wid, b ); | 443 | d->show(wid, b ); |
443 | } | 444 | } |
444 | void QPEApplication::showMainDocumentWidget( QWidget* mw, bool m) { | 445 | void QPEApplication::showMainDocumentWidget( QWidget* mw, bool m) { |
445 | if ( mw && argc() == 2 ) | 446 | if ( mw && argc() == 2 ) |
446 | Global::setDocument( mw, QString::fromUtf8(argv()[1] ) ); | 447 | Global::setDocument( mw, QString::fromUtf8(argv()[1] ) ); |
447 | 448 | ||
448 | d->show(mw, m ); | 449 | d->show(mw, m ); |
449 | } | 450 | } |
450 | void QPEApplication::showDialog( QDialog* d, bool nomax ) { | 451 | void QPEApplication::showDialog( QDialog* d, bool nomax ) { |
451 | QSize sh = d->sizeHint(); | 452 | QSize sh = d->sizeHint(); |
452 | int w = QMAX(sh.width(),d->width()); | 453 | int w = QMAX(sh.width(),d->width()); |
453 | int h = QMAX(sh.height(),d->height()); | 454 | int h = QMAX(sh.height(),d->height()); |
454 | if ( !nomax | 455 | if ( !nomax |
455 | && ( w > qApp->desktop()->width()*3/4 | 456 | && ( w > qApp->desktop()->width()*3/4 |
456 | || h > qApp->desktop()->height()*3/4 ) ) | 457 | || h > qApp->desktop()->height()*3/4 ) ) |
457 | { | 458 | { |
458 | d->showMaximized(); | 459 | d->showMaximized(); |
459 | } else { | 460 | } else { |
460 | d->resize(w,h); | 461 | d->resize(w,h); |
461 | d->show(); | 462 | d->show(); |
462 | } | 463 | } |
463 | } | 464 | } |
464 | int QPEApplication::execDialog( QDialog* d, bool nomax) { | 465 | int QPEApplication::execDialog( QDialog* d, bool nomax) { |
465 | showDialog(d,nomax); | 466 | showDialog(d,nomax); |
466 | return d->exec(); | 467 | return d->exec(); |
467 | } | 468 | } |
468 | void QPEApplication::setKeepRunning() { | 469 | void QPEApplication::setKeepRunning() { |
469 | if ( qApp && qApp->inherits( "QPEApplication" ) ) { | 470 | if ( qApp && qApp->inherits( "QPEApplication" ) ) { |
470 | QPEApplication * qpeApp = ( QPEApplication* ) qApp; | 471 | QPEApplication * qpeApp = ( QPEApplication* ) qApp; |
471 | qpeApp->d->keep_running = TRUE; | 472 | qpeApp->d->keep_running = TRUE; |
472 | } | 473 | } |
473 | } | 474 | } |
474 | bool QPEApplication::keepRunning()const { | 475 | bool QPEApplication::keepRunning()const { |
475 | return d->keep_running; | 476 | return d->keep_running; |
476 | } | 477 | } |
477 | bool QPEApplication::keyboardGrabbed()const { | 478 | bool QPEApplication::keyboardGrabbed()const { |
478 | return d->kbgrabber; | 479 | return d->kbgrabber; |
479 | } | 480 | } |
480 | int QPEApplication::exec() { | 481 | int QPEApplication::exec() { |
481 | /* now send the QCOP stuff gotten from the file */ | 482 | /* now send the QCOP stuff gotten from the file */ |
482 | d->sendQCopQ(); | 483 | d->sendQCopQ(); |
483 | 484 | ||
484 | if ( d->keep_running ) { | 485 | if ( d->keep_running ) { |
485 | qWarning("going to exec"); | 486 | qWarning("going to exec"); |
486 | int a = QApplication::exec(); | 487 | int a = QApplication::exec(); |
487 | qWarning("left"); | 488 | qWarning("left"); |
488 | return a; | 489 | return a; |
489 | } | 490 | } |
490 | 491 | ||
491 | { | 492 | { |
492 | QCopEnvelope e( "QPE/System", "closing(QString)" ); | 493 | QCopEnvelope e( "QPE/System", "closing(QString)" ); |
493 | e << d->appName; | 494 | e << d->appName; |
494 | } | 495 | } |
495 | qWarning("processing events!"); | 496 | qWarning("processing events!"); |
496 | processEvents(); | 497 | processEvents(); |
497 | return 0; | 498 | return 0; |
498 | } | 499 | } |
499 | void QPEApplication::internalSetStyle( const QString& ) { | 500 | void QPEApplication::internalSetStyle( const QString& ) { |
500 | 501 | ||
501 | } | 502 | } |
502 | void QPEApplication::systemMessage( const QCString& chan, const QByteArray& ) { | 503 | void QPEApplication::systemMessage( const QCString& chan, const QByteArray& ) { |
503 | qWarning("QPEApplication::systemMessage( %s )", chan.data() ); | 504 | qWarning("QPEApplication::systemMessage( %s )", chan.data() ); |
504 | } | 505 | } |
505 | void QPEApplication::pidMessage( const QCString& msg, const QByteArray& ) { | 506 | void QPEApplication::pidMessage( const QCString& msg, const QByteArray& ) { |
506 | if ( msg == "flush()" ) { | 507 | if ( msg == "flush()" ) { |
507 | emit flush(); | 508 | emit flush(); |
508 | QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" ); | 509 | QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" ); |
509 | e << d->appName; | 510 | e << d->appName; |
510 | }else if ( msg == "reload()" ) { | 511 | }else if ( msg == "reload()" ) { |
511 | emit reload(); | 512 | emit reload(); |
512 | } | 513 | } |
513 | 514 | ||
514 | } | 515 | } |
515 | void QPEApplication::timerEvent( QTimerEvent* e ) { | 516 | void QPEApplication::timerEvent( QTimerEvent* e ) { |
516 | if ( e->timerId() == d->presstimer && d->presswidget ) { | 517 | if ( e->timerId() == d->presstimer && d->presswidget ) { |
517 | // Right pressed | 518 | // Right pressed |
518 | postEvent( d->presswidget, | 519 | postEvent( d->presswidget, |
519 | new QMouseEvent( QEvent::MouseButtonPress, d->presspos, | 520 | new QMouseEvent( QEvent::MouseButtonPress, d->presspos, |
520 | RightButton, LeftButton ) ); | 521 | RightButton, LeftButton ) ); |
521 | killTimer( d->presstimer ); | 522 | killTimer( d->presstimer ); |
522 | d->presstimer = 0; | 523 | d->presstimer = 0; |
523 | } | 524 | } |
524 | } | 525 | } |
525 | 526 | ||
526 | // InputMethods Hints | 527 | // InputMethods Hints |
527 | namespace { | 528 | namespace { |
528 | static QPtrDict<void>* inputMethodDict = 0; | 529 | static QPtrDict<void>* inputMethodDict = 0; |
529 | static void createInputMethodDict(){ | 530 | static void createInputMethodDict(){ |
530 | if ( !inputMethodDict ) | 531 | if ( !inputMethodDict ) |
531 | inputMethodDict = new QPtrDict<void>; | 532 | inputMethodDict = new QPtrDict<void>; |
532 | } | 533 | } |
533 | 534 | ||