/**
 * thunar_sbr_replace_renamer_set_pattern:
 * @replace_renamer : a #ThunarSbrReplaceRenamer.
 * @pattern         : the new pattern for @replace_renamer.
 *
 * Sets the search pattern of @replace_renamer to @pattern.
 **/
void
thunar_sbr_replace_renamer_set_pattern (ThunarSbrReplaceRenamer *replace_renamer,
                                        const gchar             *pattern)
{
  g_return_if_fail (THUNAR_SBR_IS_REPLACE_RENAMER (replace_renamer));
  g_return_if_fail (g_utf8_validate (pattern, -1, NULL));

  /* check if we have a new pattern */
  if (!exo_str_is_equal (replace_renamer->pattern, pattern))
    {
      /* apply the new value */
      g_free (replace_renamer->pattern);
      replace_renamer->pattern = g_strdup (pattern);

#ifdef HAVE_PCRE
      /* pre-compile the pattern */
      thunar_sbr_replace_renamer_pcre_update (replace_renamer);
#endif

      /* update the renamer */
      thunarx_renamer_changed (THUNARX_RENAMER (replace_renamer));

      /* notify listeners */
      g_object_notify (G_OBJECT (replace_renamer), "pattern");
    }
}
static ThunarVfsVolumeHal*
thunar_vfs_volume_manager_hal_get_volume_by_udi (ThunarVfsVolumeManagerHal *manager_hal,
                                                 const gchar               *udi)
{
  GList *lp;

  for (lp = THUNAR_VFS_VOLUME_MANAGER (manager_hal)->volumes; lp != NULL; lp = lp->next)
    if (exo_str_is_equal (THUNAR_VFS_VOLUME_HAL (lp->data)->udi, udi))
      return THUNAR_VFS_VOLUME_HAL (lp->data);

  return NULL;
}
/**
 * thunar_sbr_number_renamer_set_text:
 * @number_renamer : a #ThunarSbrNumberRenamer.
 * @text           : the new text for @number_renamer.
 *
 * Sets the text for @number_renamer to @text.
 **/
void
thunar_sbr_number_renamer_set_text (ThunarSbrNumberRenamer *number_renamer,
                                    const gchar            *text)
{
  g_return_if_fail (THUNAR_SBR_IS_NUMBER_RENAMER (number_renamer));

  /* check if we have a new text */
  if (G_LIKELY (!exo_str_is_equal (number_renamer->text, text)))
    {
      /* apply the new text */
      g_free (number_renamer->text);
      number_renamer->text = g_strdup (text);

      /* update the renamer */
      thunar_sbr_number_renamer_update (number_renamer);

      /* notify listeners */
      g_object_notify (G_OBJECT (number_renamer), "text");
    }
}
/**
 * thunar_sbr_insert_renamer_set_text:
 * @insert_renamer : a #ThunarSbrInsertRenamer.
 * @text           : the new text for @insert_renamer.
 *
 * Sets the text for @insert_renamer to @text.
 **/
void
thunar_sbr_insert_renamer_set_text (ThunarSbrInsertRenamer *insert_renamer,
                                    const gchar            *text)
{
  g_return_if_fail (THUNAR_SBR_IS_INSERT_RENAMER (insert_renamer));

  /* check if we have a new text */
  if (G_LIKELY (!exo_str_is_equal (insert_renamer->text, text)))
    {
      /* apply the new text */
      g_free (insert_renamer->text);
      insert_renamer->text = g_strdup (text);

      /* update the renamer */
      thunarx_renamer_changed (THUNARX_RENAMER (insert_renamer));

      /* notify listeners */
      g_object_notify (G_OBJECT (insert_renamer), "text");
    }
}
static void
transform_string_to_enum (const GValue *src,
                          GValue       *dst)
{
  GEnumClass *klass;
  gint        value = 0;
  guint       n;

  /* determine the enum value matching the src... */
  klass = g_type_class_ref (G_VALUE_TYPE (dst));
  for (n = 0; n < klass->n_values; ++n)
    {
      value = klass->values[n].value;
      if (exo_str_is_equal (klass->values[n].value_name, g_value_get_string (src)))
        break;
    }
  g_type_class_unref (klass);

  /* ...and return that value */
  g_value_set_enum (dst, value);
}
/**
 * thunar_sbr_replace_renamer_set_replacement:
 * @replace_renamer : a #ThunarSbrReplaceRenamer.
 * @replacement     : the new replacement.
 *
 * Sets the replacement of @replace_renamer to @replacement.
 **/
void
thunar_sbr_replace_renamer_set_replacement (ThunarSbrReplaceRenamer *replace_renamer,
                                            const gchar             *replacement)
{
  g_return_if_fail (THUNAR_SBR_IS_REPLACE_RENAMER (replace_renamer));
  g_return_if_fail (g_utf8_validate (replacement, -1, NULL));

  /* check if we have a new replacement */
  if (!exo_str_is_equal (replace_renamer->replacement, replacement))
    {
      /* apply the setting */
      g_free (replace_renamer->replacement);
      replace_renamer->replacement = g_strdup (replacement);

      /* update the renamer */
      thunarx_renamer_changed (THUNARX_RENAMER (replace_renamer));

      /* notify listeners */
      g_object_notify (G_OBJECT (replace_renamer), "replacement");
    }
}
Exemple #7
0
static gboolean
model_has_action (ExoToolbarsModel *model,
                  GtkAction        *action)
{
  const gchar *action_name;
  const gchar *id;
  gboolean     is_separator;
  gint         i;
  gint         j;

  action_name = gtk_action_get_name (action);

  for (i = 0; i < exo_toolbars_model_n_toolbars (model); ++i)
    for (j = 0; j < exo_toolbars_model_n_items (model, i); ++j)
      {
        exo_toolbars_model_item_nth (model, i, j, &is_separator, &id, NULL);
        if (!is_separator && exo_str_is_equal (id, action_name))
          return TRUE;
      }

  return FALSE;
}
static void
thunar_apr_desktop_page_file_changed (ThunarAprAbstractPage *abstract_page,
                                      ThunarxFileInfo       *file)
{
    ThunarAprDesktopPage *desktop_page = THUNAR_APR_DESKTOP_PAGE (abstract_page);
    GKeyFile             *key_file;
    gboolean              writable;
    gboolean              enabled;
    GError               *error = NULL;
    gchar                *filename;
    gchar                *value;
    gchar                *type;
    gchar                *uri;

    /* allocate the key file memory */
    key_file = g_key_file_new ();

    /* determine the local path to the file */
    uri = thunarx_file_info_get_uri (file);
    filename = g_filename_from_uri (uri, NULL, NULL);
    g_free (uri);

    /* try to load the file contents */
    if (filename != NULL && g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, NULL))
    {
        /* determine the type of the .desktop file (default to "Application") */
        type = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, "Type", NULL);
        if (G_UNLIKELY (type == NULL))
            type = g_strdup ("Application");

        /* change page title depending on the type */
        if (strcmp (type, "Application") == 0)
            thunarx_property_page_set_label (THUNARX_PROPERTY_PAGE (desktop_page), _("Launcher"));
        else if (strcmp (type, "Link") == 0)
            thunarx_property_page_set_label (THUNARX_PROPERTY_PAGE (desktop_page), _("Link"));
        else
            thunarx_property_page_set_label (THUNARX_PROPERTY_PAGE (desktop_page), type);

        /* update the "Description" entry */
        value = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP, "GenericName", NULL, NULL);
        if (!exo_str_is_equal (value, desktop_page->description_text))
        {
            /* update the entry */
            gtk_entry_set_text (GTK_ENTRY (desktop_page->description_entry), (value != NULL) ? value : "");

            /* update the saved value */
            g_free (desktop_page->description_text);
            desktop_page->description_text = value;
        }
        else
        {
            g_free (value);
        }

        /* update the "Comment" entry */
        value = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP, "Comment", NULL, NULL);
        if (!exo_str_is_equal (value, desktop_page->comment_text))
        {
            /* update the entry */
            gtk_entry_set_text (GTK_ENTRY (desktop_page->comment_entry), (value != NULL) ? value : "");

            /* update the saved value */
            g_free (desktop_page->comment_text);
            desktop_page->comment_text = value;
        }
        else
        {
            g_free (value);
        }

        /* update the type dependant entries */
        if (strcmp (type, "Application") == 0)
        {
            /* update the "Command" entry */
            value = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, "Exec", NULL);
            if (!exo_str_is_equal (value, desktop_page->command_text))
            {
                /* update the entry */
                gtk_entry_set_text (GTK_ENTRY (desktop_page->command_entry), (value != NULL) ? value : "");

                /* update the saved value */
                g_free (desktop_page->command_text);
                desktop_page->command_text = value;
            }
            else
            {
                g_free (value);
            }

            /* update the "Path" entry */
            value = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, "Path", NULL);
            if (!exo_str_is_equal (value, desktop_page->path_text))
            {
                /* update the entry */
                gtk_entry_set_text (GTK_ENTRY (desktop_page->path_entry), (value != NULL) ? value : "");

                /* update the saved value */
                g_free (desktop_page->path_text);
                desktop_page->path_text = value;
            }
            else
            {
                g_free (value);
            }

            /* update the "Use startup notification" button */
            enabled = g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, "StartupNotify", &error);
            g_signal_handlers_block_by_func (G_OBJECT (desktop_page->snotify_button), thunar_apr_desktop_page_toggled, desktop_page);
            gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (desktop_page->snotify_button), (error == NULL && enabled));
            g_signal_handlers_unblock_by_func (G_OBJECT (desktop_page->snotify_button), thunar_apr_desktop_page_toggled, desktop_page);
            g_clear_error (&error);

            /* update the "Run in terminal" button */
            enabled = g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, "Terminal", &error);
            g_signal_handlers_block_by_func (G_OBJECT (desktop_page->terminal_button), thunar_apr_desktop_page_toggled, desktop_page);
            gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (desktop_page->terminal_button), (error == NULL && enabled));
            g_signal_handlers_unblock_by_func (G_OBJECT (desktop_page->terminal_button), thunar_apr_desktop_page_toggled, desktop_page);
            g_clear_error (&error);

            /* update visibility of the specific widgets */
            gtk_widget_show (desktop_page->command_entry);
            gtk_widget_show (desktop_page->path_entry);
            gtk_widget_hide (desktop_page->url_entry);
            gtk_widget_show (desktop_page->snotify_button);
            gtk_widget_show (desktop_page->terminal_button);
        }
        else if (strcmp (type, "Link") == 0)
        {
            /* update the "URL" entry */
            value = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, "URL", NULL);
            if (!exo_str_is_equal (value, desktop_page->url_text))
            {
                /* update the entry */
                gtk_entry_set_text (GTK_ENTRY (desktop_page->url_entry), (value != NULL) ? value : "");

                /* update the saved value */
                g_free (desktop_page->url_text);
                desktop_page->url_text = value;
            }
            else
            {
                g_free (value);
            }

            /* update visibility of the specific widgets */
            gtk_widget_hide (desktop_page->command_entry);
            gtk_widget_hide (desktop_page->path_entry);
            gtk_widget_show (desktop_page->url_entry);
            gtk_widget_hide (desktop_page->snotify_button);
            gtk_widget_hide (desktop_page->terminal_button);
        }
        else
        {
            /* hide the specific widgets */
            gtk_widget_hide (desktop_page->command_entry);
            gtk_widget_hide (desktop_page->path_entry);
            gtk_widget_hide (desktop_page->url_entry);
            gtk_widget_hide (desktop_page->snotify_button);
            gtk_widget_hide (desktop_page->terminal_button);
        }

        /* check if the file is writable... */
        writable = (g_access (filename, W_OK) == 0);

        /* ...and update the editability of the entries */
        gtk_editable_set_editable (GTK_EDITABLE (desktop_page->description_entry), writable);
        gtk_editable_set_editable (GTK_EDITABLE (desktop_page->command_entry), writable);
        gtk_editable_set_editable (GTK_EDITABLE (desktop_page->path_entry), writable);
        gtk_editable_set_editable (GTK_EDITABLE (desktop_page->url_entry), writable);
        gtk_editable_set_editable (GTK_EDITABLE (desktop_page->comment_entry), writable);
        gtk_widget_set_sensitive (desktop_page->snotify_button, writable);
        gtk_widget_set_sensitive (desktop_page->terminal_button, writable);

        /* cleanup */
        g_free (type);
    }
    else
    {
        /* reset page title */
        thunarx_property_page_set_label (THUNARX_PROPERTY_PAGE (desktop_page), _("Unknown"));

        /* hide all widgets */
        gtk_widget_hide (desktop_page->description_entry);
        gtk_widget_hide (desktop_page->command_entry);
        gtk_widget_hide (desktop_page->path_entry);
        gtk_widget_hide (desktop_page->url_entry);
        gtk_widget_hide (desktop_page->comment_entry);
        gtk_widget_hide (desktop_page->snotify_button);
        gtk_widget_hide (desktop_page->terminal_button);
    }

    /* cleanup */
    g_key_file_free (key_file);
    g_free (filename);
}
Exemple #9
0
/**
 * thunar_dialogs_show_rename_file:
 * @parent : a #GtkWidget on which the error dialog should be shown, or a #GdkScreen
 *           if no #GtkWidget is known. May also be %NULL, in which case the default
 *           #GdkScreen will be used.
 * @file   : the #ThunarFile we're going to rename.
 *
 * Displays the Thunar rename dialog for a single file rename.
 *
 * Return value: The #ThunarJob responsible for renaming the file or
 *               %NULL if there was no renaming required.
 **/
ThunarJob *
thunar_dialogs_show_rename_file (gpointer    parent,
                                 ThunarFile *file)
{
  ThunarIconFactory *icon_factory;
  GtkIconTheme      *icon_theme;
  const gchar       *filename;
  const gchar       *text;
  ThunarJob         *job = NULL;
  GtkWidget         *dialog;
  GtkWidget         *entry;
  GtkWidget         *label;
  GtkWidget         *image;
  GtkWidget         *table;
  GtkWindow         *window;
  GdkPixbuf         *icon;
  GdkScreen         *screen;
  glong              offset;
  gchar             *title;
  gint               response;
  PangoLayout       *layout;
  gint               layout_width;
  gint               layout_offset;
  gint               parent_width = 500;

  _thunar_return_val_if_fail (parent == NULL || GDK_IS_SCREEN (parent) || GTK_IS_WINDOW (parent), FALSE);
  _thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE);

  /* parse the parent window and screen */
  screen = thunar_util_parse_parent (parent, &window);

  /* get the filename of the file */
  filename = thunar_file_get_display_name (file);

  /* create a new dialog window */
  title = g_strdup_printf (_("Rename \"%s\""), filename);
  dialog = gtk_dialog_new_with_buttons (title,
                                        window,
                                        GTK_DIALOG_MODAL
                                        | GTK_DIALOG_NO_SEPARATOR
                                        | GTK_DIALOG_DESTROY_WITH_PARENT,
                                        GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                        _("_Rename"), GTK_RESPONSE_OK,
                                        NULL);
  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
  g_free (title);

  /* move the dialog to the appropriate screen */
  if (G_UNLIKELY (window == NULL && screen != NULL))
    gtk_window_set_screen (GTK_WINDOW (dialog), screen);

  table = g_object_new (GTK_TYPE_TABLE, "border-width", 6, "column-spacing", 6, "row-spacing", 3, NULL);
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), table, TRUE, TRUE, 0);
  gtk_widget_show (table);

  icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (dialog));
  icon_factory = thunar_icon_factory_get_for_icon_theme (icon_theme);
  icon = thunar_icon_factory_load_file_icon (icon_factory, file, THUNAR_FILE_ICON_STATE_DEFAULT, 48);
  g_object_unref (G_OBJECT (icon_factory));

  image = gtk_image_new_from_pixbuf (icon);
  gtk_misc_set_padding (GTK_MISC (image), 6, 6);
  gtk_table_attach (GTK_TABLE (table), image, 0, 1, 0, 2, GTK_FILL, GTK_FILL, 0, 0);
  g_object_unref (G_OBJECT (icon));
  gtk_widget_show (image);

  label = gtk_label_new (_("Enter the new name:"));
  gtk_misc_set_alignment (GTK_MISC (label), 0.0f, 0.5f);
  gtk_table_attach (GTK_TABLE (table), label, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
  gtk_widget_show (label);

  entry = gtk_entry_new ();
  gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
  gtk_table_attach (GTK_TABLE (table), entry, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
  gtk_widget_show (entry);

  /* setup the old filename */
  gtk_entry_set_text (GTK_ENTRY (entry), filename);

  /* check if we don't have a directory here */
  if (!thunar_file_is_directory (file))
    {
      /* check if the filename contains an extension */
      text = thunar_util_str_get_extension (filename);
      if (G_LIKELY (text != NULL))
        {
          /* grab focus to the entry first, else the selection will be altered later */
          gtk_widget_grab_focus (entry);

          /* determine the UTF-8 char offset */
          offset = g_utf8_pointer_to_offset (filename, text);

          /* select the text prior to the dot */
          if (G_LIKELY (offset > 0))
            gtk_editable_select_region (GTK_EDITABLE (entry), 0, offset);
        }
    }

  /* get the size the entry requires to render the full text */
  layout = gtk_entry_get_layout (GTK_ENTRY (entry));
  pango_layout_get_pixel_size (layout, &layout_width, NULL);
  gtk_entry_get_layout_offsets (GTK_ENTRY (entry), &layout_offset, NULL);
  layout_width += (layout_offset * 2) + (12 * 4) + 48; /* 12px free space in entry */

  /* parent window width */
  if (G_LIKELY (window != NULL))
    {
      /* keep below 90% of the parent window width */
      gtk_window_get_size (GTK_WINDOW (window), &parent_width, NULL);
      parent_width *= 0.90f;
    }

  /* resize the dialog to make long names fit as much as possible */
  gtk_window_set_default_size (GTK_WINDOW (dialog), CLAMP (layout_width, 300, parent_width), -1);

  /* run the dialog */
  response = gtk_dialog_run (GTK_DIALOG (dialog));
  if (G_LIKELY (response == GTK_RESPONSE_OK))
    {
      /* hide the dialog */
      gtk_widget_hide (dialog);
      
      /* determine the new filename */
      text = gtk_entry_get_text (GTK_ENTRY (entry));

      /* check if we have a new name here */
      if (G_LIKELY (!exo_str_is_equal (filename, text)))
        {
          /* try to rename the file */
          job = thunar_io_jobs_rename_file (file, text);
        }
    }

  /* cleanup */
  gtk_widget_destroy (dialog);

  return job;
}