made the main widget transparency-capable
[simple-launcher] / simple-launcher.cc
index 8c2e319..021d8ad 100644 (file)
@@ -29,6 +29,7 @@
 #include "launcher-item.h"
 #include "sla-list.h"
 #include "launchable-item.h"
+#include "settings-dialog.h"
 
 #define SL_APPLET_DBUS_NAME  "simple-launcher"
 #define SL_APPLET_VERSION    "0.0"
@@ -172,6 +173,7 @@ void SimpleLauncherApplet::addItem(LauncherItems& items, const std::string& name
   }
 }
 
+// FIXME: this probably should be done somehow differently
 static char *configFileName="/home/user/.slarc";
 
 void SimpleLauncherApplet::loadConfig() {
@@ -188,7 +190,6 @@ void SimpleLauncherApplet::loadConfig() {
       }
 
       addItem(myItems, buffer, (p != NULL && (*p == '1' || *p == 'y' || *p == 'Y')));
-
     }
 
     delete buffer;
@@ -237,11 +238,9 @@ void SimpleLauncherApplet::processDirectory(LauncherItems& items, const std::str
 }
 
 bool SimpleLauncherApplet::initWidget() {
-  myWidget = gtk_frame_new(NULL);
+  myWidget = gtk_hbox_new(false, 0);
 
   if (myWidget != NULL) {
-    gtk_frame_set_shadow_type(GTK_FRAME(myWidget), GTK_SHADOW_ETCHED_IN);
-
     updateWidget();
   }
 
@@ -249,40 +248,34 @@ bool SimpleLauncherApplet::initWidget() {
 }
 
 void SimpleLauncherApplet::updateWidget() {
-  GtkWidget *child = gtk_bin_get_child(GTK_BIN(myWidget));
-
-  if (child != NULL) {
-    gtk_container_remove(GTK_CONTAINER(myWidget), child);
-    gtk_widget_destroy(child);
-  }
+  gtk_container_foreach(GTK_CONTAINER(myWidget), (GtkCallback)gtk_widget_destroy, NULL);
 
   int button_no = 0;
-  GtkToolbar *toolbar = GTK_TOOLBAR(gtk_toolbar_new());
 
   for (size_t i = 0 ; i < myItems.size() ; ++i) {
     LauncherItem *item = myItems[i];
 
     if (item != NULL && item->isEnabled()) {
-      GtkToolItem *button = gtk_tool_button_new(gtk_image_new_from_pixbuf(item->getIcon(SL_APPLET_ICON_SIZE)), NULL);
+      GtkWidget *button = gtk_button_new();
+
+      // gtk_button_set_relief(GTK_BUTTON(button),GTK_RELIEF_NONE);
+      gtk_button_set_focus_on_click(GTK_BUTTON(button),FALSE);
+
+      gtk_container_add(GTK_CONTAINER(button), gtk_image_new_from_pixbuf(item->getIcon(SL_APPLET_ICON_SIZE)));
 
       gtk_object_set_user_data(GTK_OBJECT(button), item);
       g_signal_connect(button, "clicked", G_CALLBACK(_button_clicked), this);
 
-      gtk_toolbar_insert(toolbar, button, -1);
+      gtk_box_pack_start(GTK_BOX(myWidget), GTK_WIDGET(button), false, false, 0);
 
       ++button_no;
     }
   }
 
-  if (button_no) {
-    gtk_container_add(GTK_CONTAINER(myWidget), GTK_WIDGET(toolbar));
-    if (button_no == 0) {
-      gtk_widget_set_size_request(myWidget, SL_APPLET_ICON_SIZE+SL_APPLET_CANVAS_SIZE, SL_APPLET_ICON_SIZE+SL_APPLET_CANVAS_SIZE);
-    } else {
-      gtk_widget_set_size_request(myWidget, button_no*(SL_APPLET_ICON_SIZE+SL_APPLET_CANVAS_SIZE), SL_APPLET_ICON_SIZE+SL_APPLET_CANVAS_SIZE);
-    }
+  if (button_no == 0) {
+    gtk_widget_set_size_request(myWidget, SL_APPLET_ICON_SIZE+SL_APPLET_CANVAS_SIZE, SL_APPLET_ICON_SIZE+SL_APPLET_CANVAS_SIZE);
   } else {
-    gtk_widget_destroy(GTK_WIDGET(toolbar));
+    gtk_widget_set_size_request(myWidget, button_no*(SL_APPLET_ICON_SIZE+SL_APPLET_CANVAS_SIZE), SL_APPLET_ICON_SIZE+SL_APPLET_CANVAS_SIZE);
   }
 
   gtk_widget_show_all(myWidget);
@@ -315,10 +308,6 @@ int SimpleLauncherApplet::saveState(void **state_data, int *state_size) {
 }
 
 GtkWidget *SimpleLauncherApplet::settings(GtkWindow *parent) {
-  // TODO: in case we want SimpleLauncherApplet to be configurable, this method
-  // should return a gtk_menu_item that would be included in home settings
-  // menu.  Method should make sure that when we activate that item, a
-  // corresponding dialog appears.
   myParent = parent;  // FIXME: Ugly piece of code :(
 
   GtkWidget *menuItem = gtk_menu_item_new_with_label("Launcher settings...");
@@ -333,23 +322,15 @@ void SimpleLauncherApplet::_run_dialog(GtkMenuItem *, void *self) {
 }
 
 void SimpleLauncherApplet::runDialog() {
-  LauncherItems newItems = myItems;
-
-  updateItems(newItems);  // User requested 'settings', let's give her the latest stuff :)
-
-  SLAList list(SL_APPLET_ICON_SIZE, newItems);
-
-  GtkDialog *dialog = GTK_DIALOG(gtk_dialog_new_with_buttons("Launcher Settings", myParent, (GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT), "OK", GTK_RESPONSE_OK, "Cancel", GTK_RESPONSE_CANCEL, NULL));
+  // We update the items before using them to avoid a small memory leak
+  // FIXME: deal with the situation in a better way (figure it out first :))
+  updateItems(myItems);       // User requested 'settings', let's give her the latest stuff :)
 
-  gtk_container_add(GTK_CONTAINER(dialog->vbox), list.getWidget());
-
-  gtk_widget_set_size_request(GTK_WIDGET(dialog), 540, 257);
-
-  int response = gtk_dialog_run(dialog);
+  LauncherItems newItems = myItems;
 
-  gtk_widget_destroy(GTK_WIDGET(dialog));
+  SettingsDialog dialog(myParent, SL_APPLET_ICON_SIZE, newItems);
 
-  switch (response) {
+  switch (dialog.run()) {
     case GTK_RESPONSE_OK:
       myItems = newItems;
       saveConfig();   // save it immediately!