Stepan Salenikovich | d81ef29 | 2015-02-17 18:47:37 -0500 | [diff] [blame] | 1 | /* |
Stepan Salenikovich | be87d2c | 2016-01-25 14:14:34 -0500 | [diff] [blame^] | 2 | * Copyright (C) 2013-2016 Savoir-faire Linux Inc. |
Stepan Salenikovich | d81ef29 | 2015-02-17 18:47:37 -0500 | [diff] [blame] | 3 | * Author: Tristan Matthews <tristan.matthews@savoirfairelinux.com> |
Stepan Salenikovich | bb9c24e | 2015-09-15 09:55:02 -0400 | [diff] [blame] | 4 | * Author: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com> |
Stepan Salenikovich | d81ef29 | 2015-02-17 18:47:37 -0500 | [diff] [blame] | 5 | * |
| 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 Salenikovich | d81ef29 | 2015-02-17 18:47:37 -0500 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #include "ring_client_options.h" |
| 22 | |
Stepan Salenikovich | c1dac25 | 2015-03-25 17:19:35 -0400 | [diff] [blame] | 23 | #include "config.h" |
Stepan Salenikovich | e40e48d | 2015-09-17 18:38:25 -0400 | [diff] [blame] | 24 | #include "revision.h" |
Stepan Salenikovich | bb9c24e | 2015-09-15 09:55:02 -0400 | [diff] [blame] | 25 | #include "ring_client.h" |
Stepan Salenikovich | d81ef29 | 2015-02-17 18:47:37 -0500 | [diff] [blame] | 26 | #include <glib/gi18n.h> |
| 27 | #include <gtk/gtk.h> |
| 28 | #include <stdlib.h> |
| 29 | |
| 30 | G_GNUC_NORETURN static gboolean |
| 31 | option_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 Salenikovich | e40e48d | 2015-09-17 18:38:25 -0400 | [diff] [blame] | 36 | g_print("%d.%d.%d - %s\n", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, RING_CLIENT_REVISION); |
Stepan Salenikovich | d81ef29 | 2015-02-17 18:47:37 -0500 | [diff] [blame] | 37 | exit(EXIT_SUCCESS); |
| 38 | } |
| 39 | |
| 40 | static gboolean |
| 41 | option_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 Salenikovich | bb9c24e | 2015-09-15 09:55:02 -0400 | [diff] [blame] | 51 | static gboolean |
| 52 | option_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 Salenikovich | d81ef29 | 2015-02-17 18:47:37 -0500 | [diff] [blame] | 63 | static const GOptionEntry all_options[] = { |
| 64 | {"version", 'v', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_version_cb, NULL, NULL}, |
Stepan Salenikovich | 593ddf5 | 2015-09-17 17:14:43 -0400 | [diff] [blame] | 65 | {"debug", 'd', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_debug_cb, N_("Enable debug"), NULL}, |
Stepan Salenikovich | bb9c24e | 2015-09-15 09:55:02 -0400 | [diff] [blame] | 66 | {"restore-last-window-state", 'r', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_restore_cb, |
Stepan Salenikovich | 593ddf5 | 2015-09-17 17:14:43 -0400 | [diff] [blame] | 67 | N_("Restores the hidden state of the main window (only applicable to the primary instance)"), NULL}, |
Stepan Salenikovich | d81ef29 | 2015-02-17 18:47:37 -0500 | [diff] [blame] | 68 | {NULL} /* list must be NULL-terminated */ |
| 69 | }; |
| 70 | |
Stepan Salenikovich | 0d515e5 | 2015-05-19 16:31:05 -0400 | [diff] [blame] | 71 | #if GLIB_CHECK_VERSION(2,40,0) |
| 72 | void |
| 73 | ring_client_add_options(GApplication *app) { |
Stepan Salenikovich | 593ddf5 | 2015-09-17 17:14:43 -0400 | [diff] [blame] | 74 | /* 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 Salenikovich | 0d515e5 | 2015-05-19 16:31:05 -0400 | [diff] [blame] | 77 | g_application_add_main_option_entries(app, all_options); |
| 78 | } |
| 79 | |
| 80 | #else |
Stepan Salenikovich | d81ef29 | 2015-02-17 18:47:37 -0500 | [diff] [blame] | 81 | GOptionContext * |
| 82 | ring_client_options_get_context() |
| 83 | { |
Stepan Salenikovich | a1b8cb3 | 2015-09-11 14:58:35 -0400 | [diff] [blame] | 84 | GOptionContext *context = g_option_context_new(_("- GNOME client for Ring")); |
Stepan Salenikovich | 36c025c | 2015-03-03 19:06:44 -0500 | [diff] [blame] | 85 | g_option_context_set_ignore_unknown_options(context, TRUE); |
Stepan Salenikovich | 593ddf5 | 2015-09-17 17:14:43 -0400 | [diff] [blame] | 86 | g_option_context_add_main_entries(context, all_options, PACKAGE_NAME); |
Stepan Salenikovich | d81ef29 | 2015-02-17 18:47:37 -0500 | [diff] [blame] | 87 | g_option_context_add_group(context, gtk_get_option_group(TRUE)); |
| 88 | return context; |
| 89 | } |
Stepan Salenikovich | 0d515e5 | 2015-05-19 16:31:05 -0400 | [diff] [blame] | 90 | #endif |