Updated Spanish translation
[anjuta.git] / src / main.c
blob6392a0035dca51a200146274cde8c446a113ff04
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 <unique/unique.h>
34 #include <libanjuta/resources.h>
35 #include <libanjuta/anjuta-debug.h>
36 #include <libanjuta/interfaces/ianjuta-file-loader.h>
38 #include "anjuta.h"
40 #ifdef ENABLE_NLS
41 #include <locale.h>
42 #endif
44 #define ANJUTA_PIXMAP_SPLASH_SCREEN "anjuta_splash.png"
46 /* App */
47 static AnjutaApp *app = NULL;
49 /* Command line options */
50 static gboolean no_splash = 0;
51 static gboolean no_client = 0;
52 static gboolean no_session = 0;
53 static gboolean no_files = 0;
54 static gboolean proper_shutdown = 0;
55 static gchar *anjuta_geometry = NULL;
56 static gchar **anjuta_filenames = NULL;
58 static const GOptionEntry anjuta_options[] = {
60 "geometry", 'g', 0, G_OPTION_ARG_STRING,
61 &anjuta_geometry,
62 N_("Specify the size and location of the main window"),
63 /* This is the format you can specify the size andposition
64 * of the window on command line */
65 N_("WIDTHxHEIGHT+XOFF+YOFF")
68 "no-splash", 's', 0, G_OPTION_ARG_NONE,
69 &no_splash,
70 N_("Do not show the splashscreen"),
71 NULL
74 "no-client", 'c', 0, G_OPTION_ARG_NONE,
75 &no_client,
76 N_("Start a new instance and do not open the file in a existing"),
77 NULL
80 "no-session", 'n', 0, G_OPTION_ARG_NONE,
81 &no_session,
82 N_("Do not open last session on startup"),
83 NULL
86 "no-files", 'f', 0, G_OPTION_ARG_NONE,
87 &no_files,
88 N_("Do not open last project and files on startup"),
89 NULL
92 "proper-shutdown", 'p', 0, G_OPTION_ARG_NONE,
93 &proper_shutdown,
94 N_("Shutdown anjuta properly releasing all resources (for debugging)"),
95 NULL
98 G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY,
99 &anjuta_filenames,
100 NULL,
101 NULL
103 {NULL}
106 static UniqueResponse
107 message_received_cb (UniqueApp *unique,
108 UniqueCommand command,
109 UniqueMessageData *message,
110 guint time_,
111 gpointer user_data)
113 UniqueResponse res;
115 switch (command)
117 case UNIQUE_ACTIVATE:
118 /* move the main window to the screen that sent us the command */
119 gtk_window_set_screen (GTK_WINDOW (app), unique_message_data_get_screen (message));
120 gtk_window_present (GTK_WINDOW (app));
121 res = UNIQUE_RESPONSE_OK;
122 break;
123 case UNIQUE_OPEN:
125 gchar** uris = unique_message_data_get_uris(message);
126 gchar** uri;
127 for (uri = uris; *uri != NULL; uri++)
129 IAnjutaFileLoader* loader =
130 anjuta_shell_get_interface(ANJUTA_SHELL(app), IAnjutaFileLoader, NULL);
131 GFile* gfile = g_file_new_for_commandline_arg(*uri);
132 ianjuta_file_loader_load(loader, gfile, FALSE, NULL);
133 g_object_unref (gfile);
135 g_strfreev(uris);
136 res = UNIQUE_RESPONSE_OK;
137 break;
139 default:
140 res = UNIQUE_RESPONSE_OK;
141 break;
144 return res;
149 main (int argc, char *argv[])
151 GOptionContext *context;
152 GError* error = NULL;
153 gchar* im_file;
154 UniqueApp* unique;
156 context = g_option_context_new (_("- Integrated Development Environment"));
157 #ifdef ENABLE_NLS
158 setlocale (LC_ALL, "");
159 bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
160 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
161 textdomain (GETTEXT_PACKAGE);
162 g_option_context_add_main_entries (context, anjuta_options, GETTEXT_PACKAGE);
163 #else
164 g_option_context_add_main_entries (context, anjuta_options, NULL);
165 #endif
167 g_option_context_add_group (context, gtk_get_option_group (TRUE));
169 /* Initialize threads, if possible */
170 #ifdef G_THREADS_ENABLED
171 if (!g_thread_supported()) g_thread_init(NULL);
172 #else
173 #warning "Some plugins won't work without thread support"
174 #endif
176 /* Initialize gnome program */
177 if (!g_option_context_parse (context, &argc, &argv, &error))
179 DEBUG_PRINT ("Option parsing failed: %s", error->message);
180 exit(1);
183 /* Init debug helpers */
184 anjuta_debug_init ();
186 unique = unique_app_new ("org.gnome.anjuta", NULL);
188 if (unique_app_is_running(unique))
190 UniqueResponse response;
192 if (!no_client)
194 if (anjuta_filenames)
196 UniqueMessageData* message = unique_message_data_new();
197 if (!unique_message_data_set_uris (message, anjuta_filenames))
198 g_warning("Set uris failed");
199 response = unique_app_send_message (unique, UNIQUE_OPEN, message);
200 unique_message_data_free(message);
202 response = unique_app_send_message (unique, UNIQUE_ACTIVATE, NULL);
204 /* we don't need the application instance anymore */
205 g_object_unref (unique);
207 if (response == UNIQUE_RESPONSE_OK)
208 return 0;
209 else
210 DEBUG_PRINT("Faild to contact first instance, starting up normally");
214 /* Init gtk+ */
215 gtk_init (&argc, &argv);
216 g_set_application_name (_("Anjuta"));
217 gtk_window_set_default_icon_name ("anjuta");
218 gtk_window_set_auto_startup_notification(FALSE);
220 /* Initialize application */
221 im_file = anjuta_res_get_pixmap_file (ANJUTA_PIXMAP_SPLASH_SCREEN);
222 app = anjuta_new (argv[0], anjuta_filenames, no_splash, no_session, no_files,
223 im_file, proper_shutdown, anjuta_geometry);
224 g_signal_connect (unique, "message-received", G_CALLBACK (message_received_cb), NULL);
226 g_free (im_file);
227 gtk_window_set_role (GTK_WINDOW (app), "anjuta-app");
229 /* Run Anjuta application */
230 gtk_window_set_auto_startup_notification(TRUE);
231 gtk_widget_show (GTK_WIDGET (app));
232 gtk_main();
234 return 0;