summaryrefslogtreecommitdiff
authorzecke <zecke>2004-02-05 15:57:13 (UTC)
committer zecke <zecke>2004-02-05 15:57:13 (UTC)
commit823399a552c04821fb0b49d816d733fa21a12a21 (patch) (unidiff)
treea5683ede5436c6b912a89d4ccc6cd63953214ea4
parent8cb0ae68f155c989cb9533c1f04d04ec64083708 (diff)
downloadopie-823399a552c04821fb0b49d816d733fa21a12a21.zip
opie-823399a552c04821fb0b49d816d733fa21a12a21.tar.gz
opie-823399a552c04821fb0b49d816d733fa21a12a21.tar.bz2
Stop trying to scale a null image
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/startmenu.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/core/launcher/startmenu.cpp b/core/launcher/startmenu.cpp
index f17c7f8..b84eed8 100644
--- a/core/launcher/startmenu.cpp
+++ b/core/launcher/startmenu.cpp
@@ -23,262 +23,264 @@
23// is called for each new tab and calls then each time the refresh of startmenu 23// is called for each new tab and calls then each time the refresh of startmenu
24// suboptimal 24// suboptimal
25 25
26#define INCLUDE_MENUITEM_DEF 26#define INCLUDE_MENUITEM_DEF
27 27
28#include "startmenu.h" 28#include "startmenu.h"
29 29
30#include <qtopia/qpeapplication.h> 30#include <qtopia/qpeapplication.h>
31#include <qtopia/config.h> 31#include <qtopia/config.h>
32#include <qtopia/applnk.h> 32#include <qtopia/applnk.h>
33#include <qtopia/global.h> 33#include <qtopia/global.h>
34#include <qtopia/resource.h> 34#include <qtopia/resource.h>
35#include <qtopia/mimetype.h> 35#include <qtopia/mimetype.h>
36#include <qtopia/qlibrary.h> 36#include <qtopia/qlibrary.h>
37 37
38#include <qdict.h> 38#include <qdict.h>
39#include <qdir.h> 39#include <qdir.h>
40//#include <qpainter.h> 40//#include <qpainter.h>
41 41
42//#include <stdlib.h> 42//#include <stdlib.h>
43 43
44 44
45#define APPLNK_ID_OFFSET 250 45#define APPLNK_ID_OFFSET 250
46#define NO_ID -1 46#define NO_ID -1
47 47
48 48
49void StartPopupMenu::keyPressEvent( QKeyEvent *e ) 49void StartPopupMenu::keyPressEvent( QKeyEvent *e )
50{ 50{
51 if ( e->key() == Key_F33 || e->key() == Key_Space ) { 51 if ( e->key() == Key_F33 || e->key() == Key_Space ) {
52 // "OK" button, little hacky 52 // "OK" button, little hacky
53 QKeyEvent ke(QEvent::KeyPress, Key_Enter, 13, 0); 53 QKeyEvent ke(QEvent::KeyPress, Key_Enter, 13, 0);
54 QPopupMenu::keyPressEvent( &ke ); 54 QPopupMenu::keyPressEvent( &ke );
55 } else { 55 } else {
56 QPopupMenu::keyPressEvent( e ); 56 QPopupMenu::keyPressEvent( e );
57 } 57 }
58} 58}
59 59
60//--------------------------------------------------------------------------- 60//---------------------------------------------------------------------------
61 61
62StartMenu::StartMenu(QWidget *parent) : QLabel( parent ) 62StartMenu::StartMenu(QWidget *parent) : QLabel( parent )
63{ 63{
64 startButtonPixmap = "go"; // No tr 64 startButtonPixmap = "go"; // No tr
65 65
66 int sz = AppLnk::smallIconSize()+3; 66 int sz = AppLnk::smallIconSize()+3;
67 QPixmap pm; 67 QPixmap pm;
68 pm.convertFromImage(Resource::loadImage( startButtonPixmap).smoothScale( sz,sz) ); 68 pm.convertFromImage(Resource::loadImage( startButtonPixmap).smoothScale( sz,sz) );
69 setPixmap(pm); 69 setPixmap(pm);
70 setFocusPolicy( NoFocus ); 70 setFocusPolicy( NoFocus );
71 71
72 useWidePopupMenu = true; 72 useWidePopupMenu = true;
73 launchMenu = 0; 73 launchMenu = 0;
74 refreshMenu(); 74 refreshMenu();
75} 75}
76 76
77 77
78void StartMenu::mousePressEvent( QMouseEvent * ) 78void StartMenu::mousePressEvent( QMouseEvent * )
79{ 79{
80 launch(); 80 launch();
81} 81}
82 82
83 83
84StartMenu::~StartMenu() 84StartMenu::~StartMenu()
85{ 85{
86 clearApplets(); 86 clearApplets();
87} 87}
88 88
89void StartMenu::createMenu() 89void StartMenu::createMenu()
90{ 90{
91 clearApplets(); 91 clearApplets();
92 delete launchMenu; 92 delete launchMenu;
93 93
94 launchMenu = new StartPopupMenu( this ); 94 launchMenu = new StartPopupMenu( this );
95 loadMenu( launchMenu ); 95 loadMenu( launchMenu );
96 loadApplets(); 96 loadApplets();
97 97
98 bool result = currentItem || menuApplets.count(); 98 bool result = currentItem || menuApplets.count();
99 if ( result ) 99 if ( result )
100 connect( launchMenu, SIGNAL(activated(int)), SLOT(itemSelected(int)) ); 100 connect( launchMenu, SIGNAL(activated(int)), SLOT(itemSelected(int)) );
101} 101}
102 102
103void StartMenu::refreshMenu() 103void StartMenu::refreshMenu()
104{ 104{
105 Config cfg( "StartMenu" ); 105 Config cfg( "StartMenu" );
106 cfg.setGroup( "Menu" ); 106 cfg.setGroup( "Menu" );
107 bool ltabs = cfg.readBoolEntry( "LauncherTabs", TRUE ); 107 bool ltabs = cfg.readBoolEntry( "LauncherTabs", TRUE );
108 bool lot = cfg.readBoolEntry( "LauncherOther", TRUE ); 108 bool lot = cfg.readBoolEntry( "LauncherOther", TRUE );
109 useWidePopupMenu = cfg.readBoolEntry( "LauncherSubPopup", TRUE ); 109 useWidePopupMenu = cfg.readBoolEntry( "LauncherSubPopup", TRUE );
110 110
111 if ( launchMenu && !(ltabs || lot) ) return; // nothing to do 111 if ( launchMenu && !(ltabs || lot) ) return; // nothing to do
112 112
113 createMenu(); 113 createMenu();
114} 114}
115 115
116void StartMenu::itemSelected( int id ) 116void StartMenu::itemSelected( int id )
117{ 117{
118 if ( id == NO_ID ) return; 118 if ( id == NO_ID ) return;
119 119
120 if ( id < 0 ) { 120 if ( id < 0 ) {
121 MenuApplet *applet = menuApplets.find( id ); 121 MenuApplet *applet = menuApplets.find( id );
122 if ( applet ) { 122 if ( applet ) {
123 applet->iface->activated(); 123 applet->iface->activated();
124 } 124 }
125 } else if ( id >= APPLNK_ID_OFFSET ) { 125 } else if ( id >= APPLNK_ID_OFFSET ) {
126 AppLnk * appLnk = appLnks.find( id ); 126 AppLnk * appLnk = appLnks.find( id );
127 if ( appLnk ) { 127 if ( appLnk ) {
128 appLnk->execute(); 128 appLnk->execute();
129 } 129 }
130 } else { 130 } else {
131 QString *tabName = tabNames.find( id ); 131 QString *tabName = tabNames.find( id );
132 if ( tabName ) { 132 if ( tabName ) {
133 emit tabSelected( *tabName ); 133 emit tabSelected( *tabName );
134 } 134 }
135 } 135 }
136} 136}
137 137
138void StartMenu::createAppEntry( QPopupMenu *menu, QDir dir, QString file ) 138void StartMenu::createAppEntry( QPopupMenu *menu, QDir dir, QString file )
139{ 139{
140 if ( file.right(8) == ".desktop" ) { 140 if ( file.right(8) == ".desktop" ) {
141 AppLnk* applnk = new AppLnk( dir.path() + "/" + file ); 141 AppLnk* applnk = new AppLnk( dir.path() + "/" + file );
142 if ( !applnk->isValid() ) { 142 if ( !applnk->isValid() ) {
143 delete applnk; 143 delete applnk;
144 return; 144 return;
145 } 145 }
146 146
147 if ( applnk->type() == "Separator" ) { // No tr 147 if ( applnk->type() == "Separator" ) { // No tr
148 menu->insertSeparator(); 148 menu->insertSeparator();
149 delete applnk; 149 delete applnk;
150 } else { 150 } else {
151 QPixmap test; 151 QPixmap test;
152 test.convertFromImage( 152 QImage img = Resource::loadImage( applnk->icon() );
153 Resource::loadImage( applnk->icon() ).smoothScale( 153 if(!img.isNull() )
154 AppLnk::smallIconSize(), AppLnk::smallIconSize() ), 0 ); 154 test.convertFromImage(
155 155 img.smoothScale(
156 menu->insertItem( test, applnk->name(), 156 AppLnk::smallIconSize(), AppLnk::smallIconSize() ), 0 );
157
158 menu->insertItem( test, applnk->name(),
157 currentItem + APPLNK_ID_OFFSET ); 159 currentItem + APPLNK_ID_OFFSET );
158 appLnks.insert( currentItem + APPLNK_ID_OFFSET, applnk ); 160 appLnks.insert( currentItem + APPLNK_ID_OFFSET, applnk );
159 currentItem++; 161 currentItem++;
160 } 162 }
161 } 163 }
162 164
163} 165}
164 166
165void StartMenu::createDirEntry( QPopupMenu *menu, QDir dir, QString file, bool lot ) 167void StartMenu::createDirEntry( QPopupMenu *menu, QDir dir, QString file, bool lot )
166{ 168{
167 // do some sanity checks and collect information 169 // do some sanity checks and collect information
168 170
169 if ( file == "." || file == ".." ) return; 171 if ( file == "." || file == ".." ) return;
170 172
171 Config cfg( dir.path() + "/" + file + "/.directory", Config::File ); 173 Config cfg( dir.path() + "/" + file + "/.directory", Config::File );
172 if ( !cfg.isValid() ) return; 174 if ( !cfg.isValid() ) return;
173 175
174 QString name = cfg.readEntry( "Name" ); 176 QString name = cfg.readEntry( "Name" );
175 QString icon = cfg.readEntry( "Icon" ); 177 QString icon = cfg.readEntry( "Icon" );
176 if ( !name || !icon ) return; 178 if ( !name || !icon ) return;
177 179
178 QDir subdir = QDir( dir ); 180 QDir subdir = QDir( dir );
179 subdir.cd( file ); 181 subdir.cd( file );
180 subdir.setFilter( QDir::Files ); 182 subdir.setFilter( QDir::Files );
181 subdir.setNameFilter( "*.desktop" ); 183 subdir.setNameFilter( "*.desktop" );
182 // we don' t show the menu if there are no entries 184 // we don' t show the menu if there are no entries
183 // perhaps one should check if there exist subsubdirs with entries... 185 // perhaps one should check if there exist subsubdirs with entries...
184 if ( subdir.entryList().isEmpty() ) return; 186 if ( subdir.entryList().isEmpty() ) return;
185 187
186 // checks were ok 188 // checks were ok
187 189
188 QPixmap test; 190 QPixmap test;
189 test.convertFromImage( Resource::loadImage( icon ).smoothScale( 191 test.convertFromImage( Resource::loadImage( icon ).smoothScale(
190 AppLnk::smallIconSize(), AppLnk::smallIconSize() ), 0 ); 192 AppLnk::smallIconSize(), AppLnk::smallIconSize() ), 0 );
191 193
192 if ( useWidePopupMenu ) { 194 if ( useWidePopupMenu ) {
193 // generate submenu 195 // generate submenu
194 QPopupMenu *submenu = new QPopupMenu( menu ); 196 QPopupMenu *submenu = new QPopupMenu( menu );
195 connect( submenu, SIGNAL(activated(int)), SLOT(itemSelected(int)) ); 197 connect( submenu, SIGNAL(activated(int)), SLOT(itemSelected(int)) );
196 menu->insertItem( test, name, submenu, NO_ID ); 198 menu->insertItem( test, name, submenu, NO_ID );
197 199
198 // ltabs is true cause else we wouldn't stuck around.. 200 // ltabs is true cause else we wouldn't stuck around..
199 createMenuEntries( submenu, subdir, true, lot ); 201 createMenuEntries( submenu, subdir, true, lot );
200 } else { 202 } else {
201 // no submenus - just bring corresponding tab to front 203 // no submenus - just bring corresponding tab to front
202 menu->insertItem( test, name, currentItem ); 204 menu->insertItem( test, name, currentItem );
203 tabNames.insert( currentItem, new QString( file ) ); 205 tabNames.insert( currentItem, new QString( file ) );
204 currentItem++; 206 currentItem++;
205 } 207 }
206} 208}
207 209
208void StartMenu::createMenuEntries( QPopupMenu *menu, QDir dir, bool ltabs, bool lot ) 210void StartMenu::createMenuEntries( QPopupMenu *menu, QDir dir, bool ltabs, bool lot )
209{ 211{
210 if ( lot ) { 212 if ( lot ) {
211 dir.setFilter( QDir::Files ); 213 dir.setFilter( QDir::Files );
212 dir.setNameFilter( "*.desktop" ); 214 dir.setNameFilter( "*.desktop" );
213 QStringList files = dir.entryList(); 215 QStringList files = dir.entryList();
214 files.sort(); 216 files.sort();
215 217
216 for ( QStringList::Iterator it = files.begin(); it != files.end(); it++ ) { 218 for ( QStringList::Iterator it = files.begin(); it != files.end(); it++ ) {
217 createAppEntry( menu, dir, *it ); 219 createAppEntry( menu, dir, *it );
218 } 220 }
219 } 221 }
220 if ( ltabs ) { 222 if ( ltabs ) {
221 dir.setNameFilter( "*" ); 223 dir.setNameFilter( "*" );
222 dir.setFilter( QDir::Dirs ); 224 dir.setFilter( QDir::Dirs );
223 QStringList dirs = dir.entryList(); 225 QStringList dirs = dir.entryList();
224 dirs.sort(); 226 dirs.sort();
225 227
226 for ( QStringList::Iterator it = dirs.begin(); it != dirs.end(); it++ ) { 228 for ( QStringList::Iterator it = dirs.begin(); it != dirs.end(); it++ ) {
227 createDirEntry( menu, dir, *it, lot ); 229 createDirEntry( menu, dir, *it, lot );
228 } 230 }
229 } 231 }
230} 232}
231 233
232bool StartMenu::loadMenu( QPopupMenu *menu ) 234bool StartMenu::loadMenu( QPopupMenu *menu )
233{ 235{
234 Config cfg("StartMenu"); 236 Config cfg("StartMenu");
235 cfg.setGroup("Menu"); 237 cfg.setGroup("Menu");
236 238
237 bool ltabs = cfg.readBoolEntry("LauncherTabs", TRUE); 239 bool ltabs = cfg.readBoolEntry("LauncherTabs", TRUE);
238 bool lot = cfg.readBoolEntry("LauncherOther", TRUE); 240 bool lot = cfg.readBoolEntry("LauncherOther", TRUE);
239 useWidePopupMenu = cfg.readBoolEntry( "LauncherSubPopup", TRUE ); 241 useWidePopupMenu = cfg.readBoolEntry( "LauncherSubPopup", TRUE );
240 bool sepfirst = !ltabs && !lot; 242 bool sepfirst = !ltabs && !lot;
241 243
242 currentItem = 0; 244 currentItem = 0;
243 launchMenu->clear(); 245 launchMenu->clear();
244 246
245 appLnks.setAutoDelete( true ); 247 appLnks.setAutoDelete( true );
246 tabNames.setAutoDelete( true ); 248 tabNames.setAutoDelete( true );
247 appLnks.clear(); 249 appLnks.clear();
248 tabNames.clear(); 250 tabNames.clear();
249 appLnks.setAutoDelete( false ); 251 appLnks.setAutoDelete( false );
250 tabNames.setAutoDelete( false ); 252 tabNames.setAutoDelete( false );
251 253
252 QDir dir( MimeType::appsFolderName(), QString::null, QDir::Name ); 254 QDir dir( MimeType::appsFolderName(), QString::null, QDir::Name );
253 createMenuEntries( menu, dir, ltabs, lot ); 255 createMenuEntries( menu, dir, ltabs, lot );
254 256
255 if ( !menu->count() ) sepfirst = TRUE; 257 if ( !menu->count() ) sepfirst = TRUE;
256 258
257 launchMenu->setName( sepfirst ? "accessories" : "accessories_need_sep" ); // No tr 259 launchMenu->setName( sepfirst ? "accessories" : "accessories_need_sep" ); // No tr
258 260
259 return currentItem; 261 return currentItem;
260} 262}
261 263
262 264
263void StartMenu::launch() 265void StartMenu::launch()
264{ 266{
265 int y = mapToGlobal( QPoint() ).y() - launchMenu->sizeHint().height(); 267 int y = mapToGlobal( QPoint() ).y() - launchMenu->sizeHint().height();
266 268
267 if ( launchMenu->isVisible() ) 269 if ( launchMenu->isVisible() )
268 launchMenu->hide(); 270 launchMenu->hide();
269 else 271 else
270 launchMenu->popup( QPoint( 1, y ) ); 272 launchMenu->popup( QPoint( 1, y ) );
271} 273}
272 274
273 275
274 276
275 277
276static int compareAppletPositions(const void *b, const void *a) 278static int compareAppletPositions(const void *b, const void *a)
277{ 279{
278 const MenuApplet* aa = *(const MenuApplet**)a; 280 const MenuApplet* aa = *(const MenuApplet**)a;
279 const MenuApplet* ab = *(const MenuApplet**)b; 281 const MenuApplet* ab = *(const MenuApplet**)b;
280 int d = aa->iface->position() - ab->iface->position(); 282 int d = aa->iface->position() - ab->iface->position();
281 if ( d ) return d; 283 if ( d ) return d;
282 return QString::compare(aa->library->library(),ab->library->library()); 284 return QString::compare(aa->library->library(),ab->library->library());
283} 285}
284 286