summaryrefslogtreecommitdiff
path: root/core/launcher/startmenu.cpp
Unidiff
Diffstat (limited to 'core/launcher/startmenu.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/startmenu.cpp79
1 files changed, 37 insertions, 42 deletions
diff --git a/core/launcher/startmenu.cpp b/core/launcher/startmenu.cpp
index ce7840e..24a9d7e 100644
--- a/core/launcher/startmenu.cpp
+++ b/core/launcher/startmenu.cpp
@@ -1,76 +1,80 @@
1/********************************************************************** 1/*
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2                 This file is part of the Opie Project
3** 3 =. (C) 2000-2002 Trolltech AS
4** This file is part of the Qtopia Environment. 4 .=l. (C) 2002-2005 The Opie Team <opie-devel@handhelds.org>
5** 5           .>+-=
6** This file may be distributed and/or modified under the terms of the 6 _;:,     .>    :=|. This program is free software; you can
7** GNU General Public License version 2 as published by the Free Software 7.> <`_,   >  .   <= redistribute it and/or modify it under
8** Foundation and appearing in the file LICENSE.GPL included in the 8 :`=1 )Y*s>-.--   : the terms of the GNU Library General Public
9** packaging of this file. 9.="- .-=="i,     .._ License as published by the Free Software
10** 10 - .   .-<_>     .<> Foundation; version 2 of the License.
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11     ._= =}       :
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12    .%`+i>       _;_.
13** 13    .i_,=:_.      -<s. This program is distributed in the hope that
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15** 15 : ..    .:,     . . . without even the implied warranty of
16** Contact info@trolltech.com if any conditions of this licensing are 16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17** not clear to you. 17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
18** 18..}^=.=       =       ; Library General Public License for more
19**********************************************************************/ 19++=   -.     .`     .: details.
20 20 :     =  ...= . :.=-
21 -.   .:....=;==+<; You should have received a copy of the GNU
22  -_. . .   )=.  = Library General Public License along with
23    --        :-=` this library; see the file COPYING.LIB.
24 If not, write to the Free Software Foundation,
25 Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA.
27*/
21// TODO. During startup 28// TODO. During startup
22// Launcher::typeAdded 29// Launcher::typeAdded
23// is called for each new tab and calls then each time the refresh of startmenu 30// is called for each new tab and calls then each time the refresh of startmenu
24// suboptimal 31// suboptimal
25 32
26#define INCLUDE_MENUITEM_DEF 33#define INCLUDE_MENUITEM_DEF
27 34
28#include "startmenu.h" 35#include "startmenu.h"
29 36
37/* OPIE */
38#include <opie2/oresource.h>
39using namespace Opie::Core;
30#include <qtopia/qpeapplication.h> 40#include <qtopia/qpeapplication.h>
31#include <qtopia/config.h> 41#include <qtopia/config.h>
32#include <qtopia/resource.h>
33#include <qtopia/mimetype.h> 42#include <qtopia/mimetype.h>
34#include <qtopia/qlibrary.h> 43#include <qtopia/qlibrary.h>
35 44
36//#include <qpainter.h>
37
38//#include <stdlib.h>
39
40
41#define APPLNK_ID_OFFSET 250 45#define APPLNK_ID_OFFSET 250
42#define NO_ID -1 46#define NO_ID -1
43 47
44 48
45void StartPopupMenu::keyPressEvent( QKeyEvent *e ) 49void StartPopupMenu::keyPressEvent( QKeyEvent *e )
46{ 50{
47 if ( e->key() == Key_F33 || e->key() == Key_Space ) { 51 if ( e->key() == Key_F33 || e->key() == Key_Space ) {
48 // "OK" button, little hacky 52 // "OK" button, little hacky
49 QKeyEvent ke(QEvent::KeyPress, Key_Enter, 13, 0); 53 QKeyEvent ke(QEvent::KeyPress, Key_Enter, 13, 0);
50 QPopupMenu::keyPressEvent( &ke ); 54 QPopupMenu::keyPressEvent( &ke );
51 } else { 55 } else {
52 QPopupMenu::keyPressEvent( e ); 56 QPopupMenu::keyPressEvent( e );
53 } 57 }
54} 58}
55 59
56//--------------------------------------------------------------------------- 60//---------------------------------------------------------------------------
57 61
58StartMenu::StartMenu(QWidget *parent) : QLabel( parent ) 62StartMenu::StartMenu(QWidget *parent) : QLabel( parent )
59{ 63{
60 startButtonPixmap = "go"; // No tr 64 startButtonPixmap = "go"; // No tr
61 65
62 int sz = AppLnk::smallIconSize()+3; 66 int sz = AppLnk::smallIconSize()+3;
63 QPixmap pm; 67 QPixmap pm;
64 pm.convertFromImage(Resource::loadImage( startButtonPixmap).smoothScale( sz,sz) ); 68 pm.convertFromImage(OResource::loadImage( startButtonPixmap, OResource::NoScale ).smoothScale( sz,sz) );
65 setPixmap(pm); 69 setPixmap(pm);
66 setFocusPolicy( NoFocus ); 70 setFocusPolicy( NoFocus );
67 71
68 useWidePopupMenu = true; 72 useWidePopupMenu = true;
69 launchMenu = 0; 73 launchMenu = 0;
70 currentItem = 0; 74 currentItem = 0;
71 refreshMenu(); 75 refreshMenu();
72} 76}
73 77
74 78
75void StartMenu::mousePressEvent( QMouseEvent * ) 79void StartMenu::mousePressEvent( QMouseEvent * )
76{ 80{
@@ -136,42 +140,36 @@ void StartMenu::createAppEntry( QPopupMenu *menu, QDir dir, QString file )
136{ 140{
137 if ( file.right(8) == ".desktop" ) { 141 if ( file.right(8) == ".desktop" ) {
138 AppLnk* applnk = new AppLnk( dir.path() + "/" + file ); 142 AppLnk* applnk = new AppLnk( dir.path() + "/" + file );
139 if ( !applnk->isValid() ) { 143 if ( !applnk->isValid() ) {
140 delete applnk; 144 delete applnk;
141 return; 145 return;
142 } 146 }
143 147
144 if ( applnk->type() == "Separator" ) { // No tr 148 if ( applnk->type() == "Separator" ) { // No tr
145 menu->insertSeparator(); 149 menu->insertSeparator();
146 delete applnk; 150 delete applnk;
147 } else { 151 } else {
148 QPixmap test; 152 QPixmap pixmap = OResource::loadPixmap( applnk->icon(), OResource::SmallIcon );
149 QImage img = Resource::loadImage( applnk->icon() );
150 if(!img.isNull() )
151 test.convertFromImage(
152 img.smoothScale(
153 AppLnk::smallIconSize(), AppLnk::smallIconSize() ), 0 );
154
155 // Insert items ordered lexically 153 // Insert items ordered lexically
156 int current, left = 0, right = currentItem; 154 int current, left = 0, right = currentItem;
157 while( left != right ) { 155 while( left != right ) {
158 current = ( left + right ) / 2; 156 current = ( left + right ) / 2;
159 if ( menu->text(menu->idAt( ( current ) ) ) < applnk->name() ) 157 if ( menu->text(menu->idAt( ( current ) ) ) < applnk->name() )
160 left = ++current; 158 left = ++current;
161 else 159 else
162 right = current; 160 right = current;
163 } 161 }
164 162
165 menu->insertItem( test, applnk->name(), 163 menu->insertItem( pixmap, applnk->name(),
166 currentItem + APPLNK_ID_OFFSET, current ); 164 currentItem + APPLNK_ID_OFFSET, current );
167 appLnks.insert( currentItem + APPLNK_ID_OFFSET, applnk ); 165 appLnks.insert( currentItem + APPLNK_ID_OFFSET, applnk );
168 currentItem++; 166 currentItem++;
169 } 167 }
170 } 168 }
171 169
172} 170}
173 171
174void StartMenu::createDirEntry( QPopupMenu *menu, QDir dir, QString file, bool lot ) 172void StartMenu::createDirEntry( QPopupMenu *menu, QDir dir, QString file, bool lot )
175{ 173{
176 // do some sanity checks and collect information 174 // do some sanity checks and collect information
177 175
@@ -185,39 +183,36 @@ void StartMenu::createDirEntry( QPopupMenu *menu, QDir dir, QString file, bool l
185 if ( !name || !icon ) return; 183 if ( !name || !icon ) return;
186 184
187 QDir subdir = QDir( dir ); 185 QDir subdir = QDir( dir );
188 subdir.cd( file ); 186 subdir.cd( file );
189 subdir.setFilter( QDir::Files ); 187 subdir.setFilter( QDir::Files );
190 subdir.setNameFilter( "*.desktop" ); 188 subdir.setNameFilter( "*.desktop" );
191 // we don' t show the menu if there are no entries 189 // we don' t show the menu if there are no entries
192 // perhaps one should check if there exist subsubdirs with entries... 190 // perhaps one should check if there exist subsubdirs with entries...
193 if ( subdir.entryList().isEmpty() ) return; 191 if ( subdir.entryList().isEmpty() ) return;
194 192
195 // checks were ok 193 // checks were ok
196 194
197 QPixmap test; 195 QPixmap pixmap = OResource::loadPixmap( icon, OResource::SmallIcon );
198 test.convertFromImage( Resource::loadImage( icon ).smoothScale(
199 AppLnk::smallIconSize(), AppLnk::smallIconSize() ), 0 );
200
201 if ( useWidePopupMenu ) { 196 if ( useWidePopupMenu ) {
202 // generate submenu 197 // generate submenu
203 QPopupMenu *submenu = new QPopupMenu( menu ); 198 QPopupMenu *submenu = new QPopupMenu( menu );
204 connect( submenu, SIGNAL(activated(int)), SLOT(itemSelected(int)) ); 199 connect( submenu, SIGNAL(activated(int)), SLOT(itemSelected(int)) );
205 menu->insertItem( test, name, submenu, NO_ID ); 200 menu->insertItem( pixmap, name, submenu, NO_ID );
206 201
207 // ltabs is true cause else we wouldn't stuck around.. 202 // ltabs is true cause else we wouldn't stuck around..
208 createMenuEntries( submenu, subdir, true, lot ); 203 createMenuEntries( submenu, subdir, true, lot );
209 } else { 204 } else {
210 // no submenus - just bring corresponding tab to front 205 // no submenus - just bring corresponding tab to front
211 menu->insertItem( test, name, currentItem ); 206 menu->insertItem( pixmap, name, currentItem );
212 tabNames.insert( currentItem, new QString( file ) ); 207 tabNames.insert( currentItem, new QString( file ) );
213 currentItem++; 208 currentItem++;
214 } 209 }
215} 210}
216 211
217void StartMenu::createMenuEntries( QPopupMenu *menu, QDir dir, bool ltabs, bool lot ) 212void StartMenu::createMenuEntries( QPopupMenu *menu, QDir dir, bool ltabs, bool lot )
218{ 213{
219 if ( lot ) { 214 if ( lot ) {
220 dir.setFilter( QDir::Files ); 215 dir.setFilter( QDir::Files );
221 dir.setNameFilter( "*.desktop" ); 216 dir.setNameFilter( "*.desktop" );
222 QStringList files = dir.entryList(); 217 QStringList files = dir.entryList();
223 files.sort(); 218 files.sort();