* added code to create the actual toolbar
authormss <noemail>
Tue, 5 Dec 2006 00:07:05 +0000 (00:07 +0000)
committermss <noemail>
Tue, 5 Dec 2006 00:07:05 +0000 (00:07 +0000)
 * added a number of .desktop entries to show in the applet
 * re-arranged widget initialization

git-svn-id: file:///svnroot/simple-launcher/trunk@9 3ba93dab-e023-0410-b42a-de7732cf370a

simple-launcher.cc

index fcc5ff4..d60f195 100644 (file)
@@ -35,9 +35,13 @@ public:
 
   GtkWidget *getWidget() { return myWidget; }
 
+  static void _button_clicked(GtkToolButton *, void *);
+
 private:
   bool initWidget();
 
+  void buttonClicked(GtkToolButton *);
+
 private:
   osso_context_t *myContext;
   GtkWidget *myWidget;
@@ -89,6 +93,12 @@ int hildon_home_applet_lib_save_state (void *applet_data, void **state_data, int
 // SimpleLauncherApplet implementation
 
 char *SimpleLauncherApplet::ourFiles[] = {
+  "/usr/share/applications/hildon/FBReader.desktop",
+  "/usr/share/applications/hildon/filemanager.desktop",
+  "/usr/share/applications/hildon/hildon-control-panel.desktop",
+  "/usr/share/applications/hildon/osso-application-installer.desktop",
+  "/usr/share/applications/hildon/osso-music-player.desktop",
+  "/usr/share/applications/hildon/osso-xterm.desktop",
   0
 };
 
@@ -101,10 +111,6 @@ bool SimpleLauncherApplet::doInit(void *state_data, int *state_size) {
     return false;
   }
 
-  if (!initWidget()) {
-    return false;
-  }
-
   for (int i = 0 ; ourFiles[i] != 0 ; ++i) {
     LauncherItem *item = new LauncherItem();
 
@@ -115,7 +121,9 @@ bool SimpleLauncherApplet::doInit(void *state_data, int *state_size) {
     }
   }
 
-  // g_signal_connect (applet->myWidget, "do_search", G_CALLBACK (mis_applet_do_search), (gpointer)applet);
+  if (!initWidget()) {
+    return false;
+  }
 
   gtk_widget_show_all(myWidget);
 
@@ -144,7 +152,41 @@ SimpleLauncherApplet::~SimpleLauncherApplet() {
 }
 
 bool SimpleLauncherApplet::initWidget() {
-  return false;
+  bool have_buttons = false;
+
+  myWidget = 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(26)), 0);
+
+    gtk_object_set_user_data(GTK_OBJECT(button), *it);
+    g_signal_connect(button, "clicked", G_CALLBACK(_button_clicked), this);
+
+    gtk_toolbar_insert(GTK_TOOLBAR(myWidget), button, -1);
+
+    have_buttons = true;
+  }
+
+  if (!have_buttons) {
+    gtk_widget_destroy(myWidget);
+    myWidget = 0;
+  }
+
+  return true;
+}
+
+void SimpleLauncherApplet::_button_clicked(GtkToolButton *button, void *self) {
+  ((SimpleLauncherApplet *)self)->buttonClicked(button);
+}
+
+void SimpleLauncherApplet::buttonClicked(GtkToolButton *button) {
+  if (button != 0) {
+    LauncherItem *item = (LauncherItem *)gtk_object_get_user_data(GTK_OBJECT(button));
+
+    if (item != 0) {
+      item->activate(myContext);
+    }
+  }
 }
 
 int SimpleLauncherApplet::saveState(void **state_data, int *state_size) {