7 #include <hildon-home-plugin/hildon-home-plugin-interface.h>
10 #include "launcher-item.h"
13 void *hildon_home_applet_lib_initialize (void *state_data, int *state_size, GtkWidget **widget);
14 void hildon_home_applet_lib_deinitialize (void *applet_data);
15 void hildon_home_applet_lib_background (void *applet_data);
16 void hildon_home_applet_lib_foreground(void *applet_data);
17 int hildon_home_applet_lib_save_state(void *applet_data, void **state_data, int *state_size);
18 GtkWidget *hildon_home_applet_lib_settings(void *applet_data, GtkWindow *parent);
21 #define SLA_APPLET_DBUS_NAME "simple-launcher"
22 #define SLA_APPLET_VERSION "0.0"
24 class SimpleLauncherApplet {
26 SimpleLauncherApplet();
27 ~SimpleLauncherApplet();
29 bool doInit(void *state_data, int *state_size);
33 int saveState(void **state_data, int *state_size);
34 GtkWidget *settings(GtkWindow *parent);
36 GtkWidget *getWidget() { return myWidget; }
38 bool startApplication(const std::string& application);
41 osso_context_t *myContext;
44 std::vector<LauncherItem *> myItems;
46 static char *ourFiles[];
49 // Hildon home applet interface functions
51 void *hildon_home_applet_lib_initialize (void *state_data, int *state_size, GtkWidget **widget) {
52 SimpleLauncherApplet *applet = new SimpleLauncherApplet();
55 if (applet->doInit(state_data, state_size)) {
56 *widget = applet->getWidget();
66 void hildon_home_applet_lib_deinitialize(void *applet_data) {
67 SimpleLauncherApplet *applet = (SimpleLauncherApplet *)applet_data;
72 void hildon_home_applet_lib_background(void *applet_data) {
73 ((SimpleLauncherApplet *)applet_data)->background();
76 void hildon_home_applet_lib_foreground (void *applet_data) {
77 ((SimpleLauncherApplet *)applet_data)->foreground();
80 GtkWidget *hildon_home_applet_lib_settings(void *applet_data, GtkWindow *parent) {
81 return ((SimpleLauncherApplet *)applet_data)->settings(parent);
84 int hildon_home_applet_lib_save_state (void *applet_data, void **state_data, int *state_size) {
85 return ((SimpleLauncherApplet *)applet_data)->saveState(state_data, state_size);
88 // SimpleLauncherApplet implementation
90 char *SimpleLauncherApplet::ourFiles[] = {
94 SimpleLauncherApplet::SimpleLauncherApplet(): myContext(0), myWidget(0) {
97 bool SimpleLauncherApplet::doInit(void *state_data, int *state_size) {
98 if ((myContext = osso_initialize(SLA_APPLET_DBUS_NAME, SLA_APPLET_VERSION, FALSE, NULL)) == 0) {
99 g_debug("sla-applet: failed to initialize the osso layer");
103 // myWidget = mis_widget_new_with_engines_and_history();
108 for (int i = 0 ; ourFiles[i] != 0 ; ++i) {
109 LauncherItem *item = new LauncherItem();
111 if (item->load(ourFiles[i])) {
112 myItems.push_back(item);
118 // g_signal_connect (applet->myWidget, "do_search", G_CALLBACK (mis_applet_do_search), (gpointer)applet);
120 gtk_widget_show_all(myWidget);
125 SimpleLauncherApplet::~SimpleLauncherApplet() {
126 for (std::vector<LauncherItem *>::iterator it = myItems.begin(); it != myItems.end(); ++it) {
136 gtk_widget_destroy(myWidget);
140 if (myContext != 0) {
141 osso_deinitialize(myContext);
146 int SimpleLauncherApplet::saveState(void **state_data, int *state_size) {
147 if (state_data != 0) {
151 if (state_size != 0) {
158 GtkWidget *SimpleLauncherApplet::settings(GtkWindow *parent) {
159 // TODO: in case we want SimpleLauncherApplet to be configurable, this method
160 // should return a gtk_menu_item that would be included in home settings
161 // menu. Method should make sure that when we activate that item, a
162 // corresponding dialog appears.
166 bool SimpleLauncherApplet::startApplication(const std::string& application) {
167 return osso_application_top(myContext, application.c_str(), 0) == OSSO_OK;