63
56
} runState = STATE_STARTING;
65
gboolean on_quit(GtkWidget *widget, GdkEvent *event, gpointer user_data);
68
/** bacon message callback */
70
on_bacon_message_received (const char *message, gpointer data)
59
COMMAND_0 = 0, /* 0 is not a valid command */
64
message_received_cb (UniqueApp *app,
65
UniqueCommand command,
66
UniqueMessageData *message,
72
debug1(DEBUG_GUI, "bacon message received >>>%s<<<", message);
74
/* Currently we only know a single simple command "raise"
75
which tells the program to raise the window because
76
another instance was requested which is not supported */
78
if (g_str_equal (message, "raise")) {
79
debug0 (DEBUG_GUI, "-> raise window requested");
80
liferea_shell_present ();
82
g_warning ("Received unknown bacon command: >>>%s<<<", message);
73
debug1(DEBUG_GUI, "libunique command received >>>%d<<<", command);
78
/* Raise the liferea window */
79
debug0 (DEBUG_GUI, "-> raise window requested");
80
liferea_shell_present ();
81
res = UNIQUE_RESPONSE_OK;
83
case COMMAND_ADD_FEED:
84
feed = unique_message_data_get_text (message);
85
feedlist_add_subscription (feed, NULL, NULL, 0);
87
res = UNIQUE_RESPONSE_OK;
90
g_warning ("Received unknown libunique command: >>>%d<<<", command);
91
res = UNIQUE_RESPONSE_OK;
86
static void fatal_signal_handler(int sig) {
98
static void G_GNUC_NORETURN
99
fatal_signal_handler (int sig)
90
sigprocmask(SIG_SETMASK, &sigset, NULL);
92
g_print("\nLiferea did receive signal %d (%s).\n", sig, g_strsignal(sig));
95
g_print("You have probably triggered a program bug. I will now try to \n");
96
g_print("create a backtrace which you can attach to any support requests.\n\n");
97
g_on_error_stack_trace(PACKAGE);
103
sigemptyset (&sigset);
104
sigprocmask (SIG_SETMASK, &sigset, NULL);
106
g_print ("\nLiferea did receive signal %d (%s).\n", sig, g_strsignal (sig));
108
g_print ("You have probably triggered a program bug. I will now try to \n");
109
g_print ("create a backtrace which you can attach to any support requests.\n\n");
110
g_on_error_stack_trace (PACKAGE);
132
144
*debug_flags |= DEBUG_PARSING;
133
145
} else if (g_str_equal (option_name, "--debug-performance")) {
134
146
*debug_flags |= DEBUG_PERF;
135
} else if (g_str_equal (option_name, "--debug-plugins")) {
136
*debug_flags |= DEBUG_PLUGINS;
137
147
} else if (g_str_equal (option_name, "--debug-trace")) {
138
148
*debug_flags |= DEBUG_TRACE;
139
149
} else if (g_str_equal (option_name, "--debug-update")) {
140
150
*debug_flags |= DEBUG_UPDATE;
151
} else if (g_str_equal (option_name, "--debug-vfolder")) {
152
*debug_flags |= DEBUG_VFOLDER;
141
153
} else if (g_str_equal (option_name, "--debug-verbose")) {
142
154
*debug_flags |= DEBUG_VERBOSE;
178
194
{ "session", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &opt_session_arg, NULL, NULL },
180
196
{ "version", 'v', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, show_version, N_("Show version information and exit"), NULL },
197
{ "add-feed", 'a', 0, G_OPTION_ARG_STRING, &feed, N_("Add a new subscription"), N_("uri") },
184
201
GOptionEntry debug_entries[] = {
185
202
{ "debug-all", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages of all types"), NULL },
186
203
{ "debug-cache", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages for the cache handling"), NULL },
187
{ "debug-conf", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages of the configuration handling"), NULL },
204
{ "debug-conf", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages for the configuration handling"), NULL },
188
205
{ "debug-db", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages of the database handling"), NULL },
189
206
{ "debug-gui", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages of all GUI functions"), NULL },
190
{ "debug-html", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Enables HTML rendering debugging. Each time Liferea renders HTML output it will also dump the generated HTML into ~/.liferea_1.6/output.xhtml"), NULL },
207
{ "debug-html", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Enables HTML rendering debugging. Each time Liferea renders HTML output it will also dump the generated HTML into ~/.liferea_1.8/output.xhtml"), NULL },
191
208
{ "debug-net", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages of all network activity"), NULL },
192
209
{ "debug-parsing", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages of all parsing functions"), NULL },
193
210
{ "debug-performance", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages when a function takes too long to process"), NULL },
194
{ "debug-plugins", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages for the plugin loading"), NULL },
195
211
{ "debug-trace", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages when entering/leaving functions"), NULL },
196
212
{ "debug-update", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages of the feed update processing"), NULL },
213
{ "debug-vfolder", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages of the search folder matching"), NULL },
197
214
{ "debug-verbose", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print verbose debugging messages"), NULL },
234
251
has to be initialized before update_init() */
238
dbus_g_thread_init ();
241
254
/* We need to do the network initialization here to allow
242
255
network-manager to be setup before gtk_init() */
245
258
gtk_init (&argc, &argv);
260
/* Single instance checks */
261
app = unique_app_new_with_commands ("net.sourceforge.liferea", NULL,
262
"add_feed", COMMAND_ADD_FEED,
264
if (unique_app_is_running (app)) {
265
g_print ("Liferea is already running\n");
266
unique_app_send_message (app, UNIQUE_ACTIVATE, NULL);
268
msg = unique_message_data_new ();
269
unique_message_data_set_text (msg, feed, -1);
270
unique_app_send_message (app, COMMAND_ADD_FEED, msg);
274
g_signal_connect (app, "message-received", G_CALLBACK (message_received_cb), NULL);
247
277
/* GTK theme support */
248
278
g_set_application_name (_("Liferea"));
249
279
gtk_window_set_default_icon_name ("liferea");
251
/* Note: bacon connection check needs to be done after the
252
command line parameter checking to allow help and version
253
switches to be used when we are already running */
254
bacon_connection = bacon_message_connection_new ("liferea");
255
if (bacon_connection) {
256
if (!bacon_message_connection_get_is_server (bacon_connection)) {
257
g_warning(_("Liferea seems to be running already!"));
259
debug0(DEBUG_VERBOSE, "Startup as bacon client...");
260
bacon_message_connection_send (bacon_connection, "raise");
261
bacon_message_connection_free (bacon_connection);
263
gdk_notify_startup_complete ();
266
debug0 (DEBUG_VERBOSE, "Startup as bacon server...");
267
bacon_message_connection_set_callback (bacon_connection,
268
on_bacon_message_received,
272
g_warning ("Cannot create IPC connection for Liferea!");
275
281
debug_start_measurement (DEBUG_DB);
277
283
/* order is important! */
278
284
db_init (); /* initialize sqlite */
279
285
xml_init (); /* initialize libxml2 */
280
plugin_mgmt_init (); /* get list of plugins and initialize them */
281
conf_load (); /* load global feed settings */
282
script_init (); /* setup scripting if supported */
283
social_init (); /* initialized social bookmarking */
285
dbus = liferea_dbus_new ();
287
debug0 (DEBUG_GUI, "Compiled without DBUS support.");
291
if (conf_get_bool_value (SYNC_AVAHI_ENABLED)) {
292
LifereaAvahiPublisher *avahiPublisher = NULL;
294
debug0 (DEBUG_CACHE, "Registering with AVAHI");
295
avahiPublisher = liferea_avahi_publisher_new ();
296
liferea_avahi_publisher_publish (avahiPublisher, conf_get_str_value (SYNC_AVAHI_SERVICE_NAME), 23632);
298
debug0 (DEBUG_CACHE, "Avahi support available, but disabled by preferences.");
301
debug0 (DEBUG_CACHE, "Compiled without AVAHI support");
286
#ifdef HAVE_LIBNOTIFY
287
notification_plugin_register (&libnotify_plugin);
289
social_init (); /* initialize social bookmarking */
291
dbus = liferea_dbus_new ();
304
293
/* how to start liferea, command line takes precedence over preferences */
294
conf_get_bool_value (SHOW_TRAY_ICON, &show_tray_icon);
295
conf_get_bool_value (START_IN_TRAY, &start_in_tray);
305
296
if (g_str_equal(initial_state, "iconified")) {
306
297
initialState = MAINWINDOW_ICONIFIED;
307
298
} else if (g_str_equal(initial_state, "hidden") ||
308
(conf_get_bool_value (SHOW_TRAY_ICON) &&
309
conf_get_bool_value (START_IN_TRAY))) {
299
(show_tray_icon && start_in_tray)) {
310
300
initialState = MAINWINDOW_HIDDEN;
312
302
initialState = MAINWINDOW_SHOWN;