Example #1
0
void
egg_icon_chooser_unselect_filename (EggIconChooser *chooser,
				    const gchar    *filename)
{
  EggIconChooserIface *iface;
  GtkFileSystem *fs;
  GtkFilePath *path;

  g_return_if_fail (EGG_IS_ICON_CHOOSER (chooser));

  iface = EGG_ICON_CHOOSER_GET_IFACE (chooser);

  g_return_if_fail (iface->unselect_path != NULL);
  g_return_if_fail (iface->get_file_system != NULL);

  fs = (*iface->get_file_system) (chooser);

  path = gtk_file_system_filename_to_path (fs, filename);

  if (path != NULL)
    {
      (*iface->unselect_path) (chooser, path);
      gtk_file_path_free (path);
    }
}
Example #2
0
static GSList *
file_paths_to_strings (GtkFileSystem *fs,
                       GSList        *paths,
                       gchar *      (*convert_func) (GtkFileSystem *fs, const GtkFilePath *path))
{
  GSList *strings;

  strings = NULL;

  while (paths != NULL)
    {
      GtkFilePath *path;
      gchar *string;

      path = paths->data;
      string = (* convert_func) (fs, path);

      /* Eat the list */
      gtk_file_path_free (path);
      paths = g_slist_remove_link (paths, paths);

      if (string)
        strings = g_slist_prepend (strings, string);
    }

  return g_slist_reverse (strings);
}
Example #3
0
gboolean
egg_icon_chooser_select_filename (EggIconChooser *chooser,
				  const gchar    *filename)
{
  EggIconChooserIface *iface;
  GtkFileSystem *fs;
  GtkFilePath *path;
  gboolean retval;

  g_return_val_if_fail (EGG_IS_ICON_CHOOSER (chooser), FALSE);

  iface = EGG_ICON_CHOOSER_GET_IFACE (chooser);

  g_return_val_if_fail (iface->select_path != NULL, FALSE);
  g_return_val_if_fail (iface->get_file_system != NULL, FALSE);

  fs = (*iface->get_file_system) (chooser);

  path = gtk_file_system_filename_to_path (fs, filename);

  if (path != NULL)
    {
      retval = (*iface->select_path) (chooser, path, NULL);
      gtk_file_path_free (path);
    }
  else
    retval = FALSE;

  return retval;
}
Example #4
0
static void
test_folder_switch_and_filters (void)
{
  gboolean passed;
  char *cwd;
  char *base_dir;
  GtkFilePath *cwd_path;
  GtkFilePath *base_dir_path;
  GtkWidget *dialog;
  GtkFileFilter *all_filter;
  GtkFileFilter *txt_filter;
  GtkFileChooserDefault *impl;

  passed = TRUE;

  cwd = g_get_current_dir ();
  base_dir = g_build_filename (cwd, "file-chooser-test-dir", NULL);

  dialog = gtk_file_chooser_dialog_new ("Test", NULL, GTK_FILE_CHOOSER_ACTION_OPEN,
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
					GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
					NULL);
  impl = get_impl_from_dialog (dialog);

  cwd_path = gtk_file_system_filename_to_path (impl->file_system, cwd);
  base_dir_path = gtk_file_system_filename_to_path (impl->file_system, base_dir);

  passed = passed && gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), base_dir);
  g_assert (passed);

  /* All files filter */

  all_filter = gtk_file_filter_new ();
  gtk_file_filter_set_name (all_filter, "All files");
  gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), all_filter);

  /* *.txt filter */

  txt_filter = gtk_file_filter_new ();
  gtk_file_filter_set_name (all_filter, "*.txt");
  gtk_file_filter_add_pattern (txt_filter, "*.txt");
  gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), txt_filter);

  /* Test filter set */

  gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), all_filter);
  passed = passed && (gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (dialog)) == all_filter);
  g_assert (passed);

  gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), txt_filter);
  passed = passed && (gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (dialog)) == txt_filter);
  log_test (passed, "test_folder_switch_and_filters(): set and get filter");
  g_assert (passed);

  gtk_widget_show (dialog);

  /* Test that filter is unchanged when we switch folders */

  gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), cwd);
  sleep_in_main_loop (0.5);
  passed = passed && (gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (dialog)) == txt_filter);
  g_assert (passed);

  gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), base_dir);
  sleep_in_main_loop (0.25);

  g_signal_emit_by_name (impl->browse_path_bar, "path-clicked",
			 (GtkFilePath *) cwd_path,
			 (GtkFilePath *) base_dir_path,
			 FALSE);
  sleep_in_main_loop (0.25);
  passed = passed && (gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (dialog)) == txt_filter);
  log_test (passed, "test_folder_switch_and_filters(): filter after changing folder");
  g_assert (passed);

  /* cleanups */
  g_free (cwd);
  g_free (base_dir);
  gtk_file_path_free (cwd_path);
  gtk_file_path_free (base_dir_path);

  gtk_widget_destroy (dialog);

  log_test (passed, "test_folder_switch_and_filters(): all filter tests");
}