Trim trailing white spaces on empty lines.
[geeqie.git] / src / view_dir_list.c
index 29ca17b..fa65a74 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Geeqie
  * (C) 2004 John Ellis
- * Copyright (C) 2008 The Geeqie Team
+ * Copyright (C) 2008 - 2012 The Geeqie Team
  *
  * Author: John Ellis
  *
  *-----------------------------------------------------------------------------
  */
 
-gint vdlist_find_row(ViewDir *vd, FileData *fd, GtkTreeIter *iter)
+gboolean vdlist_find_row(ViewDir *vd, FileData *fd, GtkTreeIter *iter)
 {
        GtkTreeModel *store;
-       gint valid;
-       gint row = 0;
+       gboolean valid;
 
        store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view));
        valid = gtk_tree_model_get_iter_first(store, iter);
@@ -49,13 +48,12 @@ gint vdlist_find_row(ViewDir *vd, FileData *fd, GtkTreeIter *iter)
                {
                FileData *fd_n;
                gtk_tree_model_get(GTK_TREE_MODEL(store), iter, DIR_COLUMN_POINTER, &fd_n, -1);
-               if (fd_n == fd) return row;
+               if (fd_n == fd) return TRUE;
 
                valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), iter);
-               row++;
                }
 
-       return -1;
+       return FALSE;
 }
 
 
@@ -98,7 +96,7 @@ static void vdlist_scroll_to_row(ViewDir *vd, FileData *fd, gfloat y_align)
 {
        GtkTreeIter iter;
 
-       if (GTK_WIDGET_REALIZED(vd->view) && vd_find_row(vd, fd, &iter) >= 0)
+       if (gtk_widget_get_realized(vd->view) && vd_find_row(vd, fd, &iter))
                {
                GtkTreeModel *store;
                GtkTreePath *tpath;
@@ -109,7 +107,7 @@ static void vdlist_scroll_to_row(ViewDir *vd, FileData *fd, gfloat y_align)
                gtk_tree_view_set_cursor(GTK_TREE_VIEW(vd->view), tpath, NULL, FALSE);
                gtk_tree_path_free(tpath);
 
-               if (!GTK_WIDGET_HAS_FOCUS(vd->view)) gtk_widget_grab_focus(vd->view);
+               if (!gtk_widget_has_focus(vd->view)) gtk_widget_grab_focus(vd->view);
                }
 }
 
@@ -119,18 +117,6 @@ static void vdlist_scroll_to_row(ViewDir *vd, FileData *fd, gfloat y_align)
  *-----------------------------------------------------------------------------
  */
 
-void vdlist_select_row(ViewDir *vd, FileData *fd)
-{
-       if (fd && vd->select_func)
-               {
-               gchar *path;
-
-               path = g_strdup(fd->path);
-               vd->select_func(vd, path, vd->select_data);
-               g_free(path);
-               }
-}
-
 const gchar *vdlist_row_get_path(ViewDir *vd, gint row)
 {
        FileData *fd;
@@ -142,28 +128,30 @@ const gchar *vdlist_row_get_path(ViewDir *vd, gint row)
        return NULL;
 }
 
-static gint vdlist_populate(ViewDir *vd, gboolean clear)
+static gboolean vdlist_populate(ViewDir *vd, gboolean clear)
 {
        GtkListStore *store;
        GList *work;
        GtkTreeIter iter;
-       gint valid;
+       gboolean valid;
        gchar *filepath;
        GList *old_list;
-       gint ret;
+       gboolean ret;
        FileData *fd;
+       SortType sort_type = SORT_NAME;
+       gboolean sort_ascend = TRUE;
 
        old_list = VDLIST(vd)->list;
 
        ret = filelist_read(vd->dir_fd, NULL, &VDLIST(vd)->list);
-       VDLIST(vd)->list = filelist_sort(VDLIST(vd)->list, SORT_NAME, TRUE);
+       VDLIST(vd)->list = filelist_sort(VDLIST(vd)->list, sort_type, sort_ascend);
 
        /* add . and .. */
 
        if (strcmp(vd->dir_fd->path, G_DIR_SEPARATOR_S) != 0)
                {
                filepath = g_build_filename(vd->dir_fd->path, "..", NULL);
-               fd = file_data_new_simple(filepath);
+               fd = file_data_new_dir(filepath);
                VDLIST(vd)->list = g_list_prepend(VDLIST(vd)->list, fd);
                g_free(filepath);
                }
@@ -171,7 +159,7 @@ static gint vdlist_populate(ViewDir *vd, gboolean clear)
        if (options->file_filter.show_dot_directory)
                {
                filepath = g_build_filename(vd->dir_fd->path, ".", NULL);
-               fd = file_data_new_simple(filepath);
+               fd = file_data_new_dir(filepath);
                VDLIST(vd)->list = g_list_prepend(VDLIST(vd)->list, fd);
                g_free(filepath);
        }
@@ -187,8 +175,9 @@ static gint vdlist_populate(ViewDir *vd, gboolean clear)
                gint match;
                GdkPixbuf *pixbuf;
                const gchar *date = "";
+               gboolean done = FALSE;
+
                fd = work->data;
-               gint done = FALSE;
 
                if (access_file(fd->path, R_OK | X_OK) && fd->name)
                        {
@@ -203,7 +192,7 @@ static gint vdlist_populate(ViewDir *vd, gboolean clear)
                        else
                                {
                                pixbuf = vd->pf->close;
-                               if (options->layout.show_directory_date)
+                               if (vd->layout && vd->layout->options.show_directory_date)
                                        date = text_from_time(fd->date);
                                }
                        }
@@ -228,11 +217,11 @@ static gint vdlist_populate(ViewDir *vd, gboolean clear)
                                        }
                                else
                                        {
-                                       match = filelist_sort_compare_filedata_full(fd, old_fd, SORT_NAME, TRUE); 
+                                       match = filelist_sort_compare_filedata_full(fd, old_fd, sort_type, sort_ascend);
 
                                        if (match == 0) g_warning("multiple fd for the same path");
                                        }
-                                       
+
                                }
                        else
                                {
@@ -288,7 +277,7 @@ static gint vdlist_populate(ViewDir *vd, gboolean clear)
 
                valid = gtk_list_store_remove(store, &iter);
                }
-               
+
 
        vd->click_fd = NULL;
        vd->drop_fd = NULL;
@@ -297,10 +286,10 @@ static gint vdlist_populate(ViewDir *vd, gboolean clear)
        return ret;
 }
 
-gint vdlist_set_fd(ViewDir *vd, FileData *dir_fd)
+gboolean vdlist_set_fd(ViewDir *vd, FileData *dir_fd)
 {
-       gint ret;
-       gchar *old_path = NULL;
+       gboolean ret;
+       gchar *old_path = NULL; /* Used to store directory for walking up */
 
        if (!dir_fd) return FALSE;
        if (vd->dir_fd == dir_fd) return TRUE;
@@ -312,7 +301,7 @@ gint vdlist_set_fd(ViewDir *vd, FileData *dir_fd)
                base = remove_level_from_path(vd->dir_fd->path);
                if (strcmp(base, dir_fd->path) == 0)
                        {
-                       old_path = g_strdup(vd->dir_fd->name);
+                       old_path = g_strdup(filename_from_path(vd->dir_fd->path));
                        }
                g_free(base);
                }
@@ -342,7 +331,7 @@ gint vdlist_set_fd(ViewDir *vd, FileData *dir_fd)
                return ret;
                }
 
-       if (GTK_WIDGET_REALIZED(vd->view))
+       if (gtk_widget_get_realized(vd->view))
                {
                gtk_tree_view_scroll_to_point(GTK_TREE_VIEW(vd->view), 0, 0);
                }
@@ -355,12 +344,12 @@ void vdlist_refresh(ViewDir *vd)
        vdlist_populate(vd, FALSE);
 }
 
-gint vdlist_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
+gboolean vdlist_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
 {
        ViewDir *vd = data;
        GtkTreePath *tpath;
 
-       if (event->keyval != GDK_Menu) return FALSE;
+       if (event->keyval != GDK_KEY_Menu) return FALSE;
 
        gtk_tree_view_get_cursor(GTK_TREE_VIEW(vd->view), &tpath, NULL);
        if (tpath)
@@ -388,7 +377,7 @@ gint vdlist_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
        return TRUE;
 }
 
-gint vdlist_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
+gboolean vdlist_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
 {
        ViewDir *vd = data;
        GtkTreePath *tpath;
@@ -438,9 +427,8 @@ ViewDir *vdlist_new(ViewDir *vd, FileData *dir_fd)
        GtkCellRenderer *renderer;
 
        vd->info = g_new0(ViewDirInfoList, 1);
-       vd->type = DIRVIEW_LIST;
 
-       VDLIST(vd)->list = NULL;
+       vd->type = DIRVIEW_LIST;
 
        store = gtk_list_store_new(5, G_TYPE_POINTER, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_STRING);
        vd->view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
@@ -474,3 +462,4 @@ ViewDir *vdlist_new(ViewDir *vd, FileData *dir_fd)
 
        return vd;
 }
+/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */