Browse Source
loading (and yes this might break internal plugins, but the plugin's (Old svn revision: 25890)upstream/xfce4-panel-4.10.1

69 changed files with 9034 additions and 4800 deletions
@ -0,0 +1,378 @@ |
|||
/* $Id$ */ |
|||
/*
|
|||
* Copyright (c) 2007 Nick Schermer <nick@xfce.org> |
|||
* |
|||
* This program is free software; you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the Free |
|||
* Software Foundation; either version 2 of the License, or (at your option) |
|||
* any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, but WITHOUT |
|||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|||
* more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License along with |
|||
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
|||
* Place, Suite 330, Boston, MA 02111-1307 USA |
|||
*/ |
|||
|
|||
#ifdef HAVE_CONFIG_H |
|||
#include <config.h> |
|||
#endif |
|||
|
|||
#ifdef HAVE_MATH_H |
|||
#include <math.h> |
|||
#endif |
|||
#ifdef HAVE_TIME_H |
|||
#include <time.h> |
|||
#endif |
|||
|
|||
#include <gtk/gtk.h> |
|||
#include <cairo/cairo.h> |
|||
|
|||
#include "clock.h" |
|||
#include "clock-analog.h" |
|||
|
|||
#ifndef M_PI |
|||
#define M_PI 3.141592654 |
|||
#endif |
|||
|
|||
#define CLOCK_SCALE 0.1 |
|||
#define TICKS_TO_RADIANS(x) (M_PI - (M_PI / 30.0) * (x)) |
|||
#define HOURS_TO_RADIANS(x,y) (M_PI - (M_PI / 6.0) * (((x) > 12 ? (x) - 12 : (x)) + (y) / 60.0)) |
|||
|
|||
|
|||
|
|||
/* prototypes */ |
|||
static void xfce_clock_analog_class_init (XfceClockAnalogClass *klass); |
|||
static void xfce_clock_analog_init (XfceClockAnalog *clock); |
|||
static void xfce_clock_analog_finalize (GObject *object); |
|||
static void xfce_clock_analog_set_property (GObject *object, |
|||
guint prop_id, |
|||
const GValue *value, |
|||
GParamSpec *pspec); |
|||
static void xfce_clock_analog_get_property (GObject *object, |
|||
guint prop_id, |
|||
GValue *value, |
|||
GParamSpec *pspec); |
|||
static void xfce_clock_analog_size_request (GtkWidget *widget, |
|||
GtkRequisition *requisition); |
|||
static gboolean xfce_clock_analog_expose_event (GtkWidget *widget, |
|||
GdkEventExpose *event); |
|||
static void xfce_clock_analog_draw_ticks (cairo_t *cr, |
|||
gdouble xc, |
|||
gdouble yc, |
|||
gdouble radius); |
|||
static void xfce_clock_analog_draw_pointer (cairo_t *cr, |
|||
gdouble xc, |
|||
gdouble yc, |
|||
gdouble radius, |
|||
gdouble angle, |
|||
gdouble scale, |
|||
gboolean line); |
|||
|
|||
|
|||
|
|||
enum |
|||
{ |
|||
PROP_0, |
|||
PROP_SHOW_SECONDS |
|||
}; |
|||
|
|||
struct _XfceClockAnalogClass |
|||
{ |
|||
GtkImageClass __parent__; |
|||
}; |
|||
|
|||
struct _XfceClockAnalog |
|||
{ |
|||
GtkImage __parent__; |
|||
|
|||
/* draw seconds */ |
|||
guint show_seconds : 1; |
|||
}; |
|||
|
|||
|
|||
|
|||
static GObjectClass *xfce_clock_analog_parent_class; |
|||
|
|||
|
|||
|
|||
GType |
|||
xfce_clock_analog_get_type (void) |
|||
{ |
|||
static GType type = G_TYPE_INVALID; |
|||
|
|||
if (G_UNLIKELY (type == G_TYPE_INVALID)) |
|||
{ |
|||
type = g_type_register_static_simple (GTK_TYPE_IMAGE, |
|||
I_("XfceClockAnalog"), |
|||
sizeof (XfceClockAnalogClass), |
|||
(GClassInitFunc) xfce_clock_analog_class_init, |
|||
sizeof (XfceClockAnalog), |
|||
(GInstanceInitFunc) xfce_clock_analog_init, |
|||
0); |
|||
} |
|||
|
|||
return type; |
|||
} |
|||
|
|||
|
|||
|
|||
static void |
|||
xfce_clock_analog_class_init (XfceClockAnalogClass *klass) |
|||
{ |
|||
GObjectClass *gobject_class; |
|||
GtkWidgetClass *gtkwidget_class; |
|||
|
|||
xfce_clock_analog_parent_class = g_type_class_peek_parent (klass); |
|||
|
|||
gobject_class = G_OBJECT_CLASS (klass); |
|||
gobject_class->finalize = xfce_clock_analog_finalize; |
|||
gobject_class->set_property = xfce_clock_analog_set_property; |
|||
gobject_class->get_property = xfce_clock_analog_get_property; |
|||
|
|||
gtkwidget_class = GTK_WIDGET_CLASS (klass); |
|||
gtkwidget_class->size_request = xfce_clock_analog_size_request; |
|||
gtkwidget_class->expose_event = xfce_clock_analog_expose_event; |
|||
|
|||
/**
|
|||
* Whether we display seconds |
|||
**/ |
|||
g_object_class_install_property (gobject_class, |
|||
PROP_SHOW_SECONDS, |
|||
g_param_spec_boolean ("show-seconds", "show-seconds", "show-seconds", |
|||
FALSE, PANEL_PARAM_READWRITE)); |
|||
} |
|||
|
|||
|
|||
|
|||
static void |
|||
xfce_clock_analog_init (XfceClockAnalog *clock) |
|||
{ |
|||
/* init */ |
|||
clock->show_seconds = FALSE; |
|||
} |
|||
|
|||
|
|||
|
|||
static void |
|||
xfce_clock_analog_finalize (GObject *object) |
|||
{ |
|||
(*G_OBJECT_CLASS (xfce_clock_analog_parent_class)->finalize) (object); |
|||
} |
|||
|
|||
|
|||
|
|||
static void |
|||
xfce_clock_analog_set_property (GObject *object, |
|||
guint prop_id, |
|||
const GValue *value, |
|||
GParamSpec *pspec) |
|||
{ |
|||
XfceClockAnalog *clock = XFCE_CLOCK_ANALOG (object); |
|||
|
|||
switch (prop_id) |
|||
{ |
|||
case PROP_SHOW_SECONDS: |
|||
clock->show_seconds = g_value_get_boolean (value); |
|||
break; |
|||
|
|||
default: |
|||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
|||
break; |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
static void |
|||
xfce_clock_analog_get_property (GObject *object, |
|||
guint prop_id, |
|||
GValue *value, |
|||
GParamSpec *pspec) |
|||
{ |
|||
XfceClockAnalog *clock = XFCE_CLOCK_ANALOG (object); |
|||
|
|||
switch (prop_id) |
|||
{ |
|||
case PROP_SHOW_SECONDS: |
|||
g_value_set_boolean (value, clock->show_seconds); |
|||
break; |
|||
|
|||
default: |
|||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
|||
break; |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
static void |
|||
xfce_clock_analog_size_request (GtkWidget *widget, |
|||
GtkRequisition *requisition) |
|||
{ |
|||
gint width, height; |
|||
|
|||
/* get the current widget size */ |
|||
gtk_widget_get_size_request (widget, &width, &height); |
|||
|
|||
/* square the widget */ |
|||
requisition->width = requisition->height = MAX (width, height); |
|||
} |
|||
|
|||
|
|||
|
|||
static gboolean |
|||
xfce_clock_analog_expose_event (GtkWidget *widget, |
|||
GdkEventExpose *event) |
|||
{ |
|||
XfceClockAnalog *clock = XFCE_CLOCK_ANALOG (widget); |
|||
gdouble xc, yc; |
|||
gdouble angle, radius; |
|||
cairo_t *cr; |
|||
time_t now = time (0); |
|||
struct tm tm; |
|||
|
|||
g_return_val_if_fail (XFCE_CLOCK_IS_ANALOG (clock), FALSE); |
|||
|
|||
/* get center of the widget and the radius */ |
|||
xc = (widget->allocation.width / 2.0); |
|||
yc = (widget->allocation.height / 2.0); |
|||
radius = MIN (xc, yc); |
|||
|
|||
/* add the window offset */ |
|||
xc += widget->allocation.x; |
|||
yc += widget->allocation.y; |
|||
|
|||
/* get the cairo context */ |
|||
cr = gdk_cairo_create (widget->window); |
|||
|
|||
if (G_LIKELY (cr != NULL)) |
|||
{ |
|||
/* get the local time */ |
|||
localtime_r (&now, &tm); |
|||
|
|||
/* set the line properties */ |
|||
cairo_set_line_width (cr, 1); |
|||
gdk_cairo_set_source_color (cr, &widget->style->fg[GTK_STATE_NORMAL]); |
|||
|
|||
/* draw the ticks */ |
|||
xfce_clock_analog_draw_ticks (cr, xc, yc, radius); |
|||
|
|||
if (clock->show_seconds) |
|||
{ |
|||
/* second pointer */ |
|||
angle = TICKS_TO_RADIANS (tm.tm_sec); |
|||
xfce_clock_analog_draw_pointer (cr, xc, yc, radius, angle, 0.7, TRUE); |
|||
} |
|||
|
|||
/* minute pointer */ |
|||
angle = TICKS_TO_RADIANS (tm.tm_min); |
|||
xfce_clock_analog_draw_pointer (cr, xc, yc, radius, angle, 0.8, FALSE); |
|||
|
|||
/* hour pointer */ |
|||
angle = HOURS_TO_RADIANS (tm.tm_hour, tm.tm_min); |
|||
xfce_clock_analog_draw_pointer (cr, xc, yc, radius, angle, 0.5, FALSE); |
|||
|
|||
/* cleanup */ |
|||
cairo_destroy (cr); |
|||
} |
|||
|
|||
return FALSE; |
|||
} |
|||
|
|||
|
|||
|
|||
static void |
|||
xfce_clock_analog_draw_ticks (cairo_t *cr, |
|||
gdouble xc, |
|||
gdouble yc, |
|||
gdouble radius) |
|||
{ |
|||
gint i; |
|||
gdouble x, y, angle; |
|||
|
|||
for (i = 0; i < 12; i++) |
|||
{ |
|||
/* calculate */ |
|||
angle = HOURS_TO_RADIANS (i, 0); |
|||
x = xc + sin (angle) * (radius * (1.0 - CLOCK_SCALE)); |
|||
y = yc + cos (angle) * (radius * (1.0 - CLOCK_SCALE)); |
|||
|
|||
/* draw arc */ |
|||
cairo_move_to (cr, x, y); |
|||
cairo_arc (cr, x, y, radius * CLOCK_SCALE, 0, 2 * M_PI); |
|||
cairo_close_path (cr); |
|||
} |
|||
|
|||
/* fill the arcs */ |
|||
cairo_fill (cr); |
|||
} |
|||
|
|||
|
|||
|
|||
static void |
|||
xfce_clock_analog_draw_pointer (cairo_t *cr, |
|||
gdouble xc, |
|||
gdouble yc, |
|||
gdouble radius, |
|||
gdouble angle, |
|||
gdouble scale, |
|||
gboolean line) |
|||
{ |
|||
gdouble xs, ys; |
|||
gdouble xt, yt; |
|||
|
|||
/* calculate tip position */ |
|||
xt = xc + sin (angle) * radius * scale; |
|||
yt = yc + cos (angle) * radius * scale; |
|||
|
|||
if (line) |
|||
{ |
|||
/* draw the line */ |
|||
cairo_move_to (cr, xc, yc); |
|||
cairo_line_to (cr, xt, yt); |
|||
|
|||
/* draw the line */ |
|||
cairo_stroke (cr); |
|||
} |
|||
else |
|||
{ |
|||
/* calculate start position */ |
|||
xs = xc + sin (angle - 0.5 * M_PI) * radius * CLOCK_SCALE; |
|||
ys = yc + cos (angle - 0.5 * M_PI) * radius * CLOCK_SCALE; |
|||
|
|||
/* draw the pointer */ |
|||
cairo_move_to (cr, xs, ys); |
|||
cairo_arc (cr, xc, yc, radius * CLOCK_SCALE, -angle + M_PI, -angle); |
|||
cairo_line_to (cr, xt, yt); |
|||
cairo_close_path (cr); |
|||
|
|||
/* fill the pointer */ |
|||
cairo_fill (cr); |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
GtkWidget * |
|||
xfce_clock_analog_new (void) |
|||
{ |
|||
return g_object_new (XFCE_CLOCK_TYPE_ANALOG, NULL); |
|||
} |
|||
|
|||
|
|||
|
|||
gboolean |
|||
xfce_clock_analog_update (gpointer user_data) |
|||
{ |
|||
GtkWidget *widget = GTK_WIDGET (user_data); |
|||
|
|||
/* update if the widget if visible */ |
|||
if (G_LIKELY (GTK_WIDGET_VISIBLE (widget))) |
|||
gtk_widget_queue_draw (widget); |
|||
|
|||
return TRUE; |
|||
} |
@ -0,0 +1,43 @@ |
|||
/* $Id$ */ |
|||
/*
|
|||
* Copyright (c) 2007 Nick Schermer <nick@xfce.org> |
|||
* |
|||
* This program is free software; you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the Free |
|||
* Software Foundation; either version 2 of the License, or (at your option) |
|||
* any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, but WITHOUT |
|||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|||
* more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License along with |
|||
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
|||
* Place, Suite 330, Boston, MA 02111-1307 USA |
|||
*/ |
|||
|
|||
#ifndef __CLOCK_ANALOG_H__ |
|||
#define __CLOCK_ANALOG_H__ |
|||
|
|||
G_BEGIN_DECLS |
|||
|
|||
typedef struct _XfceClockAnalogClass XfceClockAnalogClass; |
|||
typedef struct _XfceClockAnalog XfceClockAnalog; |
|||
|
|||
#define XFCE_CLOCK_TYPE_ANALOG (xfce_clock_analog_get_type ()) |
|||
#define XFCE_CLOCK_ANALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFCE_CLOCK_TYPE_ANALOG, XfceClockAnalog)) |
|||
#define XFCE_CLOCK_ANALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XFCE_CLOCK_TYPE_ANALOG, XfceClockAnalogClass)) |
|||
#define XFCE_CLOCK_IS_ANALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XFCE_CLOCK_TYPE_ANALOG)) |
|||
#define XFCE_CLOCK_IS_ANALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XFCE_CLOCK_TYPE_ANALOG)) |
|||
#define XFCE_CLOCK_ANALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XFCE_CLOCK_TYPE_ANALOG, XfceClockAnalogClass)) |
|||
|
|||
GType xfce_clock_analog_get_type (void) G_GNUC_CONST G_GNUC_INTERNAL; |
|||
|
|||
GtkWidget *xfce_clock_analog_new (void) G_GNUC_MALLOC G_GNUC_INTERNAL; |
|||
|
|||
gboolean xfce_clock_analog_update (gpointer user_data) G_GNUC_INTERNAL; |
|||
|
|||
G_END_DECLS |
|||
|
|||
#endif /* !__CLOCK_ANALOG_H__ */ |
@ -0,0 +1,396 @@ |
|||
/* $Id$ */ |
|||
/*
|
|||
* Copyright (c) 2007 Nick Schermer <nick@xfce.org> |
|||
* |
|||
* This program is free software; you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the Free |
|||
* Software Foundation; either version 2 of the License, or (at your option) |
|||
* any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, but WITHOUT |
|||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|||
* more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License along with |
|||
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
|||
* Place, Suite 330, Boston, MA 02111-1307 USA |
|||
*/ |
|||
|
|||
#ifdef HAVE_CONFIG_H |
|||
#include <config.h> |
|||
#endif |
|||
|
|||
#ifdef HAVE_TIME_H |
|||
#include <time.h> |
|||
#endif |
|||
#ifdef HAVE_MATH_H |
|||
#include <math.h> |
|||
#endif |
|||
|
|||
#ifndef M_PI |
|||
#define M_PI 3.141592654 |
|||
#endif |
|||
|
|||
#include <gtk/gtk.h> |
|||
#include <cairo/cairo.h> |
|||
|
|||
#include "clock.h" |
|||
#include "clock-binary.h" |
|||
|
|||
|
|||
|
|||
/* class functions */ |
|||
static void xfce_clock_binary_class_init (XfceClockBinaryClass *klass); |
|||
static void xfce_clock_binary_init (XfceClockBinary *clock); |
|||
static void xfce_clock_binary_finalize (GObject *object); |
|||
static void xfce_clock_binary_set_property (GObject *object, |
|||
guint prop_id, |
|||
const GValue *value, |
|||
GParamSpec *pspec); |
|||
static void xfce_clock_binary_get_property (GObject *object, |
|||
guint prop_id, |
|||
GValue *value, |
|||
GParamSpec *pspec); |
|||
static void xfce_clock_binary_size_request (GtkWidget *widget, |
|||
GtkRequisition *requisition); |
|||
static gboolean xfce_clock_binary_expose_event (GtkWidget *widget, |
|||
GdkEventExpose *event); |
|||
|
|||
|
|||
enum |
|||
{ |
|||
PROP_0, |
|||
PROP_SHOW_SECONDS, |
|||
PROP_TRUE_BINARY |
|||
}; |
|||
|
|||
struct _XfceClockBinaryClass |
|||
{ |
|||
GtkImageClass __parent__; |
|||
}; |
|||
|
|||
struct _XfceClockBinary |
|||
{ |
|||
GtkImage __parent__; |
|||
|
|||
/* whether we draw seconds */ |
|||
guint show_seconds : 1; |
|||
|
|||
/* if this is a true binary clock */ |
|||
guint true_binary : 1; |
|||
}; |
|||
|
|||
|
|||
|
|||
static GObjectClass *xfce_clock_binary_parent_class; |
|||
|
|||
|
|||
|
|||
GType |
|||
xfce_clock_binary_get_type (void) |
|||
{ |
|||
static GType type = G_TYPE_INVALID; |
|||
|
|||
if (G_UNLIKELY (type == G_TYPE_INVALID)) |
|||
{ |
|||
type = g_type_register_static_simple (GTK_TYPE_IMAGE, |
|||
I_("XfceClockBinary"), |
|||
sizeof (XfceClockBinaryClass), |
|||
(GClassInitFunc) xfce_clock_binary_class_init, |
|||
sizeof (XfceClockBinary), |
|||
(GInstanceInitFunc) xfce_clock_binary_init, |
|||
0); |
|||
} |
|||
|
|||
return type; |
|||
} |
|||
|
|||
|
|||
|
|||
static void |
|||
xfce_clock_binary_class_init (XfceClockBinaryClass *klass) |
|||
{ |
|||
GObjectClass *gobject_class; |
|||
GtkWidgetClass *gtkwidget_class; |
|||
|
|||
xfce_clock_binary_parent_class = g_type_class_peek_parent (klass); |
|||
|
|||
gobject_class = G_OBJECT_CLASS (klass); |
|||
gobject_class->finalize = xfce_clock_binary_finalize; |
|||
gobject_class->set_property = xfce_clock_binary_set_property; |
|||
gobject_class->get_property = xfce_clock_binary_get_property; |
|||
|
|||
gtkwidget_class = GTK_WIDGET_CLASS (klass); |
|||
gtkwidget_class->size_request = xfce_clock_binary_size_request; |
|||
gtkwidget_class->expose_event = xfce_clock_binary_expose_event; |
|||
|
|||
/**
|
|||
* Whether we display seconds |
|||
**/ |
|||
g_object_class_install_property (gobject_class, |
|||
PROP_SHOW_SECONDS, |
|||
g_param_spec_boolean ("show-seconds", "show-seconds", "show-seconds", |
|||
FALSE, PANEL_PARAM_READWRITE)); |
|||
|
|||
/**
|
|||
* Whether this is a true binary clock |
|||
**/ |
|||
g_object_class_install_property (gobject_class, |
|||
PROP_TRUE_BINARY, |
|||
g_param_spec_boolean ("true-binary", "true-binary", "true-binary", |
|||
FALSE, PANEL_PARAM_READWRITE)); |
|||
} |
|||
|
|||
|
|||
|
|||
static void |
|||
xfce_clock_binary_init (XfceClockBinary *clock) |
|||
{ |
|||
/* init */ |
|||
clock->show_seconds = FALSE; |
|||
clock->true_binary = FALSE; |
|||
} |
|||
|
|||
|
|||
|
|||
static void |
|||
xfce_clock_binary_finalize (GObject *object) |
|||
{ |
|||
(*G_OBJECT_CLASS (xfce_clock_binary_parent_class)->finalize) (object); |
|||
} |
|||
|
|||
|
|||
|
|||
static void |
|||
xfce_clock_binary_set_property (GObject *object, |
|||
guint prop_id, |
|||
const GValue *value, |
|||
GParamSpec *pspec) |
|||
{ |
|||
XfceClockBinary *clock = XFCE_CLOCK_BINARY (object); |
|||
|
|||
switch (prop_id) |
|||
{ |
|||
case PROP_SHOW_SECONDS: |
|||
clock->show_seconds = g_value_get_boolean (value); |
|||
break; |
|||
|
|||
case PROP_TRUE_BINARY: |
|||
clock->true_binary = g_value_get_boolean (value); |
|||
break; |
|||
|
|||
default: |
|||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
|||
break; |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
static void |
|||
xfce_clock_binary_get_property (GObject *object, |
|||
guint prop_id, |
|||
GValue *value, |
|||
GParamSpec *pspec) |
|||
{ |
|||
XfceClockBinary *clock = XFCE_CLOCK_BINARY (object); |
|||
|
|||
switch (prop_id) |
|||
{ |
|||
case PROP_SHOW_SECONDS: |
|||
g_value_set_boolean (value, clock->show_seconds); |
|||
break; |
|||
|
|||
case PROP_TRUE_BINARY: |
|||
g_value_set_boolean (value, clock->true_binary); |
|||
break; |
|||
|
|||
default: |
|||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
|||
break; |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
static void |
|||
xfce_clock_binary_size_request (GtkWidget *widget, |
|||
GtkRequisition *requisition) |
|||
{ |
|||
gint width, height; |
|||
gdouble ratio; |
|||
XfceClockBinary *clock = XFCE_CLOCK_BINARY (widget); |
|||
|
|||
/* get the current widget size */ |
|||
gtk_widget_get_size_request (widget, &width, &height); |
|||
|
|||
/* ratio of the clock */ |
|||
if (clock->true_binary) |
|||
{ |
|||
ratio = clock->show_seconds ? 2.0 : 3.0; |
|||
} |
|||
else |
|||
{ |
|||
ratio = clock->show_seconds ? 1.5 : 1.0; |
|||
} |
|||
|
|||
/* set requisition based on the plugin orientation */ |
|||
if (width == -1) |
|||
{ |
|||
requisition->height = height; |
|||
requisition->width = height * ratio; |
|||
} |
|||
else |
|||
{ |
|||
requisition->height = width / ratio; |
|||
requisition->width = width; |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
static gboolean |
|||
xfce_clock_binary_expose_event (GtkWidget *widget, |
|||
GdkEventExpose *event) |
|||
{ |
|||
XfceClockBinary *clock = XFCE_CLOCK_BINARY (widget); |
|||
gdouble cw, ch, columns; |
|||
gint ticks, cells, decimal; |
|||
gdouble radius; |
|||
gdouble x, y; |
|||
gint i, j; |
|||
gint decimal_tb[] = {32, 16, 8, 4, 2, 1}; |
|||
gint decimal_bcd[] = {80, 40, 20, 10, 8, 4, 2, 1}; |
|||
cairo_t *cr; |
|||
GdkColor active, inactive; |
|||
time_t now = time (0); |
|||
struct tm tm; |
|||
|
|||
g_return_val_if_fail (XFCE_CLOCK_IS_BINARY (clock), FALSE); |
|||
|
|||
/* number of columns and cells */ |
|||
columns = clock->show_seconds ? 3.0 : 2.0; |
|||
cells = clock->true_binary ? 6 : 8; |
|||
|
|||
/* cell width and height */ |
|||
if (clock->true_binary) |
|||
{ |
|||
cw = widget->allocation.width / 6.0; |
|||
ch = widget->allocation.height / columns; |
|||
} |
|||
else /* bcd clock */ |
|||
{ |
|||
cw = widget->allocation.width / columns / 2.0; |
|||
ch = widget->allocation.height / 4.0; |
|||
} |
|||
|
|||
/* arc radius */ |
|||
radius = MIN (cw, ch) / 2.0 * 0.7; |
|||
|
|||
/* get colors */ |
|||
inactive = widget->style->fg[GTK_STATE_NORMAL]; |
|||
active = widget->style->bg[GTK_STATE_SELECTED]; |
|||
|
|||
/* get the cairo context */ |
|||
cr = gdk_cairo_create (widget->window); |
|||
|
|||
if (G_LIKELY (cr != NULL)) |
|||
{ |
|||
/* get the current time */ |
|||
localtime_r (&now, &tm); |
|||
|
|||
/* walk the three or two time parts */ |
|||
for (i = 0; i < columns; i++) |
|||
{ |
|||
/* get the time of this column */ |
|||
if (i == 0) |
|||
ticks = tm.tm_hour; |
|||
else if (i == 1) |
|||
ticks = tm.tm_min; |
|||
else |
|||
ticks = tm.tm_sec; |
|||
|
|||
/* walk the binary columns */ |
|||
for (j = 0; j < cells; j++) |
|||
{ |
|||
if (clock->true_binary) |
|||
{ |
|||
/* skip the columns we don't draw */ |
|||
if (i == 0 && j == 0) |
|||
continue; |
|||
|
|||
/* decimal representation of this cell */ |
|||
decimal = decimal_tb[j]; |
|||
|
|||
/* center of the arc */ |
|||
x = cw * (j + 0.5) + widget->allocation.x; |
|||
y = ch * (i + 0.5) + widget->allocation.y; |
|||
} |
|||
else /* bcd clock */ |
|||
{ |
|||
/* skip the columns we don't draw */ |
|||
if ((j == 0) || (i == 0 && j == 1)) |
|||
continue; |
|||
|
|||
/* decimal representation of this cell */ |
|||
decimal = decimal_bcd[j]; |
|||
|
|||
/* center of the arc */ |
|||
x = cw * (i * 2 + (j < 4 ? 0 : 1) + 0.5) + widget->allocation.x; |
|||
y = ch * ((j >= 4 ? j - 4 : j) + 0.5) + widget->allocation.y; |
|||
} |
|||
|
|||
/* if this binary values 'fits' in the time */ |
|||
if (ticks >= decimal) |
|||
{ |
|||
/* extract the decimal value from the time */ |
|||
ticks -= decimal; |
|||
|
|||
/* set the active color */ |
|||
gdk_cairo_set_source_color (cr, &active); |
|||
} |
|||
else |
|||
{ |
|||
/* set the inactive color */ |
|||
gdk_cairo_set_source_color (cr, &inactive); |
|||
} |
|||
|
|||
/* draw the arc */ |
|||
cairo_move_to (cr, x, y); |
|||
cairo_arc (cr, x, y, radius, 0, 2 * M_PI); |
|||
cairo_close_path (cr); |
|||
|
|||
/* fill the arc */ |
|||
cairo_fill (cr); |
|||
} |
|||
} |
|||
|
|||
/* cleanup */ |
|||
cairo_destroy (cr); |
|||
} |
|||
|
|||
return FALSE; |
|||
} |
|||
|
|||
|
|||
|
|||
GtkWidget * |
|||
xfce_clock_binary_new (void) |
|||
{ |
|||
return g_object_new (XFCE_CLOCK_TYPE_BINARY, NULL); |
|||
} |
|||
|
|||
|
|||
|
|||
gboolean |
|||
xfce_clock_binary_update (gpointer user_data) |
|||
{ |
|||
GtkWidget *widget = GTK_WIDGET (user_data); |
|||
|
|||
/* update if the widget if visible */ |
|||
if (G_LIKELY (GTK_WIDGET_VISIBLE (widget))) |
|||
gtk_widget_queue_draw (widget); |
|||
|
|||
return TRUE; |
|||
} |
@ -0,0 +1,43 @@ |
|||
/* $Id$ */ |
|||
/*
|
|||
* Copyright (c) 2007 Nick Schermer <nick@xfce.org> |
|||
* |
|||
* This program is free software; you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the Free |
|||
* Software Foundation; either version 2 of the License, or (at your option) |
|||
* any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, but WITHOUT |
|||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|||
* more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License along with |
|||
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
|||
* Place, Suite 330, Boston, MA 02111-1307 USA |
|||
*/ |
|||
|
|||
#ifndef __CLOCK_BINARY_H__ |
|||
#define __CLOCK_BINARY_H__ |
|||
|
|||
G_BEGIN_DECLS |
|||
|
|||
typedef struct _XfceClockBinaryClass XfceClockBinaryClass; |
|||
typedef struct _XfceClockBinary XfceClockBinary; |
|||
|
|||
#define XFCE_CLOCK_TYPE_BINARY (xfce_clock_binary_get_type ()) |
|||
#define XFCE_CLOCK_BINARY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFCE_CLOCK_TYPE_BINARY, XfceClockBinary)) |
|||
#define XFCE_CLOCK_BINARY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XFCE_CLOCK_TYPE_BINARY, XfceClockBinaryClass)) |
|||
#define XFCE_CLOCK_IS_BINARY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XFCE_CLOCK_TYPE_BINARY)) |
|||
#define XFCE_CLOCK_IS_BINARY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XFCE_CLOCK_TYPE_BINARY)) |
|||
#define XFCE_CLOCK_BINARY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XFCE_CLOCK_TYPE_BINARY, XfceClockBinaryClass)) |
|||
|
|||
GType xfce_clock_binary_get_type (void) G_GNUC_CONST G_GNUC_INTERNAL; |
|||
|
|||
GtkWidget *xfce_clock_binary_new (void) G_GNUC_MALLOC G_GNUC_INTERNAL; |
|||
|
|||
gboolean xfce_clock_binary_update (gpointer user_data) G_GNUC_INTERNAL; |
|||
|
|||
G_END_DECLS |
|||
|
|||
#endif /* !__CLOCK_BINARY_H__ */ |
@ -0,0 +1,543 @@ |
|||
/* $Id$ */ |
|||
/*
|
|||
* Copyright (c) 2007 Nick Schermer <nick@xfce.org> |
|||
* |
|||
* This program is free software; you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the Free |
|||
* Software Foundation; either version 2 of the License, or (at your option) |
|||
* any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, but WITHOUT |
|||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|||
* more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License along with |
|||
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
|||
* Place, Suite 330, Boston, MA 02111-1307 USA |
|||
*/ |
|||
|
|||
#ifdef HAVE_CONFIG_H |
|||
#include <config.h> |
|||
#endif |
|||
|
|||
#ifdef HAVE_STRING_H |
|||
#include <string.h> |
|||
#endif |
|||
|
|||
#include <gtk/gtk.h> |
|||
#include <libxfce4util/libxfce4util.h> |
|||
#include <libxfce4panel/xfce-panel-plugin.h> |
|||
#include <libxfcegui4/xfce-titled-dialog.h> |
|||
#include <libxfcegui4/xfce_framebox.h> |
|||
#include <libxfcegui4/xfce-widget-helpers.h> |
|||
|
|||
#include "clock.h" |
|||
#include "clock-dialog.h" |
|||
|
|||
|
|||
|
|||
/** default formats **/ |
|||
static const gchar *tooltip_formats[] = { |
|||
DEFAULT_TOOLTIP_FORMAT, |
|||
"%x", |
|||
NULL |
|||
}; |
|||
|
|||
static const gchar *digital_formats[] = { |
|||
DEFAULT_DIGITAL_FORMAT, |
|||
"%T", |
|||
"%r", |
|||
"%R %p", |
|||
NULL |
|||
}; |
|||
|
|||
|
|||
|
|||
/** prototypes **/ |
|||
void xfce_clock_dialog_options (ClockPlugin *clock); |
|||
|
|||
|
|||
|
|||
static void |
|||
xfce_clock_dialog_reload_settings (ClockPlugin *clock) |
|||
{ |
|||
if (G_LIKELY (clock->widget)) |
|||
{ |
|||
/* save the settings */ |
|||
xfce_clock_widget_update_settings (clock); |
|||
|
|||
/* make sure the plugin sets it's size again */ |
|||
gtk_widget_queue_resize (clock->widget); |
|||
|
|||
/* run a direct update */ |
|||
(clock->update) (clock->widget); |
|||
|
|||
/* reschedule the timeout */ |
|||
xfce_clock_widget_sync (clock); |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
static void |
|||
xfce_clock_dialog_mode_changed (GtkComboBox *combo, |
|||
ClockPlugin *clock) |
|||
{ |
|||
/* set the new mode */ |
|||
clock->mode = gtk_combo_box_get_active (combo); |
|||
|
|||
/* update the plugin widget */ |
|||
if (G_LIKELY (clock->widget)) |
|||
{ |
|||
/* set the new clock mode */ |
|||
xfce_clock_widget_set_mode (clock); |
|||
|
|||
/* update the settings */ |
|||
xfce_clock_dialog_reload_settings (clock); |
|||
|
|||
/* update the plugin size */ |
|||
xfce_clock_plugin_set_size (clock, xfce_panel_plugin_get_size (clock->plugin)); |
|||
} |
|||
|
|||
/* update the dialog */ |
|||
xfce_clock_dialog_options (clock); |
|||
} |
|||
|
|||
|
|||
|
|||
static void |
|||
xfce_clock_dialog_show_frame_toggled (GtkToggleButton *button, |
|||
ClockPlugin *clock) |
|||
{ |
|||
/* set frame mode */ |
|||
clock->show_frame = gtk_toggle_button_get_active (button); |
|||
|
|||
/* change frame shadow */ |
|||
gtk_frame_set_shadow_type (GTK_FRAME (clock->frame), clock->show_frame ? GTK_SHADOW_IN : GTK_SHADOW_NONE); |
|||
} |
|||
|
|||
|
|||
|
|||
static void |
|||
xfce_clock_dialog_tooltip_format_changed (GtkComboBox *combo, |
|||
ClockPlugin *clock) |
|||
{ |
|||
gint index; |
|||
GtkWidget *entry; |
|||
|
|||
/* stop running timeout */ |
|||
if (clock->tooltip_timeout_id) |
|||
{ |
|||
g_source_remove (clock->tooltip_timeout_id); |
|||
clock->tooltip_timeout_id = 0; |
|||
} |
|||
|
|||
/* get index of selected item */ |
|||
index = gtk_combo_box_get_active (combo); |
|||
|
|||
/* get the custom entry */ |
|||
entry = g_object_get_data (G_OBJECT (combo), I_("entry")); |
|||
|
|||
/* set one of the default formats */ |
|||
if (index < G_N_ELEMENTS (tooltip_formats)) |
|||
{ |
|||
/* hide the entry */ |
|||
gtk_widget_hide (entry); |
|||
|
|||
/* cleanup old format */ |
|||
g_free (clock->tooltip_format); |
|||
|
|||
/* set new format */ |
|||
clock->tooltip_format = g_strdup (tooltip_formats[index]); |
|||
|
|||
/* restart the tooltip timeout */ |
|||
xfce_clock_tooltip_sync (clock); |
|||
} |
|||
else |
|||
{ |
|||
/* set string */ |
|||
gtk_entry_set_text (GTK_ENTRY (entry), clock->tooltip_format); |
|||
|
|||
/* show */ |
|||
gtk_widget_show (entry); |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
static void |
|||
xfce_clock_dialog_tooltip_entry_changed (GtkEntry *entry, |
|||
ClockPlugin *clock) |
|||
{ |
|||
/* cleanup old format */ |
|||
g_free (clock->tooltip_format); |
|||
|
|||
/* set new format */ |
|||
clock->tooltip_format = g_strdup (gtk_entry_get_text (entry)); |
|||
|
|||
/* restart the tooltip timeout */ |
|||
xfce_clock_tooltip_sync (clock); |
|||
} |
|||
|
|||
|
|||
|
|||
static void |
|||
xfce_clock_dialog_show_seconds_toggled (GtkToggleButton *button, |
|||
ClockPlugin *clock) |
|||
{ |
|||
/* whether we show seconds */ |
|||
clock->show_seconds = gtk_toggle_button_get_active (button); |
|||
|
|||
/* update the clock */ |
|||
xfce_clock_dialog_reload_settings (clock); |
|||
} |
|||
|
|||
|
|||
|
|||
static void |
|||
xfce_clock_dialog_show_military_toggled (GtkToggleButton *button, |
|||
ClockPlugin *clock) |
|||
{ |
|||
/* whether we show a 24h clock */ |
|||
clock->show_military = gtk_toggle_button_get_active (button); |
|||
|
|||
/* update the clock */ |
|||
xfce_clock_dialog_reload_settings (clock); |
|||
} |
|||
|
|||
|
|||
|
|||
static void |
|||
xfce_clock_dialog_show_meridiem_toggled (GtkToggleButton *button, |
|||
ClockPlugin *clock) |
|||
{ |
|||
/* whether we show am/pm */ |
|||
clock->show_meridiem = gtk_toggle_button_get_active (button); |
|||
|
|||
/* update the clock */ |
|||
xfce_clock_dialog_reload_settings (clock); |
|||
} |
|||
|
|||
|
|||
|
|||
static void |
|||
xfce_clock_dialog_true_binary_toggled (GtkToggleButton *button, |
|||
ClockPlugin *clock) |
|||
{ |
|||
/* whether we this is a true binary clock */ |
|||
clock->true_binary = gtk_toggle_button_get_active (button); |
|||
|
|||
/* update the clock */ |
|||
xfce_clock_dialog_reload_settings (clock); |
|||
} |
|||
|
|||
|
|||
|
|||
static void |
|||
xfce_clock_dialog_digital_format_changed (GtkComboBox *combo, |
|||
ClockPlugin *clock) |
|||
{ |
|||
gint index; |
|||
GtkWidget *entry; |
|||
|
|||
/* get index of selected item */ |
|||
index = gtk_combo_box_get_active (combo); |
|||
|
|||
/* get the custom entry */ |
|||
entry = g_object_get_data (G_OBJECT (combo), I_("entry")); |
|||
|
|||
/* set one of the default formats */ |
|||
if (index < G_N_ELEMENTS (digital_formats)) |
|||
{ |
|||
/* hide the entry */ |
|||
gtk_widget_hide (entry); |
|||
|
|||
/* cleanup old format */ |
|||
g_free (clock->digital_format); |
|||
|
|||
/* set new format */ |
|||
clock->digital_format = g_strdup (digital_formats[index]); |
|||
|
|||
/* reload settings */ |
|||
xfce_clock_dialog_reload_settings (clock); |
|||
} |
|||
else |
|||
{ |
|||
/* set string */ |
|||
gtk_entry_set_text (GTK_ENTRY (entry), clock->digital_format); |
|||
|
|||
/* show */ |
|||
gtk_widget_show (entry); |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
static void |
|||
xfce_clock_dialog_digital_entry_changed (GtkEntry *entry, |
|||
ClockPlugin *clock) |
|||
{ |
|||
/* cleanup old format */ |
|||
g_free (clock->digital_format); |
|||
|
|||
/* set new format */ |
|||
clock->digital_format = g_strdup (gtk_entry_get_text (entry)); |
|||
|
|||
/* reload settings */ |
|||
xfce_clock_dialog_reload_settings (clock); |
|||
} |
|||
|
|||
|
|||
|
|||
static gboolean |
|||
xfce_clock_dialog_row_separator_func (GtkTreeModel *model, |
|||
GtkTreeIter *iter, |
|||
gpointer user_data) |
|||
{ |
|||
gchar *title; |
|||
gboolean result = FALSE; |
|||
|
|||
gtk_tree_model_get (model, iter, 0, &title, -1); |
|||
if (G_LIKELY (title != NULL)) |
|||
{ |
|||
result = (strcmp (title, "-") == 0); |
|||
|
|||
/* cleanup */ |
|||
g_free (title); |
|||
} |
|||
|
|||
return result; |
|||
} |
|||
|
|||
|
|||
|
|||
static gboolean |
|||
xfce_clock_dialog_append_combobox_formats (GtkComboBox *combo, |
|||
const gchar *formats[], |
|||
const gchar *current_format) |
|||
{ |
|||
gint i; |
|||
time_t now = time (0); |
|||
struct tm tm; |
|||
gchar *string; |
|||
gboolean has_active = FALSE; |
|||
|
|||
/* get the local time */ |
|||
localtime_r (&now, &tm); |
|||
|
|||
for (i = 0; formats[i] != NULL; i++) |
|||
{ |
|||
/* insert user-redable string */ |
|||
string = xfce_clock_util_strdup_strftime (formats[i], &tm); |
|||
gtk_combo_box_append_text (GTK_COMBO_BOX (combo), string); |
|||
g_free (string); |
|||
|
|||
/* check if this is the active string */ |
|||
if (!has_active && current_format && strcmp (formats[i], current_format) == 0) |
|||
{ |
|||
gtk_combo_box_set_active (GTK_COMBO_BOX (combo), i); |
|||
has_active = TRUE; |
|||
} |
|||
} |
|||
|
|||
/* insert the separator and the custom line */ |
|||
gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "-"); |
|||
gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Custom")); |
|||
|
|||
if (!has_active) |
|||
{ |
|||
if (!current_format) |
|||
{ |
|||
has_active = TRUE; |
|||
i = -1; |
|||
} |
|||
|
|||
/* select item */ |
|||
gtk_combo_box_set_active (GTK_COMBO_BOX (combo), i + 1); |
|||
} |
|||
|
|||
return has_active; |
|||
} |
|||
|
|||
|
|||
|
|||
static void |
|||
xfce_clock_dialog_response (GtkWidget *dialog, |
|||
gint response, |
|||
ClockPlugin *clock) |
|||
{ |
|||
/* destroy the dialog */ |
|||
gtk_widget_destroy (dialog); |
|||
|
|||
/* remove links */ |
|||
g_object_set_data (G_OBJECT (clock->plugin), I_("configure-dialog"), NULL); |
|||
g_object_set_data (G_OBJECT (clock->plugin), I_("configure-dialog-bin"), NULL); |
|||
|
|||
/* unblock the plugin menu */ |
|||
xfce_panel_plugin_unblock_menu (clock->plugin); |
|||
} |
|||
|
|||
|
|||
|
|||
void |
|||
xfce_clock_dialog_options (ClockPlugin *clock) |
|||
{ |
|||
GtkWidget *button, *bin, *vbox, *combo, *entry; |
|||
gboolean has_active; |
|||
|
|||
/* get the frame bin */ |
|||
bin = g_object_get_data (G_OBJECT (clock->plugin), I_("configure-dialog-bin")); |
|||
gtk_container_foreach (GTK_CONTAINER (bin), (GtkCallback) gtk_widget_destroy, NULL); |
|||
|
|||
/* main vbox */ |
|||
vbox = gtk_vbox_new (FALSE, 8); |
|||
gtk_container_add (GTK_CONTAINER (bin), vbox); |
|||
gtk_widget_show (vbox); |
|||
|
|||
if (clock->mode == XFCE_CLOCK_ANALOG || clock->mode == XFCE_CLOCK_BINARY || clock->mode == XFCE_CLOCK_LCD) |
|||
{ |
|||
button = gtk_check_button_new_with_mnemonic (_("Display _seconds")); |
|||
gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0); |
|||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), clock->show_seconds); |
|||
g_signal_connect (button, "toggled", G_CALLBACK (xfce_clock_dialog_show_seconds_toggled), clock); |
|||
gtk_widget_show (button); |
|||
} |
|||
|
|||
if (clock->mode == XFCE_CLOCK_LCD) |
|||
{ |
|||
button = gtk_check_button_new_with_mnemonic (_("Use 24-_hour clock")); |
|||
gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0); |
|||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), clock->show_military); |
|||
g_signal_connect (button, "toggled", G_CALLBACK (xfce_clock_dialog_show_military_toggled), clock); |
|||
gtk_widget_show (button); |
|||
|
|||
button = gtk_check_button_new_with_mnemonic (_("Sho_w AM/PM")); |
|||
gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0); |
|||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), clock->show_meridiem); |
|||
g_signal_connect (button, "toggled", G_CALLBACK (xfce_clock_dialog_show_meridiem_toggled), clock); |
|||
gtk_widget_show (button); |
|||
} |
|||
|
|||
if (clock->mode == XFCE_CLOCK_BINARY) |
|||
{ |
|||
button = gtk_check_button_new_with_mnemonic (_("True _binary clock")); |
|||
gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0); |
|||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), clock->true_binary); |
|||
g_signal_connect (button, "toggled", G_CALLBACK (xfce_clock_dialog_true_binary_toggled), clock); |
|||
gtk_widget_show (button); |
|||
} |
|||
|
|||
if (clock->mode == XFCE_CLOCK_DIGITAL) |
|||
{ |
|||
combo = gtk_combo_box_new_text (); |
|||
gtk_box_pack_start (GTK_BOX (vbox), combo, TRUE, TRUE, 0); |
|||
gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combo), xfce_clock_dialog_row_separator_func, NULL, NULL); |
|||
has_active = xfce_clock_dialog_append_combobox_formats (GTK_COMBO_BOX (combo), digital_formats, clock->digital_format); |
|||
g_signal_connect (G_OBJECT (combo), "changed", G_CALLBACK (xfce_clock_dialog_digital_format_changed), clock); |
|||
gtk_widget_show (combo); |
|||
|
|||
entry = gtk_entry_new_with_max_length (BUFFER_SIZE-1); |
|||
gtk_box_pack_start (GTK_BOX (vbox), entry, TRUE, TRUE, 0); |
|||
g_object_set_data (G_OBJECT (combo), I_("entry"), entry); |
|||
if (!has_active) |
|||
{ |
|||
gtk_widget_show (entry); |
|||
gtk_entry_set_text (GTK_ENTRY (entry), clock->digital_format); |
|||
} |
|||
g_signal_connect (G_OBJECT (entry), "changed", G_CALLBACK (xfce_clock_dialog_digital_entry_changed), clock); |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
void |
|||
xfce_clock_dialog_show (ClockPlugin *clock) |
|||
{ |
|||
GtkWidget *dialog, *dialog_vbox; |
|||
GtkWidget *frame, *bin, *vbox, *combo; |
|||
GtkWidget *button, *entry; |
|||
gboolean has_active; |
|||
|
|||
/* block the right-click menu */ |
|||
xfce_panel_plugin_block_menu (clock->plugin); |
|||
|
|||
/* create dialog */ |
|||
dialog = xfce_titled_dialog_new_with_buttons (_("Clock"), NULL, |
|||
GTK_DIALOG_NO_SEPARATOR, |
|||
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, |
|||
NULL); |
|||
gtk_window_set_screen (GTK_WINDOW (dialog), gtk_widget_get_screen (GTK_WIDGET (clock->plugin))); |
|||
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER); |
|||
gtk_window_set_icon_name (GTK_WINDOW (dialog), "xfce4-settings"); |
|||
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE); |
|||
g_object_set_data (G_OBJECT (clock->plugin), I_("configure-dialog"), dialog); |
|||
g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (xfce_clock_dialog_response), clock); |
|||
|
|||
/* get dialog vbox */ |
|||
dialog_vbox = GTK_DIALOG (dialog)->vbox; |
|||
|
|||
/* appearance settings */ |
|||
frame = xfce_create_framebox (_("Appearance"), &bin); |
|||
gtk_box_pack_start (GTK_BOX (dialog_vbox), frame, FALSE, TRUE, 0); |
|||
gtk_widget_show (frame); |
|||
|
|||
vbox = gtk_vbox_new (FALSE, 8); |
|||
gtk_container_add (GTK_CONTAINER (bin), vbox); |
|||
gtk_widget_show (vbox); |
|||
|
|||
combo = gtk_combo_box_new_text (); |
|||
gtk_box_pack_start (GTK_BOX (vbox), combo, TRUE, TRUE, 0); |
|||
gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Analog")); |
|||
gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Binary")); |
|||
gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Digital")); |
|||
gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("LCD")); |
|||
gtk_combo_box_set_active (GTK_COMBO_BOX (combo), clock->mode); |
|||
g_signal_connect (G_OBJECT (combo), "changed", G_CALLBACK (xfce_clock_dialog_mode_changed), clock); |
|||
gtk_widget_show (combo); |
|||
|
|||
button = gtk_check_button_new_with_mnemonic (_("Show _frame")); |
|||
gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0); |
|||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), clock->show_frame); |
|||
g_signal_connect (button, "toggled", G_CALLBACK (xfce_clock_dialog_show_frame_toggled), clock); |
|||
gtk_widget_show (button); |
|||
|
|||
/* tooltip settings */ |
|||
frame = xfce_create_framebox (_("Tooltip Format"), &bin); |
|||
gtk_box_pack_start (GTK_BOX (dialog_vbox), frame, FALSE, TRUE, 0); |
|||
gtk_widget_show (frame); |
|||
|
|||
vbox = gtk_vbox_new (FALSE, 8); |
|||
gtk_container_add (GTK_CONTAINER (bin), vbox); |
|||
gtk_widget_show (vbox); |
|||
|
|||
combo = gtk_combo_box_new_text (); |
|||
gtk_box_pack_start (GTK_BOX (vbox), combo, TRUE, TRUE, 0); |
|||
gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combo), xfce_clock_dialog_row_separator_func, NULL, NULL); |
|||
has_active = xfce_clock_dialog_append_combobox_formats (GTK_COMBO_BOX (combo), tooltip_formats, clock->tooltip_format); |
|||
g_signal_connect (G_OBJECT (combo), "changed", G_CALLBACK (xfce_clock_dialog_tooltip_format_changed), clock); |
|||
gtk_widget_show (combo); |
|||
|
|||
entry = gtk_entry_new_with_max_length (BUFFER_SIZE-1); |
|||
gtk_box_pack_start (GTK_BOX (vbox), entry, TRUE, TRUE, 0); |
|||
g_object_set_data (G_OBJECT (combo), I_("entry"), entry); |
|||
if (!has_active) |
|||
{ |
|||
gtk_widget_show (entry); |
|||
gtk_entry_set_text (GTK_ENTRY (entry), clock->tooltip_format); |
|||
} |
|||
g_signal_connect (G_OBJECT (entry), "changed", G_CALLBACK (xfce_clock_dialog_tooltip_entry_changed), clock); |
|||
|
|||
/* clock settings */ |
|||
frame = xfce_create_framebox (_("Clock Options"), &bin); |
|||
gtk_box_pack_start (GTK_BOX (dialog_vbox), frame, FALSE, TRUE, 0); |
|||
g_object_set_data (G_OBJECT (clock->plugin), I_("configure-dialog-bin"), bin); |
|||
gtk_widget_show (frame); |
|||
|
|||
/* add the potions */ |
|||
xfce_clock_dialog_options (clock); |
|||
|
|||
/* show the dialog */ |
|||
gtk_widget_show (dialog); |
|||
} |
|||
|
@ -0,0 +1,31 @@ |
|||
/* $Id$ */ |
|||
/*
|
|||
* Copyright (c) 2007 Nick Schermer <nick@xfce.org> |
|||
* |
|||
* This program is free software; you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the Free |
|||
* Software Foundation; either version 2 of the License, or (at your option) |
|||
* any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, but WITHOUT |
|||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|||
* more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License along with |
|||
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
|||
* Place, Suite 330, Boston, MA 02111-1307 USA |
|||
*/ |
|||
|
|||
#ifndef __CLOCK_DIALOG_H__ |
|||
#define __CLOCK_DIALOG_H__ |
|||
|
|||
#include <gtk/gtk.h> |
|||
|
|||
G_BEGIN_DECLS |
|||
|
|||
void xfce_clock_dialog_show (ClockPlugin *clock) G_GNUC_INTERNAL; |
|||
|
|||
G_END_DECLS |
|||
|
|||
#endif /* !__CLOCK_DIALOG_H__ */ |
@ -0,0 +1,224 @@ |
|||
/* $Id$ */ |
|||
/*
|
|||
* Copyright (c) 2007 Nick Schermer <nick@xfce.org> |
|||
* |
|||
* This program is free software; you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the Free |
|||
* Software Foundation; either version 2 of the License, or (at your option) |
|||
* any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, but WITHOUT |
|||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|||
* more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License along with |
|||
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
|||
* Place, Suite 330, Boston, MA 02111-1307 USA |
|||
*/ |
|||
|
|||
#ifdef HAVE_CONFIG_H |
|||
#include <config.h> |
|||
#endif |
|||
|
|||
#ifdef HAVE_TIME_H |
|||
#include <time.h> |
|||
#endif |
|||
|
|||
#include <gtk/gtk.h> |
|||
|
|||
#include "clock.h" |
|||
#include "clock-digital.h" |
|||
|
|||
|
|||
|
|||
/* class functions */ |
|||
static void xfce_clock_digital_class_init (XfceClockDigitalClass *klass); |
|||
static void xfce_clock_digital_init (XfceClockDigital *clock); |
|||
static void xfce_clock_digital_finalize (GObject *object); |
|||
static void xfce_clock_digital_set_property (GObject *object, |
|||
guint prop_id, |
|||
const GValue *value, |
|||
GParamSpec *pspec); |
|||
static void xfce_clock_digital_get_property (GObject *object, |
|||
guint prop_id, |
|||
GValue *value, |
|||
GParamSpec *pspec); |
|||
|
|||
|
|||
|
|||
enum |
|||
{ |
|||
PROP_0, |
|||
PROP_DIGITAL_FORMAT |
|||
}; |
|||
|
|||
struct _XfceClockDigitalClass |
|||
{ |
|||
|