1 // -*- C++ -*-
2
3 /*
4 * Gnome Crystal
5 * main.cc
6 *
7 * Copyright (C) 2000-2011 Jean Bréfort <jean.brefort@normalesup.org>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 3 of the
12 * License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
22 * USA
23 */
24
25 #include "config.h"
26 #include <sys/stat.h>
27 #include <unistd.h>
28 #include <gcu/element.h>
29 #include <gcu/macros.h>
30 #include "application.h"
31 #include "document.h"
32 #include "view.h"
33 #include <glib/gi18n.h>
34 #include <cstdio>
35 #include <cstring>
36
37 using namespace gcu;
38 using namespace std;
39
40 extern GtkWidget *vbox1;
41
42 gcDocument* pDoc;
43 gcView* pView;
44 GtkWidget *mainwindow, *vbox1 ;
45 GOConfNode *node;
46
cb_print_version(G_GNUC_UNUSED const gchar * option_name,G_GNUC_UNUSED const gchar * value,G_GNUC_UNUSED gpointer data,G_GNUC_UNUSED GError ** error)47 static void cb_print_version (G_GNUC_UNUSED const gchar *option_name, G_GNUC_UNUSED const gchar *value, G_GNUC_UNUSED gpointer data, G_GNUC_UNUSED GError **error)
48 {
49 char *version = g_strconcat (_("Gnome Chemistry Utils version: "), VERSION, NULL);
50 puts (version);
51 g_free (version);
52 exit (0);
53 }
54
55 static GOptionEntry entries[] =
56 {
57 { "version", 'v', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (void*) cb_print_version, "prints Gnome Crystal version", NULL },
58 { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
59 };
60
main(int argc,char * argv[])61 int main(int argc, char *argv[])
62 {
63 GOptionContext *context;
64 GError *error = NULL;
65
66 gtk_init (&argc, &argv);
67 Element::LoadRadii ();
68 if (argc > 1 && argv[1][0] == '-') {
69 context = g_option_context_new (_(" [file...]"));
70 g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
71 g_option_context_add_group (context, gtk_get_option_group (TRUE));
72 g_option_context_set_help_enabled (context, TRUE);
73 g_option_context_parse (context, &argc, &argv, &error);
74 if (error) {
75 puts (error->message);
76 g_error_free (error);
77 return -1;
78 }
79 } else {
80 argc --;
81 argv ++;
82 }
83
84 gcr::Application* gcApp = new gcApplication ();
85 gcr::Document *pDoc = gcApp->OnFileNew();
86 gcApp->SetOpening();
87
88 char *path, *uri;
89 bool bres = false;
90 while (*argv) {
91 if (**argv == '-') {
92 printf (_("Invalid or misplaced argument: %s\n"), *argv);
93 delete gcApp;
94 exit (-1);
95 }
96 if (strstr (*argv, "://"))
97 uri = g_strdup (*argv);
98 else {
99 if (g_path_is_absolute (*argv))
100 path = g_strdup (*argv);
101 else {
102 char *dir = g_get_current_dir ();
103 path = g_build_filename (dir, *argv, NULL);
104 g_free (dir);
105 }
106 uri = g_filename_to_uri (path, NULL, NULL);
107 g_free (path);
108 }
109 if (bres)
110 pDoc = gcApp->OnFileNew ();
111 char *mime_type = go_get_mime_type (uri);
112 bres = gcApp->FileProcess (uri, mime_type, false, NULL, pDoc);
113 g_free (mime_type);
114 g_free (uri);
115 argv++;
116 }
117 gtk_main ();
118
119 delete gcApp;
120
121 return 0 ;
122 }
123