X-Git-Url: http://git.maemo.org/git/?p=simple-launcher;a=blobdiff_plain;f=simple-launcher.cc;h=c20c886bf41fadabf2a00fc7221c293388af116e;hp=fd82294532320ef4dca02a58313d24f52c175277;hb=9d678e60480b6c411ce4ba134ce6b553d98dd9a6;hpb=6026044c12cda563008119b08e34b28de0fdbdbf diff --git a/simple-launcher.cc b/simple-launcher.cc index fd82294..c20c886 100644 --- a/simple-launcher.cc +++ b/simple-launcher.cc @@ -23,22 +23,36 @@ #include -#include #include #include "launcher-item.h" -#include "sla-list.h" #include "launchable-item.h" #include "settings-dialog.h" +#include "gconf-wrapper.h" #define SL_APPLET_DBUS_NAME "simple-launcher" #define SL_APPLET_VERSION "0.0" #define SL_APPLET_GCONF_PATH "/apps/simple-launcher" +// A copy of interface functions from hildon-home-plugin-interface (new hildon desktop does not have it) {{{ + +extern "C" { + + void *hildon_home_applet_lib_initialize(void *state_data, int *state_size, GtkWidget **widget); + int hildon_home_applet_lib_save_state(void *applet_data, void **state_data, int *state_size); + void hildon_home_applet_lib_background(void *applet_data); + void hildon_home_applet_lib_foreground(void *applet_data); + void hildon_home_applet_lib_deinitialize(void *applet_data); + GtkWidget *hildon_home_applet_lib_settings(void *applet_data, GtkWindow *parent); + +}; + +// }}} + class SimpleLauncherApplet { public: - SimpleLauncherApplet(); + SimpleLauncherApplet(const GConfKey&); ~SimpleLauncherApplet(); bool doInit(void *state_data, int *state_size); @@ -79,9 +93,9 @@ private: LauncherItems myItems; - bool myTransparent; + GConfBooleanOption myTransparent; // bool myShowInfobanner; // FIXME: to implement - int myIconSize; + GConfIntegerOption myIconSize; static char *ourDirs[]; }; @@ -89,7 +103,9 @@ private: // Hildon home applet interface functions void *hildon_home_applet_lib_initialize(void *state_data, int *state_size, GtkWidget **widget) { - SimpleLauncherApplet *applet = new SimpleLauncherApplet(); + GConfKey baseKey(SL_APPLET_GCONF_PATH); + + SimpleLauncherApplet *applet = new SimpleLauncherApplet(baseKey); if (applet != NULL) { if (applet->doInit(state_data, state_size)) { @@ -133,7 +149,7 @@ char *SimpleLauncherApplet::ourDirs[] = { }; // SimpleLauncherApplet::SimpleLauncherApplet() : myMainSettings(myClient.getKey(SL_APPLET_GCONF_PATH)), myContext(NULL), myWidget(NULL), myParent(NULL) { -SimpleLauncherApplet::SimpleLauncherApplet() : myContext(NULL), myWidget(NULL), myParent(NULL), myTransparent(true), myIconSize(48) { +SimpleLauncherApplet::SimpleLauncherApplet(const GConfKey& base) : myContext(NULL), myWidget(NULL), myParent(NULL), myTransparent(base, "transparent", false), myIconSize(base, "icon_size", 48) { } bool SimpleLauncherApplet::doInit(void *state_data, int *state_size) { @@ -153,12 +169,13 @@ bool SimpleLauncherApplet::doInit(void *state_data, int *state_size) { SimpleLauncherApplet::~SimpleLauncherApplet() { myItems.clear(); - +#if 0 + // This does not seem to be necessary if (myWidget != NULL) { gtk_widget_destroy(myWidget); myWidget = NULL; } - +#endif if (myContext != NULL) { osso_deinitialize(myContext); myContext = NULL; @@ -181,11 +198,19 @@ void SimpleLauncherApplet::addItem(LauncherItems& items, const std::string& name } } -// FIXME: this probably should be done somehow differently -static char *configFileName="/home/user/.slarc"; +// {{{ Configuration file managment +static const gchar *getConfigFileName() { + static gchar *configFileName = NULL; + + if (configFileName == NULL) { + configFileName = g_build_filename(g_get_home_dir(), ".slarc", NULL); + } + + return configFileName; +} void SimpleLauncherApplet::loadConfig() { - std::ifstream config(configFileName); + std::ifstream config(getConfigFileName()); if (config) { char *buffer = new char [1024]; @@ -200,13 +225,13 @@ void SimpleLauncherApplet::loadConfig() { addItem(myItems, buffer, (p != NULL && (*p == '1' || *p == 'y' || *p == 'Y'))); } - delete buffer; + delete [] buffer; } } void SimpleLauncherApplet::saveConfig() { // TODO: make saving config an atomic operation - std::ofstream config(configFileName); + std::ofstream config(getConfigFileName()); if (config) { for (size_t i = 0 ; i < myItems.size() ; ++i) { @@ -215,6 +240,8 @@ void SimpleLauncherApplet::saveConfig() { } } +// }}} + void SimpleLauncherApplet::updateItems(LauncherItems& items) { for (int i = 0 ; ourDirs[i] != NULL ; ++i) { processDirectory(items, ourDirs[i]); @@ -246,7 +273,7 @@ void SimpleLauncherApplet::processDirectory(LauncherItems& items, const std::str } bool SimpleLauncherApplet::initWidget() { - myWidget = gtk_hbox_new(false, 0); + myWidget = gtk_hbox_new(false, 2); if (myWidget != NULL) { updateWidget(); @@ -271,10 +298,10 @@ void SimpleLauncherApplet::updateWidget() { gtk_widget_set_events(button, GDK_BUTTON_PRESS_MASK); g_signal_connect(button, "button-press-event", G_CALLBACK(_button_pressed), this); - gtk_event_box_set_visible_window(GTK_EVENT_BOX(button), !myTransparent); + gtk_event_box_set_visible_window(GTK_EVENT_BOX(button), !myTransparent.value()); { - GdkPixbuf *pixbuf = item->getIcon(myIconSize); + GdkPixbuf *pixbuf = item->getIcon(myIconSize.value()); gtk_container_add(GTK_CONTAINER(button), gtk_image_new_from_pixbuf(pixbuf)); g_object_unref(G_OBJECT(pixbuf)); } @@ -291,10 +318,12 @@ void SimpleLauncherApplet::updateWidget() { g_object_unref(G_OBJECT(group)); + int totalSize = myIconSize.value(); + if (button_no == 0) { - gtk_widget_set_size_request(myWidget, myIconSize, myIconSize); + gtk_widget_set_size_request(myWidget, totalSize, totalSize); } else { - gtk_widget_set_size_request(myWidget, button_no*myIconSize, myIconSize); + gtk_widget_set_size_request(myWidget, button_no*totalSize, totalSize); } gtk_widget_show_all(myWidget); @@ -347,11 +376,14 @@ void SimpleLauncherApplet::runDialog() { LauncherItems newItems = myItems; - SettingsDialog dialog(myParent, newItems); + // TODO: make it nicer... this code is ugly :( + SettingsDialog dialog(myParent, newItems, myTransparent, myIconSize); switch (dialog.run()) { case GTK_RESPONSE_OK: myItems = newItems; + dialog.updateValues(); // FIXME: hackish :( make it better + saveConfig(); // save it immediately! updateWidget(); break; @@ -362,6 +394,8 @@ void SimpleLauncherApplet::runDialog() { default: ; // FIXME: do I want to do anything in here? } + + // newItems.clear(); // TODO: do I really need it? } // vim:ts=2:sw=2:et