22cbb6090d6d3f9a1f53896bdfe6ba3b94290132
[prss.git] / src / main.c
1 /*
2  * Copyright (C) 2012-2013 jeanfi@gmail.com
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301 USA
18  */
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <getopt.h>
23
24 #include <json/json.h>
25
26 #include <glib/gi18n.h>
27 #include <gtk/gtk.h>
28
29 static const char *program_name;
30
31 static struct option long_options[] = {
32         {"version", no_argument, 0, 'v'},
33         {"help", no_argument, 0, 'h'},
34         {0, 0, 0, 0}
35 };
36
37 static void print_version()
38 {
39         printf("prss %s\n", VERSION);
40         printf(_("Copyright (C) %s jeanfi@gmail.com\n"
41                  "License GPLv2: GNU GPL version 2 or later "
42                  "<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>\n"
43                  "This is free software: you are free to change and "
44                  " redistribute it.\n"
45                  "There is NO WARRANTY, to the extent permitted by law.\n"),
46                "2012-2013");
47 }
48
49 static void print_help()
50 {
51         printf(_("Usage: %s [OPTION]...\n"), program_name);
52
53         puts(_("Prss is a GTK+ news reader for tt-rss."));
54
55         puts("");
56         puts(_("Options:"));
57         puts(_("  -h, --help          display this help and exit\n"
58                "  -v, --version       display version information and exit"));
59
60         puts("");
61
62         printf(_("Report bugs to: %s\n"), PACKAGE_BUGREPORT);
63         puts("");
64         printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
65 }
66
67
68 int main(int argc, char **argv)
69 {
70         GtkWidget *window;
71         GtkBuilder *builder;
72         int optc, cmdok, opti;
73
74         program_name = argv[0];
75
76         setlocale(LC_ALL, "");
77
78 #if ENABLE_NLS
79         bindtextdomain(PACKAGE, LOCALEDIR);
80         textdomain(PACKAGE);
81 #endif
82
83         cmdok = 1;
84         while ((optc = getopt_long(argc, argv, "vh", long_options,
85                                    &opti)) != -1) {
86                 switch (optc) {
87                 case 'h':
88                         print_help();
89                         exit(EXIT_SUCCESS);
90                 case 'v':
91                         print_version();
92                         exit(EXIT_SUCCESS);
93                 default:
94                         cmdok = 0;
95                         break;
96                 }
97         }
98
99         if (!cmdok || optind != argc) {
100                 fprintf(stderr, _("Try `%s --help' for more information.\n"),
101                         program_name);
102                 exit(EXIT_FAILURE);
103         }
104
105         gtk_init(NULL, NULL);
106         builder = gtk_builder_new();
107         gtk_builder_add_from_file
108                 (builder,
109                  PACKAGE_DATA_DIR G_DIR_SEPARATOR_S "prss.glade",
110                  NULL);
111         window = GTK_WIDGET(gtk_builder_get_object(builder, "window"));
112
113         gtk_builder_connect_signals(builder, NULL);
114
115         g_object_unref(G_OBJECT(builder));
116
117         gtk_widget_show_all(window);
118
119         gtk_main();
120
121         exit(EXIT_SUCCESS);
122 }