hi people!
this is my first patch (first time i use rcs too), so dont expect big
things.
It just reads the ~/.gtk-bookmarks file to populate the favorites tree.
i didn't know how to open and read the file (im not an experienced
programmer at all and probably i should use some mallocs to follow your
code guidelines, but this worked for me and wanted to know if there were
any good example i could look at).
i have plans to do some more work in the file chooser (when everything
is working, id like to implement an option to see hidden files, for
example), but till february ill be too busy, so if you have any idea or
suggestion will be welcomed.
greetings,
- yiyus
"any confirmation prompts at all may be a sign that what your interface
really needs is an undo command" - Eric. S. Raymond
--- ./etk_filechooser_widget.c 2006/01/16 22:58:40 1.3
+++ ./etk_filechooser_widget.c 2006/01/17 01:18:58
@@ -19,7 +19,7 @@
/* TODO: Etk_Theme */
#define ETK_DEFAULT_ICON_SET_FILE PACKAGE_DATA_DIR "/stock_icons/default.edj"
-
+#define ETK_FILECHOOSER_FAVS ".gtk-bookmarks"
/**
* @addtogroup Etk_Filechooser_Widget
* @{
@@ -45,7 +45,9 @@
static void _etk_filechooser_widget_destructor(Etk_Filechooser_Widget *filechooser_widget);
static void _etk_filechooser_widget_property_set(Etk_Object *object, int property_id, Etk_Property_Value *value);
static void _etk_filechooser_widget_property_get(Etk_Object *object, int property_id, Etk_Property_Value *value);
+static void _etk_filechooser_widget_favs_get(Etk_Filechooser_Widget *filechooser_widget);
static void _etk_filechooser_widget_dir_row_selected_cb(Etk_Object *object, Etk_Tree_Row *row, void *data);
+static void _etk_filechooser_widget_fav_row_selected_cb(Etk_Object *object, Etk_Tree_Row *row, void *data);
static Etk_Filechooser_Widget_Icons _etk_file_chooser_icons[] =
{
@@ -198,6 +200,8 @@
ecore_list_destroy(files);
}
+
+
/**************************
*
* Etk specific functions
@@ -238,13 +242,8 @@
fcw->fav_col = etk_tree_col_new(ETK_TREE(fcw->fav_tree), "Favorites", etk_tree_model_icon_text_new(ETK_TREE(fcw->fav_tree), ETK_TREE_FROM_EDJE), 120);
etk_tree_build(ETK_TREE(fcw->fav_tree));
etk_widget_show(fcw->fav_tree);
-
- etk_tree_append(ETK_TREE(fcw->fav_tree), fcw->fav_col, ETK_DEFAULT_ICON_SET_FILE, "devices/drive-harddisk", "Root", NULL);
- etk_tree_append(ETK_TREE(fcw->fav_tree), fcw->fav_col, ETK_DEFAULT_ICON_SET_FILE, "mimetypes/x-directory-normal-home", "Home", NULL);
- etk_tree_append(ETK_TREE(fcw->fav_tree), fcw->fav_col, ETK_DEFAULT_ICON_SET_FILE, "mimetypes/x-directory-normal", "Musics", NULL);
- etk_tree_append(ETK_TREE(fcw->fav_tree), fcw->fav_col, ETK_DEFAULT_ICON_SET_FILE, "mimetypes/x-directory-normal", "Videos", NULL);
- etk_tree_append(ETK_TREE(fcw->fav_tree), fcw->fav_col, ETK_DEFAULT_ICON_SET_FILE, "mimetypes/x-directory-normal", "Images", NULL);
-
+ etk_signal_connect("row_selected", ETK_OBJECT(fcw->fav_tree), ETK_CALLBACK(_etk_filechooser_widget_fav_row_selected_cb), fcw);
+
fcw->files_tree = etk_tree_new();
etk_widget_visibility_locked_set(fcw->files_tree, TRUE);
etk_widget_size_request_set(fcw->files_tree, 400, 120);
@@ -255,6 +254,8 @@
etk_tree_build(ETK_TREE(fcw->files_tree));
etk_widget_show(fcw->files_tree);
+
+ _etk_filechooser_widget_favs_get(ETK_FILECHOOSER_WIDGET(fcw));
fcw->current_folder = NULL;
/* Go to home */
@@ -305,6 +306,38 @@
}
}
+/* Get favorites from file in ~/ETK_FILECHOOSER_FAVS */
+void _etk_filechooser_widget_favs_get(Etk_Filechooser_Widget *filechooser_widget)
+{
+ char *folder;
+ char file_path[PATH_MAX];
+ char fav[PATH_MAX];
+ char line[PATH_MAX];
+ FILE *f;
+
+ if (!filechooser_widget)
+ return;
+ if (!(folder = getenv("HOME")))
+ return;
+
+ sprintf(file_path,"%s/%s", folder, ETK_FILECHOOSER_FAVS);
+
+ f = fopen (file_path,"r");
+ if(!f)
+ return;
+
+ etk_tree_clear(ETK_TREE(filechooser_widget->fav_tree));
+
+ while(fgets(line, PATH_MAX, f) != NULL)
+ {
+ sscanf(line,"file://%s",fav);
+ etk_tree_append(ETK_TREE(filechooser_widget->fav_tree),
+ filechooser_widget->fav_col, ETK_DEFAULT_ICON_SET_FILE, "mimetypes/x-directory-normal", fav, NULL);
+ }
+ fclose (f);
+}
+
+
/**************************
*
* Callbacks and handlers
@@ -328,6 +361,19 @@
free(new_dir);
}
+static void _etk_filechooser_widget_fav_row_selected_cb(Etk_Object *object, Etk_Tree_Row *row, void *data)
+{
+ Etk_Filechooser_Widget *filechooser_widget;
+ char *selected_dir;
+
+ if (!(filechooser_widget = ETK_FILECHOOSER_WIDGET(data)))
+ return;
+ etk_tree_row_fields_get(row, filechooser_widget->fav_col, NULL, NULL, &selected_dir, NULL);
+
+ etk_filechooser_widget_current_folder_set(filechooser_widget, selected_dir);
+}
+
+
/**************************
*
* Private functions
--- etk_filechooser_widget.h.old 2005-12-02 22:57:55.000000000 +0100
+++ etk_filechooser_widget.h 2006-01-17 02:31:18.000000000 +0100
@@ -5,6 +5,8 @@
#include <Evas.h>
#include "etk_bin.h"
#include "etk_types.h"
+#include <limits.h>
+
/**
* @defgroup Etk_Filechooser_Widget Etk_Filechooser_Widget
@@ -46,6 +48,7 @@
void etk_filechooser_widget_current_folder_set(Etk_Filechooser_Widget *filechooser_widget, const char *folder);
+
/** @} */
#endif