-rw-r--r-- | core/launcher/mrulist.cpp | 199 |
1 files changed, 199 insertions, 0 deletions
diff --git a/core/launcher/mrulist.cpp b/core/launcher/mrulist.cpp new file mode 100644 index 0000000..4daf7d2 --- a/dev/null +++ b/core/launcher/mrulist.cpp | |||
@@ -0,0 +1,199 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of 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 | |||
21 | #include "mrulist.h" | ||
22 | |||
23 | #include <qpe/global.h> | ||
24 | #include <qpe/applnk.h> | ||
25 | #include <qpe/resource.h> | ||
26 | |||
27 | #include <qframe.h> | ||
28 | #include <qpushbutton.h> | ||
29 | #include <qtoolbutton.h> | ||
30 | #include <qpopupmenu.h> | ||
31 | #include <qpainter.h> | ||
32 | #include <qwindowsystem_qws.h> | ||
33 | |||
34 | |||
35 | QList<MRUList>*MRUList::MRUListWidgets = NULL; | ||
36 | QList<AppLnk>*MRUList::task = NULL; | ||
37 | |||
38 | |||
39 | MRUList::MRUList( QWidget *parent ) | ||
40 | : QFrame( parent ), selected(-1), oldsel(-1) | ||
41 | { | ||
42 | setBackgroundMode( PaletteButton ); | ||
43 | if (!MRUListWidgets) | ||
44 | MRUListWidgets = new QList<MRUList>; | ||
45 | if (!task) | ||
46 | task = new QList<AppLnk>; | ||
47 | MRUListWidgets->append( this ); | ||
48 | } | ||
49 | |||
50 | |||
51 | MRUList::~MRUList() | ||
52 | { | ||
53 | if (MRUListWidgets) | ||
54 | MRUListWidgets->remove( this ); | ||
55 | if (task) | ||
56 | task->setAutoDelete( TRUE ); | ||
57 | } | ||
58 | |||
59 | |||
60 | QSize MRUList::sizeHint() const | ||
61 | { | ||
62 | return QSize( frameWidth(), 16 ); | ||
63 | } | ||
64 | |||
65 | |||
66 | void MRUList::addTask( const AppLnk *appLnk ) | ||
67 | { | ||
68 | if ( !appLnk ) | ||
69 | return; | ||
70 | unsigned int i = 0; | ||
71 | |||
72 | if ( !task ) | ||
73 | return; | ||
74 | |||
75 | for ( ; i < task->count(); i++ ) { | ||
76 | AppLnk *t = task->at(i); | ||
77 | if ( t->exec() == appLnk->exec() ) { | ||
78 | if (i != 0) { | ||
79 | task->remove(); | ||
80 | task->prepend( t ); | ||
81 | } | ||
82 | for (unsigned i = 0; i < MRUListWidgets->count(); i++ ) | ||
83 | MRUListWidgets->at(i)->update(); | ||
84 | return; | ||
85 | } | ||
86 | } | ||
87 | |||
88 | AppLnk *t = new AppLnk( *appLnk ); | ||
89 | // DocLnks have an overloaded virtual function exec() | ||
90 | t->setExec( appLnk->exec() ); | ||
91 | task->prepend( t ); | ||
92 | |||
93 | if ( task->count() > 6 ) { | ||
94 | t = task->last(); | ||
95 | task->remove(); | ||
96 | Global::terminate(t); | ||
97 | delete t; | ||
98 | } | ||
99 | |||
100 | for (unsigned i = 0; i < MRUListWidgets->count(); i++ ) | ||
101 | MRUListWidgets->at(i)->update(); | ||
102 | } | ||
103 | |||
104 | bool MRUList::quitOldApps() | ||
105 | { | ||
106 | QStringList appsstarted; | ||
107 | QStringList appsrunning; | ||
108 | for ( int i=task->count()-1; i>=0; --i ) { | ||
109 | AppLnk *t = task->at(i); | ||
110 | appsstarted.append(t->exec()); | ||
111 | } | ||
112 | |||
113 | const QList<QWSWindow> &list = qwsServer->clientWindows(); | ||
114 | QWSWindow* w; | ||
115 | for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) { | ||
116 | QString app = w->client()->identity(); | ||
117 | if ( appsstarted.contains(app) && !appsrunning.contains(app) ) | ||
118 | appsrunning.append(app); | ||
119 | } | ||
120 | |||
121 | if ( appsrunning.count() > 1 ) { | ||
122 | QStringList::ConstIterator it = appsrunning.begin(); | ||
123 | ++it; // top stays running! | ||
124 | for (; it != appsrunning.end(); it++) { | ||
125 | for ( int i=task->count()-1; i>=0; --i ) { | ||
126 | AppLnk *t = task->at(i); | ||
127 | if ( t->exec() == *it ) | ||
128 | Global::terminate(t); | ||
129 | } | ||
130 | } | ||
131 | return TRUE; | ||
132 | } else { | ||
133 | return FALSE; | ||
134 | } | ||
135 | } | ||
136 | |||
137 | |||
138 | void MRUList::mousePressEvent(QMouseEvent *e) | ||
139 | { | ||
140 | selected = 0; | ||
141 | int x=0; | ||
142 | QListIterator<AppLnk> it( *task ); | ||
143 | for ( ; it.current(); ++it,++selected,x+=15 ) { | ||
144 | if ( x + 15 <= width() ) { | ||
145 | if ( e->x() >= x && e->x() < x+15 ) { | ||
146 | if ( selected < (int)task->count() ) { | ||
147 | repaint(FALSE); | ||
148 | return; | ||
149 | } | ||
150 | } | ||
151 | } else { | ||
152 | break; | ||
153 | } | ||
154 | } | ||
155 | selected = -1; | ||
156 | repaint( FALSE ); | ||
157 | } | ||
158 | |||
159 | |||
160 | void MRUList::mouseReleaseEvent(QMouseEvent *) | ||
161 | { | ||
162 | if ( selected >= 0 ) { | ||
163 | if ( parentWidget() ) | ||
164 | if ( parentWidget()->isA( "QPopupMenu" ) ) | ||
165 | parentWidget()->hide(); | ||
166 | Global::execute( task->at(selected)->exec() ); | ||
167 | selected = -1; | ||
168 | oldsel = -1; | ||
169 | update(); | ||
170 | } | ||
171 | } | ||
172 | |||
173 | |||
174 | void MRUList::paintEvent( QPaintEvent * ) | ||
175 | { | ||
176 | QPainter p( this ); | ||
177 | AppLnk *t; | ||
178 | int x = 0; | ||
179 | int y = (height() - 14) / 2; | ||
180 | int i = 0; | ||
181 | |||
182 | p.fillRect( 0, 0, width(), height(), colorGroup().background() ); | ||
183 | |||
184 | if ( task ) { | ||
185 | QListIterator<AppLnk> it( *task ); | ||
186 | for ( ; it.current(); i++, ++it ) { | ||
187 | if ( x + 15 <= width() ) { | ||
188 | t = it.current(); | ||
189 | if ( (int)i == selected ) | ||
190 | p.fillRect( x, y, 15, t->pixmap().height()+1, colorGroup().highlight() ); | ||
191 | else if ( (int)i == oldsel ) | ||
192 | p.eraseRect( x, y, 15, t->pixmap().height()+1 ); | ||
193 | p.drawPixmap( x, y, t->pixmap() ); | ||
194 | x += 15; | ||
195 | } | ||
196 | } | ||
197 | } | ||
198 | } | ||
199 | |||