/*
* Geeqie
* (C) 2006 John Ellis
- * Copyright (C) 2008 The Geeqie Team
+ * Copyright (C) 2008 - 2012 The Geeqie Team
*
* Author: John Ellis
*
#include "editors.h"
#include "filedata.h"
#include "img-view.h"
-#include "info.h"
#include "layout.h"
#include "layout_image.h"
#include "misc.h"
ci->pixbuf = pixbuf;
}
-gint collection_info_load_thumb(CollectInfo *ci)
+gboolean collection_info_load_thumb(CollectInfo *ci)
{
if (!ci) return FALSE;
log_printf("collection_info_load_thumb not implemented!\n(because an instant thumb loader not implemented)");
return FALSE;
-#if 0
- if (create_thumbnail(ci->fd->path, &ci->pixmap, &ci->mask) < 0) return FALSE;
-
- if (ci->pixmap) gdk_pixmap_ref(ci->pixmap);
- if (ci->mask) gdk_bitmap_ref(ci->mask);
-
- return TRUE;
-#endif
}
void collection_list_free(GList *list)
const CollectInfo *cia = a;
const CollectInfo *cib = b;
- switch(collection_list_sort_method)
+ switch (collection_list_sort_method)
{
case SORT_NAME:
break;
return g_list_sort(list, collection_list_sort_cb);
}
+GList *collection_list_randomize(GList *list)
+{
+ guint random, length, i;
+ gpointer tmp;
+ GList *nlist, *olist;
+
+ length = g_list_length(list);
+ if (!length) return NULL;
+
+ srand((unsigned int)time(NULL)); // Initialize random generator (hasn't to be that much strong)
+
+ for (i = 0; i < length; i++)
+ {
+ random = (guint) (1.0 * length * rand()/(RAND_MAX + 1.0));
+ olist = g_list_nth(list, i);
+ nlist = g_list_nth(list, random);
+ tmp = olist->data;
+ olist->data = nlist->data;
+ nlist->data = tmp;
+ }
+
+ return list;
+}
+
GList *collection_list_add(GList *list, CollectInfo *ci, SortType method)
{
if (method != SORT_NONE)
return NULL;
}
-#if 0
-static GList *collection_list_find_link(GList *list, gchar *path)
-{
- GList *work = list;
-
- while (work)
- {
- CollectInfo *ci = work->data;
- if (strcmp(ci->fd->path, path) == 0) return work;
- work = work->next;
- }
-
- return NULL;
-}
-
-static gint collection_list_find_index(GList *list, gchar *path)
-{
- gint c = 0;
- GList *work = list;
-
- while (work)
- {
- CollectInfo *ci = work->data;
- if (strcmp(ci->fd->path, path) == 0) return c;
- work = work->next;
- c++;
- }
-
- return -1;
-}
-#endif
-
GList *collection_list_to_filelist(GList *list)
{
GList *filelist = NULL;
cd = g_new0(CollectionData, 1);
- collection_list = g_list_append(collection_list, cd);
-
cd->ref = 1; /* starts with a ref of 1 */
-
- cd->list = NULL;
cd->sort_method = SORT_NONE;
- cd->thumb_loader = NULL;
- cd->info_updated_func = NULL;
-
- cd->window_read = FALSE;
- cd->window_x = 0;
- cd->window_y = 0;
cd->window_w = COLLECT_DEF_WIDTH;
cd->window_h = COLLECT_DEF_HEIGHT;
-
- cd->changed = FALSE;
-
cd->existence = g_hash_table_new(NULL, NULL);
if (path)
}
else
{
- cd->path = NULL;
-
if (untitled_counter == 0)
{
cd->name = g_strdup(_("Untitled"));
file_data_register_notify_func(collection_notify_cb, cd, NOTIFY_PRIORITY_MEDIUM);
+
+ collection_list = g_list_append(collection_list, cd);
+
return cd;
}
collection_window_refresh(collection_window_find(cd));
}
+void collection_randomize(CollectionData *cd)
+{
+ if (!cd) return;
+
+ cd->list = collection_list_randomize(cd->list);
+ cd->sort_method = SORT_NONE;
+ if (cd->list) cd->changed = TRUE;
+
+ collection_window_refresh(collection_window_find(cd));
+}
+
void collection_set_update_info_func(CollectionData *cd,
void (*func)(CollectionData *, CollectInfo *, gpointer), gpointer data)
{
return ci;
}
-gint collection_add_check(CollectionData *cd, FileData *fd, gint sorted, gint must_exist)
+gboolean collection_add_check(CollectionData *cd, FileData *fd, gboolean sorted, gboolean must_exist)
{
struct stat st;
- gint valid;
+ gboolean valid;
if (must_exist)
{
return valid;
}
-gint collection_add(CollectionData *cd, FileData *fd, gint sorted)
+gboolean collection_add(CollectionData *cd, FileData *fd, gboolean sorted)
{
return collection_add_check(cd, fd, sorted, TRUE);
}
-gint collection_insert(CollectionData *cd, FileData *fd, CollectInfo *insert_ci, gint sorted)
+gboolean collection_insert(CollectionData *cd, FileData *fd, CollectInfo *insert_ci, gboolean sorted)
{
struct stat st;
return FALSE;
}
-gint collection_remove(CollectionData *cd, FileData *fd)
+gboolean collection_remove(CollectionData *cd, FileData *fd)
{
CollectInfo *ci;
collection_window_refresh(collection_window_find(cd));
}
-gint collection_rename(CollectionData *cd, FileData *fd)
+gboolean collection_rename(CollectionData *cd, FileData *fd)
{
CollectInfo *ci;
ci = collection_list_find_fd(cd->list, fd);
{
CollectionData *cd = data;
- if (type != NOTIFY_TYPE_CHANGE || !fd->change) return;
+ if (!(type & NOTIFY_CHANGE) || !fd->change) return;
+
+ DEBUG_1("Notify collection: %s %04x", fd->path, type);
- switch(fd->change->type)
+ switch (fd->change->type)
{
case FILEDATA_CHANGE_MOVE:
case FILEDATA_CHANGE_RENAME:
*-------------------------------------------------------------------
*/
-static gint collection_window_keypress(GtkWidget *widget, GdkEventKey *event, gpointer data)
+static gboolean collection_window_keypress(GtkWidget *widget, GdkEventKey *event, gpointer data)
{
CollectWindow *cw = data;
- gint stop_signal = FALSE;
- gint edit_val = -1;
+ gboolean stop_signal = FALSE;
GList *list;
if (event->state & GDK_CONTROL_MASK)
switch (event->keyval)
{
case '1':
- edit_val = 0;
- break;
case '2':
- edit_val = 1;
- break;
case '3':
- edit_val = 2;
- break;
case '4':
- edit_val = 3;
- break;
case '5':
- edit_val = 4;
- break;
case '6':
- edit_val = 5;
- break;
case '7':
- edit_val = 6;
- break;
case '8':
- edit_val = 7;
- break;
case '9':
- edit_val = 8;
- break;
case '0':
- edit_val = 9;
break;
case 'A': case 'a':
if (event->state & GDK_SHIFT_MASK)
case 'D': case 'd':
file_util_delete(NULL, collection_table_selection_get_list(cw->table), cw->window);
break;
- case 'P': case 'p':
- info_window_new(NULL, collection_table_selection_get_list(cw->table), NULL);
- break;
case 'S': case 's':
collection_dialog_save_as(NULL, cw->cd);
break;
stop_signal = TRUE;
switch (event->keyval)
{
- case GDK_Return: case GDK_KP_Enter:
+ case GDK_KEY_Return: case GDK_KEY_KP_Enter:
layout_image_set_collection(NULL, cw->cd,
collection_table_get_focus_info(cw->table));
break;
collection_set_sort_method(cw->cd, SORT_PATH);
}
break;
- case GDK_Delete: case GDK_KP_Delete:
+ case GDK_KEY_Delete: case GDK_KEY_KP_Delete:
list = g_list_copy(cw->table->selection);
if (list)
{
break;
}
}
-
- if (edit_val != -1)
- {
- list = collection_table_selection_get_list(cw->table);
- file_util_start_editor_from_filelist(edit_val, list, cw->window);
- filelist_free(list);
- }
-
return stop_signal;
}
static void collection_window_get_geometry(CollectWindow *cw)
{
CollectionData *cd;
+ GdkWindow *window;
if (!cw) return;
cd = cw->cd;
- gdk_window_get_position(cw->window->window, &cd->window_x, &cd->window_y);
- gdk_drawable_get_size(cw->window->window, &cd->window_w, &cd->window_h);
+ window = gtk_widget_get_window(cw->window);
+ gdk_window_get_position(window, &cd->window_x, &cd->window_y);
+ cd->window_w = gdk_window_get_width(window);
+ cd->window_h = gdk_window_get_height(window);
cd->window_read = TRUE;
}
if (!cw) return;
}
-#if 0
-static void collection_window_move(CollectWindow *cw, CollectInfo *ci)
-{
- if (!cw) return;
-}
-#endif
-
static void collection_window_remove(CollectWindow *cw, CollectInfo *ci)
{
if (!cw) return;
if (cw) collection_window_close_final(cw);
}
-gint collection_window_modified_exists(void)
+gboolean collection_window_modified_exists(void)
{
GList *work;
return FALSE;
}
-static gint collection_window_delete(GtkWidget *widget, GdkEvent *event, gpointer data)
+static gboolean collection_window_delete(GtkWidget *widget, GdkEvent *event, gpointer data)
{
CollectWindow *cw = data;
collection_window_close(cw);
cw = g_new0(CollectWindow, 1);
- cw->close_dialog = NULL;
-
collection_window_list = g_list_append(collection_window_list, cw);
cw->cd = collection_new(path);
GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE);
- if (options->layout.save_window_positions && path && collection_load_only_geometry(cw->cd, path))
+ if (options->save_window_positions && path && collection_load_only_geometry(cw->cd, path))
{
/* FIXME: x, y is not implemented */
gtk_window_set_default_size(GTK_WINDOW(cw->window), cw->cd->window_w, cw->cd->window_h);