aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui/year-view.c
blob: e8cb12feb32511363ec478b9c6791d448bea9e27 (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
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
/* Week view composite widget for gncal
 *
 * Copyright (C) 1998 The Free Software Foundation
 *
 * Author: Arturo Espinosa <arturo@nuclecu.unam.mx>
 * 
 * Heavily based on Federico Mena's week view.
 * 
 */

#include "gncal-year-view.h"
#include "calendar.h"
#include "timeutil.h"

static void gncal_year_view_init (GncalYearView *yview);

static void
double_click(GtkCalendar *gc, GncalYearView *yview)
{
    struct tm tm;
    time_t t;

    tm.tm_mday = gc->selected_day;
    tm.tm_mon  = gc->month;
    tm.tm_year = gc->year - 1900;
    tm.tm_hour = 0;
    tm.tm_min  = 0;
    tm.tm_sec  = 0;
    tm.tm_isdst  = -1;
    t = mktime (&tm);

    gnome_calendar_dayjump (yview->gcal, t);
}
    
static void
do_nothing(GtkCalendarClass *c)
{
}

static void
select_day(GtkWidget *widget, gpointer data)
{
    int i;
    
    GncalYearView *yview;
    
    yview = GNCAL_YEAR_VIEW(data);
    
    for (i = 0; i < 12; i++)
      gtk_signal_handler_block(GTK_OBJECT(yview->calendar[i]),
                   yview->handler[i]);
    
    for (i = 0; i < 12; i++)
      if (GTK_CALENDAR(yview->calendar[i]) != GTK_CALENDAR(widget))
        gtk_calendar_select_day(GTK_CALENDAR(yview->calendar[i]), 0);
                          
    for (i = 0; i < 12; i++)
      gtk_signal_handler_unblock(GTK_OBJECT(yview->calendar[i]),
                   yview->handler[i]);
}

guint
gncal_year_view_get_type (void)
{
        static guint year_view_type = 0;

    if (!year_view_type) {
        GtkTypeInfo year_view_info = {
            "GncalYearView",
            sizeof (GncalYearView),
            sizeof (GncalYearViewClass),
            (GtkClassInitFunc) NULL,
            (GtkObjectInitFunc) gncal_year_view_init,
            (GtkArgSetFunc) NULL,
            (GtkArgGetFunc) NULL
        };

        year_view_type = gtk_type_unique (gtk_table_get_type (), 
                          &year_view_info);
    }

    return year_view_type;
}

static void
gncal_year_view_init (GncalYearView *yview)
{
    int i;
    
    for (i = 0; i < 12; i++) {
        yview->calendar[i] = NULL;
        yview->handler [i] = 0;
    }
    
    yview->gcal = NULL;
    yview->year_label = NULL;
    yview->year = 0;
}

GtkWidget *
gncal_year_view_new (GnomeCalendar *calendar, time_t date)
{
    struct tm my_tm = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    char monthbuff[40];
    GncalYearView *yview;
    GtkWidget *frame, *vbox, *label;
    struct tm *tmptm;
    int i, x, y;

    yview = gtk_type_new (gncal_year_view_get_type ());

    tmptm = localtime(&date);
    yview->year = tmptm->tm_year;
    yview->gcal = calendar;
    my_tm.tm_year = tmptm->tm_year;
    yview->year_label = gtk_label_new("");
    gtk_table_attach (GTK_TABLE (yview), 
              GTK_WIDGET (yview->year_label),
              1, 2,
              0, 1,
              0, 0, 0, 5);
    gtk_widget_show(GTK_WIDGET(yview->year_label));
    
    for (x = 0; x < 3; x++)
      for (y = 0; y < 4; y++) {
          
          i = y * 3 + x;
          
          yview->calendar[i] = gtk_calendar_new();
          gtk_calendar_display_options(GTK_CALENDAR(yview->calendar[i]), 
                           GTK_CALENDAR_SHOW_DAY_NAMES |
                           GTK_CALENDAR_NO_MONTH_CHANGE);
          frame = gtk_frame_new(NULL);
          vbox = gtk_vbox_new(0,0);
        
          yview->handler[i] = 
            gtk_signal_connect(GTK_OBJECT(yview->calendar[i]), "day_selected", 
                       GTK_SIGNAL_FUNC(select_day), (gpointer *) yview);
          
          gtk_signal_connect(GTK_OBJECT(yview->calendar[i]), "day_selected_double_click",
                     GTK_SIGNAL_FUNC(double_click), (gpointer *) yview);

          my_tm.tm_mon = i;
          strftime(monthbuff, 40, "%B", &my_tm);
          label = gtk_label_new(monthbuff);
        
          gtk_container_add(GTK_CONTAINER(frame), vbox);
          gtk_box_pack_start(GTK_BOX(vbox), label, 0, 0, 0);
          gtk_box_pack_start(GTK_BOX(vbox), yview->calendar[i], 0, 0, 0);
          
          gtk_table_attach (GTK_TABLE (yview), 
                    GTK_WIDGET (frame),
                    x, x + 1,
                    y + 1, y + 2,
                    0, 0, 0, 0);

          gtk_widget_show (frame);
          gtk_widget_show (vbox);
          gtk_widget_show (GTK_WIDGET (yview->calendar[i]));
      }

    gncal_year_view_set (yview, date);
    
    return GTK_WIDGET (yview);
}

static void
year_view_mark_day (iCalObject *ical, time_t start, time_t end, void *closure)
{
    GncalYearView *yview = (GncalYearView *) closure;
    struct tm tm_s;
    int days, day;
    time_t t, day_end;

    tm_s = *localtime (&start);
    day_end = time_end_of_day (end);

    for (t = start; t <= day_end; t+= 60*60*24){
        time_t new = mktime (&tm_s);
        struct tm tm_day;
        
        tm_day = *localtime (&new);
        gtk_calendar_mark_day (GTK_CALENDAR (yview->calendar [tm_day.tm_mon]),
                       tm_day.tm_mday);
        tm_s.tm_mday++;
    }
}

static void
gncal_year_view_set_year (GncalYearView *yview, int year)
{
    time_t year_begin, year_end;
    char buff[20];
    GList  *l;
    int i;

    if (!yview->gcal->cal)
        return;
    
    snprintf(buff, 20, "%d", yview->year + 1900);
    gtk_label_set(GTK_LABEL(yview->year_label), buff);

    for (i = 0; i < 12; i++) {
        gtk_calendar_freeze (GTK_CALENDAR (yview->calendar [i]));
        gtk_calendar_select_month (GTK_CALENDAR(yview->calendar[i]), i, yview->year + 1900);
        gtk_calendar_clear_marks (GTK_CALENDAR (yview->calendar[i]));
    }
    
    year_begin = time_year_begin (yview->year);
    year_end   = time_year_end   (yview->year);

    l = calendar_get_events_in_range (yview->gcal->cal, year_begin, year_end);
    for (; l; l = l->next){
        CalendarObject *co = l->data;

        year_view_mark_day (co->ico, co->ev_start, co->ev_end, yview);
    }
    for (i = 0; i < 12; i++) 
        gtk_calendar_thaw (GTK_CALENDAR (yview->calendar [i]));

    calendar_destroy_event_list (l);
}

void
gncal_year_view_set (GncalYearView *yview, time_t date)
{
    struct tm *tmptm;

    tmptm = localtime(&date);
    yview->year = tmptm->tm_year;

    gncal_year_view_set_year (yview, yview->year);
}

void
gncal_year_view_update (GncalYearView *yview, iCalObject *ico, int flags)
{
    g_return_if_fail (yview != NULL);
    g_return_if_fail (GNCAL_IS_YEAR_VIEW (yview));

    /* If only the summary changed, we dont care */
    if (flags && (flags & CHANGE_SUMMARY) == flags)
        return;

    gncal_year_view_set_year (yview, yview->year);
}
td>Bharath Acharya2008-08-1232-17/+146 * Added necessary libraries to link to. Build break while compiling onBharath Acharya2008-08-126-1/+30 * ** Fixes bug #546892Matthew Barnes2008-08-1276-404/+299 * Updated Portuguese translation.Duarte Loreto2008-08-112-4111/+5092 * Updated Galician translationIgnacio Casal Quinteiro2008-08-112-169/+176 * ** Fix for bug #352695Milan Crha2008-08-112-2/+11 * ** Fix for bug #519292Milan Crha2008-08-117-54/+56 * ** Fix for bug #352695Milan Crha2008-08-117-23/+139 * ** Part fix for bug #529743Srinivasa Ragavan2008-08-112-0/+21 * Don't use uninitialized exception. It leads to freeing uninitializedSrinivasa Ragavan2008-08-112-2/+13 * 2.23.90Chao-Hsiung Liao2008-08-093-8068/+9909 * ** Fix for bug #546748Michael Monreal2008-08-092-1/+9 * Updated Spanish translationJorge Gonzalez Gonzalez2008-08-092-54/+28 * Remove unused EShell pointer from ImportData.Matthew Barnes2008-08-092-2/+5 * ** Additional fix for bug #467115Michael Monreal2008-08-0810-4/+16 * ** Fix for bug #546744Michael Monreal2008-08-082-1/+8 * ** Fix for bug #544117Milan Crha2008-08-082-3/+10 * Translation updated by Ivar SmolinPriit Laes2008-08-082-1775/+2210 * ** Fix for bug #546788Paul Bolle2008-08-084-21/+16 * ** Fixes bug #546785Paul Bolle2008-08-084-2/+24 * Updated Spanish translationJorge Gonzalez Gonzalez2008-08-081-286/+184 * Updated Spanish translationJorge Gonzalez Gonzalez2008-08-082-196/+346 * Updated Galician translationIgnacio Casal Quinteiro2008-08-082-178/+283 * ** Fixes bug #467115Matthew Barnes2008-08-078-73/+70 * ** Fixes bug #530402Matthew Barnes2008-08-072-4/+11 * ** Fix for bug #324203Milan Crha2008-08-073-2/+69 * ** Fix for bug #535745Milan Crha2008-08-074-19/+394 * ** Fix for bug #546668Paul Bolle2008-08-073-4/+8 * Use CamelDList instead of EDList.Matthew Barnes2008-08-073-5/+11 * Updated spanish translationJorge Gonzalez Gonzalez2008-08-072-528/+587 * Updated Spanish translationJorge Gonzalez Gonzalez2008-08-072-81/+37 * ** Fix for bug #249844Milan Crha2008-08-0611-17/+51 * ** Fix for bug #467115Michael Monreal2008-08-0623-9/+38 * ** Fix for bug #531288Michael Monreal2008-08-064-1/+11 * ** Fix for bug #546263Milan Crha2008-08-062-21/+37 * Updated Arabic Translation by Abou Manal. Djihed Afifi2008-08-062-458/+494 * ** Fix for bug #435969Milan Crha2008-08-062-0/+10 * Evolution 2.23.6 release and version bump.EVOLUTION_2_23_6Srinivasa Ragavan2008-08-063-1/+68 * Updated Spanish translationJorge Gonzalez Gonzalez2008-08-062-2732/+2821 * Fix a performance issue, where we can just go by the presence than theSrinivasa Ragavan2008-08-052-1/+9 * Committed Translation by Sweta KothariSweta Kothari2008-08-052-3953/+4729 * Updated Galician translationIgnacio Casal Quinteiro2008-08-053-107/+109 * Use G_STRLOC or G_STRFUNC instead of deprecated G_GNUC_PRETTY_FUNCTION.Matthew Barnes2008-08-055-10/+20 * Updated Russian translationLeonid Kanter2008-08-042-1884/+2019 * Patch from Matthias Braun <matze@braunis.de>: Fix for bug #544051 (WebDAV bac...Suman Manjunath2008-08-045-1/+432 * Patch from Paul Bolle <pebolle@tiscali.nl>: Fix for bug #544252 (Use names c...Suman Manjunath2008-08-042-3/+10 * Patch from Paul Bolle <pebolle@tiscali.nl>: Fix for bug #544157 (Sort View /...Suman Manjunath2008-08-042-2/+9 * Patch from Paul Bolle <pebolle@tiscali.nl>: Fix for bug #543058 (Use "Inbox"...Suman Manjunath2008-08-043-1/+15 * Patch from Paul Bolle <pebolle@tiscali.nl>: Fix related to bug #539268 (Do n...Suman Manjunath2008-08-042-0/+8 * Matthew Barnes <mbarnes@redhat.com> ** Fixes bug #249844 (Use C_() macro ins...Suman Manjunath2008-08-0410-13/+48 * Patch from Paul Bolle <pebolle@tiscali.nl>: Fixes bug #537088 (Message heade...Suman Manjunath2008-08-042-2/+10 * Make Claude happy (bug #544886 comment 4).Andre Klapper2008-08-042-1/+5 * Typo fixes and fix for bug #544886 on behalf of Allan Day.Andre Klapper2008-08-042-6/+11 * Update German translation.Andre Klapper2008-08-042-2751/+2754 * ** Fixes bug #546057Matthew Barnes2008-08-0313-13/+36 * Updated Galician translationIgnacio Casal Quinteiro2008-08-022-21/+34 * ** Fixes bug #428384Matthew Barnes2008-08-022-2/+11 * ** Fixes bug #514006Matthew Barnes2008-08-024-8/+24 * Updated Galician translationIgnacio Casal Quinteiro2008-08-02