summaryrefslogtreecommitdiff
authorharlekin <harlekin>2003-11-30 17:58:02 (UTC)
committer harlekin <harlekin>2003-11-30 17:58:02 (UTC)
commita7e786be4f9545a881015de8ba8a124a62f0f891 (patch) (unidiff)
tree6d4c5d6e0f83cdc9aea5ab4083ec1fe0a261d6ac
parentf50b547e2660c26b2c84512c2cb3d83f2ddf147c (diff)
downloadopie-a7e786be4f9545a881015de8ba8a124a62f0f891.zip
opie-a7e786be4f9545a881015de8ba8a124a62f0f891.tar.gz
opie-a7e786be4f9545a881015de8ba8a124a62f0f891.tar.bz2
startmenu was further developed in branch
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/startmenu.cpp729
-rw-r--r--core/launcher/startmenu.h201
2 files changed, 498 insertions, 432 deletions
diff --git a/core/launcher/startmenu.cpp b/core/launcher/startmenu.cpp
index 08ae885..f17c7f8 100644
--- a/core/launcher/startmenu.cpp
+++ b/core/launcher/startmenu.cpp
@@ -1,337 +1,392 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the 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**********************************************************************/ 19**********************************************************************/
20 20
21#define INCLUDE_MENUITEM_DEF 21// TODO. During startup
22 22// Launcher::typeAdded
23#include "startmenu.h" 23// is called for each new tab and calls then each time the refresh of startmenu
24 24// suboptimal
25#include <qtopia/qpeapplication.h> 25
26#include <qtopia/config.h> 26#define INCLUDE_MENUITEM_DEF
27#include <qtopia/applnk.h> 27
28#include <qtopia/global.h> 28#include "startmenu.h"
29#include <qtopia/resource.h> 29
30#include <qtopia/mimetype.h> 30#include <qtopia/qpeapplication.h>
31#include <qtopia/qlibrary.h> 31#include <qtopia/config.h>
32 32#include <qtopia/applnk.h>
33#include <qdict.h> 33#include <qtopia/global.h>
34#include <qdir.h> 34#include <qtopia/resource.h>
35#include <qpainter.h> 35#include <qtopia/mimetype.h>
36 36#include <qtopia/qlibrary.h>
37#include <stdlib.h> 37
38 38#include <qdict.h>
39 39#include <qdir.h>
40void StartPopupMenu::keyPressEvent( QKeyEvent *e ) 40//#include <qpainter.h>
41{ 41
42 if ( e->key() == Key_F33 || e->key() == Key_Space ) { 42//#include <stdlib.h>
43 // "OK" button, little hacky 43
44 QKeyEvent ke(QEvent::KeyPress, Key_Enter, 13, 0); 44
45 QPopupMenu::keyPressEvent( &ke ); 45#define APPLNK_ID_OFFSET 250
46 } else { 46#define NO_ID -1
47 QPopupMenu::keyPressEvent( e ); 47
48 } 48
49} 49void StartPopupMenu::keyPressEvent( QKeyEvent *e )
50 50{
51//--------------------------------------------------------------------------- 51 if ( e->key() == Key_F33 || e->key() == Key_Space ) {
52 52 // "OK" button, little hacky
53StartMenu::StartMenu(QWidget *parent) : QLabel( parent ) 53 QKeyEvent ke(QEvent::KeyPress, Key_Enter, 13, 0);
54{ 54 QPopupMenu::keyPressEvent( &ke );
55 startButtonPixmap = "go"; // No tr 55 } else {
56 56 QPopupMenu::keyPressEvent( e );
57 int sz = AppLnk::smallIconSize()+3; 57 }
58 QPixmap pm; 58}
59 pm.convertFromImage(Resource::loadImage(startButtonPixmap).smoothScale(sz,sz)); 59
60 setPixmap(pm); 60//---------------------------------------------------------------------------
61 setFocusPolicy( NoFocus ); 61
62 62StartMenu::StartMenu(QWidget *parent) : QLabel( parent )
63 launchMenu = 0; 63{
64 refreshMenu(); 64 startButtonPixmap = "go"; // No tr
65} 65
66 66 int sz = AppLnk::smallIconSize()+3;
67 67 QPixmap pm;
68void StartMenu::mousePressEvent( QMouseEvent * ) 68 pm.convertFromImage(Resource::loadImage( startButtonPixmap).smoothScale( sz,sz) );
69{ 69 setPixmap(pm);
70 launch(); 70 setFocusPolicy( NoFocus );
71} 71
72 72 useWidePopupMenu = true;
73 73 launchMenu = 0;
74StartMenu::~StartMenu() 74 refreshMenu();
75{ 75}
76 clearApplets(); 76
77} 77
78 78void StartMenu::mousePressEvent( QMouseEvent * )
79void StartMenu::createMenu() 79{
80{ 80 launch();
81 clearApplets(); 81}
82 delete launchMenu; 82
83 83
84 launchMenu = new StartPopupMenu( this ); 84StartMenu::~StartMenu()
85 loadMenu( launchMenu ); 85{
86 loadApplets(); 86 clearApplets();
87 87}
88 bool result = nother || ntabs || m_applets.count(); 88
89 if ( result ) 89void StartMenu::createMenu()
90 connect( launchMenu, SIGNAL(activated(int)), SLOT(itemSelected(int)) ); 90{
91 91 clearApplets();
92} 92 delete launchMenu;
93 93
94void StartMenu::refreshMenu() 94 launchMenu = new StartPopupMenu( this );
95{ 95 loadMenu( launchMenu );
96 Config cfg("Taskbar"); 96 loadApplets();
97 cfg.setGroup("Menu"); 97
98 bool ltabs = cfg.readBoolEntry("LauncherTabs",TRUE); 98 bool result = currentItem || menuApplets.count();
99 bool lot = cfg.readBoolEntry("LauncherOther",TRUE); 99 if ( result )
100 bool lt = ltabs || lot; 100 connect( launchMenu, SIGNAL(activated(int)), SLOT(itemSelected(int)) );
101 if ( launchMenu && !lt ) 101}
102 return; // nothing to do 102
103 103void StartMenu::refreshMenu()
104 if ( launchMenu ) { 104{
105 int i; 105 Config cfg( "StartMenu" );
106 /* find the first entry we want to remove */ 106 cfg.setGroup( "Menu" );
107 for (i=0; i<(int)launchMenu->count(); i++) { 107 bool ltabs = cfg.readBoolEntry( "LauncherTabs", TRUE );
108 QMenuItem* item = launchMenu->findItem(launchMenu->idAt(i)); 108 bool lot = cfg.readBoolEntry( "LauncherOther", TRUE );
109 if ( item && item->id() >= 0 && item->id() < ntabs ) { 109 useWidePopupMenu = cfg.readBoolEntry( "LauncherSubPopup", TRUE );
110 break; 110
111 } 111 if ( launchMenu && !(ltabs || lot) ) return; // nothing to do
112 if ( item && item->isSeparator() ) { 112
113 i++; 113 createMenu();
114 break; 114}
115 } 115
116 } 116void StartMenu::itemSelected( int id )
117 /* remove them */ 117{
118 while (i<(int)launchMenu->count()) 118 if ( id == NO_ID ) return;
119 launchMenu->removeItemAt(i); 119
120 loadMenu(launchMenu); 120 if ( id < 0 ) {
121 addApplets(launchMenu); 121 MenuApplet *applet = menuApplets.find( id );
122 } else { 122 if ( applet ) {
123 createMenu(); 123 applet->iface->activated();
124 } 124 }
125} 125 } else if ( id >= APPLNK_ID_OFFSET ) {
126 126 AppLnk * appLnk = appLnks.find( id );
127void StartMenu::itemSelected( int id ) 127 if ( appLnk ) {
128{ 128 appLnk->execute();
129 if ( id >= 0 && id < ntabs ) { 129 }
130 emit tabSelected(tabs[id]); 130 } else {
131 } else if ( id >= 20 && id < 20+nother ) { 131 QString *tabName = tabNames.find( id );
132 other.at(id-20)->execute(); 132 if ( tabName ) {
133 }else { 133 emit tabSelected( *tabName );
134 MenuApplet *applet = m_applets.find ( id ); 134 }
135 if ( applet ) { 135 }
136 qWarning("activated"); 136}
137 applet-> iface-> activated(); 137
138 } 138void StartMenu::createAppEntry( QPopupMenu *menu, QDir dir, QString file )
139 } 139{
140} 140 if ( file.right(8) == ".desktop" ) {
141 141 AppLnk* applnk = new AppLnk( dir.path() + "/" + file );
142bool StartMenu::loadMenu( QPopupMenu *menu ) 142 if ( !applnk->isValid() ) {
143{ 143 delete applnk;
144 Config cfg("Taskbar"); 144 return;
145 cfg.setGroup("Menu"); 145 }
146 146
147 bool ltabs = cfg.readBoolEntry("LauncherTabs",TRUE); 147 if ( applnk->type() == "Separator" ) { // No tr
148 bool lot = cfg.readBoolEntry("LauncherOther",TRUE); 148 menu->insertSeparator();
149 bool sepfirst = !ltabs && !lot; 149 delete applnk;
150 150 } else {
151 tabs.clear(); 151 QPixmap test;
152 other.setAutoDelete(TRUE); 152 test.convertFromImage(
153 other.clear(); 153 Resource::loadImage( applnk->icon() ).smoothScale(
154 ntabs = 0; 154 AppLnk::smallIconSize(), AppLnk::smallIconSize() ), 0 );
155 nother = 0; 155
156 156 menu->insertItem( test, applnk->name(),
157 bool f=TRUE; 157 currentItem + APPLNK_ID_OFFSET );
158 if ( ltabs || lot ) { 158 appLnks.insert( currentItem + APPLNK_ID_OFFSET, applnk );
159 QDir dir( MimeType::appsFolderName(), QString::null, QDir::Name ); 159 currentItem++;
160 for (int i=0; i<(int)dir.count(); i++) { 160 }
161 QString d = dir[i]; 161 }
162 Config cfg(dir.path()+"/"+d+"/.directory",Config::File); 162
163 if ( cfg.isValid() ) { 163}
164 QString nm = cfg.readEntry("Name"); 164
165 QString ic = cfg.readEntry("Icon"); 165void StartMenu::createDirEntry( QPopupMenu *menu, QDir dir, QString file, bool lot )
166 if ( !!nm && !!ic ) { 166{
167 tabs.append(d); 167 // do some sanity checks and collect information
168 menu->insertItem( Resource::loadIconSet(ic), nm, ntabs++ ); 168
169 } 169 if ( file == "." || file == ".." ) return;
170 } else if ( lot && d.right(8)==".desktop") { 170
171 AppLnk* applnk = new AppLnk(dir.path()+"/"+d); 171 Config cfg( dir.path() + "/" + file + "/.directory", Config::File );
172 if ( applnk->isValid() ) { 172 if ( !cfg.isValid() ) return;
173 if ( applnk->type() == "Separator" ) { // No tr 173
174 if ( lot ) { 174 QString name = cfg.readEntry( "Name" );
175 menu->insertSeparator(); 175 QString icon = cfg.readEntry( "Icon" );
176 sepfirst = f && !ltabs; 176 if ( !name || !icon ) return;
177 } 177
178 delete applnk; 178 QDir subdir = QDir( dir );
179 } else { 179 subdir.cd( file );
180 f = FALSE; 180 subdir.setFilter( QDir::Files );
181 other.append(applnk); 181 subdir.setNameFilter( "*.desktop" );
182 menu->insertItem( Resource::loadIconSet(applnk->icon()), 182 // we don' t show the menu if there are no entries
183 applnk->name(), 20+nother++ ); 183 // perhaps one should check if there exist subsubdirs with entries...
184 } 184 if ( subdir.entryList().isEmpty() ) return;
185 } else { 185
186 delete applnk; 186 // checks were ok
187 } 187
188 } 188 QPixmap test;
189 } 189 test.convertFromImage( Resource::loadImage( icon ).smoothScale(
190 190 AppLnk::smallIconSize(), AppLnk::smallIconSize() ), 0 );
191 if ( !menu->count() ) 191
192 sepfirst = TRUE; 192 if ( useWidePopupMenu ) {
193 } 193 // generate submenu
194 194 QPopupMenu *submenu = new QPopupMenu( menu );
195 launchMenu->setName(sepfirst ? "accessories" : "accessories_need_sep"); // No tr 195 connect( submenu, SIGNAL(activated(int)), SLOT(itemSelected(int)) );
196 196 menu->insertItem( test, name, submenu, NO_ID );
197 return (nother || ntabs ); 197
198} 198 // ltabs is true cause else we wouldn't stuck around..
199 199 createMenuEntries( submenu, subdir, true, lot );
200 200 } else {
201void StartMenu::launch() 201 // no submenus - just bring corresponding tab to front
202{ 202 menu->insertItem( test, name, currentItem );
203 int y = mapToGlobal( QPoint() ).y() - launchMenu->sizeHint().height(); 203 tabNames.insert( currentItem, new QString( file ) );
204 204 currentItem++;
205 if ( launchMenu->isVisible() ) 205 }
206 launchMenu->hide(); 206}
207 else 207
208 launchMenu->popup( QPoint( 1, y ) ); 208void StartMenu::createMenuEntries( QPopupMenu *menu, QDir dir, bool ltabs, bool lot )
209} 209{
210 210 if ( lot ) {
211 211 dir.setFilter( QDir::Files );
212 212 dir.setNameFilter( "*.desktop" );
213 213 QStringList files = dir.entryList();
214static int compareAppletPositions(const void *a, const void *b) 214 files.sort();
215{ 215
216 const MenuApplet* aa = *(const MenuApplet**)a; 216 for ( QStringList::Iterator it = files.begin(); it != files.end(); it++ ) {
217 const MenuApplet* ab = *(const MenuApplet**)b; 217 createAppEntry( menu, dir, *it );
218 int d = aa->iface->position() - ab->iface->position(); 218 }
219 if ( d ) return d; 219 }
220 return QString::compare(aa->library->library(),ab->library->library()); 220 if ( ltabs ) {
221} 221 dir.setNameFilter( "*" );
222 222 dir.setFilter( QDir::Dirs );
223void StartMenu::clearApplets() 223 QStringList dirs = dir.entryList();
224{ 224 dirs.sort();
225 if (launchMenu ) 225
226 launchMenu-> hide(); 226 for ( QStringList::Iterator it = dirs.begin(); it != dirs.end(); it++ ) {
227 227 createDirEntry( menu, dir, *it, lot );
228 for ( QIntDictIterator<MenuApplet> it ( m_applets ); it. current ( ); ++it ) { 228 }
229 MenuApplet *applet = it. current ( ); 229 }
230 if ( launchMenu ) { 230}
231 launchMenu-> removeItem ( applet-> id ); 231
232 delete applet-> popup; 232bool StartMenu::loadMenu( QPopupMenu *menu )
233 } 233{
234 234 Config cfg("StartMenu");
235 applet-> iface-> release(); 235 cfg.setGroup("Menu");
236 applet-> library-> unload(); 236
237 delete applet-> library; 237 bool ltabs = cfg.readBoolEntry("LauncherTabs", TRUE);
238 } 238 bool lot = cfg.readBoolEntry("LauncherOther", TRUE);
239 m_applets.clear(); 239 useWidePopupMenu = cfg.readBoolEntry( "LauncherSubPopup", TRUE );
240} 240 bool sepfirst = !ltabs && !lot;
241 241
242 242 currentItem = 0;
243 243 launchMenu->clear();
244 244
245void StartMenu::loadApplets() 245 appLnks.setAutoDelete( true );
246{ 246 tabNames.setAutoDelete( true );
247 Config cfg( "StartMenu" ); 247 appLnks.clear();
248 cfg.setGroup( "Applets" ); 248 tabNames.clear();
249 249 appLnks.setAutoDelete( false );
250 // SafeMode causes too much problems, so we disable it for now -- 250 tabNames.setAutoDelete( false );
251 // maybe we should reenable it for OPIE 1.0 - sandman 26.09.02 251
252 // removed in the remerge PluginManager could handle it 252 QDir dir( MimeType::appsFolderName(), QString::null, QDir::Name );
253 // we don't currently use it -zecke 253 createMenuEntries( menu, dir, ltabs, lot );
254 254
255 QStringList exclude = cfg.readListEntry( "ExcludeApplets", ',' ); 255 if ( !menu->count() ) sepfirst = TRUE;
256 256
257 QString lang = getenv( "LANG" ); 257 launchMenu->setName( sepfirst ? "accessories" : "accessories_need_sep" ); // No tr
258 QString path = QPEApplication::qpeDir() + "/plugins/applets"; 258
259#ifdef Q_OS_MACX 259 return currentItem;
260 QDir dir( path, "lib*.dylib" ); 260}
261#else 261
262 QDir dir( path, "lib*.so" ); 262
263#endif /* Q_OS_MACX */ 263void StartMenu::launch()
264 QStringList list = dir.entryList(); 264{
265 QStringList::Iterator it; 265 int y = mapToGlobal( QPoint() ).y() - launchMenu->sizeHint().height();
266 int napplets=0; 266
267 MenuApplet* *xapplets = new MenuApplet*[list.count()]; 267 if ( launchMenu->isVisible() )
268 for ( it = list.begin(); it != list.end(); ++it ) { 268 launchMenu->hide();
269 if ( exclude.find( *it ) != exclude.end() ) 269 else
270 continue; 270 launchMenu->popup( QPoint( 1, y ) );
271 MenuAppletInterface *iface = 0; 271}
272 QLibrary *lib = new QLibrary( path + "/" + *it ); 272
273 if (( lib->queryInterface( IID_MenuApplet, (QUnknownInterface**)&iface ) == QS_OK ) && iface ) { 273
274 MenuApplet *applet = new MenuApplet; 274
275 xapplets[napplets++] = applet; 275
276 applet->library = lib; 276static int compareAppletPositions(const void *b, const void *a)
277 applet->iface = iface; 277{
278 278 const MenuApplet* aa = *(const MenuApplet**)a;
279 QTranslator *trans = new QTranslator(qApp); 279 const MenuApplet* ab = *(const MenuApplet**)b;
280 QString type = (*it).left( (*it).find(".") ); 280 int d = aa->iface->position() - ab->iface->position();
281 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm"; 281 if ( d ) return d;
282 if ( trans->load( tfn )) 282 return QString::compare(aa->library->library(),ab->library->library());
283 qApp->installTranslator( trans ); 283}
284 else 284
285 delete trans; 285void StartMenu::clearApplets()
286 } else { 286{
287 exclude += *it; 287 if ( launchMenu )
288 delete lib; 288 launchMenu-> hide();
289 } 289
290 } 290 for ( QIntDictIterator<MenuApplet> it( menuApplets ); it.current(); ++it ) {
291 cfg.writeEntry( "ExcludeApplets", exclude, ',' ); 291 MenuApplet *applet = it.current();
292 qsort(xapplets,napplets,sizeof(m_applets[0]),compareAppletPositions); 292 if ( launchMenu ) {
293 293 launchMenu->removeItem( applet-> id );
294 294 delete applet->popup;
295 int foo = ( launchMenu-> count ( )) ? launchMenu-> insertSeparator ( ) : 0; 295 }
296 296
297 while (napplets--) { 297 applet->iface->release();
298 MenuApplet *applet = xapplets[napplets]; 298 applet->library->unload();
299 299 delete applet-> library;
300 applet-> popup = applet-> iface-> popup ( this ); 300 }
301 301 menuApplets.clear();
302 if ( applet-> popup ) 302}
303 applet-> id = launchMenu-> insertItem ( applet-> iface-> icon ( ), applet-> iface-> text ( ), applet-> popup ); 303
304 else 304
305 applet-> id = launchMenu-> insertItem ( applet-> iface-> icon ( ), applet-> iface-> text ( ) ); 305
306 306
307 307void StartMenu::loadApplets()
308 m_applets.insert ( applet-> id, new MenuApplet(*applet)); 308{
309 } 309 Config cfg( "StartMenu" );
310 delete [] xapplets; 310 cfg.setGroup( "Applets" );
311 311
312} 312 // SafeMode causes too much problems, so we disable it for now --
313 313 // maybe we should reenable it for OPIE 1.0 - sandman 26.09.02
314 314 // removed in the remerge PluginManager could handle it
315/* 315 // we don't currently use it -zecke
316 * Launcher calls loadMenu too often fix that 316
317 */ 317 QStringList exclude = cfg.readListEntry( "ExcludeApplets", ',' );
318void StartMenu::addApplets(QPopupMenu* pop) { 318
319 QIntDict<MenuApplet> dict; 319 QString lang = getenv( "LANG" );
320 if( pop-> count ( )) 320 QString path = QPEApplication::qpeDir() + "/plugins/applets";
321 pop-> insertSeparator ( ); 321 QDir dir( path, "lib*.so" );
322 322 QStringList list = dir.entryList();
323 for ( QIntDictIterator<MenuApplet> it ( m_applets ); it. current ( ); ++it ) { 323 QStringList::Iterator it;
324 MenuApplet *applet = it. current ( ); 324 int napplets = 0;
325 if ( applet-> popup ) 325 MenuApplet* *xapplets = new MenuApplet*[list.count()];
326 applet-> id = pop-> insertItem ( applet-> iface-> icon ( ), applet-> iface-> text ( ), applet-> popup ); 326 for ( it = list.begin(); it != list.end(); ++it ) {
327 else 327 if ( exclude.find( *it ) != exclude.end() )
328 applet-> id = pop-> insertItem ( applet-> iface-> icon ( ), applet-> iface-> text ( ) ); 328 continue;
329 329 MenuAppletInterface *iface = 0;
330 dict.insert( applet->id, new MenuApplet(*applet) ); 330 QLibrary *lib = new QLibrary( path + "/" + *it );
331 } 331 if (( lib->queryInterface( IID_MenuApplet, (QUnknownInterface**)&iface ) == QS_OK ) && iface ) {
332 /* need to update the key */ 332 MenuApplet *applet = new MenuApplet;
333 m_applets.setAutoDelete( true ); 333 xapplets[napplets++] = applet;
334 m_applets.clear(); 334 applet->library = lib;
335 m_applets.setAutoDelete( false ); 335 applet->iface = iface;
336 m_applets = dict; 336
337} 337 QTranslator *trans = new QTranslator(qApp);
338 QString type = (*it).left( (*it).find(".") );
339 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm";
340 if ( trans->load( tfn ))
341 qApp->installTranslator( trans );
342 else
343 delete trans;
344 } else {
345 exclude += *it;
346 delete lib;
347 }
348 }
349 cfg.writeEntry( "ExcludeApplets", exclude, ',' );
350 qsort(xapplets, napplets, sizeof(menuApplets[0]), compareAppletPositions);
351
352
353 while ( napplets-- ) {
354 MenuApplet *applet = xapplets[napplets];
355
356 applet->popup = applet->iface->popup( this );
357
358 // menuApplets got an id < -1
359 menuApplets.insert( -( currentItem + 2 ), new MenuApplet( *applet ) );
360 currentItem++;
361 }
362 delete [] xapplets;
363
364 addApplets( launchMenu );
365}
366
367
368/*
369 * Launcher calls loadMenu too often fix that
370 */
371void StartMenu::addApplets(QPopupMenu* pop) {
372 QIntDict<MenuApplet> dict;
373 if( pop-> count ( ))
374 pop-> insertSeparator ( );
375
376 for ( QIntDictIterator<MenuApplet> it( menuApplets ); it.current(); ++it ) {
377 MenuApplet *applet = it.current();
378 if ( applet->popup )
379 applet->id = pop->insertItem( applet->iface->icon(),
380 applet->iface->text(), applet->popup );
381 else
382 applet->id = pop->insertItem( applet->iface->icon(),
383 applet->iface->text() );
384
385 dict.insert( applet->id, new MenuApplet( *applet ) );
386 }
387 /* need to update the key */
388 menuApplets.setAutoDelete( true );
389 menuApplets.clear();
390 menuApplets.setAutoDelete( false );
391 menuApplets = dict;
392}
diff --git a/core/launcher/startmenu.h b/core/launcher/startmenu.h
index 99df0f0..7218035 100644
--- a/core/launcher/startmenu.h
+++ b/core/launcher/startmenu.h
@@ -1,95 +1,106 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the 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**********************************************************************/ 19**********************************************************************/
20 20
21#ifndef __START_MENU_H__ 21#ifndef __START_MENU_H__
22#define __START_MENU_H__ 22#define __START_MENU_H__
23 23
24#include <qtopia/applnk.h> 24#include <qtopia/applnk.h>
25#include <qintdict.h> 25#include <qintdict.h>
26#include <qstring.h> 26#include <qstring.h>
27#include <qlist.h> 27#include <qlist.h>
28#include <qlabel.h> 28#include <qmap.h>
29#include <qpopupmenu.h> 29#include <qdir.h>
30 30#include <qlabel.h>
31#include <qtopia/menuappletinterface.h> 31#include <qpopupmenu.h>
32 32
33class StartPopupMenu : public QPopupMenu 33#include <qtopia/menuappletinterface.h>
34{ 34
35public: 35class StartPopupMenu : public QPopupMenu
36 StartPopupMenu( QWidget *parent ) : QPopupMenu( parent ) {} 36{
37protected: 37
38 void keyPressEvent( QKeyEvent *e ); 38public:
39}; 39 StartPopupMenu( QWidget *parent ) : QPopupMenu( parent ) {}
40 40
41class QLibrary; 41protected:
42 42 void keyPressEvent( QKeyEvent *e );
43 43
44struct MenuApplet { 44};
45 QLibrary *library; 45
46 MenuAppletInterface *iface; 46class QLibrary;
47 int id; 47
48 QPopupMenu *popup; 48
49}; 49struct MenuApplet {
50 50 QLibrary *library;
51class StartMenu : public QLabel { 51 MenuAppletInterface *iface;
52 Q_OBJECT 52 int id;
53public: 53 QPopupMenu *popup;
54 StartMenu( QWidget * ); 54};
55 ~StartMenu(); 55
56 56class StartMenu : public QLabel {
57 void refreshMenu(); 57
58 58 Q_OBJECT
59public: 59
60 StartPopupMenu *launchMenu; 60public:
61 61 StartMenu( QWidget * );
62signals: 62 ~StartMenu();
63 void tabSelected(const QString&); 63
64 64 void refreshMenu();
65public slots: 65
66 void launch( ); 66public:
67 void createMenu( ); 67 StartPopupMenu *launchMenu;
68 68
69protected slots: 69signals:
70 void itemSelected( int id ); 70 void tabSelected(const QString&);
71 71
72protected: 72public slots:
73 virtual void mousePressEvent( QMouseEvent * ); 73 void launch( );
74 74 void createMenu( );
75private: 75
76 void loadApplets(); 76protected slots:
77 void clearApplets(); 77 void itemSelected( int id );
78 void addApplets( QPopupMenu* menu ); 78
79 bool loadMenu( QPopupMenu *menu ); 79protected:
80 80 virtual void mousePressEvent( QMouseEvent * );
81private: 81
82 bool useWidePopupMenu; 82private:
83 QString popupMenuSidePixmap; 83 void loadApplets();
84 84 void clearApplets();
85 bool startButtonIsFlat; 85 void addApplets( QPopupMenu* menu );
86 QString startButtonPixmap; 86 bool loadMenu( QPopupMenu *menu );
87 87 void createMenuEntries( QPopupMenu *menu, QDir dir, bool ltabs, bool lot );
88 QStringList tabs; 88 void createDirEntry( QPopupMenu *menu, QDir dir, QString file, bool lot );
89 QList<AppLnk> other; 89 void createAppEntry( QPopupMenu *menu, QDir dir, QString file );
90 QIntDict<MenuApplet> m_applets; 90
91 int ntabs; 91private:
92 int nother; 92 bool useWidePopupMenu;
93}; 93 QString popupMenuSidePixmap;
94 94
95#endif // __START_MENU_H__ 95 bool startButtonIsFlat;
96 QString startButtonPixmap;
97
98 int currentItem;
99
100 QIntDict<AppLnk> appLnks;
101 QIntDict<QString> tabNames;
102 QIntDict<MenuApplet> menuApplets;
103
104};
105
106#endif // __START_MENU_H__