summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--core/launcher/startmenu.cpp253
-rw-r--r--core/launcher/startmenu.h21
2 files changed, 170 insertions, 104 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
@@ -20,2 +20,7 @@
20 20
21// TODO. During startup
22// Launcher::typeAdded
23// is called for each new tab and calls then each time the refresh of startmenu
24// suboptimal
25
21#define INCLUDE_MENUITEM_DEF 26#define INCLUDE_MENUITEM_DEF
@@ -34,5 +39,9 @@
34#include <qdir.h> 39#include <qdir.h>
35#include <qpainter.h> 40//#include <qpainter.h>
41
42//#include <stdlib.h>
43
36 44
37#include <stdlib.h> 45#define APPLNK_ID_OFFSET 250
46#define NO_ID -1
38 47
@@ -62,2 +71,3 @@ StartMenu::StartMenu(QWidget *parent) : QLabel( parent )
62 71
72 useWidePopupMenu = true;
63 launchMenu = 0; 73 launchMenu = 0;
@@ -87,6 +97,5 @@ void StartMenu::createMenu()
87 97
88 bool result = nother || ntabs || m_applets.count(); 98 bool result = currentItem || menuApplets.count();
89 if ( result ) 99 if ( result )
90 connect( launchMenu, SIGNAL(activated(int)), SLOT(itemSelected(int)) ); 100 connect( launchMenu, SIGNAL(activated(int)), SLOT(itemSelected(int)) );
91
92} 101}
@@ -95,3 +104,3 @@ void StartMenu::refreshMenu()
95{ 104{
96 Config cfg("Taskbar"); 105 Config cfg( "StartMenu" );
97 cfg.setGroup("Menu"); 106 cfg.setGroup("Menu");
@@ -99,28 +108,8 @@ void StartMenu::refreshMenu()
99 bool lot = cfg.readBoolEntry("LauncherOther",TRUE); 108 bool lot = cfg.readBoolEntry("LauncherOther",TRUE);
100 bool lt = ltabs || lot; 109 useWidePopupMenu = cfg.readBoolEntry( "LauncherSubPopup", TRUE );
101 if ( launchMenu && !lt ) 110
102 return; // nothing to do 111 if ( launchMenu && !(ltabs || lot) ) return; // nothing to do
103 112
104 if ( launchMenu ) {
105 int i;
106 /* find the first entry we want to remove */
107 for (i=0; i<(int)launchMenu->count(); i++) {
108 QMenuItem* item = launchMenu->findItem(launchMenu->idAt(i));
109 if ( item && item->id() >= 0 && item->id() < ntabs ) {
110 break;
111 }
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);
122 } else {
123 createMenu(); 113 createMenu();
124 } 114 }
125}
126 115
@@ -128,12 +117,19 @@ void StartMenu::itemSelected( int id )
128{ 117{
129 if ( id >= 0 && id < ntabs ) { 118 if ( id == NO_ID ) return;
130 emit tabSelected(tabs[id]); 119
131 } else if ( id >= 20 && id < 20+nother ) { 120 if ( id < 0 ) {
132 other.at(id-20)->execute(); 121 MenuApplet *applet = menuApplets.find( id );
133 }else {
134 MenuApplet *applet = m_applets.find ( id );
135 if ( applet ) { 122 if ( applet ) {
136 qWarning("activated");
137 applet-> iface-> activated(); 123 applet-> iface-> activated();
138 } 124 }
125 } else if ( id >= APPLNK_ID_OFFSET ) {
126 AppLnk * appLnk = appLnks.find( id );
127 if ( appLnk ) {
128 appLnk->execute();
129 }
130 } else {
131 QString *tabName = tabNames.find( id );
132 if ( tabName ) {
133 emit tabSelected( *tabName );
134 }
139 } 135 }
@@ -141,54 +137,120 @@ void StartMenu::itemSelected( int id )
141 137
142bool StartMenu::loadMenu( QPopupMenu *menu ) 138void StartMenu::createAppEntry( QPopupMenu *menu, QDir dir, QString file )
143{ 139{
144 Config cfg("Taskbar"); 140 if ( file.right(8) == ".desktop" ) {
145 cfg.setGroup("Menu"); 141 AppLnk* applnk = new AppLnk( dir.path() + "/" + file );
146 142 if ( !applnk->isValid() ) {
147 bool ltabs = cfg.readBoolEntry("LauncherTabs",TRUE); 143 delete applnk;
148 bool lot = cfg.readBoolEntry("LauncherOther",TRUE); 144 return;
149 bool sepfirst = !ltabs && !lot; 145 }
150
151 tabs.clear();
152 other.setAutoDelete(TRUE);
153 other.clear();
154 ntabs = 0;
155 nother = 0;
156 146
157 bool f=TRUE;
158 if ( ltabs || lot ) {
159 QDir dir( MimeType::appsFolderName(), QString::null, QDir::Name );
160 for (int i=0; i<(int)dir.count(); i++) {
161 QString d = dir[i];
162 Config cfg(dir.path()+"/"+d+"/.directory",Config::File);
163 if ( cfg.isValid() ) {
164 QString nm = cfg.readEntry("Name");
165 QString ic = cfg.readEntry("Icon");
166 if ( !!nm && !!ic ) {
167 tabs.append(d);
168 menu->insertItem( Resource::loadIconSet(ic), nm, ntabs++ );
169 }
170 } else if ( lot && d.right(8)==".desktop") {
171 AppLnk* applnk = new AppLnk(dir.path()+"/"+d);
172 if ( applnk->isValid() ) {
173 if ( applnk->type() == "Separator" ) { // No tr 147 if ( applnk->type() == "Separator" ) { // No tr
174 if ( lot ) {
175 menu->insertSeparator(); 148 menu->insertSeparator();
176 sepfirst = f && !ltabs;
177 }
178 delete applnk; 149 delete applnk;
179 } else { 150 } else {
180 f = FALSE; 151 QPixmap test;
181 other.append(applnk); 152 test.convertFromImage(
182 menu->insertItem( Resource::loadIconSet(applnk->icon()), 153 Resource::loadImage( applnk->icon() ).smoothScale(
183 applnk->name(), 20+nother++ ); 154 AppLnk::smallIconSize(), AppLnk::smallIconSize() ), 0 );
155
156 menu->insertItem( test, applnk->name(),
157 currentItem + APPLNK_ID_OFFSET );
158 appLnks.insert( currentItem + APPLNK_ID_OFFSET, applnk );
159 currentItem++;
160 }
184 } 161 }
162
163}
164
165void StartMenu::createDirEntry( QPopupMenu *menu, QDir dir, QString file, bool lot )
166{
167 // do some sanity checks and collect information
168
169 if ( file == "." || file == ".." ) return;
170
171 Config cfg( dir.path() + "/" + file + "/.directory", Config::File );
172 if ( !cfg.isValid() ) return;
173
174 QString name = cfg.readEntry( "Name" );
175 QString icon = cfg.readEntry( "Icon" );
176 if ( !name || !icon ) return;
177
178 QDir subdir = QDir( dir );
179 subdir.cd( file );
180 subdir.setFilter( QDir::Files );
181 subdir.setNameFilter( "*.desktop" );
182 // we don' t show the menu if there are no entries
183 // perhaps one should check if there exist subsubdirs with entries...
184 if ( subdir.entryList().isEmpty() ) return;
185
186 // checks were ok
187
188 QPixmap test;
189 test.convertFromImage( Resource::loadImage( icon ).smoothScale(
190 AppLnk::smallIconSize(), AppLnk::smallIconSize() ), 0 );
191
192 if ( useWidePopupMenu ) {
193 // generate submenu
194 QPopupMenu *submenu = new QPopupMenu( menu );
195 connect( submenu, SIGNAL(activated(int)), SLOT(itemSelected(int)) );
196 menu->insertItem( test, name, submenu, NO_ID );
197
198 // ltabs is true cause else we wouldn't stuck around..
199 createMenuEntries( submenu, subdir, true, lot );
185 } else { 200 } else {
186 delete applnk; 201 // no submenus - just bring corresponding tab to front
202 menu->insertItem( test, name, currentItem );
203 tabNames.insert( currentItem, new QString( file ) );
204 currentItem++;
187 } 205 }
188 } 206 }
207
208void StartMenu::createMenuEntries( QPopupMenu *menu, QDir dir, bool ltabs, bool lot )
209{
210 if ( lot ) {
211 dir.setFilter( QDir::Files );
212 dir.setNameFilter( "*.desktop" );
213 QStringList files = dir.entryList();
214 files.sort();
215
216 for ( QStringList::Iterator it = files.begin(); it != files.end(); it++ ) {
217 createAppEntry( menu, dir, *it );
218 }
189 } 219 }
220 if ( ltabs ) {
221 dir.setNameFilter( "*" );
222 dir.setFilter( QDir::Dirs );
223 QStringList dirs = dir.entryList();
224 dirs.sort();
190 225
191 if ( !menu->count() ) 226 for ( QStringList::Iterator it = dirs.begin(); it != dirs.end(); it++ ) {
192 sepfirst = TRUE; 227 createDirEntry( menu, dir, *it, lot );
193 } 228 }
229 }
230}
231
232bool StartMenu::loadMenu( QPopupMenu *menu )
233{
234 Config cfg("StartMenu");
235 cfg.setGroup("Menu");
236
237 bool ltabs = cfg.readBoolEntry("LauncherTabs", TRUE);
238 bool lot = cfg.readBoolEntry("LauncherOther", TRUE);
239 useWidePopupMenu = cfg.readBoolEntry( "LauncherSubPopup", TRUE );
240 bool sepfirst = !ltabs && !lot;
241
242 currentItem = 0;
243 launchMenu->clear();
244
245 appLnks.setAutoDelete( true );
246 tabNames.setAutoDelete( true );
247 appLnks.clear();
248 tabNames.clear();
249 appLnks.setAutoDelete( false );
250 tabNames.setAutoDelete( false );
251
252 QDir dir( MimeType::appsFolderName(), QString::null, QDir::Name );
253 createMenuEntries( menu, dir, ltabs, lot );
254
255 if ( !menu->count() ) sepfirst = TRUE;
194 256
@@ -196,3 +258,3 @@ bool StartMenu::loadMenu( QPopupMenu *menu )
196 258
197 return (nother || ntabs ); 259 return currentItem;
198} 260}
@@ -213,3 +275,3 @@ void StartMenu::launch()
213 275
214static int compareAppletPositions(const void *a, const void *b) 276static int compareAppletPositions(const void *b, const void *a)
215{ 277{
@@ -227,3 +289,3 @@ void StartMenu::clearApplets()
227 289
228 for ( QIntDictIterator<MenuApplet> it ( m_applets ); it. current ( ); ++it ) { 290 for ( QIntDictIterator<MenuApplet> it( menuApplets ); it.current(); ++it ) {
229 MenuApplet *applet = it. current ( ); 291 MenuApplet *applet = it. current ( );
@@ -238,3 +300,3 @@ void StartMenu::clearApplets()
238 } 300 }
239 m_applets.clear(); 301 menuApplets.clear();
240} 302}
@@ -258,7 +320,3 @@ void StartMenu::loadApplets()
258 QString path = QPEApplication::qpeDir() + "/plugins/applets"; 320 QString path = QPEApplication::qpeDir() + "/plugins/applets";
259#ifdef Q_OS_MACX
260 QDir dir( path, "lib*.dylib" );
261#else
262 QDir dir( path, "lib*.so" ); 321 QDir dir( path, "lib*.so" );
263#endif /* Q_OS_MACX */
264 QStringList list = dir.entryList(); 322 QStringList list = dir.entryList();
@@ -291,7 +349,5 @@ void StartMenu::loadApplets()
291 cfg.writeEntry( "ExcludeApplets", exclude, ',' ); 349 cfg.writeEntry( "ExcludeApplets", exclude, ',' );
292 qsort(xapplets,napplets,sizeof(m_applets[0]),compareAppletPositions); 350 qsort(xapplets, napplets, sizeof(menuApplets[0]), compareAppletPositions);
293 351
294 352
295 int foo = ( launchMenu-> count ( )) ? launchMenu-> insertSeparator ( ) : 0;
296
297 while (napplets--) { 353 while (napplets--) {
@@ -301,9 +357,5 @@ void StartMenu::loadApplets()
301 357
302 if ( applet-> popup ) 358 // menuApplets got an id < -1
303 applet-> id = launchMenu-> insertItem ( applet-> iface-> icon ( ), applet-> iface-> text ( ), applet-> popup ); 359 menuApplets.insert( -( currentItem + 2 ), new MenuApplet( *applet ) );
304 else 360 currentItem++;
305 applet-> id = launchMenu-> insertItem ( applet-> iface-> icon ( ), applet-> iface-> text ( ) );
306
307
308 m_applets.insert ( applet-> id, new MenuApplet(*applet));
309 } 361 }
@@ -311,2 +363,3 @@ void StartMenu::loadApplets()
311 363
364 addApplets( launchMenu );
312} 365}
@@ -322,8 +375,10 @@ void StartMenu::addApplets(QPopupMenu* pop) {
322 375
323 for ( QIntDictIterator<MenuApplet> it ( m_applets ); it. current ( ); ++it ) { 376 for ( QIntDictIterator<MenuApplet> it( menuApplets ); it.current(); ++it ) {
324 MenuApplet *applet = it. current ( ); 377 MenuApplet *applet = it. current ( );
325 if ( applet-> popup ) 378 if ( applet-> popup )
326 applet-> id = pop-> insertItem ( applet-> iface-> icon ( ), applet-> iface-> text ( ), applet-> popup ); 379 applet->id = pop->insertItem( applet->iface->icon(),
380 applet->iface->text(), applet->popup );
327 else 381 else
328 applet-> id = pop-> insertItem ( applet-> iface-> icon ( ), applet-> iface-> text ( ) ); 382 applet->id = pop->insertItem( applet->iface->icon(),
383 applet->iface->text() );
329 384
@@ -332,6 +387,6 @@ void StartMenu::addApplets(QPopupMenu* pop) {
332 /* need to update the key */ 387 /* need to update the key */
333 m_applets.setAutoDelete( true ); 388 menuApplets.setAutoDelete( true );
334 m_applets.clear(); 389 menuApplets.clear();
335 m_applets.setAutoDelete( false ); 390 menuApplets.setAutoDelete( false );
336 m_applets = dict; 391 menuApplets = dict;
337} 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
@@ -27,2 +27,4 @@
27#include <qlist.h> 27#include <qlist.h>
28#include <qmap.h>
29#include <qdir.h>
28#include <qlabel.h> 30#include <qlabel.h>
@@ -34,6 +36,9 @@ class StartPopupMenu : public QPopupMenu
34{ 36{
37
35public: 38public:
36 StartPopupMenu( QWidget *parent ) : QPopupMenu( parent ) {} 39 StartPopupMenu( QWidget *parent ) : QPopupMenu( parent ) {}
40
37protected: 41protected:
38 void keyPressEvent( QKeyEvent *e ); 42 void keyPressEvent( QKeyEvent *e );
43
39}; 44};
@@ -51,3 +56,5 @@ struct MenuApplet {
51class StartMenu : public QLabel { 56class StartMenu : public QLabel {
57
52 Q_OBJECT 58 Q_OBJECT
59
53public: 60public:
@@ -79,2 +86,5 @@ private:
79 bool loadMenu( QPopupMenu *menu ); 86 bool loadMenu( QPopupMenu *menu );
87 void createMenuEntries( QPopupMenu *menu, QDir dir, bool ltabs, bool lot );
88 void createDirEntry( QPopupMenu *menu, QDir dir, QString file, bool lot );
89 void createAppEntry( QPopupMenu *menu, QDir dir, QString file );
80 90
@@ -87,7 +97,8 @@ private:
87 97
88 QStringList tabs; 98 int currentItem;
89 QList<AppLnk> other; 99
90 QIntDict<MenuApplet> m_applets; 100 QIntDict<AppLnk> appLnks;
91 int ntabs; 101 QIntDict<QString> tabNames;
92 int nother; 102 QIntDict<MenuApplet> menuApplets;
103
93}; 104};