1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
|
/*
* Copyright (C) 2004-2006 Jimmy Do <crispyleaves@gmail.com>
*
* 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
#include "layout-utils.h"
/* for _() macro */
#include <libgnome/gnome-i18n.h>
GtkWidget *
create_group_box (GtkWidget *header_widget)
{
GtkWidget *two_row_vbox;
GtkWidget *two_column_hbox;
GtkWidget *spacer_label;
GtkWidget *content_vbox;
two_row_vbox = gtk_vbox_new (FALSE, 6);
two_column_hbox = gtk_hbox_new (FALSE, 0);
spacer_label = gtk_label_new (" ");
content_vbox = gtk_vbox_new (FALSE, 6);
gtk_box_pack_start (GTK_BOX (two_row_vbox), header_widget, FALSE, FALSE, 0);
/* TO-DO: allow this to *not* expand if necessary - do this by packing in widget in content_vbox
* that will not expand & not fill
*/
gtk_box_pack_start (GTK_BOX (two_row_vbox), two_column_hbox, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (two_column_hbox), spacer_label, FALSE, FALSE, 0);
/* TO-DO: allow this to *not* expand if necesssary */
gtk_box_pack_start (GTK_BOX (two_column_hbox), content_vbox, TRUE, TRUE, 0);
gtk_widget_show (spacer_label);
gtk_widget_show (content_vbox);
gtk_widget_show (two_column_hbox);
g_object_set_data (G_OBJECT (two_row_vbox), "content-vbox", content_vbox);
return two_row_vbox;
}
/*
GtkWidget *
create_group_box_with_label (const gchar *label)
{
GtkWidget *label_widget;
gchar *label_str;
label_str = g_strdup_printf ("<span weight=\"bold\">%s</span>", label);
label_widget = gtk_label_new (label_str);
g_object_set (G_OBJECT (label_widget), "use-markup", TRUE, "xalign", 0.0, NULL);
gtk_widget_show (label_widget);
return create_group_box (label_widget);
}
*/
void
group_box_add_row_full (GtkWidget *group_box, GtkWidget *row_widget, gboolean expand, gboolean fill)
{
GtkWidget *content_vbox;
content_vbox = g_object_get_data (G_OBJECT (group_box), "content-vbox");
gtk_box_pack_start (GTK_BOX (content_vbox), row_widget, expand, fill, 0);
}
void
group_box_add_row (GtkWidget *group_box, GtkWidget *row_widget)
{
group_box_add_row_full (group_box, row_widget, FALSE, FALSE);
}
GtkWidget *
create_duration_chooser (void)
{
GtkWidget *time_select_area;
time_select_area = gtk_vbox_new (FALSE, 6);
{
GtkWidget *row_hbox;
GtkWidget *label;
GtkAdjustment *spin_adj;
GtkWidget *spin_button;
GtkSizeGroup *size_group;
size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
g_object_set_data (G_OBJECT (time_select_area), "size-group", size_group);
row_hbox = gtk_hbox_new (FALSE, 6);
label = gtk_label_new_with_mnemonic (_("_Hours:"));
g_object_set (G_OBJECT (label), "xalign", 0.0, NULL);
gtk_size_group_add_widget (size_group, label);
gtk_box_pack_start (GTK_BOX (row_hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
spin_adj = (GtkAdjustment *) gtk_adjustment_new (0, 0, MAX_NUM_HOURS, 1, 1, 1);
spin_button = gtk_spin_button_new (spin_adj, 1.0, 0);
g_object_set (G_OBJECT (spin_button), "activates-default", TRUE, NULL);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin_button);
gtk_box_pack_start (GTK_BOX (row_hbox), spin_button, TRUE, TRUE, 0);
gtk_widget_show (spin_button);
gtk_box_pack_start (GTK_BOX (time_select_area), row_hbox, FALSE, FALSE, 0);
gtk_widget_show (row_hbox);
g_object_set_data (G_OBJECT (time_select_area), "spin-hours", spin_button);
row_hbox = gtk_hbox_new (FALSE, 6);
label = gtk_label_new_with_mnemonic (_("_Minutes:"));
g_object_set (G_OBJECT (label), "xalign", 0.0, NULL);
gtk_size_group_add_widget (size_group, label);
gtk_box_pack_start (GTK_BOX (row_hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
spin_adj = (GtkAdjustment *) gtk_adjustment_new (0, 0, 59, 1, 1, 1);
spin_button = gtk_spin_button_new (spin_adj, 1.0, 0);
g_object_set (G_OBJECT (spin_button), "activates-default", TRUE, NULL);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin_button);
gtk_box_pack_start (GTK_BOX (row_hbox), spin_button, TRUE, TRUE, 0);
gtk_widget_show (spin_button);
gtk_box_pack_start (GTK_BOX (time_select_area), row_hbox, FALSE, FALSE, 0);
gtk_widget_show (row_hbox);
g_object_set_data (G_OBJECT (time_select_area), "spin-minutes", spin_button);
row_hbox = gtk_hbox_new (FALSE, 6);
label = gtk_label_new_with_mnemonic (_("_Seconds:"));
g_object_set (G_OBJECT (label), "xalign", 0.0, NULL);
gtk_size_group_add_widget (size_group, label);
gtk_box_pack_start (GTK_BOX (row_hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
spin_adj = (GtkAdjustment *) gtk_adjustment_new (0, 0, 59, 1, 1, 1);
spin_button = gtk_spin_button_new (spin_adj, 1.0, 0);
g_object_set (G_OBJECT (spin_button), "activates-default", TRUE, NULL);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), spin_button);
gtk_box_pack_start (GTK_BOX (row_hbox), spin_button, TRUE, TRUE, 0);
gtk_widget_show (spin_button);
gtk_box_pack_start (GTK_BOX (time_select_area), row_hbox, FALSE, FALSE, 0);
gtk_widget_show (row_hbox);
g_object_set_data (G_OBJECT (time_select_area), "spin-seconds", spin_button);
}
return time_select_area;
}
GtkWidget *
duration_chooser_get_hours_spin (GtkWidget *duration_chooser)
{
return g_object_get_data (G_OBJECT (duration_chooser), "spin-hours");
}
GtkWidget *
duration_chooser_get_minutes_spin (GtkWidget *duration_chooser)
{
return g_object_get_data (G_OBJECT (duration_chooser), "spin-minutes");
}
GtkWidget *
duration_chooser_get_seconds_spin (GtkWidget *duration_chooser)
{
return g_object_get_data (G_OBJECT (duration_chooser), "spin-seconds");
}
GtkSizeGroup *
duration_chooser_get_labels_size_group (GtkWidget *duration_chooser)
{
return g_object_get_data (G_OBJECT (duration_chooser), "size-group");
}
/**
* Given a number of seconds, this function returns a string representing
* the remaining amount of time. The caller should free the returned string
* when it's finished being used.
* show_all indicates whether this function should return hours:minutes:seconds.
* shorten_zero indicates whether a "shortened" string (currenty, an empty string)
* should be returned when remaining_seconds is equal to zero.
* If show_all == false, it returns either hours:minutes or minutes:seconds,
* depending on how much time is remaining, so that the user isn't given
* information he doesn't need.
*/
gchar *
construct_time_str (guint remaining_seconds, gboolean show_all, gboolean shorten_zero)
{
guint hours, minutes, seconds;
gchar *time_str;
if (!shorten_zero || remaining_seconds > 0)
{
hours = remaining_seconds / 3600;
minutes = (remaining_seconds - (hours * 3600)) / 60;
seconds = remaining_seconds - (hours *3600) - (minutes * 60);
g_assert (hours <= MAX_NUM_HOURS);
g_assert (minutes <= 59);
g_assert (seconds <= 59);
/* Strip hour indication field if we don't time hours and skip seconds
* indicator if we are.
*/
if (show_all) {
/* hours:minutes:seconds */
time_str = g_strdup_printf (_("%.2u:%.2u:%.2u"), hours, minutes, seconds);
}
else {
if ((hours > 0) || (minutes > 14)) {
/* hours:minutes */
time_str = g_strdup_printf (_("%.2u:%.2u"), hours, minutes);
}
else {
/* minutes:seconds */
time_str = g_strdup_printf (_("%.2u:%.2u"), minutes, seconds);
}
}
}
else
{
time_str = g_strdup ("");
}
return time_str;
}
/**
* Given a preset name and its associated duration of seconds,
* this function returns a string that can be used to display the preset.
* Caller is responsible for freeing the string when done.
*/
gchar *
construct_display_name (const gchar *name, guint duration)
{
gchar *display_name;
gchar *time_str;
time_str = construct_time_str (duration,
TRUE /* always show hh:mm:ss */,
FALSE /* don't shorten zero */);
/* <name of preset> (<number of hours, minutes, and seconds>) */
display_name = g_strdup_printf (_("%s (%s)"), name, time_str);
g_free (time_str);
time_str = NULL;
return display_name;
}
|