From 33367511af3bc46c5447e84a406c302ddea2d8d8 Mon Sep 17 00:00:00 2001 From: Carsten Haitzler Date: Tue, 6 Jan 2009 02:10:45 +0000 Subject: [PATCH] add 2 more pages to wizard - 1 to add .desktops for your user for apps that might not have them - if the app is installed, and to allow the user to select what goes in their ibar to start with. only .desktop files in ~/Desktop left to deal with. SVN revision: 38473 --- src/modules/wizard/Makefile.am | 14 +- src/modules/wizard/e_mod_main.c | 2 + src/modules/wizard/page_070.c | 288 ++++++++++++++++++++++++++------ src/modules/wizard/page_080.c | 158 ++++++++++++++++++ src/modules/wizard/page_200.c | 93 +++++++++++ 5 files changed, 499 insertions(+), 56 deletions(-) create mode 100644 src/modules/wizard/page_080.c create mode 100644 src/modules/wizard/page_200.c diff --git a/src/modules/wizard/Makefile.am b/src/modules/wizard/Makefile.am index ba920098a..0ebdff5f5 100644 --- a/src/modules/wizard/Makefile.am +++ b/src/modules/wizard/Makefile.am @@ -22,7 +22,9 @@ pkg_LTLIBRARIES = module.la \ page_010.la \ page_020.la \ page_030.la \ - page_070.la + page_070.la \ + page_080.la \ + page_200.la ### disabled because profile selector really does the job. code here just for ### informational purposes on how to make wizard pages @@ -79,5 +81,15 @@ page_070_la_LIBADD = @e_libs@ @dlopen_libs@ page_070_la_LDFLAGS = -module -avoid-version page_070_la_DEPENDENCIES = $(top_builddir)/config.h +page_080_la_SOURCES = page_080.c +page_080_la_LIBADD = @e_libs@ @dlopen_libs@ +page_080_la_LDFLAGS = -module -avoid-version +page_080_la_DEPENDENCIES = $(top_builddir)/config.h + +page_200_la_SOURCES = page_200.c +page_200_la_LIBADD = @e_libs@ @dlopen_libs@ +page_200_la_LDFLAGS = -module -avoid-version +page_200_la_DEPENDENCIES = $(top_builddir)/config.h + uninstall: rm -rf $(DESTDIR)$(libdir)/enlightenment/modules/$(MODULE) diff --git a/src/modules/wizard/e_mod_main.c b/src/modules/wizard/e_mod_main.c index 251110486..ca34cb2d7 100644 --- a/src/modules/wizard/e_mod_main.c +++ b/src/modules/wizard/e_mod_main.c @@ -95,6 +95,8 @@ e_modapi_init(E_Module *m) dlsym(handle, "wizard_page_hide"), dlsym(handle, "wizard_page_apply")); } + else + printf("%s\n", dlerror()); } ecore_list_next(files); } diff --git a/src/modules/wizard/page_070.c b/src/modules/wizard/page_070.c index 314989bac..2c619435f 100644 --- a/src/modules/wizard/page_070.c +++ b/src/modules/wizard/page_070.c @@ -4,9 +4,180 @@ #include "e.h" #include "e_mod_main.h" +typedef struct _App App; +struct _App +{ + const char *file; // must be unique - should normally be app name + const char *name, *generic, *comment; // fields we should provide + const char *exec; // the exec line + const char *icon; // icon file + const char *extra; // extra fields (tranlations etc.) + int found; +}; + +static App apps[] = +{ + { "firefox", "Firefox", "Web Browser", "Browse the Internet", + "firefox %u", "web_browser.png", + "StartupNotify=true\n" + "StartupWMClass=Firefox-bin\n" + "Categories=Application;Network;", + 0 }, + { "xterm", "XTerm", "Terminal", "Run commands in a shell", + "xterm", "xterm.png", + "StartupWMClass=XTerm\n" + "Categories=Utility;TerminalEmulator;", + 0 }, + { "eterm", "ETerm", "Terminal", "Run commands in a shell", + "Eterm", "xterm.png", + "StartupWMClass=Eterm\n" + "Categories=Utility;TerminalEmulator;", + 0 }, + { "sylpheed", "Sylpheed", "E-Mail Client", "Read and write E-Mail", + "sylpheed", "mail_client.png", + "StartupNotify=true\n" + "StartupWMClass=Sylpheed\n" + "Categories=Application;Network;", + 0 }, + { "xine", "Xine", "Movie Player", "Watch movies and videos", + "xine %U", "video_player.png", + "StartupWMClass=xine\n" + "Categories=Application;AudioVideo;Player;", + 0 }, + { "mplayer", "MPlayer", "Movie Player", "Watch movies and videos", + "mplayer %U", "video_player.png", + "StartupWMClass=MPlayer\n" + "Categories=Application;AudioVideo;Player;", + 0 }, + { "xmms", "XMMS", "Audio Player", "Listen to music", + "xmms %U", "audio_player.png", + "StartupWMClass=XMMS\n" + "Categories=Application;AudioVideo;Player;", + 0 }, + { "beep-media-player", "BMP", "Audio Player", "Listen to music", + "beep-media-player %U", "audio_player.png", + "StartupWMClass=Beep-Media-Player\n" + "Categories=Application;AudioVideo;Player;", + 0 }, + { "audacious", "Audacious", "Audio Player", "Listen to music", + "audacious %U", "audio_player.png", + "StartupWMClass=Audacious\n" + "Categories=Application;AudioVideo;Player;", + 0 }, + { "gqview", "GQView", "Image Viewer", "Look at photos", + "gqview %U", "image_viewer.png", + "StartupWMClass=GQView\n" + "Categories=Application;Graphics;Viewer;", + 0 }, + { "xjed", "X-Jed", "Text Editor", "Edit text files", + "xjed %U", "text_editor.png", + "StartupWMClass=XJed\n" + "Categories=Application;Utility;TextEditor;\n" + "MimeType=text/plain;", + 0 } + // FIXME: add more apps to search for to add .desktops for OR add to ibar. + // feel free to have a pretty big list here. only list from the above ones + // that have a executable installed. + // FIXME: make sure these .desktop handle MimteType lists like xjed + // FIXME: this might be nice moved into a set of sample .desktops that get + // loaded and parsed to make it easier to add more in some dir somewhere +}; + +static int +_cb_sort_desks(Efreet_Desktop *d1, Efreet_Desktop *d2) +{ + if (!d1->name) return 1; + if (!d2->name) return -1; + return strcmp(d1->name, d2->name); +} + +static void +_app_write(App *a) +{ + FILE *f; + char buf[PATH_MAX]; + + snprintf(buf, sizeof(buf), "%s/applications", + efreet_data_home_get()); + ecore_file_mkpath(buf); + snprintf(buf, sizeof(buf), "%s/applications/%s.desktop", + efreet_data_home_get(), a->file); + f = fopen(buf, "w"); + if (!f) return; + fprintf(f, + "[Desktop Entry]\n" + "Encoding=UTF-8\n" + "Type=Application\n" + "Name=%s\n" + "GenericName=%s\n" + "Comment=%s\n" + "Exec=%s\n" + "Icon=%s\n", + a->name, a->generic, a->comment, a->exec, a->icon); + if (a->extra) fprintf(f, "%s\n", a->extra); + fclose(f); + efreet_desktop_get(buf); +} + EAPI int wizard_page_init(E_Wizard_Page *pg) { + Ecore_List *desks = NULL; + int i; + + efreet_util_init(); + + desks = efreet_util_desktop_name_glob_list("*"); + if (desks) + { + Efreet_Desktop *desk; + + ecore_list_first_goto(desks); + while ((desk = ecore_list_next(desks))) + { + char dbuf[4096]; + + if (!desk->exec) continue; + if (sscanf(desk->exec, "%4000s", dbuf) == 1) + { + for (i = 0; i < (sizeof(apps) / sizeof(App)); i++) + { + if (apps[i].found == 0) + { + char abuf[4096]; + + if (sscanf(apps[i].exec, "%4000s", abuf) == 1) + { + char *p1, *p2; + + if (!ecore_file_app_installed(abuf)) + { + /* can't find exe - mark as not available */ + apps[i].found = -1; + } + else + { + p1 = strrchr(dbuf, '/'); + if (p1) p1++; + else p1 = dbuf; + p2 = strrchr(abuf, '/'); + if (p2) p2++; + else p2 = abuf; + if (!strcmp(p1, p2)) + /* mark as found in .desktops */ + apps[i].found = 2; + } + } + } + } + } + } + ecore_list_destroy(desks); + } + efreet_util_shutdown(); + // FIXME: list all apps and of the apps either already installed, or to be + // created, offer them to be added to ibar by default. (actually should be + // page_080) return 1; } EAPI int @@ -17,73 +188,80 @@ wizard_page_shutdown(E_Wizard_Page *pg) EAPI int wizard_page_show(E_Wizard_Page *pg) { - char buf[PATH_MAX]; - const char *homedir; + Evas_Object *o, *of, *ob, *li, *ck; + Evas_Coord mw, mh; + int i; + int appnum = 0; - if ((e_config_profile_get()) && (strlen(e_config_profile_get()) > 0)) + for (i = 0; i < (sizeof(apps) / sizeof(App)); i++) { - // delete profile - homedir = e_user_homedir_get(); - snprintf(buf, sizeof(buf), "%s/.e/e/config/%s", homedir, e_config_profile_get()); - printf("del %s\n", buf); - if (ecore_file_is_dir(buf)) ecore_file_recursive_rm(buf); + if (apps[i].found == 0) appnum++; } - // load profile as e_config - e_config_load(); - return 0; /* 1 == show ui, and wait for user, 0 == just continue */ + if (appnum == 0) return 0; + + o = e_widget_list_add(pg->evas, 1, 0); + e_wizard_title_set(_("Applications")); + + of = e_widget_framelist_add(pg->evas, _("Select Icons to Add"), 0); + + li = e_widget_list_add(pg->evas, 1, 0); + ob = e_widget_scrollframe_simple_add(pg->evas, li); + e_widget_min_size_set(ob, 140 * e_scale, 140 * e_scale); + + for (i = 0; i < (sizeof(apps) / sizeof(App)); i++) + { + if (apps[i].found == 0) + { + char *icon; + + apps[i].found = 1; + icon = efreet_icon_path_find(e_config->icon_theme, + apps[i].icon, 48); + ck = e_widget_check_icon_add(pg->evas, apps[i].name, + icon, 32 * e_scale, 32 * e_scale, + &(apps[i].found)); + if (icon) free(icon); + e_widget_list_object_append(li, ck, 1, 1, 0.0); + evas_object_show(ck); + } + } + + e_widget_min_size_get(li, &mw, &mh); + evas_object_resize(li, mw, mh); + + e_widget_framelist_object_append(of, ob); + e_widget_list_object_append(o, of, 1, 1, 0.5); + evas_object_show(ob); + evas_object_show(of); + evas_object_show(li); + + e_wizard_page_show(o); + + return 1; /* 1 == show ui, and wait for user, 0 == just continue */ } EAPI int wizard_page_hide(E_Wizard_Page *pg) { + int i; + + /* .desktops are actually written here. this is because page_080 needs them + * to exist in the efreet desktops list to select what is to go in ibar */ + for (i = 0; i < (sizeof(apps) / sizeof(App)); i++) + { + printf("%s %i\n", apps[i].name, apps[i].found); + if (apps[i].found == 1) + { + _app_write(&(apps[i])); + } + } evas_object_del(pg->data); return 1; } EAPI int wizard_page_apply(E_Wizard_Page *pg) { - char buf[PATH_MAX]; - const char *homedir; - - // setup ~/Desktop and ~/.e/e/fileman/favorites and - // ~/.e/e/applications/bar/default, maybe ~/.e/e/applications/startup/.order - - homedir = e_user_homedir_get(); - - // setup default .desktop files - snprintf(buf, sizeof(buf), "%s/applications", efreet_data_home_get()); - ecore_file_mkpath(buf); - snprintf(buf, sizeof(buf), - "gzip -d -c < %s/data/other/desktop_files.tar.gz | " - "(cd %s/applications/ ; tar -xkf -)", - e_prefix_data_get(), efreet_data_home_get()); - system(buf); - // setup ibar - snprintf(buf, sizeof(buf), - "gzip -d -c < %s/data/other/desktop_order.tar.gz | " - "(cd %s/.e/e/ ; tar -xkf -)", - e_prefix_data_get(), homedir); - system(buf); - - // setup fileman favorites - snprintf(buf, sizeof(buf), - "gzip -d -c < %s/data/other/efm_favorites.tar.gz | " - "(cd %s/.e/e/ ; tar -xkf -)", - e_prefix_data_get(), homedir); - system(buf); - // ~/Desktop - snprintf(buf, sizeof(buf), "%s/Desktop", homedir); - ecore_file_mkpath(buf); - // FIXME: ln -s the .desktop files in favorites - snprintf(buf, sizeof(buf), "%s/Desktop/home.desktop", homedir); - ecore_file_symlink("../.e/e/fileman/favorites/home.desktop", buf); - snprintf(buf, sizeof(buf), "%s/Desktop/root.desktop", homedir); - ecore_file_symlink("../.e/e/fileman/favorites/root.desktop", buf); - snprintf(buf, sizeof(buf), "%s/Desktop/tmp.desktop", homedir); - ecore_file_symlink("../.e/e/fileman/favorites/tmp.desktop", buf); - - // save the config now everyone has modified it - e_config_save(); - // restart e - e_sys_action_do(E_SYS_RESTART, NULL); + // FIXME: write ~/.e/e/applications/bar/default/.order + // which should contain whatever apps the user wants in their bar by + // default (should be page_080) return 1; } diff --git a/src/modules/wizard/page_080.c b/src/modules/wizard/page_080.c new file mode 100644 index 000000000..69888e572 --- /dev/null +++ b/src/modules/wizard/page_080.c @@ -0,0 +1,158 @@ +/* + * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2 + */ +#include "e.h" +#include "e_mod_main.h" + +static Eina_List *desktops = NULL; +static int *desktops_add = NULL; +static int desktops_num = 0; + +static int +_cb_sort_desks(Efreet_Desktop *d1, Efreet_Desktop *d2) +{ + if (!d1->name) return 1; + if (!d2->name) return -1; + return strcmp(d1->name, d2->name); +} + +EAPI int +wizard_page_init(E_Wizard_Page *pg) +{ + Ecore_List *desks = NULL; + int i; + + efreet_util_init(); + + desks = efreet_util_desktop_name_glob_list("*"); + if (desks) + { + Efreet_Desktop *desk; + + ecore_list_sort(desks, ECORE_COMPARE_CB(_cb_sort_desks), ECORE_SORT_MIN); + ecore_list_first_goto(desks); + while ((desk = ecore_list_next(desks))) + { + char dbuf[4096]; + + if (!desk->exec) continue; + efreet_desktop_ref(desk); + desktops = eina_list_append(desktops, desk); + } + ecore_list_destroy(desks); + } + efreet_util_shutdown(); + if (desktops) + { + desktops_num = eina_list_count(desktops); + desktops_add = calloc(sizeof(int), desktops_num); + } + return 1; +} +EAPI int +wizard_page_shutdown(E_Wizard_Page *pg) +{ + return 1; +} +EAPI int +wizard_page_show(E_Wizard_Page *pg) +{ + Evas_Object *o, *of, *ob, *li, *ck; + Evas_Coord mw, mh; + Eina_List *l; + int i; + + printf("desktops = %p\n", desktops); + if (!desktops) return 0; + + o = e_widget_list_add(pg->evas, 1, 0); + e_wizard_title_set(_("IBar Quick Launch")); + + of = e_widget_framelist_add(pg->evas, _("Select Applications"), 0); + + li = e_widget_list_add(pg->evas, 1, 0); + ob = e_widget_scrollframe_simple_add(pg->evas, li); + e_widget_min_size_set(ob, 140 * e_scale, 140 * e_scale); + + for (i = 0, l = desktops; l ; l = l->next, i++) + { + Efreet_Desktop *desk; + char *icon; + + desk = l->data; + icon = NULL; + if (desk->icon) + icon = efreet_icon_path_find(e_config->icon_theme, + desk->icon, 48); + ck = e_widget_check_icon_add(pg->evas, desk->name, + icon, 32 * e_scale, 32 * e_scale, + &(desktops_add[i])); + if (icon) free(icon); + e_widget_list_object_append(li, ck, 1, 1, 0.0); + evas_object_show(ck); + } + + e_widget_min_size_get(li, &mw, &mh); + evas_object_resize(li, mw, mh); + + e_widget_framelist_object_append(of, ob); + e_widget_list_object_append(o, of, 1, 1, 0.5); + evas_object_show(ob); + evas_object_show(of); + evas_object_show(li); + + e_wizard_page_show(o); + + return 1; /* 1 == show ui, and wait for user, 0 == just continue */ +} +EAPI int +wizard_page_hide(E_Wizard_Page *pg) +{ + evas_object_del(pg->data); + return 1; +} +EAPI int +wizard_page_apply(E_Wizard_Page *pg) +{ + Eina_List *l; + int i; + FILE *f; + char buf[PATH_MAX]; + const char *homedir; + + homedir = e_user_homedir_get(); + snprintf(buf, sizeof(buf), "%s/.e/e/applications/bar/default", homedir); + ecore_file_mkpath(buf); + snprintf(buf, sizeof(buf), "%s/.e/e/applications/bar/default/.order", homedir); + f = fopen(buf, "w"); + if (f) + { + for (i = 0, l = desktops; l ; l = l->next, i++) + { + if (desktops_add[i]) + { + Efreet_Desktop *desk; + char *p; + + desk = l->data; + p = strrchr(desk->orig_path, '/'); + if (!p) p = desk->orig_path; + else p++; + fprintf(f, "%s\n", p); + } + } + fclose(f); + } + while (desktops) + { + efreet_desktop_free(desktops->data); + desktops = eina_list_remove_list(desktops, desktops); + } + if (desktops_add) + { + free(desktops_add); + desktops_add = NULL; + } + desktops_num = 0; + return 1; +} diff --git a/src/modules/wizard/page_200.c b/src/modules/wizard/page_200.c new file mode 100644 index 000000000..b6bd09512 --- /dev/null +++ b/src/modules/wizard/page_200.c @@ -0,0 +1,93 @@ +/* + * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2 + */ +#include "e.h" +#include "e_mod_main.h" + +EAPI int +wizard_page_init(E_Wizard_Page *pg) +{ + return 1; +} +EAPI int +wizard_page_shutdown(E_Wizard_Page *pg) +{ + return 1; +} +EAPI int +wizard_page_show(E_Wizard_Page *pg) +{ + char buf[PATH_MAX]; + const char *homedir; + + if ((e_config_profile_get()) && (strlen(e_config_profile_get()) > 0)) + { + // delete profile + homedir = e_user_homedir_get(); + snprintf(buf, sizeof(buf), "%s/.e/e/config/%s", homedir, e_config_profile_get()); + printf("del %s\n", buf); + if (ecore_file_is_dir(buf)) ecore_file_recursive_rm(buf); + } + // load profile as e_config + e_config_load(); + return 0; /* 1 == show ui, and wait for user, 0 == just continue */ +} +EAPI int +wizard_page_hide(E_Wizard_Page *pg) +{ + evas_object_del(pg->data); + return 1; +} +EAPI int +wizard_page_apply(E_Wizard_Page *pg) +{ + char buf[PATH_MAX]; + const char *homedir; + + // setup ~/Desktop and ~/.e/e/fileman/favorites and + // ~/.e/e/applications/bar/default, maybe ~/.e/e/applications/startup/.order + + homedir = e_user_homedir_get(); + + // FIXME: this is going into page 070 + // setup default .desktop files +// snprintf(buf, sizeof(buf), "%s/applications", efreet_data_home_get()); +// ecore_file_mkpath(buf); +// snprintf(buf, sizeof(buf), +// "gzip -d -c < %s/data/other/desktop_files.tar.gz | " +// "(cd %s/applications/ ; tar -xkf -)", +// e_prefix_data_get(), efreet_data_home_get()); +// system(buf); + // FIXME: this is going into page 070 + // setup ibar +// snprintf(buf, sizeof(buf), +// "gzip -d -c < %s/data/other/desktop_order.tar.gz | " +// "(cd %s/.e/e/ ; tar -xkf -)", +// e_prefix_data_get(), homedir); +// system(buf); + + // FIXME: should become a wizard page on its own + // setup fileman favorites + snprintf(buf, sizeof(buf), + "gzip -d -c < %s/data/other/efm_favorites.tar.gz | " + "(cd %s/.e/e/ ; tar -xkf -)", + e_prefix_data_get(), homedir); + system(buf); + // FIXME: efm favorites linked to desktop should be an option in another + // wizard page + // ~/Desktop + snprintf(buf, sizeof(buf), "%s/Desktop", homedir); + ecore_file_mkpath(buf); + snprintf(buf, sizeof(buf), "%s/Desktop/home.desktop", homedir); + ecore_file_symlink("../.e/e/fileman/favorites/home.desktop", buf); + snprintf(buf, sizeof(buf), "%s/Desktop/root.desktop", homedir); + ecore_file_symlink("../.e/e/fileman/favorites/root.desktop", buf); + snprintf(buf, sizeof(buf), "%s/Desktop/tmp.desktop", homedir); + ecore_file_symlink("../.e/e/fileman/favorites/tmp.desktop", buf); + + // save the config now everyone has modified it + e_config_save(); + // restart e + e_sys_action_do(E_SYS_RESTART, NULL); + return 1; +}