Skip to content

Commit

Permalink
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 55 deletions.
21 changes: 12 additions & 9 deletions applets/clock/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ CLOCK_CPPFLAGS = \
-I$(srcdir)/../../libmate-panel-applet \
-I$(top_builddir)/libmate-panel-applet \
-DMATELOCALEDIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
-DBUILDERDIR=\""$(uidir)"\" \
-DCLOCK_MENU_UI_DIR=\""$(xmluidir)"\" \
-DICONDIR=\""$(datadir)/mate-panel/pixmaps"\" \
-DMATEWEATHER_I_KNOW_THIS_IS_UNSTABLE

CLOCK_LDADD = \
Expand Down Expand Up @@ -122,6 +119,8 @@ clock-typebuiltins.h: @REBUILD@ $(clock_enum_headers)
BUILT_SOURCES = \
clock-marshallers.c \
clock-marshallers.h \
clock-resources.c \
clock-resources.h \
clock-typebuiltins.c \
clock-typebuiltins.h

Expand Down Expand Up @@ -149,11 +148,15 @@ org.mate.panel.applet.ClockAppletFactory.service: $(service_in_files)
$< > $@
endif

uidir = $(datadir)/mate-panel/ui
ui_DATA = clock.ui
ui_FILES = \
clock.ui \
clock-menu.xml

xmluidir = $(datadir)/mate-panel/ui
xmlui_DATA = clock-menu.xml
clock-resources.c: clock.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/clock.gresource.xml)
$(AM_V_GEN)$(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate --c-name clock $<

clock-resources.h: clock.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/clock.gresource.xml)
$(AM_V_GEN)$(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate --c-name clock $<

clock_gschemas_in = org.mate.panel.applet.clock.gschema.xml.in
gsettings_SCHEMAS = $(clock_gschemas_in:.xml.in=.xml)
Expand All @@ -164,8 +167,8 @@ gsettings_SCHEMAS = $(clock_gschemas_in:.xml.in=.xml)
EXTRA_DIST = \
org.mate.panel.ClockApplet.mate-panel-applet.in.in \
$(clock_gschemas_in) \
$(xmlui_DATA) \
$(ui_DATA) \
$(ui_FILES) \
clock.gresource.xml \
clock-marshallers.list \
$(service_in_files)

Expand Down
23 changes: 14 additions & 9 deletions applets/clock/clock-face.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <math.h>
#include <time.h>

#include "clock.h"
#include "clock-face.h"
#include "clock-location.h"
#include "clock-utils.h"
Expand Down Expand Up @@ -436,18 +437,22 @@ clock_face_load_face (ClockFace *this, gint width, gint height)
return;
}

/* The pixbuf is not cached, let's load it */
name = g_strconcat (ICONDIR, "/clock-face-", size_string[priv->size],
"-", daytime_string[priv->timeofday], ".svg",
NULL);
priv->face_pixbuf = clock_utils_pixbuf_from_svg_file_at_size (name, width, height);
/* The pixbuf is not cached, let's load it */
name = g_strconcat (CLOCK_RESOURCE_PATH "icons/",
"clock-face-", size_string[priv->size],
"-", daytime_string[priv->timeofday], ".svg",
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 = clock_utils_pixbuf_from_svg_file_at_size (name, width, height);
g_free (name);
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);
}

/* Save the found pixbuf in the cache */
Expand Down
35 changes: 25 additions & 10 deletions applets/clock/clock-map.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,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] = { 0 };
Expand Down Expand Up @@ -135,8 +135,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);
}
}
}

Expand Down Expand Up @@ -208,11 +217,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);
Expand Down
22 changes: 18 additions & 4 deletions applets/clock/clock-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,28 @@ clock_utils_display_help (GtkWidget *widget,
}

GdkPixbuf *
clock_utils_pixbuf_from_svg_file_at_size (const char *name, int width, int height)
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;

handle = rsvg_handle_new_from_file (name, NULL);
stream = g_resources_open_stream (resource, 0, NULL);
if (!stream)
goto out;

handle = rsvg_handle_new ();
if (!handle)
return NULL;
goto out;

if (!rsvg_handle_read_stream_sync (handle, stream, NULL, NULL))
goto out;

rsvg_handle_get_dimensions (handle, &svg_dimensions);

Expand All @@ -155,7 +165,11 @@ clock_utils_pixbuf_from_svg_file_at_size (const char *name, int width, int heigh
pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0, width, height);
cairo_surface_destroy (surface);

rsvg_handle_close (handle, NULL);
out:
if (handle)
rsvg_handle_close (handle, NULL);
if (stream)
g_object_unref (stream);

return pixbuf;
}
Expand Down
4 changes: 3 additions & 1 deletion applets/clock/clock-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ void clock_utils_display_help (GtkWidget *widget,
const char *doc_id,
const char *link_id);

GdkPixbuf * clock_utils_pixbuf_from_svg_file_at_size (const char *name, int width, int height);
GdkPixbuf *clock_utils_pixbuf_from_svg_resource_at_size (const char *resource,
int width,
int height);

#ifdef __cplusplus
}
Expand Down
22 changes: 4 additions & 18 deletions applets/clock/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -2377,9 +2377,6 @@ fill_clock_applet (MatePanelApplet *applet)
ClockData *cd;
GtkActionGroup *action_group;
GtkAction *action;
gchar *ui_path;
char *filename;
GError *error;

mate_panel_applet_set_flags (applet, MATE_PANEL_APPLET_EXPAND_MINOR);

Expand All @@ -2394,17 +2391,7 @@ fill_clock_applet (MatePanelApplet *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);

Expand Down Expand Up @@ -2436,10 +2423,9 @@ fill_clock_applet (MatePanelApplet *applet)
clock_menu_actions,
G_N_ELEMENTS (clock_menu_actions),
cd);
ui_path = g_build_filename (CLOCK_MENU_UI_DIR, "clock-menu.xml", NULL);
mate_panel_applet_setup_menu_from_file (MATE_PANEL_APPLET (cd->applet),
ui_path, action_group);
g_free (ui_path);
mate_panel_applet_setup_menu_from_resource (MATE_PANEL_APPLET (cd->applet),
CLOCK_RESOURCE_PATH "clock-menu.xml",
action_group);

if (mate_panel_applet_get_locked_down (MATE_PANEL_APPLET (cd->applet))) {
action = gtk_action_group_get_action (action_group, "ClockPreferences");
Expand Down
17 changes: 17 additions & 0 deletions applets/clock/clock.gresource.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/mate/panel/applet/clock">
<file compressed="true">clock.ui</file>
<file compressed="true">clock-menu.xml</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>
1 change: 1 addition & 0 deletions applets/clock/clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ extern "C" {
#endif

#define CLOCK_ICON "mate-panel-clock"
#define CLOCK_RESOURCE_PATH "/org/mate/panel/applet/clock/"
#define CLOCK_SCHEMA "org.mate.panel.applet.clock"

#ifdef __cplusplus
Expand Down
6 changes: 2 additions & 4 deletions applets/clock/pixmaps/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
icondir = $(datadir)/mate-panel/pixmaps
icon_DATA = \
clock-calendar-icon.png \
icon_FILES = \
clock-face-large.svg \
clock-face-small.svg \
clock-face-small-morning.svg \
Expand All @@ -14,7 +12,7 @@ icon_DATA = \

EXTRA_DIST = \
clock-map.svg \
$(icon_DATA)
$(icon_FILES)

MAINTAINERCLEANFILES = Makefile.in

Expand Down
Binary file removed applets/clock/pixmaps/clock-calendar-icon.png
Binary file not shown.

0 comments on commit dcb6025

Please sign in to comment.