summaryrefslogtreecommitdiff
path: root/core/launcher/serverinterface.cpp
blob: 9eb7f7579ab926ebabf0642a6a99376479981cc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
/**********************************************************************
** Copyright (C) 2000-2002 Trolltech AS.  All rights reserved.
**
** This file is part of the Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include "serverinterface.h"
#include "server.h"
#include "documentlist.h"

#include <qtopia/qpeapplication.h>
#include <qwindowsystem_qws.h>
#include <qgfx_qws.h>

class LayoutManager : public QObject
{
    Q_OBJECT
public:
    LayoutManager();

    void addDocked( QWidget *w, ServerInterface::DockArea placement );

private:
    struct Item {
	QWidget *w;
	ServerInterface::DockArea p;
    };

    bool eventFilter( QObject *object, QEvent *event );
    void layout();
    Item *findWidget( const QWidget *w ) const;

    QList<Item> docked;
};

LayoutManager::LayoutManager()
{
    docked.setAutoDelete( TRUE );
    qApp->desktop()->installEventFilter( this );
}

void LayoutManager::addDocked( QWidget *w, ServerInterface::DockArea placement )
{
    Item *i = new Item;
    i->w = w;
    i->p = placement;
    w->installEventFilter( this );
    docked.append(i);
    layout();
}

bool LayoutManager::eventFilter( QObject *object, QEvent *event )
{
    if ( object == qApp->desktop() ) {
	if ( event->type() == QEvent::Resize )
	    layout();
	return QObject::eventFilter( object, event );
    }

    Item *item;

    switch ( event->type() ) {
	case QEvent::Destroy:
	    item = findWidget( (QWidget *)object );
	    if ( item ) {
		docked.removeRef( item );
		layout();
	    }
	    break;

	case QEvent::Hide:
	case QEvent::Show:
	    item = findWidget( (QWidget *)object );
	    if ( item )
		layout();
	    break;

	default:
	    break;
    }

    return QObject::eventFilter( object, event );
}

void LayoutManager::layout()
{
    QRect mwr( qApp->desktop()->geometry() );
    QListIterator<Item> it( docked );
    Item *item;
    for ( ; (item = it.current()); ++it ) {
	QWidget *w = item->w;
	if ( !w->isVisible() )
	    continue;

        QSize sh = w->sizeHint();
	switch ( item->p ) {
	    case ServerInterface::Top:
                w->setGeometry( mwr.left(), mwr.top(),
                                mwr.width(), sh.height() );
		mwr.setTop( w->geometry().bottom() + 1 );
		break;
	    case ServerInterface::Bottom:
                w->setGeometry( mwr.left(), mwr.bottom() - sh.height(),
                                mwr.width(), sh.height() );
		mwr.setBottom( w->geometry().top() - 1 );
		break;
	    case ServerInterface::Left:
                w->setGeometry( mwr.left(), mwr.top(),
                                sh.width(), mwr.height() );
		mwr.setLeft( w->geometry().right() + 1 );
		break;
	    case ServerInterface::Right:
                w->setGeometry( mwr.right() - sh.width(), mwr.top(),
                                sh.width(), mwr.height() );
		mwr.setRight( w->geometry().left() - 1 );
		break;
	}
    }

#ifdef Q_WS_QWS
# if QT_VERSION < 0x030000
    QWSServer::setMaxWindowRect( qt_screen->mapToDevice(mwr,
	QSize(qt_screen->width(),qt_screen->height())) );
# else
    QWSServer::setMaxWindowRect( mwr );
# endif
#endif
}

LayoutManager::Item *LayoutManager::findWidget( const QWidget *w ) const
{
    QListIterator<Item> it( docked );
    Item *item;
    for ( ; (item = it.current()); ++it ) {
	if ( item->w == w )
	    return item;
    }

    return 0;
}

//---------------------------------------------------------------------------

/*! \class ServerInterface serverinterface.h
  \brief The ServerInterface class provides an interface for Qtopia
  custom launchers.

  The ServerInterface allows the user interface of the launcher to be
  customized to suit the device.  For a PDA style device, the default
  launcher is strongly recommended, however specialist devices may
  choose to provide a launcher better suited to the application.

  The launcher is fixed for any particular device and is not loaded
  as a plugin.  Launcher interfaces must
  be compilied into the server by editing server.pro and server.cpp.
*/

/*!
  \fn ServerInterface::createGUI()

  Implement this function to create the custom launcher UI.
*/

/*!
  \fn ServerInterface::destroyGUI()

  Implement this function to destroy the custom launcher UI.  All resources
  allocated by createGUI() must be released.
*/

/*!
  \enum ServerInterface::ApplicationState

  The ApplicationState enum type specifies the state of an application.
  The possible values are: <ul>

  <li> \c Launching - the application has been requested, but is not yet running.
  <li> \c Running - the application is running.
  <li> \c Terminated - the application has been terminated.
</ul>
*/

/*!
  \fn ServerInterface::applicationStateChanged(const QString& name, ApplicationState state)

  The application \a name has changed state to \a state.  This can be used
  to show launch notification and update a list of running applications.
*/

/*!
  \fn ServerInterface::typeAdded(const QString& type, const QString& name, const QPixmap& pixmap, const QPixmap& bgPixmap)

  An application category \a type has been added, for example "Games".
  \a name is the translated name of the category.  \a pixmap and
  \a bgPixmap are small and large icons for the new type.

  Types can be added or removed at any time, for example, when a storage
  card containing a non-standard category is inserted or removed.

  \sa typeRemoved()
*/

/*!
  \fn ServerInterface::typeRemoved(const QString& type)

  An application category \a type has been removed.

  Types can be added or removed at any time, for example, when a storage
  card containing a non-standard category is inserted or removed.

  \sa typeAdded()
*/

/*!
  \fn ServerInterface::applicationAdded(const QString& type, const AppLnk& app)

  Add an application \a app of type \a type to the launcher.

  \sa applicationRemoved()
*/

/*!
  \fn ServerInterface::applicationRemoved(const QString& type, const AppLnk& app)

  Remove an application \a app of type \a type from the launcher.

  \sa applicationAdded()
*/

/*!
  \fn ServerInterface::allApplicationsRemoved()

  Remove all applications from the launcher.
*/

/*!
  \fn const AppLnkSet &ServerInterface::appLnks()

  Returns the current set of available applications.
*/

/*!
  \fn ServerInterface::documentAdded(const DocLnk& doc)

  Add a document \a doc to the launcher.

  \sa documentRemoved()
*/

/*!
  \fn ServerInterface::documentRemoved(const DocLnk& doc)

  Remove a document \a doc to the launcher.

  \sa documentAdded()
*/

/*!
  \fn ServerInterface::documentChanged(const DocLnk& oldDoc, const DocLnk& newDoc)

  Change document properties of existing document \a oldDoc to \a newDoc.
*/

/*!
  \fn ServerInterface::allDocumentsRemoved()

  Remove all documents from the launcher.
*/

/*!
  \fn ServerInterface::storageChanged(const QList<FileSystem> &)

  A filesystem has been added or removed.
*/

/*!
  \fn ServerInterface::applicationScanningProgress(int percent)

  The system is scanning for installed applications.  \a percent
  provides the percentage of the filesystems scanned.  This function will
  always be called with \a percent equal to zero when scanning starts,
  and with \a percent equal to 100 when scanning is complete.
*/

/*!
  \fn ServerInterface::documentScanningProgress(int percent)

  The system is scanning for documents.  \a percent
  provides the percentage of the filesystems scanned.  This function will
  always be called with \a percent equal to zero when scanning starts,
  and with \a percent equal to 100 when scanning is complete.
*/

/*!
  \fn bool ServerInterface::requiresApplications() const

  Return TRUE if the custom launcher requires the server to scan for
  applications.
*/

/*!
  \fn bool ServerInterface::requiresDocuments() const

  Return TRUE if the custom launcher requires the server to scan for
  documents.
*/

/*!
  \enum ServerInterface::DockArea

  The DockArea enum type defines the areas where widgets can be docked:
  <ul>
  <li> \c Top - the top of the screen.
  <li> \c Bottom - the Bottom of the screen.
  <li> \c Left - the Left of the screen.
  <li> \c Right - the Right of the screen.
  </ul>
*/

/*!
  \fn ServerInterface::dockWidget(QWidget *w, DockArea placement)

  Docks a top-level widget \a w on a side of the screen specified by
  \a placement.  The widget is placed
  according to the order that it was docked, its sizeHint() and whether
  previously docked widgets are visible.  The desktop area available to
  QWidget::showMaximized() will exclude any visible docked widgets.

  For example, if a widget is
  docked at the bottom of the screen, its sizeHint() will define its
  height and it will use the full width of the screen.  If a widget is
  then docked to the right, its sizeHint() will define its width and
  it will be as high as possible without covering
  the widget docked at the bottom.

  This function is useful for reserving system areas such as taskbars
  and input methods that should not be covered by applications.
*/


ServerInterface::~ServerInterface()
{
}

void ServerInterface::dockWidget( QWidget *w, DockArea placement )
{
    static LayoutManager *lm = 0;

    if ( !lm )
	lm = new LayoutManager;

    lm->addDocked( w, placement );
}

const AppLnkSet& ServerInterface::appLnks()
{
    return *DocumentList::appLnkSet;
}

#include "serverinterface.moc"