summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
Diffstat (limited to 'gtk')
-rw-r--r--gtk/gui.c41
-rw-r--r--gtk/res/netsurf.gresource.xml9
-rw-r--r--gtk/resources.c9
-rw-r--r--gtk/throbber.c85
-rw-r--r--gtk/throbber.h2
5 files changed, 60 insertions, 86 deletions
diff --git a/gtk/gui.c b/gtk/gui.c
index 90991dae9..1df7bfc56 100644
--- a/gtk/gui.c
+++ b/gtk/gui.c
@@ -84,8 +84,6 @@ GdkPixbuf *win_default_icon_pixbuf; /** default window icon pixbuf */
GtkBuilder *warning_builder;
-#define THROBBER_FRAMES 9
-
char **respaths; /** resource search path vector */
/**
@@ -125,36 +123,6 @@ nsgtk_init_resource(const char *resource_path)
return respath;
}
-/* This is an ugly hack to just get the new-style throbber going.
- * It, along with the PNG throbber loader, need making more generic.
- */
-static bool nsgtk_throbber_init(char **respath, int framec)
-{
- char **filenames;
- char targetname[PATH_MAX];
- int frame_num;
- bool ret;
-
- filenames = calloc(framec, sizeof(char *));
- if (filenames == NULL)
- return false;
-
- for (frame_num = 0; frame_num < framec; frame_num++) {
- snprintf(targetname, PATH_MAX, "throbber/throbber%d.png", frame_num);
- filenames[frame_num] = filepath_find(respath, targetname);
- }
-
- ret = nsgtk_throbber_initialise_from_png(frame_num, filenames);
-
- for (frame_num = 0; frame_num < framec; frame_num++) {
- free(filenames[frame_num]);
- }
- free(filenames);
-
- return ret;
-
-}
-
/**
* Set option defaults for gtk frontend.
@@ -307,9 +275,12 @@ static nserror nsgtk_init(int argc, char** argv, char **respath)
toolbar_indices_file_location = filepath_find(respath, "toolbarIndices");
LOG("Using '%s' as custom toolbar settings file", toolbar_indices_file_location);
- /* load throbber images */
- if (nsgtk_throbber_init(respath, THROBBER_FRAMES) == false)
- die("Unable to load throbber image.\n");
+ /* initialise throbber */
+ error = nsgtk_throbber_init();
+ if (error != NSERROR_OK) {
+ LOG("Unable to initialise throbber.");
+ return error;
+ }
/* Initialise completions - cannot fail */
nsgtk_completion_init();
diff --git a/gtk/res/netsurf.gresource.xml b/gtk/res/netsurf.gresource.xml
index 09683faa9..55f3a3dc8 100644
--- a/gtk/res/netsurf.gresource.xml
+++ b/gtk/res/netsurf.gresource.xml
@@ -30,5 +30,14 @@
<file preprocess="to-pixdata">favicon.png</file>
<file preprocess="to-pixdata">netsurf.xpm</file>
<file preprocess="to-pixdata">menu_cursor.png</file>
+ <file preprocess="to-pixdata">throbber/throbber0.png</file>
+ <file preprocess="to-pixdata">throbber/throbber1.png</file>
+ <file preprocess="to-pixdata">throbber/throbber2.png</file>
+ <file preprocess="to-pixdata">throbber/throbber3.png</file>
+ <file preprocess="to-pixdata">throbber/throbber4.png</file>
+ <file preprocess="to-pixdata">throbber/throbber5.png</file>
+ <file preprocess="to-pixdata">throbber/throbber6.png</file>
+ <file preprocess="to-pixdata">throbber/throbber7.png</file>
+ <file preprocess="to-pixdata">throbber/throbber8.png</file>
</gresource>
</gresources>
diff --git a/gtk/resources.c b/gtk/resources.c
index d28414d60..d1c3c86fc 100644
--- a/gtk/resources.c
+++ b/gtk/resources.c
@@ -78,6 +78,15 @@ static struct nsgtk_resource_s gen_resource[] = {
{ "favicon.png", 11, NSGTK_RESOURCE_FILE, NULL },
{ "netsurf.xpm", 11, NSGTK_RESOURCE_FILE, NULL },
{ "menu_cursor.png", 15, NSGTK_RESOURCE_FILE, NULL },
+ { "throbber/throbber0.png", 22, NSGTK_RESOURCE_FILE, NULL },
+ { "throbber/throbber1.png", 22, NSGTK_RESOURCE_FILE, NULL },
+ { "throbber/throbber2.png", 22, NSGTK_RESOURCE_FILE, NULL },
+ { "throbber/throbber3.png", 22, NSGTK_RESOURCE_FILE, NULL },
+ { "throbber/throbber4.png", 22, NSGTK_RESOURCE_FILE, NULL },
+ { "throbber/throbber5.png", 22, NSGTK_RESOURCE_FILE, NULL },
+ { "throbber/throbber6.png", 22, NSGTK_RESOURCE_FILE, NULL },
+ { "throbber/throbber7.png", 22, NSGTK_RESOURCE_FILE, NULL },
+ { "throbber/throbber8.png", 22, NSGTK_RESOURCE_FILE, NULL },
{ NULL, 0, NSGTK_RESOURCE_FILE, NULL },
};
diff --git a/gtk/throbber.c b/gtk/throbber.c
index 8726763ed..725df4626 100644
--- a/gtk/throbber.c
+++ b/gtk/throbber.c
@@ -20,76 +20,61 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
-#ifdef WITH_GIF
-#include <libnsgif.h>
-#endif
+#include <gtk/gtk.h>
+
#include "utils/log.h"
+
+#include "gtk/resources.h"
#include "gtk/throbber.h"
-#include "gtk/bitmap.h"
struct nsgtk_throbber *nsgtk_throbber = NULL;
-/**
- * Creates the throbber using a PNG for each frame.
- *
- * The number of frames must be at least two. The first frame is the
- * inactive frame, others are the active frames.
- *
- * \param frames The number of frames. Must be at least two.
- * \param frame_files Filenames of PNGs containing frames.
- * \return true on success.
- */
-bool nsgtk_throbber_initialise_from_png(const int frames, char** frame_files)
+#define THROBBER_FRAMES 9
+#define THROBBER_FMT "throbber/throbber%d.png"
+
+/* exported interface documented in gtk/throbber.h */
+nserror nsgtk_throbber_init(void)
{
- GError *err = NULL;
struct nsgtk_throbber *throb; /**< structure we generate */
- bool errors_when_loading = false; /**< true if a frame failed */
- int frame_loop;
-
- if (frames < 2) {
- /* we need at least two frames - one for idle, one for active */
- LOG("Insufficent number of frames in throbber animation!");
- LOG("(called with %d frames, where 2 is a minimum.)", frames);
- return false;
- }
-
+ int frame;
+ char resname[] = THROBBER_FMT;
+ nserror res = NSERROR_OK;
+
throb = malloc(sizeof(*throb));
- if (throb == NULL)
- return false;
+ if (throb == NULL) {
+ return NSERROR_NOMEM;
+ }
- throb->nframes = frames;
- throb->framedata = malloc(sizeof(GdkPixbuf *) * throb->nframes);
+ throb->framedata = malloc(sizeof(GdkPixbuf *) * THROBBER_FRAMES);
if (throb->framedata == NULL) {
free(throb);
return false;
}
-
- for (frame_loop = 0; frame_loop < frames; frame_loop++) {
- throb->framedata[frame_loop] = gdk_pixbuf_new_from_file(frame_files[frame_loop], &err);
- if (err != NULL) {
- LOG("Error when loading %s: %s (%d)", frame_files[frame_loop], err->message, err->code);
- throb->framedata[frame_loop] = NULL;
- errors_when_loading = true;
+
+ for (frame = 0; frame < THROBBER_FRAMES; frame++) {
+ snprintf(resname, sizeof(resname), THROBBER_FMT, frame);
+ res = nsgdk_pixbuf_new_from_resname(resname,
+ throb->framedata + frame);
+ if (res != NSERROR_OK) {
+ break;
}
+ LOG("%s",resname);
}
-
- if (errors_when_loading == true) {
- for (frame_loop = 0; frame_loop < frames; frame_loop++) {
- if (throb->framedata[frame_loop] != NULL)
- g_object_unref(throb->framedata[frame_loop]);
- }
- free(throb->framedata);
- free(throb);
-
- return false;
+ if (frame < 1) {
+ /* we need at least two frames - one for idle, one for active */
+ LOG("Insufficent number of frames (%d) in throbber animation.", frame);
+ res = NSERROR_INIT_FAILED;
}
-
+
+ throb->nframes = frame;
nsgtk_throbber = throb;
-
- return true;
+ return res;
+
+
}
+
void nsgtk_throbber_finalise(void)
{
int i;
diff --git a/gtk/throbber.h b/gtk/throbber.h
index 1463c9b26..e0b47e15c 100644
--- a/gtk/throbber.h
+++ b/gtk/throbber.h
@@ -29,7 +29,7 @@ struct nsgtk_throbber
extern struct nsgtk_throbber *nsgtk_throbber;
-bool nsgtk_throbber_initialise_from_png(const int frames, char** frame_files);
+nserror nsgtk_throbber_init(void);
void nsgtk_throbber_finalise(void);
#endif /* __GTK_THROBBER_H__ */