1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
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
31 #include <libgnome/gnome-program.h>
32 #include <gtk/gtkwindow.h>
33 #include <libgnomevfs/gnome-vfs.h>
34 #include <libanjuta/resources.h>
35 #include <libanjuta/anjuta-debug.h>
36 #include <libanjuta/interfaces/ianjuta-file-loader.h>
39 #include "bacon-message-connection.h"
45 #define ANJUTA_PIXMAP_SPLASH_SCREEN "anjuta_splash.png"
48 static AnjutaApp
*app
= NULL
;
51 static guint32 startup_timestamp
= 0;
52 static BaconMessageConnection
*connection
;
54 /* Command line options */
56 static gint line_position
= 0;
57 static GList
*file_list
= NULL
;
58 static gboolean no_splash
= 0;
59 static gboolean no_client
= 0;
60 static gboolean no_session
= 0;
61 static gboolean no_files
= 0;
62 static gboolean proper_shutdown
= 0;
63 static gchar
*anjuta_geometry
= NULL
;
64 static gchar
**anjuta_filenames
= NULL
;
66 static const GOptionEntry anjuta_options
[] = {
68 "geometry", 'g', 0, G_OPTION_ARG_STRING
,
70 N_("Specify the size and location of the main window"),
71 /* This is the format you can specify the size andposition
72 * of the window on command line */
73 N_("WIDTHxHEIGHT+XOFF+YOFF")
76 "no-splash", 's', 0, G_OPTION_ARG_NONE
,
78 N_("Do not show the splashscreen"),
82 "no-client", 'c', 0, G_OPTION_ARG_NONE
,
84 N_("Start a new instance and do not open the file in a existing"),
88 "no-session", 'n', 0, G_OPTION_ARG_NONE
,
90 N_("Do not open last session on startup"),
94 "no-files", 'f', 0, G_OPTION_ARG_NONE
,
96 N_("Do not open last project and files on startup"),
100 "proper-shutdown", 'p', 0, G_OPTION_ARG_NONE
,
102 N_("Shutdown anjuta properly releasing all resources (for debugging)"),
106 G_OPTION_REMAINING
, 0, 0, G_OPTION_ARG_FILENAME_ARRAY
,
115 get_real_path (const gchar
*file_name
)
119 gchar path
[PATH_MAX
+1];
122 uri_scheme
= gnome_vfs_get_uri_scheme (file_name
);
125 memset(path
, '\0', PATH_MAX
+1);
126 realpath(file_name
, path
);
127 return g_strdup (path
);
130 return g_strdup (file_name
);
137 get_command_line_args ()
140 if (anjuta_filenames
)
141 for (i
= 0; anjuta_filenames
[i
]; i
++)
142 file_list
= g_list_append (file_list
,
143 get_real_path (anjuta_filenames
[i
]));
147 display_open_if_needed (const gchar
*name
)
151 GdkDisplay
*display
= NULL
;
153 displays
= gdk_display_manager_list_displays (gdk_display_manager_get ());
155 for (l
= displays
; l
!= NULL
; l
= l
->next
)
157 if (strcmp (gdk_display_get_name ((GdkDisplay
*) l
->data
), name
) == 0)
164 g_slist_free (displays
);
166 return display
!= NULL
? display
: gdk_display_open (name
);
171 on_message_received (const char *message
, gpointer data
)
182 g_return_if_fail (message
!= NULL
);
184 commands
= g_strsplit (message
, "\v", -1);
187 params
= g_strsplit (commands
[0], "\t", 4);
188 startup_timestamp
= atoi (params
[0]); /* CHECK if this is safe */
189 display_name
= g_strdup (params
[1]);
190 screen_number
= atoi (params
[2]);
192 display
= display_open_if_needed (display_name
);
193 screen
= gdk_display_get_screen (display
, screen_number
);
194 g_free (display_name
);
199 gtk_window_present (GTK_WINDOW (app
));
203 params
= g_strsplit (commands
[i
], "\t", -1);
205 if (strcmp (params
[0], "OPEN-URIS") == 0)
210 line_position
= atoi (params
[1]);
212 n_uris
= atoi (params
[2]);
213 uris
= g_strsplit (params
[3], " ", n_uris
);
215 for (i
= 0; i
< n_uris
; i
++)
216 file_list
= g_list_prepend (file_list
, uris
[i
]);
217 file_list
= g_list_reverse (file_list
);
219 /* the list takes ownerhip of the strings,
220 * only free the array */
225 g_warning ("Unexpected bacon command");
232 g_strfreev (commands
);
234 /* execute the commands */
236 for (file
= file_list
; file
!= NULL
; file
= g_list_next (file
))
238 IAnjutaFileLoader
* loader
=
239 anjuta_shell_get_interface(ANJUTA_SHELL(app
), IAnjutaFileLoader
, NULL
);
240 GFile
* gfile
= g_file_new_for_commandline_arg(file
->data
);
243 ianjuta_file_loader_load(loader
, gfile
, FALSE
, NULL
);
244 g_object_unref (gfile
);
248 /* free the file list and reset to default */
249 g_list_foreach (file_list
, (GFunc
) g_free
, NULL
);
250 g_list_free (file_list
);
258 send_bacon_message (void)
262 const gchar
*display_name
;
266 screen
= gdk_screen_get_default ();
267 display
= gdk_screen_get_display (screen
);
269 display_name
= gdk_display_get_name (display
);
270 screen_number
= gdk_screen_get_number (screen
);
272 command
= g_string_new (NULL
);
275 g_string_append_printf (command
,
276 "%" G_GUINT32_FORMAT
"\t%s\t%d",
281 /* OPEN_URIS command, optionally specify line_num and encoding */
286 command
= g_string_append_c (command
, '\v');
287 command
= g_string_append (command
, "OPEN-URIS");
289 g_string_append_printf (command
,
292 g_list_length (file_list
));
294 for (l
= file_list
; l
!= NULL
; l
= l
->next
)
296 command
= g_string_append (command
, l
->data
);
298 command
= g_string_append_c (command
, ' ');
302 bacon_message_connection_send (connection
,
305 g_string_free (command
, TRUE
);
309 main (int argc
, char *argv
[])
311 GnomeProgram
*program
;
312 GOptionContext
*context
;
316 context
= g_option_context_new (_("- Integrated Development Environment"));
318 setlocale (LC_ALL
, "");
319 bindtextdomain (GETTEXT_PACKAGE
, PACKAGE_LOCALE_DIR
);
320 bind_textdomain_codeset(GETTEXT_PACKAGE
, "UTF-8");
321 textdomain (GETTEXT_PACKAGE
);
322 g_option_context_add_main_entries (context
, anjuta_options
, PACKAGE
);
324 g_option_context_add_main_entries (context
, anjuta_options
, NULL
);
327 data_dir
= g_strdup (PACKAGE_DATA_DIR
);
328 data_dir
[strlen (data_dir
) - strlen (PACKAGE
) - 1] = '\0';
330 /* Initialize threads, if possible */
331 #ifdef G_THREADS_ENABLED
332 if (!g_thread_supported()) g_thread_init(NULL
);
334 #warning "Some plugins won't work without thread support"
337 /* Initialize gnome program */
338 g_option_context_parse (context
, &argc
, &argv
, NULL
);
339 program
= gnome_program_init (PACKAGE
, VERSION
,
340 LIBGNOMEUI_MODULE
, argc
, argv
,
341 GNOME_PARAM_GOPTION_CONTEXT
, context
,
342 GNOME_PARAM_HUMAN_READABLE_NAME
,
343 _("Integrated Development Environment"),
344 GNOME_PARAM_APP_DATADIR
, data_dir
,
348 /* Get the command line files */
349 get_command_line_args ();
351 connection
= bacon_message_connection_new ("anjuta");
353 if (connection
!= NULL
)
355 if (!bacon_message_connection_get_is_server (connection
) &&
358 DEBUG_PRINT("Client");
359 send_bacon_message ();
361 /* we never popup a window... tell startup-notification
364 gdk_notify_startup_complete ();
366 bacon_message_connection_free (connection
);
372 DEBUG_PRINT("Server");
373 bacon_message_connection_set_callback (connection
,
379 g_warning ("Cannot create the 'anjuta' connection.");
381 g_set_application_name (_("Anjuta"));
382 gtk_window_set_default_icon_name ("anjuta");
383 gtk_window_set_auto_startup_notification(FALSE
);
385 im_file
= anjuta_res_get_pixmap_file (ANJUTA_PIXMAP_SPLASH_SCREEN
);
387 /* Initialize applicatoin */
388 app
= anjuta_new (argv
[0], file_list
, no_splash
, no_session
, no_files
,
389 im_file
, proper_shutdown
, anjuta_geometry
);
392 gtk_window_set_role (GTK_WINDOW (app
), "anjuta-app");
394 /* Run Anjuta application */
395 gtk_window_set_auto_startup_notification(TRUE
);
396 gtk_widget_show (GTK_WIDGET (app
));
399 gnome_vfs_shutdown();