aboutsummaryrefslogtreecommitdiffstats
path: root/mail/message-tag-followup.c
blob: bee65fab6d8be03af265db77c334b0d669eccf21 (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
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 *  Authors: Jeffrey Stedfast <fejj@ximian.com>
 *
 *  Copyright 2002 Ximian, Inc. (www.ximian.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 Street #330, Boston, MA 02111-1307, USA.
 *
 */


#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <glade/glade.h>

#include <libgnome/gnome-defs.h>
#include <libgnomeui/gnome-window-icon.h>
#include <libgnomeui/gnome-pixmap.h>

#include <gal/widgets/e-unicode.h>
#include <gal/util/e-unicode-i18n.h>

#include "message-tag-followup.h"
#include "mail-config.h"

static void message_tag_followup_class_init (MessageTagFollowUpClass *class);
static void message_tag_followup_init (MessageTagFollowUp *followup);
static void message_tag_followup_finalise (GtkObject *obj);

static CamelTag *get_tag_list (MessageTagEditor *editor);
static void set_tag_list (MessageTagEditor *editor, CamelTag *tags);


#define DEFAULT_FLAG  2  /* Follow-Up */
static char *available_flags[] = {
    N_("Call"),
    N_("Do Not Forward"),
    N_("Follow-Up"),
    N_("For Your Information"),
    N_("Forward"),
    N_("No Response Necessary"),
    N_("Read"),
    N_("Reply"),
    N_("Reply to All"),
    N_("Review"),
};

static int num_available_flags = sizeof (available_flags) / sizeof (available_flags[0]);


static MessageTagEditorClass *parent_class = NULL;


GtkType
message_tag_followup_get_type (void)
{
    static GtkType type = 0;
    
    if (!type) {
        GtkTypeInfo type_info = {
            "MessageTagFollowUp",
            sizeof (MessageTagFollowUp),
            sizeof (MessageTagFollowUpClass),
            (GtkClassInitFunc) message_tag_followup_class_init,
            (GtkObjectInitFunc) message_tag_followup_init,
            (GtkArgSetFunc) NULL,
            (GtkArgGetFunc) NULL
        };
        
        type = gtk_type_unique (message_tag_editor_get_type (), &type_info);
    }
    
    return type;
}

static void
message_tag_followup_class_init (MessageTagFollowUpClass *klass)
{
    GtkObjectClass *object_class;
    MessageTagEditorClass *editor_class;
    
    object_class = (GtkObjectClass *) klass;
    editor_class = (MessageTagEditorClass *) klass;
    parent_class = gtk_type_class (message_tag_editor_get_type ());
    
    object_class->finalize = message_tag_followup_finalise;
    
    editor_class->get_tag_list = get_tag_list;
    editor_class->set_tag_list = set_tag_list;
}

static void
message_tag_followup_init (MessageTagFollowUp *editor)
{
    editor->combo = NULL;
    editor->target_date = NULL;
    editor->completed = NULL;
    editor->clear = NULL;
    editor->completed_date = 0;
}


static void
message_tag_followup_finalise (GtkObject *obj)
{
    MessageTagFollowUp *editor = (MessageTagFollowUp *) obj;
    
    editor->completed_date = 0;
    
        ((GtkObjectClass *)(parent_class))->finalize (obj);
}


static CamelTag *
get_tag_list (MessageTagEditor *editor)
{
    MessageTagFollowUp *followup = (MessageTagFollowUp *) editor;
    CamelTag *tags = NULL;
    time_t date;
    char *text;
    
    text = e_utf8_gtk_entry_get_text (GTK_ENTRY (followup->combo->entry));
    camel_tag_set (&tags, "follow-up", text);
    g_free (text);
    
    date = e_date_edit_get_time (followup->target_date);
    if (date != (time_t) -1) {
        text = header_format_date (date, 0);
        camel_tag_set (&tags, "due-by", text);
        g_free (text);
    } else {
        camel_tag_set (&tags, "due-by", "");
    }
    
    if (gtk_toggle_button_get_active (followup->completed)) {
        text = header_format_date (followup->completed_date, 0);
        camel_tag_set (&tags, "completed-on", text);
        g_free (text);
    } else {
        camel_tag_set (&tags, "completed-on", "");
    }
    
    return tags;
}

static void
set_tag_list (MessageTagEditor *editor, CamelTag *tags)
{
    MessageTagFollowUp *followup = (MessageTagFollowUp *) editor;
    const char *text;
    time_t date;
    
    text = camel_tag_get (&tags, "follow-up");
    if (text)
        e_utf8_gtk_entry_set_text (GTK_ENTRY (followup->combo->entry), text);
    
    text = camel_tag_get (&tags, "due-by");
    if (text && *text) {
        date = header_decode_date (text, NULL);
        e_date_edit_set_time (followup->target_date, date);
    } else {
        e_date_edit_set_time (followup->target_date, (time_t) -1);
    }
    
    text = camel_tag_get (&tags, "completed-on");
    if (text && *text) {
        date = header_decode_date (text, NULL);
        if (date != (time_t) 0) {
            gtk_toggle_button_set_active (followup->completed, TRUE);
            followup->completed_date = date;
        }
    }
}

static void
clear_clicked (GtkButton *button, gpointer user_data)
{
    MessageTagFollowUp *followup = user_data;
    
    gtk_list_select_item (GTK_LIST (followup->combo->list), DEFAULT_FLAG);
    
    e_date_edit_set_time (followup->target_date, (time_t) -1);
    gtk_toggle_button_set_active (followup->completed, FALSE);
}

static void
completed_toggled (GtkToggleButton *button, gpointer user_data)
{
    MessageTagFollowUp *followup = user_data;
    
    if (gtk_toggle_button_get_active (followup->completed))
        followup->completed_date = time (NULL);
    else
        followup->completed_date = 0;
}

GtkWidget *target_date_new (const char *s1, const char *s2, int i1, int i2);

GtkWidget *
target_date_new (const char *s1, const char *s2, int i1, int i2)
{
    GtkWidget *widget;
    int start;

    widget = e_date_edit_new ();
    e_date_edit_set_show_date (E_DATE_EDIT (widget), TRUE);
    e_date_edit_set_show_time (E_DATE_EDIT (widget), TRUE);

    start = (mail_config_get_week_start_day()+6) % 7;   /* Note that this is 0 (Sun) to 6 (Sat), conver to 0 (mon) to 6 (sun) */

    e_date_edit_set_week_start_day (E_DATE_EDIT (widget), start);
    e_date_edit_set_use_24_hour_format (E_DATE_EDIT (widget), mail_config_get_time_24hour());
    e_date_edit_set_allow_no_date_set (E_DATE_EDIT (widget), TRUE);
    e_date_edit_set_time_popup_range (E_DATE_EDIT (widget), 0, 24);
    
    return widget;
}

static void
construct (MessageTagEditor *editor)
{
    MessageTagFollowUp *followup = (MessageTagFollowUp *) editor;
    GtkWidget *widget;
    GList *strings;
    GladeXML *gui;
    int i;
    
    gtk_window_set_title (GTK_WINDOW (editor), _("Flag to Follow Up"));
    gnome_window_icon_set_from_file (GTK_WINDOW (editor), EVOLUTION_IMAGES "/flag-for-followup-16.png");
    
    gui = glade_xml_new (EVOLUTION_GLADEDIR "/message-tags.glade", "followup_editor");
    
    widget = glade_xml_get_widget (gui, "toplevel");
    
    /* reparent */
    gtk_widget_reparent (widget, GNOME_DIALOG (editor)->vbox);
    
    widget = glade_xml_get_widget (gui, "pixmap");
    gnome_pixmap_load_file (GNOME_PIXMAP (widget), EVOLUTION_GLADEDIR "/flag-for-followup-48.png");
    
    followup->message_list = GTK_CLIST (glade_xml_get_widget (gui, "message_list"));
    
    followup->combo = GTK_COMBO (glade_xml_get_widget (gui, "combo"));
    gtk_combo_set_case_sensitive (followup->combo, FALSE);
    strings = NULL;
    for (i = 0; i < num_available_flags; i++)
        strings = g_list_append (strings, (char *) _(available_flags[i]));
    gtk_combo_set_popdown_strings (followup->combo, strings);
    g_list_free (strings);
    gtk_list_select_item (GTK_LIST (followup->combo->list), DEFAULT_FLAG);
    
    followup->target_date = E_DATE_EDIT (glade_xml_get_widget (gui, "target_date"));
    e_date_edit_set_time (followup->target_date, (time_t) -1);
    
    followup->completed = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui, "completed"));
    gtk_signal_connect (GTK_OBJECT (followup->completed), "toggled",
                completed_toggled, followup);
    
    followup->clear = GTK_BUTTON (glade_xml_get_widget (gui, "clear"));
    gtk_signal_connect (GTK_OBJECT (followup->clear), "clicked",
                clear_clicked, followup);
    
    gtk_object_unref (GTK_OBJECT (gui));
}

MessageTagEditor *
message_tag_followup_new (void)
{
    MessageTagEditor *editor;
    
    editor = (MessageTagEditor *) gtk_type_new (message_tag_followup_get_type ());
    construct (editor);
    
    return editor;
}

void
message_tag_followup_append_message (MessageTagFollowUp *editor,
                     const char *from,
                     const char *subject)
{
    char *text[3];
    
    g_return_if_fail (IS_MESSAGE_TAG_FOLLOWUP (editor));
    
    text[0] = e_utf8_to_gtk_string (GTK_WIDGET (editor->message_list), from);
    text[1] = e_utf8_to_gtk_string (GTK_WIDGET (editor->message_list), subject);
    text[2] = NULL;
    
    gtk_clist_append (editor->message_list, text);
    
    g_free (text[0]);
    g_free (text[1]);
}