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"
28 #define SLA_APPLET_DBUS_NAME "simple-launcher"
29 #define SLA_APPLET_VERSION "0.0"
30 #define SLA_APPLET_ICON_SIZE 26
31 #define SLA_APPLET_BORDER_SIZE 14
32 #define SLA_APPLET_CANVAS_SIZE (SLA_APPLET_BORDER_SIZE+SLA_APPLET_BORDER_SIZE)
34 class SimpleLauncherApplet {
36 SimpleLauncherApplet();
37 ~SimpleLauncherApplet();
39 bool doInit(void *state_data, int *state_size);
43 int saveState(void **state_data, int *state_size);
44 GtkWidget *settings(GtkWindow *parent);
46 GtkWidget *getWidget() { return myWidget; }
48 static void _button_clicked(GtkToolButton *, void *);
53 void buttonClicked(GtkToolButton *);
56 osso_context_t *myContext;
59 std::vector<LauncherItem *> myItems;
61 static char *ourFiles[];
64 // Hildon home applet interface functions
66 void *hildon_home_applet_lib_initialize(void *state_data, int *state_size, GtkWidget **widget) {
67 SimpleLauncherApplet *applet = new SimpleLauncherApplet();
70 if (applet->doInit(state_data, state_size)) {
71 *widget = applet->getWidget();
81 void hildon_home_applet_lib_deinitialize(void *applet_data) {
82 SimpleLauncherApplet *applet = (SimpleLauncherApplet *)applet_data;
87 void hildon_home_applet_lib_background(void *applet_data) {
88 ((SimpleLauncherApplet *)applet_data)->background();
91 void hildon_home_applet_lib_foreground (void *applet_data) {
92 ((SimpleLauncherApplet *)applet_data)->foreground();
95 GtkWidget *hildon_home_applet_lib_settings(void *applet_data, GtkWindow *parent) {
96 return ((SimpleLauncherApplet *)applet_data)->settings(parent);
99 int hildon_home_applet_lib_save_state (void *applet_data, void **state_data, int *state_size) {
100 return ((SimpleLauncherApplet *)applet_data)->saveState(state_data, state_size);
103 // SimpleLauncherApplet implementation
105 char *SimpleLauncherApplet::ourFiles[] = {
106 "/usr/share/applications/hildon/FBReader.desktop",
107 "/usr/share/applications/hildon/mp_ui.desktop",
108 "/usr/share/applications/hildon/osso-xterm.desktop",
109 "/usr/share/applications/hildon/filemanager.desktop",
110 "/usr/share/applications/hildon/osso-application-installer.desktop",
111 "/usr/share/applications/hildon/hildon-control-panel.desktop",
115 SimpleLauncherApplet::SimpleLauncherApplet(): myContext(0), myWidget(0) {
118 bool SimpleLauncherApplet::doInit(void *state_data, int *state_size) {
119 if ((myContext = osso_initialize(SLA_APPLET_DBUS_NAME, SLA_APPLET_VERSION, FALSE, 0)) == 0) {
120 g_debug("sla-applet: failed to initialize the osso layer");
124 for (int i = 0 ; ourFiles[i] != 0 ; ++i) {
125 LauncherItem *item = new LauncherItem();
127 if (item->load(ourFiles[i])) {
128 myItems.push_back(item);
138 gtk_widget_show_all(myWidget);
143 SimpleLauncherApplet::~SimpleLauncherApplet() {
144 for (std::vector<LauncherItem *>::iterator it = myItems.begin(); it != myItems.end(); ++it) {
154 gtk_widget_destroy(myWidget);
158 if (myContext != 0) {
159 osso_deinitialize(myContext);
164 bool SimpleLauncherApplet::initWidget() {
167 GtkToolbar *toolbar = GTK_TOOLBAR(gtk_toolbar_new());
169 for (std::vector<LauncherItem *>::const_iterator it = myItems.begin(); it != myItems.end(); ++it) {
170 GtkToolItem *button = gtk_tool_button_new(gtk_image_new_from_pixbuf((*it)->getIcon(SLA_APPLET_ICON_SIZE)), 0);
172 gtk_object_set_user_data(GTK_OBJECT(button), *it);
173 g_signal_connect(button, "clicked", G_CALLBACK(_button_clicked), this);
175 gtk_toolbar_insert(toolbar, button, -1);
181 myWidget = gtk_frame_new(0);
182 gtk_frame_set_shadow_type(GTK_FRAME(myWidget), GTK_SHADOW_ETCHED_IN);
183 gtk_widget_set_size_request(myWidget, button_no*(SLA_APPLET_ICON_SIZE+SLA_APPLET_CANVAS_SIZE), SLA_APPLET_ICON_SIZE+SLA_APPLET_CANVAS_SIZE);
184 gtk_container_add(GTK_CONTAINER(myWidget), GTK_WIDGET(toolbar));
186 gtk_widget_destroy(GTK_WIDGET(toolbar));
189 return myWidget != 0;
192 void SimpleLauncherApplet::_button_clicked(GtkToolButton *button, void *self) {
193 ((SimpleLauncherApplet *)self)->buttonClicked(button);
196 void SimpleLauncherApplet::buttonClicked(GtkToolButton *button) {
198 LauncherItem *item = (LauncherItem *)gtk_object_get_user_data(GTK_OBJECT(button));
201 item->activate(myContext);
206 int SimpleLauncherApplet::saveState(void **state_data, int *state_size) {
207 if (state_data != 0) {
211 if (state_size != 0) {
218 GtkWidget *SimpleLauncherApplet::settings(GtkWindow *parent) {
219 // TODO: in case we want SimpleLauncherApplet to be configurable, this method
220 // should return a gtk_menu_item that would be included in home settings
221 // menu. Method should make sure that when we activate that item, a
222 // corresponding dialog appears.