Exemplo n.º 1
0
static void
onOpenDialogResponse( GtkDialog * dialog, int response, gpointer core )
{
    char * folder;

    /* remember this folder the next time we use this dialog */
    folder = gtk_file_chooser_get_current_folder( GTK_FILE_CHOOSER( dialog ) );
    gtr_pref_string_set( PREF_KEY_OPEN_DIALOG_FOLDER, folder );
    g_free( folder );

    if( response == GTK_RESPONSE_ACCEPT )
    {
        GtkFileChooser  * chooser = GTK_FILE_CHOOSER( dialog );
        GtkWidget       * w = gtk_file_chooser_get_extra_widget( chooser );
        GtkToggleButton * tb = GTK_TOGGLE_BUTTON( w );
        const gboolean    do_start = gtr_pref_flag_get( TR_PREFS_KEY_START );
        const gboolean    do_prompt = gtk_toggle_button_get_active( tb );
        const gboolean    do_notify = FALSE;
        GSList * files = gtk_file_chooser_get_files( chooser );

        gtr_core_add_files( core, files, do_start, do_prompt, do_notify );
        g_slist_foreach( files, (GFunc)g_object_unref, NULL );
        g_slist_free( files );
    }

    gtk_widget_destroy( GTK_WIDGET( dialog ) );
}
Exemplo n.º 2
0
void
on_extensions_add_clicked(GtkButton *button, I7App *app)
{
	GtkWidget *dialog = gtk_file_chooser_dialog_new(
	  _("Select the extensions to install"),
	  GTK_WINDOW(app->prefs->window),
	  GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
	  GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
	gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);
	/* Create appropriate file filters */
	GtkFileFilter *filter1 = gtk_file_filter_new();
	gtk_file_filter_set_name(filter1, _("Inform 7 Extensions (*.i7x)"));
	gtk_file_filter_add_pattern(filter1, "*.i7x");
	GtkFileFilter *filter2 = gtk_file_filter_new();
	gtk_file_filter_set_name(filter2, _("All Files"));
	gtk_file_filter_add_pattern(filter2, "*");
	gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter1);
	gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter2);

	if(gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_ACCEPT) {
		gtk_widget_destroy(dialog);
		return;
	}

	/* Install each selected extension */
	GSList *extlist = gtk_file_chooser_get_files(GTK_FILE_CHOOSER(dialog));
	g_slist_foreach(extlist, (GFunc)install_extensions, app);

	/* Free stuff */
	g_slist_foreach(extlist, (GFunc)g_object_unref, NULL);
	g_slist_free(extlist);
	gtk_widget_destroy(dialog);
}
Exemplo n.º 3
0
static void
open_dialog_response_cb (CeditFileChooserDialog *dialog,
                         gint                    response_id,
                         CeditWindow            *window)
{
	GSList *files;
	const CeditEncoding *encoding;

	cedit_debug (DEBUG_COMMANDS);

	if (response_id != GTK_RESPONSE_OK)
	{
		gtk_widget_destroy (GTK_WIDGET (dialog));

		return;
	}

	files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (dialog));
	g_return_if_fail (files != NULL);

	encoding = cedit_file_chooser_dialog_get_encoding (dialog);

	gtk_widget_destroy (GTK_WIDGET (dialog));

	/* Remember the folder we navigated to */
	 _cedit_window_set_default_location (window, files->data);

	cedit_commands_load_files (window,
				   files,
				   encoding,
				   0);

	g_slist_foreach (files, (GFunc) g_object_unref, NULL);
	g_slist_free (files);
}
Exemplo n.º 4
0
static void
file_chooser_dialog_response_cb (GtkDialog *dialog,
				 int        response,
				 gpointer   user_data)
{
	GthSlideshowPreferences *self = user_data;

	switch (response) {
	case GTK_RESPONSE_DELETE_EVENT:
	case GTK_RESPONSE_CANCEL:
		gtk_widget_destroy (GTK_WIDGET (dialog));
		break;

	case GTK_RESPONSE_OK:
		{
			GSList       *files;
			GthIconCache *icon_cache;
			GtkListStore *list_store;
			GSList       *scan;

			files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (dialog));
			icon_cache = gth_icon_cache_new_for_widget(GTK_WIDGET (self), GTK_ICON_SIZE_MENU);
			list_store = (GtkListStore *) gtk_builder_get_object (self->priv->builder, "files_liststore");
			for (scan = files; scan; scan = scan->next) {
				GFile       *file = scan->data;
				GIcon       *icon;
				GdkPixbuf   *pixbuf;
				char        *uri;
				char        *name;
				GtkTreeIter  iter;

				icon = g_content_type_get_icon ("audio");
				pixbuf = gth_icon_cache_get_pixbuf (icon_cache, icon);
				uri = g_file_get_uri (file);
				name = _g_file_get_display_name (file);

				gtk_list_store_append (list_store, &iter);
				gtk_list_store_set (list_store, &iter,
						    FILE_COLUMN_ICON, pixbuf,
						    FILE_COLUMN_NAME, name,
						    FILE_COLUMN_URI, uri,
						    -1);

				g_free (name);
				g_free (uri);
				g_object_unref (pixbuf);
			}

			gth_icon_cache_free (icon_cache);
			g_slist_foreach (files, (GFunc) g_object_unref, NULL);
			g_slist_free (files);
		}
		gtk_widget_destroy (GTK_WIDGET (dialog));
		break;
	}
}
Exemplo n.º 5
0
int main(int argc, char** argv)
{
    int i;
    GtkDialog* dialog;
    GSList* files;
    gint res;

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

    gtk_init(&argc, &argv);

    files = NULL;
    if (argc == 1) {
	dialog = GTK_DIALOG(gtk_file_chooser_dialog_new(
			_("Caja Filename Repairer: Select Files To Rename"),
			NULL,
			GTK_FILE_CHOOSER_ACTION_OPEN,
			GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
			GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
			NULL));
	gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);
	res = gtk_dialog_run(dialog);
	if (res == GTK_RESPONSE_ACCEPT) {
	    files = gtk_file_chooser_get_files(GTK_FILE_CHOOSER(dialog));
	}
	gtk_widget_destroy(GTK_WIDGET(dialog));
    } else {
	for (i = 1; i < argc; i++) {
	    GFile* file = g_file_new_for_path(argv[i]);
	    files = g_slist_prepend(files, file);
	}
	files = g_slist_reverse(files);
    }

    if (files == NULL)
	return 0;

    dialog = repair_dialog_new(files);
    res = gtk_dialog_run(dialog);
    gtk_widget_hide(GTK_WIDGET(dialog));

    if (res == GTK_RESPONSE_APPLY) {
	repair_dialog_do_repair(dialog);
    }

    gtk_widget_destroy(GTK_WIDGET(dialog));

    g_slist_foreach(files, (GFunc)g_object_unref, NULL);
    g_slist_free(files);

    return 0;
}
Exemplo n.º 6
0
static void
ide_editor_perspective_actions_open_file (GSimpleAction *action,
                                          GVariant      *variant,
                                          gpointer       user_data)
{
  IdeEditorPerspective *self = user_data;
  GtkFileChooserNative *chooser;
  IdeWorkbench *workbench;
  gint ret;

  g_assert (G_IS_SIMPLE_ACTION (action));
  g_assert (IDE_IS_EDITOR_PERSPECTIVE (self));

  workbench = ide_widget_get_workbench (GTK_WIDGET (self));

  if (workbench == NULL)
    {
      g_warning ("Failed to locate workbench");
      return;
    }

  chooser = gtk_file_chooser_native_new (_("Open File"),
                                         GTK_WINDOW (workbench),
                                         GTK_FILE_CHOOSER_ACTION_OPEN,
                                         _("Open"),
                                         _("Cancel"));
  gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (chooser), FALSE);
  gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (chooser), TRUE);

  ret = gtk_native_dialog_run (GTK_NATIVE_DIALOG (chooser));

  if (ret == GTK_RESPONSE_ACCEPT)
    {
      g_autoptr(GPtrArray) ar = NULL;
      GSList *files;

      ar = g_ptr_array_new_with_free_func (g_object_unref);
      files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (chooser));
      for (const GSList *iter = files; iter; iter = iter->next)
        g_ptr_array_add (ar, iter->data);
      g_slist_free (files);

      if (ar->len > 0)
        ide_workbench_open_files_async (workbench,
                                        (GFile **)ar->pdata,
                                        ar->len,
                                        "editor",
                                        IDE_WORKBENCH_OPEN_FLAGS_NONE,
                                        NULL, NULL, NULL);
    }

  gtk_native_dialog_destroy (GTK_NATIVE_DIALOG (chooser));
}
Exemplo n.º 7
0
static GSList *
gtk_file_chooser_native_get_files (GtkFileChooser *chooser)
{
  GtkFileChooserNative *self = GTK_FILE_CHOOSER_NATIVE (chooser);

  switch (self->mode)
    {
    case MODE_WIN32:
      return g_slist_copy_deep (self->custom_files, (GCopyFunc)g_object_ref, NULL);

    case MODE_FALLBACK:
    default:
      return gtk_file_chooser_get_files (GTK_FILE_CHOOSER (self->dialog));
    }
}
Exemplo n.º 8
0
static GSList *
delegate_get_files (GtkFileChooser *chooser)
{
  return gtk_file_chooser_get_files (get_delegate (chooser));
}
Exemplo n.º 9
0
/*
 * To add a picture in the list -> call a FileSelectionWindow
 */
void Picture_Add_Button_Clicked (GObject *object)
{
    GtkWidget *FileSelectionWindow;
    GtkFileFilter *filter;
    GtkWindow *parent_window = NULL;
    static gchar *init_dir = NULL;
    gint response;

    g_return_if_fail (PictureEntryView != NULL);

    parent_window = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(object)));
    if (!gtk_widget_is_toplevel(GTK_WIDGET(parent_window)))
    {
        g_warning("Could not get parent window\n");
        return;
    }


    FileSelectionWindow = gtk_file_chooser_dialog_new(_("Add Images"),
                                                      parent_window,
                                                      GTK_FILE_CHOOSER_ACTION_OPEN,
                                                      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                                      GTK_STOCK_OPEN,   GTK_RESPONSE_OK,
                                                      NULL);

    // Add files filters
    // "All files" filter
    filter = gtk_file_filter_new ();
    gtk_file_filter_set_name(GTK_FILE_FILTER(filter), _("All Files"));
    gtk_file_filter_add_pattern(GTK_FILE_FILTER(filter), "*");
    gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(FileSelectionWindow), GTK_FILE_FILTER(filter));

    // "PNG and JPEG" filter
    filter = gtk_file_filter_new ();
    gtk_file_filter_set_name(GTK_FILE_FILTER(filter), _("PNG and JPEG"));
    gtk_file_filter_add_mime_type(GTK_FILE_FILTER(filter), "image/jpeg"); // Using mime type avoid problem of case sensitive with extensions
    gtk_file_filter_add_mime_type(GTK_FILE_FILTER(filter), "image/png");
    //gtk_file_filter_add_pattern(GTK_FILE_FILTER(filter), "*.jpeg"); // Warning: *.JPEG or *.JpEg files will not be displayed
    //gtk_file_filter_add_pattern(GTK_FILE_FILTER(filter), "*.jpg");
    //gtk_file_filter_add_pattern(GTK_FILE_FILTER(filter), "*.png");
    gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (FileSelectionWindow), GTK_FILE_FILTER(filter));
    // Make this filter the default
    gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(FileSelectionWindow), GTK_FILE_FILTER(filter));

    // Behaviour following the tag type...
    switch (ETCore->ETFileDisplayed->ETFileDescription->TagType)
    {
        case MP4_TAG:
        {
            // Only one file can be selected
            gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(FileSelectionWindow), FALSE);
            break;
        }

        // Other tag types
        default:
        {
            gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(FileSelectionWindow), TRUE);
            break;
        }
    }

    gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (FileSelectionWindow),
                                     FALSE);

    // Starting directory (the same of the current file)
    if (ETCore->ETFileDisplayed)
    {
        gchar *cur_filename_utf8 = ((File_Name *)((GList *)ETCore->ETFileDisplayed->FileNameCur)->data)->value_utf8;
        init_dir = g_path_get_dirname(cur_filename_utf8);
        gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(FileSelectionWindow),init_dir);
    }else
    // Starting directory (the same than the previous one)
    if (init_dir)
        gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(FileSelectionWindow),init_dir);

    response = gtk_dialog_run(GTK_DIALOG(FileSelectionWindow));
    if (response == GTK_RESPONSE_OK)
    {
        GtkTreeSelection *selection;
        GSList *list;

        selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(PictureEntryView));
        gtk_tree_selection_unselect_all(selection);

        list = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (FileSelectionWindow));
        g_slist_foreach (list, (GFunc) et_picture_load_file, NULL);
        g_slist_free_full (list, g_object_unref);

        // Save the directory selected for initialize next time
        g_free(init_dir);
        init_dir = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(FileSelectionWindow));
    }

    if (ETCore->ETFileDisplayed)
    {
        ET_Save_File_Data_From_UI (ETCore->ETFileDisplayed);
        ET_Display_File_Data_To_UI (ETCore->ETFileDisplayed);
    }

    gtk_widget_destroy(FileSelectionWindow);
}
Exemplo n.º 10
0
static void
file_open_dialog_response (GtkWidget *dialog,
                           gint       response_id,
                           Gimp      *gimp)
{
  GimpFileDialog *file_dialog = GIMP_FILE_DIALOG (dialog);
  GimpOpenDialog *open_dialog = GIMP_OPEN_DIALOG (dialog);
  GSList         *files;
  GSList         *list;
  gboolean        success = FALSE;

  gimp_file_dialog_save_state (GIMP_FILE_DIALOG (dialog),
                               "gimp-file-open-dialog-state");

  if (response_id != GTK_RESPONSE_OK)
    {
      if (! file_dialog->busy)
        gtk_widget_destroy (dialog);

      return;
    }

  files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (dialog));

  if (files)
    g_object_set_data_full (G_OBJECT (gimp), GIMP_FILE_OPEN_LAST_FILE_KEY,
                            g_object_ref (files->data),
                            (GDestroyNotify) g_object_unref);

  gimp_file_dialog_set_sensitive (file_dialog, FALSE);

  /* When we are going to open new image windows, unset the transient
   * window. We don't need it since we will use gdk_window_raise() to
   * keep the dialog on top. And if we don't do it, then the dialog
   * will pull the image window it was invoked from on top of all the
   * new opened image windows, and we don't want that to happen.
   */
  if (! open_dialog->open_as_layers)
    gtk_window_set_transient_for (GTK_WINDOW (dialog), NULL);

  for (list = files; list; list = g_slist_next (list))
    {
      GFile *file = list->data;

      if (open_dialog->open_as_layers)
        {
          if (! file_dialog->image)
            {
              file_dialog->image = file_open_dialog_open_image (dialog,
                                                                gimp,
                                                                file,
                                                                file_dialog->file_proc);

              if (file_dialog->image)
                success = TRUE;
            }
          else if (file_open_dialog_open_layers (dialog,
                                                 file_dialog->image,
                                                 file,
                                                 file_dialog->file_proc))
            {
              success = TRUE;
            }
        }
      else
        {
          if (file_open_dialog_open_image (dialog,
                                           gimp,
                                           file,
                                           file_dialog->file_proc))
            {
              success = TRUE;

              /* Make the dialog stay on top of all images we open if
               * we open say 10 at once
               */
              gdk_window_raise (gtk_widget_get_window (dialog));
            }
        }

      if (file_dialog->canceled)
        break;
    }

  if (success)
    {
      if (open_dialog->open_as_layers && file_dialog->image)
        gimp_image_flush (file_dialog->image);

      gtk_widget_destroy (dialog);
    }
  else
    {
      gimp_file_dialog_set_sensitive (file_dialog, TRUE);
    }

  g_slist_free_full (files, (GDestroyNotify) g_object_unref);
}