-rw-r--r-- | core/launcher/startmenu.cpp | 79 |
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,88 +1,92 @@ | |||
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> | ||
39 | using 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 | ||
45 | void StartPopupMenu::keyPressEvent( QKeyEvent *e ) | 49 | void 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 | ||
58 | StartMenu::StartMenu(QWidget *parent) : QLabel( parent ) | 62 | StartMenu::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 | ||
75 | void StartMenu::mousePressEvent( QMouseEvent * ) | 79 | void StartMenu::mousePressEvent( QMouseEvent * ) |
76 | { | 80 | { |
77 | launch(); | 81 | launch(); |
78 | } | 82 | } |
79 | 83 | ||
80 | 84 | ||
81 | StartMenu::~StartMenu() | 85 | StartMenu::~StartMenu() |
82 | { | 86 | { |
83 | clearApplets(); | 87 | clearApplets(); |
84 | } | 88 | } |
85 | 89 | ||
86 | void StartMenu::createMenu() | 90 | void StartMenu::createMenu() |
87 | { | 91 | { |
88 | clearApplets(); | 92 | clearApplets(); |
@@ -124,112 +128,103 @@ void StartMenu::itemSelected( int id ) | |||
124 | if ( appLnk ) { | 128 | if ( appLnk ) { |
125 | appLnk->execute(); | 129 | appLnk->execute(); |
126 | } | 130 | } |
127 | } else { | 131 | } else { |
128 | QString *tabName = tabNames.find( id ); | 132 | QString *tabName = tabNames.find( id ); |
129 | if ( tabName ) { | 133 | if ( tabName ) { |
130 | emit tabSelected( *tabName ); | 134 | emit tabSelected( *tabName ); |
131 | } | 135 | } |
132 | } | 136 | } |
133 | } | 137 | } |
134 | 138 | ||
135 | void StartMenu::createAppEntry( QPopupMenu *menu, QDir dir, QString file ) | 139 | 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 | ||
174 | void StartMenu::createDirEntry( QPopupMenu *menu, QDir dir, QString file, bool lot ) | 172 | void 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 | ||
178 | if ( file == "." || file == ".." ) return; | 176 | if ( file == "." || file == ".." ) return; |
179 | 177 | ||
180 | Config cfg( dir.path() + "/" + file + "/.directory", Config::File ); | 178 | Config cfg( dir.path() + "/" + file + "/.directory", Config::File ); |
181 | if ( !cfg.isValid() ) return; | 179 | if ( !cfg.isValid() ) return; |
182 | 180 | ||
183 | QString name = cfg.readEntry( "Name" ); | 181 | QString name = cfg.readEntry( "Name" ); |
184 | QString icon = cfg.readEntry( "Icon" ); | 182 | QString icon = cfg.readEntry( "Icon" ); |
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 | ||
217 | void StartMenu::createMenuEntries( QPopupMenu *menu, QDir dir, bool ltabs, bool lot ) | 212 | void 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(); |
224 | 219 | ||
225 | for ( QStringList::Iterator it = files.begin(); it != files.end(); it++ ) { | 220 | for ( QStringList::Iterator it = files.begin(); it != files.end(); it++ ) { |
226 | createAppEntry( menu, dir, *it ); | 221 | createAppEntry( menu, dir, *it ); |
227 | } | 222 | } |
228 | } | 223 | } |
229 | if ( ltabs ) { | 224 | if ( ltabs ) { |
230 | dir.setNameFilter( "*" ); | 225 | dir.setNameFilter( "*" ); |
231 | dir.setFilter( QDir::Dirs ); | 226 | dir.setFilter( QDir::Dirs ); |
232 | QStringList dirs = dir.entryList(); | 227 | QStringList dirs = dir.entryList(); |
233 | dirs.sort(); | 228 | dirs.sort(); |
234 | 229 | ||
235 | for ( QStringList::Iterator it = dirs.begin(); it != dirs.end(); it++ ) { | 230 | for ( QStringList::Iterator it = dirs.begin(); it != dirs.end(); it++ ) { |