GtkFileChooser (non local) URI weirdness
- From: Albert Veli <albert veli biosensor se>
- To: gtk-app-devel-list gnome org
- Subject: GtkFileChooser (non local) URI weirdness
- Date: Tue, 16 Aug 2005 23:27:48 +0200
Hi!
I'm trying to write an app that (among other things) shows a
GtkFileChooserDialog that lets the user select a file (for opening).
I want it to work both on the local filesystem and over FTP.
And I want the app to work on both Linux and Windows.
---
On Linux (Debian/Sarge, gtk+-2.6.4) an URI like this works:
"ftp://192.168.0.101/"
with gtk_file_chooser_set_current_folder_uri().
Then a new dialog pops up that asks for anonymous or username/password
login. I'm not sure, but I suspect gnome-vfs is beeing used as backend
and that the login dialog comes from there.
It even works with an URI like:
"ftp://username:password 192 168 0 101/home/username/some/directory"
But if directories are appended after the hostname a warning like this
is showed:
libgnomevfs-WARNING **: gnome-vfs-monitor.c: A monitor handle was
destroyed before it was added to the method hash table. This is a bug in
the application and can cause crashed. It is probably a race-condition.
---
On Windows (MinGW, gtk+-2.6.8) it works for local filesystem URI:s like
"file:///C:/some/directory"
But nothing happens with "ftp://" URI:s. The filechooser dialog
only shows the current directory instead of the FTP directory.
It is possible though to specify windows shares:
"file:////192.168.0.102/sharename"
But I don't want windows shares, I want the application to work the same
on Windows and Linux so I want FTP and local filesystem.
---
Is it possible to use GtkFileChooser with FTP on Windows?
First I thought that it should be relatively easy to write a custom
backend to GtkFileChooser that uses something like libcurl to browse
FTP, but I just couldn't figure out how to do it. There must be some
easier way...
Below is a minimal application that shows a filechooser dialog and tries
to browse FTP on localhost "ftp://127.0.0.1/".
The test-application works on Linux but not on Windows. There should,
off course, be an FTP-server at the specified IP-address.
Hope someone has an answer to my FTP troubles.
Regards, Albert
------ filechooser.c --8<--
/* Example program to experiment with a filechooser dialog.
* Compile with:
*
* gcc -W -Wall -o filechooser filechooser.c `pkg-config --cflags
--libs gtk+-2.0`
*
* On Windows, add the flag -mms-bitfields:
*
* gcc -W -Wall -mms-bitfields -o filechooser filechooser.c `pkg-config
--cflags --libs gtk+-2.0`
*/
#include <gtk/gtk.h>
/* Avoid warnings for (intentionally) unused variables */
#define UNUSED __attribute__ ((unused))
/* Global variable */
GtkWidget *main_window;
/* Callback for open button.
* Show a filechooser dialog with start directory "folder_uri" and
* print uri to selected file with g_print().
*/
static void open_callback(UNUSED GtkWidget *widget,
gchar *folder_uri)
{
GtkWidget *dialog;
gchar *chosen_uri;
dialog = gtk_file_chooser_dialog_new("Open File",
GTK_WINDOW(main_window),
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
NULL);
/* Allow open across network connections */
gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(dialog), FALSE);
/* Select current directory for file chooser */
gtk_file_chooser_set_current_folder_uri(GTK_FILE_CHOOSER(dialog),
folder_uri);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
chosen_uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(dialog));
g_print("Open \"%s\"\n", chosen_uri);
g_free(chosen_uri);
} else {
g_print("Cancel\n");
}
gtk_widget_destroy(dialog);
}
int main(int argc, char *argv[])
{
GtkWidget *button;
gtk_init(&argc, &argv);
main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(G_OBJECT(main_window), "delete_event",
G_CALLBACK(gtk_main_quit), NULL);
/* Create an open button and connect it to open_callback() */
button = gtk_button_new_from_stock(GTK_STOCK_OPEN);
g_signal_connect(G_OBJECT(button), "clicked",
G_CALLBACK(open_callback),
"ftp://127.0.0.1/");
gtk_container_add(GTK_CONTAINER(main_window), button);
gtk_widget_show(button);
gtk_widget_show(main_window);
gtk_main();
return 0;
}
-->8-- filechooser.c ------
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]