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
@@ -1,348 +1,350 @@
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// TODO. During startup 21// TODO. During startup
22// Launcher::typeAdded 22// Launcher::typeAdded
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
285void StartMenu::clearApplets() 287void StartMenu::clearApplets()
286{ 288{
287 if ( launchMenu ) 289 if ( launchMenu )
288 launchMenu-> hide(); 290 launchMenu-> hide();
289 291
290 for ( QIntDictIterator<MenuApplet> it( menuApplets ); it.current(); ++it ) { 292 for ( QIntDictIterator<MenuApplet> it( menuApplets ); it.current(); ++it ) {
291 MenuApplet *applet = it.current(); 293 MenuApplet *applet = it.current();
292 if ( launchMenu ) { 294 if ( launchMenu ) {
293 launchMenu->removeItem( applet-> id ); 295 launchMenu->removeItem( applet-> id );
294 delete applet->popup; 296 delete applet->popup;
295 } 297 }
296 298
297 applet->iface->release(); 299 applet->iface->release();
298 applet->library->unload(); 300 applet->library->unload();
299 delete applet-> library; 301 delete applet-> library;
300 } 302 }
301 menuApplets.clear(); 303 menuApplets.clear();
302} 304}
303 305
304 306
305 307
306 308
307void StartMenu::loadApplets() 309void StartMenu::loadApplets()
308{ 310{
309 Config cfg( "StartMenu" ); 311 Config cfg( "StartMenu" );
310 cfg.setGroup( "Applets" ); 312 cfg.setGroup( "Applets" );
311 313
312 // SafeMode causes too much problems, so we disable it for now -- 314 // SafeMode causes too much problems, so we disable it for now --
313 // maybe we should reenable it for OPIE 1.0 - sandman 26.09.02 315 // maybe we should reenable it for OPIE 1.0 - sandman 26.09.02
314 // removed in the remerge PluginManager could handle it 316 // removed in the remerge PluginManager could handle it
315 // we don't currently use it -zecke 317 // we don't currently use it -zecke
316 318
317 QStringList exclude = cfg.readListEntry( "ExcludeApplets", ',' ); 319 QStringList exclude = cfg.readListEntry( "ExcludeApplets", ',' );
318 320
319 QString lang = getenv( "LANG" ); 321 QString lang = getenv( "LANG" );
320 QString path = QPEApplication::qpeDir() + "/plugins/applets"; 322 QString path = QPEApplication::qpeDir() + "/plugins/applets";
321 QDir dir( path, "lib*.so" ); 323 QDir dir( path, "lib*.so" );
322 QStringList list = dir.entryList(); 324 QStringList list = dir.entryList();
323 QStringList::Iterator it; 325 QStringList::Iterator it;
324 int napplets = 0; 326 int napplets = 0;
325 MenuApplet* *xapplets = new MenuApplet*[list.count()]; 327 MenuApplet* *xapplets = new MenuApplet*[list.count()];
326 for ( it = list.begin(); it != list.end(); ++it ) { 328 for ( it = list.begin(); it != list.end(); ++it ) {
327 if ( exclude.find( *it ) != exclude.end() ) 329 if ( exclude.find( *it ) != exclude.end() )
328 continue; 330 continue;
329 MenuAppletInterface *iface = 0; 331 MenuAppletInterface *iface = 0;
330 QLibrary *lib = new QLibrary( path + "/" + *it ); 332 QLibrary *lib = new QLibrary( path + "/" + *it );
331 if (( lib->queryInterface( IID_MenuApplet, (QUnknownInterface**)&iface ) == QS_OK ) && iface ) { 333 if (( lib->queryInterface( IID_MenuApplet, (QUnknownInterface**)&iface ) == QS_OK ) && iface ) {
332 MenuApplet *applet = new MenuApplet; 334 MenuApplet *applet = new MenuApplet;
333 xapplets[napplets++] = applet; 335 xapplets[napplets++] = applet;
334 applet->library = lib; 336 applet->library = lib;
335 applet->iface = iface; 337 applet->iface = iface;
336 338
337 QTranslator *trans = new QTranslator(qApp); 339 QTranslator *trans = new QTranslator(qApp);
338 QString type = (*it).left( (*it).find(".") ); 340 QString type = (*it).left( (*it).find(".") );
339 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm"; 341 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm";
340 if ( trans->load( tfn )) 342 if ( trans->load( tfn ))
341 qApp->installTranslator( trans ); 343 qApp->installTranslator( trans );
342 else 344 else
343 delete trans; 345 delete trans;
344 } else { 346 } else {
345 exclude += *it; 347 exclude += *it;
346 delete lib; 348 delete lib;
347 } 349 }
348 } 350 }