Fix up the custom filelist. DND in the main window still doesn't work

This commit is contained in:
Jaime Thomas 2008-06-20 20:08:45 +00:00
parent cbb925d4cb
commit 95537031b9
5 changed files with 306 additions and 52 deletions

View File

@ -25,6 +25,9 @@
if (dat) { free(dat); dat = NULL; } \ if (dat) { free(dat); dat = NULL; } \
} }
#undef __UNUSED__
#define __UNUSED__ __attribute__ ((unused))
/* ECDB Global Variables */ /* ECDB Global Variables */
typedef struct _Ecdb_Main Ecdb_Main; typedef struct _Ecdb_Main Ecdb_Main;
struct _Ecdb_Main struct _Ecdb_Main

View File

@ -1,9 +1,44 @@
#include "ecdb.h" #include "ecdb.h"
static void free_file(Ewl_Filelist_File *file); static void free_file(Ewl_Filelist_File *file);
void ecdb_custom_filelist_model_filter(Ewl_Filelist_Directory *dir);
unsigned int ecdb_custom_filelist_model_data_unref(void *data);
void *ecdb_custom_filelist_model_data_fetch(void *data, unsigned int row,
unsigned int column);
Ewl_Filelist_Directory *ecdb_custom_filelist_directory_new(Ecdb_Source *src);
void ecdb_custom_filelist_dnd_dropped_cb(Ewl_Widget *w, void *ev, void *data);
static void ecdb_custom_filelist_cb_clicked(Ewl_Widget *w, void *ev,
void *data);
char *ecdb_custom_filelist_selected_file_get(Ewl_Filelist *fl);
Ewl_Widget *ecdb_custom_filelist_view_widget_fetch(void *data, unsigned int row, unsigned int column);
Ewl_Widget *
ecdb_custom_filelist_new(void)
{
const char *dnd_types[] = {"text/uri-list", NULL};
Ewl_Widget *ret;
ret = ewl_filelist_new();
ewl_model_data_unref_set(EWL_FILELIST(ret)->model,
ecdb_custom_filelist_model_data_unref);
ewl_model_data_fetch_set(EWL_FILELIST(ret)->model,
ecdb_custom_filelist_model_data_fetch);
ewl_view_widget_fetch_set(EWL_FILELIST(ret)->view,
ecdb_custom_filelist_view_widget_fetch);
ewl_callback_append(ret, EWL_CALLBACK_DND_DATA_RECEIVED,
ecdb_custom_filelist_dnd_dropped_cb, NULL);
ewl_dnd_accepted_types_set(ret, dnd_types);
ewl_callback_del_type(EWL_FILELIST(ret)->controller,
EWL_CALLBACK_CLICKED);
ewl_callback_prepend(EWL_FILELIST(ret)->controller,
EWL_CALLBACK_CLICKED, ecdb_custom_filelist_cb_clicked,
ret);
return ret;
}
void void
ecdb_filelist_dnd_dropped_cb(Ewl_Widget *w, void *ev, void *data) ecdb_custom_filelist_dnd_dropped_cb(Ewl_Widget *w, void *ev,
void *data__UNUSED__)
{ {
int i; int i;
Ewl_Event_Dnd_Data_Received *dnd = ev; Ewl_Event_Dnd_Data_Received *dnd = ev;
@ -14,27 +49,22 @@ ecdb_filelist_dnd_dropped_cb(Ewl_Widget *w, void *ev, void *data)
* and add them as children to parent */ * and add them as children to parent */
parent = ewl_widget_data_get(w, "source"); parent = ewl_widget_data_get(w, "source");
/* Only handle uris for now */
if (strcmp(dnd->type, "text/uri-list"))
return;
for (i = 0; i < dnd->len; i++) for (i = 0; i < dnd->len; i++)
{ {
printf("file: %s\n", files[i]);
/* Cheap and dirty hax */ /* Cheap and dirty hax */
/* XXX FIXME XXX */ /* XXX FIXME XXX */
path = strdup(&files[i][7]); path = strdup(&files[i][7]);
child = ecdb_source_new(); child = ecdb_source_new();
ecdb_source_data_set(child, path); ecdb_source_data_set(child, path);
ecdb_source_child_append(parent, child); ecdb_source_child_append(parent, child);
free(path);
} }
ecdb_filelist_directory_set(EWL_FILELIST(w), parent); ecdb_custom_filelist_directory_set(EWL_FILELIST(w), parent);
} }
void void
ecdb_filelist_directory_set(Ewl_Filelist *fl, Ecdb_Source *src) ecdb_custom_filelist_directory_set(Ewl_Filelist *fl, Ecdb_Source *src)
{ {
if (src) if (src)
{ {
@ -42,9 +72,9 @@ ecdb_filelist_directory_set(Ewl_Filelist *fl, Ecdb_Source *src)
Ewl_Event_Action_Response ev_data; Ewl_Event_Action_Response ev_data;
data = ewl_mvc_data_get(EWL_MVC(fl->controller)); data = ewl_mvc_data_get(EWL_MVC(fl->controller));
if (data) ewl_filelist_model_data_unref(data); if (data) ecdb_custom_filelist_model_data_unref(data);
data = ecdb_filelist_directory_new(src); data = ecdb_custom_filelist_directory_new(src);
ewl_mvc_data_set(EWL_MVC(fl->controller), data); ewl_mvc_data_set(EWL_MVC(fl->controller), data);
ewl_mvc_dirty_set(EWL_MVC(fl->controller), TRUE); ewl_mvc_dirty_set(EWL_MVC(fl->controller), TRUE);
ev_data.response = EWL_FILELIST_EVENT_DIR_CHANGE; ev_data.response = EWL_FILELIST_EVENT_DIR_CHANGE;
@ -57,7 +87,7 @@ ecdb_filelist_directory_set(Ewl_Filelist *fl, Ecdb_Source *src)
} }
Ewl_Filelist_Directory * Ewl_Filelist_Directory *
ecdb_filelist_directory_new(Ecdb_Source *parent) ecdb_custom_filelist_directory_new(Ecdb_Source *parent)
{ {
Ecdb_Source *src; Ecdb_Source *src;
Ewl_Filelist_Directory *dir; Ewl_Filelist_Directory *dir;
@ -81,12 +111,11 @@ ecdb_filelist_directory_new(Ecdb_Source *parent)
{ {
if (!ecore_file_exists(src->dst)) if (!ecore_file_exists(src->dst))
{ {
printf("File doesn't exist!\n"); printf("File doesn't exist: %s\n", src->dst);
break; break;
} }
file = calloc(1, sizeof(Ewl_Filelist_File)); file = calloc(1, sizeof(Ewl_Filelist_File));
file->name = ecore_string_instance(ecore_file_file_get file->name = ecore_string_instance(src->dst);
(src->dst));
stat(src->dst, &st); stat(src->dst, &st);
file->size = st.st_size; file->size = st.st_size;
@ -116,20 +145,15 @@ ecdb_filelist_directory_new(Ecdb_Source *parent)
dir = calloc(1, sizeof(Ewl_Filelist_Directory)); dir = calloc(1, sizeof(Ewl_Filelist_Directory));
dir->rfiles = ecore_list_new(); dir->files = ecore_list_new();
dir->rdirs = ecore_list_new(); dir->dirs = ecore_list_new();
dir->rfiles = files;
/* Also dirty hax, need filtering instead of this */ dir->rdirs = dirs;
//dir->files = ecore_list_new();
//dir->dirs = ecore_list_new();
dir->name = ecore_string_instance("bunny");
dir->files = files;
dir->dirs = dirs;
dir->filter = NULL;
dir->num_dirs = nd; dir->num_dirs = nd;
dir->num_files = nf; dir->num_files = nf;
ecdb_custom_filelist_model_filter(dir);
return dir; return dir;
} }
@ -138,3 +162,213 @@ static void free_file(Ewl_Filelist_File *file)
ecore_string_release(file->name); ecore_string_release(file->name);
FREE(file); FREE(file);
} }
void
ecdb_custom_filelist_model_filter(Ewl_Filelist_Directory *dir)
{
Ewl_Filelist_File *file;
int nd, nf;
ecore_list_clear(dir->files);
ecore_list_clear(dir->dirs);
nd = nf = 0;
if (!dir->show_dot)
{
ecore_list_first_goto(dir->rfiles);
while ((file = ecore_list_next(dir->rfiles)))
{
if (ecore_file_file_get(file->name)[0] != '.')
{
ecore_list_append(dir->files, file);
nf++;
}
}
ecore_list_first_goto(dir->rdirs);
while ((file = ecore_list_next(dir->rdirs)))
{
if (ecore_file_file_get(file->name)[0] != '.')
{
ecore_list_append(dir->dirs, file);
nd++;
}
}
}
else
{
ecore_list_first_goto(dir->rfiles);
while ((file = ecore_list_next(dir->rfiles)))
{
ecore_list_append(dir->files, file);
nf++;
}
ecore_list_first_goto(dir->rdirs);
while ((file = ecore_list_next(dir->rdirs)))
{
ecore_list_append(dir->dirs, file);
nd++;
}
}
dir->num_dirs = nd;
dir->num_files = nf;
}
unsigned int
ecdb_custom_filelist_model_data_unref(void *data)
{
Ewl_Filelist_Directory *dir;
dir = data;
ecore_list_destroy(dir->files);
ecore_list_destroy(dir->dirs);
ecore_list_destroy(dir->rfiles);
ecore_list_destroy(dir->rdirs);
FREE(dir);
return TRUE;
}
void *
ecdb_custom_filelist_model_data_fetch(void *data, unsigned int row,
unsigned int column)
{
Ewl_Filelist_Directory *fld;
Ewl_Filelist_File *file;
int i;
void *ret;
fld = data;
/* Check if in dirs or files list */
if (row < fld->num_dirs)
file = ecore_list_index_goto(fld->dirs, row);
else
{
i = (row - fld->num_dirs);
file = ecore_list_index_goto(fld->files, i);
}
if (column == 1) ret = ewl_filelist_size_get(file->size);
else if (column == 2) ret = ewl_filelist_perms_get(file->mode);
else if (column == 3) ret = ewl_filelist_username_get
(file->username);
else if (column == 4) ret = ewl_filelist_groupname_get
(file->groupname);
else if (column == 5) ret = ewl_filelist_modtime_get
(file->modtime);
else ret = strdup(file->name);
/* ret needs to be freed by the view or with model_data_free_set */
return ret;
}
static void ecdb_custom_filelist_cb_clicked(Ewl_Widget *w, void *ev,
void *data)
{
Ewl_Event_Mouse_Down *md;
char *file;
int i = 0;
Ewl_Widget *c;
Ewl_Filelist *fl;
Ecdb_Source *parent, *child;
md = ev;
fl = data;
if (!ewl_mvc_selected_count_get(EWL_MVC(fl->controller)))
return;
if (md->clicks != 2)
{
ewl_filelist_selected_files_change_notify(fl);
return;
}
c = ewl_container_child_at_recursive_get(EWL_CONTAINER(fl),
md->base.x, md->base.y);
while (c && c->parent)
{
if (!ewl_widget_internal_is(c))
{
i = 1;
break;
}
c = c->parent;
}
if (!i)
return;
file = ecdb_custom_filelist_selected_file_get(fl);
parent = ewl_widget_data_get(EWL_WIDGET(fl), "source");
i = 0;
while ((child = parent->children[i]))
{
if ((child->dir) && (!strcmp(child->dst, file)))
{
printf("Setting directory\n");
ecdb_custom_filelist_directory_set(fl, child);
FREE(file);
return;
}
i++;
}
ewl_filelist_selected_files_change_notify(fl);
FREE(file);
}
char *
ecdb_custom_filelist_selected_file_get(Ewl_Filelist *fl)
{
Ewl_Filelist_Directory *data;
Ewl_Filelist_File *file;
Ewl_Selection_Idx *idx;
int i;
idx = ewl_mvc_selected_get(EWL_MVC(fl->controller));
data = EWL_SELECTION(idx)->data;
if (idx->row < data->num_dirs)
file = ecore_list_index_goto(data->dirs, idx->row);
else
{
i = (idx->row - data->num_dirs);
file = ecore_list_index_goto(data->files, i);
}
FREE(idx);
return strdup(file->name);
}
Ewl_Widget *
ecdb_custom_filelist_view_widget_fetch(void *data, unsigned int row __UNUSED__,
unsigned int column)
{
Ewl_Widget *ret;
const char *img = NULL, *stock, *filename;
/* Create icon */
ret = ewl_icon_simple_new();
ewl_icon_constrain_set(EWL_ICON(ret), EWL_ICON_SIZE_MEDIUM);
ewl_box_orientation_set(EWL_BOX(ret),
EWL_ORIENTATION_HORIZONTAL);
ewl_object_alignment_set(EWL_OBJECT(ret), EWL_FLAG_ALIGN_LEFT);
/* Get and set data into icon */
if (column == 0)
{
stock = ewl_filelist_stock_icon_get(data);
img = ewl_icon_theme_icon_path_get(stock, EWL_ICON_SIZE_MEDIUM);
if (img) ewl_icon_image_set(EWL_ICON(ret), img, NULL);
filename = ecore_file_file_get(data);
ewl_icon_label_set(EWL_ICON(ret), filename);
}
else
ewl_icon_label_set(EWL_ICON(ret), data);
FREE(data);
return ret;
}

View File

@ -1,11 +1,8 @@
#ifndef ECDB_FILELIST_CUSTOM_H #ifndef ECDB_FILELIST_CUSTOM_H
#define ECDB_FILELIST_CUSTOM_H #define ECDB_FILELIST_CUSTOM_H
void ecdb_filelist_directory_set(Ewl_Filelist *fl, void ecdb_custom_filelist_directory_set(Ewl_Filelist *fl,
Ecdb_Source *src); Ecdb_Source *src);
Ewl_Filelist_Directory *ecdb_filelist_directory_new(Ecdb_Source *src); Ewl_Widget *ecdb_custom_filelist_new(void);
void ecdb_filelist_dnd_dropped_cb(Ewl_Widget *w,
void *ev, void *data);
#endif #endif

View File

@ -6,19 +6,20 @@ static void _data_disc_cb(Ewl_Widget *w, void *ev, void *data);
static void _burn_image_cb(Ewl_Widget *w, void *ev, void *data); static void _burn_image_cb(Ewl_Widget *w, void *ev, void *data);
static void _copy_disc_cb(Ewl_Widget *w, void *ev, void *data); static void _copy_disc_cb(Ewl_Widget *w, void *ev, void *data);
static void _audio_disc_cb(Ewl_Widget *w, void *ev, void *data); static void _audio_disc_cb(Ewl_Widget *w, void *ev, void *data);
static void _hidden_files_cb(Ewl_Widget *w, void *ev, void *data);
static Ewl_Widget *_page_start(void); static Ewl_Widget *_page_start(void);
static Ewl_Widget *_page_data(void); static Ewl_Widget *_page_data(void);
static void static void
_destroy_cb(Ewl_Widget *w, void *ev, void *data) _destroy_cb(Ewl_Widget *w, void *ev __UNUSED__, void *data __UNUSED__)
{ {
ewl_widget_destroy(w); ewl_widget_destroy(w);
ecore_event_add(ECORE_EVENT_SIGNAL_EXIT, NULL, NULL, NULL); ecore_event_add(ECORE_EVENT_SIGNAL_EXIT, NULL, NULL, NULL);
} }
static void static void
_destroy_data_page_cb(Ewl_Widget *w, void *ev, void *data) _destroy_data_page_cb(Ewl_Widget *w __UNUSED__, void *ev __UNUSED__, void *data)
{ {
Ecdb_Burn_Project *proj = data; Ecdb_Burn_Project *proj = data;
printf("Destroy burn project data\n"); printf("Destroy burn project data\n");
@ -44,6 +45,7 @@ void
ecdb_create_main_gui(void) ecdb_create_main_gui(void)
{ {
Ewl_Widget *main_win, *vbox, *filelist, *note, *fn; Ewl_Widget *main_win, *vbox, *filelist, *note, *fn;
Ewl_Widget *cm, *menu;
main_win = ewl_window_new(); main_win = ewl_window_new();
ewl_window_name_set(EWL_WINDOW(main_win), "ECDB"); ewl_window_name_set(EWL_WINDOW(main_win), "ECDB");
@ -67,6 +69,16 @@ ecdb_create_main_gui(void)
ewl_object_maximum_h_set(EWL_OBJECT(filelist), 300); ewl_object_maximum_h_set(EWL_OBJECT(filelist), 300);
ewl_widget_show(filelist); ewl_widget_show(filelist);
cm = ewl_context_menu_new();
ewl_context_menu_attach(EWL_CONTEXT_MENU(cm), filelist);
menu = ewl_menu_item_new();
ewl_button_label_set(EWL_BUTTON(menu), "Show/Hide Hidden Files");
ewl_container_child_append(EWL_CONTAINER(cm), menu);
ewl_callback_append(menu, EWL_CALLBACK_CLICKED, _hidden_files_cb,
filelist);
ewl_widget_show(menu);
note = ewl_notebook_new(); note = ewl_notebook_new();
ewl_object_fill_policy_set(EWL_OBJECT(note), EWL_FLAG_FILL_ALL); ewl_object_fill_policy_set(EWL_OBJECT(note), EWL_FLAG_FILL_ALL);
ewl_container_child_append(EWL_CONTAINER(vbox), note); ewl_container_child_append(EWL_CONTAINER(vbox), note);
@ -89,27 +101,23 @@ static Ewl_Widget
char *bdr_titles[] = {"Create Data Disc", char *bdr_titles[] = {"Create Data Disc",
"Burn Image", "Burn Image",
"Copy Disc", "Copy Disc",
"Create Audio Disc", "Create Audio Disc"};
NULL};
char *but_titles[] = {"Data Disc", char *but_titles[] = {"Data Disc",
"Image", "Image",
"Copy", "Copy",
"Audio Disc", "Audio Disc"};
NULL};
char *images[] = {EWL_ICON_DRIVE_CDROM, char *images[] = {EWL_ICON_DRIVE_CDROM,
EWL_ICON_MEDIA_CDROM, EWL_ICON_MEDIA_CDROM,
EWL_ICON_DRIVE_HARDDISK, EWL_ICON_DRIVE_HARDDISK,
EWL_ICON_AUDIO_X_GENERIC, EWL_ICON_AUDIO_X_GENERIC};
NULL};
static void (*funs[]) (Ewl_Widget *w, void *ev, void *data) = static void (*funs[]) (Ewl_Widget *w, void *ev, void *data) =
{_data_disc_cb, {_data_disc_cb,
_burn_image_cb, _burn_image_cb,
_copy_disc_cb, _copy_disc_cb,
_audio_disc_cb, _audio_disc_cb};
NULL};
box = ewl_hbox_new(); box = ewl_hbox_new();
ewl_object_fill_policy_set(EWL_OBJECT(box), EWL_FLAG_FILL_NONE); ewl_object_fill_policy_set(EWL_OBJECT(box), EWL_FLAG_FILL_NONE);
@ -142,7 +150,6 @@ static Ewl_Widget
{ {
Ewl_Widget *box, *filelist; Ewl_Widget *box, *filelist;
Ecdb_Burn_Project *proj; Ecdb_Burn_Project *proj;
const char *dnd_types[] = {"text/uri-list", NULL};
proj = ecdb_burn_project_new(); proj = ecdb_burn_project_new();
@ -152,11 +159,8 @@ static Ewl_Widget
_destroy_data_page_cb, proj); _destroy_data_page_cb, proj);
ewl_widget_show(box); ewl_widget_show(box);
filelist = ewl_filelist_new(); filelist = ecdb_custom_filelist_new();
ewl_filelist_multiselect_set(EWL_FILELIST(filelist), TRUE); ewl_filelist_multiselect_set(EWL_FILELIST(filelist), TRUE);
ewl_dnd_accepted_types_set(filelist, dnd_types);
ewl_callback_append(filelist, EWL_CALLBACK_DND_DATA_RECEIVED,
ecdb_filelist_dnd_dropped_cb, NULL);
ewl_container_child_append(EWL_CONTAINER(box), filelist); ewl_container_child_append(EWL_CONTAINER(box), filelist);
ewl_widget_data_set(filelist, "source", proj->files); ewl_widget_data_set(filelist, "source", proj->files);
ewl_widget_show(filelist); ewl_widget_show(filelist);
@ -165,27 +169,40 @@ static Ewl_Widget
} }
static void static void
_data_disc_cb(Ewl_Widget *w, void *ev, void *data) _data_disc_cb(Ewl_Widget *w __UNUSED__, void *ev __UNUSED__,
void *data __UNUSED__)
{ {
printf("Create Data Disc\n"); printf("Create Data Disc\n");
ecdb_create_data_tab(); ecdb_create_data_tab();
} }
static void static void
_burn_image_cb(Ewl_Widget *w, void *ev, void *data) _burn_image_cb(Ewl_Widget *w __UNUSED__, void *ev __UNUSED__,
void *data __UNUSED__)
{ {
printf("Burn Image to Disc\n"); printf("Burn Image to Disc\n");
} }
static void static void
_copy_disc_cb(Ewl_Widget *w, void *ev, void *data) _copy_disc_cb(Ewl_Widget *w __UNUSED__, void *ev __UNUSED__,
void *data __UNUSED__)
{ {
printf("Copy Disc\n"); printf("Copy Disc\n");
} }
static void static void
_audio_disc_cb(Ewl_Widget *w, void *ev, void *data) _audio_disc_cb(Ewl_Widget *w __UNUSED__, void *ev __UNUSED__,
void *data __UNUSED__)
{ {
printf("Create Audio Disc\n"); printf("Create Audio Disc\n");
} }
static void
_hidden_files_cb(Ewl_Widget *w __UNUSED__, void *ev __UNUSED__, void *data)
{
Ewl_Filelist *filelist = data;
unsigned int hf;
hf = ewl_filelist_show_dot_files_get(filelist);
ewl_filelist_show_dot_files_set(filelist, !hf);
}

View File

@ -63,7 +63,7 @@ ecdb_source_data_set(Ecdb_Source *src, const char *dst)
/* Add the files recursively here */ /* Add the files recursively here */
if (ecore_file_is_dir(src->dst)) if (ecore_file_is_dir(src->dst))
{ {
src->dir = TRUE; src->dir = !!TRUE;
ecdb_source_add_directory_recursive(src); ecdb_source_add_directory_recursive(src);
} }
} }
@ -73,6 +73,7 @@ ecdb_source_add_directory_recursive(Ecdb_Source *parent)
{ {
Ecore_List *files; Ecore_List *files;
Ecdb_Source *child; Ecdb_Source *child;
char path[PATH_MAX];
char *src; char *src;
files = ecore_file_ls(parent->dst); files = ecore_file_ls(parent->dst);
@ -80,10 +81,12 @@ ecdb_source_add_directory_recursive(Ecdb_Source *parent)
while ((src = ecore_list_first_remove(files))) while ((src = ecore_list_first_remove(files)))
{ {
child = ecdb_source_new(); child = ecdb_source_new();
ecdb_source_data_set(child, src); snprintf(path, PATH_MAX, "%s/%s", parent->dst, src);
ecdb_source_data_set(child, path);
ecdb_source_child_append(parent, child); ecdb_source_child_append(parent, child);
free(src); free(src);
} }
ecore_list_destroy(files);
} }
void void