-
Notifications
You must be signed in to change notification settings - Fork 2
/
sb-main.c
80 lines (72 loc) · 2.33 KB
/
sb-main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* This file is part of source browser
*
* AUTHORS
* Sven Herzberg <herzi@gnome-de.org>
*
* Copyright (C) 2007 Sven Herzberg
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include "sb-window.h"
#include <gio/gio.h>
#include <glib/gi18n.h>
int
main (int argc,
char**argv)
{
gchar** files = NULL;
GError* error = NULL;
GOptionContext* context = g_option_context_new (_("[FILE]"));
GOptionEntry entries[] = {
{G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &files, "", ""},
{NULL}
};
g_option_context_set_help_enabled (context, TRUE);
g_option_context_set_ignore_unknown_options (context, FALSE);
g_option_context_add_group (context, gtk_get_option_group (TRUE));
g_option_context_add_main_entries (context, entries, NULL);
if (!g_option_context_parse (context, &argc, &argv, &error)) {
gchar* help = g_option_context_get_help (context, TRUE, NULL);
g_printerr ("%s\nInvalid arguments%s%s\n",
help,
error ? ": " : "",
error ? error->message : "");
g_option_context_free (context);
g_clear_error (&error);
g_free (help);
return 1;
}
if (files && g_strv_length (files) > 1) {
gchar* help = g_option_context_get_help (context, TRUE, NULL);
g_printerr ("%s\nInvalid arguments: only one file supported\n",
help);
g_option_context_free (context);
g_free (help);
return 1;
}
g_option_context_free (context);
GtkWidget* window = sb_window_new ();
gtk_widget_show (window);
if (files) {
GFile* file = g_file_new_for_commandline_arg (files[0]);
gchar* path = g_file_get_path (file);
sb_window_open (window, path);
g_free (path);
g_object_unref (file);
}
gtk_main ();
return 0;
}