Commit 38e733fe authored by John Sullivan's avatar John Sullivan

Lots more work pushing code from FMDirectoryView into subclasses. Almost

done now!
parent fa043157
2000-01-13 John Sullivan <sullivan@eazel.com>
More work pushing code from FMDirectoryView into subclasses.
Almost done now.
* src/file-manager/fm-directory-view.h:
Removed enum _FMDirectoryViewMode and its typedef.
Removed field entries_to_display.
Removed transition section holding function prototypes that
were on their way into subclasses.
(fm_directory_view_is_valid_mode): Removed.
(fm_directory_view_get_mode): Removed.
(fm_directory_view_set_mode): Removed.
(fm_directory_view_begin_adding_entries): New function & signal.
(fm_directory_view_add_entry): New function & signal.
(fm_directory_view_done_adding_entries): New function & signal.
(fm_directory_view_done_sorting_entries): New function & signal.
(fm_directory_view_begin_loading): New function & signal.
(fm_directory_view_display_selection_info): Newly exposed function.
*src/file-manager/fm-directory-view.c:
Removed some now-unnecessary #includes.
Added constants for new signals to enum.
Removed global variable for icon cache in favor of already-extant
fm_get_current_icon_cache().
Removed all references to entries_to_display.
(display_selection_info): Renamed to
fm_directory_view_display_selection_info now that it's public.
(view_has_icon_container): Removed.
(get_icon_container): Moved into subclass FMDirectoryViewIcons.
(add_to_icon_container): Moved into subclass FMDirectoryViewIcons.
(load_icon_container): Moved into subclass FMDirectoryViewIcons.
(display_icons_not_in_layout): Moved into subclass FMDirectoryViewIcons.
(setup_base_uri): Moved into subclass FMDirectoryViewIcons (and renamed
to set_up_base_uri).
(view_has_flist): Removed.
(get_flist): Moved into subclass FMDirectoryViewList.
(add_to_flist): Moved into subclass FMDirectoryViewList.
(class_init): Signal initialization code for begin_adding_entries,
add_entry, done_adding_entries, done_sorting_entries, and begin_loading.
(init): Removed mode-setting line.
(display_pending_entries): Replaced the bulk of this function with three
new signals: begin_adding_entries, add_entry, done_adding_entries. The
loop structure and GnomeVFSFileInfo retrieving part remains.
(directory_load_cb): Deployed new signal begin_loading where setup_base_uri
used to be.
(fm_directory_view_is_valid_mode): Removed.
(fm_directory_view_get_mode): Removed.
(fm_directory_view_set_mode): Removed.
(fm_directory_view_begin_adding_entries): New function, emits signal.
(fm_directory_view_add_entry): New function, emits signal.
(fm_directory_view_done_adding_entries): New function, emits signal.
(fm_directory_view_done_sorting_entries): New function, emits signal.
(fm_directory_view_begin_loading): New function, emits signal.
(fm_directory_view_sort): Replaced some icon-container-specific
code with fm_directory_view_done_sorting_entries().
*src/file-manager/fm-directory-view-icons.c:
(fm_directory_view_icons_initialize_class): Wired up signal handlers
for add_entry, done_adding_entries, done_sorting_entries, and begin_loading.
(fm_directory_view_icons_initialize): Removed set_mode call.
(display_icons_not_in_layout): Moved here from superclass FMDirectoryView.
(get_icon_container): Moved here from superclass FMDirectoryView.
(add_to_icon_container): Moved here from superclass FMDirectoryView.
(load_icon_container): Moved here from superclass FMDirectoryView.
(set_up_base_uri): Moved here from superclass FMDirectoryView.
(fm_directory_view_icons_add_entry): New signal handler function, code
taken and simplified from superclass FMDirectoryView.
(fm_directory_view_icons_done_adding_entries): New signal handler
function, code taken and simplified from superclass FMDirectoryView.
(fm_directory_view_icons_done_sorting_entries): New signal handler
function, code taken and simplified from superclass FMDirectoryView.
(fm_directory_view_icons_begin_loading): New signal handler function,
code taken and simplified from superclass FMDirectoryView.
*src/file-manager/fm-directory-view-list.c:
(fm_directory_view_list_initialize_class): Wired up signal handlers
for begin_adding_entries, add_entry, and done_adding_entries
(fm_directory_view_list_initialize): Removed set_mode call.
(get_flist): Moved here from superclass FMDirectoryView.
(add_to_flist): Moved here from superclass FMDirectoryView.
(fm_directory_view_list_begin_adding_entries): New signal handler
function, code taken and simplified from superclass FMDirectoryView.
(fm_directory_view_list_add_entry): New signal handler function, code
taken and simplified from superclass FMDirectoryView.
(fm_directory_view_list_done_adding_entries): New signal handler
function, code taken and simplified from superclass FMDirectoryView.
2000-01-13 John Sullivan <sullivan@eazel.com>
* libnautilus/nautilus-gtk-macros.h: Defined macros
......
......@@ -32,21 +32,41 @@
#include "fm-directory-view.h"
#include "fm-directory-view-icons.h"
#include "fm-icon-cache.h"
static FMDirectoryViewClass *parent_class = NULL;
/* forward declarations */
static GnomeIconContainer *create_icon_container (FMDirectoryViewIcons *view);
static gint display_icon_container_selection_info_idle_cb (gpointer data);
static void fm_directory_view_icons_clear (FMDirectoryView *view);
static void icon_container_activate_cb (GnomeIconContainer *icon_container,
const gchar *name,
gpointer icon_data,
gpointer data);
static void icon_container_selection_changed_cb (GnomeIconContainer *container,
gpointer data);
static gint display_icon_container_selection_info_idle_cb
(gpointer data);
static void display_icons_not_in_layout (FMDirectoryView *view);
static void fm_directory_view_icons_add_entry (FMDirectoryView *view,
GnomeVFSFileInfo *info);
static void fm_directory_view_icons_done_adding_entries
(FMDirectoryView *view);
static void fm_directory_view_icons_done_sorting_entries
(FMDirectoryView *view);
static void fm_directory_view_icons_begin_loading
(FMDirectoryView *view);
static void fm_directory_view_icons_clear (FMDirectoryView *view);
static void icon_container_activate_cb (GnomeIconContainer *icon_container,
const gchar *name,
gpointer icon_data,
gpointer data);
static void icon_container_selection_changed_cb (GnomeIconContainer *container,
gpointer data);
static GnomeIconContainer *get_icon_container (FMDirectoryView *view);
static void add_to_icon_container (FMDirectoryView *view,
FMIconCache *icon_manager,
GnomeIconContainer *icon_container,
GnomeVFSFileInfo *info,
gboolean with_layout);
static void load_icon_container (FMDirectoryView *view,
GnomeIconContainer *icon_container);
static void set_up_base_uri (FMDirectoryView *view);
/* GtkObject methods. */
......@@ -70,7 +90,17 @@ fm_directory_view_icons_initialize_class (gpointer klass)
parent_class = gtk_type_class (gtk_type_parent(object_class->type));
object_class->destroy = fm_directory_view_icons_destroy;
fm_directory_view_class->clear = fm_directory_view_icons_clear;
fm_directory_view_class->clear
= fm_directory_view_icons_clear;
fm_directory_view_class->add_entry
= fm_directory_view_icons_add_entry;
fm_directory_view_class->done_adding_entries
= fm_directory_view_icons_done_adding_entries;
fm_directory_view_class->done_sorting_entries
= fm_directory_view_icons_done_sorting_entries;
fm_directory_view_class->begin_loading
= fm_directory_view_icons_begin_loading;
}
static void
......@@ -79,12 +109,8 @@ fm_directory_view_icons_initialize (gpointer object, gpointer klass)
GnomeIconContainer *icon_container;
g_return_if_fail (FM_IS_DIRECTORY_VIEW_ICONS (object));
/* FIXME: eventually get rid of set_mode call entirely. */
fm_directory_view_set_mode (FM_DIRECTORY_VIEW (object),
FM_DIRECTORY_VIEW_MODE_ICONS);
g_assert (GTK_BIN (object)->child == NULL);
g_return_if_fail (GTK_BIN (object)->child == NULL);
icon_container = create_icon_container (object);
gnome_icon_container_set_icon_mode
(icon_container, GNOME_ICON_CONTAINER_NORMAL_ICONS);
......@@ -134,7 +160,7 @@ display_icon_container_selection_info_idle_cb (gpointer data)
icon_container = get_icon_container (view);
selection = gnome_icon_container_get_selection (icon_container);
display_selection_info (view, selection);
fm_directory_view_display_selection_info (view, selection);
g_list_free (selection);
view->display_selection_idle_id = 0;
......@@ -142,6 +168,124 @@ display_icon_container_selection_info_idle_cb (gpointer data)
return FALSE;
}
static void
display_icons_not_in_layout (FMDirectoryView *view)
{
FMIconCache *icon_manager;
GnomeIconContainer *icon_container;
GList *p;
if (view->icons_not_in_layout == NULL)
return;
icon_manager = fm_get_current_icon_cache();
icon_container = get_icon_container (view);
g_return_if_fail (icon_container != NULL);
/* FIXME: This will block if there are many files. */
for (p = view->icons_not_in_layout; p != NULL; p = p->next) {
GnomeVFSFileInfo *info;
info = p->data;
add_to_icon_container (view, icon_manager,
icon_container, info, FALSE);
}
g_list_free (view->icons_not_in_layout);
view->icons_not_in_layout = NULL;
}
static GnomeIconContainer *
get_icon_container (FMDirectoryView *view)
{
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW_ICONS (view), NULL);
g_return_val_if_fail (GNOME_IS_ICON_CONTAINER (GTK_BIN (view)->child), NULL);
return GNOME_ICON_CONTAINER (GTK_BIN (view)->child);
}
static void
add_to_icon_container (FMDirectoryView *view,
FMIconCache *icon_manager,
GnomeIconContainer *icon_container,
GnomeVFSFileInfo *info,
gboolean with_layout)
{
GdkPixbuf *image;
g_return_if_fail(info);
image = fm_icon_cache_get_icon (icon_manager, info);
if (! with_layout || view->icon_layout == NULL) {
gnome_icon_container_add_pixbuf_auto (icon_container,
image,
info->name,
info);
} else {
gboolean result;
result = gnome_icon_container_add_pixbuf_with_layout
(icon_container, image, info->name, info,
view->icon_layout);
if (! result)
view->icons_not_in_layout = g_list_prepend
(view->icons_not_in_layout, info);
}
}
static void
load_icon_container (FMDirectoryView *view,
GnomeIconContainer *icon_container)
{
gnome_icon_container_clear (icon_container);
if (view->directory_list != NULL) {
GnomeVFSDirectoryListPosition *position;
FMIconCache *icon_manager;
icon_manager = fm_get_current_icon_cache();
position = gnome_vfs_directory_list_get_first_position
(view->directory_list);
while (position != view->current_position) {
GnomeVFSFileInfo *info;
info = gnome_vfs_directory_list_get
(view->directory_list, position);
g_return_if_fail(info);
add_to_icon_container (view, icon_manager,
icon_container, info, TRUE);
position = gnome_vfs_directory_list_position_next
(position);
}
}
}
/* Set up the base URI for Drag & Drop operations. */
static void
set_up_base_uri (FMDirectoryView *view)
{
gchar *txt_uri;
g_return_if_fail (get_icon_container(view) != NULL);
txt_uri = gnome_vfs_uri_to_string (view->uri, 0);
if (txt_uri == NULL)
return;
gnome_icon_container_set_base_uri (get_icon_container (view), txt_uri);
g_free (txt_uri);
}
static void
fm_directory_view_icons_clear (FMDirectoryView *view)
{
......@@ -150,6 +294,47 @@ fm_directory_view_icons_clear (FMDirectoryView *view)
gnome_icon_container_clear (get_icon_container (view));
}
static void
fm_directory_view_icons_add_entry (FMDirectoryView *view, GnomeVFSFileInfo *info)
{
g_return_if_fail (FM_IS_DIRECTORY_VIEW_ICONS (view));
add_to_icon_container (view,
fm_get_current_icon_cache(),
get_icon_container (view),
info,
TRUE);
}
static void
fm_directory_view_icons_done_adding_entries (FMDirectoryView *view)
{
g_return_if_fail (FM_IS_DIRECTORY_VIEW_ICONS (view));
display_icons_not_in_layout (view);
}
static void
fm_directory_view_icons_done_sorting_entries (FMDirectoryView *view)
{
g_return_if_fail (FM_IS_DIRECTORY_VIEW_ICONS (view));
/* This will make sure icons are re-laid out according to the new
order. */
if (view->icon_layout != NULL)
view->icon_layout = NULL;
load_icon_container (view, get_icon_container (view));
}
static void
fm_directory_view_icons_begin_loading (FMDirectoryView *view)
{
g_return_if_fail (FM_IS_DIRECTORY_VIEW_ICONS (view));
set_up_base_uri (view);
}
/* WARNING WARNING WARNING
......
......@@ -40,11 +40,22 @@ static FMDirectoryViewClass *parent_class = NULL;
/* forward declarations */
static GtkFList *create_flist (FMDirectoryViewList *view);
static GtkFList *get_flist (FMDirectoryViewList *view);
void add_to_flist (FMIconCache *icon_manager,
GtkFList *flist,
GnomeVFSFileInfo *info);
static gint display_flist_selection_info_idle_cb (gpointer data);
static void flist_activate_cb (GtkFList *flist,
gpointer entry_data,
gpointer data);
static void flist_selection_changed_cb (GtkFList *flist, gpointer data);
static void fm_directory_view_list_begin_adding_entries
(FMDirectoryView *view);
static void fm_directory_view_list_add_entry
(FMDirectoryView *view,
GnomeVFSFileInfo *info);
static void fm_directory_view_list_done_adding_entries
(FMDirectoryView *view);
static void fm_directory_view_list_clear (FMDirectoryView *view);
......@@ -71,19 +82,19 @@ fm_directory_view_list_initialize_class (gpointer klass)
parent_class = gtk_type_class (gtk_type_parent(object_class->type));
object_class->destroy = fm_directory_view_list_destroy;
fm_directory_view_class->clear = fm_directory_view_list_clear;
fm_directory_view_class->begin_adding_entries = fm_directory_view_list_begin_adding_entries;
fm_directory_view_class->add_entry = fm_directory_view_list_add_entry;
fm_directory_view_class->done_adding_entries = fm_directory_view_list_done_adding_entries;
}
static void
fm_directory_view_list_initialize (gpointer object, gpointer klass)
{
g_return_if_fail (FM_IS_DIRECTORY_VIEW_LIST (object));
/* FIXME: eventually get rid of set_mode call entirely. */
fm_directory_view_set_mode (FM_DIRECTORY_VIEW (object),
FM_DIRECTORY_VIEW_MODE_DETAILED);
g_assert (GTK_BIN (object)->child == NULL);
g_return_if_fail (GTK_BIN (object)->child == NULL);
create_flist (object);
}
......@@ -158,11 +169,13 @@ display_flist_selection_info_idle_cb (gpointer data)
GtkFList *flist;
GList *selection;
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW_LIST (data), FALSE);
view = FM_DIRECTORY_VIEW (data);
flist = get_flist (view);
flist = get_flist (FM_DIRECTORY_VIEW_LIST (view));
selection = gtk_flist_get_selection (flist);
display_selection_info (view, selection);
fm_directory_view_display_selection_info (view, selection);
g_list_free (selection);
view->display_selection_idle_id = 0;
......@@ -206,11 +219,60 @@ flist_selection_changed_cb (GtkFList *flist,
view);
}
void
add_to_flist (FMIconCache *icon_manager,
GtkFList *flist,
GnomeVFSFileInfo *info)
{
GtkCList *clist;
gchar *text[2];
text[0] = info->name;
text[1] = NULL;
clist = GTK_CLIST (flist);
gtk_clist_append (clist, text);
gtk_clist_set_row_data (clist, clist->rows - 1, info);
}
static GtkFList *
get_flist (FMDirectoryViewList *view)
{
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW_LIST (view), NULL);
g_return_val_if_fail (GTK_IS_FLIST (GTK_BIN (view)->child), NULL);
return GTK_FLIST (GTK_BIN (view)->child);
}
static void
fm_directory_view_list_clear (FMDirectoryView *view)
{
g_return_if_fail (FM_IS_DIRECTORY_VIEW_LIST (view));
gtk_clist_clear(GTK_CLIST(get_flist(view)));
gtk_clist_clear (GTK_CLIST (get_flist (FM_DIRECTORY_VIEW_LIST (view))));
}
static void
fm_directory_view_list_begin_adding_entries (FMDirectoryView *view)
{
g_return_if_fail (FM_IS_DIRECTORY_VIEW_LIST (view));
gtk_clist_freeze (GTK_CLIST (get_flist (FM_DIRECTORY_VIEW_LIST (view))));
}
static void
fm_directory_view_list_add_entry (FMDirectoryView *view, GnomeVFSFileInfo *info)
{
g_return_if_fail (FM_IS_DIRECTORY_VIEW_LIST (view));
add_to_flist (fm_get_current_icon_cache(), get_flist (FM_DIRECTORY_VIEW_LIST (view)), info);
}
static void
fm_directory_view_list_done_adding_entries (FMDirectoryView *view)
{
g_return_if_fail (FM_IS_DIRECTORY_VIEW_LIST (view));
gtk_clist_thaw (GTK_CLIST (get_flist (FM_DIRECTORY_VIEW_LIST (view))));
}
......@@ -29,37 +29,33 @@
#include <gnome.h>
#include <libnautilus/libnautilus.h>
#include <libnautilus/gnome-icon-container.h>
#include <libnautilus/gtkflist.h>
#include <libnautilus/nautilus-gtk-macros.h>
#include "fm-directory-view.h"
#include "fm-icon-cache.h"
#include "fm-public-api.h"
#define FM_DEBUG(x) g_message x
#define WITH_LAYOUT TRUE
#define DISPLAY_TIMEOUT_INTERVAL 500
#define ENTRIES_PER_CB 1
enum
{
ADD_ENTRY,
BEGIN_ADDING_ENTRIES,
CLEAR,
DONE_ADDING_ENTRIES,
DONE_SORTING_ENTRIES,
BEGIN_LOADING,
LAST_SIGNAL
};
static guint fm_directory_view_signals[LAST_SIGNAL] = { 0 };
static GtkScrolledWindowClass *parent_class = NULL;
/* FIXME this no longer has any reason to be global,
given fm_get_current_icon_cache()
*/
static FMIconCache *icm = NULL;
void
display_selection_info (FMDirectoryView *view,
GList *selection)
fm_directory_view_display_selection_info (FMDirectoryView *view,
GList *selection)
{
GnomeVFSFileSize size;
guint count;
......@@ -127,132 +123,6 @@ display_selection_info (FMDirectoryView *view,
}
/* GnomeIconContainer handling. */
static gboolean
view_has_icon_container (FMDirectoryView *view)
{
return (view->mode == FM_DIRECTORY_VIEW_MODE_ICONS
|| view->mode == FM_DIRECTORY_VIEW_MODE_SMALLICONS);
}
GnomeIconContainer *
get_icon_container (FMDirectoryView *view)
{
GtkBin *bin;
g_return_val_if_fail (view_has_icon_container (view), NULL);
bin = GTK_BIN (view);
if (bin->child == NULL)
return NULL; /* Avoid GTK+ complaints. */
else
return GNOME_ICON_CONTAINER (bin->child);
}
static void
add_to_icon_container (FMDirectoryView *view,
FMIconCache *icon_manager,
GnomeIconContainer *icon_container,
GnomeVFSFileInfo *info,
gboolean with_layout)
{
GdkPixbuf *image;
g_return_if_fail(info);
image = fm_icon_cache_get_icon (icon_manager, info);
if (! with_layout || view->icon_layout == NULL) {
gnome_icon_container_add_pixbuf_auto (icon_container,
image,
info->name,
info);
} else {
gboolean result;
result = gnome_icon_container_add_pixbuf_with_layout
(icon_container, image, info->name, info,
view->icon_layout);
if (! result)
view->icons_not_in_layout = g_list_prepend
(view->icons_not_in_layout, info);
}
}
void
load_icon_container (FMDirectoryView *view,
GnomeIconContainer *icon_container)
{
gnome_icon_container_clear (icon_container);
if (view->directory_list != NULL) {
GnomeVFSDirectoryListPosition *position;
if (!icm)
icm = fm_get_current_icon_cache();
position = gnome_vfs_directory_list_get_first_position
(view->directory_list);
while (position != view->current_position) {
GnomeVFSFileInfo *info;
info = gnome_vfs_directory_list_get
(view->directory_list, position);
g_return_if_fail(info);
add_to_icon_container (view, icm,
icon_container, info, WITH_LAYOUT);
position = gnome_vfs_directory_list_position_next
(position);
}
}
}
/* GtkFList handling. */
static gboolean
view_has_flist (FMDirectoryView *view)
{
return (view->mode == FM_DIRECTORY_VIEW_MODE_DETAILED
|| view->mode == FM_DIRECTORY_VIEW_MODE_CUSTOM);
}
GtkFList *
get_flist (FMDirectoryView *view)
{
GtkBin *bin;
g_return_val_if_fail (view_has_flist (view), NULL);
bin = GTK_BIN (view);
if (bin->child == NULL)
return NULL; /* Avoid GTK+ complaints. */
else
return GTK_FLIST (bin->child);
}
void
add_to_flist (FMIconCache *icon_manager,
GtkFList *flist,