Stepan Salenikovich | d81ef29 | 2015-02-17 18:47:37 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013-2015 Savoir-Faire Linux Inc. |
| 3 | * Author: Tristan Matthews <tristan.matthews@savoirfairelinux.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Additional permission under GNU GPL version 3 section 7: |
| 20 | * |
| 21 | * If you modify this program, or any covered work, by linking or |
| 22 | * combining it with the OpenSSL project's OpenSSL library (or a |
| 23 | * modified version of that library), containing parts covered by the |
| 24 | * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. |
| 25 | * grants you additional permission to convey the resulting work. |
| 26 | * Corresponding Source for a non-source form of such a combination |
| 27 | * shall include the source code for the parts of OpenSSL used as well |
| 28 | * as that of the covered work. |
| 29 | */ |
| 30 | |
| 31 | #include "ring_client_options.h" |
| 32 | |
Stepan Salenikovich | c1dac25 | 2015-03-25 17:19:35 -0400 | [diff] [blame] | 33 | #include "config.h" |
Stepan Salenikovich | d81ef29 | 2015-02-17 18:47:37 -0500 | [diff] [blame] | 34 | #include <glib/gi18n.h> |
| 35 | #include <gtk/gtk.h> |
| 36 | #include <stdlib.h> |
| 37 | |
| 38 | G_GNUC_NORETURN static gboolean |
| 39 | option_version_cb(G_GNUC_UNUSED const gchar *option_name, |
| 40 | G_GNUC_UNUSED const gchar *value, |
| 41 | G_GNUC_UNUSED gpointer data, |
| 42 | G_GNUC_UNUSED GError **error) |
| 43 | { |
| 44 | /* TODO: replace with auto generated version */ |
Stepan Salenikovich | c1dac25 | 2015-03-25 17:19:35 -0400 | [diff] [blame] | 45 | g_print("%d.%d.%d\n", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH); |
Stepan Salenikovich | d81ef29 | 2015-02-17 18:47:37 -0500 | [diff] [blame] | 46 | exit(EXIT_SUCCESS); |
| 47 | } |
| 48 | |
| 49 | static gboolean |
| 50 | option_debug_cb(G_GNUC_UNUSED const gchar *option_name, |
| 51 | G_GNUC_UNUSED const gchar *value, |
| 52 | G_GNUC_UNUSED gpointer data, |
| 53 | G_GNUC_UNUSED GError **error) |
| 54 | { |
| 55 | g_setenv("G_MESSAGES_DEBUG", "all", TRUE); |
| 56 | g_debug("debug enabled"); |
| 57 | return TRUE; |
| 58 | } |
| 59 | |
| 60 | static const GOptionEntry all_options[] = { |
| 61 | {"version", 'v', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_version_cb, NULL, NULL}, |
| 62 | {"debug", 'd', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_debug_cb, "Enable debug", NULL}, |
| 63 | {NULL} /* list must be NULL-terminated */ |
| 64 | }; |
| 65 | |
Stepan Salenikovich | 0d515e5 | 2015-05-19 16:31:05 -0400 | [diff] [blame] | 66 | #if GLIB_CHECK_VERSION(2,40,0) |
| 67 | void |
| 68 | ring_client_add_options(GApplication *app) { |
| 69 | g_application_add_main_option_entries(app, all_options); |
| 70 | } |
| 71 | |
| 72 | #else |
Stepan Salenikovich | d81ef29 | 2015-02-17 18:47:37 -0500 | [diff] [blame] | 73 | GOptionContext * |
| 74 | ring_client_options_get_context() |
| 75 | { |
| 76 | /* TODO: for some reason the given description and added options aren't printed |
| 77 | * when '--help' is invoked... possibly a GTK bug. |
| 78 | */ |
Stepan Salenikovich | a1b8cb3 | 2015-09-11 14:58:35 -0400 | [diff] [blame^] | 79 | GOptionContext *context = g_option_context_new(_("- GNOME client for Ring")); |
Stepan Salenikovich | 36c025c | 2015-03-03 19:06:44 -0500 | [diff] [blame] | 80 | g_option_context_set_ignore_unknown_options(context, TRUE); |
Stepan Salenikovich | d81ef29 | 2015-02-17 18:47:37 -0500 | [diff] [blame] | 81 | |
| 82 | /* TODO: add translation domain */ |
| 83 | g_option_context_add_main_entries(context, all_options, NULL); |
| 84 | g_option_context_add_group(context, gtk_get_option_group(TRUE)); |
| 85 | return context; |
| 86 | } |
Stepan Salenikovich | 0d515e5 | 2015-05-19 16:31:05 -0400 | [diff] [blame] | 87 | #endif |