~ubuntu-branches/ubuntu/quantal/file-roller/quantal

« back to all changes in this revision

Viewing changes to src/main.c

  • Committer: Package Import Robot
  • Author(s): Robert Ancell
  • Date: 2012-06-06 13:13:15 UTC
  • mfrom: (1.2.102)
  • Revision ID: package-import@ubuntu.com-20120606131315-v6o9g8e0cq9olkq1
Tags: 3.5.1-0ubuntu1
* New upstream release
* debian/control:
  - Bump build-depends on libgtk-3-dev
  - Replace build-depends on gnome-doc-utils with yelp-tools
* debian/watch:
  - Watch for unstable versions

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include <glib/gi18n.h>
28
28
#include <glib.h>
29
29
#include <gio/gio.h>
 
30
#include "actions.h"
30
31
#include "eggsmclient.h"
31
32
#include "fr-init.h"
32
 
 
33
 
GList        *WindowList = NULL;
 
33
#include "gtk-utils.h"
 
34
 
 
35
 
34
36
gint          ForceDirectoryCreation;
35
37
 
36
38
static char **remaining_args;
41
43
static int    extract_here;
42
44
static char  *default_url = NULL;
43
45
 
44
 
static guint  startup_id = 0;
45
 
 
46
46
/* argv[0] from main(); used as the command to restart the program */
47
47
static const char *program_argv0 = NULL;
48
48
 
141
141
        /**/
142
142
 
143
143
        if (remaining_args == NULL) { /* No archive specified. */
144
 
                gtk_widget_show (fr_window_new ());
 
144
                fr_window_new ();
145
145
                return;
146
146
        }
147
147
 
216
216
                        char      *uri;
217
217
 
218
218
                        window = fr_window_new ();
219
 
                        gtk_widget_show (window);
220
219
 
221
220
                        file = g_file_new_for_commandline_arg (filename);
222
221
                        uri = g_file_get_uri (file);
231
230
}
232
231
 
233
232
 
234
 
static gboolean
235
 
startup_cb (gpointer data)
236
 
{
237
 
        g_source_remove (startup_id);
238
 
        startup_id = 0;
239
 
 
 
233
static void
 
234
activate_help (GSimpleAction *action,
 
235
               GVariant      *parameter,
 
236
               gpointer       user_data)
 
237
{
 
238
        GApplication *application = user_data;
 
239
        GList        *windows;
 
240
 
 
241
        windows = gtk_application_get_windows (GTK_APPLICATION (application));
 
242
        if (windows != NULL)
 
243
                activate_action_manual (NULL, windows->data);
 
244
}
 
245
 
 
246
 
 
247
static void
 
248
activate_about (GSimpleAction *action,
 
249
                GVariant      *parameter,
 
250
                gpointer       user_data)
 
251
{
 
252
        GApplication *application = user_data;
 
253
        GList        *windows;
 
254
 
 
255
        windows = gtk_application_get_windows (GTK_APPLICATION (application));
 
256
        if (windows != NULL)
 
257
                activate_action_about (NULL, windows->data);
 
258
}
 
259
 
 
260
 
 
261
static void
 
262
activate_quit (GSimpleAction *action,
 
263
               GVariant      *parameter,
 
264
               gpointer       user_data)
 
265
{
 
266
        activate_action_quit (NULL, NULL);
 
267
}
 
268
 
 
269
 
 
270
static const GActionEntry app_menu_entries[] = {
 
271
        { "help",  activate_help },
 
272
        { "about", activate_about },
 
273
        { "quit",  activate_quit }
 
274
};
 
275
 
 
276
 
 
277
static void
 
278
initialize_app_menu (GApplication *application)
 
279
{
 
280
        GtkBuilder *builder;
 
281
 
 
282
        g_action_map_add_action_entries (G_ACTION_MAP (application),
 
283
                                         app_menu_entries,
 
284
                                         G_N_ELEMENTS (app_menu_entries),
 
285
                                         application);
 
286
 
 
287
        builder = _gtk_builder_new_from_resource ("app-menu.ui");
 
288
        gtk_application_set_app_menu (GTK_APPLICATION (application),
 
289
                                      G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu")));
 
290
 
 
291
        g_object_unref (builder);
 
292
}
 
293
 
 
294
 
 
295
static void
 
296
startup_cb (GApplication *application)
 
297
{
240
298
        initialize_data ();
 
299
        initialize_app_menu (application);
241
300
        prepare_app ();
242
 
 
243
 
        return FALSE;
 
301
}
 
302
 
 
303
 
 
304
static void
 
305
activate_cb (GApplication *application)
 
306
{
 
307
        GList *link;
 
308
 
 
309
        for (link = gtk_application_get_windows (GTK_APPLICATION (application));
 
310
             link != NULL;
 
311
             link = link->next)
 
312
        {
 
313
                if (! fr_window_is_batch_mode (FR_WINDOW (link->data)))
 
314
                        gtk_widget_show (GTK_WIDGET (link->data));
 
315
        }
244
316
}
245
317
 
246
318
 
249
321
{
250
322
        /* discard command is automatically set by EggSMClient */
251
323
 
252
 
        GList *window;
253
 
        const char *argv[2] = { NULL };
254
 
        guint i;
 
324
        GApplication *application;
 
325
        const char   *argv[2] = { NULL };
 
326
        guint         i;
255
327
 
256
328
        /* restart command */
257
329
        argv[0] = program_argv0;
260
332
        egg_sm_client_set_restart_command (client, 1, argv);
261
333
 
262
334
        /* state */
263
 
        for (window = WindowList, i = 0; window; window = window->next, i++) {
264
 
                FrWindow *session = window->data;
265
 
                gchar *key;
266
 
 
267
 
                key = g_strdup_printf ("archive%d", i);
268
 
                if ((session->archive == NULL) || (session->archive->file == NULL)) {
269
 
                        g_key_file_set_string (state, "Session", key, "");
270
 
                } else {
271
 
                        gchar *uri;
272
 
 
273
 
                        uri = g_file_get_uri (session->archive->file);
274
 
                        g_key_file_set_string (state, "Session", key, uri);
275
 
                        g_free (uri);
 
335
        application = g_application_get_default ();
 
336
        if (application != NULL) {
 
337
                GList *window;
 
338
 
 
339
                for (window = gtk_application_get_windows (GTK_APPLICATION (application)), i = 0;
 
340
                     window != NULL;
 
341
                     window = window->next, i++)
 
342
                {
 
343
                        FrWindow *session = window->data;
 
344
                        gchar *key;
 
345
 
 
346
                        key = g_strdup_printf ("archive%d", i);
 
347
                        if ((session->archive == NULL) || (session->archive->file == NULL)) {
 
348
                                g_key_file_set_string (state, "Session", key, "");
 
349
                        }
 
350
                        else {
 
351
                                gchar *uri;
 
352
 
 
353
                                uri = g_file_get_uri (session->archive->file);
 
354
                                g_key_file_set_string (state, "Session", key, uri);
 
355
                                g_free (uri);
 
356
                        }
 
357
                        g_free (key);
276
358
                }
277
 
                g_free (key);
278
359
        }
279
360
 
280
361
        g_key_file_set_integer (state, "Session", "archives", i);
281
362
}
282
363
 
 
364
 
283
365
int
284
366
main (int argc, char **argv)
285
367
{
286
368
        GOptionContext *context = NULL;
287
369
        GError         *error = NULL;
 
370
        GtkApplication *app = NULL;
288
371
        EggSMClient    *client = NULL;
 
372
        int             status;
289
373
 
290
374
        program_argv0 = argv[0];
291
375
 
318
402
        gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
319
403
                                           PKG_DATA_DIR G_DIR_SEPARATOR_S "icons");
320
404
 
321
 
        startup_id = g_idle_add (startup_cb, NULL);
322
 
        gtk_main ();
 
405
        app = gtk_application_new ("org.gnome.file-roller", G_APPLICATION_FLAGS_NONE);
 
406
        g_signal_connect (app, "startup", G_CALLBACK (startup_cb), NULL);
 
407
        g_signal_connect (app, "activate", G_CALLBACK (activate_cb), NULL);
 
408
 
 
409
        status = g_application_run (G_APPLICATION (app), argc, argv);
 
410
 
323
411
        release_data ();
324
412
 
325
 
        return 0;
 
413
        return status;
326
414
}