Commit aa2895d3 authored by Vincent Untz's avatar Vincent Untz
Browse files

clock: Convert to GResource

parent 9fbca7df
......@@ -52,9 +52,6 @@ CLOCK_CPPFLAGS = \
-I$(srcdir)/../../libpanel-applet \
-I$(top_builddir)/libpanel-applet \
-DGNOMELOCALEDIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
-DBUILDERDIR=\""$(uidir)"\" \
-DCLOCK_MENU_UI_DIR=\""$(xmluidir)"\" \
-DICONDIR=\""$(datadir)/gnome-panel/pixmaps"\" \
-DCLOCK_EDS_ICONDIR="\"$(CLOCK_EDS_ICONDIR)\"" \
-DGWEATHER_I_KNOW_THIS_IS_UNSTABLE
......@@ -133,6 +130,8 @@ clock-typebuiltins.h: $(clock_enum_headers)
BUILT_SOURCES = \
clock-marshallers.c \
clock-marshallers.h \
clock-resources.c \
clock-resources.h \
clock-typebuiltins.c \
clock-typebuiltins.h
......@@ -160,11 +159,15 @@ org.gnome.panel.applet.ClockAppletFactory.service: $(service_in_files)
$< > $@
endif
uidir = $(datadir)/gnome-panel/ui
ui_DATA = clock.ui
ui_FILES = \
clock.ui \
clock-menu.xml
xmluidir = $(datadir)/gnome-panel/ui
xmlui_DATA = clock-menu.xml
clock-resources.c: clock.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies clock.gresource.xml)
$(AM_V_GEN)$(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate --c-name clock $(srcdir)/$<
clock-resources.h: clock.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies clock.gresource.xml)
$(AM_V_GEN)$(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate --c-name clock $(srcdir)/$<
schemasdir = $(GCONF_SCHEMA_FILE_DIR)
schemas_in_files = clock.schemas.in
......@@ -188,8 +191,7 @@ endif
EXTRA_DIST = \
org.gnome.panel.ClockApplet.panel-applet.in.in \
$(schemas_in_files) \
$(xmlui_DATA) \
$(ui_DATA) \
$(ui_FILES) \
clock-marshallers.list \
$(service_in_files)
......
......@@ -15,10 +15,10 @@
#include <math.h>
#include <time.h>
#include <librsvg/rsvg.h>
#include "clock.h"
#include "clock-face.h"
#include "clock-location.h"
#include "clock-utils.h"
static GHashTable *pixbuf_cache = NULL;
......@@ -434,21 +434,20 @@ clock_face_load_face (ClockFace *this, gint width, gint height)
}
/* The pixbuf is not cached, let's load it */
name = g_strconcat (ICONDIR, "/clock-face-", size_string[priv->size],
name = g_strconcat (CLOCK_RESOURCE_PATH "icons/",
"clock-face-", size_string[priv->size],
"-", daytime_string[priv->timeofday], ".svg",
NULL);
priv->face_pixbuf = rsvg_pixbuf_from_file_at_size (name,
width, height,
NULL);
priv->face_pixbuf = clock_utils_pixbuf_from_svg_resource_at_size (name,
width, height);
g_free (name);
if (!priv->face_pixbuf) {
name = g_strconcat (ICONDIR, "/clock-face-",
size_string[priv->size], ".svg", NULL);
priv->face_pixbuf = rsvg_pixbuf_from_file_at_size (name,
width,
height,
NULL);
name = g_strconcat (CLOCK_RESOURCE_PATH "icons/",
"clock-face-", size_string[priv->size], ".svg",
NULL);
priv->face_pixbuf = clock_utils_pixbuf_from_svg_resource_at_size (name,
width, height);
g_free (name);
}
......
......@@ -28,9 +28,9 @@ enum {
};
static char *marker_files[MARKER_NB] = {
ICONDIR "/clock-map-location-marker.png",
ICONDIR "/clock-map-location-hilight.png",
ICONDIR "/clock-map-location-current.png"
"clock-map-location-marker.png",
"clock-map-location-hilight.png",
"clock-map-location-current.png"
};
static guint signals[LAST_SIGNAL];
......@@ -136,8 +136,17 @@ clock_map_init (ClockMap *this)
g_assert (sizeof (marker_files)/sizeof (char *) == MARKER_NB);
for (i = 0; i < MARKER_NB; i++) {
priv->location_marker_pixbuf[i] = gdk_pixbuf_new_from_file
(marker_files[i], NULL);
char *resource;
GInputStream *stream;
resource = g_strconcat (CLOCK_RESOURCE_PATH "icons/", marker_files[i], NULL);
stream = g_resources_open_stream (resource, 0, NULL);
g_free (resource);
if (stream != NULL) {
priv->location_marker_pixbuf[i] = gdk_pixbuf_new_from_stream (stream, NULL, NULL);
g_object_unref (stream);
}
}
}
......@@ -209,11 +218,17 @@ clock_map_refresh (ClockMap *this)
}
if (!priv->stock_map_pixbuf) {
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file_at_scale
(ICONDIR "/clock-map.png",
priv->width, priv->height, FALSE, NULL);
priv->stock_map_pixbuf = pixbuf;
GInputStream *stream = g_resources_open_stream (CLOCK_RESOURCE_PATH "icons/clock-map.png",
0, NULL);
if (stream != NULL) {
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_stream_at_scale (stream,
priv->width, priv->height,
FALSE,
NULL, NULL);
g_object_unref (stream);
priv->stock_map_pixbuf = pixbuf;
}
}
clock_map_place_locations (this);
......
......@@ -34,6 +34,9 @@
#include <gtk/gtk.h>
#include <librsvg/rsvg.h>
#include <librsvg/rsvg-cairo.h>
#include "clock.h"
#include "clock-utils.h"
......@@ -125,3 +128,50 @@ clock_utils_display_help (GtkWidget *widget,
gtk_widget_show (dialog);
}
}
GdkPixbuf *
clock_utils_pixbuf_from_svg_resource_at_size (const char *resource,
int width,
int height)
{
GInputStream *stream = NULL;
RsvgHandle *handle = NULL;
RsvgDimensionData svg_dimensions;
GdkPixbuf *pixbuf = NULL;
cairo_surface_t *surface = NULL;
cairo_matrix_t matrix;
cairo_t *cr = NULL;
stream = g_resources_open_stream (resource, 0, NULL);
if (!stream)
goto out;
handle = rsvg_handle_new ();
if (!handle)
goto out;
if (!rsvg_handle_read_stream_sync (handle, stream, NULL, NULL))
goto out;
rsvg_handle_get_dimensions (handle, &svg_dimensions);
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
cr = cairo_create (surface);
cairo_matrix_init_scale (&matrix,
((double) width / svg_dimensions.width),
((double) height / svg_dimensions.height));
cairo_transform (cr, &matrix);
rsvg_handle_render_cairo (handle, cr);
cairo_destroy (cr);
pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0, width, height);
cairo_surface_destroy (surface);
out:
if (handle)
rsvg_handle_close (handle, NULL);
if (stream)
g_object_unref (stream);
return pixbuf;
}
......@@ -48,6 +48,10 @@ void clock_utils_display_help (GtkWidget *widget,
const char *doc_id,
const char *link_id);
GdkPixbuf *clock_utils_pixbuf_from_svg_resource_at_size (const char *resource,
int width,
int height);
G_END_DECLS
#endif /* __CLOCK_UTILS_H__ */
......@@ -2432,9 +2432,6 @@ fill_clock_applet (PanelApplet *applet)
ClockData *cd;
GtkActionGroup *action_group;
GtkAction *action;
gchar *ui_path;
char *filename;
GError *error;
panel_applet_add_preferences (applet, CLOCK_SCHEMA_DIR, NULL);
panel_applet_set_flags (applet, PANEL_APPLET_EXPAND_MINOR);
......@@ -2450,17 +2447,7 @@ fill_clock_applet (PanelApplet *applet)
cd->builder = gtk_builder_new ();
gtk_builder_set_translation_domain (cd->builder, GETTEXT_PACKAGE);
filename = g_build_filename (BUILDERDIR, "clock.ui", NULL);
error = NULL;
gtk_builder_add_from_file (cd->builder, filename, &error);
if (error) {
g_warning ("Error loading \"%s\": %s",
filename, error->message);
g_error_free (error);
}
g_free (filename);
gtk_builder_add_from_resource (cd->builder, CLOCK_RESOURCE_PATH "clock.ui", NULL);
create_clock_widget (cd);
......@@ -2492,10 +2479,9 @@ fill_clock_applet (PanelApplet *applet)
clock_menu_actions,
G_N_ELEMENTS (clock_menu_actions),
cd);
ui_path = g_build_filename (CLOCK_MENU_UI_DIR, "clock-menu.xml", NULL);
panel_applet_setup_menu_from_file (PANEL_APPLET (cd->applet),
ui_path, action_group);
g_free (ui_path);
panel_applet_setup_menu_from_resource (PANEL_APPLET (cd->applet),
CLOCK_RESOURCE_PATH "clock-menu.xml",
action_group);
action = gtk_action_group_get_action (action_group, "ClockPreferences");
g_object_bind_property (cd->applet, "locked-down",
......
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gnome/panel/applet/clock">
<file compressed="true">clock.ui</file>
<file compressed="true">clock-menu.xml</file>
<file alias="icons/clock-calendar-icon.png">pixmaps/clock-calendar-icon.png</file>
<file alias="icons/clock-face-large.svg">pixmaps/clock-face-large.svg</file>
<file alias="icons/clock-face-small.svg">pixmaps/clock-face-small.svg</file>
<file alias="icons/clock-face-small-morning.svg">pixmaps/clock-face-small-morning.svg</file>
<file alias="icons/clock-face-small-day.svg">pixmaps/clock-face-small-day.svg</file>
<file alias="icons/clock-face-small-evening.svg">pixmaps/clock-face-small-evening.svg</file>
<file alias="icons/clock-face-small-night.svg">pixmaps/clock-face-small-night.svg</file>
<file alias="icons/clock-map.png">pixmaps/clock-map.png</file>
<file alias="icons/clock-map-location-marker.png">pixmaps/clock-map-location-marker.png</file>
<file alias="icons/clock-map-location-current.png">pixmaps/clock-map-location-current.png</file>
<file alias="icons/clock-map-location-hilight.png">pixmaps/clock-map-location-hilight.png</file>
</gresource>
</gresources>
......@@ -30,6 +30,7 @@
G_BEGIN_DECLS
#define CLOCK_ICON "gnome-panel-clock"
#define CLOCK_RESOURCE_PATH "/org/gnome/panel/applet/clock/"
#define CLOCK_SCHEMA_DIR "/schemas/apps/clock_applet/prefs"
G_END_DECLS
......
icondir = $(datadir)/gnome-panel/pixmaps
icon_DATA = \
icon_FILES = \
clock-calendar-icon.png \
clock-face-large.svg \
clock-face-small.svg \
......@@ -14,7 +13,7 @@ icon_DATA = \
EXTRA_DIST = \
clock-map.svg \
$(icon_DATA)
$(icon_FILES)
MAINTAINERCLEANFILES = Makefile.in
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment