aboutsummaryrefslogtreecommitdiffstats
path: root/shell/e-folder.c
blob: ba6e10b22e3f9f14878d39e79983d71a775bc058 (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
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */

/*
 * e-folder.c: Abstract class for Evolution folders
 *
 * Author:
 *   Miguel de Icaza (miguel@helixcode.com)
 *
 * (C) 2000 Helix Code, Inc.
 */


#include <config.h>
#include <gtk/gtksignal.h>
#include <libgnome/libgnome.h>
#include "e-util/e-util.h"
#include "e-folder.h"

#define PARENT_TYPE gtk_object_get_type ()

static GtkObjectClass *parent_class;

#define EFC(o) E_FOLDER_CLASS (GTK_OBJECT (o)->klass)

enum {
    CHANGED,
    LAST_SIGNAL
};
static guint efolder_signals [LAST_SIGNAL] = { 0, };

static void
e_folder_destroy (GtkObject *object)
{
    EFolder *efolder = E_FOLDER (object);
    
    if (efolder->uri)
        g_free (efolder->uri);

    if (efolder->desc)
        g_free (efolder->desc);

    if (efolder->home_page)
        g_free (efolder->home_page);
    
    parent_class->destroy (object);
}

static void
e_folder_class_init (GtkObjectClass *object_class)
{
    parent_class = gtk_type_class (PARENT_TYPE);

    object_class->destroy = e_folder_destroy;

    efolder_signals [CHANGED] =
        gtk_signal_new ("changed",
                GTK_RUN_LAST,
                object_class->type,
                GTK_SIGNAL_OFFSET (EFolderClass, changed),
                gtk_marshal_NONE__NONE,
                GTK_TYPE_NONE,
                0);

    /* Register our signals */
    gtk_object_class_add_signals (
        object_class, efolder_signals, LAST_SIGNAL);
}

static void
e_folder_init (GtkObject *object)
{
}

E_MAKE_TYPE (e_folder, "EFolder", EFolder, e_folder_class_init, e_folder_init, PARENT_TYPE)

void
e_folder_set_uri (EFolder *efolder, const char *uri)
{
    g_return_if_fail (efolder != NULL);
    g_return_if_fail (E_IS_FOLDER (efolder));
    g_return_if_fail (uri != NULL);

    if (efolder->uri)
        g_free (efolder->uri);
    
    efolder->uri = g_strdup (uri);
}

const char *
e_folder_get_uri (EFolder *efolder)
{
    g_return_val_if_fail (efolder != NULL, NULL);
    g_return_val_if_fail (E_IS_FOLDER (efolder), NULL);

    return efolder->uri;
}

void
e_folder_set_description (EFolder *efolder, const char *desc)
{
    g_return_if_fail (efolder != NULL);
    g_return_if_fail (E_IS_FOLDER (efolder));
    g_return_if_fail (desc != NULL);

    if (efolder->desc)
        g_free (efolder->desc);
    
    efolder->desc = g_strdup (desc);
}

const char *
e_folder_get_description (EFolder *efolder)
{
    g_return_val_if_fail (efolder != NULL, NULL);
    g_return_val_if_fail (E_IS_FOLDER (efolder), NULL);

    return efolder->desc;
}

void
e_folder_set_home_page (EFolder *efolder, const char *home_page)
{
    g_return_if_fail (efolder != NULL);
    g_return_if_fail (E_IS_FOLDER (efolder));
    g_return_if_fail (home_page != NULL);

    if (efolder->home_page)
        g_free (efolder->home_page);
    
    efolder->home_page = g_strdup (home_page);
}

const char *
e_folder_get_home_page   (EFolder *efolder)
{
    g_return_val_if_fail (efolder != NULL, NULL);
    g_return_val_if_fail (E_IS_FOLDER (efolder), NULL);

    return efolder->home_page;
}

const char *
e_folder_get_type_name (EFolder *efolder)
{
    g_return_val_if_fail (efolder != NULL, NULL);
    g_return_val_if_fail (E_IS_FOLDER (efolder), NULL);

    switch (efolder->type){
    case E_FOLDER_MAIL:
        return _("A folder containing mail items");

    case E_FOLDER_CONTACTS:
        return _("A folder containing contacts");
        
    case E_FOLDER_CALENDAR:
        return _("A folder containing calendar entries");
        
    case E_FOLDER_TASKS:
        return _("A folder containing tasks");

    default:
        g_assert_not_reached ();
    }

    return NULL;
}


EFolderType
e_folder_get_folder_type (EFolder *efolder)
{
    g_return_val_if_fail (efolder != NULL, E_FOLDER_OTHER);
    g_return_val_if_fail (E_IS_FOLDER (efolder), E_FOLDER_OTHER);
    
    return (efolder->type);
}




void
e_folder_construct (EFolder *efolder, EFolderType type,
            const char *uri, const char *name,
            const char *desc, const char *home_page,
            const char *view_name)
{
    g_return_if_fail (efolder != NULL);
    g_return_if_fail (E_IS_FOLDER (efolder));

    /* EFolders are self-owned */
    GTK_OBJECT_UNSET_FLAGS (GTK_OBJECT (efolder), GTK_FLOATING);

    if (uri)
        efolder->uri = g_strdup (uri);
    if (name)
        efolder->name = g_strdup (name);
    if (desc)
        efolder->desc = g_strdup (desc);
    if (home_page)
        efolder->home_page = g_strdup (home_page);
    if (view_name)
        efolder->view_name = g_strdup (view_name);

    efolder->type = type;
}

EFolder *
e_folder_new (EFolderType type,
          const char *uri, const char *name,
          const char *desc, const char *home_page,
          const char *view_name)
{
    EFolder *efolder;
    
    efolder = gtk_type_new (e_folder_get_type ());

    e_folder_construct (efolder, type, uri, name, desc, home_page, view_name);
    return efolder;
}

const char *
e_folder_get_name (EFolder *efolder)
{
    g_return_val_if_fail (efolder != NULL, NULL);
    g_return_val_if_fail (E_IS_FOLDER (efolder), NULL);

    return efolder->name;
}

void
e_folder_set_name (EFolder *efolder, const char *name)
{
    g_return_if_fail (efolder != NULL);
    g_return_if_fail (E_IS_FOLDER (efolder));

    if (efolder->name)
        g_free (efolder->name);

    efolder->name = g_strdup (name);
}

const char *
e_folder_get_view_name (EFolder *efolder)
{
    g_return_val_if_fail (efolder != NULL, NULL);
    g_return_val_if_fail (E_IS_FOLDER (efolder), NULL);

    return efolder->view_name;
}

void
e_folder_set_view_name (EFolder *efolder, const char *view_name)
{
    g_return_if_fail (efolder != NULL);
    g_return_if_fail (E_IS_FOLDER (efolder));

    if (efolder->view_name)
        g_free (efolder->view_name);

    efolder->view_name = g_strdup (view_name);

    gtk_signal_emit (GTK_OBJECT (efolder),
             efolder_signals [CHANGED]);
}