blob: 6901a03d6ac7a9ffdb905c1c2f26f432e2805073 [file] [log] [blame]
Stepan Salenikovichd81ef292015-02-17 18:47:37 -05001/*
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 Salenikovichc1dac252015-03-25 17:19:35 -040033#include "config.h"
Stepan Salenikovichd81ef292015-02-17 18:47:37 -050034#include <glib/gi18n.h>
35#include <gtk/gtk.h>
36#include <stdlib.h>
37
38G_GNUC_NORETURN static gboolean
39option_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 Salenikovichc1dac252015-03-25 17:19:35 -040045 g_print("%d.%d.%d\n", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH);
Stepan Salenikovichd81ef292015-02-17 18:47:37 -050046 exit(EXIT_SUCCESS);
47}
48
49static gboolean
50option_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
60static 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 Salenikovich0d515e52015-05-19 16:31:05 -040066#if GLIB_CHECK_VERSION(2,40,0)
67void
68ring_client_add_options(GApplication *app) {
69 g_application_add_main_option_entries(app, all_options);
70}
71
72#else
Stepan Salenikovichd81ef292015-02-17 18:47:37 -050073GOptionContext *
74ring_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 Salenikovicha1b8cb32015-09-11 14:58:35 -040079 GOptionContext *context = g_option_context_new(_("- GNOME client for Ring"));
Stepan Salenikovich36c025c2015-03-03 19:06:44 -050080 g_option_context_set_ignore_unknown_options(context, TRUE);
Stepan Salenikovichd81ef292015-02-17 18:47:37 -050081
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 Salenikovich0d515e52015-05-19 16:31:05 -040087#endif