aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui/prop.c
blob: 58abe2f8db4e32ab24c8d2ff34f5891b02827d14 (plain) (blame)
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
/*
 * Calendar properties dialog box
 * (C) 1998 the Free Software Foundation
 *
 * Author: Miguel de Icaza <miguel@kernel.org>
 */
#include <config.h>
#include <gnome.h>
#include "gnome-cal.h"
#include "main.h"

static GtkWidget *prop_win, *r1;
static GtkObject *sa, *ea;

static void
start_changed (GtkAdjustment *sa, GtkAdjustment *ea)
{
    if (sa->value > 23.0){
        sa->value = 23.0;
        ea->value = 24.0;
        gtk_signal_emit_by_name (GTK_OBJECT (sa), "value_changed");
        gtk_signal_emit_by_name (GTK_OBJECT (ea), "value_changed");
    } else if (sa->value >= ea->value){
        ea->value = sa->value + 1.0;
        gtk_signal_emit_by_name (GTK_OBJECT (ea), "value_changed");
    }
    gnome_property_box_changed (GNOME_PROPERTY_BOX (prop_win));
}

static void
end_changed (GtkAdjustment *ea, GtkAdjustment *sa)
{
    if (ea->value < 1.0){
        ea->value = 1.0;
        sa->value = 0.0;
        gtk_signal_emit_by_name (GTK_OBJECT (ea), "value_changed");
        gtk_signal_emit_by_name (GTK_OBJECT (sa), "value_changed");
    } else if (ea->value < sa->value){
        sa->value = ea->value - 1.0;
        gtk_signal_emit_by_name (GTK_OBJECT (sa), "value_changed");
    }
    gnome_property_box_changed (GNOME_PROPERTY_BOX (prop_win));
}

/* justifies the text */
static GtkWidget *
align (GtkWidget *w, float side)
{
    GtkWidget *a;

    a = gtk_alignment_new (side, 0.5, 1.0, 1.0);
    gtk_container_add (GTK_CONTAINER (a), w);

    return a;
}

static int
prop_cancel (void)
{
    prop_win = 0;
    return FALSE;
}

static void
prop_apply (GtkWidget *w, int page)
{
    if (page != -1)
        return;
    
    day_begin = GTK_ADJUSTMENT (sa)->value;
    day_end   = GTK_ADJUSTMENT (ea)->value;
    gnome_config_set_int ("/calendar/Calendar/Day start", day_begin);
    gnome_config_set_int ("/calendar/Calendar/Day end", day_end);

    am_pm_flag = (GTK_TOGGLE_BUTTON (r1)->active) == 0;
    gnome_config_set_bool ("/calendar/Calendar/AM PM flag", am_pm_flag);

    gnome_config_sync ();

    day_range_changed ();
}

static void
toggled ()
{
    gnome_property_box_changed (GNOME_PROPERTY_BOX (prop_win));
}

void
properties (void)
{
    GtkWidget *t, *l, *ds, *de;
    GtkWidget *r2;

    if (prop_win)
        return;
    
    prop_win = gnome_property_box_new ();

    t = gtk_table_new (0, 0, 0);
    gnome_property_box_append_page (GNOME_PROPERTY_BOX (prop_win), t,
                    gtk_label_new (_("Calendar global parameters")));
    
    l = gtk_label_new (_("Day start:"));
    gtk_table_attach (GTK_TABLE (t), l,
              0, 1, 0, 1, 0, 0, 0, 0);
    sa = gtk_adjustment_new (day_begin, 0.0, 25.00, 1.0, 1.0, 1.0);
    ds = gtk_hscale_new (GTK_ADJUSTMENT (sa));
    gtk_scale_set_digits (GTK_SCALE (ds), 0);
    gtk_table_attach (GTK_TABLE (t), ds,
              1, 2, 0, 1, GTK_FILL | GTK_EXPAND, 0, 0, 0);
        
    l = gtk_label_new (_("Day end:"));
    gtk_table_attach (GTK_TABLE (t), l,
              0, 1, 1, 2, 0, 0, 0, 0);
    ea = gtk_adjustment_new (day_end, 0.0, 25.00, 1.0, 1.0, 1.0);
    de = gtk_hscale_new (GTK_ADJUSTMENT (ea));
    gtk_scale_set_digits (GTK_SCALE (de), 0);
    gtk_table_attach (GTK_TABLE (t), de,
              1, 2, 1, 2, GTK_FILL | GTK_EXPAND, 0, 0, 0);

    gtk_signal_connect (sa, "value_changed",
                GTK_SIGNAL_FUNC (start_changed), ea);
    gtk_signal_connect (ea, "value_changed",
                GTK_SIGNAL_FUNC (end_changed), sa);

    /* Nice spacing :-) */
    gtk_table_attach (GTK_TABLE (t), gtk_label_new (""),
              0, 1, 2, 3, 0, 0, 0, 0);
    
    r1 = gtk_radio_button_new_with_label (NULL, _("24 hour format"));
    r2 = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (r1),
                              _("12 hour format"));
    if (am_pm_flag)
        gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (r2), 1);

    gtk_signal_connect (GTK_OBJECT (r1), "toggled",
                GTK_SIGNAL_FUNC (toggled), NULL);
    
    gtk_table_attach (GTK_TABLE (t), align (r1, 0.0), 0, 2, 3, 4, GTK_FILL | GTK_EXPAND, 0, 0, 0);
    gtk_table_attach (GTK_TABLE (t), align (r2, 0.0), 0, 2, 4, 5, GTK_FILL | GTK_EXPAND, 0, 0, 0);

    gtk_signal_connect (GTK_OBJECT (prop_win), "destroy",
                GTK_SIGNAL_FUNC (prop_cancel), NULL);
    
    gtk_signal_connect (GTK_OBJECT (prop_win), "delete_event",
                GTK_SIGNAL_FUNC (prop_cancel), NULL);
    
    gtk_signal_connect (GTK_OBJECT (prop_win), "apply",
                GTK_SIGNAL_FUNC (prop_apply), NULL);
    
    gtk_widget_show_all (prop_win);
}