~netbook-remix-team/netbook-remix-launcher/1.0

« back to all changes in this revision

Viewing changes to src/main.c

  • Committer: Neil Jagdish Patel
  • Date: 2009-02-11 17:07:28 UTC
  • Revision ID: neil.patel@canonical.com-20090211170728-yos2pzrreu6k087a
Revert all the session work, and go back to forced restarts. It works
much more reliably than depending on gnome-session to do the right thing

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
#include <clutter/clutter.h>
37
37
#include <clutter/clutter-x11.h>
38
38
 
39
 
#include <libgnomeui/libgnomeui.h>
40
 
 
41
 
#include <gconf/gconf.h>
42
 
#include <gconf/gconf-client.h>
43
 
 
44
39
#include "launcher-app.h"
45
40
#include "launcher-catbar.h"
46
41
#include "launcher-config.h"
50
45
#define LOCAL_FAV_DIR  ".config/menus/applications-merged"
51
46
#define LOCAL_FAV_MENU ".config/menus/applications-merged/Favorites.menu"
52
47
 
53
 
#define LAST_FAV "/apps/ume-launcher/last_fav"
54
 
#define LAUNCHER_RESTARED_ALREADY "/tmp/.launcher_restarted_already"
55
 
 
56
48
/* Forwards */
57
49
static void     set_window_hints (ClutterStage *stage);
58
50
static void     size_changed     (GdkScreen *screen, ClutterActor *app);
59
51
static void     on_system_resume (LauncherConfig *config);
60
52
static gboolean on_delete_event  (ClutterActor *stage, ClutterEvent *event);
61
 
static gboolean on_sess_save     (GnomeClient        *client,
62
 
                                  gint                arg1, 
63
 
                                  GnomeSaveStyle      arg2,
64
 
                                  gboolean            arg3,
65
 
                                  GnomeInteractStyle  arg4,
66
 
                                  gboolean            arg5);
67
53
 
68
54
static gboolean windowed = FALSE;
69
55
static gint     width    = 1024;
125
111
  ClutterColor black = { 0x00, 0x00, 0x00, 0xff };
126
112
  LauncherConfig *cfg;
127
113
  GdkScreen *screen;
128
 
  GnomeClient *client = NULL;;
129
 
  GOptionContext *context;
130
 
  GConfClient *gclient;
131
114
  GError *error = NULL;
132
115
  gchar *local_apps;
133
 
  gchar *exec[] = {"ume-launcher"};
134
 
  
 
116
 
135
117
  bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
136
118
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
137
119
  textdomain (GETTEXT_PACKAGE);
140
122
  g_set_application_name ("Ubuntu Launcher");
141
123
 
142
124
  gtk_init (&argc, &argv);
143
 
  /*clutter_init_with_args (&argc, &argv,
 
125
  clutter_init_with_args (&argc, &argv,
144
126
                          " - Ubuntu Launcher", entries,
145
127
                          NULL,
146
 
                          &error);*/
147
 
  clutter_init (&argc, &argv);
 
128
                          &error);
148
129
  if (error)
149
130
  {
150
131
      g_print ("Unable to run Ubuntu Launcher: %s", error->message);
152
133
      return EXIT_FAILURE;
153
134
  }
154
135
 
155
 
  context = g_option_context_new ("Ubuntu Launcher");
156
 
  g_option_context_add_main_entries (context, entries, NULL);
157
 
  gnome_program_init ("Ubuntu Launcher", "0.6", LIBGNOMEUI_MODULE, 
158
 
                       argc, argv,
159
 
                       GNOME_PARAM_GOPTION_CONTEXT, context, 
160
 
                       GNOME_PARAM_NONE);
161
 
 
162
 
  if (!windowed)
163
 
  {
164
 
    client = gnome_master_client ();
165
 
    gnome_client_set_restart_command (client, 1, exec);
166
 
    gnome_client_set_restart_style (client, GNOME_RESTART_IMMEDIATELY);
167
 
 
168
 
    g_signal_connect (client, "save-yourself", 
169
 
                      G_CALLBACK (on_sess_save), NULL);
170
 
  }
171
 
    
172
136
  /* FIXME: Some tests that shouldn't be in here */
173
137
  local_apps = g_build_filename (g_get_home_dir (), 
174
138
                                 ".local", "share", "applications", NULL);
239
203
    g_setenv ("LAUNCHER_NORESTART", "0", TRUE);
240
204
 
241
205
  /* Init() the main application */
242
 
  gclient = gconf_client_get_default ();
243
 
  last_category = gconf_client_get_bool (gclient, LAST_FAV, NULL);
244
206
  app = launcher_app_get_default ();
245
207
  launcher_catbar_set_active_category 
246
 
                            (LAUNCHER_CATBAR (launcher_catbar_get_default ()),                                        last_category);
247
 
  g_object_unref (gclient);
 
208
                            (LAUNCHER_CATBAR (launcher_catbar_get_default ()), 
 
209
                                       last_category);
248
210
 
249
211
  cfg = launcher_config_get_default ();
250
212
  g_signal_connect (screen, "size-changed", 
254
216
 
255
217
  clutter_actor_show (stage);
256
218
  clutter_main ();
257
 
 
 
219
  
258
220
  if (windowed)
259
221
    g_setenv ("LAUNCHER_WINDOWED", "0", TRUE);
260
222
  
323
285
restart_launcher ()
324
286
{
325
287
  LauncherCatbar *bar;
326
 
  GConfClient *client;
327
 
 
 
288
  gchar *exec;
 
289
  
328
290
  bar = (LauncherCatbar *)launcher_catbar_get_default ();
329
 
  client = gconf_client_get_default ();
330
 
 
331
 
  gconf_client_set_bool (client, LAST_FAV, 
332
 
                         launcher_catbar_get_active_category (bar),
333
 
                         NULL);
334
 
  g_object_unref (client);
335
 
 
336
 
  g_spawn_command_line_sync ("touch " LAUNCHER_RESTARED_ALREADY,
337
 
                             NULL, NULL, NULL, NULL);
338
 
  
 
291
  exec = g_strdup_printf ("ume-launcher --no-restart --last-category=%d",
 
292
                          launcher_catbar_get_active_category (bar));
 
293
  gdk_spawn_command_line_on_screen (gdk_screen_get_default (),
 
294
                                    exec, NULL);
 
295
  g_free (exec);
339
296
  clutter_main_quit ();
340
297
}
341
298
 
342
299
static void
343
300
on_system_resume (LauncherConfig *config)
344
301
{
345
 
  if (!(g_file_test (LAUNCHER_RESTARED_ALREADY, G_FILE_TEST_EXISTS)))
 
302
  if (!norestart)
346
303
    restart_launcher ();
347
304
}
348
305
 
357
314
restart_launcher_for_resize ()
358
315
{
359
316
  LauncherCatbar *bar;
360
 
  GConfClient *client;
 
317
  gchar *exec;
361
318
 
362
319
  bar = (LauncherCatbar *)launcher_catbar_get_default ();
363
 
  client = gconf_client_get_default ();
364
 
 
365
 
  gconf_client_set_bool (client, LAST_FAV, 
366
 
                         launcher_catbar_get_active_category (bar),
367
 
                         NULL);
368
 
  g_object_unref (client);
369
 
  
 
320
 
 
321
  exec = g_strdup_printf ("ume-launcher --last-category=%d",
 
322
                          launcher_catbar_get_active_category (bar));
 
323
 
 
324
  gdk_spawn_command_line_on_screen (gdk_screen_get_default (),
 
325
                                    exec, NULL);
 
326
  g_free (exec);
370
327
  clutter_main_quit ();
371
328
}
372
329
 
382
339
  already_called = TRUE;
383
340
  restart_launcher_for_resize ();
384
341
}
385
 
 
386
 
static gboolean on_sess_save (GnomeClient        *client,
387
 
                              gint                arg1, 
388
 
                              GnomeSaveStyle      arg2,
389
 
                              gboolean            arg3,
390
 
                              GnomeInteractStyle  arg4,
391
 
                              gboolean            arg5)
392
 
{
393
 
  return TRUE;
394
 
}