configure: fix build of vala plugin
[anjuta.git] / src / main.c
blobf7f08996d3b4cbe8a01d065d090807216c119d07
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 main.c
4 Copyright (C) 2000 Naba Kumar <naba@gnome.org>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifdef HAVE_CONFIG_H
22 # include <config.h>
23 #endif
25 #ifdef ENABLE_NLS
26 # include <locale.h>
27 #endif
29 #include <sys/stat.h>
30 #include <stdlib.h>
32 #include <gtk/gtk.h>
33 #include <libanjuta/anjuta-debug.h>
34 #include <libxml/parser.h>
36 #include "anjuta.h"
38 #ifdef ENABLE_NLS
39 #include <locale.h>
40 #endif
42 /* Command line options */
43 static gboolean no_splash = 0;
44 static gboolean no_client = 0;
45 static gboolean no_session = 0;
46 static gboolean no_files = 0;
47 static gboolean proper_shutdown = 0;
48 static gchar *anjuta_geometry = NULL;
49 static gchar **anjuta_filenames = NULL;
51 static gboolean
52 show_version_cb (const char *option_name,
53 const char *value,
54 gpointer data,
55 GError **error)
57 g_print ("%s\n", PACKAGE_STRING);
58 exit (0);
60 return TRUE;
63 static const GOptionEntry anjuta_options[] = {
65 "geometry", 'g', 0, G_OPTION_ARG_STRING,
66 &anjuta_geometry,
67 N_("Specify the size and location of the main window"),
68 /* This is the format you can specify the size andposition
69 * of the window on command line */
70 N_("WIDTHxHEIGHT+XOFF+YOFF")
73 "no-splash", 's', 0, G_OPTION_ARG_NONE,
74 &no_splash,
75 N_("Do not show the splash screen"),
76 NULL
79 "no-client", 'c', 0, G_OPTION_ARG_NONE,
80 &no_client,
81 N_("Start a new instance and do not open the file in an existing instance"),
82 NULL
85 "no-session", 'n', 0, G_OPTION_ARG_NONE,
86 &no_session,
87 N_("Do not open last session on startup"),
88 NULL
91 "no-files", 'f', 0, G_OPTION_ARG_NONE,
92 &no_files,
93 N_("Do not open last project and files on startup"),
94 NULL
97 "proper-shutdown", 'p', 0, G_OPTION_ARG_NONE,
98 &proper_shutdown,
99 N_("Shut down Anjuta properly, releasing all resources (for debugging)"),
100 NULL
103 "version", 'v', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
104 &show_version_cb,
105 ("Display program version"),
106 NULL
109 G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY,
110 &anjuta_filenames,
111 NULL,
112 NULL
114 {NULL}
117 static void
118 free_files (GFile** files, gint n_files)
120 gint i;
121 for (i = 0; i < n_files; i++)
123 g_object_unref (files[i]);
125 g_free (files);
129 main (int argc, char *argv[])
131 GOptionContext *context;
132 GError* error = NULL;
133 Anjuta* anjuta;
134 GFile** files = NULL;
135 gint n_files = 0;
136 gint status;
138 context = g_option_context_new (_("- Integrated Development Environment"));
139 #ifdef ENABLE_NLS
140 setlocale (LC_ALL, "");
141 bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
142 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
143 textdomain (GETTEXT_PACKAGE);
144 g_option_context_add_main_entries (context, anjuta_options, GETTEXT_PACKAGE);
145 #else
146 g_option_context_add_main_entries (context, anjuta_options, NULL);
147 #endif
149 g_option_context_add_group (context, gtk_get_option_group (TRUE));
151 /* Initialize gnome program */
152 if (!g_option_context_parse (context, &argc, &argv, &error))
154 g_debug ("Option parsing failed: %s", error->message);
155 exit(1);
158 /* Init gtk+ */
159 gtk_init (&argc, &argv);
160 /* Initialize threads */
161 g_thread_init(NULL);
163 /* Init debug helpers */
164 anjuta_debug_init ();
166 /* Convert all file names to URI */
167 /* So an already existing instance of Anjuta having another current
168 * directory can still open the files */
169 if (anjuta_filenames)
171 files = g_new0 (GFile*, 1);
172 gchar** filename;
173 for (filename = anjuta_filenames; *filename != NULL; filename++)
175 GFile* file = g_file_new_for_commandline_arg(*filename);
176 files = g_realloc (files, (n_files + 1) * sizeof (GFile*));
177 files[n_files++] = file;
181 g_set_application_name (_("Anjuta"));
182 anjuta = anjuta_new ();
183 #if GLIB_2_29_2 == 1
184 if (no_client) g_application_set_flags (G_APPLICATION (anjuta), G_APPLICATION_NON_UNIQUE);
185 #endif
186 g_application_register (G_APPLICATION (anjuta), NULL, NULL);
188 #if GLIB_2_29_2 == 1
189 if (g_application_get_is_remote (G_APPLICATION (anjuta)))
190 #else
191 if (g_application_get_is_remote (G_APPLICATION (anjuta)) && !no_client)
192 #endif
194 if (files)
196 g_application_open (G_APPLICATION (anjuta), files, n_files, "");
197 free_files (files, n_files);
200 else
202 AnjutaApp *app = create_window (files, n_files,
203 no_splash, no_session, no_files,
204 proper_shutdown, anjuta_geometry);
205 gtk_window_set_application (GTK_WINDOW (app), GTK_APPLICATION (anjuta));
206 gtk_widget_show (GTK_WIDGET (app));
208 free_files (files, n_files);
211 status = g_application_run (G_APPLICATION (anjuta), argc, argv);
212 g_object_unref (anjuta);
214 /* xmlCleanupParser must be called only one time in the application */
215 if (proper_shutdown) xmlCleanupParser ();
217 return status;