aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/exchange-account-setup/exchange-account-setup.c
blob: 0a4f820910a896da32eb2b415bad07e63d227cc2 (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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
 *
 *  Sushma Rai <rsushma@novell.com>
 *  Copyright (C) 2004 Novell, Inc.
 *
 *  Permission is hereby granted, free of charge, to any person
 *  obtaining a copy of this software and associated documentation
 *  files (the "Software"), to deal in the Software without
 *  restriction, including without limitation the rights to use, copy,
 *  modify, merge, publish, distribute, sublicense, and/or sell copies
 *  of the Software, and to permit persons to whom the Software is
 *  furnished to do so, subject to the following conditions:
 *  
 *  The above copyright notice and this permission notice shall be
 *  included in all copies or substantial portions of the Software.
 *  
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 *  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 *  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 *  DEALINGS IN THE SOFTWARE.
 */

#include <string.h>
#include <libgnome/gnome-i18n.h>
#include <glade/glade.h>
#include <gtk/gtk.h>
#include <gtk/gtkdialog.h>
#include <gconf/gconf-client.h>
#include <libedataserver/e-source.h>
#include "mail/em-account-editor.h"
#include "mail/em-config.h"
#include "e-util/e-account.h"
#include "e-util/e-account-list.h"

int e_plugin_lib_enable (EPluginLib *ep, int enable);

void exchange_account_setup_commit (EPlugin *epl, EConfigHookItemFactoryData *data);
GtkWidget* org_gnome_exchange_account_setup (EPlugin *epl, EConfigHookItemFactoryData *data);
GtkWidget *org_gnome_exchange_set_url(EPlugin *epl, EConfigHookItemFactoryData *data);

#if 0
int
e_plugin_lib_enable (EPluginLib *ep, int enable)
{
    if (enable) {
    }
    return 0;
}
#endif

void 
exchange_account_setup_commit (EPlugin *epl, EConfigHookItemFactoryData *data)
{
    return;
}

static void
oof_get()
{
    /* Read the oof state and oof message */
}

static void
oof_set ()
{
    /* store the oof state and message */
}

static GtkWidget *
create_page ()
{
    GtkWidget *oof_page;
    GtkWidget *oof_table;
    GtkWidget *oof_description, *label_status, *label_empty;
    GtkWidget *radiobutton_inoff, *radiobutton_oof;
    GtkWidget *vbox_oof, *vbox_oof_message;
    GtkWidget *oof_frame;
    GtkWidget *scrolledwindow_oof;
    GtkWidget *textview_oof;

    oof_page = gtk_vbox_new (FALSE, 6);
    gtk_container_set_border_width (GTK_CONTAINER (oof_page), 12);

    /* Description section */

    oof_description = gtk_label_new (_("The message specified below will be automatically sent to \neach person who sends mail to you while you are out of the office."));
    gtk_label_set_justify (GTK_LABEL (oof_description), GTK_JUSTIFY_LEFT);
    gtk_label_set_line_wrap (GTK_LABEL (oof_description), TRUE);
    gtk_misc_set_alignment (GTK_MISC (oof_description), 0.5, 0.5);
    gtk_misc_set_padding (GTK_MISC (oof_description), 0, 18);
    
    gtk_box_pack_start (GTK_BOX (oof_page), oof_description, FALSE, TRUE, 0);

    /* Table with out of office radio buttons */

    oof_table = gtk_table_new (2, 2, FALSE);
    gtk_table_set_col_spacings (GTK_TABLE (oof_table), 6);
    gtk_table_set_row_spacings (GTK_TABLE (oof_table), 6);
    gtk_box_pack_start (GTK_BOX (oof_page), oof_table, FALSE, FALSE, 0);

    label_status = gtk_label_new (_("<b>Status:</b>"));
    gtk_label_set_justify (GTK_LABEL (label_status), GTK_JUSTIFY_CENTER);
    gtk_misc_set_alignment (GTK_MISC (label_status), 0, 0.5);
    gtk_misc_set_padding (GTK_MISC (label_status), 0, 0); 
    gtk_label_set_use_markup (GTK_LABEL (label_status), TRUE);
    gtk_table_attach (GTK_TABLE (oof_table), label_status, 0, 1, 0, 1, 
              GTK_FILL, GTK_FILL, 0, 0); 

    radiobutton_inoff = gtk_radio_button_new_with_label (NULL, 
                        _("I am in the office"));
    gtk_table_attach (GTK_TABLE (oof_table), radiobutton_inoff, 1, 2, 0, 1, 
              GTK_FILL, GTK_FILL, 0, 0);

    label_empty = gtk_label_new (_(""));
    gtk_label_set_justify (GTK_LABEL (label_empty), GTK_JUSTIFY_LEFT);
    gtk_misc_set_alignment (GTK_MISC (label_empty), 0, 0.5);
    gtk_misc_set_padding (GTK_MISC (label_empty), 0, 0);
    gtk_label_set_use_markup (GTK_LABEL (label_empty), FALSE);
    gtk_table_attach (GTK_TABLE (oof_table), label_empty, 0, 1, 1, 2, 
              GTK_FILL, GTK_FILL, 0, 0);

    radiobutton_oof = gtk_radio_button_new_with_label_from_widget (
                    GTK_RADIO_BUTTON (radiobutton_inoff), 
                    _("I am out of the office"));


    gtk_table_attach (GTK_TABLE (oof_table), radiobutton_oof, 1, 2, 1, 2, 
              GTK_FILL, GTK_FILL, 0, 0);

    /* frame containg oof message text box */

    vbox_oof = gtk_vbox_new (FALSE, 6);
    gtk_box_pack_start (GTK_BOX (oof_page), vbox_oof, FALSE, FALSE, 0);

    oof_frame = gtk_frame_new ("");
    gtk_container_set_border_width (GTK_CONTAINER (oof_frame), 1); 
    gtk_frame_set_shadow_type (GTK_FRAME (oof_frame), GTK_SHADOW_ETCHED_IN);
    gtk_frame_set_label (GTK_FRAME (oof_frame), _("Out of office Message:"));
    gtk_box_pack_start (GTK_BOX (vbox_oof), oof_frame, FALSE, FALSE, 0);

    vbox_oof_message = gtk_vbox_new (FALSE, 6);
    gtk_container_add (GTK_CONTAINER (oof_frame), vbox_oof_message);
    
    scrolledwindow_oof = gtk_scrolled_window_new(NULL, NULL);
    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow_oof), 
            GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
    gtk_scrolled_window_set_shadow_type (
            GTK_SCROLLED_WINDOW (scrolledwindow_oof), 
            GTK_SHADOW_IN); 
    gtk_box_pack_start (GTK_BOX (vbox_oof_message), 
                scrolledwindow_oof, TRUE, TRUE, 0);

    textview_oof = gtk_text_view_new(); 
    gtk_text_view_set_justification (GTK_TEXT_VIEW (textview_oof), 
                     GTK_JUSTIFY_LEFT);
    gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (textview_oof), 
                     GTK_WRAP_WORD);
    gtk_text_view_set_editable (GTK_TEXT_VIEW (textview_oof), TRUE);
    gtk_container_add (GTK_CONTAINER (scrolledwindow_oof), textview_oof);   
    gtk_widget_show_all (scrolledwindow_oof);

    gtk_widget_show_all (oof_page);

    return oof_page;
}

static GtkWidget *
construct_oof_editor (EConfigHookItemFactoryData *data)
{
    /* add oof page to editor */
    GtkWidget *oof_page;
    GladeXML *parent_xml;
    GtkNotebook *editor_notebook;
    GtkWidget *page_label;
    
    parent_xml = glade_xml_new (EVOLUTION_GLADEDIR "/mail-config.glade", 
                       "account_editor_notebook", 
                       NULL);

    editor_notebook = (GtkNotebook *) glade_xml_get_widget (parent_xml, 
                        "account_editor_notebook");
    if (!editor_notebook)
        return NULL;

    oof_page = create_page ();
    if (!oof_page)
        return NULL;
    
    page_label = gtk_label_new (_("Exchange Settings"));

    gtk_notebook_insert_page (GTK_NOTEBOOK (data->parent), 
                  oof_page, page_label, 4);
    return oof_page;
}

GtkWidget *
org_gnome_exchange_account_setup (EPlugin *epl, EConfigHookItemFactoryData *data)
{
    EMConfigTargetAccount *target_account;
    GtkWidget *oof_page = NULL;
    const char *account_url=NULL, *source_url=NULL, *temp_url=NULL;
    char *exchange_url = NULL;
    GConfClient *client;
    EAccountList *account_list;
    const char *uid;
    EAccount *gconf_account;

    target_account = (EMConfigTargetAccount *)data->config->target;

    client = gconf_client_get_default ();
    account_list = e_account_list_new (client);
    if (account_list) {
        uid = g_strdup (target_account->account->uid);  
        if (uid) {
            gconf_account = e_account_list_find (account_list, 
                                 E_ACCOUNT_FIND_UID,
                                 uid);
            if (gconf_account) {
                temp_url = e_account_get_string (gconf_account, 
                            E_ACCOUNT_SOURCE_URL);
                if (temp_url)
                    e_account_set_string (
                        target_account->account, 
                        E_ACCOUNT_SOURCE_URL, 
                        temp_url); 
                temp_url = NULL;

                temp_url = e_account_get_string (
                            gconf_account,
                             E_ACCOUNT_TRANSPORT_URL);
                if (temp_url)
                    e_account_set_string (
                            target_account->account,
                                E_ACCOUNT_TRANSPORT_URL, 
                                temp_url); 
            }
            g_free (uid);   
        }
        g_object_unref (account_list);
    }
    else {
        /* FIXME */
    }
    g_object_unref (client);

    source_url = e_account_get_string (target_account->account, 
                       E_ACCOUNT_SOURCE_URL);
    account_url = g_strdup (source_url);
    exchange_url = g_strrstr (account_url, "exchange");
    g_free (account_url);

    if (exchange_url) { 
        if (data->old)
            return data->old;

        oof_page = construct_oof_editor (data);
    }
    return oof_page;
}

static void
owa_editor_entry_changed (GtkWidget *entry, void *data) 
{
    GtkWidget *button = data;
    char *owa_entry_text = NULL; 

    /* FIXME: return owa_entry_text instead of making it global */
    owa_entry_text = gtk_entry_get_text (GTK_ENTRY (entry));
    if (owa_entry_text)
        gtk_widget_set_sensitive (button, TRUE);
}

static GtkWidget *
add_owa_entry_to_editor (GtkWidget *parent, EConfig *config, 
             EMConfigTargetAccount *target_account)
{
    GtkWidget *section, *owa_entry;
    GtkWidget *hbox, *label; 

    section =  gtk_vbox_new (FALSE, 0);
    gtk_widget_show (section);
    gtk_box_pack_start (GTK_BOX (parent), section, FALSE, FALSE, 0);

    hbox = gtk_hbox_new (FALSE, 6);
    gtk_widget_show(hbox);
    gtk_box_pack_start (GTK_BOX (section), hbox, FALSE, FALSE, 0);
    label = gtk_label_new_with_mnemonic(_("_Url:"));
    gtk_widget_show (label);

    owa_entry = gtk_entry_new ();
    gtk_widget_show (owa_entry);

    gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
    gtk_box_pack_start (GTK_BOX (hbox), owa_entry, TRUE, TRUE, 0);

    g_signal_connect (owa_entry, "changed", 
              G_CALLBACK(owa_editor_entry_changed), NULL); 
    /* FIXME - gconf handling*/
    return section; /* FIXME: return entry */

#if 0
    GtkWidget *table;
    GladeXML *gui;
    GValue rows = { 0, };
    GValue cols = { 0, };
    gint n_rows, n_cols;
    gui = glade_xml_new (EVOLUTION_GLADEDIR "/mail-config.glade",
                 "table4", NULL);
    table = glade_xml_get_widget (gui, "table4");


    g_value_init (&rows, G_TYPE_INT);
    g_value_init (&cols, G_TYPE_INT);
    g_object_get_property (G_OBJECT (table), "n-rows", &rows);
    g_object_get_property (G_OBJECT (table), "n-columns", &cols);
    n_rows = g_value_get_int (&rows); 
    n_cols = g_value_get_int (&cols); 
    printf ("NO OF COLUMES = %d ROWS = %d \n", n_cols, n_rows);

    if (owa_entry_text)
        gtk_entry_set_text (owa_entry, owa_entry_text); 

    gtk_table_attach (GTK_TABLE (table), label, 0, n_cols-1, n_rows, n_rows+1, GTK_FILL, GTK_FILL, 0, 0); 
    gtk_table_attach (GTK_TABLE (table), owa_entry, n_cols-1, n_cols, n_rows, n_rows+1, GTK_FILL, GTK_FILL, 0, 0); 

    gtk_widget_show (table); 
    return table;

#endif
    /* FIXME: Proper placing of the widget */
}

GtkWidget *
org_gnome_exchange_set_url (EPlugin *epl, EConfigHookItemFactoryData *data)
{
    EMConfigTargetAccount *target_account;
    EConfig *config;
    char *account_url=NULL, *exchange_url = NULL;
    const char *source_url, *temp_url;
    GtkWidget *owa_entry = NULL, *parent;
    GConfClient *client;
    EAccountList *account_list;
    const char *uid;
    EAccount *gconf_account;

    config = data->config;
    target_account = (EMConfigTargetAccount *)data->config->target;

    client = gconf_client_get_default ();
    account_list = e_account_list_new (client);
    if (account_list) {
        uid = g_strdup (target_account->account->uid);  
        if (uid) {
            gconf_account = e_account_list_find (account_list, 
                                 E_ACCOUNT_FIND_UID,
                                 uid);
            if (gconf_account) {
                temp_url = e_account_get_string (
                            gconf_account, 
                             E_ACCOUNT_SOURCE_URL);
                e_account_set_string (target_account->account, 
                              E_ACCOUNT_SOURCE_URL, 
                              temp_url); 
                temp_url = NULL;

                temp_url = e_account_get_string (gconf_account,
                             E_ACCOUNT_TRANSPORT_URL);
                e_account_set_string (target_account->account, 
                              E_ACCOUNT_TRANSPORT_URL, 
                              temp_url); 
            }
            g_free (uid);   
        }
        g_object_unref (account_list);
    }
    g_object_unref (client);

    source_url = e_account_get_string (target_account->account, E_ACCOUNT_SOURCE_URL); 
    account_url = g_strdup (source_url);
    exchange_url = g_strrstr (account_url, "exchange");
    g_free (account_url);

    if (exchange_url) {
        if (data->old)
            return data->old;

        /*
        parent = gtk_widget_get_toplevel (GTK_WIDGET (data->parent));
        if (!GTK_WIDGET_TOPLEVEL (parent))
            parent = NULL;
        */

        parent = data->parent;
        owa_entry = add_owa_entry_to_editor(parent, config, target_account);
        gtk_box_pack_start (GTK_BOX (parent), owa_entry, FALSE, FALSE, 0);
        gtk_widget_show (parent);
    }
    return owa_entry;
}