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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #include <gtk/gtkwindow.h>
33 #include <libgnomevfs/gnome-vfs-utils.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 N_("WIDTHxHEIGHT+XOFF+YOFF")
74 "no-splash", 's', 0, G_OPTION_ARG_NONE
,
76 N_("Do not show the splashscreen"),
80 "no-client", 'c', 0, G_OPTION_ARG_NONE
,
82 N_("Start a new instance and do not open the file in a existing"),
86 "no-session", 'n', 0, G_OPTION_ARG_NONE
,
88 N_("Do not open last session on startup"),
92 "no-files", 'f', 0, G_OPTION_ARG_NONE
,
94 N_("Do not open last project and files on startup"),
98 "proper-shutdown", 'p', 0, G_OPTION_ARG_NONE
,
100 N_("Shutdown anjuta properly releasing all resources (for debugging)"),
104 G_OPTION_REMAINING
, 0, 0, G_OPTION_ARG_FILENAME_ARRAY
,
113 get_real_path (const gchar
*file_name
)
117 gchar path
[PATH_MAX
+1];
120 uri_scheme
= gnome_vfs_get_uri_scheme (file_name
);
123 memset(path
, '\0', PATH_MAX
+1);
124 realpath(file_name
, path
);
125 return g_strdup (path
);
128 return g_strdup (file_name
);
135 get_command_line_args ()
138 if (anjuta_filenames
)
139 for (i
= 0; anjuta_filenames
[i
]; i
++)
140 file_list
= g_list_append (file_list
,
141 get_real_path (anjuta_filenames
[i
]));
145 display_open_if_needed (const gchar
*name
)
149 GdkDisplay
*display
= NULL
;
151 displays
= gdk_display_manager_list_displays (gdk_display_manager_get ());
153 for (l
= displays
; l
!= NULL
; l
= l
->next
)
155 if (strcmp (gdk_display_get_name ((GdkDisplay
*) l
->data
), name
) == 0)
162 g_slist_free (displays
);
164 return display
!= NULL
? display
: gdk_display_open (name
);
169 on_message_received (const char *message
, gpointer data
)
179 g_return_if_fail (message
!= NULL
);
181 commands
= g_strsplit (message
, "\v", -1);
184 params
= g_strsplit (commands
[0], "\t", 4);
185 startup_timestamp
= atoi (params
[0]); /* CHECK if this is safe */
186 display_name
= g_strdup (params
[1]);
187 screen_number
= atoi (params
[2]);
189 display
= display_open_if_needed (display_name
);
190 screen
= gdk_display_get_screen (display
, screen_number
);
191 g_free (display_name
);
196 gtk_window_present (GTK_WINDOW (app
));
200 params
= g_strsplit (commands
[i
], "\t", -1);
202 if (strcmp (params
[0], "OPEN-URIS") == 0)
207 line_position
= atoi (params
[1]);
209 n_uris
= atoi (params
[2]);
210 uris
= g_strsplit (params
[3], " ", n_uris
);
212 for (i
= 0; i
< n_uris
; i
++)
213 file_list
= g_list_prepend (file_list
, uris
[i
]);
214 file_list
= g_list_reverse (file_list
);
216 /* the list takes ownerhip of the strings,
217 * only free the array */
222 g_warning ("Unexpected bacon command");
229 g_strfreev (commands
);
231 /* execute the commands */
233 while (file_list
!= NULL
)
235 IAnjutaFileLoader
* file
=
236 anjuta_shell_get_interface(ANJUTA_SHELL(app
), IAnjutaFileLoader
, NULL
);
237 gchar
* uri
= g_strdup_printf("%s:%d", (gchar
*) file_list
->data
, line_position
);
239 ianjuta_file_loader_load(file
, file_list
->data
, FALSE
, NULL
);
241 file_list
= g_list_next(file_list
);
244 /* free the file list and reset to default */
245 g_list_foreach (file_list
, (GFunc
) g_free
, NULL
);
246 g_list_free (file_list
);
254 send_bacon_message (void)
258 const gchar
*display_name
;
262 screen
= gdk_screen_get_default ();
263 display
= gdk_screen_get_display (screen
);
265 display_name
= gdk_display_get_name (display
);
266 screen_number
= gdk_screen_get_number (screen
);
268 command
= g_string_new (NULL
);
271 g_string_append_printf (command
,
272 "%" G_GUINT32_FORMAT
"\t%s\t%d",
277 /* OPEN_URIS command, optionally specify line_num and encoding */
282 command
= g_string_append_c (command
, '\v');
283 command
= g_string_append (command
, "OPEN-URIS");
285 g_string_append_printf (command
,
288 g_list_length (file_list
));
290 for (l
= file_list
; l
!= NULL
; l
= l
->next
)
292 command
= g_string_append (command
, l
->data
);
294 command
= g_string_append_c (command
, ' ');
298 bacon_message_connection_send (connection
,
301 g_string_free (command
, TRUE
);
305 main (int argc
, char *argv
[])
307 GnomeProgram
*program
;
308 GOptionContext
*context
;
312 context
= g_option_context_new (_("- Integrated Development Environment"));
314 setlocale (LC_ALL
, "");
315 bindtextdomain (GETTEXT_PACKAGE
, PACKAGE_LOCALE_DIR
);
316 bind_textdomain_codeset(GETTEXT_PACKAGE
, "UTF-8");
317 textdomain (GETTEXT_PACKAGE
);
318 g_option_context_add_main_entries (context
, anjuta_options
, PACKAGE
);
320 g_option_context_add_main_entries (context
, anjuta_options
, NULL
);
323 data_dir
= g_strdup (PACKAGE_DATA_DIR
);
324 data_dir
[strlen (data_dir
) - strlen (PACKAGE
) - 1] = '\0';
326 /* Initialize threads, if possible */
327 #ifdef G_THREADS_ENABLED
328 if (!g_thread_supported()) g_thread_init(NULL
);
330 #warning "Some plugins won't work without thread support"
333 /* Initialize gnome program */
334 g_option_context_parse (context
, &argc
, &argv
, NULL
);
335 program
= gnome_program_init (PACKAGE
, VERSION
,
336 LIBGNOMEUI_MODULE
, argc
, argv
,
337 GNOME_PARAM_GOPTION_CONTEXT
, context
,
338 GNOME_PARAM_HUMAN_READABLE_NAME
,
339 _("Integrated Development Environment"),
340 GNOME_PARAM_APP_DATADIR
, data_dir
,
344 /* Get the command line files */
345 get_command_line_args ();
347 connection
= bacon_message_connection_new ("anjuta");
349 if (connection
!= NULL
)
351 if (!bacon_message_connection_get_is_server (connection
) &&
354 DEBUG_PRINT("Client");
355 send_bacon_message ();
357 /* we never popup a window... tell startup-notification
360 gdk_notify_startup_complete ();
362 bacon_message_connection_free (connection
);
368 DEBUG_PRINT("Server");
369 bacon_message_connection_set_callback (connection
,
375 g_warning ("Cannot create the 'anjuta' connection.");
377 g_set_application_name (_("Anjuta"));
378 gtk_window_set_default_icon_name ("anjuta");
379 gtk_window_set_auto_startup_notification(FALSE
);
381 im_file
= anjuta_res_get_pixmap_file (ANJUTA_PIXMAP_SPLASH_SCREEN
);
383 /* Initialize applicatoin */
384 app
= anjuta_new (argv
[0], file_list
, no_splash
, no_session
, no_files
,
385 im_file
, proper_shutdown
, anjuta_geometry
);
388 gtk_window_set_role (GTK_WINDOW (app
), "anjuta-app");
390 /* Run Anjuta application */
391 gtk_window_set_auto_startup_notification(TRUE
);
392 gtk_widget_show (GTK_WIDGET (app
));