Commit d4d85c26 authored by Colomban Wendling's avatar Colomban Wendling

OVCCGtk: always use the ParamSpec to notify properties

parent ae065329
......@@ -81,7 +81,9 @@ enum
PROP_MARGIN,
PROP_ZOOM,
PROP_STATE,
PROP_PAWN_KIND
PROP_PAWN_KIND,
N_PROPERTIES
};
enum
......@@ -91,7 +93,8 @@ enum
N_SIGNALS
};
static guint signals[N_SIGNALS] = {0};
static GParamSpec *properties[N_PROPERTIES] = { NULL };
static guint signals[N_SIGNALS] = {0};
static void ovccgtk_board_finalize (GObject *object);
static void ovccgtk_board_set_property (GObject *object,
......@@ -144,74 +147,58 @@ static void ovccgtk_board_class_init (OVCCGtkBoardClass *klass)
widget_class->key_press_event = ovccgtk_board_key_press;
klass->add_tile = NULL;
g_object_class_install_property (
object_class, PROP_BOARD,
g_param_spec_object (
"board",
"Board",
"The underlying OVCCBoard",
OVCC_TYPE_BOARD,
G_PARAM_READWRITE
)
);
properties[PROP_BOARD] =
g_param_spec_object ("board",
"Board",
"The underlying OVCCBoard",
OVCC_TYPE_BOARD,
G_PARAM_READWRITE);
/**
* OVCCGtkBoard:cursor-position:
*
* The current position of the cursor on the board, as an #OVCCPosition.
* The cursor can only be inside the board's bounds, plus one around them.
*/
g_object_class_install_property (
object_class, PROP_CURSOR_POSITION,
g_param_spec_boxed (
"cursor-position",
"Cursor position",
"The current cursor position",
OVCC_TYPE_POSITION,
G_PARAM_READWRITE
)
);
g_object_class_install_property (
object_class, PROP_MARGIN,
g_param_spec_int (
"margin",
"Margin",
"Size (in pixels) of the margin around the board",
G_MININT,
G_MAXINT,
TILE_SIZE / 2,
G_PARAM_READWRITE
)
);
g_object_class_install_property (
object_class, PROP_ZOOM,
g_param_spec_double (
"zoom",
"Zoom",
"The zoom factor",
ZOOM_MIN,
ZOOM_MAX,
1.0,
G_PARAM_READWRITE
)
);
g_object_class_install_property (object_class,
PROP_STATE,
g_param_spec_enum ("state",
"State",
"The board state (tile or pawn)",
OVCCGTK_TYPE_BOARD_STATE,
OVCCGTK_BOARD_STATE_TILE,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class,
PROP_PAWN_KIND,
g_param_spec_enum ("pawn-kind",
"Pawn kind",
"The kind of pawn to place in pawn mode",
OVCC_TYPE_PAWN_KIND,
OVCC_PAWN_KIND_NORMAL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
properties[PROP_CURSOR_POSITION] =
g_param_spec_boxed ("cursor-position",
"Cursor position",
"The current cursor position",
OVCC_TYPE_POSITION,
G_PARAM_READWRITE);
properties[PROP_MARGIN] =
g_param_spec_int ("margin",
"Margin",
"Size (in pixels) of the margin around the board",
G_MININT,
G_MAXINT,
TILE_SIZE / 2,
G_PARAM_READWRITE);
properties[PROP_ZOOM] =
g_param_spec_double ("zoom",
"Zoom",
"The zoom factor",
ZOOM_MIN,
ZOOM_MAX,
1.0,
G_PARAM_READWRITE);
properties[PROP_STATE] =
g_param_spec_enum ("state",
"State",
"The board state (tile or pawn)",
OVCCGTK_TYPE_BOARD_STATE,
OVCCGTK_BOARD_STATE_TILE,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
properties[PROP_PAWN_KIND] =
g_param_spec_enum ("pawn-kind",
"Pawn kind",
"The kind of pawn to place in pawn mode",
OVCC_TYPE_PAWN_KIND,
OVCC_PAWN_KIND_NORMAL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, N_PROPERTIES, properties);
/**
* OVCCGtkBoard::add-tile:
......@@ -370,7 +357,7 @@ set_zoom (OVCCGtkBoard *self,
if (! ZOOMS_EQ (self->priv->zoom, zoom)) {
self->priv->zoom = zoom;
g_object_notify (G_OBJECT (self), "zoom");
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ZOOM]);
gtk_widget_queue_resize (GTK_WIDGET (self));
}
}
......@@ -1161,7 +1148,7 @@ ovccgtk_board_set_margin (OVCCGtkBoard *self,
self->priv->margin = margin;
gtk_widget_queue_resize (GTK_WIDGET (self));
g_object_notify (G_OBJECT (self), "margin");
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MARGIN]);
}
/**
......@@ -1207,7 +1194,8 @@ ovccgtk_board_move_cursor (OVCCGtkBoard *self,
if (pos->x <= max_x && pos->x >= min_x &&
pos->y <= max_y && pos->y >= min_y) {
self->priv->cursor_pos = *pos;
g_object_notify (G_OBJECT (self), "cursor-position");
g_object_notify_by_pspec (G_OBJECT (self),
properties[PROP_CURSOR_POSITION]);
/* redraw the cursor */
gtk_widget_queue_draw (GTK_WIDGET (self));
moved = TRUE;
......@@ -1268,7 +1256,7 @@ ovccgtk_board_set_state (OVCCGtkBoard *self,
if (state != self->priv->state) {
self->priv->state = state;
gtk_widget_queue_draw (GTK_WIDGET (self));
g_object_notify (G_OBJECT (self), "state");
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_STATE]);
}
}
......@@ -1288,6 +1276,6 @@ ovccgtk_board_set_pawn_kind (OVCCGtkBoard *self,
if (kind != self->priv->pawn_kind) {
self->priv->pawn_kind = kind;
g_object_notify (G_OBJECT (self), "pawn-kind");
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_PAWN_KIND]);
}
}
......@@ -80,7 +80,9 @@ enum
PROP_HOSTNAME,
PROP_PORT,
PROP_USERNAME
PROP_USERNAME,
N_PROPERTIES
};
enum
......@@ -90,7 +92,8 @@ enum
};
static guint signals[N_SIGNALS] = { 0 };
static GParamSpec *properties[N_PROPERTIES] = { NULL };
static guint signals[N_SIGNALS] = { 0 };
static gboolean
......@@ -151,27 +154,29 @@ ovccgtk_connection_dialog_class_init (OVCCGtkConnectionDialogClass *klass)
klass->validate = ovccgtk_connection_dialog_real_validate;
g_object_class_install_property (object_class, PROP_HOSTNAME,
g_param_spec_string ("hostname",
"Hostname",
"The hostname",
"",
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class, PROP_PORT,
g_param_spec_uint ("port",
"Port",
"The host port",
0, 0xffff, 0xdead,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class, PROP_USERNAME,
g_param_spec_string ("username",
"Username",
"The user's name",
"",
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
properties[PROP_HOSTNAME] =
g_param_spec_string ("hostname",
"Hostname",
"The hostname",
"",
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
properties[PROP_PORT] =
g_param_spec_uint ("port",
"Port",
"The host port",
0, 0xffff, 0xdead,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
properties[PROP_USERNAME] =
g_param_spec_string ("username",
"Username",
"The user's name",
"",
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, N_PROPERTIES, properties);
signals[SIGNAL_VALIDATE] = g_signal_new ("validate",
G_TYPE_FROM_CLASS (klass),
......@@ -409,7 +414,7 @@ host_notify_handler (GObject *object,
OVCCGtkConnectionDialog *self)
{
if (validate_host (self)) {
g_object_notify (G_OBJECT (self), "hostname");
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_HOSTNAME]);
}
ovccgtk_connection_dialog_validate (self);
}
......@@ -420,7 +425,7 @@ port_notify_handler (GObject *object,
OVCCGtkConnectionDialog *self)
{
if (validate_port (self)) {
g_object_notify (G_OBJECT (self), "port");
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_PORT]);
}
ovccgtk_connection_dialog_validate (self);
}
......@@ -431,7 +436,7 @@ username_notify_handler (GObject *object,
OVCCGtkConnectionDialog *self)
{
if (validate_username (self)) {
g_object_notify (G_OBJECT (self), "username");
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_USERNAME]);
}
ovccgtk_connection_dialog_validate (self);
}
......@@ -478,7 +483,7 @@ ovccgtk_connection_dialog_set_hostname (OVCCGtkConnectionDialog *self,
if (strcmp (ovccgtk_connection_dialog_get_hostname (self), hostname) != 0) {
gtk_entry_set_text (GTK_ENTRY (self->priv->host), hostname);
g_object_notify (G_OBJECT (self), "hostname");
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_HOSTNAME]);
}
}
......@@ -505,7 +510,7 @@ ovccgtk_connection_dialog_set_port (OVCCGtkConnectionDialog *self,
* displayed. Setting the value here (even to the same) fixes the issue. */
gtk_spin_button_set_value (GTK_SPIN_BUTTON (self->priv->port), port);
if (oldval != port) {
g_object_notify (G_OBJECT (self), "port");
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_PORT]);
}
}
......@@ -526,7 +531,7 @@ ovccgtk_connection_dialog_set_username (OVCCGtkConnectionDialog *self,
if (strcmp (ovccgtk_connection_dialog_get_username (self), username) != 0) {
gtk_entry_set_text (GTK_ENTRY (self->priv->username), username);
g_object_notify (G_OBJECT (self), "username");
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_USERNAME]);
}
}
......
......@@ -69,10 +69,15 @@ enum
PROP_SECONDARY_TEXT,
PROP_SECONDARY_USE_MARKUP,
PROP_TEXT,
PROP_USE_MARKUP
PROP_USE_MARKUP,
N_PROPERTIES
};
static GParamSpec *properties[N_PROPERTIES] = { NULL };
static void
ovccgtk_message_info_class_init (OVCCGtkMessageInfoClass *klass)
{
......@@ -84,43 +89,45 @@ ovccgtk_message_info_class_init (OVCCGtkMessageInfoClass *klass)
widget_class->show_all = gtk_widget_show;
g_object_class_install_property (object_class, PROP_BUTTONS,
g_param_spec_enum ("buttons",
"Buttons",
"The buttons shown in the message info",
GTK_TYPE_BUTTONS_TYPE,
GTK_BUTTONS_NONE,
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class, PROP_SECONDARY_TEXT,
g_param_spec_string ("secondary-text",
"Secondary text",
"The secondary text",
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class, PROP_SECONDARY_USE_MARKUP,
g_param_spec_boolean ("secondary-use-markup",
"Secondary use markup",
"Whether the secondary text uses Pango markup",
FALSE,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class, PROP_TEXT,
g_param_spec_string ("text",
"Text",
"The primary text",
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class, PROP_USE_MARKUP,
g_param_spec_boolean ("use-markup",
"Use markup",
"Whether the primary text uses Pango markup",
FALSE,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
properties[PROP_BUTTONS] =
g_param_spec_enum ("buttons",
"Buttons",
"The buttons shown in the message info",
GTK_TYPE_BUTTONS_TYPE,
GTK_BUTTONS_NONE,
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
properties[PROP_SECONDARY_TEXT] =
g_param_spec_string ("secondary-text",
"Secondary text",
"The secondary text",
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
properties[PROP_SECONDARY_USE_MARKUP] =
g_param_spec_boolean ("secondary-use-markup",
"Secondary use markup",
"Whether the secondary text uses Pango markup",
FALSE,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
properties[PROP_TEXT] =
g_param_spec_string ("text",
"Text",
"The primary text",
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
properties[PROP_USE_MARKUP] =
g_param_spec_boolean ("use-markup",
"Use markup",
"Whether the primary text uses Pango markup",
FALSE,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, N_PROPERTIES, properties);
g_type_class_add_private (klass, sizeof (OVCCGtkMessageInfoPrivate));
}
......@@ -351,7 +358,7 @@ ovccgtk_message_info_set_use_markup (OVCCGtkMessageInfo *self,
gtk_label_set_use_markup (GTK_LABEL (self->priv->primary_label),
use_markup);
update_label_tooltip (self);
g_object_notify (G_OBJECT (self), "use-markup");
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_USE_MARKUP]);
}
}
......@@ -390,7 +397,8 @@ ovccgtk_message_info_set_secondary_use_markup (OVCCGtkMessageInfo *self,
if (gtk_label_get_use_markup (GTK_LABEL (self->priv->secondary_label)) != use_markup) {
gtk_label_set_use_markup (GTK_LABEL (self->priv->secondary_label),
use_markup);
g_object_notify (G_OBJECT (self), "secondary-use-markup");
g_object_notify_by_pspec (G_OBJECT (self),
properties[PROP_SECONDARY_USE_MARKUP]);
}
}
......@@ -425,7 +433,7 @@ ovccgtk_message_info_set_secondary_label (OVCCGtkMessageInfo *self,
}
gtk_widget_set_visible (self->priv->secondary_label, label != NULL);
g_object_notify (G_OBJECT (self), "secondary-text");
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SECONDARY_TEXT]);
}
const gchar *
......
......@@ -85,10 +85,15 @@ enum
PROP_0,
PROP_DEFAULT_PLAYER,
PROP_GAME
PROP_GAME,
N_PROPERTIES
};
static GParamSpec *properties[N_PROPERTIES] = { NULL };
static void
ovccgtk_player_list_class_init (OVCCGtkPlayerListClass *klass)
{
......@@ -105,20 +110,22 @@ ovccgtk_player_list_class_init (OVCCGtkPlayerListClass *klass)
widget_class->button_press_event = ovccgtk_player_list_button_press;
widget_class->button_release_event = ovccgtk_player_list_button_release;
g_object_class_install_property (object_class, PROP_DEFAULT_PLAYER,
g_param_spec_object ("default-player",
"Default player",
"The default player",
OVCC_TYPE_PLAYER,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class, PROP_GAME,
g_param_spec_object ("game",
"Game",
"The game for which show players",
OVCC_TYPE_GAME,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
properties[PROP_DEFAULT_PLAYER] =
g_param_spec_object ("default-player",
"Default player",
"The default player",
OVCC_TYPE_PLAYER,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
properties[PROP_GAME] =
g_param_spec_object ("game",
"Game",
"The game for which show players",
OVCC_TYPE_GAME,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, N_PROPERTIES, properties);
g_type_class_add_private (klass, sizeof (OVCCGtkPlayerListPrivate));
}
......@@ -441,7 +448,7 @@ ovccgtk_player_list_set_game (OVCCGtkPlayerList *self,
}
ovccgtk_player_list_update_current_player (self);
}
g_object_notify (G_OBJECT (self), "game");
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_GAME]);
}
}
......@@ -463,7 +470,7 @@ ovccgtk_player_list_set_default_player (OVCCGtkPlayerList *self,
if (self->priv->default_player != player) {
self->priv->default_player = player;
g_object_notify (G_OBJECT (self), "default-player");
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DEFAULT_PLAYER]);
}
}
......
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