X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=simple-launcher.cc;h=7b72077adb5e6935c4076007c0837bc5384540d9;hb=refs%2Fheads%2Fsvn%2Ftags%2F0.7;hp=e82b19d74bf674519851d1cbfdf9cc46cb3c840b;hpb=afb8fddb7b832cfc536fdf9540a58e3db4f11503;p=simple-launcher diff --git a/simple-launcher.cc b/simple-launcher.cc index e82b19d..7b72077 100644 --- a/simple-launcher.cc +++ b/simple-launcher.cc @@ -1,3 +1,19 @@ +// This file is a part of Simple Launcher +// +// 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 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 +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +// more details. +// +// You should have received a copy of the GNU General Public License along with +// this program; if not, write to the Free Software Foundation, Inc., 51 +// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include @@ -8,18 +24,14 @@ #include #include "launcher-item.h" +#include "sla-list.h" +#include "launchable-item.h" -extern "C" { - void *hildon_home_applet_lib_initialize (void *state_data, int *state_size, GtkWidget **widget); - void hildon_home_applet_lib_deinitialize (void *applet_data); - void hildon_home_applet_lib_background (void *applet_data); - void hildon_home_applet_lib_foreground(void *applet_data); - int hildon_home_applet_lib_save_state(void *applet_data, void **state_data, int *state_size); - GtkWidget *hildon_home_applet_lib_settings(void *applet_data, GtkWindow *parent); -}; - -#define SLA_APPLET_DBUS_NAME "simple-launcher" -#define SLA_APPLET_VERSION "0.0" +#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: @@ -38,20 +50,25 @@ public: private: bool initWidget(); - bool startApplication(const std::string& application); + void buttonClicked(GtkToolButton *); + void runDialog(); + + static void _button_clicked(GtkToolButton *, void *); + static void _run_dialog(GtkMenuItem *, void *); private: osso_context_t *myContext; GtkWidget *myWidget; + GtkWindow *myParent; - std::vector myItems; + LaunchableItems myItems; static char *ourFiles[]; }; // Hildon home applet interface functions -void *hildon_home_applet_lib_initialize (void *state_data, int *state_size, GtkWidget **widget) { +void *hildon_home_applet_lib_initialize(void *state_data, int *state_size, GtkWidget **widget) { SimpleLauncherApplet *applet = new SimpleLauncherApplet(); if (applet != 0) { @@ -91,33 +108,37 @@ 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/mp_ui.desktop", + "/usr/share/applications/hildon/osso-xterm.desktop", + "/usr/share/applications/hildon/filemanager.desktop", + "/usr/share/applications/hildon/osso-application-installer.desktop", + "/usr/share/applications/hildon/hildon-control-panel.desktop", 0 }; -SimpleLauncherApplet::SimpleLauncherApplet(): myContext(0), myWidget(0) { +SimpleLauncherApplet::SimpleLauncherApplet(): myContext(0), myWidget(0), myParent(0) { } bool SimpleLauncherApplet::doInit(void *state_data, int *state_size) { - if ((myContext = osso_initialize(SLA_APPLET_DBUS_NAME, SLA_APPLET_VERSION, FALSE, NULL)) == 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; } - if (!initWidget()) { - return false; - } - for (int i = 0 ; ourFiles[i] != 0 ; ++i) { LauncherItem *item = new LauncherItem(); if (item->load(ourFiles[i])) { - myItems.push_back(item); + myItems.push_back(std::pair(ourFiles[i], new LaunchableItem(item, true))); } else { delete item; } } - // g_signal_connect (applet->myWidget, "do_search", G_CALLBACK (mis_applet_do_search), (gpointer)applet); + if (!initWidget()) { + return false; + } gtk_widget_show_all(myWidget); @@ -125,10 +146,10 @@ bool SimpleLauncherApplet::doInit(void *state_data, int *state_size) { } SimpleLauncherApplet::~SimpleLauncherApplet() { - for (std::vector::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; } } @@ -146,7 +167,45 @@ SimpleLauncherApplet::~SimpleLauncherApplet() { } bool SimpleLauncherApplet::initWidget() { - return false; + int button_no = 0; + + GtkToolbar *toolbar = GTK_TOOLBAR(gtk_toolbar_new()); + + 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->second); + g_signal_connect(button, "clicked", G_CALLBACK(_button_clicked), this); + + gtk_toolbar_insert(toolbar, button, -1); + + ++button_no; + } + + 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*(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)); + } + + return myWidget != 0; +} + +void SimpleLauncherApplet::_button_clicked(GtkToolButton *button, void *self) { + ((SimpleLauncherApplet *)self)->buttonClicked(button); +} + +void SimpleLauncherApplet::buttonClicked(GtkToolButton *button) { + if (button != 0) { + LaunchableItem *item = (LaunchableItem *)gtk_object_get_user_data(GTK_OBJECT(button)); + + if (item != 0) { + item->activate(myContext); + } + } } int SimpleLauncherApplet::saveState(void **state_data, int *state_size) { @@ -166,9 +225,42 @@ GtkWidget *SimpleLauncherApplet::settings(GtkWindow *parent) { // 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. - return 0; + myParent = parent; // FIXME: Ugly piece of code :( + + GtkWidget *menuItem = gtk_menu_item_new_with_label("Launcher settings..."); + + g_signal_connect(menuItem, "activate", G_CALLBACK(_run_dialog), this); + + return menuItem; +} + +void SimpleLauncherApplet::_run_dialog(GtkMenuItem *, void *self) { + ((SimpleLauncherApplet *)self)->runDialog(); } -bool SimpleLauncherApplet::startApplication(const std::string& application) { - return osso_application_top(myContext, application.c_str(), 0) == OSSO_OK; +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)); + + switch (response) { + case GTK_RESPONSE_OK: + break; + + case GTK_RESPONSE_CANCEL: + break; + + default: + ; // FIXME: do I want to do anything in here? + } } + +// vim:ts=2:sw=2:et