aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/gui/component/addressbook-component.c
blob: 6138aaf6eaf33221e1153b5e0966511dd2924111 (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
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* addressbook-component.c
 *
 * Copyright (C) 2003  Ettore Perazzoli
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU General Public
 * License as published by the Free Software Foundation.
 *
 * 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 Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * Author: Ettore Perazzoli <ettore@ximian.com>
 */

/* EPFIXME: Add autocompletion setting.  */


#include <config.h>

#include "addressbook-component.h"
#include "addressbook-config.h"
#include "addressbook-migrate.h"
#include "addressbook-view.h"
#include "addressbook/gui/contact-editor/eab-editor.h"
#include "addressbook/gui/widgets/eab-gui-util.h"

#include "widgets/misc/e-task-bar.h"
#include "widgets/misc/e-info-label.h"

#include <string.h>
#include <bonobo/bonobo-i18n.h>
#include <gtk/gtkimage.h>
#include <gconf/gconf-client.h>
#include <gal/util/e-util.h>

#ifdef ENABLE_SMIME
#include "smime/gui/component.h"
#endif


#define PARENT_TYPE bonobo_object_get_type ()
static BonoboObjectClass *parent_class = NULL;

struct _AddressbookComponentPrivate {
    GConfClient *gconf_client;
    char *base_directory;
};

/* Evolution::Component CORBA methods.  */

static void
impl_createControls (PortableServer_Servant servant,
             Bonobo_Control *corba_sidebar_control,
             Bonobo_Control *corba_view_control,
             Bonobo_Control *corba_statusbar_control,
             CORBA_Environment *ev)
{
    AddressbookView *view = addressbook_view_new ();
    BonoboControl *sidebar_control;
    BonoboControl *view_control;
    BonoboControl *statusbar_control;

    sidebar_control = bonobo_control_new (addressbook_view_peek_sidebar (view));
    view_control = addressbook_view_peek_folder_view (view);
    statusbar_control = bonobo_control_new (addressbook_view_peek_statusbar (view));

    *corba_sidebar_control = CORBA_Object_duplicate (BONOBO_OBJREF (sidebar_control), ev);
    *corba_view_control = CORBA_Object_duplicate (BONOBO_OBJREF (view_control), ev);
    *corba_statusbar_control = CORBA_Object_duplicate (BONOBO_OBJREF (statusbar_control), ev);
}

static GNOME_Evolution_CreatableItemTypeList *
impl__get_userCreatableItems (PortableServer_Servant servant,
                  CORBA_Environment *ev)
{
    GNOME_Evolution_CreatableItemTypeList *list = GNOME_Evolution_CreatableItemTypeList__alloc ();

    list->_length  = 3;
    list->_maximum = list->_length;
    list->_buffer  = GNOME_Evolution_CreatableItemTypeList_allocbuf (list->_length);

    CORBA_sequence_set_release (list, FALSE);

    list->_buffer[0].id = "contact";
    list->_buffer[0].description = _("New Contact");
    list->_buffer[0].menuDescription = _("_Contact");
    list->_buffer[0].tooltip = _("Create a new contact");
    list->_buffer[0].menuShortcut = 'c';
    list->_buffer[0].iconName = "evolution-contacts-mini.png";
    list->_buffer[0].type = GNOME_Evolution_CREATABLE_OBJECT;

    list->_buffer[1].id = "contact_list";
    list->_buffer[1].description = _("New Contact List");
    list->_buffer[1].menuDescription = _("Contact _List");
    list->_buffer[1].tooltip = _("Create a new contact list");
    list->_buffer[1].menuShortcut = 'l';
    list->_buffer[1].iconName = "contact-list-16.png";
    list->_buffer[1].type = GNOME_Evolution_CREATABLE_OBJECT;

    list->_buffer[2].id = "address_book";
    list->_buffer[2].description = _("New Contacts Group");
    list->_buffer[2].menuDescription = _("_Contacts Group");
    list->_buffer[2].tooltip = _("Create a new contacts group");
    list->_buffer[2].menuShortcut = 'g';
    list->_buffer[2].iconName = "evolution-contacts-mini.png";
    list->_buffer[2].type = GNOME_Evolution_CREATABLE_FOLDER;

    return list;
}

static void
impl_requestCreateItem (PortableServer_Servant servant,
            const CORBA_char *item_type_name,
            CORBA_Environment *ev)
{
    AddressbookComponent *addressbook_component = ADDRESSBOOK_COMPONENT (bonobo_object_from_servant (servant));
    AddressbookComponentPrivate *priv;
    EBook *book = NULL;
    EContact *contact;

    priv = addressbook_component->priv;

    if (!strcmp (item_type_name, "address_book")) {
        addressbook_config_create_new_source (NULL);
        return;
    }

    if (!e_book_get_default_addressbook (&book, NULL)) {
        CORBA_exception_set (ev, CORBA_USER_EXCEPTION, ex_GNOME_Evolution_Component_Failed, NULL);
        return;
    }

    contact = e_contact_new ();

    if (!item_type_name) {
        CORBA_exception_set (ev, CORBA_USER_EXCEPTION, ex_GNOME_Evolution_Component_UnknownType, NULL);
    }
    else if (!strcmp (item_type_name, "contact")) {
        eab_show_contact_editor (book, contact, TRUE, TRUE);
    }
    else if (!strcmp (item_type_name, "contact_list")) {
        eab_show_contact_list_editor (book, contact, TRUE, TRUE);
    }
    else {
        CORBA_exception_set (ev, CORBA_USER_EXCEPTION, ex_GNOME_Evolution_Component_UnknownType, NULL);
    }

    g_object_unref (book);
    g_object_unref (contact);
}

static CORBA_boolean
impl_upgradeFromVersion (PortableServer_Servant servant, short major, short minor, short revision, CORBA_Environment *ev)
{
    return addressbook_migrate (addressbook_component_peek (), major, minor, revision);
}

static CORBA_boolean
impl_requestQuit (PortableServer_Servant servant, CORBA_Environment *ev)
{
    return eab_editor_request_close_all ();
}

/* GObject methods.  */

static void
impl_dispose (GObject *object)
{
    AddressbookComponentPrivate *priv = ADDRESSBOOK_COMPONENT (object)->priv;

    if (priv->gconf_client != NULL) {
        g_object_unref (priv->gconf_client);
        priv->gconf_client = NULL;
    }

    (* G_OBJECT_CLASS (parent_class)->dispose) (object);
}

static void
impl_finalize (GObject *object)
{
    AddressbookComponentPrivate *priv = ADDRESSBOOK_COMPONENT (object)->priv;

    g_free (priv);

    (* G_OBJECT_CLASS (parent_class)->finalize) (object);
}


/* Initialization.  */

static void
addressbook_component_class_init (AddressbookComponentClass *class)
{
    POA_GNOME_Evolution_Component__epv *epv = &class->epv;
    GObjectClass *object_class = G_OBJECT_CLASS (class);

    epv->createControls          = impl_createControls;
    epv->_get_userCreatableItems = impl__get_userCreatableItems;
    epv->requestCreateItem       = impl_requestCreateItem;
    epv->upgradeFromVersion      = impl_upgradeFromVersion;
    epv->requestQuit             = impl_requestQuit;

    object_class->dispose  = impl_dispose;
    object_class->finalize = impl_finalize;

    parent_class = g_type_class_peek_parent (class);
}

static void
addressbook_component_init (AddressbookComponent *component)
{
    AddressbookComponentPrivate *priv;

    priv = g_new0 (AddressbookComponentPrivate, 1);

    /* EPFIXME: Should use a custom one instead? */
    priv->gconf_client = gconf_client_get_default ();

    priv->base_directory = g_build_filename (g_get_home_dir (), ".evolution", NULL);

    component->priv = priv;

#ifdef ENABLE_SMIME
    smime_component_init ();
#endif
}


/* Public API.  */

AddressbookComponent *
addressbook_component_peek (void)
{
    static AddressbookComponent *component = NULL;

    if (component == NULL)
        component = g_object_new (addressbook_component_get_type (), NULL);

    return component;
}

GConfClient*
addressbook_component_peek_gconf_client (AddressbookComponent *component)
{
    g_return_val_if_fail (ADDRESSBOOK_IS_COMPONENT (component), NULL);

    return component->priv->gconf_client;
}

const char *
addressbook_component_peek_base_directory (AddressbookComponent *component)
{
    g_return_val_if_fail (ADDRESSBOOK_IS_COMPONENT (component), NULL);

    return component->priv->base_directory;
}

BONOBO_TYPE_FUNC_FULL (AddressbookComponent, GNOME_Evolution_Component, PARENT_TYPE, addressbook_component)