Commit 3268755e authored by Adrien Plazas's avatar Adrien Plazas
Browse files

Remove the deprecated HdyDialerCycleButton

parent 99f38281
......@@ -36,15 +36,16 @@ what GNOME upstream projects do.
```c
static gboolean
button_clicked_cb (HdyDialerCycleButton *self,
GdkEventButton *event)
key_press_event_cb (GtkWidget *widget,
GdkEvent *event,
gpointer data)
```
*Bad*:
```c
static gboolean
button_clicked_cb (HdyDialerCycleButton *self, GdkEventButton *event)
key_press_event_cb (GtkWidget *widget, GdkEvent *event, gpointer data)
```
......@@ -166,8 +167,9 @@ Prefix signal enum names with *SIGNAL_*.
```c
enum {
SIGNAL_CYCLE_START = 0,
SIGNAL_CYCLE_END,
SIGNAL_SUBMITTED = 0,
SIGNAL_DELETED,
SIGNAL_SYMBOL_CLICKED,
SIGNAL_LAST_SIGNAL,
};
```
......@@ -185,7 +187,11 @@ Prefix property enum names with *PROP_*.
```c
enum {
PROP_0 = 0,
PROP_CYCLE_TIMEOUT,
PROP_NUMBER,
PROP_SHOW_ACTION_BUTTONS,
PROP_COLUMN_SPACING,
PROP_ROW_SPACING,
PROP_RELIEF,
PROP_LAST_PROP,
};
```
......@@ -234,17 +240,17 @@ Static functions don't need the class prefix. E.g. with a type foo_bar:
*Good*:
```c
static gboolean
button_clicked_cb (HdyDialerCycleButton *self,
GdkEventButton *event)
static void
grab_focus_cb (HdyDialer *dialer,
gpointer unused)
```
*Bad*:
```c
static gboolean
foo_bar_button_clicked_cb (HdyDialerCycleButton *self,
GdkEventButton *event)
static void
hdy_dialer_grab_focus_cb (HdyDialer *dialer,
gpointer unused)
```
Note however that virtual methods like
......
......@@ -38,13 +38,6 @@ libhandy-1.so.0 libhandy-1-0 #MINVER#
hdy_dialer_button_get_symbols@LIBHANDY_1_0 0.0.3
hdy_dialer_button_get_type@LIBHANDY_1_0 0.0~git20180429
hdy_dialer_button_new@LIBHANDY_1_0 0.0~git20180429
hdy_dialer_cycle_button_get_current_symbol@LIBHANDY_1_0 0.0~git20180429
hdy_dialer_cycle_button_get_cycle_timeout@LIBHANDY_1_0 0.0~git20180429
hdy_dialer_cycle_button_get_type@LIBHANDY_1_0 0.0~git20180429
hdy_dialer_cycle_button_is_cycling@LIBHANDY_1_0 0.0~git20180429
hdy_dialer_cycle_button_new@LIBHANDY_1_0 0.0~git20180429
hdy_dialer_cycle_button_set_cycle_timeout@LIBHANDY_1_0 0.0~git20180429
hdy_dialer_cycle_button_stop_cycle@LIBHANDY_1_0 0.0~git20180429
hdy_dialog_get_narrow@LIBHANDY_1_0 0.0.11
hdy_dialog_get_type@LIBHANDY_1_0 0.0.7
hdy_dialog_new@LIBHANDY_1_0 0.0.7
......
......@@ -40,7 +40,6 @@
<xi:include href="xml/hdy-column.xml"/>
<xi:include href="xml/hdy-combo-row.xml"/>
<xi:include href="xml/hdy-dialer-button.xml"/>
<xi:include href="xml/hdy-dialer-cycle-button.xml"/>
<xi:include href="xml/hdy-dialog.xml"/>
<xi:include href="xml/hdy-enum-value-object.xml"/>
<xi:include href="xml/hdy-expander-row.xml"/>
......
src/gtkprogresstracker.c
src/hdy-column.c
src/hdy-dialer-button.c
src/hdy-dialer-cycle-button.c
src/hdy-fold.c
src/hdy-header-group.c
src/hdy-leaflet.c
......
......@@ -32,7 +32,6 @@ G_BEGIN_DECLS
#include "hdy-deprecation-macros.h"
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
#include "hdy-dialer-button.h"
#include "hdy-dialer-cycle-button.h"
G_GNUC_END_IGNORE_DEPRECATIONS
#include "hdy-dialog.h"
#include "hdy-enum-value-object.h"
......
/*
* Copyright (C) 2017 Purism SPC
*
* SPDX-License-Identifier: LGPL-2.1+
*/
#include "config.h"
#include <glib/gi18n-lib.h>
#include "hdy-dialer-cycle-button.h"
/**
* SECTION:hdy-dialer-cycle-button
* @short_description: A button on a #HdyDialer keypad cycling through available symbols.
* @Title: HdyDialerCycleButton
*
* The #HdyDialerCycleButton widget is a single button on an #HdyDialer
* representing symbols such as digits, letters, #, +
* or ☃. When the button is pressed multiple times in a row, the
* symbols are cycled through. That is a call to #get_curent_symbol
* returns another symbol each time the button is pressed. If no
* further button presses are received, cycling mode ends after a
* timeout. This is configurable via the
* #HdyDialerCycleButton:cycle-timeout property.
*
* Deprecated: 0.0.12: This widget is considered a #HdyDialer internal
*/
typedef struct
{
int num; /* number of button presses in the cycle */
guint32 source_id; /* timeout handler id */
gint timeout; /* timeout between button presses */
} HdyDialerCycleButtonPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (HdyDialerCycleButton, hdy_dialer_cycle_button, HDY_TYPE_DIALER_BUTTON)
enum {
PROP_0,
PROP_CYCLE_TIMEOUT,
PROP_LAST_PROP,
};
static GParamSpec *props[PROP_LAST_PROP];
enum {
SIGNAL_CYCLE_START,
SIGNAL_CYCLE_END,
SIGNAL_LAST_SIGNAL,
};
static guint signals [SIGNAL_LAST_SIGNAL];
static void
end_cycle (HdyDialerCycleButton *self)
{
HdyDialerCycleButtonPrivate *priv =
hdy_dialer_cycle_button_get_instance_private(HDY_DIALER_CYCLE_BUTTON (self));
priv->num = 0;
priv->source_id = 0;
g_signal_emit (self, signals[SIGNAL_CYCLE_END], 0);
}
static gboolean
expire_cb (HdyDialerCycleButton *self)
{
g_return_val_if_fail (HDY_IS_DIALER_CYCLE_BUTTON (self), FALSE);
end_cycle (self);
return FALSE;
}
static gboolean
button_clicked_cb (HdyDialerCycleButton *self,
GdkEventButton *event)
{
HdyDialerCycleButtonPrivate *priv = hdy_dialer_cycle_button_get_instance_private(HDY_DIALER_CYCLE_BUTTON (self));
g_return_val_if_fail (HDY_IS_DIALER_CYCLE_BUTTON (self), FALSE);
/* Only cycle if we have more than one symbol */
if (strlen (hdy_dialer_button_get_symbols (HDY_DIALER_BUTTON (self))) < 2)
return FALSE;
if (hdy_dialer_cycle_button_is_cycling (self)) {
g_source_remove (priv->source_id);
priv->num++;
} else {
g_signal_emit (self, signals[SIGNAL_CYCLE_START], 0);
}
priv->source_id = g_timeout_add (priv->timeout,
(GSourceFunc) expire_cb,
self);
return FALSE;
}
static void
hdy_dialer_cycle_button_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
HdyDialerCycleButton *self = HDY_DIALER_CYCLE_BUTTON (object);
HdyDialerCycleButtonPrivate *priv = hdy_dialer_cycle_button_get_instance_private (self);
switch (property_id) {
case PROP_CYCLE_TIMEOUT:
priv->timeout = g_value_get_int (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
hdy_dialer_cycle_button_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
HdyDialerCycleButton *self = HDY_DIALER_CYCLE_BUTTON (object);
HdyDialerCycleButtonPrivate *priv = hdy_dialer_cycle_button_get_instance_private (self);
switch (property_id) {
case PROP_CYCLE_TIMEOUT:
g_value_set_int (value, priv->timeout);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
hdy_dialer_cycle_button_dispose (GObject *object)
{
HdyDialerCycleButton *self = HDY_DIALER_CYCLE_BUTTON (object);
HdyDialerCycleButtonPrivate *priv = hdy_dialer_cycle_button_get_instance_private (self);
if (priv->source_id) {
g_source_remove (priv->source_id);
priv->source_id = 0;
}
G_OBJECT_CLASS (hdy_dialer_cycle_button_parent_class)->dispose (object);
}
static void
hdy_dialer_cycle_button_class_init (HdyDialerCycleButtonClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = hdy_dialer_cycle_button_dispose;
object_class->set_property = hdy_dialer_cycle_button_set_property;
object_class->get_property = hdy_dialer_cycle_button_get_property;
props[PROP_CYCLE_TIMEOUT] =
g_param_spec_int ("cycle-timeout",
_("Cycle timeout"),
_("The timeout (in seconds) between button presses after"
"which a cycle ends"),
0, G_MAXINT, 1000,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
/**
* HdyDialerCycleButton::cycle-start:
* @self: The #HdyDialer instance.
*
* This signal is emitted when the button starts cycling (that is on
* the first button press).
*
* Deprecated: 0.0.12: This widget is considered a #HdyDialer internal
* api
*/
signals[SIGNAL_CYCLE_START] =
g_signal_new ("cycle-start",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (HdyDialerCycleButtonClass, cycle_start),
NULL, NULL, NULL,
G_TYPE_NONE,
0);
/**
* HdyDialerCycleButton::cycle-end:
* @self: The #HdyDialer instance.
*
* This signal is emitted when the cycle ends. This can either be
* because of timeout or because #hdy_dialer_cycle_stop_cycle got
* called.
*
* Deprecated: 0.0.12: This widget is considered a #HdyDialer internal
* api
*/
signals[SIGNAL_CYCLE_END] =
g_signal_new ("cycle-end",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (HdyDialerCycleButtonClass, cycle_end),
NULL, NULL, NULL,
G_TYPE_NONE,
0);
}
/**
* hdy_dialer_cycle_button_new:
* @symbols: the symbols displayed on the #HdyDialerCycleButton
*
* Create a new #HdyDialerCycleButton which displays @symbols. The
* symbols can by cycled through by pressing the button multiple
* times.
*
* Returns: the newly created #HdyDialerCycleButton widget
*
* Deprecated: 0.0.12: This widget is considered a #HdyDialer internal
* api
*/
GtkWidget *hdy_dialer_cycle_button_new (const gchar* symbols)
{
/* FIXME: we should call this 'symbols' in the base class already */
return g_object_new (HDY_TYPE_DIALER_CYCLE_BUTTON, "symbols", symbols, NULL);
}
static void
hdy_dialer_cycle_button_init (HdyDialerCycleButton *self)
{
GtkStyleContext *context;
GObject *secondary_label;
g_signal_connect (self, "clicked", G_CALLBACK (button_clicked_cb), NULL);
end_cycle (self);
secondary_label = gtk_widget_get_template_child (GTK_WIDGET (self), HDY_TYPE_DIALER_BUTTON, "secondary_label");
context = gtk_widget_get_style_context (GTK_WIDGET (secondary_label));
gtk_style_context_remove_class (context, "dim-label");
}
/**
* hdy_dialer_cycle_button_get_current_symbol:
* @self: a #HdyDialerCycleButton
*
* Get the symbol the dialer should display
*
* Returns: a pointer to the symbol
*
* Deprecated: 0.0.12: This widget is considered a #HdyDialer internal
* api
*/
gunichar
hdy_dialer_cycle_button_get_current_symbol (HdyDialerCycleButton *self)
{
HdyDialerCycleButtonPrivate *priv = hdy_dialer_cycle_button_get_instance_private (self);
const gchar *symbols = hdy_dialer_button_get_symbols (HDY_DIALER_BUTTON (self));
gint off = priv->num % g_utf8_strlen (symbols, -1);
return g_utf8_get_char (g_utf8_offset_to_pointer (symbols, off));
}
/**
* hdy_dialer_cycle_button_is_cycling:
* @self: a #HdyDialerCycleButton
*
* Check whether the button is in cycling mode.
*
* Returns: #TRUE if the in cycling mode otherwise #FALSE
*
* Deprecated: 0.0.12: This widget is considered a #HdyDialer internal
* api
*/
gboolean
hdy_dialer_cycle_button_is_cycling (HdyDialerCycleButton *self)
{
HdyDialerCycleButtonPrivate *priv = hdy_dialer_cycle_button_get_instance_private (self);
return !!priv->source_id;
}
/**
* hdy_dialer_cycle_button_stop_cycle:
* @self: a #HdyDialerCycleButton
*
* Stop the cycling mode.
*
* Deprecated: 0.0.12: This widget is considered a #HdyDialer internal
* api
*/
void
hdy_dialer_cycle_button_stop_cycle (HdyDialerCycleButton *self)
{
HdyDialerCycleButtonPrivate *priv = hdy_dialer_cycle_button_get_instance_private(self);
g_return_if_fail (HDY_IS_DIALER_CYCLE_BUTTON (self));
if (priv->source_id) {
g_source_remove (priv->source_id);
priv->source_id = 0;
}
end_cycle(self);
}
/**
* hdy_dialer_cycle_button_get_cycle_timeout:
* @self: a #HdyDialerCycleButton
*
* Get the cycle timeout in milliseconds.
*
* Deprecated: 0.0.12: This widget is considered a #HdyDialer internal
* api
*/
gint
hdy_dialer_cycle_button_get_cycle_timeout (HdyDialerCycleButton *self)
{
HdyDialerCycleButtonPrivate *priv = hdy_dialer_cycle_button_get_instance_private(self);
g_return_val_if_fail (HDY_IS_DIALER_CYCLE_BUTTON (self), 0);
return priv->timeout;
}
/**
* hdy_dialer_cycle_button_set_cycle_timeout:
* @self: a #HdyDialerCycleButton
* @timeout: the timeout in milliseconds
*
* Set the cycle timeout in milliseconds.
* Deprecated: 0.0.12: This widget is considered a #HdyDialer internal
* api
*/
void
hdy_dialer_cycle_button_set_cycle_timeout (HdyDialerCycleButton *self,
gint timeout)
{
g_return_if_fail (HDY_IS_DIALER_CYCLE_BUTTON (self));
g_object_set (G_OBJECT (self), "cycle-timeout", timeout, NULL);
}
/*
* Copyright (C) 2017 Purism SPC
*
* SPDX-License-Identifier: LGPL-2.1+
*/
#pragma once
#if !defined(_HANDY_INSIDE) && !defined(HANDY_COMPILATION)
#error "Only <handy.h> can be included directly."
#endif
#include "hdy-deprecation-macros.h"
#include "hdy-dialer-button.h"
G_BEGIN_DECLS
#define HDY_TYPE_DIALER_CYCLE_BUTTON (hdy_dialer_cycle_button_get_type())
G_DECLARE_DERIVABLE_TYPE (HdyDialerCycleButton, hdy_dialer_cycle_button, HDY, DIALER_CYCLE_BUTTON, HdyDialerButton)
/**
* HdyDialerCycleButtonClass:
* @parent_class: The parent classqn
* @cycle_start: Class handler for the #HdyDialerCycleButton::cycle-start signal
* @cycle_end: Class handler for the #HdyDialerCycleButton::cycle-end signal
*/
_HDY_DEPRECATED
struct _HdyDialerCycleButtonClass
{
HdyDialerButtonClass parent_class;
/* Signals */
void (*cycle_start) (HdyDialerCycleButton *self);
void (*cycle_end) (HdyDialerCycleButton *self);
};
_HDY_DEPRECATED
GtkWidget *hdy_dialer_cycle_button_new (const gchar *symbols);
_HDY_DEPRECATED
gunichar hdy_dialer_cycle_button_get_current_symbol (HdyDialerCycleButton *self);
_HDY_DEPRECATED
gboolean hdy_dialer_cycle_button_is_cycling (HdyDialerCycleButton *self);
_HDY_DEPRECATED
void hdy_dialer_cycle_button_stop_cycle (HdyDialerCycleButton *self);
_HDY_DEPRECATED
gint hdy_dialer_cycle_button_get_cycle_timeout (HdyDialerCycleButton *self);
_HDY_DEPRECATED
void hdy_dialer_cycle_button_set_cycle_timeout (HdyDialerCycleButton *self,
gint timeout);
G_END_DECLS
......@@ -66,7 +66,6 @@ src_headers = [
'hdy-combo-row.h',
'hdy-deprecation-macros.h',
'hdy-dialer-button.h',
'hdy-dialer-cycle-button.h',
'hdy-dialog.h',
'hdy-enum-value-object.h',
'hdy-expander-row.h',
......@@ -111,7 +110,6 @@ src_sources = [
'hdy-column.c',
'hdy-combo-row.c',
'hdy-dialer-button.c',
'hdy-dialer-cycle-button.c',
'hdy-dialog.c',
'hdy-enum-value-object.c',
'hdy-expander-row.c',
......
......@@ -21,7 +21,6 @@ test_link_args = [
test_names = [
'test-action-row',
'test-combo-row',
'test-dialer-cycle-button',
'test-dialog',
'test-expander-row',
'test-header-bar',
......
/*
* Copyright (C) 2017 Purism SPC
*
* SPDX-License-Identifier: LGPL-2.1+
*/
#define HANDY_USE_UNSTABLE_API
#include <handy.h>
gint notified;
static void
cycle_end_cb(GtkWidget *widget, gpointer data)
{
notified++;
}
static void
test_hdy_dialer_cycle_button_cycle_end(void)
{
GtkWidget *btn;
btn = hdy_dialer_cycle_button_new ("abc");
g_signal_connect (btn, "cycle-end", G_CALLBACK (cycle_end_cb), NULL);
hdy_dialer_cycle_button_stop_cycle (HDY_DIALER_CYCLE_BUTTON (btn));
g_assert_cmpint (1, ==, notified);
notified = 0;
}
static void
test_hdy_dialer_cycle_button_cycle_timeout(void)
{
HdyDialerCycleButton *btn;
btn = HDY_DIALER_CYCLE_BUTTON (hdy_dialer_cycle_button_new ("abc"));
g_assert_cmpint (1000, ==, hdy_dialer_cycle_button_get_cycle_timeout (btn));
hdy_dialer_cycle_button_set_cycle_timeout (btn, 10);
g_assert_cmpint (10, ==, hdy_dialer_cycle_button_get_cycle_timeout (btn));
}
gint
main (gint argc,
gchar *argv[])
{
gtk_test_init (&argc, &argv, NULL);
hdy_init (&argc, &argv);
g_test_add_func("/Handy/DialerCycleButton/cycle_end", test_hdy_dialer_cycle_button_cycle_end);
g_test_add_func("/Handy/DialerCycleButton/cycle_timeout", test_hdy_dialer_cycle_button_cycle_timeout);
return g_test_run();
}
Supports Markdown
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