Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Gweather #1075

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ requires:
- gobject-introspection
- itstool
- libcanberra
- libmateweather
- libgweather
- libsm
- libwnck3
- make
Expand Down Expand Up @@ -40,10 +40,10 @@ requires:
- libgirepository1.0-dev
- libglib2.0-dev
- libgtk-3-dev
- libgweather-3-dev
- libice-dev
- libmate-desktop-dev
- libmate-menu-dev
- libmateweather-dev
- libpango1.0-dev
- librsvg2-dev
- libsm-dev
Expand Down Expand Up @@ -71,7 +71,7 @@ requires:
- gtk3-devel
- libSM-devel
- libcanberra-devel
- libmateweather-devel
- libgweather-devel
- librsvg2-devel
- libwnck3-devel
- make
Expand All @@ -97,10 +97,10 @@ requires:
- libgirepository1.0-dev
- libglib2.0-dev
- libgtk-3-dev
- libgweather-3-dev
- libice-dev
- libmate-desktop-dev
- libmate-menu-dev
- libmateweather-dev
- libpango1.0-dev
- librsvg2-dev
- libsm-dev
Expand Down
2 changes: 1 addition & 1 deletion applets/clock/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ CLOCK_CPPFLAGS = \
-I$(srcdir)/../../libmate-panel-applet \
-I$(top_builddir)/libmate-panel-applet \
-DMATELOCALEDIR=\""$(datadir)/locale"\" \
-DMATEWEATHER_I_KNOW_THIS_IS_UNSTABLE
-DGWEATHER_I_KNOW_THIS_IS_UNSTABLE

CLOCK_LDADD = \
../../libmate-panel-applet/libmate-panel-applet-4.la \
Expand Down
113 changes: 76 additions & 37 deletions applets/clock/clock-location-tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ typedef struct {
G_DEFINE_TYPE_WITH_PRIVATE (ClockLocationTile, clock_location_tile, GTK_TYPE_BIN)

static void clock_location_tile_finalize (GObject *);
static void clock_location_tile_dispose (GObject *g_obj);

static void clock_location_tile_fill (ClockLocationTile *this);
static void update_weather_icon (ClockLocation *loc, WeatherInfo *info, gpointer data);
static void update_weather_icon (ClockLocation *loc, GWeatherInfo *info, gpointer data);
static gboolean weather_tooltip (GtkWidget *widget,
gint x, gint y,
gboolean keyboard_mode,
Expand All @@ -68,7 +69,7 @@ clock_location_tile_new (ClockLocation *loc,
ClockLocationTile *this;
ClockLocationTilePrivate *priv;

this = g_object_new (CLOCK_LOCATION_TILE_TYPE, NULL);
this = g_object_new (CLOCK_TYPE_LOCATION_TILE, NULL);

priv = clock_location_tile_get_instance_private (this);

Expand All @@ -77,7 +78,6 @@ clock_location_tile_new (ClockLocation *loc,

clock_location_tile_fill (this);

update_weather_icon (loc, clock_location_get_weather_info (loc), this);
gtk_widget_set_has_tooltip (priv->weather_icon, TRUE);

g_signal_connect (priv->weather_icon, "query-tooltip",
Expand All @@ -93,7 +93,8 @@ clock_location_tile_class_init (ClockLocationTileClass *this_class)
{
GObjectClass *g_obj_class = G_OBJECT_CLASS (this_class);

g_obj_class->finalize = clock_location_tile_finalize;
g_obj_class->dispose = clock_location_tile_dispose;
//g_obj_class->finalize = clock_location_tile_finalize;

signals[TILE_PRESSED] = g_signal_new ("tile-pressed",
G_TYPE_FROM_CLASS (g_obj_class),
Expand Down Expand Up @@ -130,6 +131,37 @@ clock_location_tile_init (ClockLocationTile *this)
priv->time_label = NULL;
}

static void
clock_location_tile_dispose (GObject *g_obj)
{
ClockLocationTile *this;
ClockLocationTilePrivate *priv;

this = CLOCK_LOCATION_TILE (g_obj);
priv = clock_location_tile_get_instance_private (this);

if (priv->location) {
if (priv->location_weather_updated_id > 0)
g_signal_handler_disconnect (priv->location, priv->location_weather_updated_id);
priv->location_weather_updated_id = 0;

g_object_unref (priv->location);
priv->location = NULL;
}

if (priv->button_group) {
g_object_unref (priv->button_group);
priv->button_group = NULL;
}

if (priv->current_group) {
g_object_unref (priv->current_group);
priv->current_group = NULL;
}

G_OBJECT_CLASS (clock_location_tile_parent_class)->dispose (g_obj);
}

static void
clock_location_tile_finalize (GObject *g_obj)
{
Expand All @@ -140,7 +172,8 @@ clock_location_tile_finalize (GObject *g_obj)
priv = clock_location_tile_get_instance_private (this);

if (priv->location) {
g_signal_handler_disconnect (priv->location, priv->location_weather_updated_id);
if (priv->location_weather_updated_id > 0)
g_signal_handler_disconnect (priv->location, priv->location_weather_updated_id);
priv->location_weather_updated_id = 0;

g_object_unref (priv->location);
Expand Down Expand Up @@ -415,7 +448,7 @@ copy_tm (struct tm *from, struct tm *to)

static char *
format_time (struct tm *now,
char *tzname,
const char *tzname,
ClockFormat clock_format,
long offset)
{
Expand All @@ -425,7 +458,7 @@ format_time (struct tm *now,
struct tm local_now;
char *utf8;
char *tmp;
long hours, minutes;
long hours;

time (&local_t);
localtime_r (&local_t, &local_now);
Expand Down Expand Up @@ -469,13 +502,9 @@ format_time (struct tm *now,
strcpy (buf, "???");
}

hours = offset / 3600;
minutes = labs (offset % 3600) / 60;
hours = offset / 60;

if (minutes != 0) {
tmp = g_strdup_printf ("%s <small>%s %+ld:%ld</small>", buf, tzname, hours, minutes);
}
else if (hours != 0) {
if (hours != 0) {
tmp = g_strdup_printf ("%s <small>%s %+ld</small>", buf, tzname, hours);
}
else {
Expand Down Expand Up @@ -521,12 +550,13 @@ void
clock_location_tile_refresh (ClockLocationTile *this, gboolean force_refresh)
{
ClockLocationTilePrivate *priv = clock_location_tile_get_instance_private (this);
gchar *tmp, *tzname;
gchar *tmp;
const gchar *tzname;
struct tm now;
long offset;
int format;

g_return_if_fail (IS_CLOCK_LOCATION_TILE (this));
g_return_if_fail (CLOCK_IS_LOCATION_TILE (this));

if (clock_location_is_current (priv->location)) {
gtk_widget_hide (priv->current_spacer);
Expand All @@ -541,6 +571,7 @@ clock_location_tile_refresh (ClockLocationTile *this, gboolean force_refresh)
}
}

/* FIXME */
if (clock_needs_face_refresh (this)) {
clock_face_refresh (CLOCK_FACE (priv->clock_face));
}
Expand All @@ -551,62 +582,66 @@ clock_location_tile_refresh (ClockLocationTile *this, gboolean force_refresh)

clock_location_localtime (priv->location, &now);
tzname = clock_location_get_tzname (priv->location);
if (tzname == NULL) {
tzname = clock_location_get_tzid (priv->location);
}

copy_tm (&now, &(priv->last_refresh));
priv->last_offset = clock_location_get_offset (priv->location);

if (priv->location == NULL) {
return;
}
tmp = g_strdup_printf ("<big><b>%s</b></big>",
clock_location_get_display_name (priv->location));
gtk_label_set_markup (GTK_LABEL (priv->city_label), tmp);
g_free (tmp);

g_signal_emit (this, signals[NEED_CLOCK_FORMAT], 0, &format);

offset = - priv->last_offset;

tmp = format_time (&now, tzname, format, offset);
tmp = format_time (&now, tzname, format, priv->last_offset);

gtk_label_set_markup (GTK_LABEL (priv->time_label), tmp);

g_free (tmp);
}

void
weather_info_setup_tooltip (WeatherInfo *info, ClockLocation *location, GtkTooltip *tooltip,
weather_info_setup_tooltip (GWeatherInfo *info, ClockLocation *location, GtkTooltip *tooltip,
ClockFormat clock_format)
{
GdkPixbuf *pixbuf = NULL;
GtkIconTheme *theme = NULL;
const gchar *conditions, *wind;
gchar *temp, *apparent;
gchar *line1, *line2, *line3, *line4, *tip;
gchar *line1, *line2, *line3, *line4, *line5, *tip;
const gchar *icon_name;
const gchar *sys_timezone;
time_t sunrise_time, sunset_time;
gchar *sunrise_str, *sunset_str;
gint icon_scale;

theme = gtk_icon_theme_get_default ();
icon_name = weather_info_get_icon_name (info);
icon_name = gweather_info_get_icon_name (info);
icon_scale = gdk_window_get_scale_factor (gdk_get_default_root_window ());

pixbuf = gtk_icon_theme_load_icon_for_scale (theme, icon_name, 48, icon_scale,
GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL);
if (pixbuf)
gtk_tooltip_set_icon (tooltip, pixbuf);

conditions = weather_info_get_conditions (info);
conditions = gweather_info_get_conditions (info);
if (strcmp (conditions, "-") != 0)
line1 = g_strdup_printf (_("%s, %s"),
conditions,
weather_info_get_sky (info));
gweather_info_get_sky (info));
else
line1 = g_strdup (weather_info_get_sky (info));
line1 = g_strdup (gweather_info_get_weather_summary (info));

/* we need to g_strdup() since both functions return the same address
* of a static buffer */
temp = g_strdup (weather_info_get_temp (info));
apparent = g_strdup (weather_info_get_apparent (info));
temp = g_strdup (gweather_info_get_temp (info));
apparent = g_strdup (gweather_info_get_apparent (info));
if (strcmp (apparent, temp) != 0 &&
/* FMQ: it's broken to read from another module's translations; add some API to libmateweather. */
strcmp (apparent, dgettext ("mate-applets-2.0", "Unknown")) != 0)
Expand All @@ -617,20 +652,20 @@ weather_info_setup_tooltip (WeatherInfo *info, ClockLocation *location, GtkToolt
g_free (temp);
g_free (apparent);

wind = weather_info_get_wind (info);
wind = gweather_info_get_wind (info);
if (strcmp (wind, dgettext ("mate-applets-2.0", "Unknown")) != 0)
line3 = g_strdup_printf ("%s\n", wind);
else
line3 = g_strdup ("");

sys_timezone = getenv ("TZ");
setenv ("TZ", clock_location_get_timezone (location), 1);
setenv ("TZ", clock_location_get_tzid (location), 1);
tzset ();
if (weather_info_get_value_sunrise (info, &sunrise_time))
if (gweather_info_get_value_sunrise (info, &sunrise_time))
sunrise_str = convert_time_to_str (sunrise_time, clock_format);
else
sunrise_str = g_strdup ("???");
if (weather_info_get_value_sunset (info, &sunset_time))
if (gweather_info_get_value_sunset (info, &sunset_time))
sunset_str = convert_time_to_str (sunset_time, clock_format);
else
sunset_str = g_strdup ("???");
Expand All @@ -639,18 +674,22 @@ weather_info_setup_tooltip (WeatherInfo *info, ClockLocation *location, GtkToolt
g_free (sunrise_str);
g_free (sunset_str);

line5 = g_strdup_printf ("%s %s", gweather_info_get_visibility(info),
gweather_info_get_pressure(info));

if (sys_timezone)
setenv ("TZ", sys_timezone, 1);
else
unsetenv ("TZ");
tzset ();

tip = g_strdup_printf ("<b>%s</b>\n%s\n%s%s", line1, line2, line3, line4);
tip = g_strdup_printf ("<b>%s</b>\n%s\n%s\n%s%s", line1, line2, line5, line3, line4);
gtk_tooltip_set_markup (tooltip, tip);
g_free (line1);
g_free (line2);
g_free (line3);
g_free (line4);
g_free (line5);
g_free (tip);
}

Expand All @@ -664,14 +703,14 @@ weather_tooltip (GtkWidget *widget,
{
ClockLocationTile *tile;
ClockLocationTilePrivate *priv;
WeatherInfo *info;
GWeatherInfo *info;
int clock_format;

tile = CLOCK_LOCATION_TILE (data);
priv = clock_location_tile_get_instance_private (tile);
info = clock_location_get_weather_info (priv->location);

if (!info || !weather_info_is_valid (info))
if (!info || !gweather_info_is_valid (info))
return FALSE;

g_signal_emit (tile, signals[NEED_CLOCK_FORMAT], 0, &clock_format);
Expand All @@ -682,7 +721,7 @@ weather_tooltip (GtkWidget *widget,
}

static void
update_weather_icon (ClockLocation *loc, WeatherInfo *info, gpointer data)
update_weather_icon (ClockLocation *loc, GWeatherInfo *info, gpointer data)
{
ClockLocationTile *tile;
ClockLocationTilePrivate *priv;
Expand All @@ -691,13 +730,13 @@ update_weather_icon (ClockLocation *loc, WeatherInfo *info, gpointer data)
const gchar *icon_name;
gint icon_scale;

if (!info || !weather_info_is_valid (info))
if (!info || !gweather_info_is_valid (info))
return;

tile = CLOCK_LOCATION_TILE (data);
priv = clock_location_tile_get_instance_private (tile);
theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (priv->weather_icon)));
icon_name = weather_info_get_icon_name (info);
icon_name = gweather_info_get_icon_name (info);
icon_scale = gtk_widget_get_scale_factor (GTK_WIDGET (priv->weather_icon));

surface = gtk_icon_theme_load_surface (theme, icon_name, 16, icon_scale,
Expand All @@ -714,7 +753,7 @@ clock_location_tile_get_location (ClockLocationTile *this)
{
ClockLocationTilePrivate *priv;

g_return_val_if_fail (IS_CLOCK_LOCATION_TILE (this), NULL);
g_return_val_if_fail (CLOCK_IS_LOCATION_TILE (this), NULL);

priv = clock_location_tile_get_instance_private (this);

Expand Down
Loading