예제 #1
0
static gint
gedit_app_handle_local_options (GApplication *application,
                                GVariantDict *options)
{
	if (g_variant_dict_contains (options, "version"))
	{
		g_print ("%s - Version %s\n", g_get_application_name (), VERSION);
		return 0;
	}

	if (g_variant_dict_contains (options, "list-encodings"))
	{
		print_all_encodings ();
		return 0;
	}

	if (g_variant_dict_contains (options, "standalone"))
	{
		GApplicationFlags old_flags;

		old_flags = g_application_get_flags (application);
		g_application_set_flags (application, old_flags | G_APPLICATION_NON_UNIQUE);
	}

	if (g_variant_dict_contains (options, "wait"))
	{
		GApplicationFlags old_flags;

		old_flags = g_application_get_flags (application);
		g_application_set_flags (application, old_flags | G_APPLICATION_IS_LAUNCHER);
	}

	return -1;
}
static void
gbp_greeter_application_addin_handle_command_line (IdeApplicationAddin     *addin,
                                                   IdeApplication          *application,
                                                   GApplicationCommandLine *cmdline)
{
  GbpGreeterApplicationAddin *self = (GbpGreeterApplicationAddin *)addin;
  g_auto(GStrv) argv = NULL;
  GVariantDict *dict;
  const gchar *clone_uri = NULL;
  gint argc;

  g_assert (GBP_IS_GREETER_APPLICATION_ADDIN (self));
  g_assert (IDE_IS_APPLICATION (application));
  g_assert (G_IS_APPLICATION_COMMAND_LINE (cmdline));

  dict = g_application_command_line_get_options_dict (cmdline);
  argv = ide_application_get_argv (IDE_APPLICATION (application), cmdline);
  argc = g_strv_length (argv);

  /*
   * If we are processing the arguments for the startup of the primary
   * instance, then we want to show the greeter if no arguments are
   * provided. (That means argc == 1, the programe executable).
   *
   * Also, if they provided --greeter or -g we'll show a new greeter.
   */
  if ((!g_application_command_line_get_is_remote (cmdline) && argc == 1) ||
      g_variant_dict_contains (dict, "greeter"))
    {
      present_greeter_with_surface (NULL, NULL, addin);
      return;
    }

  /*
   * If the --clone=URI option was provided, switch the greeter to the
   * clone surface and begin cloning.
   */
  if (dict != NULL && g_variant_dict_lookup (dict, "clone", "&s", &clone_uri))
    {
      IdeGreeterWorkspace *workspace;
      IdeWorkbench *workbench;
      IdeSurface *surface;

      workbench = ide_workbench_new ();
      ide_application_add_workbench (self->application, workbench);

      workspace = ide_greeter_workspace_new (self->application);
      ide_workbench_add_workspace (workbench, IDE_WORKSPACE (workspace));

      surface = ide_workspace_get_surface_by_name (IDE_WORKSPACE (workspace), "clone");
      ide_workspace_set_visible_surface (IDE_WORKSPACE (workspace), surface);

      if (IDE_IS_CLONE_SURFACE (surface))
        ide_clone_surface_set_uri (IDE_CLONE_SURFACE (surface), clone_uri);

      ide_workbench_focus_workspace (workbench, IDE_WORKSPACE (workspace));
    }
}
예제 #3
0
파일: setting.c 프로젝트: tschaefer/loom
static void
parse_configuration (Setting *setting)
{
  GVariantDict *dict = NULL;
  GVariant *value = NULL;
  LoomSetting *loom_setting = LOOM_SETTING (setting);

  dict = g_variant_dict_new (setting->configuration);
  value = g_variant_dict_lookup_value (dict, "address", G_VARIANT_TYPE_STRING);
  loom_setting_set_address (loom_setting, g_variant_get_string (value, NULL));

  if (g_variant_dict_contains (dict, "router"))
    {
      value = g_variant_dict_lookup_value (dict, "router",
                                           G_VARIANT_TYPE_STRING);
      loom_setting_set_router (loom_setting, g_variant_get_string (value, NULL));
    }

  if (g_variant_dict_contains (dict, "nameservers"))
    {
      value = g_variant_dict_lookup_value (dict, "nameservers",
                                           G_VARIANT_TYPE_STRING_ARRAY);
      gchar **strv = g_variant_dup_strv (value, NULL);
      loom_setting_set_name_servers (loom_setting, (const gchar **)strv);
      g_strfreev (strv);
    }

  if (g_variant_dict_contains (dict, "domain"))
    {
      value = g_variant_dict_lookup_value (dict, "domains",
                                           G_VARIANT_TYPE_STRING);
      loom_setting_set_domain (loom_setting, g_variant_get_string (value, NULL));
    }

  if (g_variant_dict_contains (dict, "searches"))
    {
      value = g_variant_dict_lookup_value (dict, "searches",
                                           G_VARIANT_TYPE_STRING_ARRAY);
      gchar **strv = g_variant_dup_strv (value, NULL);
      loom_setting_set_searches (loom_setting, (const gchar **)strv);
      g_strfreev (strv);
    }

  g_variant_dict_unref (dict);
}
예제 #4
0
static void
properties_changed (GDBusProxy *proxy,
		    GVariant   *changed_properties,
		    GStrv       invalidated_properties,
		    gpointer    user_data)
{
	GVariant *v;
	GVariantDict dict;

	g_variant_dict_init (&dict, changed_properties);

	if (g_variant_dict_contains (&dict, "HasAccelerometer")) {
		v = g_dbus_proxy_get_cached_property (iio_proxy, "HasAccelerometer");
		g_message ("Accelerometer %s", g_variant_get_boolean (v) ? "appeared" : "disappeared");
		g_variant_unref (v);
	}
	if (g_variant_dict_contains (&dict, "AccelerometerOrientation")) {
		v = g_dbus_proxy_get_cached_property (iio_proxy, "AccelerometerOrientation");
		g_message ("Accelerometer orientation changed: %s", g_variant_get_string (v, NULL));
		g_variant_unref (v);
	}
	if (g_variant_dict_contains (&dict, "HasAmbientLight")) {
		v = g_dbus_proxy_get_cached_property (iio_proxy, "HasAmbientLight");
		g_message ("Light sensor %s", g_variant_get_boolean (v) ? "appeared" : "disappeared");
		g_variant_unref (v);
	}
	if (g_variant_dict_contains (&dict, "LightLevel")) {
		GVariant *unit;

		v = g_dbus_proxy_get_cached_property (iio_proxy, "LightLevel");
		unit = g_dbus_proxy_get_cached_property (iio_proxy, "LightLevelUnit");
		g_message ("Light changed: %lf (%s)", g_variant_get_double (v), g_variant_get_string (unit, NULL));
		g_variant_unref (v);
		g_variant_unref (unit);
	}
}
예제 #5
0
static gint
gedit_app_command_line (GApplication            *application,
                        GApplicationCommandLine *cl)
{
	GeditAppPrivate *priv;
	GVariantDict *options;
	const gchar *encoding_charset;
	const gchar **remaining_args;

	priv = gedit_app_get_instance_private (GEDIT_APP (application));

	options = g_application_command_line_get_options_dict (cl);

	g_variant_dict_lookup (options, "new-window", "b", &priv->new_window);
	g_variant_dict_lookup (options, "new-document", "b", &priv->new_document);
	g_variant_dict_lookup (options, "geometry", "s", &priv->geometry);

	if (g_variant_dict_contains (options, "wait"))
	{
		priv->command_line = cl;
	}

	if (g_variant_dict_lookup (options, "encoding", "&s", &encoding_charset))
	{
		priv->encoding = gtk_source_encoding_get_from_charset (encoding_charset);

		if (priv->encoding == NULL)
		{
			g_application_command_line_printerr (cl,
							     _("%s: invalid encoding."),
							     encoding_charset);
		}
	}

	/* Parse filenames */
	if (g_variant_dict_lookup (options, G_OPTION_REMAINING, "^a&ay", &remaining_args))
	{
		gint i;

		for (i = 0; remaining_args[i]; i++)
		{
			if (*remaining_args[i] == '+')
			{
				if (*(remaining_args[i] + 1) == '\0')
				{
					/* goto the last line of the document */
					priv->line_position = G_MAXINT;
					priv->column_position = 0;
				}
				else
				{
					get_line_column_position (remaining_args[i] + 1,
								  &priv->line_position,
								  &priv->column_position);
				}
			}
			else if (*remaining_args[i] == '-' && *(remaining_args[i] + 1) == '\0')
			{
				priv->stdin_stream = g_application_command_line_get_stdin (cl);
			}
			else
			{
				GFile *file;

				file = g_application_command_line_create_file_for_arg (cl, remaining_args[i]);
				priv->file_list = g_slist_prepend (priv->file_list, file);
			}
		}

		priv->file_list = g_slist_reverse (priv->file_list);
		g_free (remaining_args);
	}

	g_application_activate (application);
	clear_options (GEDIT_APP (application));

	return 0;
}
예제 #6
0
파일: settings.c 프로젝트: tschaefer/loom
static gboolean
validate_configuration (GVariant *configuration,
                        GError **error)
{
  GVariantDict *dict = NULL;
  GVariant *value = NULL;

  dict = g_variant_dict_new (configuration);

  if (g_variant_dict_contains (dict, "address"))
    {
      value = g_variant_dict_lookup_value (dict, "address",
                                           G_VARIANT_TYPE_STRING);
      if (value == NULL)
        {
          g_variant_dict_unref (dict);
          *error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
                                _("'address' entry must be a string"));
          return FALSE;
        }
      if (!validate_address ("address", g_variant_get_string (value, NULL),
                             TRUE, error))
        {
          g_variant_dict_unref (dict);
          return FALSE;
        }
    }
  else
    {
      g_variant_dict_unref (dict);
      *error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
                            _("'address' entry is required"));
      return FALSE;
    }

  if (g_variant_dict_contains (dict, "router"))
    {
      value = g_variant_dict_lookup_value (dict, "router",
                                           G_VARIANT_TYPE_STRING);
      if (value == NULL)
        {
          g_variant_dict_unref (dict);
          *error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
                                _("'router' entry must be a string"));
          return FALSE;
        }
      if (!validate_address ("router", g_variant_get_string (value, NULL),
                             FALSE, error))
        {
          g_variant_dict_unref (dict);
          return FALSE;
        }
    }

  if (g_variant_dict_contains (dict, "nameservers"))
    {
      value = g_variant_dict_lookup_value (dict, "nameservers",
                                           G_VARIANT_TYPE_STRING_ARRAY);
      if (value == NULL)
        {
          g_variant_dict_unref (dict);
          *error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
                            _("'nameservers' entry must be a string array"));
          return FALSE;
        }
      gsize len;
      gs_strfreev gchar **nameservers = g_variant_dup_strv (value, &len);
      for (gsize i = 0; i < len; i++)
        {
          if (!validate_address ("nameservers", nameservers[i],
                                 FALSE, error))
            {
              g_variant_dict_unref (dict);
              return FALSE;
            }
        }
    }

  if (g_variant_dict_contains (dict, "domain"))
    {
      value = g_variant_dict_lookup_value (dict, "domain",
                                           G_VARIANT_TYPE_STRING);
      if (value == NULL)
        {
          g_variant_dict_unref (dict);
          *error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
                                _("'domain' entry must be a string"));
          return FALSE;
        }
      if (!validate_domainname ("domain", g_variant_get_string (value, NULL),
                                error))
        {
          g_variant_dict_unref (dict);
          return FALSE;
        }
    }

  if (g_variant_dict_contains (dict, "searches"))
    {
      value = g_variant_dict_lookup_value (dict, "searches",
                                           G_VARIANT_TYPE_STRING_ARRAY);
      if (value == NULL)
        {
          g_variant_dict_unref (dict);
          *error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
                               _("'searches' entry must be a string array"));

          return FALSE;
        }
      gsize len;
      gs_strfreev gchar **searches = g_variant_dup_strv (value, &len);
      for (gsize i = 0; i < len; i++)
        {
          if (!validate_domainname ("searches", searches[i], error))
            {
              g_variant_dict_unref (dict);
              return FALSE;
            }
        }
    }

  g_variant_dict_unref (dict);

  return TRUE;
}