root/trunk/third/nautilus/components/services/summary/nautilus-view/nautilus-summary-callbacks.c @ 15547

Revision 15547, 9.8 KB (checked in by ghudson, 9 years ago)

This commit was generated by cvs2svn to compensate for changes in r15546,
which included commits to RCS files with non-trunk default branches.

Line 
1/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2
3/*
4 * Copyright (C) 2000 Eazel, Inc
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 *
21 * Author: J Shane Culpepper <pepper@eazel.com>
22 */
23
24#include <config.h>
25
26#include <libgnomeui/gnome-stock.h>
27#include <stdio.h>
28#include <unistd.h>
29
30#include <orb/orbit.h>
31#include <liboaf/liboaf.h>
32#include <libtrilobite/eazelproxy.h>
33#include <libtrilobite/libammonite.h>
34#include <libtrilobite/trilobite-redirect.h>
35#include <bonobo/bonobo-main.h>
36
37#include <libnautilus-extensions/nautilus-caption-table.h>
38
39#include "nautilus-summary-view.h"
40#include "eazel-summary-shared.h"
41#include "nautilus-summary-dialogs.h"
42#include "nautilus-summary-menu-items.h"
43#include "nautilus-summary-callbacks.h"
44#include "nautilus-summary-view-private.h"
45
46#define notDEBUG_PEPPER 1
47
48static void     authn_cb_succeeded                      (const EazelProxy_User          *user,
49                                                         gpointer                       state,
50                                                         CORBA_Environment              *ev);
51static void     authn_cb_failed                         (const EazelProxy_User          *user,
52                                                         const EazelProxy_AuthnFailInfo *info,
53                                                         gpointer                       state,
54                                                         CORBA_Environment              *ev);
55
56
57/* Be careful not to invoke another HTTP request; this call is
58 * invoked from a two-way CORBA call from ammonite
59 */
60static void
61authn_cb_succeeded (const EazelProxy_User *user, gpointer state, CORBA_Environment *ev)
62{
63        NautilusSummaryView    *view;
64        gint                    timeout;
65
66        view = NAUTILUS_SUMMARY_VIEW (state);
67
68        g_assert (Pending_Login == view->details->pending_operation);
69
70        view->details->pending_operation = Pending_None;
71       
72        timeout = gtk_timeout_add (0, logged_in_callback, view);
73
74        bonobo_object_unref (BONOBO_OBJECT (view->details->nautilus_view));
75}
76
77/* Be careful not to invoke another HTTP request; this call is
78 * invoked from a two-way CORBA call from ammonite
79 */
80static void
81authn_cb_failed (const EazelProxy_User *user, const EazelProxy_AuthnFailInfo *info, gpointer state, CORBA_Environment *ev)
82{
83        NautilusSummaryView    *view;
84
85        view = NAUTILUS_SUMMARY_VIEW (state);
86
87        g_assert (Pending_Login == view->details->pending_operation);
88
89        view->details->pending_operation = Pending_None;
90
91        view->details->logged_in = FALSE;
92       
93        update_menu_items (view, FALSE);
94
95        if (info && ( info->code == EAZELPROXY_AUTHN_FAIL_NETWORK
96            || info->code == EAZELPROXY_AUTHN_FAIL_SERVER)) {
97                nautilus_summary_login_failure_dialog (view, _("I'm sorry, network problems are preventing you from connecting to Eazel Services."));
98                view->details->attempt_number = 0;
99                view->details->current_attempt = initial;
100        } else if (info && ( info->code == EAZELPROXY_AUTHN_FAIL_USER_NOT_ACTIVATED)) {
101                /* FIXME we really should use the services alert icon here, eh? */
102                nautilus_summary_login_failure_dialog (view, _("Your Eazel Services account has not yet been activated.  "
103                            "You can't log into Eazel Services until you activate your account.\n\n"
104                            "Please check your email for activation instructions."));
105                view->details->attempt_number = 0;
106                view->details->current_attempt = initial;
107        } else if (info && ( info->code == EAZELPROXY_AUTHN_FAIL_USER_DISABLED)) {
108                /* FIXME we really should use the services alert icon here, eh? */
109                nautilus_summary_login_failure_dialog (view, _("Your Eazel Service User Account has been temporarily disabled.\n\n"
110                            "Please try again in a few minutes, or contact Eazel support if this problem continues."));
111                view->details->attempt_number = 0;
112                view->details->current_attempt = initial;
113        } else {
114                /* Most likely error: bad username or password */
115
116                view->details->attempt_number++;
117
118                /* FIXME it would be best to display an error dialog
119                 * explaining the problem and offering at least an "I forgot
120                 * my password" button (and possibly a "Register" button as well)
121                 * In any vase, the dialog that's here is insufficient
122                 */
123
124#if 0
125                if (view->details->attempt_number > 0 && view->details->attempt_number < 5) {
126#endif
127                        view->details->current_attempt = retry;
128                        generate_login_dialog (view);
129#if 0
130                } else {
131                        nautilus_summary_login_failure_dialog (view, _("We're sorry, but your name and password are still not recognized."));
132                        view->details->attempt_number = 0;
133                        view->details->current_attempt = initial;
134                }
135#endif
136        }
137       
138        bonobo_object_unref (BONOBO_OBJECT (view->details->nautilus_view));
139}
140
141/* callback to handle the login button.  Right now only does a simple redirect. */
142void
143login_button_cb (GtkWidget      *button, NautilusSummaryView    *view)
144{
145        char            *user_name;
146        char            *password;
147        EazelProxy_AuthnInfo *authinfo;
148        CORBA_Environment ev;
149
150        AmmoniteAuthCallbackWrapperFuncs cb_funcs = {
151                authn_cb_succeeded, authn_cb_failed
152        };
153
154        CORBA_exception_init (&ev);
155
156        g_assert (Pending_None == view->details->pending_operation);
157
158        /* FIXME this doesn't actually handle the case when user_control is NIL
159         * very well.  No callback is generated, so no user feedback is generated
160         * and the summary view is left in an illegal state
161         */
162
163        if (CORBA_OBJECT_NIL != view->details->user_control) {
164                view->details->authn_callback = ammonite_auth_callback_wrapper_new (bonobo_poa(), &cb_funcs, view);
165
166                user_name = nautilus_caption_table_get_entry_text (NAUTILUS_CAPTION_TABLE (view->details->caption_table), 0);
167                password = nautilus_caption_table_get_entry_text (NAUTILUS_CAPTION_TABLE (view->details->caption_table), 1);
168
169                authinfo = EazelProxy_AuthnInfo__alloc ();
170                authinfo->username = CORBA_string_dup (user_name);
171                authinfo->password = CORBA_string_dup (password);
172                user_name = NULL;
173                password = NULL;
174                               
175                authinfo->services_redirect_uri = CORBA_string_dup ("");
176                authinfo->services_login_path = CORBA_string_dup ("");
177
178                /* Ref myself until the callback returns */
179                bonobo_object_ref (BONOBO_OBJECT (view->details->nautilus_view));
180
181                view->details->pending_operation = Pending_Login;
182               
183                EazelProxy_UserControl_authenticate_user (
184                        view->details->user_control,
185                        authinfo, TRUE, 
186                        view->details->authn_callback, &ev
187                );
188
189                if (CORBA_NO_EXCEPTION != ev._major) {
190                        g_warning ("Exception during EazelProxy login");
191                        /* FIXME bugzilla.eazel.com 2745: cleanup after fail here */
192                }
193
194
195        }
196       
197        CORBA_exception_free (&ev);
198}
199
200/* callback to handle the logout button.  Right now only does a simple redirect. */
201void
202logout_button_cb (GtkWidget      *button, NautilusSummaryView    *view)
203{
204        CORBA_Environment       ev;
205        EazelProxy_UserList     *users;
206        CORBA_unsigned_long     i;
207        gint                    timeout;
208        CORBA_exception_init (&ev);
209
210        if (CORBA_OBJECT_NIL != view->details->user_control) {
211        /* Get list of currently active users */
212
213                users = EazelProxy_UserControl_get_active_users (
214                        view->details->user_control, &ev
215                );
216
217                if (CORBA_NO_EXCEPTION != ev._major) {
218                        g_message ("Exception while logging out user");
219                        return;
220                }
221
222        /* Log out the current default user */
223                for (i = 0; i < users->_length ; i++) {
224                        EazelProxy_User *cur;
225
226                        cur = users->_buffer + i;
227
228                        if (cur->is_default) {
229                                g_message ("Logging out user '%s'", cur->user_name);
230                                EazelProxy_UserControl_logout_user (
231                                        view->details->user_control,
232                                        cur->proxy_port, &ev
233                                );
234                                break;
235                        }
236                }
237
238                CORBA_free (users);
239        }
240
241        timeout = gtk_timeout_add (0, logged_out_callback, view);
242
243        CORBA_exception_free (&ev);
244}
245
246gint
247logged_in_callback (gpointer    raw)
248{
249        NautilusSummaryView     *view;
250
251        view = NAUTILUS_SUMMARY_VIEW (raw);
252        view->details->logged_in = TRUE;
253
254        update_menu_items (view, TRUE);
255        nautilus_view_open_location_in_this_window
256                (view->details->nautilus_view, "eazel:");
257
258        return (FALSE);
259}
260
261
262gint
263logged_out_callback (gpointer   raw)
264{
265        NautilusSummaryView     *view;
266
267        view = NAUTILUS_SUMMARY_VIEW (raw);
268        view->details->logged_in = FALSE;
269       
270        update_menu_items (view, FALSE);
271        nautilus_view_open_location_in_this_window
272                (view->details->nautilus_view, "eazel:");
273
274        return (FALSE);
275}
276
277/* callback to handle the maintenance button.  Right now only does a simple redirect. */
278void
279preferences_button_cb (GtkWidget      *button, NautilusSummaryView    *view)
280{
281        char    *url;
282        url = NULL;
283
284        url = trilobite_redirect_lookup (PREFERENCES_KEY);
285        if (!url) {
286                g_error ("Failed to load Registration url!");
287        }
288
289        nautilus_view_open_location_in_this_window
290                (view->details->nautilus_view, url);
291        g_free (url);
292
293}
294
295/* callback to handle the forgotten password button. */
296void
297forgot_password_button_cb (GtkWidget      *button, NautilusSummaryView    *view)
298{
299
300        nautilus_view_open_location_in_this_window
301                (view->details->nautilus_view, SUMMARY_CHANGE_PWD_FORM);
302
303}
304
305/* callback to handle the register button.  Right now only does a simple redirect. */
306void
307register_button_cb (GtkWidget      *button, NautilusSummaryView    *view)
308{
309        char    *url;
310        url = NULL;
311
312        url = trilobite_redirect_lookup (REGISTER_KEY);
313        if (!url) {
314                g_error ("Failed to load Registration url!");
315        }
316
317        nautilus_view_open_location_in_this_window
318                (view->details->nautilus_view, url);
319        g_free (url);
320
321}
322
323/* here is the callback to handle service tab selection */
324void
325service_tab_selected_callback (GtkWidget                *widget,
326                                int                     which_tab,
327                                NautilusSummaryView     *view)
328{
329
330        gtk_notebook_set_page (GTK_NOTEBOOK (view->details->services_notebook), which_tab);
331
332}
333
334/* here is the callback to handle updates tab selection */
335void
336updates_tab_selected_callback (GtkWidget                *widget,
337                                int                     which_tab,
338                                NautilusSummaryView     *view)
339{
340
341        gtk_notebook_set_page (GTK_NOTEBOOK (view->details->updates_notebook), which_tab);
342
343}
344
Note: See TracBrowser for help on using the browser.