static void gnac_ui_init_unique(void) { #ifdef HAVE_LIBUNIQUE /* We only want a single instance of gnac to be running */ app = unique_app_new_with_commands("org.gnome.Gnac", NULL, "add-files", UNIQUE_CMD_ADD, "debug" , UNIQUE_CMD_DEBUG, "verbose" , UNIQUE_CMD_VERBOSE, NULL); g_signal_connect(app, "message-received", G_CALLBACK(gnac_ui_message_received_cb), NULL); if (unique_app_is_running(app)) { libgnac_info(_("An instance of Gnac is already running")); UniqueResponse response; /* Give the focus to the running instance */ response = unique_app_send_message(app, UNIQUE_ACTIVATE, NULL); /* Transmit the debug option */ if (options.debug) { response = unique_app_send_message(app, UNIQUE_CMD_DEBUG, NULL); if (response != UNIQUE_RESPONSE_OK) { libgnac_warning(_("Failed to transmit the debug option")); } /* Transmit the verbose option */ } else if (options.verbose) { response = unique_app_send_message(app, UNIQUE_CMD_VERBOSE, NULL); if (response != UNIQUE_RESPONSE_OK) { libgnac_warning(_("Failed to transmit the verbose option")); } } /* Transmit filenames */ if (options.filenames) { UniqueMessageData *message = unique_message_data_new(); gchar **uris = gnac_utils_get_filenames_from_cmd_line(options.filenames); g_strfreev(options.filenames); if (!unique_message_data_set_uris(message, uris)) { libgnac_warning(_("Failed to convert some uris")); } g_strfreev(uris); response = unique_app_send_message(app, UNIQUE_CMD_ADD, message); unique_message_data_free(message); if (response != UNIQUE_RESPONSE_OK) { libgnac_warning(_("Failed to transmit filenames")); } else { libgnac_info(_("Filenames transmitted to the running instance")); } } g_object_unref(app); gnac_exit(response == UNIQUE_RESPONSE_OK); } #endif /* HAVE_LIBUNIQUE */ }
int main (int argc, char **argv) { UniqueApp *app; GtkWidget *window; g_thread_init (NULL); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); gtk_init (&argc, &argv); /* TODO: use GOption to parse arguments */ app = unique_app_new_with_commands ("com.intel.Bisho", NULL, "callback", COMMAND_CALLBACK, NULL); if (unique_app_is_running (app)) { UniqueResponse response; if (argc != 2) { response = unique_app_send_message (app, UNIQUE_ACTIVATE, NULL); } else { UniqueMessageData *msg; msg = unique_message_data_new (); unique_message_data_set_uris (msg, argv + 1); response = unique_app_send_message (app, COMMAND_CALLBACK, msg); unique_message_data_free (msg); } if (response == UNIQUE_RESPONSE_OK) goto done; } load_modules (); window = bisho_window_new (); unique_app_watch_window (app, GTK_WINDOW (window)); g_signal_connect (app, "message-received", G_CALLBACK (unique_message_cb), window); g_signal_connect (window, "delete-event", gtk_main_quit, NULL); gtk_widget_show (window); gtk_main (); done: g_object_unref (app); return 0; }
static gint luaH_unique_new(lua_State *L) { if (application) luaL_error(L, "unique app already setup"); const gchar *name = luaL_checkstring(L, 1); application = unique_app_new_with_commands(name, NULL, "message", 1, NULL); g_signal_connect(G_OBJECT(application), "message-received", G_CALLBACK(message_cb), L); return 0; }
int main (int argc, char *argv[]) { #if HAVE_GEOCLUE EmpathyLocationManager *location_manager = NULL; #endif EmpathyStatusIcon *icon; EmpathyDispatcher *dispatcher; TpAccountManager *account_manager; EmpathyLogManager *log_manager; EmpathyChatroomManager *chatroom_manager; EmpathyCallFactory *call_factory; EmpathyFTFactory *ft_factory; GtkWidget *window; EmpathyIdle *idle; EmpathyConnectivity *connectivity; GError *error = NULL; TpDBusDaemon *dbus_daemon; UniqueApp *unique_app; gboolean chatroom_manager_ready; GOptionContext *optcontext; GOptionEntry options[] = { { "no-connect", 'n', 0, G_OPTION_ARG_NONE, &no_connect, N_("Don't connect on startup"), NULL }, { "start-hidden", 'h', 0, G_OPTION_ARG_NONE, &start_hidden, N_("Don't display the contact list or any other dialogs on startup"), NULL }, { "accounts", 'a', 0, G_OPTION_ARG_NONE, &account_dialog_only, N_("Show the accounts dialog"), NULL }, { "version", 'v', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, show_version_cb, NULL, NULL }, { NULL } }; /* Init */ g_thread_init (NULL); empathy_init (); optcontext = g_option_context_new (N_("- Empathy IM Client")); g_option_context_add_group (optcontext, gst_init_get_option_group ()); g_option_context_add_group (optcontext, gtk_get_option_group (TRUE)); g_option_context_add_main_entries (optcontext, options, GETTEXT_PACKAGE); if (!g_option_context_parse (optcontext, &argc, &argv, &error)) { g_print ("%s\nRun '%s --help' to see a full list of available command line options.\n", error->message, argv[0]); g_warning ("Error in empathy init: %s", error->message); return EXIT_FAILURE; } g_option_context_free (optcontext); empathy_gtk_init (); g_set_application_name (_(PACKAGE_NAME)); g_setenv ("PULSE_PROP_media.role", "phone", TRUE); #if HAVE_LIBCHAMPLAIN gtk_clutter_init (&argc, &argv); #endif gtk_window_set_default_icon_name ("empathy"); textdomain (GETTEXT_PACKAGE); #ifdef ENABLE_DEBUG /* Set up debugger */ g_log_set_default_handler (default_log_handler, NULL); #endif unique_app = unique_app_new_with_commands ("org.gnome.Empathy", NULL, "accounts_dialog", COMMAND_ACCOUNTS_DIALOG, NULL); if (unique_app_is_running (unique_app)) { unique_app_send_message (unique_app, account_dialog_only ? COMMAND_ACCOUNTS_DIALOG : UNIQUE_ACTIVATE, NULL); g_object_unref (unique_app); return EXIT_SUCCESS; } /* Take well-known name */ dbus_daemon = tp_dbus_daemon_dup (&error); if (error == NULL) { if (!tp_dbus_daemon_request_name (dbus_daemon, "org.gnome.Empathy", TRUE, &error)) { DEBUG ("Failed to request well-known name: %s", error ? error->message : "no message"); g_clear_error (&error); } g_object_unref (dbus_daemon); } else { DEBUG ("Failed to dup dbus daemon: %s", error ? error->message : "no message"); g_clear_error (&error); } if (account_dialog_only) { account_manager = tp_account_manager_dup (); show_accounts_ui (NULL, TRUE); gtk_main (); g_object_unref (account_manager); return 0; } notify_init (_(PACKAGE_NAME)); /* Setting up Idle */ idle = empathy_idle_dup_singleton (); empathy_idle_set_auto_away (idle, TRUE); /* Setting up Connectivity */ connectivity = empathy_connectivity_dup_singleton (); use_conn_notify_cb (empathy_conf_get (), EMPATHY_PREFS_USE_CONN, connectivity); empathy_conf_notify_add (empathy_conf_get (), EMPATHY_PREFS_USE_CONN, use_conn_notify_cb, connectivity); /* account management */ account_manager = tp_account_manager_dup (); tp_account_manager_prepare_async (account_manager, NULL, account_manager_ready_cb, NULL); /* Handle channels */ dispatcher = setup_dispatcher (); g_signal_connect (dispatcher, "dispatch", G_CALLBACK (dispatch_cb), NULL); migrate_config_to_xdg_dir (); /* Setting up UI */ window = empathy_main_window_show (); icon = empathy_status_icon_new (GTK_WINDOW (window), start_hidden); g_signal_connect (unique_app, "message-received", G_CALLBACK (unique_app_message_cb), window); /* Logging */ log_manager = empathy_log_manager_dup_singleton (); empathy_log_manager_observe (log_manager, dispatcher); chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL); empathy_chatroom_manager_observe (chatroom_manager, dispatcher); g_object_get (chatroom_manager, "ready", &chatroom_manager_ready, NULL); if (!chatroom_manager_ready) { g_signal_connect (G_OBJECT (chatroom_manager), "notify::ready", G_CALLBACK (chatroom_manager_ready_cb), account_manager); } else { chatroom_manager_ready_cb (chatroom_manager, NULL, account_manager); } /* Create the call factory */ call_factory = empathy_call_factory_initialise (); g_signal_connect (G_OBJECT (call_factory), "new-call-handler", G_CALLBACK (new_call_handler_cb), NULL); /* Create the FT factory */ ft_factory = empathy_ft_factory_dup_singleton (); g_signal_connect (ft_factory, "new-ft-handler", G_CALLBACK (new_ft_handler_cb), NULL); g_signal_connect (ft_factory, "new-incoming-transfer", G_CALLBACK (new_incoming_transfer_cb), NULL); /* Location mananger */ #if HAVE_GEOCLUE location_manager = empathy_location_manager_dup_singleton (); #endif gtk_main (); empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_OFFLINE); g_object_unref (idle); g_object_unref (connectivity); g_object_unref (icon); g_object_unref (account_manager); g_object_unref (log_manager); g_object_unref (dispatcher); g_object_unref (chatroom_manager); #if HAVE_GEOCLUE g_object_unref (location_manager); #endif g_object_unref (ft_factory); g_object_unref (unique_app); notify_uninit (); return EXIT_SUCCESS; }
int main (int argc, char *argv[]) { UniqueApp *app; UniqueMessageData *msg; GError *error = NULL; GOptionContext *context; GOptionGroup *debug; gulong debug_flags = 0; LifereaDBus *dbus = NULL; const gchar *initial_state = "shown"; gchar *feed = NULL; int initialState; gboolean show_tray_icon, start_in_tray; #ifdef USE_SM gchar *opt_session_arg = NULL; #endif GOptionEntry entries[] = { { "mainwindow-state", 'w', 0, G_OPTION_ARG_STRING, &initial_state, N_("Start Liferea with its main window in STATE. STATE may be `shown', `iconified', or `hidden'"), N_("STATE") }, #ifdef USE_SM { "session", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &opt_session_arg, NULL, NULL }, #endif { "version", 'v', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, show_version, N_("Show version information and exit"), NULL }, { "add-feed", 'a', 0, G_OPTION_ARG_STRING, &feed, N_("Add a new subscription"), N_("uri") }, { NULL } }; GOptionEntry debug_entries[] = { { "debug-all", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages of all types"), NULL }, { "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 }, { "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 }, { "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 }, { "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 }, { "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 }, { "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 }, { "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 }, { "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 }, { "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 }, { "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 }, { "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 }, { "debug-verbose", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print verbose debugging messages"), NULL }, { NULL } }; if (!g_thread_supported ()) g_thread_init (NULL); #ifdef ENABLE_NLS bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif debug = g_option_group_new ("debug", _("Print debugging messages for the given topic"), _("Print debugging messages for the given topic"), &debug_flags, NULL); g_option_group_set_translation_domain(debug, GETTEXT_PACKAGE); g_option_group_add_entries (debug, debug_entries); context = g_option_context_new (NULL); g_option_context_set_summary (context, N_("Liferea, the Linux Feed Reader")); g_option_context_set_description (context, N_("For more information, please visit http://liferea.sourceforge.net/")); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); g_option_context_set_translation_domain(context, GETTEXT_PACKAGE); g_option_context_add_group (context, debug); g_option_context_add_group (context, gtk_get_option_group (FALSE)); g_option_context_parse (context, &argc, &argv, &error); g_option_context_free (context); if (error) { g_print ("Error parsing options: %s\n", error->message); } set_debug_level (debug_flags); /* Configuration necessary for network options, so it has to be initialized before update_init() */ conf_init (); #ifdef USE_DBUS dbus_g_thread_init (); #endif /* We need to do the network initialization here to allow network-manager to be setup before gtk_init() */ update_init (); gtk_init (&argc, &argv); /* Single instance checks */ app = unique_app_new_with_commands ("net.sourceforge.liferea", NULL, "add_feed", COMMAND_ADD_FEED, NULL); if (unique_app_is_running (app)) { g_print ("Liferea is already running\n"); unique_app_send_message (app, UNIQUE_ACTIVATE, NULL); if (feed) { msg = unique_message_data_new (); unique_message_data_set_text (msg, feed, -1); unique_app_send_message (app, COMMAND_ADD_FEED, msg); } return 1; } else { g_signal_connect (app, "message-received", G_CALLBACK (message_received_cb), NULL); } /* GTK theme support */ g_set_application_name (_("Liferea")); gtk_window_set_default_icon_name ("liferea"); debug_start_measurement (DEBUG_DB); /* order is important! */ db_init (); /* initialize sqlite */ xml_init (); /* initialize libxml2 */ #ifdef HAVE_LIBNOTIFY notification_plugin_register (&libnotify_plugin); #endif social_init (); /* initialize social bookmarking */ #ifdef USE_DBUS dbus = liferea_dbus_new (); #else debug0 (DEBUG_GUI, "Compiled without DBUS support."); #endif #ifdef USE_AVAHI if (conf_get_bool_value (SYNC_AVAHI_ENABLED)) { LifereaAvahiPublisher *avahiPublisher = NULL; debug0 (DEBUG_CACHE, "Registering with AVAHI"); avahiPublisher = liferea_avahi_publisher_new (); liferea_avahi_publisher_publish (avahiPublisher, conf_get_str_value (SYNC_AVAHI_SERVICE_NAME), 23632); } else { debug0 (DEBUG_CACHE, "Avahi support available, but disabled by preferences."); } #else debug0 (DEBUG_CACHE, "Compiled without AVAHI support"); #endif /* how to start liferea, command line takes precedence over preferences */ conf_get_bool_value (SHOW_TRAY_ICON, &show_tray_icon); conf_get_bool_value (START_IN_TRAY, &start_in_tray); if (g_str_equal(initial_state, "iconified")) { initialState = MAINWINDOW_ICONIFIED; } else if (g_str_equal(initial_state, "hidden") || (show_tray_icon && start_in_tray)) { initialState = MAINWINDOW_HIDDEN; } else { initialState = MAINWINDOW_SHOWN; } liferea_shell_create (initialState); g_set_prgname ("liferea"); #ifdef USE_SM /* This must be after feedlist reading because some session managers will tell Liferea to exit if Liferea does not respond to SM requests within a minute or two. This starts the main loop soon after opening the SM connection. */ session_init (BIN_DIR G_DIR_SEPARATOR_S "liferea", opt_session_arg); session_set_cmd (NULL, initialState); #endif signal (SIGTERM, signal_handler); signal (SIGINT, signal_handler); signal (SIGHUP, signal_handler); #ifndef G_OS_WIN32 signal (SIGBUS, fatal_signal_handler); signal (SIGSEGV, fatal_signal_handler); #endif /* Note: we explicitely do not use the gdk_thread_* locking in Liferea because it freezes the program when running Flash applets in gtkmozembed */ runState = STATE_STARTING; debug_end_measurement (DEBUG_DB, "startup"); if (feed) feedlist_add_subscription (feed, NULL, NULL, 0); gtk_main (); g_object_unref (G_OBJECT (dbus)); return 0; }
int main(int argc, char* argv[]) try { g_thread_init(NULL); Gio::init(); setlocale(LC_ALL, ""); bindtextdomain(GETTEXT_PACKAGE, gobby_localedir().c_str()); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); bool new_instance = false; bool display_version = false; std::vector<Glib::ustring> hostnames; Glib::OptionGroup opt_group_gobby("gobby", _("Gobby options"), _("Options related to Gobby")); Glib::OptionEntry opt_version; opt_version.set_short_name('v'); opt_version.set_long_name("version"); opt_version.set_description( _("Display version information and exit")); opt_group_gobby.add_entry(opt_version, display_version); Glib::OptionEntry opt_new_instance; opt_new_instance.set_short_name('n'); opt_new_instance.set_long_name("new-instance"); opt_new_instance.set_description( _("Also start a new Gobby instance when there is one " "running already")); opt_group_gobby.add_entry(opt_new_instance, new_instance); Glib::OptionEntry opt_connect; opt_connect.set_short_name('c'); opt_connect.set_long_name("connect"); opt_connect.set_description( _("Connect to given host on startup, can be given multiple times")); opt_connect.set_arg_description(_("HOSTNAME")); opt_group_gobby.add_entry(opt_connect, hostnames); Glib::OptionContext opt_ctx; opt_ctx.set_help_enabled(true); opt_ctx.set_ignore_unknown_options(false); opt_ctx.set_main_group(opt_group_gobby); // I would rather like to have Gtk::Main on the stack, but I see // no other chance to catch exceptions from the command line option // parsing. armin. // TODO: Maybe we should parse before initializing GTK+, using // Gtk::Main::add_gtk_option_group() with open_default_display set // to false. std::auto_ptr<Gtk::Main> kit; try { kit.reset(new Gtk::Main(argc, argv, opt_ctx)); } catch(Glib::Exception& e) { // Protect for non-UTF8 command lines (GTK probably already // converts to UTF-8 in case the system locale is not UTF-8, // but it can happen that input is given not in the system // locale, or simply invalid UTF-8. In that case, printing // e.what() on stdout would throw another exception, which we // want to avoid here, because otherwise we would want to // show that exception in an error dialog, but GTK+ failed // to initialize. if(e.what().validate()) std::cerr << e.what() << std::endl; else std::cerr << "Invalid input on command line" << std::endl; return EXIT_FAILURE; } if(display_version) { std::cout << "Gobby " << PACKAGE_VERSION << std::endl; return EXIT_SUCCESS; } #ifdef WITH_UNIQUE UniqueApp* app = unique_app_new_with_commands( "de._0x539.gobby", NULL, "UNIQUE_GOBBY_CONNECT", Gobby::UNIQUE_GOBBY_CONNECT, NULL); if(!new_instance && unique_app_is_running(app)) { int exit_code = my_unique_check_other( app, argc - 1, argv + 1, hostnames); g_object_unref(app); return exit_code; } #endif // WITH_UNIQUE GError* error = NULL; if(!inf_init(&error)) { std::string message = error->message; g_error_free(error); throw std::runtime_error(message); } // Read the configuration Gobby::Config config(Gobby::config_filename("config.xml")); Gobby::Preferences preferences(config); Gobby::CertificateManager cert_manager(preferences); Gobby::IconManager icon_manager; // Set default icon Gtk::Window::set_default_icon_name("gobby-0.5"); // Open a scope here, so that the main window is destructed // before we serialize the preferences, so that if the window // sets options at destruction time, they are stored correctly. { // Create window Gobby::Window wnd( argc-1, argv+1, config, preferences, icon_manager, cert_manager #ifdef WITH_UNIQUE , app #endif ); #ifdef WITH_UNIQUE g_object_unref(app); #endif wnd.show(); for(std::vector<Glib::ustring>::const_iterator i = hostnames.begin(); i != hostnames.end(); ++ i) { wnd.connect_to_host(*i); } wnd.signal_hide().connect(sigc::ptr_fun(&Gtk::Main::quit) ); kit->run(); } preferences.serialize(config); //inf_deinit(); return 0; } catch(Glib::Exception& e) { handle_exception(e.what() ); } catch(std::exception& e) { handle_exception(e.what() ); }
int main(int argc, char **argv) { struct Gtkabber gtkabber; gboolean version = FALSE; GError *error = NULL; UniqueApp *unique_app; int i = 1; if (!g_thread_supported()) g_thread_init(NULL); memset( >kabber, '\0', sizeof( struct Gtkabber ) ); GOptionEntry cmdline_ops[] = { { "version", 'v', 0, G_OPTION_ARG_NONE, &version, "Print version information", NULL }, { NULL } }; if (!gtk_init_with_args( &argc, &argv, "foo", cmdline_ops, NULL, &(error))) { g_printerr( "Can't init gtk: %s\n", error->message ); g_error_free( error ); return EXIT_FAILURE; } unique_app = unique_app_new_with_commands( "gtkabber.gtkabber", NULL, "next-socket", COMMAND_PRINT_XID, NULL ); if( unique_app_is_running( unique_app )) { unique_instance( argc, argv, unique_app ); return EXIT_SUCCESS; } if (version) { fprintf(stderr, "%s %s\n", "gtkabber ", VERSION); return EXIT_SUCCESS; } setup_toplevel_win( >kabber, unique_app ); for(; i < argc; ++i) { if (strcmp( argv[i], "next-socket" ) == 0) setup_new_socket_for_plug( >kabber ); } gtk_main(); g_object_unref(unique_app); return EXIT_SUCCESS; }