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
33 #include <unique/unique.h>
34 #include <libanjuta/resources.h>
35 #include <libanjuta/anjuta-debug.h>
36 #include <libanjuta/interfaces/ianjuta-file-loader.h>
44 #define ANJUTA_PIXMAP_SPLASH_SCREEN "anjuta_splash.png"
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
,
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
,
70 N_("Do not show the splashscreen"),
74 "no-client", 'c', 0, G_OPTION_ARG_NONE
,
76 N_("Start a new instance and do not open the file in a existing"),
80 "no-session", 'n', 0, G_OPTION_ARG_NONE
,
82 N_("Do not open last session on startup"),
86 "no-files", 'f', 0, G_OPTION_ARG_NONE
,
88 N_("Do not open last project and files on startup"),
92 "proper-shutdown", 'p', 0, G_OPTION_ARG_NONE
,
94 N_("Shutdown anjuta properly releasing all resources (for debugging)"),
98 G_OPTION_REMAINING
, 0, 0, G_OPTION_ARG_FILENAME_ARRAY
,
106 static UniqueResponse
107 message_received_cb (UniqueApp
*unique
,
108 UniqueCommand command
,
109 UniqueMessageData
*message
,
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
;
125 gchar
** uris
= unique_message_data_get_uris(message
);
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
);
136 res
= UNIQUE_RESPONSE_OK
;
140 res
= UNIQUE_RESPONSE_OK
;
149 main (int argc
, char *argv
[])
151 GOptionContext
*context
;
152 GError
* error
= NULL
;
156 context
= g_option_context_new (_("- Integrated Development Environment"));
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
);
164 g_option_context_add_main_entries (context
, anjuta_options
, NULL
);
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
);
173 #warning "Some plugins won't work without thread support"
176 /* Initialize gnome program */
177 if (!g_option_context_parse (context
, &argc
, &argv
, &error
))
179 DEBUG_PRINT ("Option parsing failed: %s", error
->message
);
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
;
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
)
210 DEBUG_PRINT("Faild to contact first instance, starting up normally");
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
);
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
));