aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui/ea-gnome-calendar.c
blob: ad7d108c25219962bfad4f2750549c8ad19a1529 (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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/*
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) version 3.
 *
 * 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with the program; if not, see <http://www.gnu.org/licenses/>
 *
 *
 * Authors:
 *      Bolian Yin <bolian.yin@sun.com>
 *
 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 *
 */

#include "ea-gnome-calendar.h"
#include "e-calendar-view.h"
#include <string.h>
#include <gtk/gtk.h>
#include <libecal/e-cal-time-util.h>
#include <libedataserver/e-data-server-util.h>
#include <glib/gi18n.h>

static void ea_gnome_calendar_class_init (EaGnomeCalendarClass *klass);

static gint ea_gnome_calendar_get_n_children (AtkObject* obj);
static AtkObject * ea_gnome_calendar_ref_child (AtkObject *obj, gint i);

static void ea_gcal_dates_change_cb (GnomeCalendar *gcal, gpointer data);

static gpointer parent_class = NULL;

static G_CONST_RETURN gchar *
ea_gnome_calendar_get_name (AtkObject *accessible)
{
    if (accessible->name)
        return accessible->name;
    return _("Gnome Calendar");
}

static G_CONST_RETURN gchar *
ea_gnome_calendar_get_description (AtkObject *accessible)
{
    if (accessible->description)
        return accessible->description;
    return <glossary id="apx-gloss">
  
  <title>Glossary</title>
  
  <glossentry id="assistant">
    <glossterm>Assistant:</glossterm>
    <glossdef>
      <para>
            A tool which guides a user through a series of steps,
    usually to configure or set up a program.  Equivalent to "Wizard"
    and "Druid."
      </para>
    </glossdef>
  </glossentry>

  <glossentry id="attachment">
  <glossterm>Attachment:</glossterm>
  <glossdef>
   <para>
    Any file sent along with an email.  Attachments may be embedded in
    a message or appended to it.
   </para>
  </glossdef>
 </glossentry>

<glossentry id="automatic-indexing">
  <glossterm>Automatic Indexing:</glossterm>
  <glossdef>
   <para>
     Pre-fetching procedure that allows
     <application>Evolution</application> to refer to data quickly.
     It enables faster searches and decreases memory usage for
     data displays.
   </para>
  </glossdef>
 </glossentry>

 <glossentry id="bcc">
  <glossterm>Bcc (Blind Carbon Copy):</glossterm>
  <glossdef>
   <para>
    A way of addressing a message.  Bcc is used to send a group of
    people an e-mail, while hiding their names and addresses from each
    other.
   </para>
  </glossdef>
 </glossentry>

 <glossentry id="cc">
  <glossterm>Cc (Carbon Copy):</glossterm>
  <glossdef>
   <para>
    Carbon-copies are used to send a 3rd party a copy of the e-mail,
    so they an keep up to date on a conversation, without being in the
    To: list.
   </para>
  </glossdef>
 </glossentry>

 <glossentry id="conduit">
  <glossterm>Conduit:</glossterm>
  <glossdef>
   <para>
     A small application which controls
     the transfer of data between a handheld device and a desktop
     computer.
   </para>
  </glossdef>
 </glossentry>


 <glossentry id="druid">
  <glossterm>Druid:</glossterm>
  <glossdef>
   <para>
     See "Assistant."
   </para>
  </glossdef>
 </glossentry>

 <glossentry id="evolution">
  <glossterm>Evolution:</glossterm>
  <glossdef>
   <para>
    <application>Evolution</application> is the <acronym> GNOME
    </acronym> groupware application.
   </para>
  </glossdef>
 </glossentry>

 <glossentry id="execute">
  <glossterm>Execute:</glossterm>
  <glossdef>
   <para>
    To run a program.  Any file that can be run is called an
    executable.  <application>Evolution</application> can download
    executable attachments, but before they can be run, the files must
    be marked as executable with a shell or file manager.  This
    security precaution prevents the automatic or accidental execution
    of malicious programs. For more information on executables and file
    permissions, see the documentation for your file manager or shell.
   </para>
  </glossdef>
 </glossentry>

 <glossentry id="expunge">
  <glossterm>Expunge:</glossterm>
  <glossdef>
   <para>
     When messages are marked for deletion, they remain till they are expunged.
     When a message is expunged, it is permanently deleted, as long as it was
     marked for deletion.
   </para>
  </glossdef>
 </glossentry>

 <glossentry id="filetree">
  <glossterm>File Tree:</glossterm>
  <glossdef>
   <para>
     A way of describing a group of files on a computer.  With the
     perversity typical of computer (and especially Unix and Linux)
     nomenclature, the top of the tree is called the root directory,
     and denoted by <filename>/</filename>.
     The rest of the "branches" spread downward from the root.  Don't
     confuse the root directory with the root
     account, or root's home directory, normally
     <filename>/root</filename>.
   </para>
  </glossdef>
 </glossentry>

 <glossentry id="filter">
  <glossterm>Filter:</glossterm>
  <glossdef>
   <para>
    Within <application>Evolution</application>, a filter is a method
    of sorting mail automatically when it's downloaded.  You can create filters to perform
    one or more actions on a message that meets any (or all) of a wide
    range of criteria.
   </para>
  </glossdef>
 </glossentry>

 <glossentry id="forward">
  <glossterm>Forward:</glossterm>
  <glossdef>
   <para>
    If you get a message intended for someone else, you can use
    message forwarding to send it on to the right person. 
   </para>
  </glossdef>5">, end_tm;
    static gchar buffer[512];
    gchar end_buffer[256];
    GnomeCalendarViewType view;

    model = gnome_calendar_get_model (gcal);
    zone = e_cal_model_get_timezone (model);

    view_type = gnome_calendar_get_view (gcal);
    calendar_view = gnome_calendar_get_calendar_view (gcal, view_type);

    e_calendar_view_get_visible_time_range (
        calendar_view, &start_time, &end_time);

    start_tt = icaltime_from_timet_with_zone (start_time, FALSE, zone);
    start_tm.tm_year = start_tt.year - 1900;
    start_tm.tm_mon = start_tt.month - 1;
    start_tm.tm_mday = start_tt.day;
    start_tm.tm_hour = start_tt.hour;
    start_tm.tm_min = start_tt.minute;
    start_tm.tm_sec = start_tt.second;
    start_tm.tm_isdst = -1;
    start_tm.tm_wday = time_day_of_week (start_tt.day, start_tt.month - 1,
                         start_tt.year);

    /* Take one off end_time so we don't get an extra day. */
    end_tt = icaltime_from_timet_with_zone (end_time - 1, FALSE, zone);
    end_tm.tm_year = end_tt.year - 1900;
    end_tm.tm_mon = end_tt.month - 1;
    end_tm.tm_mday = end_tt.day;
    end_tm.tm_hour = end_tt.hour;
    end_tm.tm_min = end_tt.minute;
    end_tm.tm_sec = end_tt.second;
    end_tm.tm_isdst = -1;
    end_tm.tm_wday = time_day_of_week (end_tt.day, end_tt.month - 1,
                       end_tt.year);

    view = gnome_calendar_get_view (gcal);

    switch (view) {
    case GNOME_CAL_DAY_VIEW:
    case GNOME_CAL_WORK_WEEK_VIEW:
    case GNOME_CAL_WEEK_VIEW:
        if (start_tm.tm_year == end_tm.tm_year
            && start_tm.tm_mon == end_tm.tm_mon
            && start_tm.tm_mday == end_tm.tm_mday) {
            e_utf8_strftime (buffer, sizeof (buffer),
                    _("%A %d %b %Y"), &start_tm);
        } else if (start_tm.tm_year == end_tm.tm_year) {
            e_utf8_strftime (buffer, sizeof (buffer),
                    _("%a %d %b"), &start_tm);
            e_utf8_strftime (end_buffer, sizeof (end_buffer),
                    _("%a %d %b %Y"), &end_tm);
            strcat (buffer, " - ");
            strcat (buffer, end_buffer);
        } else {
            e_utf8_strftime (buffer, sizeof (buffer),
                    _("%a %d %b %Y"), &start_tm);
            e_utf8_strftime (end_buffer, sizeof (end_buffer),
                    _("%a %d %b %Y"), &end_tm);
            strcat (buffer, " - ");
            strcat (buffer, end_buffer);
        }
        break;
    case GNOME_CAL_MONTH_VIEW:
    case GNOME_CAL_LIST_VIEW:
        if (start_tm.tm_year == end_tm.tm_year) {
            if (start_tm.tm_mon == end_tm.tm_mon) {
                if (start_tm.tm_mday == end_tm.tm_mday) {
                    buffer [0] = '\0';
                } else {
                    e_utf8_strftime (buffer, sizeof (buffer),
                            "%d", &start_tm);
                    strcat (buffer, " - ");
                }
                e_utf8_strftime (end_buffer, sizeof (end_buffer),
                        _("%d %b %Y"), &end_tm);
                strcat (buffer, end_buffer);
            } else {
                e_utf8_strftime (buffer, sizeof (buffer),
                        _("%d %b"), &start_tm);
                e_utf8_strftime (end_buffer, sizeof (end_buffer),
                        _("%d %b %Y"), &end_tm);
                strcat (buffer, " - ");
                strcat (buffer, end_buffer);
            }
        } else {
            e_utf8_strftime (buffer, sizeof (buffer),
                    _("%d %b %Y"), &start_tm);
            e_utf8_strftime (end_buffer, sizeof (end_buffer),
                    _("%d %b %Y"), &end_tm);
            strcat (buffer, " - ");
            strcat (buffer, end_buffer);
        }
        break;
    default:
        g_return_val_if_reached (NULL);
    }
    return buffer;
}

static gint
ea_gnome_calendar_get_n_children (AtkObject* obj)
{
    g_return_val_if_fail (EA_IS_GNOME_CALENDAR (obj), 0);

    if (!GTK_ACCESSIBLE (obj)->widget)
        return -1;
    return 2;
}

static AtkObject *
ea_gnome_calendar_ref_child (AtkObject *obj, gint i)
{
    AtkObject * child = NULL;
    GnomeCalendar * calendarWidget;
    GnomeCalendarViewType view_type;
    ECalendarView *view;
    ECalendar *date_navigator;
    GtkWidget *childWidget;

    g_return_val_if_fail (EA_IS_GNOME_CALENDAR (obj), NULL);
    /* valid child index range is [0-3] */
    if (i < 0 || i >3 )
        return NULL;

    if (!GTK_ACCESSIBLE (obj)->widget)
        return NULL;
    calendarWidget = GNOME_CALENDAR (GTK_ACCESSIBLE (obj)->widget);

    switch (i) {
    case 0:
        /* for the day/week view */
        view_type = gnome_calendar_get_view (calendarWidget);
        view = gnome_calendar_get_calendar_view (calendarWidget, view_type);
        childWidget = GTK_WIDGET (view);
        child = gtk_widget_get_accessible (childWidget);
        atk_object_set_parent (child, obj);
        break;
    case 1:
        /* for calendar */
        date_navigator = gnome_calendar_get_date_navigator (calendarWidget);
        childWidget = GTK_WIDGET (date_navigator);
        child = gtk_widget_get_accessible (childWidget);
        break;
    default:
        break;
    }
    if (child)
        g_object_ref(child);
    return child;
}

static void
ea_gcal_dates_change_cb (GnomeCalendar *gcal, gpointer data)
{
    const gchar *new_name;

    g_return_if_fail (GNOME_IS_CALENDAR (gcal));
    g_return_if_fail (data);
    g_return_if_fail (EA_IS_GNOME_CALENDAR (data));

    new_name = ea_gnome_calendar_get_label_description (gcal);
    atk_object_set_name (ATK_OBJECT(data), new_name);
    g_signal_emit_by_name (data, "visible_data_changed");

#ifdef ACC_DEBUG
    printf ("AccDebug: calendar dates changed, label=%s\n", new_name);
#endif
}