summaryrefslogtreecommitdiff
path: root/core/launcher/serverinterface.cpp
Unidiff
Diffstat (limited to 'core/launcher/serverinterface.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/serverinterface.cpp372
1 files changed, 372 insertions, 0 deletions
diff --git a/core/launcher/serverinterface.cpp b/core/launcher/serverinterface.cpp
new file mode 100644
index 0000000..7002243
--- a/dev/null
+++ b/core/launcher/serverinterface.cpp
@@ -0,0 +1,372 @@
1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3**
4** This file is part of the Qtopia Environment.
5**
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
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
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.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "serverinterface.h"
21#include "server.h"
22#include "documentlist.h"
23
24#include <qtopia/qpeapplication.h>
25#include <qwindowsystem_qws.h>
26#include <qgfx_qws.h>
27
28class LayoutManager : public QObject
29{
30 Q_OBJECT
31public:
32 LayoutManager();
33
34 void addDocked( QWidget *w, ServerInterface::DockArea placement );
35
36private:
37 struct Item {
38 QWidget *w;
39 ServerInterface::DockArea p;
40 };
41
42 bool eventFilter( QObject *object, QEvent *event );
43 void layout();
44 Item *findWidget( const QWidget *w ) const;
45
46 QList<Item> docked;
47};
48
49LayoutManager::LayoutManager()
50{
51 docked.setAutoDelete( TRUE );
52 qApp->desktop()->installEventFilter( this );
53}
54
55void LayoutManager::addDocked( QWidget *w, ServerInterface::DockArea placement )
56{
57 Item *i = new Item;
58 i->w = w;
59 i->p = placement;
60 w->installEventFilter( this );
61 docked.append(i);
62 layout();
63}
64
65bool LayoutManager::eventFilter( QObject *object, QEvent *event )
66{
67 if ( object == qApp->desktop() ) {
68 if ( event->type() == QEvent::Resize )
69 layout();
70 return QObject::eventFilter( object, event );
71 }
72
73 Item *item;
74
75 switch ( event->type() ) {
76 case QEvent::Destroy:
77 item = findWidget( (QWidget *)object );
78 if ( item ) {
79 docked.removeRef( item );
80 layout();
81 }
82 break;
83
84 case QEvent::Hide:
85 case QEvent::Show:
86 item = findWidget( (QWidget *)object );
87 if ( item )
88 layout();
89 break;
90
91 default:
92 break;
93 }
94
95 return QObject::eventFilter( object, event );
96}
97
98void LayoutManager::layout()
99{
100 QRect mwr( qApp->desktop()->geometry() );
101 QListIterator<Item> it( docked );
102 Item *item;
103 for ( ; (item = it.current()); ++it ) {
104 QWidget *w = item->w;
105 if ( !w->isVisible() )
106 continue;
107 switch ( item->p ) {
108 case ServerInterface::Top:
109 w->resize( mwr.width(), w->sizeHint().height() );
110 w->move( mwr.topLeft() );
111 mwr.setTop( w->geometry().bottom() + 1 );
112 break;
113 case ServerInterface::Bottom:
114 w->resize( mwr.width(), w->sizeHint().height() );
115 w->move( mwr.left(), mwr.bottom()-w->height()+1 );
116 mwr.setBottom( w->geometry().top() - 1 );
117 break;
118 case ServerInterface::Left:
119 w->resize( w->sizeHint().width(), mwr.height() );
120 w->move( mwr.topLeft() );
121 mwr.setLeft( w->geometry().right() + 1 );
122 break;
123 case ServerInterface::Right:
124 w->resize( w->sizeHint().width(), mwr.height() );
125 w->move( mwr.right()-w->width()+1, mwr.top() );
126 mwr.setRight( w->geometry().left() - 1 );
127 break;
128 }
129 }
130
131#ifdef Q_WS_QWS
132# if QT_VERSION < 0x030000
133 QWSServer::setMaxWindowRect( qt_screen->mapToDevice(mwr,
134 QSize(qt_screen->width(),qt_screen->height())) );
135# else
136 QWSServer::setMaxWindowRect( mwr );
137# endif
138#endif
139}
140
141LayoutManager::Item *LayoutManager::findWidget( const QWidget *w ) const
142{
143 QListIterator<Item> it( docked );
144 Item *item;
145 for ( ; (item = it.current()); ++it ) {
146 if ( item->w == w )
147 return item;
148 }
149
150 return 0;
151}
152
153//---------------------------------------------------------------------------
154
155/*! \class ServerInterface serverinterface.h
156 \brief The ServerInterface class provides an interface for Qtopia
157 custom launchers.
158
159 The ServerInterface allows the user interface of the launcher to be
160 customized to suit the device. For a PDA style device, the default
161 launcher is strongly recommended, however specialist devices may
162 choose to provide a launcher better suited to the application.
163
164 The launcher is fixed for any particular device and is not loaded
165 as a plugin. Launcher interfaces must
166 be compilied into the server by editing server.pro and server.cpp.
167*/
168
169/*!
170 \fn ServerInterface::createGUI()
171
172 Implement this function to create the custom launcher UI.
173*/
174
175/*!
176 \fn ServerInterface::destroyGUI()
177
178 Implement this function to destroy the custom launcher UI. All resources
179 allocated by createGUI() must be released.
180*/
181
182/*!
183 \enum ServerInterface::ApplicationState
184
185 The ApplicationState enum type specifies the state of an application.
186 The possible values are: <ul>
187
188 <li> \c Launching - the application has been requested, but is not yet running.
189 <li> \c Running - the application is running.
190 <li> \c Terminated - the application has been terminated.
191</ul>
192*/
193
194/*!
195 \fn ServerInterface::applicationStateChanged(const QString& name, ApplicationState state)
196
197 The application \a name has changed state to \a state. This can be used
198 to show launch notification and update a list of running applications.
199*/
200
201/*!
202 \fn ServerInterface::typeAdded(const QString& type, const QString& name, const QPixmap& pixmap, const QPixmap& bgPixmap)
203
204 An application category \a type has been added, for example "Games".
205 \a name is the translated name of the category. \a pixmap and
206 \a bgPixmap are small and large icons for the new type.
207
208 Types can be added or removed at any time, for example, when a storage
209 card containing a non-standard category is inserted or removed.
210
211 \sa typeRemoved()
212*/
213
214/*!
215 \fn ServerInterface::typeRemoved(const QString& type)
216
217 An application category \a type has been removed.
218
219 Types can be added or removed at any time, for example, when a storage
220 card containing a non-standard category is inserted or removed.
221
222 \sa typeAdded()
223*/
224
225/*!
226 \fn ServerInterface::applicationAdded(const QString& type, const AppLnk& app)
227
228 Add an application \a app of type \a type to the launcher.
229
230 \sa applicationRemoved()
231*/
232
233/*!
234 \fn ServerInterface::applicationRemoved(const QString& type, const AppLnk& app)
235
236 Remove an application \a app of type \a type from the launcher.
237
238 \sa applicationAdded()
239*/
240
241/*!
242 \fn ServerInterface::allApplicationsRemoved()
243
244 Remove all applications from the launcher.
245*/
246
247/*!
248 \fn const AppLnkSet &ServerInterface::appLnks()
249
250 Returns the current set of available applications.
251*/
252
253/*!
254 \fn ServerInterface::documentAdded(const DocLnk& doc)
255
256 Add a document \a doc to the launcher.
257
258 \sa documentRemoved()
259*/
260
261/*!
262 \fn ServerInterface::documentRemoved(const DocLnk& doc)
263
264 Remove a document \a doc to the launcher.
265
266 \sa documentAdded()
267*/
268
269/*!
270 \fn ServerInterface::documentChanged(const DocLnk& oldDoc, const DocLnk& newDoc)
271
272 Change document properties of existing document \a oldDoc to \a newDoc.
273*/
274
275/*!
276 \fn ServerInterface::allDocumentsRemoved()
277
278 Remove all documents from the launcher.
279*/
280
281/*!
282 \fn ServerInterface::storageChanged(const QList<FileSystem> &)
283
284 A filesystem has been added or removed.
285*/
286
287/*!
288 \fn ServerInterface::applicationScanningProgress(int percent)
289
290 The system is scanning for installed applications. \a percent
291 provides the percentage of the filesystems scanned. This function will
292 always be called with \a percent equal to zero when scanning starts,
293 and with \a percent equal to 100 when scanning is complete.
294*/
295
296/*!
297 \fn ServerInterface::documentScanningProgress(int percent)
298
299 The system is scanning for documents. \a percent
300 provides the percentage of the filesystems scanned. This function will
301 always be called with \a percent equal to zero when scanning starts,
302 and with \a percent equal to 100 when scanning is complete.
303*/
304
305/*!
306 \fn bool ServerInterface::requiresApplications() const
307
308 Return TRUE if the custom launcher requires the server to scan for
309 applications.
310*/
311
312/*!
313 \fn bool ServerInterface::requiresDocuments() const
314
315 Return TRUE if the custom launcher requires the server to scan for
316 documents.
317*/
318
319/*!
320 \enum ServerInterface::DockArea
321
322 The DockArea enum type defines the areas where widgets can be docked:
323 <ul>
324 <li> \c Top - the top of the screen.
325 <li> \c Bottom - the Bottom of the screen.
326 <li> \c Left - the Left of the screen.
327 <li> \c Right - the Right of the screen.
328 </ul>
329*/
330
331/*!
332 \fn ServerInterface::dockWidget(QWidget *w, DockArea placement)
333
334 Docks a top-level widget \a w on a side of the screen specified by
335 \a placement. The widget is placed
336 according to the order that it was docked, its sizeHint() and whether
337 previously docked widgets are visible. The desktop area available to
338 QWidget::showMaximized() will exclude any visible docked widgets.
339
340 For example, if a widget is
341 docked at the bottom of the screen, its sizeHint() will define its
342 height and it will use the full width of the screen. If a widget is
343 then docked to the right, its sizeHint() will define its width and
344 it will be as high as possible without covering
345 the widget docked at the bottom.
346
347 This function is useful for reserving system areas such as taskbars
348 and input methods that should not be covered by applications.
349*/
350
351
352ServerInterface::~ServerInterface()
353{
354}
355
356void ServerInterface::dockWidget( QWidget *w, DockArea placement )
357{
358 static LayoutManager *lm = 0;
359
360 if ( !lm )
361 lm = new LayoutManager;
362
363 lm->addDocked( w, placement );
364}
365
366const AppLnkSet& ServerInterface::appLnks()
367{
368 return *DocumentList::appLnkSet;
369}
370
371#include "serverinterface.moc"
372