-rw-r--r-- | core/launcher/startmenu.cpp | 171 |
1 files changed, 171 insertions, 0 deletions
diff --git a/core/launcher/startmenu.cpp b/core/launcher/startmenu.cpp new file mode 100644 index 0000000..54bdfcc --- a/dev/null +++ b/core/launcher/startmenu.cpp | |||
@@ -0,0 +1,171 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include "startmenu.h" | ||
22 | #include "sidething.h" | ||
23 | #include "mrulist.h" | ||
24 | #include "info.h" | ||
25 | |||
26 | #include <qpe/qpeapplication.h> | ||
27 | #include <qpe/config.h> | ||
28 | #include <qpe/applnk.h> | ||
29 | #include <qpe/global.h> | ||
30 | #include <qpe/resource.h> | ||
31 | |||
32 | #include <qdict.h> | ||
33 | |||
34 | #include <stdlib.h> | ||
35 | |||
36 | |||
37 | // #define USE_CONFIG_FILE | ||
38 | |||
39 | |||
40 | StartMenu::StartMenu(QWidget *parent) : QLabel( parent ) | ||
41 | { | ||
42 | loadOptions(); | ||
43 | |||
44 | setPixmap( Resource::loadPixmap( startButtonPixmap ) ); | ||
45 | setFocusPolicy( NoFocus ); | ||
46 | //setFlat( startButtonIsFlat ); | ||
47 | |||
48 | apps = new AppLnkSet( QPEApplication::qpeDir() + "apps" ); | ||
49 | |||
50 | createMenu(); | ||
51 | } | ||
52 | |||
53 | |||
54 | void StartMenu::mousePressEvent( QMouseEvent * ) | ||
55 | { | ||
56 | launch(); | ||
57 | if (desktopInfo) | ||
58 | desktopInfo->menuClicked(); | ||
59 | } | ||
60 | |||
61 | |||
62 | StartMenu::~StartMenu() | ||
63 | { | ||
64 | delete apps; | ||
65 | } | ||
66 | |||
67 | |||
68 | void StartMenu::loadOptions() | ||
69 | { | ||
70 | #ifdef USE_CONFIG_FILE | ||
71 | // Read configuration file | ||
72 | Config config("StartMenu"); | ||
73 | config.setGroup( "StartMenu" ); | ||
74 | QString tmpBoolString1 = config.readEntry( "UseWidePopupMenu", "FALSE" ); | ||
75 | useWidePopupMenu = ( tmpBoolString1 == "TRUE" ) ? TRUE : FALSE; | ||
76 | QString tmpBoolString2 = config.readEntry( "StartButtonIsFlat", "TRUE" ); | ||
77 | startButtonIsFlat = ( tmpBoolString2 == "TRUE" ) ? TRUE : FALSE; | ||
78 | QString tmpBoolString3 = config.readEntry( "UseMRUList", "TRUE" ); | ||
79 | popupMenuSidePixmap = config.readEntry( "PopupMenuSidePixmap", "sidebar" ); | ||
80 | startButtonPixmap = config.readEntry( "StartButtonPixmap", "go" ); | ||
81 | #else | ||
82 | // Basically just #include the .qpe_menu.conf file settings | ||
83 | useWidePopupMenu = FALSE; | ||
84 | popupMenuSidePixmap = "sidebar"; | ||
85 | startButtonIsFlat = TRUE; | ||
86 | startButtonPixmap = "go"; | ||
87 | #endif | ||
88 | } | ||
89 | |||
90 | |||
91 | void StartMenu::createMenu() | ||
92 | { | ||
93 | if ( useWidePopupMenu ) | ||
94 | launchMenu = new PopupWithLaunchSideThing( this, &popupMenuSidePixmap ); | ||
95 | else | ||
96 | launchMenu = new StartPopupMenu( this ); | ||
97 | |||
98 | loadMenu( apps, launchMenu ); | ||
99 | |||
100 | } | ||
101 | |||
102 | void StartMenu::itemSelected( int id ) | ||
103 | { | ||
104 | const AppLnk *app = apps->find( id ); | ||
105 | if ( app ) | ||
106 | app->execute(); | ||
107 | } | ||
108 | |||
109 | bool StartMenu::loadMenu( AppLnkSet *folder, QPopupMenu *menu ) | ||
110 | { | ||
111 | bool result = FALSE; | ||
112 | |||
113 | QStringList typs = folder->types(); | ||
114 | QDict<QPopupMenu> typpop; | ||
115 | for (QStringList::Iterator tit=typs.begin(); tit!=typs.end(); ++tit) { | ||
116 | if ( !(*tit).isEmpty() ) { | ||
117 | QPopupMenu *new_menu = new StartPopupMenu( menu ); | ||
118 | typpop.insert(*tit, new_menu); | ||
119 | connect( new_menu, SIGNAL(activated(int)), SLOT(itemSelected(int)) ); | ||
120 | menu->insertItem( folder->typePixmap(*tit), *tit, new_menu ); | ||
121 | } | ||
122 | } | ||
123 | |||
124 | QListIterator<AppLnk> it( folder->children() ); | ||
125 | for ( ; it.current(); ++it ) { | ||
126 | AppLnk *app = it.current(); | ||
127 | if ( app->type() == "Separator" ) { | ||
128 | menu->insertSeparator(); | ||
129 | } else { | ||
130 | QString t = app->type(); | ||
131 | QPopupMenu* pmenu = typpop.find(t); | ||
132 | if ( !pmenu ) | ||
133 | pmenu = menu; | ||
134 | pmenu->insertItem( app->pixmap(), app->name(), app->id() ); | ||
135 | result=TRUE; | ||
136 | } | ||
137 | } | ||
138 | |||
139 | if ( result ) | ||
140 | connect( menu, SIGNAL(activated(int)), SLOT(itemSelected(int)) ); | ||
141 | |||
142 | return result; | ||
143 | } | ||
144 | |||
145 | |||
146 | void StartMenu::launch() | ||
147 | { | ||
148 | int y = mapToGlobal( QPoint() ).y() - launchMenu->sizeHint().height(); | ||
149 | |||
150 | if ( launchMenu->isVisible() ) | ||
151 | launchMenu->hide(); | ||
152 | else | ||
153 | launchMenu->popup( QPoint( 1, y ) ); | ||
154 | } | ||
155 | |||
156 | const AppLnk* StartMenu::execToLink(const QString& appname) | ||
157 | { | ||
158 | const AppLnk* a = apps->findExec( appname ); | ||
159 | return a; | ||
160 | } | ||
161 | |||
162 | void StartPopupMenu::keyPressEvent( QKeyEvent *e ) | ||
163 | { | ||
164 | if ( e->key() == Key_F33 || e->key() == Key_Space ) { | ||
165 | // "OK" button, little hacky | ||
166 | QKeyEvent ke(QEvent::KeyPress, Key_Enter, 13, 0); | ||
167 | QPopupMenu::keyPressEvent( &ke ); | ||
168 | } else { | ||
169 | QPopupMenu::keyPressEvent( e ); | ||
170 | } | ||
171 | } | ||