3 * aka "2wm" - too weak menu, two week menu, akin to twm
5 * Craig wants a super minimal menu ASAP before launch, so lets see what I can put together in 2 weeks with not much
6 * free time ;) I'd like to do a fuller ('tiny', but with plugin support and a decent expansion and customizing design..)
11 /* mmenu - This is the actual menu
12 * The goal of this app is to show a application picker screen of some sort, allow the user to perform some useful
13 * activities (such as set clock speed, say), and request an app to run, or shutdown, etc.
14 * To keep the memory footprint down, when invoking an application, the menu _exits_, and simply spits out
15 * an operation for mmwrapper to perform. In the case of no wrapper, the menu will just exit, which is handy for
20 * 1) determine app list (via pnd scan, .desktop scan, whatever voodoo)
21 * 2) show a menu, allow user to interact:
22 * a) user picks an application to run, or -> exit, pass shell run line to wrapper
23 * b) user requests menu shutdown -> exit, tell wrapper to exit as well
24 * c) user performsn some operation (set clock, copy files, whatever) -> probably stays within the menu
33 #include <sys/types.h>
37 #include "pnd_logger.h"
39 #include "pnd_utility.h"
41 #include "pnd_container.h"
42 #include "pnd_discovery.h"
43 #include "pnd_locate.h"
44 #include "pnd_device.h"
47 #include "mmwrapcmd.h"
53 pnd_box_handle *g_active_apps = NULL;
54 unsigned int g_active_appcount = 0;
55 char g_username [ 128 ]; // since we have to wait for login (!!), store username here
56 pnd_conf_handle g_conf = 0;
58 char *pnd_run_script = NULL;
59 char *g_skinpath = NULL;
61 int main ( int argc, char *argv[] ) {
62 int logall = -1; // -1 means normal logging rules; >=0 means log all!
65 // boilerplate stuff from pndnotifyd and pndevmapperd
67 /* iterate across args
69 for ( i = 1; i < argc; i++ ) {
71 if ( argv [ i ][ 0 ] == '-' && argv [ i ][ 1 ] == 'l' ) {
73 if ( isdigit ( argv [ i ][ 2 ] ) ) {
74 unsigned char x = atoi ( argv [ i ] + 2 );
85 //printf ( "Unknown: %s\n", argv [ i ] );
86 printf ( "%s [-l##]\n", argv [ 0 ] );
87 printf ( "-l#\tLog-it; -l is 0-and-up (or all), and -l2 means 2-and-up (not all); l[0-3] for now. Log goes to /tmp/mmenu.log\n" );
88 printf ( "-f\tFull path of frontend to run\n" );
96 pnd_log_set_pretext ( "mmenu" );
97 pnd_log_set_flush ( 1 );
100 // standard logging; non-daemon versus daemon
102 #if 1 // HACK: set debug level to high on desktop, but not on pandora; just a convenience while devving, until the conf file is read
104 if ( stat ( PND_DEVICE_BATTERY_GAUGE_PERC, &statbuf ) == 0 ) {
106 pnd_log_set_filter ( pndn_error );
108 pnd_log_set_filter ( pndn_debug );
117 f = fopen ( "/tmp/mmenu.log", "w" );
120 pnd_log_set_filter ( logall );
121 pnd_log_to_stream ( f );
122 pnd_log ( pndn_rem, "logall mode - logging to /tmp/mmenu.log\n" );
125 if ( logall == pndn_debug ) {
126 pnd_log_set_buried_logging ( 1 ); // log the shit out of it
127 pnd_log ( pndn_rem, "logall mode 0 - turned on buried logging\n" );
132 pnd_log ( pndn_rem, "%s built %s %s", argv [ 0 ], __DATE__, __TIME__ );
134 pnd_log ( pndn_rem, "log level starting as %u", pnd_log_get_filter() );
136 // wait for a user to be logged in - we should probably get hupped when a user logs in, so we can handle
137 // log-out and back in again, with SDs popping in and out between..
138 pnd_log ( pndn_rem, "Checking to see if a user is logged in\n" );
140 if ( pnd_check_login ( g_username, 127 ) ) {
143 pnd_log ( pndn_debug, " No one logged in yet .. spinning.\n" );
146 pnd_log ( pndn_rem, "Looks like user '%s' is in, continue.\n", g_username );
150 g_conf = pnd_conf_fetch_by_name ( MMENU_CONF, MMENU_CONF_SEARCHPATH );
153 pnd_log ( pndn_error, "ERROR: Couldn't fetch conf file '%s'!\n", MMENU_CONF );
154 emit_and_quit ( MM_QUIT );
158 pnd_log_set_filter ( pnd_conf_get_as_int_d ( g_conf, "minimenu.loglevel", pndn_error ) );
164 pnd_run_script = pnd_locate_filename ( pnd_conf_get_as_char ( g_conf, "minimenu.pndrun" ), "pnd_run.sh" );
166 if ( ! pnd_run_script ) {
167 pnd_log ( pndn_error, "ERROR: Couldn't locate pnd_run.sh!\n" );
168 emit_and_quit ( MM_QUIT );
171 pnd_run_script = strdup ( pnd_run_script ); // so we don't lose it next pnd_locate
173 pnd_log ( pndn_rem, "Found pnd_run.sh at '%s'\n", pnd_run_script );
175 // figure out skin path
176 if ( ! pnd_conf_get_as_char ( g_conf, MMENU_ARTPATH ) ||
177 ! pnd_conf_get_as_char ( g_conf, "minimenu.font" )
180 pnd_log ( pndn_error, "ERROR: Couldn't set up skin!\n" );
181 emit_and_quit ( MM_QUIT );
184 g_skinpath = pnd_locate_filename ( pnd_conf_get_as_char ( g_conf, MMENU_ARTPATH ),
185 pnd_conf_get_as_char ( g_conf, "minimenu.font" ) );
187 if ( ! g_skinpath ) {
188 pnd_log ( pndn_error, "ERROR: Couldn't locate skin font!\n" );
189 emit_and_quit ( MM_QUIT );
192 g_skinpath = strdup ( g_skinpath ); // so we don't lose it next pnd_locate
194 * strstr ( g_skinpath, pnd_conf_get_as_char ( g_conf, "minimenu.font" ) ) = '\0';
196 pnd_log ( pndn_debug, "Looks like skin is at '%s'\n", g_skinpath );
198 // attempt to set up UI
199 if ( ! ui_setup() ) {
200 pnd_log ( pndn_error, "ERROR: Couldn't set up the UI!\n" );
201 emit_and_quit ( MM_QUIT );
207 // set up static image cache
208 if ( ! ui_imagecache ( g_skinpath ) ) {
209 pnd_log ( pndn_error, "ERROR: Couldn't set up static UI image cache!\n" );
210 emit_and_quit ( MM_QUIT );
213 /* inhale applications, icons, categories, etc
217 ui_discoverscreen ( 1 /* clear screen */ );
219 // determine current app list, cache icons
220 pnd_log ( pndn_debug, "Looking for pnd applications here: %s\n", pnd_conf_get_as_char ( g_conf, MMENU_APP_SEARCHPATH ) );
221 g_active_apps = pnd_disco_search ( pnd_conf_get_as_char ( g_conf, MMENU_APP_SEARCHPATH ), NULL ); // ignore overrides for now
222 g_active_appcount = pnd_box_get_size ( g_active_apps );
224 unsigned char maxwidth, maxheight;
225 maxwidth = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_ICON_MAX_WIDTH, 50 );
226 maxheight = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_ICON_MAX_HEIGHT, 50 );
229 ui_cachescreen ( 1 /* clear screen */, NULL );
231 pnd_log ( pndn_debug, "Found pnd applications, and caching icons:\n" );
232 pnd_disco_t *iter = pnd_box_get_head ( g_active_apps );
234 //pnd_log ( pndn_debug, " App: '%s'\n", IFNULL(iter->title_en,"No Name") );
236 // update cachescreen
237 ui_cachescreen ( 1 /* clear screen */, IFNULL(iter->title_en,"No Name") );
240 if ( iter -> pnd_icon_pos &&
241 ! cache_icon ( iter, maxwidth, maxheight ) )
243 pnd_log ( pndn_warning, " Couldn't load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
246 // cache the preview --> SHOULD DEFER
247 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_now", 0 ) > 0 ) {
248 // load the preview pics now!
249 if ( iter -> preview_pic1 &&
250 ! cache_preview ( iter, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ), pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) ) )
252 pnd_log ( pndn_warning, " Couldn't load preview pic: '%s' -> '%s'\n", IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
256 // push to All category
257 // we do this first, so first category is always All
258 if ( ! category_push ( CATEGORY_ALL, iter ) ) {
259 pnd_log ( pndn_warning, " Couldn't categorize to All: '%s'\n", IFNULL(iter -> title_en, "No Name") );
262 // push the categories
266 if ( iter -> main_category && pnd_conf_get_as_int_d ( g_conf, "tabs.top_maincat", 1 ) ) {
267 if ( ! category_push ( iter -> main_category, iter ) ) {
268 pnd_log ( pndn_warning, " Couldn't categorize to %s: '%s'\n", iter -> main_category, IFNULL(iter -> title_en, "No Name") );
272 if ( iter -> main_category1 && pnd_conf_get_as_int_d ( g_conf, "tabs.top_maincat1", 0 ) ) {
273 if ( ! category_push ( iter -> main_category1, iter ) ) {
274 pnd_log ( pndn_warning, " Couldn't categorize to %s: '%s'\n", iter -> main_category1, IFNULL(iter -> title_en, "No Name") );
278 if ( iter -> main_category2 && pnd_conf_get_as_int_d ( g_conf, "tabs.top_maincat2", 0 ) ) {
279 if ( ! category_push ( iter -> main_category2, iter ) ) {
280 pnd_log ( pndn_warning, " Couldn't categorize to %s: '%s'\n", iter -> main_category2, IFNULL(iter -> title_en, "No Name") );
285 if ( iter -> alt_category && pnd_conf_get_as_int_d ( g_conf, "tabs.top_altcat", 0 ) ) {
286 if ( ! category_push ( iter -> alt_category, iter ) ) {
287 pnd_log ( pndn_warning, " Couldn't categorize to %s: '%s'\n", iter -> alt_category, IFNULL(iter -> title_en, "No Name") );
291 if ( iter -> alt_category1 && pnd_conf_get_as_int_d ( g_conf, "tabs.top_altcat1", 0 ) ) {
292 if ( ! category_push ( iter -> alt_category1, iter ) ) {
293 pnd_log ( pndn_warning, " Couldn't categorize to %s: '%s'\n", iter -> alt_category1, IFNULL(iter -> title_en, "No Name") );
297 if ( iter -> alt_category2 && pnd_conf_get_as_int_d ( g_conf, "tabs.top_altcat2", 0 ) ) {
298 if ( ! category_push ( iter -> alt_category2, iter ) ) {
299 pnd_log ( pndn_warning, " Couldn't categorize to %s: '%s'\n", iter -> alt_category2, IFNULL(iter -> title_en, "No Name") );
304 iter = pnd_box_get_next ( iter );
313 while ( 1 ) { // forever!
315 // show the menu, or changes thereof
316 ui_render ( CHANGED_NOTHING );
318 // wait for input or time-based events (like animations)
320 ui_process_input ( 1 /* block */ );
330 void emit_and_quit ( char *s ) {
331 printf ( "%s\n", s );