finally started to use version control system
[simple-launcher] / simple-launcher.cc
1
2 #include <string>
3 #include <vector>
4
5 #include <gtk/gtk.h>
6
7 #include <hildon-home-plugin/hildon-home-plugin-interface.h>
8 #include <libosso.h>
9
10 #include "launcher-item.h"
11
12 extern "C" {
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);
19 };
20
21 #define SLA_APPLET_DBUS_NAME  "simple-launcher"
22 #define SLA_APPLET_VERSION    "0.0"
23
24 class SimpleLauncherApplet {
25 public:
26   SimpleLauncherApplet();
27  ~SimpleLauncherApplet();
28
29   bool doInit(void *state_data, int *state_size);
30
31   void background() {}
32   void foreground() {}
33   int saveState(void **state_data, int *state_size);
34   GtkWidget *settings(GtkWindow *parent);
35
36   GtkWidget *getWidget() { return myWidget; }
37
38   bool startApplication(const std::string& application);
39
40 private:
41   osso_context_t *myContext;
42   GtkWidget *myWidget;
43
44   std::vector<LauncherItem *> myItems;
45
46   static char *ourFiles[];
47 };
48
49 // Hildon home applet interface functions
50
51 void *hildon_home_applet_lib_initialize (void *state_data, int *state_size, GtkWidget **widget) {
52   SimpleLauncherApplet *applet = new SimpleLauncherApplet();
53
54   if (applet != 0) {
55     if (applet->doInit(state_data, state_size)) {
56       *widget = applet->getWidget();
57     } else {
58       delete applet;
59       applet = 0;
60     }
61   }
62
63   return (void*)applet;
64 }
65
66 void hildon_home_applet_lib_deinitialize(void *applet_data) {
67   SimpleLauncherApplet *applet = (SimpleLauncherApplet *)applet_data;
68
69   delete applet;
70 }
71
72 void hildon_home_applet_lib_background(void *applet_data) {
73   ((SimpleLauncherApplet *)applet_data)->background();
74 }
75
76 void hildon_home_applet_lib_foreground (void *applet_data) {
77   ((SimpleLauncherApplet *)applet_data)->foreground();
78 }
79
80 GtkWidget *hildon_home_applet_lib_settings(void *applet_data, GtkWindow *parent) {
81   return ((SimpleLauncherApplet *)applet_data)->settings(parent);
82 }
83
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);
86 }
87
88 // SimpleLauncherApplet implementation
89
90 char *SimpleLauncherApplet::ourFiles[] = {
91   0
92 };
93
94 SimpleLauncherApplet::SimpleLauncherApplet(): myContext(0), myWidget(0) {
95 }
96
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");
100     return false;
101   }
102
103   // myWidget = mis_widget_new_with_engines_and_history();
104   if (myWidget == 0) {
105     return false;
106   }
107
108   for (int i = 0 ; ourFiles[i] != 0 ; ++i) {
109     LauncherItem *item = new LauncherItem();
110
111     if (item->load(ourFiles[i])) {
112       myItems.push_back(item);
113     } else {
114       delete item;
115     }
116   }
117
118   // g_signal_connect (applet->myWidget, "do_search", G_CALLBACK (mis_applet_do_search), (gpointer)applet);
119
120   gtk_widget_show_all(myWidget);
121
122   return true;
123 }
124
125 SimpleLauncherApplet::~SimpleLauncherApplet() {
126   for (std::vector<LauncherItem *>::iterator it = myItems.begin(); it != myItems.end(); ++it) {
127     if (*it != 0) {
128       delete *it;
129       *it = 0;
130     }
131   }
132
133   myItems.resize(0);
134
135   if (myWidget != 0) {
136     gtk_widget_destroy(myWidget);
137     myWidget = 0;
138   }
139
140   if (myContext != 0) {
141     osso_deinitialize(myContext);
142     myContext = 0;
143   }
144 }
145
146 int SimpleLauncherApplet::saveState(void **state_data, int *state_size) {
147   if (state_data != 0) {
148     *state_data = 0;
149   }
150
151   if (state_size != 0) {
152     *state_size = 0;
153   }
154
155   return 1;
156 }
157
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.
163   return 0;
164 }
165
166 bool SimpleLauncherApplet::startApplication(const std::string& application) {
167   return osso_application_top(myContext, application.c_str(), 0) == OSSO_OK;
168 }