aboutsummaryrefslogtreecommitdiffstats
path: root/mail/subscribe-control-factory.c
blob: 9d1cbb9caa699462b2b459750285b9171c13f9c8 (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
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * subscribe-control-factory.c: A Bonobo Control factory for Subscribe Controls
 *
 * Author:
 *   Chris Toshok (toshok@helixcode.com)
 *
 * (C) 2000 Helix Code, Inc.
 */

#include <config.h>

#include <gnome.h>
#include <bonobo/bonobo-main.h>
#include <bonobo/bonobo-object.h>
#include <bonobo/bonobo-generic-factory.h>
#include <bonobo/bonobo-control.h> 
#include <bonobo/bonobo-ui-component.h>

#include <gal/util/e-util.h>
#include <gal/widgets/e-gui-utils.h>

#include "subscribe-control-factory.h"

#include "subscribe-control.h"
#include "mail.h"
#include "shell/Evolution.h"
#include "mail-config.h"
#include "mail-ops.h"

/* The Subscribe BonoboControls we have.  */
static GList *control_list = NULL;

/*
 * Add with 'subscribe_control'
 */
static BonoboUIVerb verbs [] = {
    /* Edit Menu */
    BONOBO_UI_VERB ("EditSelectAll", subscribe_select_all),
    BONOBO_UI_VERB ("EditUnSelectAll", subscribe_unselect_all),
    
    /* Folder Menu */
    BONOBO_UI_VERB ("SubscribeFolder", subscribe_folder),
    BONOBO_UI_VERB ("UnsubscribeFolder", unsubscribe_folder),

    /* Toolbar Specific */
    BONOBO_UI_VERB ("RefreshList", subscribe_refresh_list),

    BONOBO_UI_VERB_END
};

static void
set_pixmap (Bonobo_UIContainer container,
        const char        *xml_path,
        const char        *icon)
{
    char *path;
    GdkPixbuf *pixbuf;

    path = g_concat_dir_and_file (EVOLUTION_DATADIR "/images/evolution/buttons", icon);

    pixbuf = gdk_pixbuf_new_from_file (path);
    g_return_if_fail (pixbuf != NULL);

    bonobo_ui_util_set_pixbuf (container, xml_path, pixbuf);

    gdk_pixbuf_unref (pixbuf);

    g_free (path);
}

static void
update_pixmaps (Bonobo_UIContainer container)
{
    set_pixmap (container, "/Toolbar/SubscribeFolder", "fetch-mail.png"); /* XXX */
    set_pixmap (container, "/Toolbar/UnsubscribeFolder", "compose-message.png"); /* XXX */
    set_pixmap (container, "/Toolbar/RefreshList", "forward.png"); /* XXX */
}

static void
control_activate (BonoboControl *control, BonoboUIHandler *uih,
          SubscribeControl *fb)
{
    GtkWidget         *subscribe_control;
    BonoboUIComponent *component;
    Bonobo_UIContainer container;

    container = bonobo_control_get_remote_ui_handler (control);
    bonobo_ui_handler_set_container (uih, container);
    bonobo_object_release_unref (container, NULL);

    g_assert (container == bonobo_ui_compat_get_container (uih));
    g_return_if_fail (container != CORBA_OBJECT_NIL);
        
    subscribe_control = bonobo_control_get_widget (control);

    component = bonobo_ui_compat_get_component (uih);
    bonobo_ui_component_add_verb_list_with_data (
        component, verbs, subscribe_control);

    bonobo_ui_container_freeze (container, NULL);

    bonobo_ui_util_set_ui (
        component, container,
        EVOLUTION_DATADIR, "evolution-subscribe.xml",
        "evolution-mail");

    update_pixmaps (container);

    bonobo_ui_container_thaw (container, NULL);
}

static void
control_deactivate (BonoboControl *control,
            BonoboUIHandler *uih,
            SubscribeControl *subscribe)
{
    g_warning ("In subscribe control_deactivate");
    bonobo_ui_component_rm (
        bonobo_ui_compat_get_component (uih),
        bonobo_ui_compat_get_container (uih), "/", NULL);

    bonobo_ui_handler_unset_container (uih);
}

static void
control_activate_cb (BonoboControl *control, 
             gboolean activate, 
             gpointer user_data)
{
    BonoboUIHandler  *uih;

    uih = bonobo_control_get_ui_handler (control);
    g_assert (uih);

    if (activate)
        control_activate (control, uih, user_data);
    else
        control_deactivate (control, uih, user_data);
}

static void
control_destroy_cb (BonoboControl *control,
            gpointer       user_data)
{
    GtkWidget *subscribe_control = user_data;

    control_list = g_list_remove (control_list, control);

    gtk_object_destroy (GTK_OBJECT (subscribe_control));
}

BonoboControl *
subscribe_control_factory_new_control (const char *uri,
                   const Evolution_Shell shell)
{
    BonoboControl *control;
    GtkWidget *subscribe_control;

    subscribe_control = subscribe_control_new (shell);
    if (subscribe_control == NULL)
        return NULL;

    if (!subscribe_control_set_uri (SUBSCRIBE_CONTROL (subscribe_control), uri)) {
        gtk_object_sink (GTK_OBJECT (subscribe_control));
        return NULL;
    }

    gtk_widget_show (subscribe_control);
    
    control = bonobo_control_new (subscribe_control);
    
    if (control == NULL) {
        gtk_object_destroy (GTK_OBJECT (subscribe_control));
        return NULL;
    }
    
    gtk_signal_connect (GTK_OBJECT (control), "activate",
                control_activate_cb, subscribe_control);

    gtk_signal_connect (GTK_OBJECT (control), "destroy",
                control_destroy_cb, subscribe_control);

    control_list = g_list_prepend (control_list, control);

    return control;
}

GList *
subscribe_control_factory_get_control_list (void)
{
    return control_list;
}