Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
	UniqueApp *app;
	GtkWidget *window;
	GtkWidget *notebook;
	GError *error = NULL;

	bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
	textdomain(GETTEXT_PACKAGE);

	if (gtk_init_with_args(&argc, &argv, NULL,
				options, GETTEXT_PACKAGE, &error) == FALSE) {
		if (error) {
			g_print("%s\n", error->message);
			g_error_free(error);
		} else
			g_print("An unknown error occurred\n");

		return 1;
	}

	if (option_dump != FALSE) {
		dump_devices ();
		return 0;
	}

	app = unique_app_new ("org.mate.Bluetooth.properties", NULL);
	if (unique_app_is_running (app)) {
		gdk_notify_startup_complete ();
		unique_app_send_message (app, UNIQUE_ACTIVATE, NULL);
		return 0;
	}

	g_set_application_name(_("Bluetooth Properties"));

	gtk_window_set_default_icon_name("bluetooth");

	bluetooth_plugin_manager_init ();

	notebook = gtk_notebook_new();
	gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), FALSE);

	setup_adapter(GTK_NOTEBOOK(notebook));

	window = create_window(notebook);

	g_signal_connect (app, "message-received",
			  G_CALLBACK (message_received_cb), window);

	gtk_main();

	bluetooth_plugin_manager_cleanup ();

	cleanup_adapter();

	g_object_unref(app);

	return 0;
}
Ejemplo n.º 2
0
Archivo: gnac-ui.c Proyecto: GNOME/gnac
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 */
}
Ejemplo n.º 3
0
static gint
luaH_unique_is_running(lua_State *L)
{
    if (!application)
        luaL_error(L, "unique app not setup");

    lua_pushboolean(L, unique_app_is_running(application) ? TRUE : FALSE);
    return 1;
}
Ejemplo n.º 4
0
Archivo: main.c Proyecto: lcp/bisho
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;
}
Ejemplo n.º 5
0
static gint
luaH_unique_send_message(lua_State *L)
{
    if (!application)
        luaL_error(L, "unique app not setup");

    if (!unique_app_is_running(application))
        luaL_error(L, "no other instances running");

    const gchar *text = luaL_checkstring(L, 1);
    UniqueMessageData *data = unique_message_data_new();
    unique_message_data_set_text(data, text, -1);
    unique_app_send_message(application, 1, data);
    unique_message_data_free(data);
    return 0;
}
Ejemplo n.º 6
0
/**
 * main:
 **/
int
main (int argc, char *argv[])
{
	gboolean program_version = FALSE;
	GOptionContext *context;
	GtkWidget *main_window;
	GtkWidget *widget;
	PkControl *control;
	UniqueApp *unique_app;
	guint retval;
	guint xid = 0;
	GError *error = NULL;
	GMainLoop *loop;

	const GOptionEntry options[] = {
		{ "version", '\0', 0, G_OPTION_ARG_NONE, &program_version,
		  _("Show the program version and exit"), NULL },
		{ "parent-window", 'p', 0, G_OPTION_ARG_INT, &xid,
		  /* TRANSLATORS: we can make this modal (stay on top of) another window */
		  _("Set the parent window to make this modal"), NULL },
		{ NULL}
	};

	setlocale (LC_ALL, "");

	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);

	if (! g_thread_supported ())
		g_thread_init (NULL);
	dbus_g_thread_init ();
	g_type_init ();
	gtk_init (&argc, &argv);

	context = g_option_context_new (NULL);
	/* TRANSLATORS: program name, an application to set per-user policy for updates */
	g_option_context_set_summary(context, _("Software Update Preferences"));
	g_option_context_add_main_entries (context, options, NULL);
	g_option_context_add_group (context, egg_debug_get_option_group ());
	g_option_context_add_group (context, gtk_get_option_group (TRUE));
	g_option_context_parse (context, &argc, &argv, NULL);
	g_option_context_free (context);

	if (program_version) {
		g_print (VERSION "\n");
		return 0;
	}

	/* are we already activated? */
	unique_app = unique_app_new ("org.freedesktop.PackageKit.Prefs", NULL);
	if (unique_app_is_running (unique_app)) {
		egg_debug ("You have another instance running. This program will now close");
		unique_app_send_message (unique_app, UNIQUE_ACTIVATE, NULL);
		goto unique_out;
	}
	g_signal_connect (unique_app, "message-received",
			  G_CALLBACK (gpk_prefs_message_received_cb), NULL);

	/* get actions */
	loop = g_main_loop_new (NULL, FALSE);
	control = pk_control_new ();
	g_signal_connect (control, "notify::network-state",
			  G_CALLBACK (gpk_prefs_notify_network_state_cb), NULL);

	/* get UI */
	builder = gtk_builder_new ();
	retval = gtk_builder_add_from_file (builder, GPK_DATA "/gpk-prefs.ui", &error);
	if (retval == 0) {
		egg_warning ("failed to load ui: %s", error->message);
		g_error_free (error);
		goto out_build;
	}

	main_window = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_prefs"));

	/* Hide window first so that the dialogue resizes itself without redrawing */
	gtk_widget_hide (main_window);
	gtk_window_set_icon_name (GTK_WINDOW (main_window), GPK_ICON_SOFTWARE_UPDATE_PREFS);
	g_signal_connect (main_window, "delete_event",
			  G_CALLBACK (gpk_prefs_delete_event_cb), loop);

	widget = GTK_WIDGET (gtk_builder_get_object (builder, "checkbutton_mobile_broadband"));
	gpk_prefs_notify_checkbutton_setup (widget, GPK_CONF_CONNECTION_USE_MOBILE);

	widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_close"));
	g_signal_connect (widget, "clicked",
			  G_CALLBACK (gpk_prefs_close_cb), loop);
	widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_help"));
	g_signal_connect (widget, "clicked",
			  G_CALLBACK (gpk_prefs_help_cb), NULL);

	/* update the combo boxes */
	gpk_prefs_update_freq_combo_setup ();
	gpk_prefs_upgrade_freq_combo_setup ();
	gpk_prefs_auto_update_combo_setup ();

	gtk_widget_show (main_window);

	/* set the parent window if it is specified */
	if (xid != 0) {
		egg_debug ("Setting xid %i", xid);
		gpk_window_set_parent_xid (GTK_WINDOW (main_window), xid);
	}

	/* get some data */
	pk_control_get_properties_async (control, NULL, (GAsyncReadyCallback) gpk_prefs_get_properties_cb, loop);

	/* wait */
	g_main_loop_run (loop);

out_build:
	g_main_loop_unref (loop);
	g_object_unref (control);
	g_object_unref (builder);
unique_out:
	g_object_unref (unique_app);

	return 0;
}
Ejemplo n.º 7
0
int main(int argc, char * argv[], char * env[])
{
	setlocale(LC_ALL,"");
	gtk_set_locale();
	textdomain(GETTEXT_PACKAGE);

	GError * err = NULL;
	gchar * domain_dir=NULL;

	GOptionEntry args[] =
	{
			{"locale",'\0',0,G_OPTION_ARG_STRING,&domain_dir,_("set domain dir root"),N_("dir")},
			{0}
	};

	g_set_prgname(PACKAGE_NAME);

	if(G_UNLIKELY(!gtk_init_with_args(&argc, &argv,PACKAGE_STRING,args,PACKAGE_NAME,&err)))
	{
		g_error("%s",err->message);
	}

	if(domain_dir)
	{
		bindtextdomain(GETTEXT_PACKAGE,domain_dir);
		g_free(domain_dir);
	}

	g_set_application_name(_("gl2tp - GUI frontend for l2tp connection"));

	UniqueApp * unique = unique_app_new("net.vpn." PACKAGE_NAME,NULL);

	if (unique_app_is_running(unique))
	{
		g_message("already running!");

		if(UNIQUE_RESPONSE_OK != unique_app_send_message(unique,UNIQUE_ACTIVATE,NULL))
		{
			GtkWidget  * dlg = gtk_message_dialog_new(NULL,GTK_DIALOG_MODAL,GTK_MESSAGE_INFO,GTK_BUTTONS_CLOSE,
					_("Another one is running"));
			gtk_dialog_run(GTK_DIALOG(dlg));
		}else
		{
			g_message("active previous one");
		}
		return 1;
	}

	Gl2tpClient * l2client = gl2tpclient_new();

	if(!gl2tpclient_bind(l2client))
	{

		GtkWidget  * dlg = gtk_message_dialog_new(NULL,GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_CLOSE,
				_("unable to bind to local port 1701? Another one running?"));
		gtk_dialog_run(GTK_DIALOG(dlg));
		g_error(_("unable to bind to local port 1701? Another one running?"));
	}


	GdkPixbuf	* pixbuf = gdk_pixbuf_new_from_inline(-1,gl2tp_icon,FALSE,NULL);

	GtkWidget * main = gtk_window_new(GTK_WINDOW_TOPLEVEL);

	g_signal_connect(unique,"message-received",G_CALLBACK(active_instance),main);

	gtk_window_set_icon(GTK_WINDOW(main),pixbuf);

	GtkWidget * box = gtk_vbox_new(FALSE,TRUE);

	gtk_container_add(GTK_CONTAINER(main),box);

	g_signal_connect(G_OBJECT (main), "destroy", G_CALLBACK(gtk_main_quit), NULL);

	GtkWidget * gl2tp = gl2tp_new();

	gtk_box_pack_start(GTK_BOX(box),gl2tp,TRUE,TRUE,FALSE);

	status =  gtk_statusbar_new();

	guint id = gtk_statusbar_get_context_id(GTK_STATUSBAR(status),"status");

	gtk_box_pack_end(GTK_BOX(box),status,FALSE,TRUE,TRUE);

	gtk_statusbar_push(GTK_STATUSBAR(status),id,_("Ready"));

	g_signal_connect(gl2tp,"status-changed",G_CALLBACK(show_status),GUINT_TO_POINTER(id));
	g_signal_connect(gl2tp,"status-restore",G_CALLBACK(pop_status),GUINT_TO_POINTER(id));

	g_idle_add(gl2tp_load_config,gl2tp);

	gtk_widget_show_all(main);
	gtk_main();
	return 0;
}
/**
 * main:
 **/
int
main (int argc, char *argv[])
{
	gboolean program_version = FALSE;
	gboolean timed_exit = FALSE;
	GpkCheckUpdate *cupdate = NULL;
	GpkWatch *watch = NULL;
	GpkFirmware *firmware = NULL;
	GpkHardware *hardware = NULL;
	GOptionContext *context;
	UniqueApp *unique_app;
	gboolean ret;

	const GOptionEntry options[] = {
		{ "timed-exit", '\0', 0, G_OPTION_ARG_NONE, &timed_exit,
		  _("Exit after a small delay"), NULL },
		{ "version", '\0', 0, G_OPTION_ARG_NONE, &program_version,
		  _("Show the program version and exit"), NULL },
		{ NULL}
	};

	setlocale (LC_ALL, "");

	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);

	if (! g_thread_supported ())
		g_thread_init (NULL);
	g_type_init ();
	gtk_init (&argc, &argv);
	dbus_g_thread_init ();
	notify_init ("gpk-update-icon");

	/* TRANSLATORS: program name, a session wide daemon to watch for updates and changing system state */
	g_set_application_name (_("Update Applet"));
	context = g_option_context_new (NULL);
	g_option_context_set_summary (context, _("Update Applet"));
	g_option_context_add_main_entries (context, options, NULL);
	g_option_context_add_group (context, egg_debug_get_option_group ());
	g_option_context_add_group (context, gtk_get_option_group (TRUE));
	g_option_context_parse (context, &argc, &argv, NULL);
	g_option_context_free (context);

	if (program_version) {
		g_print (VERSION "\n");
		return 0;
	}

	/* TRANSLATORS: title to pass to to the user if there are not enough privs */
	ret = gpk_check_privileged_user (_("Update applet"), FALSE);
	if (!ret) {
		egg_warning ("Exit: gpk_check_privileged_user returned FALSE");
		return 1;
	}

	/* are we already activated? */
	unique_app = unique_app_new ("org.freedesktop.PackageKit.UpdateIcon", NULL);
	if (unique_app_is_running (unique_app)) {
		egg_debug ("You have another instance running. This program will now close");
		unique_app_send_message (unique_app, UNIQUE_ACTIVATE, NULL);
		goto unique_out;
	}

	/* add application specific icons to search path */
	gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
					   GPK_DATA G_DIR_SEPARATOR_S "icons");

	/* create new objects */
	cupdate = gpk_check_update_new ();
	watch = gpk_watch_new ();
	firmware = gpk_firmware_new ();
	hardware = gpk_hardware_new ();

	/* Only timeout if we have specified iton the command line */
	if (timed_exit)
		g_timeout_add_seconds (120, (GSourceFunc) gtk_main_quit, NULL);

	/* wait */
	gtk_main ();

	g_object_unref (cupdate);
	g_object_unref (watch);
	g_object_unref (firmware);
	g_object_unref (hardware);
unique_out:
	g_object_unref (unique_app);
	return 0;
}
Ejemplo n.º 9
0
int
main (int argc, char *argv[])
{
  TpAccountManager *account_manager;
  GError *error = NULL;
  UniqueApp *unique_app;

  GOptionContext *optcontext;
  GOptionEntry options[] = {
      { "hidden", 'h',
        0, G_OPTION_ARG_NONE, &hidden,
        N_("Don't display any dialogs; do any work (eg, importing) and exit"),
        NULL },
      { "if-needed", 'n',
        0, G_OPTION_ARG_NONE, &only_if_needed,
        N_("Don't display any dialogs if there are any non-salut accounts"),
        NULL },
      { "select-account", 's',
        G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &selected_account_name,
        N_("Initially select given account (eg, "
            "gabble/jabber/foo_40example_2eorg0)"),
        N_("<account-id>") },

      { NULL }
  };

  g_thread_init (NULL);
  empathy_init ();

  optcontext = g_option_context_new (N_("- Empathy Accounts"));
  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 (_("Empathy Accounts"));

  gtk_window_set_default_icon_name ("empathy");
  textdomain (GETTEXT_PACKAGE);

  unique_app = unique_app_new (EMPATHY_ACCOUNTS_DBUS_NAME, NULL);

  if (unique_app_is_running (unique_app))
    {
      unique_app_send_message (unique_app, UNIQUE_ACTIVATE, NULL);

      g_object_unref (unique_app);
      return EXIT_SUCCESS;
    }

  account_manager = tp_account_manager_dup ();

  tp_account_manager_prepare_async (account_manager, NULL,
    account_manager_ready_for_accounts_cb, selected_account_name);

  g_signal_connect (unique_app, "message-received",
      G_CALLBACK (unique_app_message_cb), NULL);

  gtk_main ();

  g_object_unref (account_manager);
  g_object_unref (unique_app);

  return EXIT_SUCCESS;
}
Ejemplo n.º 10
0
int
main (int argc, char *argv[])
{
    gboolean kill_shell;
    gboolean no_default_window;
    gboolean browser_window;
    gboolean no_desktop;
    gboolean version;
    gboolean autostart_mode;
    const char *autostart_id;
    gchar *geometry;
    gchar **remaining;
    gboolean perform_self_check;
    CajaApplication *application;
    GOptionContext *context;
    GFile *file = NULL;
    GFileInfo *fileinfo = NULL;
    GAppInfo *appinfo = NULL;
    char *uri = NULL;
    char **uris = NULL;
    GPtrArray *uris_array;
    GError *error;
    int i;

    const GOptionEntry options[] =
    {
#ifndef CAJA_OMIT_SELF_CHECK
        {
            "check", 'c', 0, G_OPTION_ARG_NONE, &perform_self_check,
            N_("Perform a quick set of self-check tests."), NULL
        },
#endif
        {
            "version", '\0', 0, G_OPTION_ARG_NONE, &version,
            N_("Show the version of the program."), NULL
        },
        {
            "geometry", 'g', 0, G_OPTION_ARG_STRING, &geometry,
            N_("Create the initial window with the given geometry."), N_("GEOMETRY")
        },
        {
            "no-default-window", 'n', 0, G_OPTION_ARG_NONE, &no_default_window,
            N_("Only create windows for explicitly specified URIs."), NULL
        },
        {
            "no-desktop", '\0', 0, G_OPTION_ARG_NONE, &no_desktop,
            N_("Do not manage the desktop (ignore the preference set in the preferences dialog)."), NULL
        },
        {
            "browser", '\0', 0, G_OPTION_ARG_NONE, &browser_window,
            N_("open a browser window."), NULL
        },
        {
            "quit", 'q', 0, G_OPTION_ARG_NONE, &kill_shell,
            N_("Quit Caja."), NULL
        },
        { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &remaining, NULL,  N_("[URI...]") },

        { NULL }
    };

#if defined (HAVE_MALLOPT) && defined(M_MMAP_THRESHOLD)
    /* Caja uses lots and lots of small and medium size allocations,
     * and then a few large ones for the desktop background. By default
     * glibc uses a dynamic treshold for how large allocations should
     * be mmaped. Unfortunately this triggers quickly for caja when
     * it does the desktop background allocations, raising the limit
     * such that a lot of temporary large allocations end up on the
     * heap and are thus not returned to the OS. To fix this we set
     * a hardcoded limit. I don't know what a good value is, but 128K
     * was the old glibc static limit, lets use that.
     */
    mallopt (M_MMAP_THRESHOLD, 128 *1024);
#endif

    g_thread_init (NULL);

    /* This will be done by gtk+ later, but for now, force it to MATE */
    g_desktop_app_info_set_desktop_env ("MATE");

    if (g_getenv ("CAJA_DEBUG") != NULL)
    {
        eel_make_warnings_and_criticals_stop_in_debugger ();
    }

    /* Initialize gettext support */
    bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
    textdomain (GETTEXT_PACKAGE);

    autostart_mode = FALSE;

    autostart_id = g_getenv ("DESKTOP_AUTOSTART_ID");
    if (autostart_id != NULL && *autostart_id != '\0')
    {
        autostart_mode = TRUE;
    }

    /* Get parameters. */
    remaining = NULL;
    geometry = NULL;
    version = FALSE;
    kill_shell = FALSE;
    no_default_window = FALSE;
    no_desktop = FALSE;
    perform_self_check = FALSE;
    browser_window = FALSE;

    g_set_prgname ("caja");

    if (g_file_test (DATADIR "/applications/caja.desktop", G_FILE_TEST_EXISTS))
    {
        egg_set_desktop_file (DATADIR "/applications/caja.desktop");
    }

    context = g_option_context_new (_("\n\nBrowse the file system with the file manager"));
    g_option_context_add_main_entries (context, options, NULL);

    g_option_context_add_group (context, gtk_get_option_group (TRUE));
    g_option_context_add_group (context, egg_sm_client_get_option_group ());

    error = NULL;
    if (!g_option_context_parse (context, &argc, &argv, &error))
    {
        g_printerr ("Could not parse arguments: %s\n", error->message);
        g_error_free (error);
        return 1;
    }

    g_option_context_free (context);

    if (version)
    {
        g_print ("MATE caja " PACKAGE_VERSION "\n");
        return 0;
    }

#ifdef HAVE_EXEMPI
    xmp_init();
#endif

    setup_debug_log ();

    /* If in autostart mode (aka started by mate-session), we need to ensure
         * caja starts with the correct options.
         */
    if (autostart_mode)
    {
        no_default_window = TRUE;
        no_desktop = FALSE;
    }

    if (perform_self_check && remaining != NULL)
    {
        /* translators: %s is an option (e.g. --check) */
        fprintf (stderr, _("caja: %s cannot be used with URIs.\n"),
                 "--check");
        return EXIT_FAILURE;
    }
    if (perform_self_check && kill_shell)
    {
        fprintf (stderr, _("caja: --check cannot be used with other options.\n"));
        return EXIT_FAILURE;
    }
    if (kill_shell && remaining != NULL)
    {
        fprintf (stderr, _("caja: %s cannot be used with URIs.\n"),
                 "--quit");
        return EXIT_FAILURE;
    }
    if (geometry != NULL && remaining != NULL && remaining[0] != NULL && remaining[1] != NULL)
    {
        fprintf (stderr, _("caja: --geometry cannot be used with more than one URI.\n"));
        return EXIT_FAILURE;
    }

    /* Initialize the services that we use. */
    LIBXML_TEST_VERSION

    /* Initialize preferences. This is needed so that proper
     * defaults are available before any preference peeking
     * happens.
     */
    caja_global_preferences_init ();

    /* exit_with_last_window being FALSE, caja can run without window. */
    exit_with_last_window = g_settings_get_boolean (caja_preferences, CAJA_PREFERENCES_EXIT_WITH_LAST_WINDOW);

    application = NULL;

    /* Do either the self-check or the real work. */
    if (perform_self_check)
    {
		#ifndef CAJA_OMIT_SELF_CHECK
			/* Run the checks (each twice) for caja and libcaja-private. */

			caja_run_self_checks ();
			caja_run_lib_self_checks ();
			eel_exit_if_self_checks_failed ();

			caja_run_self_checks ();
			caja_run_lib_self_checks ();
			eel_exit_if_self_checks_failed ();
		#endif
    }
    else
    {
        /* Convert args to URIs */
        if (remaining != NULL)
        {
            uris_array = g_ptr_array_new ();
            for (i = 0; remaining[i] != NULL; i++)
            {
                file = g_file_new_for_commandline_arg (remaining[i]);
                if (file != NULL)
                {
                    uri = g_file_get_uri (file);
                    if (uri)
                    {
                        fileinfo = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL);
                        if (fileinfo && g_file_info_get_file_type(fileinfo) == G_FILE_TYPE_DIRECTORY)
                        {
                            g_ptr_array_add (uris_array, uri);
                        }
                        else
                        {
                            if (fileinfo)
                                g_object_unref (fileinfo);
                            fileinfo = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL);
                            if (fileinfo)
                            {
                                appinfo = g_app_info_get_default_for_type (g_file_info_get_content_type (fileinfo), TRUE);
                                if (appinfo)
                                {
                                    if (g_strcmp0 (g_app_info_get_executable (appinfo), "caja") != 0)
                                    {
                                        g_app_info_launch_default_for_uri (uri, NULL, NULL);
                                    }
                                    else
                                    {
                                        fprintf (stderr, _("caja: set erroneously as default application for '%s' content type.\n"),
                                                 g_file_info_get_content_type (fileinfo));
                                    }
                                    g_object_unref (appinfo);
                                }
                                g_free (uri);
                            }
                            else
                            {
                                g_ptr_array_add (uris_array, uri);
                            }
                        }
                        if (fileinfo)
                            g_object_unref (fileinfo);
                    }
                    if (file)
                        g_object_unref (file);
                }
            }
            if (uris_array->len == 0)
            {
                /* Caja is being used only to open files (not directories), so closing */
                g_strfreev (remaining);
                return EXIT_SUCCESS;
            }
            g_ptr_array_add (uris_array, NULL);
            uris = (char**) g_ptr_array_free (uris_array, FALSE);
            g_strfreev (remaining);
        }


        /* Run the caja application. */
        application = caja_application_new ();

        if (egg_sm_client_is_resumed (application->smclient))
        {
            no_default_window = TRUE;
        }

        caja_application_startup
        (application,
         kill_shell, no_default_window, no_desktop,
         browser_window,
         geometry,
         uris);
        g_strfreev (uris);

        if (unique_app_is_running (application->unique_app) ||
                kill_shell)
        {
            exit_with_last_window = TRUE;
        }

        if (is_event_loop_needed ())
        {
            gtk_main ();
        }
    }

    caja_icon_info_clear_caches ();

    if (application != NULL)
    {
        g_object_unref (application);
    }

    eel_debug_shut_down ();

    caja_application_save_accel_map (NULL);

    return EXIT_SUCCESS;
}
Ejemplo n.º 11
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;
}
Ejemplo n.º 12
0
int main(int argc, char* argv[])
{
	gboolean hidden = FALSE;
	UniqueApp* unique_app;
	AppShellData* app_data;
	GSList* actions;
	GError* error;
	GOptionEntry options[] = {
		{"hide", 0, 0, G_OPTION_ARG_NONE, &hidden, N_("Hide on start (useful to preload the shell)"), NULL},
		{NULL}
	};

	#ifdef ENABLE_NLS
		bindtextdomain(GETTEXT_PACKAGE, MATELOCALEDIR);
		bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
		textdomain(GETTEXT_PACKAGE);
	#endif

	error = NULL;

	if (!gtk_init_with_args(&argc, &argv, NULL, options, GETTEXT_PACKAGE, &error))
	{
		g_printerr("%s\n", error->message);
		g_error_free(error);
		return 1;
	}

	unique_app = unique_app_new("org.mate.mate-control-center.shell", NULL);

	if (unique_app_is_running(unique_app))
	{
		int retval = 0;

		if (!hidden)
		{
			UniqueResponse response;
			response = unique_app_send_message(unique_app, UNIQUE_ACTIVATE, NULL);
			retval = (response != UNIQUE_RESPONSE_OK);
		}

		g_object_unref(unique_app);
		return retval;
	}

	app_data = appshelldata_new("matecc.menu", GTK_ICON_SIZE_DND, FALSE, TRUE, 0);
	generate_categories(app_data);

	actions = get_actions_list();
	layout_shell(app_data, _("Filter"), _("Groups"), _("Common Tasks"), actions, handle_static_action_clicked);

	create_main_window(app_data, "MyControlCenter", _("Control Center"), "preferences-desktop", 975, 600, hidden);

	unique_app_watch_window(unique_app, GTK_WINDOW(app_data->main_app));
	g_signal_connect(unique_app, "message-received", G_CALLBACK(message_received_cb), app_data);

	gtk_main();

	g_object_unref(unique_app);

	return 0;
}
/**
 * main:
 **/
int
main (int argc, char *argv[])
{
	gboolean program_version = FALSE;
	GpkUpdateViewer *update_viewer = NULL;
	GOptionContext *context;
	UniqueApp *unique_app;
	gboolean ret;

	const GOptionEntry options[] = {
		{ "version", '\0', 0, G_OPTION_ARG_NONE, &program_version,
		  /* TRANSLATORS: show the program version */
		  _("Show the program version and exit"), NULL },
		{ NULL}
	};

	setlocale (LC_ALL, "");

	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);

	if (! g_thread_supported ())
		g_thread_init (NULL);
	dbus_g_thread_init ();
	g_type_init ();
	gtk_init (&argc, &argv);

	context = g_option_context_new (NULL);
	g_option_context_set_summary (context, _("Add/Remove Software"));
	g_option_context_add_main_entries (context, options, NULL);
	g_option_context_add_group (context, egg_debug_get_option_group ());
	g_option_context_add_group (context, gtk_get_option_group (TRUE));
	g_option_context_parse (context, &argc, &argv, NULL);
	g_option_context_free (context);

	if (program_version) {
		g_print (VERSION "\n");
		return 0;
	}

	/* add application specific icons to search path */
	gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
					   GPK_DATA G_DIR_SEPARATOR_S "icons");

	/* TRANSLATORS: title to pass to to the user if there are not enough privs */
	ret = gpk_check_privileged_user (_("Software Update Viewer"), TRUE);
	if (!ret)
		return 1;

	/* are we already activated? */
	unique_app = unique_app_new ("org.freedesktop.PackageKit.UpdateViewer", NULL);
	if (unique_app_is_running (unique_app)) {
		egg_debug ("You have another instance running. This program will now close");
		unique_app_send_message (unique_app, UNIQUE_ACTIVATE, NULL);
		goto unique_out;
	}

	/* create a new update_viewer object */
	update_viewer = gpk_update_viewer_new ();
	g_signal_connect (unique_app, "message-received",
			  G_CALLBACK (gpk_update_viewer_message_received_cb), update_viewer);
	g_signal_connect (update_viewer, "action-close",
			  G_CALLBACK (gpk_update_viewer_close_cb), NULL);

	/* wait */
	gtk_main ();

	g_object_unref (update_viewer);
unique_out:
	g_object_unref (unique_app);
	return 0;
}
Ejemplo n.º 14
0
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( &gtkabber, '\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( &gtkabber, unique_app );
	for(; i < argc; ++i)
	{
		if (strcmp( argv[i], "next-socket" ) == 0)
			setup_new_socket_for_plug( &gtkabber );
	}
	gtk_main();
	g_object_unref(unique_app);

	return EXIT_SUCCESS;
}
Ejemplo n.º 15
0
int main(int argc, char *argv[])
{
	UniqueApp *app;
	GtkStatusIcon *statusicon;
	GtkWidget *menu;
	GOptionContext *context;
	GError *error = NULL;

	bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
	textdomain(GETTEXT_PACKAGE);

#if !GLIB_CHECK_VERSION (2, 36, 0)
	g_type_init ();
#endif

	/* Parse command-line options */
	context = g_option_context_new (N_("- Bluetooth applet"));
	g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
	g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);
	g_option_context_add_group (context, gtk_get_option_group (TRUE));
	if (g_option_context_parse (context, &argc, &argv, &error) == FALSE) {
		g_print (_("%s\nRun '%s --help' to see a full list of available command line options.\n"),
			 error->message, argv[0]);
		g_error_free (error);
		return 1;
	}

	if (option_debug == FALSE) {
		app = unique_app_new ("org.mate.Bluetooth.applet", NULL);
		if (unique_app_is_running (app)) {
			gdk_notify_startup_complete ();
			g_warning ("Applet is already running, exiting");
			return 0;
		}
	} else {
		app = NULL;
	}

	g_set_application_name(_("Bluetooth Applet"));

	gtk_window_set_default_icon_name("bluetooth");

	killswitch = bluetooth_killswitch_new ();
	g_signal_connect (G_OBJECT (killswitch), "state-changed",
			  G_CALLBACK (killswitch_state_changed), NULL);

	menu = create_popupmenu();

	client = bluetooth_client_new();

	devices_model = bluetooth_client_get_model(client);

	g_signal_connect(G_OBJECT(devices_model), "row-inserted",
			 G_CALLBACK(device_added), NULL);
	g_signal_connect(G_OBJECT(devices_model), "row-deleted",
			 G_CALLBACK(device_removed), NULL);
	g_signal_connect (G_OBJECT (devices_model), "row-changed",
			  G_CALLBACK (device_changed), NULL);

	/* Set the default adapter */
	device_changed (devices_model, NULL, NULL, NULL);
	if (bluetooth_killswitch_has_killswitches (killswitch) != FALSE) {
		killswitch_state_changed (killswitch,
					  bluetooth_killswitch_get_state (killswitch));
	}

	/* Make sure all the unblocked adapters are powered,
	 * so as to avoid seeing unpowered, but unblocked
	 * devices */
	bluetooth_set_adapter_powered ();

	settings = g_settings_new (SCHEMA_NAME);
	show_icon_pref = g_settings_get_boolean (settings, PREF_SHOW_ICON);

	g_signal_connect (G_OBJECT (settings), "changed::" PREF_SHOW_ICON,
			  G_CALLBACK (show_icon_changed), NULL);

	statusicon = init_notification();

	update_icon_visibility();

	g_signal_connect(statusicon, "activate",
				G_CALLBACK(activate_callback), menu);
	g_signal_connect(statusicon, "popup-menu",
				G_CALLBACK(popup_callback), menu);

	setup_agents();

	gtk_main();

	gtk_widget_destroy(menu);

	g_object_unref(settings);

	cleanup_agents();

	cleanup_notification();

	g_object_unref(devices_model);

	g_object_unref(client);

	if (app != NULL)
		g_object_unref (app);

	return 0;
}
Ejemplo n.º 16
0
/**
 * main:
 **/
int
main (int argc, char *argv[])
{
	GOptionContext *context;
	guint retval = 0;
	GError *error = NULL;
	GMainLoop *loop;
	GtkWidget *main_window;
	GtkWidget *widget;
	UniqueApp *unique_app;
	guint xid = 0;
	McmColorimeter *colorimeter = NULL;

	const GOptionEntry options[] = {
		{ "parent-window", 'p', 0, G_OPTION_ARG_INT, &xid,
		  /* TRANSLATORS: we can make this modal (stay on top of) another window */
		  _("Set the parent window to make this modal"), NULL },
		{ NULL}
	};

	/* setup translations */
	setlocale (LC_ALL, "");
	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);

	/* setup LCMS */
	cmsSetLogErrorHandler (mcm_picker_error_cb);

	context = g_option_context_new (NULL);
	/* TRANSLATORS: tool that is used to pick colors */
	g_option_context_set_summary (context, _("MATE Color Manager Color Picker"));
	g_option_context_add_group (context, egg_debug_get_option_group ());
	g_option_context_add_group (context, gtk_get_option_group (TRUE));
	g_option_context_add_main_entries (context, options, NULL);
	g_option_context_parse (context, &argc, &argv, NULL);
	g_option_context_free (context);

	/* block in a loop */
	loop = g_main_loop_new (NULL, FALSE);


	/* are we already activated? */
	unique_app = unique_app_new ("org.mate.ColorManager.Picker", NULL);
	if (unique_app_is_running (unique_app)) {
		egg_debug ("You have another instance running. This program will now close");
		unique_app_send_message (unique_app, UNIQUE_ACTIVATE, NULL);
		goto out;
	}
	g_signal_connect (unique_app, "message-received",
			  G_CALLBACK (mcm_picker_message_received_cb), NULL);

	/* get UI */
	builder = gtk_builder_new ();
	retval = gtk_builder_add_from_file (builder, MCM_DATA "/mcm-picker.ui", &error);
	if (retval == 0) {
		egg_warning ("failed to load ui: %s", error->message);
		g_error_free (error);
		goto out;
	}

	main_window = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_picker"));
	gtk_window_set_icon_name (GTK_WINDOW (main_window), MCM_STOCK_ICON);
	g_signal_connect (main_window, "delete_event",
			  G_CALLBACK (mcm_picker_delete_event_cb), loop);

	widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_close"));
	g_signal_connect (widget, "clicked",
			  G_CALLBACK (mcm_picker_close_cb), loop);

	widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_help"));
	g_signal_connect (widget, "clicked",
			  G_CALLBACK (mcm_picker_help_cb), NULL);

	widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_measure"));
	g_signal_connect (widget, "clicked",
			  G_CALLBACK (mcm_picker_measure_cb), NULL);

	widget = GTK_WIDGET (gtk_builder_get_object (builder, "image_preview"));
	gtk_widget_set_size_request (widget, 200, 200);

	/* add application specific icons to search path */
	gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
	                                   MCM_DATA G_DIR_SEPARATOR_S "icons");

	/* use the color device */
	colorimeter = mcm_colorimeter_new ();
	g_signal_connect (colorimeter, "changed", G_CALLBACK (mcm_picker_colorimeter_changed_cb), NULL);

	/* set the parent window if it is specified */
	if (xid != 0) {
		egg_debug ("Setting xid %i", xid);
		mcm_window_set_parent_xid (GTK_WINDOW (main_window), xid);
	}


	/* use argyll */
	calibrate = MCM_CALIBRATE (mcm_calibrate_argyll_new ());
	g_signal_connect (calibrate, "notify::xyz",
			G_CALLBACK (mcm_picker_xyz_notify_cb), NULL);

	/* use an info bar if there is no device, or the wrong device */
	info_bar_hardware = gtk_info_bar_new ();
	info_bar_hardware_label = gtk_label_new (NULL);
	gtk_info_bar_set_message_type (GTK_INFO_BAR(info_bar_hardware), GTK_MESSAGE_INFO);
	widget = gtk_info_bar_get_content_area (GTK_INFO_BAR(info_bar_hardware));
	gtk_container_add (GTK_CONTAINER(widget), info_bar_hardware_label);
	gtk_widget_show (info_bar_hardware_label);

	/* add infobar to devices pane */
	widget = GTK_WIDGET (gtk_builder_get_object (builder, "vbox1"));
	gtk_box_pack_start (GTK_BOX(widget), info_bar_hardware, FALSE, FALSE, 0);

	/* disable some ui if no hardware */
	mcm_picker_colorimeter_setup_ui (colorimeter);

	/* maintain a list of profiles */
	profile_store = mcm_profile_store_new ();

	/* default to AdobeRGB */
	profile_filename = "/usr/share/color/icc/Argyll/ClayRGB1998.icm";

	/* setup RGB combobox */
	widget = GTK_WIDGET (gtk_builder_get_object (builder, "combobox_colorspace"));
	mcm_prefs_set_combo_simple_text (widget);
	mcm_prefs_setup_space_combobox (widget);
	g_signal_connect (G_OBJECT (widget), "changed",
			  G_CALLBACK (mcm_prefs_space_combo_changed_cb), NULL);

	/* setup results expander */
	mcm_picker_refresh_results ();

	/* setup initial preview window */
	widget = GTK_WIDGET (gtk_builder_get_object (builder, "image_preview"));
	gtk_image_set_from_file (GTK_IMAGE (widget), DATADIR "/icons/hicolor/64x64/apps/mate-color-manager.png");

	/* wait */
	gtk_widget_show (main_window);
	g_main_loop_run (loop);

out:
	g_object_unref (unique_app);
	if (profile_store != NULL)
		g_object_unref (profile_store);
	if (colorimeter != NULL)
		g_object_unref (colorimeter);
	if (calibrate != NULL)
		g_object_unref (calibrate);
	if (builder != NULL)
		g_object_unref (builder);
	g_main_loop_unref (loop);
	return retval;
}
Ejemplo n.º 17
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() );
}
Ejemplo n.º 18
0
/**
 * main:
 **/
int
main (int argc, char *argv[])
{
	GOptionContext *context;
	GConfClient *gconf_client;
	GtkWidget *widget;
	GtkTreeSelection *selection;
	GtkEntryCompletion *completion;
	UniqueApp *unique_app;
	gboolean ret;
	guint retval;
	guint xid = 0;
	GError *error = NULL;

	const GOptionEntry options[] = {
		{ "filter", 'f', 0, G_OPTION_ARG_STRING, &filter,
		  /* TRANSLATORS: preset the GtktextBox with this filter text */
		  N_("Set the filter to this value"), NULL },
		{ "parent-window", 'p', 0, G_OPTION_ARG_INT, &xid,
		  /* TRANSLATORS: we can make this modal (stay on top of) another window */
		  _("Set the parent window to make this modal"), NULL },
		{ NULL}
	};

	setlocale (LC_ALL, "");

	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);

	if (! g_thread_supported ())
		g_thread_init (NULL);
	g_type_init ();
	gtk_init (&argc, &argv);

	context = g_option_context_new (NULL);
	g_option_context_set_summary (context, _("Software Log Viewer"));
	g_option_context_add_main_entries (context, options, NULL);
	g_option_context_add_group (context, egg_debug_get_option_group ());
	g_option_context_add_group (context, gtk_get_option_group (TRUE));
	g_option_context_parse (context, &argc, &argv, NULL);
	g_option_context_free (context);

	/* are we running privileged */
	ret = gpk_check_privileged_user (_("Log viewer"), TRUE);
	if (!ret)
		return 1;

	/* are we already activated? */
	unique_app = unique_app_new ("org.freedesktop.PackageKit.LogViewer", NULL);
	if (unique_app_is_running (unique_app)) {
		egg_debug ("You have another instance running. This program will now close");
		unique_app_send_message (unique_app, UNIQUE_ACTIVATE, NULL);
		goto unique_out;
	}
	g_signal_connect (unique_app, "message-received",
			  G_CALLBACK (gpk_log_message_received_cb), NULL);

	/* add application specific icons to search path */
	gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
					   GPK_DATA G_DIR_SEPARATOR_S "icons");

	client = pk_client_new ();
	g_object_set (client,
		      "background", FALSE,
		      NULL);

	/* get UI */
	builder = gtk_builder_new ();
	retval = gtk_builder_add_from_file (builder, GPK_DATA "/gpk-log.ui", &error);
	if (retval == 0) {
		egg_warning ("failed to load ui: %s", error->message);
		g_error_free (error);
		goto out_build;
	}

	widget = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_simple"));
	gtk_window_set_icon_name (GTK_WINDOW (widget), GPK_ICON_SOFTWARE_LOG);

	/* set a size, if the screen allows */
	gpk_window_set_size_request (GTK_WINDOW (widget), 900, 300);

	/* if command line arguments are set, then setup UI */
	if (filter != NULL) {
		widget = GTK_WIDGET (gtk_builder_get_object (builder, "entry_package"));
		gtk_entry_set_text (GTK_ENTRY(widget), filter);
	}

	/* Get the main window quit */
	g_signal_connect_swapped (widget, "delete_event", G_CALLBACK (gtk_main_quit), NULL);

	widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_close"));
	g_signal_connect_swapped (widget, "clicked", G_CALLBACK (gtk_main_quit), NULL);
	gtk_widget_grab_default (widget);

	widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_help"));
	g_signal_connect (widget, "clicked", G_CALLBACK (gpk_log_button_help_cb), NULL);
	widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_refresh"));
	g_signal_connect (widget, "clicked", G_CALLBACK (gpk_log_button_refresh_cb), NULL);
	gtk_widget_hide (widget);
	widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_filter"));
	g_signal_connect (widget, "clicked", G_CALLBACK (gpk_log_button_filter_cb), NULL);

	/* hit enter in the search box for filter */
	widget = GTK_WIDGET (gtk_builder_get_object (builder, "entry_package"));
	g_signal_connect (widget, "activate", G_CALLBACK (gpk_log_button_filter_cb), NULL);

	/* autocompletion can be turned off as it's slow */
	gconf_client = gconf_client_get_default ();
	ret = gconf_client_get_bool (gconf_client, GPK_CONF_AUTOCOMPLETE, NULL);
	if (ret) {
		/* create the completion object */
		completion = gpk_package_entry_completion_new ();
		widget = GTK_WIDGET (gtk_builder_get_object (builder, "entry_package"));
		gtk_entry_set_completion (GTK_ENTRY (widget), completion);
		g_object_unref (completion);
	} else {
		/* use search as you type */
		g_signal_connect (widget, "key-release-event", G_CALLBACK (gpk_log_entry_filter_cb), NULL);
	}
	g_object_unref (gconf_client);

	/* create list stores */
	list_store = gtk_list_store_new (GPK_LOG_COLUMN_LAST, G_TYPE_STRING, G_TYPE_STRING,
					 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
					 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN);

	/* create transaction_id tree view */
	widget = GTK_WIDGET (gtk_builder_get_object (builder, "treeview_simple"));
	gtk_tree_view_set_model (GTK_TREE_VIEW (widget),
				 GTK_TREE_MODEL (list_store));

	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
	g_signal_connect (selection, "changed",
			  G_CALLBACK (gpk_log_treeview_clicked_cb), NULL);

	/* add columns to the tree view */
	pk_treeview_add_general_columns (GTK_TREE_VIEW (widget));
	gtk_tree_view_columns_autosize (GTK_TREE_VIEW (widget));

	gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (list_store),
					      GPK_LOG_COLUMN_TIMESPEC, GTK_SORT_DESCENDING);

	/* show */
	widget = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_simple"));
	gtk_widget_show (widget);

	/* set the parent window if it is specified */
	if (xid != 0) {
		egg_debug ("Setting xid %i", xid);
		gpk_window_set_parent_xid (GTK_WINDOW (widget), xid);
	}

	/* get the update list */
	gpk_log_refresh ();

	gtk_main ();

out_build:
	g_object_unref (builder);
	g_object_unref (list_store);
	g_object_unref (client);
	g_free (transaction_id);
	g_free (filter);
	if (transactions != NULL)
		g_ptr_array_unref (transactions);
unique_out:
	g_object_unref (unique_app);
	return 0;
}
Ejemplo n.º 19
0
	int main(int argc, char** argv)
	{
		int status = 0;

		mate_gettext(GETTEXT_PACKAGE, LOCALE_DIR, "UTF-8");

		#if !GLIB_CHECK_VERSION (2, 36, 0)
		g_type_init();
		#endif

		/* http://www.gtk.org/api/2.6/glib/glib-Commandline-option-parser.html */
		GOptionContext* context = g_option_context_new(NULL);
		g_option_context_add_main_entries(context, command_entries, GETTEXT_PACKAGE);
		g_option_context_add_group(context, gtk_get_option_group(TRUE));
		g_option_context_parse(context, &argc, &argv, NULL);

		/* Not necesary at all, program just run and die.
		 * But it free a little memory. */
		g_option_context_free(context);

		if (mate_about_nogui == TRUE)
		{
			printf("%s %s\n", gettext(program_name), version);
		}
		else
		{
			gtk_init(&argc, &argv);

			/**
			 * Examples taken from:
			 * http://developer.gnome.org/gtk3/3.0/gtk-migrating-GtkApplication.html
			 */
			#ifdef USE_UNIQUE

				mate_about_application = unique_app_new("org.mate.about", NULL);

				if (unique_app_is_running(mate_about_application))
				{
					UniqueResponse response = unique_app_send_message(mate_about_application, UNIQUE_ACTIVATE, NULL);

					if (response != UNIQUE_RESPONSE_OK)
					{
						status = 1;
					}
				}
				else
				{
					mate_about_run();
				}

			#elif GTK_CHECK_VERSION(3, 0, 0) && !defined(USE_UNIQUE)

				mate_about_application = gtk_application_new("org.mate.about", 0);
				g_signal_connect(mate_about_application, "activate", G_CALLBACK(mate_about_on_activate), NULL);

				status = g_application_run(G_APPLICATION(mate_about_application), argc, argv);

				g_object_unref(mate_about_application);

			#elif GLIB_CHECK_VERSION(2, 26, 0) && !defined(USE_UNIQUE)

				mate_about_application = g_application_new("org.mate.about", G_APPLICATION_FLAGS_NONE);
				g_signal_connect(mate_about_application, "activate", G_CALLBACK(mate_about_on_activate), NULL);

				status = g_application_run(G_APPLICATION(mate_about_application), argc, argv);

				g_object_unref(mate_about_application);

			#else

				mate_about_run();

			#endif
		}

		return status;
	}
Ejemplo n.º 20
0
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;
}
Ejemplo n.º 21
0
int start( int argc, char **argv )
{
  char file[PATH_MAX];
  char *f = NULL;
  char line[7];
  int lineToOpen = 0;

  memset(file,'\0',PATH_MAX);
  memset(line,'\0',7);

  gtk_init( &argc, &argv );

  //printf("arguments::\n");

  for( int i = 0; i < argc; i++ )
  {
    //printf(" argument %d is %s\n",i,argv[i]);fflush(stdout);
    if( i == 1 )
    {
      strncpy(file,argv[i],PATH_MAX);
      f = fileFullPath(file);
    }
    else if( i == 2 )
    {
      strncpy(line,argv[i],6);
      lineToOpen = atoi(line);
      if( lineToOpen < 0 ) lineToOpen = 0;
    }
  }

  g_app = unique_app_new(EDITOR,NULL);

  if( unique_app_is_running (g_app) )
  {
    char* fl = NULL;
    int len = 0;
    UniqueCommand cmd = UNIQUE_NEW;
    UniqueMessageData* msg = unique_message_data_new();

    if( f ) len += strlen(f);
    if( lineToOpen ) len += strlen(line) + 1;
    fl = (char*)malloc(len+1);
    
    if( f )
    {
      strcpy(fl,f);
      free(f);
      
      if( lineToOpen )
      {
        strcat(fl,"@");
        strcat(fl,line);
      }
    }

    if( len > 1 && fl )
    {      
      cmd = UNIQUE_OPEN;
      unique_message_data_set_text(msg,fl,len);
      free(fl);
    }
    
    unique_app_send_message(g_app,cmd,msg);
    unique_message_data_free(msg);
  }
  else
  {
    if(f) free(f);
    //g_appWin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    //unique_app_watch_window (app, GTK_WINDOW(g_appWin));
    g_signal_connect(g_app,"message-received",G_CALLBACK(message_received_cb),NULL);

    MyEditorHandlerLin* meh = (MyEditorHandlerLin*)MyEditorHandlerLin::getInstance();
    meh->createEditor(file,lineToOpen);

    gtk_main();

    //gtk_widget_destroy(g_appWin);
  }

  g_object_unref (g_app);

  return 0;
}