[svn-buildpackage] Tagging simple-launcher (0.7)
[simple-launcher] / simple-launcher.cc
index c2a08de..7b72077 100644 (file)
@@ -3,8 +3,8 @@
 // Copyright (C) 2006, Mikhail Sobolev
 //
 // Simple Launcher is free software; you can redistribute it and/or modify it
-// under the terms of the GNU General Public License as published by the Free
-// Software Foundation; either version 2 of the License.
+// under the terms of the GNU General Public License version 2 as published by
+// the Free Software Foundation.
 //
 // This program is distributed in the hope that it will be useful, but WITHOUT
 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 #include <libosso.h>
 
 #include "launcher-item.h"
+#include "sla-list.h"
+#include "launchable-item.h"
 
-#define SLA_APPLET_DBUS_NAME  "simple-launcher"
-#define SLA_APPLET_VERSION    "0.0"
-#define SLA_APPLET_ICON_SIZE  26
-#define SLA_APPLET_BORDER_SIZE  14
-#define SLA_APPLET_CANVAS_SIZE  (SLA_APPLET_BORDER_SIZE+SLA_APPLET_BORDER_SIZE)
+#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)
 
 class SimpleLauncherApplet {
 public:
@@ -59,7 +61,7 @@ private:
   GtkWidget *myWidget;
   GtkWindow *myParent;
 
-  std::vector<LauncherItem *> myItems;
+  LaunchableItems myItems;
 
   static char *ourFiles[];
 };
@@ -119,7 +121,7 @@ SimpleLauncherApplet::SimpleLauncherApplet(): myContext(0), myWidget(0), myParen
 }
 
 bool SimpleLauncherApplet::doInit(void *state_data, int *state_size) {
-  if ((myContext = osso_initialize(SLA_APPLET_DBUS_NAME, SLA_APPLET_VERSION, FALSE, 0)) == 0) {
+  if ((myContext = osso_initialize(SL_APPLET_DBUS_NAME, SL_APPLET_VERSION, FALSE, 0)) == 0) {
     g_debug("sla-applet: failed to initialize the osso layer");
     return false;
   }
@@ -128,7 +130,7 @@ bool SimpleLauncherApplet::doInit(void *state_data, int *state_size) {
     LauncherItem *item = new LauncherItem();
 
     if (item->load(ourFiles[i])) {
-      myItems.push_back(item);
+      myItems.push_back(std::pair<std::string, LaunchableItem *>(ourFiles[i], new LaunchableItem(item, true)));
     } else {
       delete item;
     }
@@ -144,10 +146,10 @@ bool SimpleLauncherApplet::doInit(void *state_data, int *state_size) {
 }
 
 SimpleLauncherApplet::~SimpleLauncherApplet() {
-  for (std::vector<LauncherItem *>::iterator it = myItems.begin(); it != myItems.end(); ++it) {
-    if (*it != 0) {
-      delete *it;
-      *it = 0;
+  for (LaunchableItems::iterator it = myItems.begin(); it != myItems.end(); ++it) {
+    if (it->second != 0) {
+      delete it->second;
+      it->second = 0;
     }
   }
 
@@ -169,10 +171,10 @@ bool SimpleLauncherApplet::initWidget() {
 
   GtkToolbar *toolbar = GTK_TOOLBAR(gtk_toolbar_new());
 
-  for (std::vector<LauncherItem *>::const_iterator it = myItems.begin(); it != myItems.end(); ++it) {
-    GtkToolItem *button = gtk_tool_button_new(gtk_image_new_from_pixbuf((*it)->getIcon(SLA_APPLET_ICON_SIZE)), 0);
+  for (LaunchableItems::const_iterator it = myItems.begin(); it != myItems.end(); ++it) {
+    GtkToolItem *button = gtk_tool_button_new(gtk_image_new_from_pixbuf(it->second->getIcon(SL_APPLET_ICON_SIZE)), 0);
 
-    gtk_object_set_user_data(GTK_OBJECT(button), *it);
+    gtk_object_set_user_data(GTK_OBJECT(button), it->second);
     g_signal_connect(button, "clicked", G_CALLBACK(_button_clicked), this);
 
     gtk_toolbar_insert(toolbar, button, -1);
@@ -183,7 +185,7 @@ bool SimpleLauncherApplet::initWidget() {
   if (button_no) {
     myWidget = gtk_frame_new(0);
     gtk_frame_set_shadow_type(GTK_FRAME(myWidget), GTK_SHADOW_ETCHED_IN);
-    gtk_widget_set_size_request(myWidget, button_no*(SLA_APPLET_ICON_SIZE+SLA_APPLET_CANVAS_SIZE), SLA_APPLET_ICON_SIZE+SLA_APPLET_CANVAS_SIZE);
+    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_container_add(GTK_CONTAINER(myWidget), GTK_WIDGET(toolbar));
   } else {
     gtk_widget_destroy(GTK_WIDGET(toolbar));
@@ -198,7 +200,7 @@ void SimpleLauncherApplet::_button_clicked(GtkToolButton *button, void *self) {
 
 void SimpleLauncherApplet::buttonClicked(GtkToolButton *button) {
   if (button != 0) {
-    LauncherItem *item = (LauncherItem *)gtk_object_get_user_data(GTK_OBJECT(button));
+    LaunchableItem *item = (LaunchableItem *)gtk_object_get_user_data(GTK_OBJECT(button));
 
     if (item != 0) {
       item->activate(myContext);
@@ -225,7 +227,7 @@ GtkWidget *SimpleLauncherApplet::settings(GtkWindow *parent) {
   // corresponding dialog appears.
   myParent = parent;  // FIXME: Ugly piece of code :(
 
-  GtkWidget *menuItem = gtk_menu_item_new_with_label("Launcher Settings...");
+  GtkWidget *menuItem = gtk_menu_item_new_with_label("Launcher settings...");
 
   g_signal_connect(menuItem, "activate", G_CALLBACK(_run_dialog), this);
 
@@ -237,8 +239,14 @@ void SimpleLauncherApplet::_run_dialog(GtkMenuItem *, void *self) {
 }
 
 void SimpleLauncherApplet::runDialog() {
+  SLAList list(SL_APPLET_ICON_SIZE, myItems);
+
   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, 0));
 
+  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);
 
   gtk_widget_destroy(GTK_WIDGET(dialog));