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 as published by the Free
7 // Software Foundation; either version 2 of the License.
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 void *hildon_home_applet_lib_initialize (void *state_data, int *state_size, GtkWidget **widget);
30 void hildon_home_applet_lib_deinitialize (void *applet_data);
31 void hildon_home_applet_lib_background (void *applet_data);
32 void hildon_home_applet_lib_foreground(void *applet_data);
33 int hildon_home_applet_lib_save_state(void *applet_data, void **state_data, int *state_size);
34 GtkWidget *hildon_home_applet_lib_settings(void *applet_data, GtkWindow *parent);
37 #define SLA_APPLET_DBUS_NAME "simple-launcher"
38 #define SLA_APPLET_VERSION "0.0"
39 #define SLA_APPLET_ICON_SIZE 26
40 #define SLA_APPLET_BORDER_SIZE 14
41 #define SLA_APPLET_CANVAS_SIZE (SLA_APPLET_BORDER_SIZE+SLA_APPLET_BORDER_SIZE)
43 class SimpleLauncherApplet {
45 SimpleLauncherApplet();
46 ~SimpleLauncherApplet();
48 bool doInit(void *state_data, int *state_size);
52 int saveState(void **state_data, int *state_size);
53 GtkWidget *settings(GtkWindow *parent);
55 GtkWidget *getWidget() { return myWidget; }
57 static void _button_clicked(GtkToolButton *, void *);
62 void buttonClicked(GtkToolButton *);
65 osso_context_t *myContext;
68 std::vector<LauncherItem *> myItems;
70 static char *ourFiles[];
73 // Hildon home applet interface functions
75 void *hildon_home_applet_lib_initialize(void *state_data, int *state_size, GtkWidget **widget) {
76 SimpleLauncherApplet *applet = new SimpleLauncherApplet();
79 if (applet->doInit(state_data, state_size)) {
80 *widget = applet->getWidget();
90 void hildon_home_applet_lib_deinitialize(void *applet_data) {
91 SimpleLauncherApplet *applet = (SimpleLauncherApplet *)applet_data;
96 void hildon_home_applet_lib_background(void *applet_data) {
97 ((SimpleLauncherApplet *)applet_data)->background();
100 void hildon_home_applet_lib_foreground (void *applet_data) {
101 ((SimpleLauncherApplet *)applet_data)->foreground();
104 GtkWidget *hildon_home_applet_lib_settings(void *applet_data, GtkWindow *parent) {
105 return ((SimpleLauncherApplet *)applet_data)->settings(parent);
108 int hildon_home_applet_lib_save_state (void *applet_data, void **state_data, int *state_size) {
109 return ((SimpleLauncherApplet *)applet_data)->saveState(state_data, state_size);
112 // SimpleLauncherApplet implementation
114 char *SimpleLauncherApplet::ourFiles[] = {
115 "/usr/share/applications/hildon/FBReader.desktop",
116 "/usr/share/applications/hildon/mp_ui.desktop",
117 "/usr/share/applications/hildon/osso-xterm.desktop",
118 "/usr/share/applications/hildon/filemanager.desktop",
119 "/usr/share/applications/hildon/osso-application-installer.desktop",
120 "/usr/share/applications/hildon/hildon-control-panel.desktop",
124 SimpleLauncherApplet::SimpleLauncherApplet(): myContext(0), myWidget(0) {
127 bool SimpleLauncherApplet::doInit(void *state_data, int *state_size) {
128 if ((myContext = osso_initialize(SLA_APPLET_DBUS_NAME, SLA_APPLET_VERSION, FALSE, 0)) == 0) {
129 g_debug("sla-applet: failed to initialize the osso layer");
133 for (int i = 0 ; ourFiles[i] != 0 ; ++i) {
134 LauncherItem *item = new LauncherItem();
136 if (item->load(ourFiles[i])) {
137 myItems.push_back(item);
147 gtk_widget_show_all(myWidget);
152 SimpleLauncherApplet::~SimpleLauncherApplet() {
153 for (std::vector<LauncherItem *>::iterator it = myItems.begin(); it != myItems.end(); ++it) {
163 gtk_widget_destroy(myWidget);
167 if (myContext != 0) {
168 osso_deinitialize(myContext);
173 bool SimpleLauncherApplet::initWidget() {
176 GtkToolbar *toolbar = GTK_TOOLBAR(gtk_toolbar_new());
178 for (std::vector<LauncherItem *>::const_iterator it = myItems.begin(); it != myItems.end(); ++it) {
179 GtkToolItem *button = gtk_tool_button_new(gtk_image_new_from_pixbuf((*it)->getIcon(SLA_APPLET_ICON_SIZE)), 0);
181 gtk_object_set_user_data(GTK_OBJECT(button), *it);
182 g_signal_connect(button, "clicked", G_CALLBACK(_button_clicked), this);
184 gtk_toolbar_insert(toolbar, button, -1);
190 myWidget = gtk_frame_new(0);
191 gtk_frame_set_shadow_type(GTK_FRAME(myWidget), GTK_SHADOW_ETCHED_IN);
192 gtk_widget_set_size_request(myWidget, button_no*(SLA_APPLET_ICON_SIZE+SLA_APPLET_CANVAS_SIZE), SLA_APPLET_ICON_SIZE+SLA_APPLET_CANVAS_SIZE);
193 gtk_container_add(GTK_CONTAINER(myWidget), GTK_WIDGET(toolbar));
195 gtk_widget_destroy(GTK_WIDGET(toolbar));
198 return myWidget != 0;
201 void SimpleLauncherApplet::_button_clicked(GtkToolButton *button, void *self) {
202 ((SimpleLauncherApplet *)self)->buttonClicked(button);
205 void SimpleLauncherApplet::buttonClicked(GtkToolButton *button) {
207 LauncherItem *item = (LauncherItem *)gtk_object_get_user_data(GTK_OBJECT(button));
210 item->activate(myContext);
215 int SimpleLauncherApplet::saveState(void **state_data, int *state_size) {
216 if (state_data != 0) {
220 if (state_size != 0) {
227 GtkWidget *SimpleLauncherApplet::settings(GtkWindow *parent) {
228 // TODO: in case we want SimpleLauncherApplet to be configurable, this method
229 // should return a gtk_menu_item that would be included in home settings
230 // menu. Method should make sure that when we activate that item, a
231 // corresponding dialog appears.