[Goodies-commits] r2915 - in ristretto/trunk: . src
Stephan Arts
stephan at xfce.org
Mon Jul 16 01:14:15 CEST 2007
Author: stephan
Date: 2007-07-15 23:14:15 +0000 (Sun, 15 Jul 2007)
New Revision: 2915
Modified:
ristretto/trunk/configure.in.in
ristretto/trunk/src/Makefile.am
ristretto/trunk/src/main.c
ristretto/trunk/src/picture_viewer.c
Log:
Add forward and backward buttons (for manual slideshow)
Add border-line drawing to picture-viewer widget
Modified: ristretto/trunk/configure.in.in
===================================================================
--- ristretto/trunk/configure.in.in 2007-07-13 16:47:11 UTC (rev 2914)
+++ ristretto/trunk/configure.in.in 2007-07-15 23:14:15 UTC (rev 2915)
@@ -110,6 +110,7 @@
XDT_CHECK_PACKAGE([GTK], [gtk+-2.0], [2.2.0])
XDT_CHECK_PACKAGE([GLIB], [glib-2.0], [2.2.0])
XDT_CHECK_PACKAGE([GOBJECT], [gobject-2.0], [2.2.0])
+XDT_CHECK_PACKAGE([THUNAR_VFS], [thunar-vfs-1], [0.4.0])
dnl check for debugging support
Modified: ristretto/trunk/src/Makefile.am
===================================================================
--- ristretto/trunk/src/Makefile.am 2007-07-13 16:47:11 UTC (rev 2914)
+++ ristretto/trunk/src/Makefile.am 2007-07-15 23:14:15 UTC (rev 2915)
@@ -5,17 +5,19 @@
picture_viewer.c picture_viewer.h
ristretto_CFLAGS = \
- @GTK_CFLAGS@ \
- @GLIB_CFLAGS@ \
+ $(GTK_CFLAGS) \
+ $(GLIB_CFLAGS) \
$(XFCE4UTIL_CFLAGS) \
+ $(THUNAR_VFS_CFLAGS) \
-DDATADIR=\"$(datadir)\" \
-DSRCDIR=\"$(top_srcdir)\" \
-DLOCALEDIR=\"$(localedir)\"
ristretto_LDADD = \
- @GTK_LIBS@ \
- @GLIB_LIBS@ \
- $(XFCE4UTIL_LIBS)
+ $(GTK_LIBS) \
+ $(GLIB_LIBS) \
+ $(XFCE4UTIL_LIBS) \
+ $(THUNAR_VFS_LIBS)
INCLUDES = \
-I${top_srcdir}
Modified: ristretto/trunk/src/main.c
===================================================================
--- ristretto/trunk/src/main.c 2007-07-13 16:47:11 UTC (rev 2914)
+++ ristretto/trunk/src/main.c 2007-07-15 23:14:15 UTC (rev 2915)
@@ -16,10 +16,17 @@
#include <config.h>
#include <gtk/gtk.h>
-#include <gettext.h>
+#include <string.h>
+#include <thunar-vfs/thunar-vfs.h>
+
#include "picture_viewer.h"
+static ThunarVfsMimeDatabase *mime_dbase = NULL;
+static ThunarVfsPath *working_dir = NULL;
+static GList *file_list = NULL;
+static GList *file_iter = NULL;
+
static void
cb_rstto_zoom_fit(GtkToolItem *item, RsttoPictureViewer *viewer);
static void
@@ -28,13 +35,20 @@
cb_rstto_zoom_in(GtkToolItem *item, RsttoPictureViewer *viewer);
static void
cb_rstto_zoom_out(GtkToolItem *item, RsttoPictureViewer *viewer);
+
static void
+cb_rstto_back(GtkToolItem *item, RsttoPictureViewer *viewer);
+static void
+cb_rstto_forward(GtkToolItem *item, RsttoPictureViewer *viewer);
+
+static void
cb_rstto_open(GtkToolItem *item, RsttoPictureViewer *viewer);
int main(int argc, char **argv)
{
GdkPixbuf *pixbuf;
+
#ifdef ENABLE_NLS
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
@@ -43,10 +57,38 @@
gtk_init(&argc, &argv);
+ thunar_vfs_init();
+
+ mime_dbase = thunar_vfs_mime_database_get_default();
+
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
if(argc == 2)
+ {
+ ThunarVfsPath *path = thunar_vfs_path_new(argv[1], NULL);
+ working_dir = thunar_vfs_path_get_parent(path);
+ thunar_vfs_path_ref(working_dir);
+ thunar_vfs_path_unref(path);
pixbuf = gdk_pixbuf_new_from_file(argv[1], NULL);
+
+ gchar *dir_name = thunar_vfs_path_dup_string(working_dir);
+
+ GDir *dir = g_dir_open(dir_name, 0, NULL);
+ const gchar *filename = g_dir_read_name(dir);
+ while(filename)
+ {
+ ThunarVfsMimeInfo *mime_info = thunar_vfs_mime_database_get_info_for_name(mime_dbase, filename);
+ if(!strcmp(thunar_vfs_mime_info_get_media(mime_info), "image"))
+ {
+ file_list = g_list_prepend(file_list, thunar_vfs_path_relative(working_dir, filename));
+ if(!strcmp(thunar_vfs_path_get_name(THUNAR_VFS_PATH(file_list->data)), argv[1]))
+ file_iter = file_list;
+ }
+ thunar_vfs_mime_info_unref(mime_info);
+ filename = g_dir_read_name(dir);
+ }
+ g_free(dir_name);
+ }
else
pixbuf = NULL;
@@ -62,10 +104,14 @@
GtkToolItem *zoom_fit= gtk_tool_button_new_from_stock(GTK_STOCK_ZOOM_FIT);
GtkToolItem *zoom_100= gtk_tool_button_new_from_stock(GTK_STOCK_ZOOM_100);
GtkToolItem *zoom_out= gtk_tool_button_new_from_stock(GTK_STOCK_ZOOM_OUT);
- GtkToolItem *zoom_in= gtk_tool_button_new_from_stock(GTK_STOCK_ZOOM_IN);
+ GtkToolItem *zoom_in = gtk_tool_button_new_from_stock(GTK_STOCK_ZOOM_IN);
+ GtkToolItem *forward = gtk_tool_button_new_from_stock(GTK_STOCK_GO_FORWARD);
+ GtkToolItem *separator = gtk_separator_tool_item_new();
+ GtkToolItem *back = gtk_tool_button_new_from_stock(GTK_STOCK_GO_BACK);
GtkToolItem *open = gtk_tool_button_new_from_stock(GTK_STOCK_OPEN);
GtkToolItem *spacer = gtk_tool_item_new();
+
gtk_tool_item_set_expand(spacer, TRUE);
gtk_tool_item_set_homogeneous(spacer, FALSE);
@@ -85,6 +131,9 @@
gtk_toolbar_insert(GTK_TOOLBAR(tool_bar), zoom_100, 0);
gtk_toolbar_insert(GTK_TOOLBAR(tool_bar), zoom_out, 0);
gtk_toolbar_insert(GTK_TOOLBAR(tool_bar), zoom_in, 0);
+ gtk_toolbar_insert(GTK_TOOLBAR(tool_bar), separator, 0);
+ gtk_toolbar_insert(GTK_TOOLBAR(tool_bar), forward, 0);
+ gtk_toolbar_insert(GTK_TOOLBAR(tool_bar), back, 0);
gtk_toolbar_insert(GTK_TOOLBAR(tool_bar), spacer, 0);
gtk_toolbar_insert(GTK_TOOLBAR(tool_bar), open, 0);
@@ -92,6 +141,8 @@
g_signal_connect(G_OBJECT(zoom_100), "clicked", G_CALLBACK(cb_rstto_zoom_100), viewer);
g_signal_connect(G_OBJECT(zoom_in), "clicked", G_CALLBACK(cb_rstto_zoom_in), viewer);
g_signal_connect(G_OBJECT(zoom_out), "clicked", G_CALLBACK(cb_rstto_zoom_out), viewer);
+ g_signal_connect(G_OBJECT(forward), "clicked", G_CALLBACK(cb_rstto_forward), viewer);
+ g_signal_connect(G_OBJECT(back), "clicked", G_CALLBACK(cb_rstto_back), viewer);
g_signal_connect(G_OBJECT(open), "clicked", G_CALLBACK(cb_rstto_open), viewer);
gtk_container_add(GTK_CONTAINER(window), main_vbox);
@@ -145,10 +196,79 @@
gint response = gtk_dialog_run(GTK_DIALOG(dialog));
if(response == GTK_RESPONSE_OK)
{
- pixbuf = gdk_pixbuf_new_from_file(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)), NULL);
+ const gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
+ ThunarVfsPath *path = thunar_vfs_path_new(filename, NULL);
+ if(working_dir)
+ thunar_vfs_path_unref(working_dir);
+ working_dir = thunar_vfs_path_get_parent(path);
+ thunar_vfs_path_ref(working_dir);
+ thunar_vfs_path_unref(path);
+
+ g_list_foreach(file_list, (GFunc)thunar_vfs_path_unref, NULL);
+ g_list_free(file_list);
+ file_list = file_iter = NULL;
+
+ gchar *dir_name = thunar_vfs_path_dup_string(working_dir);
+
+ GDir *dir = g_dir_open(dir_name, 0, NULL);
+ const gchar *_filename = g_dir_read_name(dir);
+ while(_filename)
+ {
+ ThunarVfsMimeInfo *mime_info = thunar_vfs_mime_database_get_info_for_name(mime_dbase, _filename);
+ if(!strcmp(thunar_vfs_mime_info_get_media(mime_info), "image"))
+ {
+ file_list = g_list_prepend(file_list, thunar_vfs_path_relative(working_dir, _filename));
+ if(!strcmp(thunar_vfs_path_get_name(THUNAR_VFS_PATH(file_list->data)), _filename))
+ file_iter = file_list;
+ }
+ thunar_vfs_mime_info_unref(mime_info);
+ _filename = g_dir_read_name(dir);
+ }
+ g_free(dir_name);
+
+ pixbuf = gdk_pixbuf_new_from_file(filename , NULL);
+
rstto_picture_viewer_set_pixbuf(RSTTO_PICTURE_VIEWER(viewer), pixbuf);
}
gtk_widget_destroy(dialog);
}
+
+static void
+cb_rstto_forward(GtkToolItem *item, RsttoPictureViewer *viewer)
+{
+ GdkPixbuf *pixbuf;
+ file_iter = g_list_next(file_iter);
+ if(!file_iter)
+ file_iter = file_list;
+
+ if(file_iter)
+ {
+ gchar *filename = thunar_vfs_path_dup_string(file_iter->data);
+
+ pixbuf = gdk_pixbuf_new_from_file(filename , NULL);
+
+ rstto_picture_viewer_set_pixbuf(RSTTO_PICTURE_VIEWER(viewer), pixbuf);
+ g_free(filename);
+ }
+}
+
+static void
+cb_rstto_back(GtkToolItem *item, RsttoPictureViewer *viewer)
+{
+ GdkPixbuf *pixbuf;
+ file_iter = g_list_previous(file_iter);
+ if(!file_iter)
+ file_iter = g_list_last(file_list);
+
+ if(file_iter)
+ {
+ gchar *filename = thunar_vfs_path_dup_string(file_iter->data);
+
+ pixbuf = gdk_pixbuf_new_from_file(filename , NULL);
+
+ rstto_picture_viewer_set_pixbuf(RSTTO_PICTURE_VIEWER(viewer), pixbuf);
+ g_free(filename);
+ }
+}
Modified: ristretto/trunk/src/picture_viewer.c
===================================================================
--- ristretto/trunk/src/picture_viewer.c 2007-07-13 16:47:11 UTC (rev 2914)
+++ ristretto/trunk/src/picture_viewer.c 2007-07-15 23:14:15 UTC (rev 2915)
@@ -203,7 +203,11 @@
{
GdkPixbuf *pixbuf = RSTTO_PICTURE_VIEWER(widget)->dst_pixbuf;
GdkColor color;
+ GdkColor line_color;
+
color.pixel = 0xdddddddd;
+ line_color.pixel = 0x0;
+
/* required for transparent pixbufs... add double buffering to fix flickering*/
if(GTK_WIDGET_REALIZED(widget))
{
@@ -214,17 +218,27 @@
gdk_draw_rectangle(GDK_DRAWABLE(buffer), gc, TRUE, 0, 0, widget->allocation.width, widget->allocation.height);
if(pixbuf)
{
+ gint x1 = (widget->allocation.width-gdk_pixbuf_get_width(pixbuf))<0?0:(widget->allocation.width-gdk_pixbuf_get_width(pixbuf))/2;
+ gint y1 = (widget->allocation.height-gdk_pixbuf_get_height(pixbuf))<0?0:(widget->allocation.height-gdk_pixbuf_get_height(pixbuf))/2;
+ gint x2 = gdk_pixbuf_get_width(pixbuf);
+ gint y2 = gdk_pixbuf_get_height(pixbuf);
gdk_draw_pixbuf(GDK_DRAWABLE(buffer),
NULL,
pixbuf,
0,
0,
- (widget->allocation.width-gdk_pixbuf_get_width(pixbuf))<0?0:(widget->allocation.width-gdk_pixbuf_get_width(pixbuf))/2,
- (widget->allocation.height-gdk_pixbuf_get_height(pixbuf))<0?0:(widget->allocation.height-gdk_pixbuf_get_height(pixbuf))/2,
- gdk_pixbuf_get_width(pixbuf),
- gdk_pixbuf_get_height(pixbuf),
+ x1,
+ y1,
+ x2,
+ y2,
GDK_RGB_DITHER_NONE,
0,0);
+ gdk_gc_set_foreground(gc, &line_color);
+ gdk_draw_line(GDK_DRAWABLE(buffer), gc, x1, y1, x1, y1+y2);
+ gdk_draw_line(GDK_DRAWABLE(buffer), gc, x1, y1+y2, x1+x2, y1+y2);
+ gdk_draw_line(GDK_DRAWABLE(buffer), gc, x1, y1, x1+x2, y1);
+ gdk_draw_line(GDK_DRAWABLE(buffer), gc, x1+x2, y1, x1+x2, y1+y2);
+
}
gdk_draw_drawable(GDK_DRAWABLE(widget->window),
gdk_gc_new(widget->window),
More information about the Goodies-commits
mailing list