/* Internal: Load command config file */
void
_verve_db_load_rc (VerveDb *db, const gchar *filename)
{
  XfceRc *rc = xfce_rc_config_open (XFCE_RESOURCE_CONFIG, filename, FALSE);
  
  g_return_if_fail (xfce_rc_has_entry (rc, "Type"));

  /* Get command type */
  gint cmd_type = xfce_rc_read_int_entry (rc, "Type", VERVE_COMMAND_TYPE_SIMPLE);
  
  switch (cmd_type)
  {
    case VERVE_COMMAND_TYPE_SCRIPT:
      _verve_db_load_script_rc (db, rc);
      break;
    
    case VERVE_COMMAND_TYPE_SIMPLE:
      _verve_db_load_simple_rc (db, rc);
      break;
  }

  xfce_rc_close (rc);
}
Esempio n. 2
0
static void
migrate_46_panel_add_plugin (ConfigParser  *parser,
                             const gchar   *name,
                             const gchar   *id,
                             GError       **error)
{
  XfconfChannel *channel;
  gchar          base[256];
  XfceRc        *rc;
  const gchar   *plugin_name = name;

  g_return_if_fail (XFCONF_IS_CHANNEL (parser->channel));

  /* open the old rc file of the plugin */
  g_snprintf (base, sizeof (base), "heartlenv" G_DIR_SEPARATOR_S
             "panel" G_DIR_SEPARATOR_S "%s-%s.rc", name, id);
  rc = xfce_rc_config_open (XFCE_RESOURCE_CONFIG, base, TRUE);

  /* open a panel with the propert base for the plugin */
  g_snprintf (base, sizeof (base), "/plugins/plugin-%d", parser->plugin_id_counter);
  channel = xfconf_channel_new_with_property_base (XFCE_PANEL_CHANNEL_NAME, base);

  if (strcmp (name, "actions") == 0)
    {
      if (G_LIKELY (rc != NULL))
        migrate_46_plugin_actions (channel, rc);
    }
  else if (strcmp (name, "clock") == 0)
    {
      if (G_LIKELY (rc != NULL))
        migrate_46_plugin_clock (channel, rc);
    }
  else if (strcmp (name, "iconbox") == 0)
    {
      plugin_name = "tasklist";
      if (G_LIKELY (rc != NULL))
        migrate_46_plugin_iconbox (channel, rc);
    }
  else if (strcmp (name, "launcher") == 0)
    {
      if (G_LIKELY (rc != NULL))
        migrate_46_plugin_launcher (channel, rc, parser->plugin_id_counter, error);
    }
  else if (strcmp (name, "pager") == 0)
    {
      if (G_LIKELY (rc != NULL))
        migrate_46_plugin_pager (channel, rc);
    }
  else if (strcmp (name, "separator") == 0)
    {
      if (G_LIKELY (rc != NULL))
        migrate_46_plugin_separator (channel, rc);
    }
  else if (strcmp (name, "showdesktop") == 0)
    {
      if (G_LIKELY (rc != NULL))
        migrate_46_plugin_showdesktop (channel, rc);
    }
  else if (strcmp (name, "systray") == 0)
    {
      if (G_LIKELY (rc != NULL))
        migrate_46_plugin_systray (channel, rc);
    }
  else if (strcmp (name, "tasklist") == 0)
    {
      if (G_LIKELY (rc != NULL))
        migrate_46_plugin_tasklist (channel, rc);
    }
  else if (strcmp (name, "windowlist") == 0)
    {
      plugin_name = "windowmenu";
      if (G_LIKELY (rc != NULL))
        migrate_46_plugin_windowlist (channel, rc);
    }
  else if (strcmp (name, "heartlenv-menu") == 0)
    {
      plugin_name = "applicationsmenu";
      if (G_LIKELY (rc != NULL))
        migrate_46_plugin_heartlenv_menu (channel, rc);
    }
  else
    {
      /* handle other "external" plugins */
    }

  /* close plugin configs */
  g_object_unref (G_OBJECT (channel));
  if (G_LIKELY (rc != NULL))
    xfce_rc_close (rc);

  /* store the (new) plugin name */
  xfconf_channel_set_string (parser->channel, base, plugin_name);
}
Esempio n. 3
0
static gboolean
thunar_preferences_store_idle (gpointer user_data)
{
  ThunarPreferences *preferences = THUNAR_PREFERENCES (user_data);
  const gchar       *string;
  GParamSpec       **specs;
  GParamSpec        *spec;
  XfceRc            *rc;
  GValue             dst = { 0, };
  GValue             src = { 0, };
  gchar             *option;
  guint              nspecs;
  guint              n;

  rc = xfce_rc_config_open (XFCE_RESOURCE_CONFIG, "Thunar/thunarrc", FALSE);
  if (G_UNLIKELY (rc == NULL))
    {
      g_warning ("Failed to store thunar preferences.");
      return FALSE;
    }

  /* suspend the monitor (hopefully tricking FAM to avoid unnecessary reloads) */
  thunar_preferences_suspend_monitor (preferences);

  xfce_rc_set_group (rc, "Configuration");

  specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (preferences), &nspecs);
  for (n = 0; n < nspecs; ++n)
    {
      spec = specs[n];

      g_value_init (&dst, G_TYPE_STRING);

      if (spec->value_type == G_TYPE_STRING)
        {
          g_object_get_property (G_OBJECT (preferences), spec->name, &dst);
        }
      else
        {
          g_value_init (&src, spec->value_type);
          g_object_get_property (G_OBJECT (preferences), spec->name, &src);
          g_value_transform (&src, &dst);
          g_value_unset (&src);
        }

      /* determine the option name for the spec */
      option = property_name_to_option_name (spec->name);

      /* store the setting */
      string = g_value_get_string (&dst);
      if (G_LIKELY (string != NULL))
        xfce_rc_write_entry (rc, option, string);

      /* cleanup */
      g_value_unset (&dst);
      g_free (option);
    }

  /* cleanup */
  xfce_rc_close (rc);
  g_free (specs);

  /* restart the monitor */
  thunar_preferences_resume_monitor (preferences);

  return FALSE;
}
Esempio n. 4
0
static gboolean
thunar_preferences_load_idle (gpointer user_data)
{
  ThunarPreferences *preferences = THUNAR_PREFERENCES (user_data);
  const gchar       *string;
  GParamSpec       **specs;
  GParamSpec        *spec;
  XfceRc            *rc;
  GValue             dst = { 0, };
  GValue             src = { 0, };
  gchar             *option;
  guint              nspecs;
  guint              n;

  rc = xfce_rc_config_open (XFCE_RESOURCE_CONFIG, "Thunar/thunarrc", TRUE);
  if (G_UNLIKELY (rc == NULL))
    {
      g_warning ("Failed to load thunar preferences.");
      return FALSE;
    }

  g_object_freeze_notify (G_OBJECT (preferences));

  xfce_rc_set_group (rc, "Configuration");

  preferences->loading_in_progress = TRUE;

  specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (preferences), &nspecs);
  for (n = 0; n < nspecs; ++n)
    {
      spec = specs[n];

      option = property_name_to_option_name (spec->name);
      string = xfce_rc_read_entry (rc, option, NULL);
      g_free (option);

      if (G_UNLIKELY (string == NULL))
        continue;

      g_value_init (&src, G_TYPE_STRING);
      g_value_set_static_string (&src, string);

      if (spec->value_type == G_TYPE_STRING)
        {
          g_object_set_property (G_OBJECT (preferences), spec->name, &src);
        }
      else if (g_value_type_transformable (G_TYPE_STRING, spec->value_type))
        {
          g_value_init (&dst, spec->value_type);
          if (g_value_transform (&src, &dst))
            g_object_set_property (G_OBJECT (preferences), spec->name, &dst);
          g_value_unset (&dst);
        }
      else
        {
          g_warning ("Failed to load property \"%s\"", spec->name);
        }

      g_value_unset (&src);
    }
  g_free (specs);

  preferences->loading_in_progress = FALSE;

  xfce_rc_close (rc);

  g_object_thaw_notify (G_OBJECT (preferences));

  return FALSE;
}
Esempio n. 5
0
/**
 * xfce_dialog_show_help_with_version:
 * @parent    : (allow-none): transient parent of the dialog, or %NULL.
 * @component : (allow-none): name of the component opening the help page or %NULL. If the
 *              value is %NULL the target will be the main page of the
 *              documentation website.
 * @page      : (allow-none): subpage of the @component on the website or %NULL.
 * @offset    : (allow-none): anchor offset in @page or %NULL.
 * @version   : (allow-none): alternative version, or %NULL to use xfce_version_string().
 *
 * Asks the user to visit the online documentation. If confirmed, it will open
 * the webbrowser and redirect the user to the correct location.
 *
 * Appart from the @component, @page and @offset the following information
 * is also send to the server: user language and the xfce_version_string()
 * or @version if set.
 *
 * See also: xfce_dialog_show_help().
 *
 * Since: 4.12
 *
 */
void
xfce_dialog_show_help_with_version (GtkWindow   *parent,
                                    const gchar *component,
                                    const gchar *page,
                                    const gchar *offset,
                                    const gchar *version)
{
  GtkWidget   *dialog;
  const gchar *name;
  gchar       *primary;
  GString     *uri;
  gchar       *locale;
  GtkWidget   *message_box;
  GtkWidget   *button;
  XfceRc      *rc;
  gboolean     auto_online;
  GdkScreen   *screen;

  g_return_if_fail (parent == NULL || GTK_IS_WINDOW (parent));

  /* get the user's locale without encoding */
  locale = g_strdup (setlocale (LC_MESSAGES, NULL));
  if (G_LIKELY (locale != NULL))
    locale = g_strdelimit (locale, ".", '\0');
  else
    locale = g_strdup ("C");

  /* use desktop version if none is set */
  if (version == NULL)
    version = xfce_version_string ();

  /* build the redirect uri */
  uri = g_string_new (MANUAL_WEBSITE);
  g_string_append_printf (uri, "?version=%s&locale=%s", version, locale);
  g_free (locale);

  if (component != NULL)
    g_string_append_printf (uri, "&component=%s", component);
  if (page != NULL)
    g_string_append_printf (uri, "&page=%s", page);
  if (offset != NULL)
    g_string_append_printf (uri, "&offset=%s", offset);

  /* check if we should automatically go online */
  rc = xfce_rc_config_open (XFCE_RESOURCE_CONFIG, "xfce4/help.rc", TRUE);
  if (rc != NULL)
    {
      auto_online = xfce_rc_read_bool_entry (rc, "auto-online", FALSE);
      xfce_rc_close (rc);

      if (auto_online)
        {
          if (parent != NULL)
            screen = gtk_window_get_screen (GTK_WINDOW (parent));
          else
            screen = xfce_gdk_screen_get_active (NULL);

          xfce_dialog_show_help_uri (screen, parent, uri);
          g_string_free (uri, TRUE);

          return;
        }
    }

  /* try to get a translated name of the application */
  name = g_get_application_name ();
  if (g_strcmp0 (name, g_get_prgname ()) == 0)
    name = NULL;

  /* try to get a decent primary text */
  if (name != NULL)
    primary = g_strdup_printf (_("Do you want to read the %s manual online?"), name);
  else
    primary = g_strdup (_("Do you want to read the manual online?"));

  dialog = xfce_message_dialog_new (parent,
                                    _("Online Documentation"),
#if !GTK_CHECK_VERSION (3, 10, 0)
                                    GTK_STOCK_DIALOG_QUESTION,
#else
                                    "dialog-question",
#endif
                                    primary,
                                    _("You will be redirected to the documentation website "
                                      "where the help pages are maintained and translated."),
#if !GTK_CHECK_VERSION (3, 10, 0)
                                    GTK_STOCK_CANCEL,
#else
                                    "gtk-cancel",
#endif
                                    GTK_RESPONSE_NO,
                                    XFCE_BUTTON_TYPE_MIXED,
#if !GTK_CHECK_VERSION (3, 10, 0)
                                    GTK_STOCK_HELP,
#else
                                    "help-browser",
#endif
                                    _("_Read Online"),
                                    GTK_RESPONSE_YES,
                                    NULL);
  g_free (primary);


  message_box = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
  g_return_if_fail (GTK_IS_BOX (message_box));

  button = gtk_check_button_new_with_mnemonic (_("_Always go directly to the online documentation"));
  gtk_box_pack_end (GTK_BOX (message_box), button, FALSE, TRUE, 0);
#if GTK_CHECK_VERSION (3, 0, 0)
  g_object_set (G_OBJECT (button), "halign", GTK_ALIGN_END, "margin-start", 8, "margin-end", 8, NULL);
  gtk_widget_set_hexpand (button, TRUE);
#endif
  g_signal_connect (G_OBJECT (button), "toggled",
      G_CALLBACK (xfce_dialog_show_help_auto_toggled), NULL);
  gtk_widget_show (button);

  /* don't focus the checkbutton */
  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
  button = gtk_dialog_get_widget_for_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
  gtk_widget_grab_focus (button);

  /* show the dialog without locking the mainloop */
  gtk_window_set_modal (GTK_WINDOW (dialog), parent != NULL);
  g_signal_connect (G_OBJECT (dialog), "response",
      G_CALLBACK (xfce_dialog_show_help_response), uri);
  gtk_window_present (GTK_WINDOW (dialog));
}
Esempio n. 6
0
/**
 * xfae_model_toggle:
 * @model : a #XfaeModel.
 * @iter  : the #GtkTreeIter referring to the item that should be toggled.
 * @error : return location for errors or %NULL.
 *
 * Attempts to toggle the state of the item referrred to by @iter.
 *
 * Return value: %TRUE on success, else %FALSE.
 **/
gboolean
xfae_model_toggle (XfaeModel   *model,
                   GtkTreeIter *iter,
                   GError     **error)
{
  GtkTreePath *path;
  XfaeItem    *item;
  XfceRc      *rc;
  GList       *lp;

  g_return_val_if_fail (XFAE_IS_MODEL (model), FALSE);
  g_return_val_if_fail (iter->stamp == model->stamp, FALSE);
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

  lp = iter->user_data;
  item = lp->data;

  /* try to open the resource config */
  rc = xfce_rc_config_open (XFCE_RESOURCE_CONFIG, item->relpath, FALSE);
  if (G_UNLIKELY (rc == NULL))
    {
      g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (EIO),
                   _("Failed to open %s for writing"), item->relpath);
      return FALSE;
    }

  xfce_rc_set_group (rc, "Desktop Entry");

  if (item->show_in_xfce)
    {
      /* This is an application with no OnlyShowIn categories or with
       * XFCE in it. In this case, toggle the Hidden flag */

      item->hidden = !item->hidden;
      xfce_rc_write_bool_entry (rc, "Hidden", item->hidden);
    }
  else
    {
      /* Normally a non-Xfce autostart application, toggle the override
       * boolean so we don't hide the service in other desktops */

      item->show_in_override = !item->show_in_override;
      xfce_rc_write_bool_entry (rc, "X-XFCE-Autostart-Override", item->show_in_override);

      /* if we override, but the item is still hidden, toggle that as well then */
      if (item->hidden && item->show_in_override)
        {
          item->hidden = !item->hidden;
          xfce_rc_write_bool_entry (rc, "Hidden", item->hidden);
        }
    }

  xfce_rc_close (rc);

  /* tell the view that we have most probably a new state */
  path = gtk_tree_path_new_from_indices (g_list_position (model->items, lp), -1);
  gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, iter);
  gtk_tree_path_free (path);

  return TRUE;
}
Esempio n. 7
0
/**
 * xfae_model_add:
 * @model       : a #XfaeModel.
 * @name        : the user visible name of the new item.
 * @description : the description for the new item.
 * @command     : the command for the new item.
 * @error       : return locations for errors or %NULL.
 *
 * Attempts to add a new item with the given parameters
 * to @model.
 *
 * Return value: %TRUE if successfull, else %FALSE.
 **/
gboolean
xfae_model_add (XfaeModel   *model,
                const gchar *name,
                const gchar *description,
                const gchar *command,
                GError     **error)
{
  GtkTreePath *path;
  GtkTreeIter  iter;
  XfaeItem    *item;
  XfceRc      *rc;
  gchar       *file;
  gchar       *dir;
  gchar        relpath[4096];
  guint        n;

  g_return_val_if_fail (XFAE_IS_MODEL (model), FALSE);
  g_return_val_if_fail (name != NULL, FALSE);
  g_return_val_if_fail (description != NULL, FALSE);
  g_return_val_if_fail (command != NULL, FALSE);
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

  dir = xfce_resource_save_location (XFCE_RESOURCE_CONFIG, "autostart/", TRUE);

  /* generate a unique file name */
  for (n = 0;; ++n)
    {
      file = (n == 0)
        ?  g_strdup_printf ("%s.desktop", name)
        : g_strdup_printf ("%s-%u.desktop", name, n);
      file = g_strdelimit (file, G_DIR_SEPARATOR_S, '-'); /* not a copy */

      g_snprintf (relpath, 4096, "%s%s", dir, file);
      if (!g_file_test (relpath, G_FILE_TEST_IS_REGULAR))
        break;

      g_free (file);
    }

  /* generate the file spec */
  g_snprintf (relpath, 4096, "autostart/%s", file);
  g_free (file);
  g_free (dir);

  /* generate the .desktop file */
  rc = xfce_rc_config_open (XFCE_RESOURCE_CONFIG, relpath, FALSE);
  if (G_UNLIKELY (rc == NULL))
    {
      g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (EIO),
                   _("Failed to create file %s"), relpath);
      return FALSE;
    }

  /* write the content */
  xfce_rc_set_group (rc, "Desktop Entry");
  xfce_rc_write_entry (rc, "Encoding", "UTF-8");
  xfce_rc_write_entry (rc, "Version", "0.9.4");
  xfce_rc_write_entry (rc, "Type", "Application");
  xfce_rc_write_entry (rc, "Name", name);
  xfce_rc_write_entry (rc, "Comment", description);
  xfce_rc_write_entry (rc, "Exec", command);
  xfce_rc_write_entry (rc, "OnlyShowIn", "XFCE;");
  xfce_rc_write_bool_entry (rc, "StartupNotify", FALSE);
  xfce_rc_write_bool_entry (rc, "Terminal", FALSE);
  xfce_rc_write_bool_entry (rc, "Hidden", FALSE);
  xfce_rc_close (rc);

  /* now load the matching item for the list */
  item = xfae_item_new (relpath);
  if (G_UNLIKELY (item == NULL))
    {
      g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (EIO),
                   _("Failed to write file %s"), relpath);
      return FALSE;
    }

  /* append it to our list */
  model->items = g_list_append (model->items, item);

  /* generate the iter for the newly appended item */
  iter.stamp = model->stamp;
  iter.user_data = g_list_last (model->items);

  /* tell the view about it */
  path = gtk_tree_path_new_from_indices (g_list_length (model->items) - 1, -1);
  gtk_tree_model_row_inserted (GTK_TREE_MODEL (model), path, &iter);
  gtk_tree_path_free (path);

  return TRUE;
}
Esempio n. 8
0
static XfaeItem*
xfae_item_new (const gchar *relpath)
{
  const gchar   *value;
  XfaeItem      *item = NULL;
  gboolean       skip = FALSE;
  XfceRc        *rc;
  gchar        **only_show_in;
  gchar        **not_show_in;
  gchar        **args;
  gint           m;
  GtkIconTheme  *icon_theme;
  gchar         *command;

  rc = xfce_rc_config_open (XFCE_RESOURCE_CONFIG, relpath, TRUE);
  if (G_LIKELY (rc != NULL))
    {
      xfce_rc_set_group (rc, "Desktop Entry");

      /* verify that we have an application here */
      value = xfce_rc_read_entry (rc, "Type", NULL);
      if (G_LIKELY (value != NULL
          && g_ascii_strcasecmp (value, "Application") == 0))
        {
          icon_theme = gtk_icon_theme_get_default ();

          item = g_new0 (XfaeItem, 1);
          item->relpath = g_strdup (relpath);

          value = xfce_rc_read_entry (rc, "Name", NULL);
          if (G_LIKELY (value != NULL))
            item->name = g_strdup (value);

          value = xfce_rc_read_entry (rc, "Icon", "application-x-executable");
          if (G_UNLIKELY (value != NULL))
            item->icon = gtk_icon_theme_load_icon (icon_theme, value, 16, GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL);

          value = xfce_rc_read_entry (rc, "Comment", NULL);
          if (G_LIKELY (value != NULL))
            item->comment = g_strdup (value);

          value = xfce_rc_read_entry (rc, "Exec", NULL);
          if (G_LIKELY (value != NULL))
            item->tooltip = g_markup_printf_escaped ("<b>%s</b> %s", _("Command:"), value);

          item->hidden = xfce_rc_read_bool_entry (rc, "Hidden", FALSE);
        }
      else
        {
          return NULL;
        }

      item->show_in_override = xfce_rc_read_bool_entry (rc, "X-XFCE-Autostart-Override", FALSE);

      /* check the NotShowIn setting */
      not_show_in = xfce_rc_read_list_entry (rc, "NotShowIn", ";");
      if (G_UNLIKELY (not_show_in != NULL))
        {
          /* check if "XFCE" is specified */
          for (m = 0; not_show_in[m] != NULL; ++m)
            if (g_ascii_strcasecmp (not_show_in[m], "XFCE") == 0)
              {
                skip = TRUE;
                break;
              }

          g_strfreev (not_show_in);
        }

      /* check the OnlyShowIn setting */
      only_show_in = xfce_rc_read_list_entry (rc, "OnlyShowIn", ";");
      if (G_UNLIKELY (only_show_in != NULL))
        {
          /* check if "XFCE" is specified */
          for (m = 0; only_show_in[m] != NULL; ++m)
            if (g_ascii_strcasecmp (only_show_in[m], "XFCE") == 0)
              {
                item->show_in_xfce = TRUE;
                break;
              }

          g_strfreev (only_show_in);
        }
      else
        {
          /* no OnlyShowIn, treat it like a normal application */
          item->show_in_xfce = TRUE;
        }

      value = xfce_rc_read_entry (rc, "TryExec", NULL);
      if (value != NULL && g_shell_parse_argv (value, NULL, &args, NULL))
        {
          if (!g_file_test (args[0], G_FILE_TEST_EXISTS))
            {
               command = g_find_program_in_path (args[0]);
               if (command == NULL)
                 skip = TRUE;
               g_free (command);
            }

          g_strfreev (args);
        }

      xfce_rc_close (rc);

      /* check if we should skip the item */
      if (G_UNLIKELY (skip))
        {
          xfae_item_free (item);
          item = NULL;
        }
    }

  return item;
}