-rw-r--r-- | core/launcher/startmenu.cpp | 252 |
1 files changed, 233 insertions, 19 deletions
diff --git a/core/launcher/startmenu.cpp b/core/launcher/startmenu.cpp index b008a30..647d0f2 100644 --- a/core/launcher/startmenu.cpp +++ b/core/launcher/startmenu.cpp | |||
@@ -1,6 +1,6 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of 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 |
@@ -19,4 +19,6 @@ | |||
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #define INCLUDE_MENUITEM_DEF | ||
22 | |||
21 | #include "startmenu.h" | 23 | #include "startmenu.h" |
22 | #include "sidething.h" | 24 | #include "sidething.h" |
@@ -29,6 +31,8 @@ | |||
29 | #include <qpe/global.h> | 31 | #include <qpe/global.h> |
30 | #include <qpe/resource.h> | 32 | #include <qpe/resource.h> |
33 | #include <qpe/qlibrary.h> | ||
31 | 34 | ||
32 | #include <qdict.h> | 35 | #include <qintdict.h> |
36 | #include <qdir.h> | ||
33 | 37 | ||
34 | #include <stdlib.h> | 38 | #include <stdlib.h> |
@@ -42,11 +46,18 @@ StartMenu::StartMenu(QWidget *parent) : QLabel( parent ) | |||
42 | loadOptions(); | 46 | loadOptions(); |
43 | 47 | ||
44 | setPixmap( Resource::loadPixmap( startButtonPixmap ) ); | 48 | int sz = AppLnk::smallIconSize()+3; |
49 | QPixmap pm; | ||
50 | pm.convertFromImage(Resource::loadImage(startButtonPixmap).smoothScale(sz,sz)); | ||
51 | setPixmap(pm); | ||
45 | setFocusPolicy( NoFocus ); | 52 | setFocusPolicy( NoFocus ); |
46 | //setFlat( startButtonIsFlat ); | 53 | //setFlat( startButtonIsFlat ); |
47 | 54 | ||
48 | apps = new AppLnkSet( QPEApplication::qpeDir() + "apps" ); | 55 | apps = 0; |
56 | launchMenu = 0; | ||
57 | applets. setAutoDelete ( true ); | ||
58 | sepId = 0; | ||
49 | 59 | ||
50 | createMenu(); | 60 | reloadApps ( ); |
61 | reloadApplets ( ); | ||
51 | } | 62 | } |
52 | 63 | ||
@@ -76,7 +87,7 @@ void StartMenu::loadOptions() | |||
76 | QString tmpBoolString2 = config.readEntry( "StartButtonIsFlat", "TRUE" ); | 87 | QString tmpBoolString2 = config.readEntry( "StartButtonIsFlat", "TRUE" ); |
77 | startButtonIsFlat = ( tmpBoolString2 == "TRUE" ) ? TRUE : FALSE; | 88 | startButtonIsFlat = ( tmpBoolString2 == "TRUE" ) ? TRUE : FALSE; |
78 | // QString tmpBoolString3 = config.readEntry( "UseMRUList", "TRUE" ); | 89 | QString tmpBoolString3 = config.readEntry( "UseMRUList", "TRUE" ); |
79 | popupMenuSidePixmap = config.readEntry( "PopupMenuSidePixmap", "launcher/sidebar" ); | 90 | popupMenuSidePixmap = config.readEntry( "PopupMenuSidePixmap", "launcher/sidebar" ); |
80 | startButtonPixmap = config.readEntry( "StartButtonPixmap", "go" ); | 91 | startButtonPixmap = config.readEntry( "StartButtonPixmap", "launcher/start_button" ); |
81 | #else | 92 | #else |
82 | // Basically just #include the .qpe_menu.conf file settings | 93 | // Basically just #include the .qpe_menu.conf file settings |
@@ -84,5 +95,5 @@ void StartMenu::loadOptions() | |||
84 | popupMenuSidePixmap = "launcher/sidebar"; | 95 | popupMenuSidePixmap = "launcher/sidebar"; |
85 | startButtonIsFlat = TRUE; | 96 | startButtonIsFlat = TRUE; |
86 | startButtonPixmap = "launcher/start_button"; | 97 | startButtonPixmap = "launcher/start_button"; // No tr |
87 | #endif | 98 | #endif |
88 | } | 99 | } |
@@ -91,4 +102,5 @@ void StartMenu::loadOptions() | |||
91 | void StartMenu::createMenu() | 102 | void StartMenu::createMenu() |
92 | { | 103 | { |
104 | delete launchMenu; | ||
93 | if ( useWidePopupMenu ) | 105 | if ( useWidePopupMenu ) |
94 | launchMenu = new PopupWithLaunchSideThing( this, &popupMenuSidePixmap ); | 106 | launchMenu = new PopupWithLaunchSideThing( this, &popupMenuSidePixmap ); |
@@ -97,5 +109,45 @@ void StartMenu::createMenu() | |||
97 | 109 | ||
98 | loadMenu( apps, launchMenu ); | 110 | loadMenu( apps, launchMenu ); |
111 | loadApplets ( ); | ||
112 | |||
113 | connect( launchMenu, SIGNAL(activated(int)), SLOT(itemSelected(int)) ); | ||
114 | } | ||
99 | 115 | ||
116 | void StartMenu::reloadApps() | ||
117 | { | ||
118 | Config cfg("StartMenu"); | ||
119 | cfg.setGroup("Menu"); | ||
120 | bool ltabs = cfg.readBoolEntry("LauncherTabs",TRUE); | ||
121 | bool lot = cfg.readBoolEntry("LauncherOther",TRUE); | ||
122 | bool lt = ltabs || lot; | ||
123 | if ( launchMenu && apps && !lt ) | ||
124 | return; // nothing to do | ||
125 | |||
126 | if ( lt ) { | ||
127 | delete apps; | ||
128 | apps = new AppLnkSet( QPEApplication::qpeDir() + "apps" ); | ||
129 | } | ||
130 | if ( launchMenu ) { | ||
131 | launchMenu-> hide ( ); | ||
132 | |||
133 | for ( QIntDictIterator<QPopupMenu> it ( tabdict ); it. current ( ); ++it ) { | ||
134 | launchMenu-> removeItem ( it. currentKey ( )); | ||
135 | delete it.current ( ); | ||
136 | } | ||
137 | tabdict. clear ( ); | ||
138 | loadMenu(apps,launchMenu); | ||
139 | } else { | ||
140 | createMenu(); | ||
141 | } | ||
142 | } | ||
143 | |||
144 | void StartMenu::reloadApplets() | ||
145 | { | ||
146 | if ( launchMenu ) { | ||
147 | clearApplets ( ); | ||
148 | loadApplets ( ); | ||
149 | } | ||
150 | else | ||
151 | createMenu ( ); | ||
100 | } | 152 | } |
101 | 153 | ||
@@ -105,4 +157,10 @@ void StartMenu::itemSelected( int id ) | |||
105 | if ( app ) | 157 | if ( app ) |
106 | app->execute(); | 158 | app->execute(); |
159 | else { | ||
160 | MenuApplet *applet = applets. find ( id ); | ||
161 | |||
162 | if ( applet ) | ||
163 | applet-> iface-> activated ( ); | ||
164 | } | ||
107 | } | 165 | } |
108 | 166 | ||
@@ -111,32 +169,72 @@ bool StartMenu::loadMenu( AppLnkSet *folder, QPopupMenu *menu ) | |||
111 | bool result = FALSE; | 169 | bool result = FALSE; |
112 | 170 | ||
113 | QStringList typs = folder->types(); | 171 | Config cfg("StartMenu"); |
172 | cfg.setGroup("Menu"); | ||
173 | |||
174 | bool ltabs = cfg.readBoolEntry("LauncherTabs",TRUE); | ||
175 | bool lot = cfg.readBoolEntry("LauncherOther",TRUE); | ||
176 | |||
177 | tabdict. clear ( ); | ||
178 | |||
179 | if ( sepId ) | ||
180 | menu-> removeItem ( sepId ); | ||
181 | sepId = ( menu-> count ( )) ? menu-> insertSeparator ( 0 ) : 0; | ||
182 | |||
183 | if ( ltabs || lot ) { | ||
114 | QDict<QPopupMenu> typpop; | 184 | QDict<QPopupMenu> typpop; |
115 | for (QStringList::Iterator tit=typs.begin(); tit!=typs.end(); ++tit) { | 185 | QStringList typs = folder->types(); |
186 | for (QStringList::Iterator tit=typs.fromLast(); ; --tit) { | ||
116 | if ( !(*tit).isEmpty() ) { | 187 | if ( !(*tit).isEmpty() ) { |
117 | QPopupMenu *new_menu = new StartPopupMenu( menu ); | 188 | QPopupMenu *new_menu; |
118 | typpop.insert(*tit, new_menu); | 189 | if ( ltabs ) { |
190 | new_menu = new StartPopupMenu( menu ); | ||
119 | connect( new_menu, SIGNAL(activated(int)), SLOT(itemSelected(int)) ); | 191 | connect( new_menu, SIGNAL(activated(int)), SLOT(itemSelected(int)) ); |
120 | menu->insertItem( folder->typePixmap(*tit), folder->typeName(*tit), new_menu ); | 192 | int id = menu->insertItem( folder->typePixmap(*tit), folder->typeName(*tit), new_menu, -1, 0 ); |
193 | tabdict. insert ( id, new_menu ); | ||
194 | } else { | ||
195 | new_menu = (QPopupMenu*)1; | ||
121 | } | 196 | } |
197 | typpop.insert(*tit, new_menu); | ||
198 | } | ||
199 | if ( tit == typs. begin ( )) | ||
200 | break; | ||
122 | } | 201 | } |
123 | |||
124 | QListIterator<AppLnk> it( folder->children() ); | 202 | QListIterator<AppLnk> it( folder->children() ); |
203 | bool f=TRUE; | ||
125 | for ( ; it.current(); ++it ) { | 204 | for ( ; it.current(); ++it ) { |
126 | AppLnk *app = it.current(); | 205 | AppLnk *app = it.current(); |
127 | if ( app->type() == "Separator" ) { | 206 | if ( app->type() == "Separator" ) { // No tr |
207 | if ( lot ) { | ||
128 | menu->insertSeparator(); | 208 | menu->insertSeparator(); |
209 | } | ||
129 | } else { | 210 | } else { |
211 | f = FALSE; | ||
130 | QString t = app->type(); | 212 | QString t = app->type(); |
131 | QPopupMenu* pmenu = typpop.find(t); | 213 | QPopupMenu* pmenu = typpop.find(t); |
214 | if ( ltabs ) { | ||
215 | if ( !pmenu && lot ) | ||
216 | pmenu = menu; | ||
217 | } else { | ||
132 | if ( !pmenu ) | 218 | if ( !pmenu ) |
133 | pmenu = menu; | 219 | pmenu = menu; |
134 | pmenu->insertItem( app->pixmap(), app->name(), app->id() ); | 220 | else |
221 | pmenu = 0; | ||
222 | } | ||
223 | if ( pmenu ) { | ||
224 | QString t = app->name(); | ||
225 | t.replace(QRegExp("&"),"&&"); // escape shortcut character | ||
226 | pmenu->insertItem( app->pixmap(), t, app->id() ); | ||
227 | } | ||
135 | result=TRUE; | 228 | result=TRUE; |
136 | } | 229 | } |
137 | } | 230 | } |
231 | } | ||
138 | 232 | ||
139 | if ( result ) | 233 | if ( sepId && ( menu-> idAt ( 0 ) == sepId )) { // no tabs entries |
140 | connect( menu, SIGNAL(activated(int)), SLOT(itemSelected(int)) ); | 234 | menu-> removeItem ( sepId ); |
235 | sepId = 0; | ||
236 | } | ||
237 | if ( !menu-> count ( )) // if we don't do this QPopupMenu will insert a dummy Separator, which won't go away later | ||
238 | sepId = menu-> insertSeparator ( ); | ||
141 | 239 | ||
142 | return result; | 240 | return result; |
@@ -170,2 +268,118 @@ void StartPopupMenu::keyPressEvent( QKeyEvent *e ) | |||
170 | } | 268 | } |
171 | } | 269 | } |
270 | |||
271 | static int compareAppletPositions(const void *a, const void *b) | ||
272 | { | ||
273 | const MenuApplet* aa = *(const MenuApplet**)a; | ||
274 | const MenuApplet* ab = *(const MenuApplet**)b; | ||
275 | int d = ab->iface->position() - aa->iface->position(); | ||
276 | if ( d ) return d; | ||
277 | return QString::compare(ab->library->library(),aa->library->library()); | ||
278 | } | ||
279 | |||
280 | void StartMenu::clearApplets() | ||
281 | { | ||
282 | launchMenu-> hide(); | ||
283 | |||
284 | for ( QIntDictIterator<MenuApplet> it ( applets ); it. current ( ); ++it ) { | ||
285 | MenuApplet *applet = it. current ( ); | ||
286 | if ( launchMenu ) { | ||
287 | launchMenu-> removeItem ( applet-> id ); | ||
288 | delete applet-> popup; | ||
289 | } | ||
290 | |||
291 | applet-> iface-> release(); | ||
292 | applet-> library-> unload(); | ||
293 | delete applet-> library; | ||
294 | } | ||
295 | applets.clear(); | ||
296 | } | ||
297 | |||
298 | |||
299 | |||
300 | void StartMenu::loadApplets() | ||
301 | { | ||
302 | Config cfg( "StartMenu" ); | ||
303 | cfg.setGroup( "Applets" ); | ||
304 | |||
305 | // SafeMode causes too much problems, so we disable it for now -- | ||
306 | // maybe we should reenable it for OPIE 1.0 - sandman 26.09.02 | ||
307 | |||
308 | bool safe = false; //cfg.readBoolEntry("SafeMode",FALSE); | ||
309 | if ( safe && !safety_tid ) | ||
310 | return; | ||
311 | cfg.writeEntry("SafeMode",TRUE); | ||
312 | cfg.write(); | ||
313 | QStringList exclude = cfg.readListEntry( "ExcludeApplets", ',' ); | ||
314 | |||
315 | QString path = QPEApplication::qpeDir() + "/plugins/applets"; | ||
316 | QDir dir( path, "lib*.so" ); | ||
317 | QStringList list = dir.entryList(); | ||
318 | QStringList::Iterator it; | ||
319 | int napplets=0; | ||
320 | MenuApplet* *xapplets = new MenuApplet*[list.count()]; | ||
321 | for ( it = list.begin(); it != list.end(); ++it ) { | ||
322 | if ( exclude.find( *it ) != exclude.end() ) | ||
323 | continue; | ||
324 | MenuAppletInterface *iface = 0; | ||
325 | QLibrary *lib = new QLibrary( path + "/" + *it ); | ||
326 | if (( lib->queryInterface( IID_MenuApplet, (QUnknownInterface**)&iface ) == QS_OK ) && iface ) { | ||
327 | MenuApplet *applet = new MenuApplet; | ||
328 | xapplets[napplets++] = applet; | ||
329 | applet->library = lib; | ||
330 | applet->iface = iface; | ||
331 | } else { | ||
332 | exclude += *it; | ||
333 | delete lib; | ||
334 | } | ||
335 | } | ||
336 | cfg.writeEntry( "ExcludeApplets", exclude, ',' ); | ||
337 | qsort(xapplets,napplets,sizeof(applets[0]),compareAppletPositions); | ||
338 | |||
339 | if ( sepId ) | ||
340 | launchMenu-> removeItem ( sepId ); | ||
341 | sepId = ( launchMenu-> count ( )) ? launchMenu-> insertSeparator ( ) : 0; | ||
342 | |||
343 | while (napplets--) { | ||
344 | MenuApplet *applet = xapplets[napplets]; | ||
345 | QString lang = getenv( "LANG" ); | ||
346 | QTranslator * trans = new QTranslator(qApp); | ||
347 | QString type = (*it).left( (*it).find(".") ); | ||
348 | QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm"; | ||
349 | if ( trans->load( tfn )) | ||
350 | qApp->installTranslator( trans ); | ||
351 | else | ||
352 | delete trans; | ||
353 | |||
354 | applet-> popup = applet-> iface-> popup ( this ); | ||
355 | |||
356 | if ( applet-> popup ) | ||
357 | applet-> id = launchMenu-> insertItem ( applet-> iface-> icon ( ), applet-> iface-> text ( ), applet-> popup ); | ||
358 | else | ||
359 | applet-> id = launchMenu-> insertItem ( applet-> iface-> icon ( ), applet-> iface-> text ( ) ); | ||
360 | applets.insert ( applet-> id, new MenuApplet(*applet)); | ||
361 | } | ||
362 | delete xapplets; | ||
363 | |||
364 | if ( sepId && ( launchMenu-> idAt ( launchMenu-> count ( ) - 1 ) == sepId )) { // no applets | ||
365 | launchMenu-> removeItem ( sepId ); | ||
366 | sepId = 0; | ||
367 | } | ||
368 | if ( !launchMenu-> count ( )) // if we don't do this QPopupMenu will insert a dummy Separator, which won't go away later | ||
369 | sepId = launchMenu-> insertSeparator ( ); | ||
370 | |||
371 | if ( !safety_tid ) | ||
372 | safety_tid = startTimer(2000); // TT has 5000, but this is a PITA for a developer ;) (sandman) | ||
373 | } | ||
374 | |||
375 | void StartMenu::timerEvent(QTimerEvent* e) | ||
376 | { | ||
377 | if ( e->timerId() == safety_tid ) { | ||
378 | Config cfg( "StartMenu" ); | ||
379 | cfg.setGroup( "Applets" ); | ||
380 | cfg.writeEntry( "SafeMode", FALSE ); | ||
381 | killTimer(safety_tid); | ||
382 | safety_tid = 0; | ||
383 | } | ||
384 | } | ||
385 | |||