~ubuntu-branches/ubuntu/maverick/almanah/maverick

« back to all changes in this revision

Viewing changes to src/events/calendar-appointment.c

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Ebner
  • Date: 2009-05-16 15:49:21 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090516154921-2uhvlj8btb4qygmd
Tags: 0.6.1-0ubuntu1
* New upstream release (LP: #368078)
* debian/control:
  - Bump Standards-Version to 3.8.1
  - Add intltool, libedataserver1.2-dev, libedataserverui1.2-dev, 
    libecal1.2-dev, libcryptui-dev as build dependency
  - Remove build dependency on autotools-dev and chrpath
* debian/{control/compat/rules}: Move to mimalistic dh7 style
* Update debian/watch
* Update copyright information

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
 
2
/*
 
3
 * Almanah
 
4
 * Copyright (C) Philip Withnall 2008 <philip@tecnocode.co.uk>
 
5
 * 
 
6
 * Almanah is free software: you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation, either version 3 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * Almanah is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with Almanah.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
#include <glib.h>
 
21
#include <glib/gi18n.h>
 
22
 
 
23
#include "event.h"
 
24
#include "calendar-appointment.h"
 
25
#include "main.h"
 
26
 
 
27
static void almanah_calendar_appointment_event_init (AlmanahCalendarAppointmentEvent *self);
 
28
static void almanah_calendar_appointment_event_finalize (GObject *object);
 
29
static const gchar *almanah_calendar_appointment_event_format_value (AlmanahEvent *event);
 
30
static gboolean almanah_calendar_appointment_event_view (AlmanahEvent *event);
 
31
 
 
32
struct _AlmanahCalendarAppointmentEventPrivate {
 
33
        gchar *summary;
 
34
        GTime start_time;
 
35
};
 
36
 
 
37
G_DEFINE_TYPE (AlmanahCalendarAppointmentEvent, almanah_calendar_appointment_event, ALMANAH_TYPE_EVENT)
 
38
#define ALMANAH_CALENDAR_APPOINTMENT_EVENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ALMANAH_TYPE_CALENDAR_APPOINTMENT_EVENT, AlmanahCalendarAppointmentEventPrivate))
 
39
 
 
40
static void
 
41
almanah_calendar_appointment_event_class_init (AlmanahCalendarAppointmentEventClass *klass)
 
42
{
 
43
        GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 
44
        AlmanahEventClass *event_class = ALMANAH_EVENT_CLASS (klass);
 
45
 
 
46
        g_type_class_add_private (klass, sizeof (AlmanahCalendarAppointmentEventPrivate));
 
47
 
 
48
        gobject_class->finalize = almanah_calendar_appointment_event_finalize;
 
49
 
 
50
        event_class->name = _("Calendar Appointment");
 
51
        event_class->description = _("An appointment on an Evolution calendar.");
 
52
        event_class->icon_name = "appointment-new";
 
53
 
 
54
        event_class->format_value = almanah_calendar_appointment_event_format_value;
 
55
        event_class->view = almanah_calendar_appointment_event_view;
 
56
}
 
57
 
 
58
static void
 
59
almanah_calendar_appointment_event_init (AlmanahCalendarAppointmentEvent *self)
 
60
{
 
61
        self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, ALMANAH_TYPE_CALENDAR_APPOINTMENT_EVENT, AlmanahCalendarAppointmentEventPrivate);
 
62
}
 
63
 
 
64
static void
 
65
almanah_calendar_appointment_event_finalize (GObject *object)
 
66
{
 
67
        AlmanahCalendarAppointmentEventPrivate *priv = ALMANAH_CALENDAR_APPOINTMENT_EVENT_GET_PRIVATE (object);
 
68
 
 
69
        g_free (priv->summary);
 
70
 
 
71
        /* Chain up to the parent class */
 
72
        G_OBJECT_CLASS (almanah_calendar_appointment_event_parent_class)->finalize (object);
 
73
}
 
74
 
 
75
AlmanahCalendarAppointmentEvent *
 
76
almanah_calendar_appointment_event_new (const gchar *summary, GTime start_time)
 
77
{
 
78
        AlmanahCalendarAppointmentEvent *event = g_object_new (ALMANAH_TYPE_CALENDAR_APPOINTMENT_EVENT, NULL);
 
79
        event->priv->summary = g_strdup (summary);
 
80
        event->priv->start_time = start_time;
 
81
 
 
82
        return event;
 
83
}
 
84
 
 
85
static const gchar *
 
86
almanah_calendar_appointment_event_format_value (AlmanahEvent *event)
 
87
{
 
88
        return ALMANAH_CALENDAR_APPOINTMENT_EVENT (event)->priv->summary;
 
89
}
 
90
 
 
91
static gboolean
 
92
almanah_calendar_appointment_event_view (AlmanahEvent *event)
 
93
{
 
94
        AlmanahCalendarAppointmentEventPrivate *priv = ALMANAH_CALENDAR_APPOINTMENT_EVENT (event)->priv;
 
95
        struct tm utc_date_tm;
 
96
        gchar *command_line;
 
97
        gboolean retval;
 
98
        GError *error = NULL;
 
99
 
 
100
        gmtime_r ((const time_t*) &(priv->start_time), &utc_date_tm);
 
101
 
 
102
        /* FIXME: once bug 409200 is fixed, we'll have to make this hh:mm:ss
 
103
         * instead of hhmmss */
 
104
        command_line = g_strdup_printf ("evolution calendar:///?startdate=%.4d%.2d%.2dT%.2d%.2d%.2dZ",
 
105
                                        utc_date_tm.tm_year + 1900,
 
106
                                        utc_date_tm.tm_mon + 1,
 
107
                                        utc_date_tm.tm_mday,
 
108
                                        utc_date_tm.tm_hour,
 
109
                                        utc_date_tm.tm_min,
 
110
                                        0);
 
111
 
 
112
        if (almanah->debug == TRUE)
 
113
                g_debug ("Executing \"%s\".", command_line);
 
114
 
 
115
        retval = gdk_spawn_command_line_on_screen (gtk_widget_get_screen (almanah->main_window), command_line, &error);
 
116
        g_free (command_line);
 
117
 
 
118
        if (retval == FALSE) {
 
119
                GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW (almanah->main_window),
 
120
                                                            GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
 
121
                                                            _("Error launching Evolution"));
 
122
                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
 
123
                gtk_dialog_run (GTK_DIALOG (dialog));
 
124
                gtk_widget_destroy (dialog);
 
125
 
 
126
                g_error_free (error);
 
127
 
 
128
                return FALSE;
 
129
        }
 
130
 
 
131
        return TRUE;
 
132
}