1 /*
2  * This file is part of d-handy.
3  *
4  * d-handy is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * d-handy is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with d-handy; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 module handy.DialerCycleButton;
20 
21 private import glib.ConstructionException;
22 private import glib.Str;
23 private import gobject.ObjectG;
24 private import gobject.Signals;
25 private import gtk.Widget;
26 private import handy.DialerButton;
27 private import handy.c.functions;
28 public  import handy.c.types;
29 private import std.algorithm;
30 
31 
32 /** */
33 public class DialerCycleButton : DialerButton
34 {
35 	/** the main Gtk struct */
36 	protected HdyDialerCycleButton* hdyDialerCycleButton;
37 
38 	/** Get the main Gtk struct */
39 	public HdyDialerCycleButton* getDialerCycleButtonStruct(bool transferOwnership = false)
40 	{
41 		if (transferOwnership)
42 			ownedRef = false;
43 		return hdyDialerCycleButton;
44 	}
45 
46 	/** the main Gtk struct as a void* */
47 	protected override void* getStruct()
48 	{
49 		return cast(void*)hdyDialerCycleButton;
50 	}
51 
52 	/**
53 	 * Sets our main struct and passes it to the parent class.
54 	 */
55 	public this (HdyDialerCycleButton* hdyDialerCycleButton, bool ownedRef = false)
56 	{
57 		this.hdyDialerCycleButton = hdyDialerCycleButton;
58 		super(cast(HdyDialerButton*)hdyDialerCycleButton, ownedRef);
59 	}
60 
61 
62 	/** */
63 	public static GType getType()
64 	{
65 		return hdy_dialer_cycle_button_get_type();
66 	}
67 
68 	/**
69 	 * Create a new #HdyDialerCycleButton which displays @symbols. The
70 	 * symbols can by cycled through by pressing the button multiple
71 	 * times.
72 	 *
73 	 * Params:
74 	 *     symbols = the symbols displayed on the #HdyDialerCycleButton
75 	 *
76 	 * Returns: the newly created #HdyDialerCycleButton widget
77 	 *
78 	 * Throws: ConstructionException GTK+ fails to create the object.
79 	 */
80 	public this(string symbols)
81 	{
82 		auto p = hdy_dialer_cycle_button_new(Str.toStringz(symbols));
83 
84 		if(p is null)
85 		{
86 			throw new ConstructionException("null returned by new");
87 		}
88 
89 		this(cast(HdyDialerCycleButton*) p);
90 	}
91 
92 	/**
93 	 * Get the symbol the dialer should display
94 	 *
95 	 * Returns: a pointer to the symbol
96 	 */
97 	public dchar getCurrentSymbol()
98 	{
99 		return hdy_dialer_cycle_button_get_current_symbol(hdyDialerCycleButton);
100 	}
101 
102 	/**
103 	 * Get the cycle timeout in milliseconds.
104 	 */
105 	public int getCycleTimeout()
106 	{
107 		return hdy_dialer_cycle_button_get_cycle_timeout(hdyDialerCycleButton);
108 	}
109 
110 	/**
111 	 * Check whether the button is in cycling mode.
112 	 *
113 	 * Returns: #TRUE if the in cycling mode otherwise #FALSE
114 	 */
115 	public bool isCycling()
116 	{
117 		return hdy_dialer_cycle_button_is_cycling(hdyDialerCycleButton) != 0;
118 	}
119 
120 	/**
121 	 * Set the cycle timeout in milliseconds.
122 	 *
123 	 * Params:
124 	 *     timeout = the timeout in milliseconds
125 	 */
126 	public void setCycleTimeout(int timeout)
127 	{
128 		hdy_dialer_cycle_button_set_cycle_timeout(hdyDialerCycleButton, timeout);
129 	}
130 
131 	/**
132 	 * Stop the cycling mode.
133 	 */
134 	public void stopCycle()
135 	{
136 		hdy_dialer_cycle_button_stop_cycle(hdyDialerCycleButton);
137 	}
138 
139 	/**
140 	 * This signal is emitted when the cycle ends. This can either be
141 	 * because of timeout or because #hdy_dialer_cycle_stop_cycle got
142 	 * called.
143 	 */
144 	gulong addOnCycleEnd(void delegate(DialerCycleButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
145 	{
146 		return Signals.connect(this, "cycle-end", dlg, connectFlags ^ ConnectFlags.SWAPPED);
147 	}
148 
149 	/**
150 	 * This signal is emitted when the button starts cycling (that is on
151 	 * the first button press).
152 	 */
153 	gulong addOnCycleStart(void delegate(DialerCycleButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
154 	{
155 		return Signals.connect(this, "cycle-start", dlg, connectFlags ^ ConnectFlags.SWAPPED);
156 	}
157 }