Skip to content
Snippets Groups Projects
Commit e24ebc3d authored by Benedikt Meurer's avatar Benedikt Meurer
Browse files

2005-07-24 Benedikt Meurer <benny@xfce.org>

	* thunar/thunar-file.c(thunar_file_load_icon): Actually cache the result
	  of an icon lookup.
	* thunarx/, thunarx/Makefile.am, configure.in.in: Add "thunarx"
	  namespace, which contains extensions to existing frameworks and
	  various helper functions that don't fit anywhere else.
	* thunarx/thunarx-gdk-pixbuf-extensions.{c,h}: Add a method to colorize
	  a GdkPixbuf to a given GdkColor.
	* thunar/main.c, thunar/thunar-desktop-model.{c,h}, thunar/Makefile.am,
	  thunar/thunar-desktop-window.{c,h}, thunar/thunar-desktop-view.{c,h}:
	  Add proof-of-concept for the desktop support.




(Old svn revision: 16409)
parent 5796662b
No related branches found
No related tags found
No related merge requests found
2005-07-24 Benedikt Meurer <benny@xfce.org>
* thunar/thunar-file.c(thunar_file_load_icon): Actually cache the result
of an icon lookup.
* thunarx/, thunarx/Makefile.am, configure.in.in: Add "thunarx"
namespace, which contains extensions to existing frameworks and
various helper functions that don't fit anywhere else.
* thunarx/thunarx-gdk-pixbuf-extensions.{c,h}: Add a method to colorize
a GdkPixbuf to a given GdkColor.
* thunar/main.c, thunar/thunar-desktop-model.{c,h}, thunar/Makefile.am,
thunar/thunar-desktop-window.{c,h}, thunar/thunar-desktop-view.{c,h}:
Add proof-of-concept for the desktop support.
2005-07-23 Benedikt Meurer <benny@xfce.org>
* thunar/thunar-list-model.c: Fix incorrect ThunarVfsMimeInfo -> GObject
......
......@@ -3,6 +3,7 @@
SUBDIRS = \
docs \
thunar-vfs \
thunarx \
thunar \
tests
......
......@@ -108,4 +108,5 @@ tests/data/Makefile
thunar/Makefile
thunar-vfs/Makefile
thunar-vfs/xdgmime/Makefile
thunarx/Makefile
])
......@@ -17,8 +17,12 @@ Thunar_SOURCES = \
thunar-clipboard-manager.h \
thunar-computer-folder.c \
thunar-computer-folder.h \
thunar-desktop-model.c \
thunar-desktop-model.h \
thunar-desktop-view.c \
thunar-desktop-view.h \
thunar-desktop-window.c \
thunar-desktop-window.h \
thunar-details-view.c \
thunar-details-view.h \
thunar-details-view-icon-renderer.c \
......@@ -90,10 +94,12 @@ Thunar_LDFLAGS = \
$(GTHREAD_LIBS)
Thunar_LDADD = \
$(top_builddir)/thunar-vfs/libthunar-vfs.la
$(top_builddir)/thunar-vfs/libthunar-vfs.la \
$(top_builddir)/thunarx/libthunarx.la
Thunar_DEPENDENCIES = \
$(top_builddir)/thunar-vfs/libthunar-vfs.la
$(top_builddir)/thunar-vfs/libthunar-vfs.la \
$(top_builddir)/thunarx/libthunarx.la
# install symlink to 'thunar'
install-data-local:
......
......@@ -28,6 +28,7 @@
#include <stdlib.h>
#endif
#include <thunar/thunar-desktop-window.h>
#include <thunar/thunar-window.h>
......@@ -58,6 +59,14 @@ main (int argc, char **argv)
/* initialize the ThunarVFS library */
thunar_vfs_init ();
if (argc >= 2 && exo_str_is_equal (argv[1], "--desktop"))
{
window = thunar_desktop_window_new ();
gtk_widget_show (window);
gtk_main ();
return 0;
}
path = (argc > 1) ? argv[1] : xfce_get_homedir ();
uri = thunar_vfs_uri_new (path, &error);
......
/* $Id$ */
/*-
* Copyright (c) 2005 Benedikt Meurer <benny@xfce.org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef HAVE_MEMORY_H
#include <memory.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include <thunar/thunar-desktop-model.h>
GType
thunar_desktop_position_get_type (void)
{
static GType type = G_TYPE_INVALID;
if (G_UNLIKELY (type == G_TYPE_INVALID))
{
type = g_boxed_type_register_static ("ThunarDesktopPosition",
(GBoxedCopyFunc) thunar_desktop_position_dup,
(GBoxedFreeFunc) thunar_desktop_position_free);
}
return type;
}
/**
* thunar_desktop_position_dup:
* @position : a #ThunarDesktopPosition.
*
* Returns a duplicate of @position. The caller
* is responsible to call #thunar_desktop_position_free()
* on the returned object.
*
* Return value: a duplicate of @position.
**/
ThunarDesktopPosition*
thunar_desktop_position_dup (const ThunarDesktopPosition *position)
{
g_return_val_if_fail (position != NULL, NULL);
return g_memdup (position, sizeof (*position));
}
/**
* thunar_desktop_position_free:
* @position : a #ThunarDesktopPosition.
*
* Frees the resources allocated for @position.
**/
void
thunar_desktop_position_free (ThunarDesktopPosition *position)
{
g_return_if_fail (position != NULL);
#ifndef G_DISABLE_CHECKS
memset (position, 0xaa, sizeof (*position));
#endif
g_free (position);
}
typedef struct _ThunarDesktopModelItem ThunarDesktopModelItem;
static void thunar_desktop_model_class_init (ThunarDesktopModelClass *klass);
static void thunar_desktop_model_tree_model_init (GtkTreeModelIface *iface);
static void thunar_desktop_model_init (ThunarDesktopModel *model);
static void thunar_desktop_model_finalize (GObject *object);
static GtkTreeModelFlags thunar_desktop_model_get_flags (GtkTreeModel *tree_model);
static gint thunar_desktop_model_get_n_columns (GtkTreeModel *tree_model);
static GType thunar_desktop_model_get_column_type (GtkTreeModel *tree_model,
gint index);
static gboolean thunar_desktop_model_get_iter (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreePath *path);
static GtkTreePath *thunar_desktop_model_get_path (GtkTreeModel *tree_model,
GtkTreeIter *iter);
static void thunar_desktop_model_get_value (GtkTreeModel *tree_model,
GtkTreeIter *iter,
gint column,
GValue *value);
static gboolean thunar_desktop_model_iter_next (GtkTreeModel *tree_model,
GtkTreeIter *iter);
static gboolean thunar_desktop_model_iter_children (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreeIter *parent);
static gboolean thunar_desktop_model_iter_has_child (GtkTreeModel *tree_model,
GtkTreeIter *iter);
static gint thunar_desktop_model_iter_n_children (GtkTreeModel *tree_model,
GtkTreeIter *iter);
static gboolean thunar_desktop_model_iter_nth_child (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreeIter *parent,
gint n);
static gboolean thunar_desktop_model_iter_parent (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreeIter *child);
static void thunar_desktop_model_item_free (ThunarDesktopModelItem *item);
struct _ThunarDesktopModelClass
{
GObjectClass __parent__;
};
struct _ThunarDesktopModel
{
GObject __parent__;
guint stamp;
GList *items;
gint n_items;
};
struct _ThunarDesktopModelItem
{
ThunarFile *file;
ThunarDesktopPosition position;
};
G_DEFINE_TYPE_WITH_CODE (ThunarDesktopModel,
thunar_desktop_model,
G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_MODEL,
thunar_desktop_model_tree_model_init));
static void
thunar_desktop_model_class_init (ThunarDesktopModelClass *klass)
{
GObjectClass *gobject_class;
gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = thunar_desktop_model_finalize;
}
static void
thunar_desktop_model_tree_model_init (GtkTreeModelIface *iface)
{
iface->get_flags = thunar_desktop_model_get_flags;
iface->get_n_columns = thunar_desktop_model_get_n_columns;
iface->get_column_type = thunar_desktop_model_get_column_type;
iface->get_iter = thunar_desktop_model_get_iter;
iface->get_path = thunar_desktop_model_get_path;
iface->get_value = thunar_desktop_model_get_value;
iface->iter_next = thunar_desktop_model_iter_next;
iface->iter_children = thunar_desktop_model_iter_children;
iface->iter_has_child = thunar_desktop_model_iter_has_child;
iface->iter_n_children = thunar_desktop_model_iter_n_children;
iface->iter_nth_child = thunar_desktop_model_iter_nth_child;
iface->iter_parent = thunar_desktop_model_iter_parent;
}
static void
thunar_desktop_model_init (ThunarDesktopModel *model)
{
ThunarDesktopModelItem *item;
ThunarVfsURI *uri;
model->stamp = g_random_int ();
uri = thunar_vfs_uri_new_for_path (xfce_get_homedir ());
item = g_new (ThunarDesktopModelItem, 1);
item->file = thunar_file_get_for_uri (uri, NULL);
item->position.row = 0;
item->position.column = 0;
item->position.screen_number = 0;
model->items = g_list_append (model->items, item);
++model->n_items;
thunar_vfs_uri_unref (uri);
uri = thunar_vfs_uri_new ("trash:", NULL);
item = g_new (ThunarDesktopModelItem, 1);
item->file = thunar_file_get_for_uri (uri, NULL);
item->position.row = 4;
item->position.column = 1;
item->position.screen_number = 0;
model->items = g_list_append (model->items, item);
++model->n_items;
thunar_vfs_uri_unref (uri);
}
static void
thunar_desktop_model_finalize (GObject *object)
{
ThunarDesktopModel *model = THUNAR_DESKTOP_MODEL (object);
/* free the desktop items */
g_list_foreach (model->items, (GFunc) thunar_desktop_model_item_free, NULL);
g_list_free (model->items);
G_OBJECT_CLASS (thunar_desktop_model_parent_class)->finalize (object);
}
static GtkTreeModelFlags
thunar_desktop_model_get_flags (GtkTreeModel *tree_model)
{
return GTK_TREE_MODEL_ITERS_PERSIST | GTK_TREE_MODEL_LIST_ONLY;
}
static gint
thunar_desktop_model_get_n_columns (GtkTreeModel *tree_model)
{
return THUNAR_DESKTOP_MODEL_N_COLUMNS;
}
static GType
thunar_desktop_model_get_column_type (GtkTreeModel *tree_model,
gint index)
{
switch (index)
{
case THUNAR_DESKTOP_MODEL_COLUMN_FILE:
return THUNAR_TYPE_FILE;
case THUNAR_DESKTOP_MODEL_COLUMN_POSITION:
return THUNAR_TYPE_DESKTOP_POSITION;
}
g_assert_not_reached ();
return G_TYPE_INVALID;
}
static gboolean
thunar_desktop_model_get_iter (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreePath *path)
{
ThunarDesktopModel *model = THUNAR_DESKTOP_MODEL (tree_model);
gint index;
g_return_val_if_fail (THUNAR_IS_DESKTOP_MODEL (model), FALSE);
g_return_val_if_fail (gtk_tree_path_get_depth (path) > 0, FALSE);
index = gtk_tree_path_get_indices (path)[0];
if (G_UNLIKELY (index >= model->n_items))
return FALSE;
iter->stamp = model->stamp;
iter->user_data = g_list_nth (model->items, index);
return TRUE;
}
static GtkTreePath*
thunar_desktop_model_get_path (GtkTreeModel *tree_model,
GtkTreeIter *iter)
{
ThunarDesktopModel *model = THUNAR_DESKTOP_MODEL (tree_model);
g_return_val_if_fail (THUNAR_IS_DESKTOP_MODEL (model), NULL);
g_return_val_if_fail (iter->stamp == model->stamp, NULL);
return gtk_tree_path_new_from_indices (g_list_position (model->items, iter->user_data), -1);
}
static void
thunar_desktop_model_get_value (GtkTreeModel *tree_model,
GtkTreeIter *iter,
gint column,
GValue *value)
{
ThunarDesktopModelItem *item = ((GList *) iter->user_data)->data;
ThunarDesktopModel *model = THUNAR_DESKTOP_MODEL (tree_model);
g_return_if_fail (THUNAR_IS_DESKTOP_MODEL (model));
g_return_if_fail (model->stamp == iter->stamp);
switch (column)
{
case THUNAR_DESKTOP_MODEL_COLUMN_FILE:
g_value_init (value, THUNAR_TYPE_FILE);
g_value_set_object (value, item->file);
break;
case THUNAR_DESKTOP_MODEL_COLUMN_POSITION:
g_value_init (value, THUNAR_TYPE_DESKTOP_POSITION);
g_value_set_boxed (value, &item->position);
break;
default:
g_assert_not_reached ();
}
}
static gboolean
thunar_desktop_model_iter_next (GtkTreeModel *tree_model,
GtkTreeIter *iter)
{
g_return_val_if_fail (THUNAR_IS_DESKTOP_MODEL (tree_model), FALSE);
g_return_val_if_fail (iter->stamp == THUNAR_DESKTOP_MODEL (tree_model)->stamp, FALSE);
iter->user_data = ((GList *) iter->user_data)->next;
return (iter->user_data != NULL);
}
static gboolean
thunar_desktop_model_iter_children (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreeIter *parent)
{
ThunarDesktopModel *model = THUNAR_DESKTOP_MODEL (tree_model);
g_return_val_if_fail (THUNAR_IS_DESKTOP_MODEL (model), FALSE);
g_return_val_if_fail (parent == NULL || parent->stamp == model->stamp, FALSE);
if (G_LIKELY (parent == NULL && model->items != NULL))
{
iter->stamp = model->stamp;
iter->user_data = model->items;
return TRUE;
}
return FALSE;
}
static gboolean
thunar_desktop_model_iter_has_child (GtkTreeModel *tree_model,
GtkTreeIter *iter)
{
return FALSE;
}
static gint
thunar_desktop_model_iter_n_children (GtkTreeModel *tree_model,
GtkTreeIter *iter)
{
ThunarDesktopModel *model = THUNAR_DESKTOP_MODEL (tree_model);
g_return_val_if_fail (THUNAR_IS_DESKTOP_MODEL (model), 0);
g_return_val_if_fail (iter == NULL || iter->stamp == model->stamp, 0);
return (iter == NULL) ? model->n_items : 0;
}
static gboolean
thunar_desktop_model_iter_nth_child (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreeIter *parent,
gint n)
{
ThunarDesktopModel *model = THUNAR_DESKTOP_MODEL (tree_model);
g_return_val_if_fail (THUNAR_IS_DESKTOP_MODEL (model), FALSE);
g_return_val_if_fail (parent == NULL || parent->stamp == model->stamp, FALSE);
if (G_LIKELY (parent == NULL && n < model->n_items))
{
iter->stamp = model->stamp;
iter->user_data = g_list_nth (model->items, n);
return TRUE;
}
return FALSE;
}
static gboolean
thunar_desktop_model_iter_parent (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreeIter *child)
{
return FALSE;
}
static void
thunar_desktop_model_item_free (ThunarDesktopModelItem *item)
{
g_object_unref (G_OBJECT (item->file));
g_free (item);
}
/**
* thunar_desktop_model_get_default:
*
* Returns the default #ThunarDesktopModel instance,
* which is shared by all #ThunarDesktopView<!---->s.
*
* The caller is responsible to free the returned
* object using #g_object_unref().
*
* Return value: the default #ThunarDesktopModel.
**/
ThunarDesktopModel*
thunar_desktop_model_get_default (void)
{
static ThunarDesktopModel *model = NULL;
if (G_LIKELY (model == NULL))
{
model = g_object_new (THUNAR_TYPE_DESKTOP_MODEL, NULL);
g_object_add_weak_pointer (G_OBJECT (model), (gpointer) &model);
}
else
{
g_object_ref (G_OBJECT (model));
}
return model;
}
/* $Id$ */
/*-
* Copyright (c) 2005 Benedikt Meurer <benny@xfce.org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __THUNAR_DESKTOP_MODEL_H__
#define __THUNAR_DESKTOP_MODEL_H__
#include <thunar/thunar-file.h>
G_BEGIN_DECLS;
typedef struct _ThunarDesktopPosition ThunarDesktopPosition;
#define THUNAR_TYPE_DESKTOP_POSITION (thunar_desktop_position_get_type ())
struct _ThunarDesktopPosition
{
gint row;
gint column;
gint screen_number;
};
GType thunar_desktop_position_get_type (void) G_GNUC_CONST;
ThunarDesktopPosition *thunar_desktop_position_dup (const ThunarDesktopPosition *position) G_GNUC_MALLOC;
void thunar_desktop_position_free (ThunarDesktopPosition *position);
typedef struct _ThunarDesktopModelClass ThunarDesktopModelClass;
typedef struct _ThunarDesktopModel ThunarDesktopModel;
#define THUNAR_TYPE_DESKTOP_MODEL (thunar_desktop_model_get_type ())
#define THUNAR_DESKTOP_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THUNAR_TYPE_DESKTOP_MODEL, ThunarDesktopModel))
#define THUNAR_DESKTOP_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), THUNAR_TYPE_DESKTOP_MODEL, ThunarDesktopModelClass))
#define THUNAR_IS_DESKTOP_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THUNAR_TYPE_DESKTOP_MODEL))
#define THUNAR_IS_DESKTOP_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), THUNAR_TYPE_DESKTOP_MODEL))
#define THUNAR_DESKTOP_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THUNAR_TYPE_DESKTOP_MODEL, ThunarDesktopModelClass))
enum
{
THUNAR_DESKTOP_MODEL_COLUMN_FILE,
THUNAR_DESKTOP_MODEL_COLUMN_POSITION,
THUNAR_DESKTOP_MODEL_N_COLUMNS,
};
GType thunar_desktop_model_get_type (void) G_GNUC_CONST;
ThunarDesktopModel *thunar_desktop_model_get_default (void);
G_END_DECLS;
#endif /* !__THUNAR_DESKTOP_MODEL_H__ */
This diff is collapsed.
......@@ -22,28 +22,39 @@
#include <gtk/gtk.h>
#include <thunar/thunar-preferences.h>
G_BEGIN_DECLS;
typedef struct _ThunarDesktopViewClass ThunarDesktopViewClass;
typedef struct _ThunarDesktopView ThunarDesktopView;
typedef struct _ThunarDesktopViewClass ThunarDesktopViewClass;
typedef struct _ThunarDesktopView ThunarDesktopView;
#define THUNAR_TYPE_DESKTOP_VIEW (thunar_desktop_view_get_type ())
#define THUNAR_DESKTOP_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THUNAR_TYPE_DESKTOP_VIEW, ThunarDesktopView))
#define THUNAR_DESKTOP_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), THUNAR_TYPE_DESKTOP_VIEW, ThunarDesktopViewClass))
#define THUNAR_IS_DESKTOP_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THUNAR_TYPE_DESKTOP_VIEW))
#define THUNAR_IS_DESKTOP_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), THUNAR_TYPE_DESKTOP_VIEW))
#define THUNAR_DESKTOP_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THUNAR_TYPE_DESKTOP_VIEW, ThunarDesktopViewClass))
#define THUNAR_DESKTOP_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THUNAR_TYPE_DESKTOP_VIEW, ThunarDesktopView))
GType thunar_desktop_view_get_type (void) G_GNUC_CONST;
GtkWidget *thunar_desktop_view_new (void);
gint thunar_desktop_view_get_icon_size (ThunarDesktopView *view);
void thunar_desktop_view_set_icon_size (ThunarDesktopView *view,
gint icon_size);
GtkTreeModel *thunar_desktop_view_get_model (ThunarDesktopView *view);
void thunar_desktop_view_set_model (ThunarDesktopView *view,
GtkTreeModel *model);
GType thunar_desktop_view_get_type (void) G_GNUC_CONST;
gint thunar_desktop_view_get_file_column (ThunarDesktopView *view);
void thunar_desktop_view_set_file_column (ThunarDesktopView *view,
gint file_column);
GtkWidget *thunar_desktop_view_new (void);
GtkWidget *thunar_desktop_view_new_with_display (GdkDisplay *display);
gint thunar_desktop_view_get_position_column (ThunarDesktopView *view);
void thunar_desktop_view_set_position_column (ThunarDesktopView *view,
gint position_column);
GdkDisplay *thunar_desktop_view_get_display (ThunarDesktopView *view);
void thunar_desktop_view_set_display (ThunarDesktopView *view,
GdkDisplay *display);
void thunar_desktop_view_unselect_all (ThunarDesktopView *view);
G_END_DECLS;
......
/* $Id$ */
/*-
* Copyright (c) 2005 Benedikt Meurer <benny@xfce.org>.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <thunar/thunar-desktop-model.h>
#include <thunar/thunar-desktop-window.h>
#include <thunar/thunar-desktop-view.h>
static void thunar_desktop_window_class_init (ThunarDesktopWindowClass *klass);
static void thunar_desktop_window_init (ThunarDesktopWindow *window);
static void thunar_desktop_window_size_request (GtkWidget *widget,
GtkRequisition *requisition);
static void thunar_desktop_window_realize (GtkWidget *widget);
static void thunar_desktop_window_unrealize (GtkWidget *widget);
static gboolean thunar_desktop_window_forward_event (GtkWidget *widget,
GdkEvent *event);
struct _ThunarDesktopWindowClass
{
GtkWindowClass __parent__;
};
struct _ThunarDesktopWindow
{
GtkWindow __parent__;
GtkWidget *view;
};
G_DEFINE_TYPE (ThunarDesktopWindow, thunar_desktop_window, GTK_TYPE_WINDOW);
static void
thunar_desktop_window_class_init (ThunarDesktopWindowClass *klass)
{
GtkWidgetClass *gtkwidget_class;
gtkwidget_class = GTK_WIDGET_CLASS (klass);
gtkwidget_class->size_request = thunar_desktop_window_size_request;
gtkwidget_class->realize = thunar_desktop_window_realize;
gtkwidget_class->unrealize = thunar_desktop_window_unrealize;
gtkwidget_class->button_press_event = (gpointer) thunar_desktop_window_forward_event;
gtkwidget_class->button_release_event = (gpointer) thunar_desktop_window_forward_event;
}
static void
thunar_desktop_window_init (ThunarDesktopWindow *window)
{
ThunarDesktopModel *model;
GTK_WIDGET_UNSET_FLAGS (window, GTK_DOUBLE_BUFFERED);
gtk_widget_add_events (GTK_WIDGET (window),
GDK_BUTTON_PRESS_MASK
| GDK_BUTTON_RELEASE_MASK);
gtk_window_move (GTK_WINDOW (window), 0, 0);
gtk_window_set_type_hint (GTK_WINDOW (window), GDK_WINDOW_TYPE_HINT_DESKTOP);
/* setup the view */
window->view = thunar_desktop_view_new ();
thunar_desktop_view_set_file_column (THUNAR_DESKTOP_VIEW (window->view), THUNAR_DESKTOP_MODEL_COLUMN_FILE);
thunar_desktop_view_set_position_column (THUNAR_DESKTOP_VIEW (window->view), THUNAR_DESKTOP_MODEL_COLUMN_POSITION);
gtk_container_add (GTK_CONTAINER (window), window->view);
gtk_widget_show (window->view);
/* setup the model */
model = thunar_desktop_model_get_default ();
thunar_desktop_view_set_model (THUNAR_DESKTOP_VIEW (window->view), GTK_TREE_MODEL (model));
g_object_unref (G_OBJECT (model));
}
static void
thunar_desktop_window_size_request (GtkWidget *widget,
GtkRequisition *requisition)
{
GdkScreen *screen = gtk_widget_get_screen (widget);
requisition->width = gdk_screen_get_width (screen);
requisition->height = gdk_screen_get_height (screen);
}
static void
thunar_desktop_window_realize (GtkWidget *widget)
{
GdkScreen *screen;
GdkWindow *root;
GdkAtom atom;
Window xid;
GTK_WIDGET_CLASS (thunar_desktop_window_parent_class)->realize (widget);
xid = GDK_DRAWABLE_XID (widget->window);
screen = gtk_widget_get_screen (widget);
root = gdk_screen_get_root_window (screen);
/* configure this window to be a "desktop" window */
atom = gdk_atom_intern ("_NET_WM_WINDOW_TYPE_DESKTOP", FALSE);
gdk_property_change (widget->window,
gdk_atom_intern ("_NET_WM_WINDOW_TYPE", FALSE),
gdk_atom_intern ("ATOM", FALSE), 32,
GDK_PROP_MODE_REPLACE, (gpointer) &atom, 1);
/* tell the root window that we have a new "desktop" window */
gdk_property_change (root,
gdk_atom_intern ("NAUTILUS_DESKTOP_WINDOW_ID", FALSE),
gdk_atom_intern ("WINDOW", FALSE), 32,
GDK_PROP_MODE_REPLACE, (gpointer) &xid, 1);
gdk_property_change (root,
gdk_atom_intern ("XFCE_DESKTOP_WINDOW", FALSE),
gdk_atom_intern ("WINDOW", FALSE), 32,
GDK_PROP_MODE_REPLACE, (gpointer) &xid, 1);
/* XRandR support */
g_signal_connect_swapped (G_OBJECT (screen), "size-changed", G_CALLBACK (gtk_widget_queue_resize), widget);
}
static void
thunar_desktop_window_unrealize (GtkWidget *widget)
{
GdkScreen *screen;
GdkWindow *root;
screen = gtk_widget_get_screen (widget);
root = gdk_screen_get_root_window (screen);
/* disconnect the XRandR support handler */
g_signal_handlers_disconnect_by_func (G_OBJECT (screen), gtk_widget_queue_resize, widget);
/* unset root window properties */
gdk_property_delete (root, gdk_atom_intern ("NAUTILUS_DESKTOP_WINDOW_ID", FALSE));
gdk_property_delete (root, gdk_atom_intern ("XFCE_DESKTOP_WINDOW", FALSE));
GTK_WIDGET_CLASS (thunar_desktop_window_parent_class)->unrealize (widget);
}
static gboolean
thunar_desktop_window_forward_event (GtkWidget *widget,
GdkEvent *event)
{
if (G_LIKELY (GTK_BIN (widget)->child != NULL))
return gtk_widget_event (GTK_BIN (widget)->child, event);
return FALSE;
}
/**
* thunar_desktop_window_new:
*
* Allocates a new #ThunarDesktopWindow instance.
*
* Return value: the newly allocated #ThunarDesktopWindow.
**/
GtkWidget*
thunar_desktop_window_new (void)
{
return thunar_desktop_window_new_with_screen (gdk_screen_get_default ());
}
/**
* thunar_desktop_window_new_with_screen:
* @screen : a #GdkScreen.
*
* Allocates a new #ThunarDesktopWindow instance and
* associates it with the given @screen.
*
* Return value: the newly allocated #ThunarDesktopWindow.
**/
GtkWidget*
thunar_desktop_window_new_with_screen (GdkScreen *screen)
{
g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
return g_object_new (THUNAR_TYPE_DESKTOP_WINDOW,
"screen", screen,
NULL);
}
/* $Id$ */
/*-
* Copyright (c) 2005 Benedikt Meurer <benny@xfce.org>.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __THUNAR_DESKTOP_WINDOW_H__
#define __THUNAR_DESKTOP_WINDOW_H__
#include <gtk/gtk.h>
G_BEGIN_DECLS;
typedef struct _ThunarDesktopWindowClass ThunarDesktopWindowClass;
typedef struct _ThunarDesktopWindow ThunarDesktopWindow;
#define THUNAR_TYPE_DESKTOP_WINDOW (thunar_desktop_window_get_type ())
#define THUNAR_DESKTOP_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THUNAR_TYPE_DESKTOP_WINDOW, ThunarDesktopWindow))
#define THUNAR_DESKTOP_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), THUNAR_TYPE_DESKTOP_WINDOW, ThunarDesktopWindowClass))
#define THUNAR_IS_DESKTOP_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THUNAR_TYPE_DESKTOP_WINDOW))
#define THUNAR_IS_DESKTOP_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), THUNAR_TYPE_DESKTOP_WINDOW))
#define THUNAR_DESKTOP_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THUNAR_TYPE_DESKTOP_WINDOW, ThunarDesktopWindowClass))
GType thunar_desktop_window_get_type (void) G_GNUC_CONST;
GtkWidget *thunar_desktop_window_new (void);
GtkWidget *thunar_desktop_window_new_with_screen (GdkScreen *screen);
G_END_DECLS;
#endif /* !__THUNAR_DESKTOP_WINDOW_H__ */
......@@ -1168,17 +1168,22 @@ thunar_file_load_icon (ThunarFile *file,
g_return_val_if_fail (THUNAR_IS_FILE (file), NULL);
/* see if we have a cached icon that matches the request */
if (file->cached_icon != NULL && file->cached_size == size)
if (file->cached_icon == NULL || file->cached_size != size)
{
/* take a reference on the cached icon for the caller */
g_object_ref (G_OBJECT (file->cached_icon));
return file->cached_icon;
/* drop any previous icon */
if (file->cached_icon != NULL)
g_object_unref (G_OBJECT (file->cached_icon));
/* load the icon */
icon_factory = thunar_icon_factory_get_default ();
icon_theme = thunar_icon_factory_get_icon_theme (icon_factory);
icon_name = THUNAR_FILE_GET_CLASS (file)->get_icon_name (file, icon_theme);
file->cached_icon = thunar_icon_factory_load_icon (icon_factory, icon_name, size, NULL, TRUE);
}
icon_factory = thunar_icon_factory_get_default ();
icon_theme = thunar_icon_factory_get_icon_theme (icon_factory);
icon_name = THUNAR_FILE_GET_CLASS (file)->get_icon_name (file, icon_theme);
return thunar_icon_factory_load_icon (icon_factory, icon_name, size, NULL, TRUE);
/* take a reference on the cached icon for the caller */
g_object_ref (G_OBJECT (file->cached_icon));
return file->cached_icon;
}
......
# $Id$
INCLUDES = \
-I$(top_srcdir) \
-DEXO_API_SUBJECT_TO_CHANGE \
-DEXO_DISABLE_DEPRECATED \
-DG_LOG_DOMAIN=\"thunarx\"
noinst_LTLIBRARIES = \
libthunarx.la
libthunarx_la_SOURCES = \
thunarx-gdk-pixbuf-extensions.c \
thunarx-gdk-pixbuf-extensions.h
libthunarx_la_CFLAGS = \
$(EXO_CFLAGS)
libthunarx_la_LDFLAGS = \
-no-undefined
libthunarx_la_LIBADD = \
$(EXO_LIBS)
# vi:set ts=8 sw=8 noet ai nocindent syntax=automake:
/* $Id$ */
/*-
* Copyright (c) 2005 Benedikt Meurer <benny@xfce.org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <thunarx/thunarx-gdk-pixbuf-extensions.h>
/**
* thunarx_gdk_pixbuf_colorize:
* @src : the source #GdkPixbuf.
* @color : the new color.
*
* Creates a new #GdkPixbuf based on @src, which is
* colorized to @color.
*
* Return value: the colorized #GdkPixbuf.
**/
GdkPixbuf*
thunarx_gdk_pixbuf_colorize (GdkPixbuf *src,
const GdkColor *color)
{
gint i, j;
gint width, height, has_alpha, src_row_stride, dst_row_stride;
gint red_value, green_value, blue_value;
guchar *target_pixels;
guchar *original_pixels;
guchar *pixsrc;
guchar *pixdest;
GdkPixbuf *dest;
red_value = color->red / 255.0;
green_value = color->green / 255.0;
blue_value = color->blue / 255.0;
dest = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (src),
gdk_pixbuf_get_has_alpha (src),
gdk_pixbuf_get_bits_per_sample (src),
gdk_pixbuf_get_width (src),
gdk_pixbuf_get_height (src));
has_alpha = gdk_pixbuf_get_has_alpha (src);
width = gdk_pixbuf_get_width (src);
height = gdk_pixbuf_get_height (src);
src_row_stride = gdk_pixbuf_get_rowstride (src);
dst_row_stride = gdk_pixbuf_get_rowstride (dest);
target_pixels = gdk_pixbuf_get_pixels (dest);
original_pixels = gdk_pixbuf_get_pixels (src);
for (i = 0; i < height; i++)
{
pixdest = target_pixels + i*dst_row_stride;
pixsrc = original_pixels + i*src_row_stride;
for (j = 0; j < width; j++)
{
*pixdest++ = (*pixsrc++ * red_value) >> 8;
*pixdest++ = (*pixsrc++ * green_value) >> 8;
*pixdest++ = (*pixsrc++ * blue_value) >> 8;
if (has_alpha)
*pixdest++ = *pixsrc++;
}
}
return dest;
}
/* $Id$ */
/*-
* Copyright (c) 2005 Benedikt Meurer <benny@xfce.org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __THUNARX_GDK_PIXBUF_EXTENSIONS_H__
#define __THUNARX_GDK_PIXBUF_EXTENSIONS_H__
#include <gdk/gdk.h>
G_BEGIN_DECLS;
GdkPixbuf *thunarx_gdk_pixbuf_colorize (GdkPixbuf *src,
const GdkColor *color);
G_END_DECLS;
#endif /* !__THUNARX_GDK_PIXBUF_EXTENSIONS_H__ */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment