summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/startmenu.cpp374
-rw-r--r--core/launcher/startmenu.h46
2 files changed, 172 insertions, 248 deletions
diff --git a/core/launcher/startmenu.cpp b/core/launcher/startmenu.cpp
index d75e8be..014418d 100644
--- a/core/launcher/startmenu.cpp
+++ b/core/launcher/startmenu.cpp
@@ -23,15 +23,14 @@
23#include "startmenu.h" 23#include "startmenu.h"
24#include "sidething.h" 24
25//#include "mrulist.h" 25#include <qtopia/qpeapplication.h>
26#include "info.h" 26#include <qtopia/config.h>
27 27#include <qtopia/applnk.h>
28#include <qpe/qpeapplication.h> 28#include <qtopia/global.h>
29#include <qpe/config.h> 29#include <qtopia/resource.h>
30#include <qpe/applnk.h> 30#include <qtopia/mimetype.h>
31#include <qpe/global.h> 31#include <qtopia/qlibrary.h>
32#include <qpe/resource.h> 32
33#include <qpe/qlibrary.h> 33#include <qdict.h>
34
35#include <qintdict.h>
36#include <qdir.h> 34#include <qdir.h>
35#include <qpainter.h>
37 36
@@ -40,4 +39,14 @@
40 39
41// #define USE_CONFIG_FILE 40void StartPopupMenu::keyPressEvent( QKeyEvent *e )
41{
42 if ( e->key() == Key_F33 || e->key() == Key_Space ) {
43 // "OK" button, little hacky
44 QKeyEvent ke(QEvent::KeyPress, Key_Enter, 13, 0);
45 QPopupMenu::keyPressEvent( &ke );
46 } else {
47 QPopupMenu::keyPressEvent( e );
48 }
49}
42 50
51//---------------------------------------------------------------------------
43 52
@@ -45,4 +54,3 @@ StartMenu::StartMenu(QWidget *parent) : QLabel( parent )
45{ 54{
46 loadOptions(); 55 startButtonPixmap = "go"; // No tr
47 safety_tid = 1; // disable the timer... valgrind said it.. we don't use that option either -zecke
48 56
@@ -53,11 +61,5 @@ StartMenu::StartMenu(QWidget *parent) : QLabel( parent )
53 setFocusPolicy( NoFocus ); 61 setFocusPolicy( NoFocus );
54 //setFlat( startButtonIsFlat );
55 62
56 apps = 0;
57 launchMenu = 0; 63 launchMenu = 0;
58 applets. setAutoDelete ( true ); 64 refreshMenu();
59 sepId = 0;
60
61 reloadApps ( );
62 reloadApplets ( );
63} 65}
@@ -68,4 +70,2 @@ void StartMenu::mousePressEvent( QMouseEvent * )
68 launch(); 70 launch();
69 if (desktopInfo)
70 desktopInfo->menuClicked();
71} 71}
@@ -75,46 +75,23 @@ StartMenu::~StartMenu()
75{ 75{
76 delete apps; 76 clearApplets();
77}
78
79
80void StartMenu::loadOptions()
81{
82#ifdef USE_CONFIG_FILE
83 // Read configuration file
84 Config config("StartMenu");
85 config.setGroup( "StartMenu" );
86 QString tmpBoolString1 = config.readEntry( "UseWidePopupMenu", "FALSE" );
87 useWidePopupMenu = ( tmpBoolString1 == "TRUE" ) ? TRUE : FALSE;
88 QString tmpBoolString2 = config.readEntry( "StartButtonIsFlat", "TRUE" );
89 startButtonIsFlat = ( tmpBoolString2 == "TRUE" ) ? TRUE : FALSE;
90 QString tmpBoolString3 = config.readEntry( "UseMRUList", "TRUE" );
91 popupMenuSidePixmap = config.readEntry( "PopupMenuSidePixmap", "launcher/sidebar" );
92 startButtonPixmap = config.readEntry( "StartButtonPixmap", "go" );
93#else
94 // Basically just #include the .qpe_menu.conf file settings
95 useWidePopupMenu = FALSE;
96 popupMenuSidePixmap = "launcher/sidebar";
97 startButtonIsFlat = TRUE;
98 startButtonPixmap = "go"; // No tr
99#endif
100} 77}
101 78
102
103void StartMenu::createMenu() 79void StartMenu::createMenu()
104{ 80{
81 clearApplets();
105 delete launchMenu; 82 delete launchMenu;
106 if ( useWidePopupMenu )
107 launchMenu = new PopupWithLaunchSideThing( this, &popupMenuSidePixmap );
108 else
109 launchMenu = new StartPopupMenu( this );
110 83
111 loadMenu ( apps, launchMenu ); 84 launchMenu = new StartPopupMenu( this );
112 loadApplets ( ); 85 loadMenu( launchMenu );
86 loadApplets();
113 87
88 bool result = nother || ntabs || m_applets.count();
89 if ( result )
114 connect( launchMenu, SIGNAL(activated(int)), SLOT(itemSelected(int)) ); 90 connect( launchMenu, SIGNAL(activated(int)), SLOT(itemSelected(int)) );
91
115} 92}
116 93
117void StartMenu::reloadApps() 94void StartMenu::refreshMenu()
118{ 95{
119 Config cfg("StartMenu"); 96 Config cfg("Taskbar");
120 cfg.setGroup("Menu"); 97 cfg.setGroup("Menu");
@@ -123,20 +100,25 @@ void StartMenu::reloadApps()
123 bool lt = ltabs || lot; 100 bool lt = ltabs || lot;
124 if ( launchMenu && apps && !lt ) 101 if ( launchMenu && !lt )
125 return; // nothing to do 102 return; // nothing to do
126 103
127 if ( lt ) {
128 delete apps;
129 apps = new AppLnkSet( QPEApplication::qpeDir() + "apps" );
130 }
131 if ( launchMenu ) { 104 if ( launchMenu ) {
132 launchMenu-> hide ( ); 105 int i;
133 106 /* find the first entry we want to remove */
134 for ( QIntDictIterator<QPopupMenu> it ( tabdict ); it. current ( ); ++it ) { 107 for (i=0; i<(int)launchMenu->count(); i++) {
135 launchMenu-> removeItem ( it. currentKey ( )); 108 QMenuItem* item = launchMenu->findItem(launchMenu->idAt(i));
136 delete it.current ( ); 109 if ( item && item->id() >= 0 && item->id() < ntabs ) {
137 } 110 break;
138 tabdict. clear ( ); 111 }
139 loadMenu(apps,launchMenu); 112 if ( item && item->isSeparator() ) {
113 i++;
114 break;
115 }
116 }
117 /* remove them */
118 while (i<(int)launchMenu->count())
119 launchMenu->removeItemAt(i);
120 loadMenu(launchMenu);
121 addApplets(launchMenu);
140 } else { 122 } else {
141 createMenu(); 123 createMenu();
142 } 124 }
@@ -144,30 +126,20 @@ void StartMenu::reloadApps()
144 126
145void StartMenu::reloadApplets()
146{
147 if ( launchMenu ) {
148 clearApplets ( );
149 loadApplets ( );
150 }
151 else
152 createMenu ( );
153}
154
155void StartMenu::itemSelected( int id ) 127void StartMenu::itemSelected( int id )
156{ 128{
157 const AppLnk *app = apps->find( id ); 129 if ( id >= 0 && id < ntabs ) {
158 if ( app ) 130 emit tabSelected(tabs[id]);
159 app->execute(); 131 } else if ( id >= 20 && id < 20+nother ) {
160 else { 132 other.at(id-20)->execute();
161 MenuApplet *applet = applets. find ( id ); 133 }else {
162 134 MenuApplet *applet = m_applets.find ( id );
163 if ( applet ) 135 if ( applet ) {
164 applet-> iface-> activated ( ); 136 qWarning("activated");
165 } 137 applet-> iface-> activated();
138 }
139 }
166} 140}
167 141
168bool StartMenu::loadMenu( AppLnkSet *folder, QPopupMenu *menu ) 142bool StartMenu::loadMenu( QPopupMenu *menu )
169{ 143{
170 bool result = FALSE; 144 Config cfg("Taskbar");
171
172 Config cfg("StartMenu");
173 cfg.setGroup("Menu"); 145 cfg.setGroup("Menu");
@@ -176,75 +148,51 @@ bool StartMenu::loadMenu( AppLnkSet *folder, QPopupMenu *menu )
176 bool lot = cfg.readBoolEntry("LauncherOther",TRUE); 148 bool lot = cfg.readBoolEntry("LauncherOther",TRUE);
149 bool sepfirst = !ltabs && !lot;
177 150
178 tabdict. clear ( ); 151 tabs.clear();
179 152 other.setAutoDelete(TRUE);
180 if ( sepId ) 153 other.clear();
181 menu-> removeItem ( sepId ); 154 ntabs = 0;
182 sepId = ( menu-> count ( )) ? menu-> insertSeparator ( 0 ) : 0; 155 nother = 0;
183 156
157 bool f=TRUE;
184 if ( ltabs || lot ) { 158 if ( ltabs || lot ) {
185 QDict<QPopupMenu> typpop; 159 QDir dir( MimeType::appsFolderName(), QString::null, QDir::Name );
186 QStringList typs = folder->types(); 160 for (int i=0; i<(int)dir.count(); i++) {
187 for (QStringList::Iterator tit=typs.fromLast(); ; --tit) { 161 QString d = dir[i];
188 if ( !(*tit).isEmpty() ) { 162 Config cfg(dir.path()+"/"+d+"/.directory",Config::File);
189 QPopupMenu *new_menu; 163 if ( cfg.isValid() ) {
190 if ( ltabs ) { 164 QString nm = cfg.readEntry("Name");
191 new_menu = new StartPopupMenu( menu ); 165 QString ic = cfg.readEntry("Icon");
192 connect( new_menu, SIGNAL(activated(int)), SLOT(itemSelected(int)) ); 166 if ( !!nm && !!ic ) {
193 int id = menu->insertItem( folder->typePixmap(*tit), folder->typeName(*tit), new_menu, -1, 0 ); 167 tabs.append(d);
194 tabdict. insert ( id, new_menu ); 168 menu->insertItem( Resource::loadIconSet(ic), nm, ntabs++ );
195 } else { 169 }
196 new_menu = (QPopupMenu*)1; 170 } else if ( lot && d.right(8)==".desktop") {
197 } 171 AppLnk* applnk = new AppLnk(dir.path()+"/"+d);
198 typpop.insert(*tit, new_menu); 172 if ( applnk->isValid() ) {
199 } 173 if ( applnk->type() == "Separator" ) { // No tr
200 if ( tit == typs. begin ( )) 174 if ( lot ) {
201 break; 175 menu->insertSeparator();
202 } 176 sepfirst = f && !ltabs;
203 QListIterator<AppLnk> it( folder->children() ); 177 }
204 bool f=TRUE; 178 delete applnk;
205 for ( ; it.current(); ++it ) { 179 } else {
206 AppLnk *app = it.current(); 180 f = FALSE;
207 if ( app->type() == "Separator" ) { // No tr 181 other.append(applnk);
208 if ( lot ) { 182 menu->insertItem( Resource::loadIconSet(applnk->icon()),
209 menu->insertSeparator(); 183 applnk->name(), 20+nother++ );
210 } 184 }
211 } else { 185 } else {
212 f = FALSE; 186 delete applnk;
213 QString t = app->type(); 187 }
214 QPopupMenu* pmenu = typpop.find(t); 188 }
215 if ( ltabs ) { 189 }
216 if ( !pmenu && lot ) 190
217 pmenu = menu; 191 if ( !menu->count() )
218 } else { 192 sepfirst = TRUE;
219 if ( !pmenu )
220 pmenu = menu;
221 else
222 pmenu = 0;
223 }
224 if ( pmenu ) {
225 QString t = app->name();
226 t.replace(QRegExp("&"),"&&"); // escape shortcut character
227
228 int index = -1;
229
230 for ( index = 0; index < pmenu-> count ( ); index++ ) {
231 if ( pmenu-> text ( pmenu-> idAt ( index )). compare ( t ) > 0 )
232 break;
233 }
234
235 pmenu->insertItem( app->pixmap(), t, app->id(), index );
236 }
237 result=TRUE;
238 }
239 }
240 } 193 }
241 194
242 if ( sepId && ( menu-> idAt ( 0 ) == sepId )) { // no tabs entries 195 launchMenu->setName(sepfirst ? "accessories" : "accessories_need_sep"); // No tr
243 menu-> removeItem ( sepId );
244 sepId = 0;
245 }
246 if ( !menu-> count ( )) // if we don't do this QPopupMenu will insert a dummy Separator, which won't go away later
247 sepId = menu-> insertSeparator ( );
248 196
249 return result; 197 return (nother || ntabs );
250} 198}
@@ -252,34 +200,14 @@ bool StartMenu::loadMenu( AppLnkSet *folder, QPopupMenu *menu )
252 200
253void StartMenu::launch ( ) 201void StartMenu::launch()
254{ 202{
255 int y = mapToGlobal ( QPoint ( )). y ( ) - launchMenu-> sizeHint ( ). height ( ); 203 int y = mapToGlobal( QPoint() ).y() - launchMenu->sizeHint().height();
256 204
257 if ( launchMenu-> isVisible ( )) { 205 if ( launchMenu->isVisible() )
258 launchMenu-> hide ( ); 206 launchMenu->hide();
259 } 207 else
260 else { 208 launchMenu->popup( QPoint( 1, y ) );
261 QWidget *active = qApp-> activeWindow ( );
262 if ( active && active-> isPopup ( ))
263 active-> close ( );
264
265 launchMenu-> popup ( QPoint ( 1, y ));
266 }
267} 209}
268 210
269const AppLnk* StartMenu::execToLink(const QString& appname)
270{
271 const AppLnk* a = apps->findExec( appname );
272 return a;
273}
274 211
275void StartPopupMenu::keyPressEvent( QKeyEvent *e ) 212
276{
277 if ( e->key() == Key_F33 || e->key() == Key_Space ) {
278 // "OK" button, little hacky
279 QKeyEvent ke(QEvent::KeyPress, Key_Enter, 13, 0);
280 QPopupMenu::keyPressEvent( &ke );
281 } else {
282 QPopupMenu::keyPressEvent( e );
283 }
284}
285 213
@@ -296,5 +224,6 @@ void StartMenu::clearApplets()
296{ 224{
297 launchMenu-> hide(); 225 if (launchMenu )
226 launchMenu-> hide();
298 227
299 for ( QIntDictIterator<MenuApplet> it ( applets ); it. current ( ); ++it ) { 228 for ( QIntDictIterator<MenuApplet> it ( m_applets ); it. current ( ); ++it ) {
300 MenuApplet *applet = it. current ( ); 229 MenuApplet *applet = it. current ( );
@@ -309,3 +238,3 @@ void StartMenu::clearApplets()
309 } 238 }
310 applets.clear(); 239 m_applets.clear();
311} 240}
@@ -314,2 +243,3 @@ void StartMenu::clearApplets()
314 243
244
315void StartMenu::loadApplets() 245void StartMenu::loadApplets()
@@ -321,8 +251,5 @@ void StartMenu::loadApplets()
321 // maybe we should reenable it for OPIE 1.0 - sandman 26.09.02 251 // maybe we should reenable it for OPIE 1.0 - sandman 26.09.02
252 // removed in the remerge PluginManager could handle it
253 // we don't currently use it -zecke
322 254
323 bool safe = false; //cfg.readBoolEntry("SafeMode",FALSE);
324 if ( safe && !safety_tid )
325 return;
326 cfg.writeEntry("SafeMode",TRUE);
327 cfg.write();
328 QStringList exclude = cfg.readListEntry( "ExcludeApplets", ',' ); 255 QStringList exclude = cfg.readListEntry( "ExcludeApplets", ',' );
@@ -360,7 +287,6 @@ void StartMenu::loadApplets()
360 cfg.writeEntry( "ExcludeApplets", exclude, ',' ); 287 cfg.writeEntry( "ExcludeApplets", exclude, ',' );
361 qsort(xapplets,napplets,sizeof(applets[0]),compareAppletPositions); 288 qsort(xapplets,napplets,sizeof(m_applets[0]),compareAppletPositions);
289
362 290
363 if ( sepId ) 291 int foo = ( launchMenu-> count ( )) ? launchMenu-> insertSeparator ( ) : 0;
364 launchMenu-> removeItem ( sepId );
365 sepId = ( launchMenu-> count ( )) ? launchMenu-> insertSeparator ( ) : 0;
366 292
@@ -373,29 +299,35 @@ void StartMenu::loadApplets()
373 applet-> id = launchMenu-> insertItem ( applet-> iface-> icon ( ), applet-> iface-> text ( ), applet-> popup ); 299 applet-> id = launchMenu-> insertItem ( applet-> iface-> icon ( ), applet-> iface-> text ( ), applet-> popup );
374 else 300 else
375 applet-> id = launchMenu-> insertItem ( applet-> iface-> icon ( ), applet-> iface-> text ( ) ); 301 applet-> id = launchMenu-> insertItem ( applet-> iface-> icon ( ), applet-> iface-> text ( ) );
376 applets.insert ( applet-> id, new MenuApplet(*applet));
377 }
378 delete [] xapplets;
379 302
380 if ( sepId && ( launchMenu-> idAt ( launchMenu-> count ( ) - 1 ) == sepId )) { // no applets 303
381 launchMenu-> removeItem ( sepId ); 304 m_applets.insert ( applet-> id, new MenuApplet(*applet));
382 sepId = 0;
383 } 305 }
384 if ( !launchMenu-> count ( )) // if we don't do this QPopupMenu will insert a dummy Separator, which won't go away later 306 delete [] xapplets;
385 sepId = launchMenu-> insertSeparator ( );
386 307
387 if ( !safety_tid )
388 safety_tid = startTimer(2000); // TT has 5000, but this is a PITA for a developer ;) (sandman)
389} 308}
390 309
391void StartMenu::timerEvent(QTimerEvent* e) 310
392{ 311/*
393 if ( e->timerId() == safety_tid ) { 312 * Launcher calls loadMenu too often fix that
394 Config cfg( "StartMenu" ); 313 */
395 cfg.setGroup( "Applets" ); 314void StartMenu::addApplets(QPopupMenu* pop) {
396 cfg.writeEntry( "SafeMode", FALSE ); 315 QIntDict<MenuApplet> dict;
397 killTimer(safety_tid); 316 if( pop-> count ( ))
398 safety_tid = 0; 317 pop-> insertSeparator ( );
318
319 for ( QIntDictIterator<MenuApplet> it ( m_applets ); it. current ( ); ++it ) {
320 MenuApplet *applet = it. current ( );
321 if ( applet-> popup )
322 applet-> id = pop-> insertItem ( applet-> iface-> icon ( ), applet-> iface-> text ( ), applet-> popup );
323 else
324 applet-> id = pop-> insertItem ( applet-> iface-> icon ( ), applet-> iface-> text ( ) );
325
326 dict.insert( applet->id, new MenuApplet(*applet) );
399 } 327 }
328 /* need to update the key */
329 m_applets.setAutoDelete( true );
330 m_applets.clear();
331 m_applets.setAutoDelete( false );
332 m_applets = dict;
400} 333}
401
diff --git a/core/launcher/startmenu.h b/core/launcher/startmenu.h
index 0a91bb8..99df0f0 100644
--- a/core/launcher/startmenu.h
+++ b/core/launcher/startmenu.h
@@ -23,5 +23,6 @@
23 23
24#include <qtopia/applnk.h>
25#include <qintdict.h>
24#include <qstring.h> 26#include <qstring.h>
25#include <qlist.h> 27#include <qlist.h>
26#include <qintdict.h>
27#include <qlabel.h> 28#include <qlabel.h>
@@ -29,6 +30,3 @@
29 30
30#include <qpe/menuappletinterface.h> 31#include <qtopia/menuappletinterface.h>
31
32class AppLnkSet;
33class AppLnk;
34 32
@@ -44,7 +42,5 @@ class QLibrary;
44 42
45struct MenuApplet 43
46{ 44struct MenuApplet {
47#ifndef QT_NO_COMPONENT
48 QLibrary *library; 45 QLibrary *library;
49#endif
50 MenuAppletInterface *iface; 46 MenuAppletInterface *iface;
@@ -53,3 +49,2 @@ struct MenuApplet
53}; 49};
54
55 50
@@ -61,3 +56,3 @@ public:
61 56
62 const AppLnk* execToLink(const QString& appname); 57 void refreshMenu();
63 58
@@ -66,8 +61,8 @@ public:
66 61
62signals:
63 void tabSelected(const QString&);
64
67public slots: 65public slots:
68 void launch( ); 66 void launch( );
69 void loadOptions( );
70 void createMenu( ); 67 void createMenu( );
71 void reloadApps( );
72 void reloadApplets( );
73 68
@@ -78,8 +73,8 @@ protected:
78 virtual void mousePressEvent( QMouseEvent * ); 73 virtual void mousePressEvent( QMouseEvent * );
79 virtual void timerEvent ( QTimerEvent * ); 74
80
81private: 75private:
82 bool loadMenu( AppLnkSet *folder, QPopupMenu *menu ); 76 void loadApplets();
83 void loadApplets( ); 77 void clearApplets();
84 void clearApplets( ); 78 void addApplets( QPopupMenu* menu );
79 bool loadMenu( QPopupMenu *menu );
85 80
@@ -92,10 +87,7 @@ private:
92 87
93 AppLnkSet *apps; 88 QStringList tabs;
94 89 QList<AppLnk> other;
95 QIntDict<MenuApplet> applets; 90 QIntDict<MenuApplet> m_applets;
96 QIntDict<QPopupMenu> tabdict; 91 int ntabs;
97 92 int nother;
98// QValueList<MenuApplet> appletList;
99 int safety_tid;
100 int sepId;
101}; 93};