1 // This file is a part of Simple Launcher
3 // Copyright (C) 2006, Mikhail Sobolev
5 // Simple Launcher is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License version 2 as published by
7 // the Free Software Foundation.
9 // This program is distributed in the hope that it will be useful, but WITHOUT
10 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 // You should have received a copy of the GNU General Public License along with
15 // this program; if not, write to the Free Software Foundation, Inc., 51
16 // Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <hildon-home-plugin/hildon-home-plugin-interface.h>
26 #include "launcher-item.h"
29 #define SL_APPLET_DBUS_NAME "simple-launcher"
30 #define SL_APPLET_VERSION "0.0"
31 #define SL_APPLET_ICON_SIZE 26
32 #define SL_APPLET_BORDER_SIZE 14
33 #define SL_APPLET_CANVAS_SIZE (SL_APPLET_BORDER_SIZE+SL_APPLET_BORDER_SIZE)
35 class SimpleLauncherApplet {
37 SimpleLauncherApplet();
38 ~SimpleLauncherApplet();
40 bool doInit(void *state_data, int *state_size);
44 int saveState(void **state_data, int *state_size);
45 GtkWidget *settings(GtkWindow *parent);
47 GtkWidget *getWidget() { return myWidget; }
52 void buttonClicked(GtkToolButton *);
55 static void _button_clicked(GtkToolButton *, void *);
56 static void _run_dialog(GtkMenuItem *, void *);
59 osso_context_t *myContext;
63 std::vector<LauncherItem *> myItems;
65 static char *ourFiles[];
68 // Hildon home applet interface functions
70 void *hildon_home_applet_lib_initialize(void *state_data, int *state_size, GtkWidget **widget) {
71 SimpleLauncherApplet *applet = new SimpleLauncherApplet();
74 if (applet->doInit(state_data, state_size)) {
75 *widget = applet->getWidget();
85 void hildon_home_applet_lib_deinitialize(void *applet_data) {
86 SimpleLauncherApplet *applet = (SimpleLauncherApplet *)applet_data;
91 void hildon_home_applet_lib_background(void *applet_data) {
92 ((SimpleLauncherApplet *)applet_data)->background();
95 void hildon_home_applet_lib_foreground (void *applet_data) {
96 ((SimpleLauncherApplet *)applet_data)->foreground();
99 GtkWidget *hildon_home_applet_lib_settings(void *applet_data, GtkWindow *parent) {
100 return ((SimpleLauncherApplet *)applet_data)->settings(parent);
103 int hildon_home_applet_lib_save_state (void *applet_data, void **state_data, int *state_size) {
104 return ((SimpleLauncherApplet *)applet_data)->saveState(state_data, state_size);
107 // SimpleLauncherApplet implementation
109 char *SimpleLauncherApplet::ourFiles[] = {
110 "/usr/share/applications/hildon/FBReader.desktop",
111 "/usr/share/applications/hildon/mp_ui.desktop",
112 "/usr/share/applications/hildon/osso-xterm.desktop",
113 "/usr/share/applications/hildon/filemanager.desktop",
114 "/usr/share/applications/hildon/osso-application-installer.desktop",
115 "/usr/share/applications/hildon/hildon-control-panel.desktop",
119 SimpleLauncherApplet::SimpleLauncherApplet(): myContext(0), myWidget(0), myParent(0) {
122 bool SimpleLauncherApplet::doInit(void *state_data, int *state_size) {
123 if ((myContext = osso_initialize(SL_APPLET_DBUS_NAME, SL_APPLET_VERSION, FALSE, 0)) == 0) {
124 g_debug("sla-applet: failed to initialize the osso layer");
128 for (int i = 0 ; ourFiles[i] != 0 ; ++i) {
129 LauncherItem *item = new LauncherItem();
131 if (item->load(ourFiles[i])) {
132 myItems.push_back(item);
142 gtk_widget_show_all(myWidget);
147 SimpleLauncherApplet::~SimpleLauncherApplet() {
148 for (std::vector<LauncherItem *>::iterator it = myItems.begin(); it != myItems.end(); ++it) {
158 gtk_widget_destroy(myWidget);
162 if (myContext != 0) {
163 osso_deinitialize(myContext);
168 bool SimpleLauncherApplet::initWidget() {
171 GtkToolbar *toolbar = GTK_TOOLBAR(gtk_toolbar_new());
173 for (std::vector<LauncherItem *>::const_iterator it = myItems.begin(); it != myItems.end(); ++it) {
174 GtkToolItem *button = gtk_tool_button_new(gtk_image_new_from_pixbuf((*it)->getIcon(SL_APPLET_ICON_SIZE)), 0);
176 gtk_object_set_user_data(GTK_OBJECT(button), *it);
177 g_signal_connect(button, "clicked", G_CALLBACK(_button_clicked), this);
179 gtk_toolbar_insert(toolbar, button, -1);
185 myWidget = gtk_frame_new(0);
186 gtk_frame_set_shadow_type(GTK_FRAME(myWidget), GTK_SHADOW_ETCHED_IN);
187 gtk_widget_set_size_request(myWidget, button_no*(SL_APPLET_ICON_SIZE+SL_APPLET_CANVAS_SIZE), SL_APPLET_ICON_SIZE+SL_APPLET_CANVAS_SIZE);
188 gtk_container_add(GTK_CONTAINER(myWidget), GTK_WIDGET(toolbar));
190 gtk_widget_destroy(GTK_WIDGET(toolbar));
193 return myWidget != 0;
196 void SimpleLauncherApplet::_button_clicked(GtkToolButton *button, void *self) {
197 ((SimpleLauncherApplet *)self)->buttonClicked(button);
200 void SimpleLauncherApplet::buttonClicked(GtkToolButton *button) {
202 LauncherItem *item = (LauncherItem *)gtk_object_get_user_data(GTK_OBJECT(button));
205 item->activate(myContext);
210 int SimpleLauncherApplet::saveState(void **state_data, int *state_size) {
211 if (state_data != 0) {
215 if (state_size != 0) {
222 GtkWidget *SimpleLauncherApplet::settings(GtkWindow *parent) {
223 // TODO: in case we want SimpleLauncherApplet to be configurable, this method
224 // should return a gtk_menu_item that would be included in home settings
225 // menu. Method should make sure that when we activate that item, a
226 // corresponding dialog appears.
227 myParent = parent; // FIXME: Ugly piece of code :(
229 GtkWidget *menuItem = gtk_menu_item_new_with_label("Launcher settings...");
231 g_signal_connect(menuItem, "activate", G_CALLBACK(_run_dialog), this);
236 void SimpleLauncherApplet::_run_dialog(GtkMenuItem *, void *self) {
237 ((SimpleLauncherApplet *)self)->runDialog();
240 void SimpleLauncherApplet::runDialog() {
241 SLAList list(SL_APPLET_ICON_SIZE);
243 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));
245 gtk_container_add(GTK_CONTAINER(dialog->vbox), list.getWidget());
247 gtk_widget_set_size_request(GTK_WIDGET(dialog), 540, 257);
249 int response = gtk_dialog_run(dialog);
251 gtk_widget_destroy(GTK_WIDGET(dialog));
254 case GTK_RESPONSE_OK:
257 case GTK_RESPONSE_CANCEL:
261 ; // FIXME: do I want to do anything in here?