telegnome r18 - in trunk: . po src
- From: cjwatson svn gnome org
- To: svn-commits-list gnome org
- Subject: telegnome r18 - in trunk: . po src
- Date: Sun, 24 Feb 2008 08:50:45 +0000 (GMT)
Author: cjwatson
Date: Sun Feb 24 08:50:44 2008
New Revision: 18
URL: http://svn.gnome.org/viewvc/telegnome?rev=18&view=rev
Log:
Port to GnomeVFS.
* configure.in (PKG_CHECK_MODULES): Add gdk-pixbuf-2.0 and
gnome-vfs-2.0.
(GNOME_GHTTP_CHECK): Remove.
* acinclude.m4: Remove.
* src/http.c (get_the_image): Use GnomeVFS rather than ghttp. Load the
image into a GdkPixbuf as we fetch it, and return a GdkPixbuf rather
than a temporary file name.
(cleanup): Remove.
* src/http.h: Remove TEMPNAM_PREFIX and PAGE_MINSIZE.
(get_the_image): Update prototype.
(cleanup): Remove prototype.
* src/main.h: Update error codes.
* src/view.c (tele_view_update_pixmap): Take a GdkPixbuf argument
rather than a file name.
(tele_view_update_page): get_the_image produces a GdkPixbuf rather
than a file name. Handle TG_ERR_PIXBUF instead of TG_ERR_TOOSMALL,
TG_ERR_VFS instead of TG_ERR_GHTTP, and remove handling of
TG_ERR_NOCONNECTION, TG_ERR_FILE, and TG_ERR_CHMOD.
* src/view.h (tele_view_update_pixmap): Update prototype.
* src/pixpack.c (pixpack_destroy): Guard against pixpack->private_data
being NULL.
(pixpack_load_image_file): Rename to ...
(pixpack_load_image): ... this. Take a GdkPixbuf argument rather than
a file name. Unref the previous stored pixbuf if set.
* src/pixpack.h (pixpack_load_image_file): Rename prototype to ...
(pixpack_load_image_file): ... this and update.
* src/gui.c (new_gui): Pass a GdkPixbuf to tele_view_update_pixmap.
(cb_quit): Stop calling cleanup.
* README: Update.
Fix a crash on window close.
* src/view.c (tele_view_update_page): Ref view->box before returning
it.
(tele_view_free): Set view->box to NULL after unreffing it, just in
case.
Fix translation infrastructure.
* configure.in (GETTEXT_PACKAGE): Set this; glib-gettextize requires
it.
* po/*.po: Update.
Removed:
trunk/acinclude.m4
Modified:
trunk/ChangeLog
trunk/README
trunk/configure.in
trunk/po/az.po
trunk/po/fr.po
trunk/po/it.po
trunk/po/nl.po
trunk/po/ru.po
trunk/po/sv.po
trunk/po/zh_CN.po
trunk/src/gui.c
trunk/src/http.c
trunk/src/http.h
trunk/src/main.h
trunk/src/pixpack.c
trunk/src/pixpack.h
trunk/src/view.c
trunk/src/view.h
Modified: trunk/README
==============================================================================
--- trunk/README (original)
+++ trunk/README Sun Feb 24 08:50:44 2008
@@ -6,10 +6,10 @@
To compile this package, you need:
An ANSI C-compiler (tested with gcc, version 2.7.3, 2.95.2 and with egcs, v1.0.1);
-GTK+ en GLib, version 1.2 (zie www.gtk.org). RPM'ers: use the -devel versions;
-GNOME-Libs, version 1.x (zie www.gnome.org). RPM'ers: use the -devel versions;
-GNOME-HTTP, or libghttp: part of GNOME, might not be installed by default.
-Gdk-pixbuf 0.7.0 or higher
+GTK+ and GLib, version 2.x (see www.gtk.org). RPM'ers: use the -devel versions;
+GNOME-Libs, version 2.x (see www.gnome.org). RPM'ers: use the -devel versions;
+GnomeVFS, version 2.x: part of GNOME, might not be installed by default.
+gdk-pixbuf, version 2.x
If you have GNOME installed in /usr, which is the default, you should do:
@@ -24,7 +24,7 @@
good luck,
+Colin Watson <cjwatson debian org>,
Arjan Scherpenisse <acscherp wins uva nl>,
Dirk-Jan <djcb dds nl>
-
Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in (original)
+++ trunk/configure.in Sun Feb 24 08:50:44 2008
@@ -17,13 +17,15 @@
AC_HEADER_STDC
AC_PROG_INSTALL
-PKG_CHECK_MODULES([TELEGNOME], [glib-2.0 libgnomeui-2.0])
-GNOME_GHTTP_CHECK
+PKG_CHECK_MODULES([TELEGNOME], [glib-2.0 gdk-pixbuf-2.0 libgnomeui-2.0 gnome-vfs-2.0])
PROGRAMS_TELEGNOME="telegnome"
AC_SUBST(PROGRAMS_TELEGNOME)
ALL_LINGUAS="az fr it nl ru sv zh_CN"
+GETTEXT_PACKAGE=telegnome
+AC_SUBST([GETTEXT_PACKAGE])
+AC_DEFINE_UNQUOTED([GETTEXT_PACKAGE], ["$GETTEXT_PACKAGE"], [Gettext Package])
AM_GLIB_GNU_GETTEXT
AM_GLIB_DEFINE_LOCALEDIR([GNOMELOCALEDIR])
Modified: trunk/src/gui.c
==============================================================================
--- trunk/src/gui.c (original)
+++ trunk/src/gui.c Sun Feb 24 08:50:44 2008
@@ -59,7 +59,8 @@
new_gui (gchar* startpage)
{
GtkWidget *app, *toolbar, *statusbar;
-
+ GdkPixbuf *pixbuf;
+ GError *error = NULL;
/* the app */
app= gnome_app_new (PACKAGE, _("TeleGNOME: Teletext for GNOME"));
@@ -128,7 +129,10 @@
load up the last page we were visiting. Otherwise,
start with a logo */
update_entry(0,0);
- tele_view_update_pixmap(currentview, gnome_pixmap_file(TG_LOGO_PIXMAP));
+ pixbuf = gdk_pixbuf_new_from_file(gnome_pixmap_file(TG_LOGO_PIXMAP),
+ &error);
+ tele_view_update_pixmap(currentview, pixbuf);
+ g_object_unref(pixbuf);
/* only auto-change to a page if it was saved the last time */
@@ -510,8 +514,6 @@
}
tele_view_free(currentview);
- /* get rid of the temp files */
- cleanup();
/* get outta here ;) */
gtk_main_quit();
}
Modified: trunk/src/http.c
==============================================================================
--- trunk/src/http.c (original)
+++ trunk/src/http.c Sun Feb 24 08:50:44 2008
@@ -21,10 +21,8 @@
*/
#include <gnome.h>
-#include <ghttp.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
+#include <libgnomevfs/gnome-vfs.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
#include "http.h"
#include "main.h"
#include "prefs.h"
@@ -64,58 +62,59 @@
/*
* get the image from a remote site
- * if all's ok, return name in an GdkImlibImage
+ * if all's ok, return name in a GdkPixbuf
*/
gint
-get_the_image (char **filename)
+get_the_image (GdkPixbuf **pixbuf)
{
gint output;
gint bytes_written;
gchar http_query[100];
gchar *http_proxy;
gint retval=0;
- ghttp_request *request= NULL;
+ GnomeVFSHandle *handle = NULL;
+ GdkPixbufLoader *loader = NULL;
+ guchar buf[4096];
+ GnomeVFSResult vfs_result;
+ GnomeVFSFileSize bytes_read;
+ GError *err = NULL;
if ( -1 == get_http_query(http_query, currentview->page_nr, currentview->subpage_nr))
return TG_ERR_HTTPQUERY;
- *filename=tempnam(NULL, TEMPNAM_PREFIX);
-
/* get the image from remote server */
- request= ghttp_request_new();
- if (-1 == ghttp_set_uri (request, http_query)) retval= TG_ERR_GHTTP;
- if ( http_proxy=gnome_config_get_string("/telegnome/Proxy/http_proxy") ) {
- if (-1 == ghttp_set_proxy (request, http_proxy)) retval= TG_ERR_GHTTP;
- }
-
- if (-1 == ghttp_set_sync (request, ghttp_sync)) retval= TG_ERR_GHTTP;
- if (-1 == ghttp_set_type (request, ghttp_type_get)) retval= TG_ERR_GHTTP;
- if (-1 == ghttp_prepare(request)) retval= TG_ERR_GHTTP;
- if (ghttp_done != ghttp_process(request)) retval= TG_ERR_GHTTP;
-
- /* write to file */
- if (-1 == (output=open(*filename, O_WRONLY | O_CREAT | O_SYNC | O_TRUNC)))
- retval= TG_ERR_FILE;
-
- bytes_written= write(output, ghttp_get_body(request), ghttp_get_body_len(request));
- fsync(output); close(output);
- if ( bytes_written < PAGE_MINSIZE )
- return TG_ERR_TOOSMALL;
-
- /* set read permissions */
- if (0 != chmod (*filename, S_IRUSR)) retval= TG_ERR_CHMOD;
- else {
- /* FIXME!!! */
- /* ghttp_request_destroy(request); */
- return TG_OK;
+ vfs_result = gnome_vfs_open(&handle, http_query, GNOME_VFS_OPEN_READ);
+ if (vfs_result != GNOME_VFS_OK)
+ return TG_ERR_VFS;
+
+ loader = gdk_pixbuf_loader_new();
+
+ for (;;) {
+ vfs_result = gnome_vfs_read(handle, buf, 4096, &bytes_read);
+ if (vfs_result == GNOME_VFS_ERROR_EOF)
+ break;
+ err = NULL;
+ if (!gdk_pixbuf_loader_write(loader, buf, (gsize)bytes_read, &err)) {
+ retval = TG_ERR_PIXBUF;
+ goto out;
+ }
}
- if (!(TG_ERR_FILE == retval))
- close (output);
-
- /* FIXME!!! */
- /* ghttp_request_destroy(request); */
-
+ *pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
+ if (!*pixbuf) {
+ retval = TG_ERR_PIXBUF;
+ goto out;
+ }
+ g_object_ref(*pixbuf);
+
+out:
+ if (loader) {
+ if (!gdk_pixbuf_loader_close(loader, &err) && !retval)
+ retval = TG_ERR_PIXBUF;
+ }
+ if (handle)
+ gnome_vfs_close(handle);
+
return retval;
}
@@ -134,10 +133,3 @@
}
return 0;
}
-
-/* gets rid of all those tmp files */
-void
-cleanup()
-{
- system("/bin/rm -f /tmp/" TEMPNAM_PREFIX "*");
-}
Modified: trunk/src/http.h
==============================================================================
--- trunk/src/http.h (original)
+++ trunk/src/http.h Sun Feb 24 08:50:44 2008
@@ -27,25 +27,18 @@
#endif /* HAVE_CONFIG_H */
#include <glib.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
#include <stdio.h>
-#include <ghttp.h>
#include <errno.h>
#define DEST_PORT 80
#define RECV_BUF_SIZE 20000
-#define TEMPNAM_PREFIX "tlgN"
-
#define TEST_TELEGNOME 1
/* #undef TEST_TELEGNOME */
-#define PAGE_MINSIZE 4000 /* min size for file to be considered 'good' result */
-
int get_page_entry (const gchar *page_entry);
-gint get_the_image (char **);
+gint get_the_image (GdkPixbuf **pixbuf);
int get_http_query (gchar* buffer, gint page_nr, gint subpage_nr);
-/* gets rid of all those tmp files */
-void cleanup();
-
#endif /* _HTTP_H_ */
Modified: trunk/src/main.h
==============================================================================
--- trunk/src/main.h (original)
+++ trunk/src/main.h Sun Feb 24 08:50:44 2008
@@ -47,12 +47,9 @@
/* errors from HTTP connections */
#define TG_OK 0
-#define TG_ERR_TOOSMALL 1 /* file's too small to be a valid page */
-#define TG_ERR_GHTTP 2
-#define TG_ERR_NOCONNECTION 3 /* internet connection failed */
-#define TG_ERR_FILE 4 /* error opening file */
-#define TG_ERR_CHMOD 5 /* chmod on file doesn't work */
-#define TG_ERR_HTTPQUERY 6 /* error getting http query */
+#define TG_ERR_PIXBUF 1 /* corrupt image */
+#define TG_ERR_VFS 2
+#define TG_ERR_HTTPQUERY 3 /* error getting http query */
#define TG_NOTFOUND_PIXMAP "telegnome/testbeeld.png"
#define TG_LOGO_PIXMAP "telegnome/telegnome-logo.png"
Modified: trunk/src/pixpack.c
==============================================================================
--- trunk/src/pixpack.c (original)
+++ trunk/src/pixpack.c Sun Feb 24 08:50:44 2008
@@ -126,13 +126,15 @@
pixpack = PIXPACK(object);
private = pixpack->private_data;
- if (private->pixbuf)
- g_object_unref(private->pixbuf);
- if (private->scaled_pixbuf)
- g_object_unref(private->scaled_pixbuf);
+ if (private) {
+ if (private->pixbuf)
+ g_object_unref(private->pixbuf);
+ if (private->scaled_pixbuf)
+ g_object_unref(private->scaled_pixbuf);
- g_free(pixpack->private_data);
- pixpack->private_data = NULL;
+ g_free(pixpack->private_data);
+ pixpack->private_data = NULL;
+ }
if (GTK_OBJECT_CLASS(parent_class)->destroy)
(*GTK_OBJECT_CLASS(parent_class)->destroy)(object);
@@ -260,16 +262,17 @@
void
-pixpack_load_image_file(PixPack *pixpack, gchar *filename)
+pixpack_load_image(PixPack *pixpack, GdkPixbuf *pixbuf)
{
PixPackPrivate *private;
- GError *error = NULL;
g_return_if_fail(IS_PIXPACK(pixpack));
private = pixpack->private_data;
- private->pixbuf = gdk_pixbuf_new_from_file(filename, &error);
- /* TODO handle errors */
+ if (private->pixbuf)
+ g_object_unref(private->pixbuf);
+ private->pixbuf = pixbuf;
+ g_object_ref(private->pixbuf);
/* this forces a repaint */
Modified: trunk/src/pixpack.h
==============================================================================
--- trunk/src/pixpack.h (original)
+++ trunk/src/pixpack.h Sun Feb 24 08:50:44 2008
@@ -58,7 +58,7 @@
GtkType pixpack_get_type ( void );
-void pixpack_load_image_file ( PixPack* pixpack, gchar* filename );
+void pixpack_load_image ( PixPack* pixpack, GdkPixbuf* pixbuf );
GtkWidget* pixpack_new ( void );
void pixpack_set_autosize ( PixPack* pixpack, gboolean value );
Modified: trunk/src/view.c
==============================================================================
--- trunk/src/view.c (original)
+++ trunk/src/view.c Sun Feb 24 08:50:44 2008
@@ -65,14 +65,14 @@
}
gint
-tele_view_update_pixmap(TeleView *view, gchar *filename)
+tele_view_update_pixmap(TeleView *view, GdkPixbuf *pixbuf)
{
gint width, height;
- if (g_file_test(filename, G_FILE_TEST_EXISTS)) {
- pixpack_load_image_file( PIXPACK(view->pixpack), filename);
+ if (pixbuf) {
+ pixpack_load_image(PIXPACK(view->pixpack), pixbuf);
} else {
- /* no existing file, resize to a default and print a warning */
- g_warning("File doesnt exist: %s\n", filename);
+ /* no pixbuf, resize to a default and print a warning */
+ g_warning("pixbuf == NULL\n");
gtk_widget_set_usize(GTK_WIDGET(view->pixpack), 200, 150);
}
@@ -83,24 +83,26 @@
tele_view_update_page(TeleView *view, int *major_nr, int *minor_nr)
{
gint retval;
- gchar *picfile;
+ GdkPixbuf *pixbuf;
+ GError *error = NULL;
/* save these the restore the, if necessary */
gint old_page= *major_nr;
gint old_subpage= *major_nr;
/* make http-request, returns the file of the saved thing */
- retval= get_the_image(&picfile);
+ retval= get_the_image(&pixbuf);
if (TG_OK == retval) {
- tele_view_update_pixmap(view, picfile);
+ tele_view_update_pixmap(view, pixbuf);
+ g_object_unref(pixbuf);
return 0;
} else {
switch(retval) {
- case TG_ERR_TOOSMALL: /* we got an error from the webpage */
+ case TG_ERR_PIXBUF: /* we got an error from the webpage */
/* maybe we forgot the subpage nr, or used it when we shouldn't */
*minor_nr= (0 == *minor_nr)?1:0;
- if (TG_OK != get_the_image(&picfile)) {
+ if (TG_OK != get_the_image(&pixbuf)) {
if (*minor_nr!=1) {
/* maybe we've run out of subpages, go to next main page */
*minor_nr=0;
@@ -112,25 +114,20 @@
*major_nr= old_page; /* restore */
*minor_nr= old_subpage;
update_entry(*major_nr, *minor_nr);
- tele_view_update_pixmap(view, gnome_pixmap_file(TG_NOTFOUND_PIXMAP));
+ pixbuf = gdk_pixbuf_new_from_file(
+ gnome_pixmap_file(TG_NOTFOUND_PIXMAP), &error);
+ tele_view_update_pixmap(view, pixbuf);
+ g_object_unref(pixbuf);
return -1;
}
} else {
- tele_view_update_pixmap(view, picfile);
+ tele_view_update_pixmap(view, pixbuf);
+ g_object_unref(pixbuf);
return 0;
}
- case TG_ERR_GHTTP:
+ case TG_ERR_VFS:
tele_view_error(view, _("Error making HTTP connection"));
return -1;
- case TG_ERR_NOCONNECTION:
- tele_view_error(view, _("No connection"));
- return -1;
- case TG_ERR_FILE:
- tele_view_error(view, _("Error using temporary file"));
- return -1;
- case TG_ERR_CHMOD:
- tele_view_error(view, _("Error setting permissions on temporary file"));
- return -1;
case TG_ERR_HTTPQUERY:
tele_view_error(view, _("Internal error in HTTP query code"));
return -1;
@@ -145,6 +142,7 @@
GtkWidget *
tele_view_get_widget(TeleView *view)
{
+ g_object_ref(view->box);
return view->box;
}
@@ -153,6 +151,7 @@
{
/* clean up */
g_object_unref(view->box);
+ view->box = NULL;
g_free(view);
}
Modified: trunk/src/view.h
==============================================================================
--- trunk/src/view.h (original)
+++ trunk/src/view.h Sun Feb 24 08:50:44 2008
@@ -51,7 +51,7 @@
TeleView *tele_view_new();
void tele_view_set_error_handler(TeleView *view, void (*e)(const char *));
void tele_view_error(TeleView *view, const char *c);
-gint tele_view_update_pixmap(TeleView *view, gchar *filename);
+gint tele_view_update_pixmap(TeleView *view, GdkPixbuf *pixbuf);
gint tele_view_update_page(TeleView *view, int *major_nr, int *minor_nr);
GtkWidget *tele_view_get_widget(TeleView *view);
void tele_view_free();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]