blob: 0b79009d12d351ee0ad0cbc8f32f33996a1371fe [file] [log] [blame]
Stepan Salenikovichd81ef292015-02-17 18:47:37 -05001/*
Stepan Salenikovichbe87d2c2016-01-25 14:14:34 -05002 * Copyright (C) 2013-2016 Savoir-faire Linux Inc.
Stepan Salenikovichd81ef292015-02-17 18:47:37 -05003 * Author: Tristan Matthews <tristan.matthews@savoirfairelinux.com>
Stepan Salenikovichbb9c24e2015-09-15 09:55:02 -04004 * Author: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com>
Stepan Salenikovichd81ef292015-02-17 18:47:37 -05005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Stepan Salenikovichd81ef292015-02-17 18:47:37 -050019 */
20
21#include "ring_client_options.h"
22
Stepan Salenikovichc1dac252015-03-25 17:19:35 -040023#include "config.h"
Stepan Salenikoviche40e48d2015-09-17 18:38:25 -040024#include "revision.h"
Stepan Salenikovichbb9c24e2015-09-15 09:55:02 -040025#include "ring_client.h"
Stepan Salenikovichd81ef292015-02-17 18:47:37 -050026#include <glib/gi18n.h>
27#include <gtk/gtk.h>
28#include <stdlib.h>
29
30G_GNUC_NORETURN static gboolean
31option_version_cb(G_GNUC_UNUSED const gchar *option_name,
32 G_GNUC_UNUSED const gchar *value,
33 G_GNUC_UNUSED gpointer data,
34 G_GNUC_UNUSED GError **error)
35{
Stepan Salenikoviche40e48d2015-09-17 18:38:25 -040036 g_print("%d.%d.%d - %s\n", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, RING_CLIENT_REVISION);
Stepan Salenikovichd81ef292015-02-17 18:47:37 -050037 exit(EXIT_SUCCESS);
38}
39
40static gboolean
41option_debug_cb(G_GNUC_UNUSED const gchar *option_name,
42 G_GNUC_UNUSED const gchar *value,
43 G_GNUC_UNUSED gpointer data,
44 G_GNUC_UNUSED GError **error)
45{
46 g_setenv("G_MESSAGES_DEBUG", "all", TRUE);
47 g_debug("debug enabled");
48 return TRUE;
49}
50
Stepan Salenikovichbb9c24e2015-09-15 09:55:02 -040051static gboolean
52option_restore_cb(G_GNUC_UNUSED const gchar *option_name,
53 G_GNUC_UNUSED const gchar *value,
54 G_GNUC_UNUSED gpointer data,
55 G_GNUC_UNUSED GError **error)
56{
57 GApplication *client = g_application_get_default();
58 if (IS_RING_CLIENT(client))
59 ring_client_set_restore_main_window_state(RING_CLIENT(client), TRUE);
60 return TRUE;
61}
62
Stepan Salenikovichd81ef292015-02-17 18:47:37 -050063static const GOptionEntry all_options[] = {
64 {"version", 'v', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_version_cb, NULL, NULL},
Stepan Salenikovich593ddf52015-09-17 17:14:43 -040065 {"debug", 'd', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_debug_cb, N_("Enable debug"), NULL},
Stepan Salenikovichbb9c24e2015-09-15 09:55:02 -040066 {"restore-last-window-state", 'r', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_restore_cb,
Stepan Salenikovich593ddf52015-09-17 17:14:43 -040067 N_("Restores the hidden state of the main window (only applicable to the primary instance)"), NULL},
Stepan Salenikovichd81ef292015-02-17 18:47:37 -050068 {NULL} /* list must be NULL-terminated */
69};
70
Stepan Salenikovich0d515e52015-05-19 16:31:05 -040071#if GLIB_CHECK_VERSION(2,40,0)
72void
73ring_client_add_options(GApplication *app) {
Stepan Salenikovich593ddf52015-09-17 17:14:43 -040074 /* NOTE: using this function, the options do not get translated in glib versions <2.45 due to
75 * bug 750322: https://bugzilla.gnome.org/show_bug.cgi?id=750322
76 */
Stepan Salenikovich0d515e52015-05-19 16:31:05 -040077 g_application_add_main_option_entries(app, all_options);
78}
79
80#else
Stepan Salenikovichd81ef292015-02-17 18:47:37 -050081GOptionContext *
82ring_client_options_get_context()
83{
Stepan Salenikovicha1b8cb32015-09-11 14:58:35 -040084 GOptionContext *context = g_option_context_new(_("- GNOME client for Ring"));
Stepan Salenikovich36c025c2015-03-03 19:06:44 -050085 g_option_context_set_ignore_unknown_options(context, TRUE);
Stepan Salenikovich593ddf52015-09-17 17:14:43 -040086 g_option_context_add_main_entries(context, all_options, PACKAGE_NAME);
Stepan Salenikovichd81ef292015-02-17 18:47:37 -050087 g_option_context_add_group(context, gtk_get_option_group(TRUE));
88 return context;
89}
Stepan Salenikovich0d515e52015-05-19 16:31:05 -040090#endif