* added myIconSize variable for SimpleLauncherApplet (will be configurable in future)
[simple-launcher] / simple-launcher.cc
index b30f5e8..5f36aae 100644 (file)
@@ -33,9 +33,8 @@
 
 #define SL_APPLET_DBUS_NAME  "simple-launcher"
 #define SL_APPLET_VERSION    "0.0"
-#define SL_APPLET_ICON_SIZE  26
-#define SL_APPLET_BORDER_SIZE  14
-#define SL_APPLET_CANVAS_SIZE  (SL_APPLET_BORDER_SIZE+SL_APPLET_BORDER_SIZE)
+
+#define SL_APPLET_GCONF_PATH  "/apps/simple-launcher"
 
 class SimpleLauncherApplet {
 public:
@@ -63,19 +62,27 @@ private:
   bool initWidget();
   void updateWidget();
 
-  void buttonClicked(GtkToolButton *);
+  void buttonPressed(GtkWidget *button, GdkEventButton *event);
   void runDialog();
 
-  static void _button_clicked(GtkToolButton *, void *);
+  static void _button_pressed(GtkWidget *button, GdkEventButton *event, void *self);
   static void _run_dialog(GtkMenuItem *, void *);
 
 private:
+  // GConfClientWrapper myClient;
+  // GConfKey myMainSettings;
+
   osso_context_t *myContext;
+
   GtkWidget *myWidget;
   GtkWindow *myParent;
 
   LauncherItems myItems;
 
+  bool myTransparent;
+  // bool myShowInfobanner; // FIXME: to implement
+  int myIconSize;
+
   static char *ourDirs[];
 };
 
@@ -125,7 +132,8 @@ char *SimpleLauncherApplet::ourDirs[] = {
   NULL
 };
 
-SimpleLauncherApplet::SimpleLauncherApplet(): myContext(NULL), myWidget(NULL), myParent(NULL) {
+// SimpleLauncherApplet::SimpleLauncherApplet() : myMainSettings(myClient.getKey(SL_APPLET_GCONF_PATH)), myContext(NULL), myWidget(NULL), myParent(NULL) {
+SimpleLauncherApplet::SimpleLauncherApplet() : myContext(NULL), myWidget(NULL), myParent(NULL), myTransparent(false), myIconSize(48) {
 }
 
 bool SimpleLauncherApplet::doInit(void *state_data, int *state_size) {
@@ -238,11 +246,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();
   }
 
@@ -250,50 +256,52 @@ bool SimpleLauncherApplet::initWidget() {
 }
 
 void SimpleLauncherApplet::updateWidget() {
-  GtkWidget *child = gtk_bin_get_child(GTK_BIN(myWidget));
+  gtk_container_foreach(GTK_CONTAINER(myWidget), (GtkCallback)gtk_widget_destroy, NULL);
 
-  if (child != NULL) {
-    gtk_container_remove(GTK_CONTAINER(myWidget), child);
-    gtk_widget_destroy(child);
-  }
+  GtkSizeGroup *group = gtk_size_group_new(GTK_SIZE_GROUP_BOTH);
 
   int button_no = 0;
-  GtkBox *box = GTK_BOX(gtk_hbox_new(true, 1));
 
   for (size_t i = 0 ; i < myItems.size() ; ++i) {
     LauncherItem *item = myItems[i];
 
     if (item != NULL && item->isEnabled()) {
-      GtkWidget *button = gtk_button_new();
+      GtkWidget *button = gtk_event_box_new();
+
+      gtk_widget_set_events(button, GDK_BUTTON_PRESS_MASK);
+      g_signal_connect(button, "button-press-event", G_CALLBACK(_button_pressed), this);
 
-      gtk_container_add(GTK_CONTAINER(button), gtk_image_new_from_pixbuf(item->getIcon(SL_APPLET_ICON_SIZE)));
+      gtk_event_box_set_visible_window(GTK_EVENT_BOX(button), !myTransparent);
+
+      gtk_container_add(GTK_CONTAINER(button), gtk_image_new_from_pixbuf(item->getIcon(myIconSize)));
 
       gtk_object_set_user_data(GTK_OBJECT(button), item);
-      g_signal_connect(button, "clicked", G_CALLBACK(_button_clicked), this);
 
-      gtk_box_pack_start(box, GTK_WIDGET(button), false, false, 0);
+      gtk_size_group_add_widget(group, button);
+
+      gtk_box_pack_start(GTK_BOX(myWidget), GTK_WIDGET(button), false, false, 0);
 
       ++button_no;
     }
   }
 
-  gtk_container_add(GTK_CONTAINER(myWidget), GTK_WIDGET(box));
+  g_object_unref(G_OBJECT(group));
 
   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);
+    gtk_widget_set_size_request(myWidget, myIconSize, myIconSize);
   } 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);
+    gtk_widget_set_size_request(myWidget, button_no*myIconSize, myIconSize);
   }
 
   gtk_widget_show_all(myWidget);
 }
 
-void SimpleLauncherApplet::_button_clicked(GtkToolButton *button, void *self) {
-  ((SimpleLauncherApplet *)self)->buttonClicked(button);
+void SimpleLauncherApplet::_button_pressed(GtkWidget *button, GdkEventButton *event, void *self) {
+  ((SimpleLauncherApplet *)self)->buttonPressed(button, event);
 }
 
-void SimpleLauncherApplet::buttonClicked(GtkToolButton *button) {
-  if (button != NULL) {
+void SimpleLauncherApplet::buttonPressed(GtkWidget *button, GdkEventButton *event) {
+  if (button != NULL && event->button == 1) {
     LaunchableItem *item = (LaunchableItem *)gtk_object_get_user_data(GTK_OBJECT(button));
 
     if (item != NULL) {
@@ -335,7 +343,7 @@ void SimpleLauncherApplet::runDialog() {
 
   LauncherItems newItems = myItems;
 
-  SettingsDialog dialog(myParent, SL_APPLET_ICON_SIZE, newItems);
+  SettingsDialog dialog(myParent, newItems);
 
   switch (dialog.run()) {
     case GTK_RESPONSE_OK: