| 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 <libnautilus-extensions/nautilus-caption-table.h> |
|---|
| 27 | #include <libnautilus-extensions/nautilus-stock-dialogs.h> |
|---|
| 28 | #include <libnautilus-extensions/nautilus-background.h> |
|---|
| 29 | #include <libnautilus-extensions/nautilus-string.h> |
|---|
| 30 | #include <libnautilus-extensions/nautilus-gnome-extensions.h> |
|---|
| 31 | #include <libnautilus-extensions/nautilus-file-utilities.h> |
|---|
| 32 | #include <libnautilus-extensions/nautilus-image.h> |
|---|
| 33 | |
|---|
| 34 | #include <libgnomeui/gnome-stock.h> |
|---|
| 35 | #include <stdio.h> |
|---|
| 36 | #include <unistd.h> |
|---|
| 37 | |
|---|
| 38 | #include <orb/orbit.h> |
|---|
| 39 | #include <liboaf/liboaf.h> |
|---|
| 40 | #include <libtrilobite/trilobite-redirect.h> |
|---|
| 41 | #include <libtrilobite/eazelproxy.h> |
|---|
| 42 | #include <libtrilobite/libammonite.h> |
|---|
| 43 | |
|---|
| 44 | #include "nautilus-summary-view.h" |
|---|
| 45 | #include "eazel-services-extensions.h" |
|---|
| 46 | #include "eazel-summary-shared.h" |
|---|
| 47 | #include "eazel-services-extensions.h" |
|---|
| 48 | #include "nautilus-summary-callbacks.h" |
|---|
| 49 | #include "nautilus-summary-dialogs.h" |
|---|
| 50 | #include "nautilus-summary-view-private.h" |
|---|
| 51 | |
|---|
| 52 | #define notDEBUG_PEPPER 1 |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | static void error_dialog_cancel_cb (GtkWidget *button, |
|---|
| 56 | NautilusSummaryView *view); |
|---|
| 57 | static GtkWindow *get_window_from_summary_view (NautilusSummaryView *view); |
|---|
| 58 | static void set_dialog_parent (NautilusSummaryView *view, |
|---|
| 59 | GnomeDialog *dialog); |
|---|
| 60 | static void name_or_password_field_activated (GtkWidget *caption_table, |
|---|
| 61 | int active_entry, |
|---|
| 62 | gpointer user_data); |
|---|
| 63 | |
|---|
| 64 | void |
|---|
| 65 | nautilus_summary_login_failure_dialog (NautilusSummaryView *view, const char *message) |
|---|
| 66 | { |
|---|
| 67 | nautilus_error_dialog (message, |
|---|
| 68 | _("Eazel Service Login Error"), |
|---|
| 69 | get_window_from_summary_view (view)); |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | void |
|---|
| 73 | generate_error_dialog (NautilusSummaryView *view, const char *message) |
|---|
| 74 | { |
|---|
| 75 | GnomeDialog *dialog; |
|---|
| 76 | |
|---|
| 77 | dialog = nautilus_error_dialog (message, |
|---|
| 78 | _("Service Error"), |
|---|
| 79 | get_window_from_summary_view (view)); |
|---|
| 80 | gtk_signal_connect (GTK_OBJECT (dialog), |
|---|
| 81 | "destroy", |
|---|
| 82 | error_dialog_cancel_cb, |
|---|
| 83 | view); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | void |
|---|
| 87 | generate_login_dialog (NautilusSummaryView *view) |
|---|
| 88 | { |
|---|
| 89 | GnomeDialog *dialog; |
|---|
| 90 | GtkWidget *hbox; |
|---|
| 91 | GtkWidget *image; |
|---|
| 92 | GtkWidget *message; |
|---|
| 93 | GtkWidget *caption_hbox; |
|---|
| 94 | char *message_text; |
|---|
| 95 | char *image_name; |
|---|
| 96 | char *button_text; |
|---|
| 97 | |
|---|
| 98 | dialog = NULL; |
|---|
| 99 | image = NULL; |
|---|
| 100 | |
|---|
| 101 | if (view->details->attempt_number == 0) { |
|---|
| 102 | button_text = g_strdup (_("Register Now")); |
|---|
| 103 | } else { |
|---|
| 104 | button_text = g_strdup (_("Help")); |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | /* if the dialog is still open, then close it and open a new one */ |
|---|
| 108 | if (view->details->login_dialog != NULL) { |
|---|
| 109 | gnome_dialog_close (GNOME_DIALOG (view->details->login_dialog)); |
|---|
| 110 | view->details->login_dialog = NULL; |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | dialog = GNOME_DIALOG (gnome_dialog_new (_("Services Login"), button_text, |
|---|
| 114 | GNOME_STOCK_BUTTON_OK, GNOME_STOCK_BUTTON_CANCEL, NULL)); |
|---|
| 115 | |
|---|
| 116 | /* TODO: replace all reference to dialog in this code with view->details->login_dialog */ |
|---|
| 117 | view->details->login_dialog = dialog; |
|---|
| 118 | |
|---|
| 119 | gtk_signal_connect (GTK_OBJECT (dialog), "destroy", GTK_SIGNAL_FUNC (gtk_widget_destroyed), |
|---|
| 120 | &view->details->login_dialog); |
|---|
| 121 | gtk_container_set_border_width (GTK_CONTAINER (dialog), GNOME_PAD); |
|---|
| 122 | gtk_window_set_policy (GTK_WINDOW (dialog), FALSE, FALSE, FALSE); |
|---|
| 123 | |
|---|
| 124 | view->details->caption_table = nautilus_caption_table_new (LOGIN_DIALOG_ROW_COUNT); |
|---|
| 125 | gtk_widget_show (view->details->caption_table); |
|---|
| 126 | |
|---|
| 127 | nautilus_caption_table_set_row_info (NAUTILUS_CAPTION_TABLE (view->details->caption_table), |
|---|
| 128 | LOGIN_DIALOG_NAME_ROW, |
|---|
| 129 | _("Username:"), |
|---|
| 130 | "", |
|---|
| 131 | TRUE, |
|---|
| 132 | FALSE); |
|---|
| 133 | |
|---|
| 134 | nautilus_caption_table_set_row_info (NAUTILUS_CAPTION_TABLE (view->details->caption_table), |
|---|
| 135 | LOGIN_DIALOG_PASSWORD_ROW, |
|---|
| 136 | _("Password:"), |
|---|
| 137 | "", |
|---|
| 138 | FALSE, |
|---|
| 139 | FALSE); |
|---|
| 140 | |
|---|
| 141 | switch (view->details->current_attempt) { |
|---|
| 142 | case initial: |
|---|
| 143 | image_name = "big_services_icon.png"; |
|---|
| 144 | message_text = _("Please log in to Eazel services"); |
|---|
| 145 | break; |
|---|
| 146 | case retry: |
|---|
| 147 | image_name = "serv_dialog_alert.png"; |
|---|
| 148 | message_text = _("Your user name or password were not correct. Please try again."); |
|---|
| 149 | break; |
|---|
| 150 | default: |
|---|
| 151 | g_assert_not_reached(); |
|---|
| 152 | image_name = "big_services_icon.png"; |
|---|
| 153 | message_text = _("Please log in to Eazel services"); |
|---|
| 154 | break; |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | image = eazel_services_image_new (image_name, NULL, 0); |
|---|
| 158 | nautilus_image_set_background_mode (NAUTILUS_IMAGE (image), NAUTILUS_SMOOTH_BACKGROUND_GTK); |
|---|
| 159 | |
|---|
| 160 | hbox = gtk_hbox_new (FALSE, 5); |
|---|
| 161 | gtk_widget_show (hbox); |
|---|
| 162 | |
|---|
| 163 | if (image) { |
|---|
| 164 | gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0); |
|---|
| 165 | gtk_widget_show (image); |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | gtk_box_set_spacing (GTK_BOX (dialog->vbox), 4); |
|---|
| 169 | |
|---|
| 170 | message = gtk_label_new (message_text); |
|---|
| 171 | gtk_label_set_justify (GTK_LABEL (message), GTK_JUSTIFY_LEFT); |
|---|
| 172 | gtk_label_set_line_wrap (GTK_LABEL (message), TRUE); |
|---|
| 173 | nautilus_gtk_label_make_bold (GTK_LABEL (message)); |
|---|
| 174 | gtk_widget_show (message); |
|---|
| 175 | |
|---|
| 176 | /* right justify the caption table box */ |
|---|
| 177 | caption_hbox = gtk_hbox_new (FALSE, 0); |
|---|
| 178 | gtk_widget_show (caption_hbox); |
|---|
| 179 | gtk_widget_set_usize (view->details->caption_table, 260, -1); |
|---|
| 180 | gtk_box_pack_end (GTK_BOX (caption_hbox), view->details->caption_table, FALSE, FALSE, 0); |
|---|
| 181 | |
|---|
| 182 | gtk_box_pack_start (GTK_BOX (hbox), message, FALSE, FALSE, 0); |
|---|
| 183 | gtk_box_pack_start (GTK_BOX (dialog->vbox), hbox, TRUE, TRUE, 0); |
|---|
| 184 | gtk_box_pack_start (GTK_BOX (dialog->vbox), caption_hbox, FALSE, FALSE, 0); |
|---|
| 185 | |
|---|
| 186 | gtk_container_set_border_width (GTK_CONTAINER (view->details->caption_table), 4); |
|---|
| 187 | |
|---|
| 188 | gtk_widget_show (dialog->vbox); |
|---|
| 189 | |
|---|
| 190 | gnome_dialog_set_close (dialog, TRUE); |
|---|
| 191 | set_dialog_parent (view, dialog); |
|---|
| 192 | |
|---|
| 193 | gnome_dialog_set_default (dialog, LOGIN_DIALOG_OK_BUTTON_INDEX); |
|---|
| 194 | gtk_signal_connect (GTK_OBJECT (view->details->caption_table), "activate", |
|---|
| 195 | name_or_password_field_activated, |
|---|
| 196 | nautilus_gnome_dialog_get_button_by_index (dialog, LOGIN_DIALOG_OK_BUTTON_INDEX)); |
|---|
| 197 | nautilus_caption_table_entry_grab_focus (NAUTILUS_CAPTION_TABLE (view->details->caption_table), LOGIN_DIALOG_NAME_ROW); |
|---|
| 198 | |
|---|
| 199 | if (view->details->attempt_number == 0) { |
|---|
| 200 | gnome_dialog_button_connect (dialog, LOGIN_DIALOG_REGISTER_BUTTON_INDEX, GTK_SIGNAL_FUNC (register_button_cb), view); |
|---|
| 201 | } else { |
|---|
| 202 | gnome_dialog_button_connect (dialog, LOGIN_DIALOG_REGISTER_BUTTON_INDEX, GTK_SIGNAL_FUNC (forgot_password_button_cb), view); |
|---|
| 203 | } |
|---|
| 204 | |
|---|
| 205 | gnome_dialog_button_connect (dialog, LOGIN_DIALOG_OK_BUTTON_INDEX, GTK_SIGNAL_FUNC (login_button_cb), view); |
|---|
| 206 | |
|---|
| 207 | gnome_dialog_set_close (dialog, TRUE); |
|---|
| 208 | gtk_widget_show (GTK_WIDGET (dialog)); |
|---|
| 209 | } |
|---|
| 210 | |
|---|
| 211 | void |
|---|
| 212 | widget_set_nautilus_background_color (GtkWidget *widget, const char *color) |
|---|
| 213 | { |
|---|
| 214 | NautilusBackground *background; |
|---|
| 215 | |
|---|
| 216 | g_return_if_fail (GTK_IS_WIDGET (widget)); |
|---|
| 217 | g_return_if_fail (color != NULL); |
|---|
| 218 | |
|---|
| 219 | background = nautilus_get_widget_background (widget); |
|---|
| 220 | |
|---|
| 221 | nautilus_background_reset (background); |
|---|
| 222 | nautilus_background_set_color (background, color); |
|---|
| 223 | |
|---|
| 224 | } |
|---|
| 225 | |
|---|
| 226 | /* callback to handle cancel error_dialog button. */ |
|---|
| 227 | static void |
|---|
| 228 | error_dialog_cancel_cb (GtkWidget *button, NautilusSummaryView *view) |
|---|
| 229 | { |
|---|
| 230 | char *user_home; |
|---|
| 231 | user_home = nautilus_get_user_main_directory (); |
|---|
| 232 | nautilus_view_open_location_in_this_window (view->details->nautilus_view, user_home); |
|---|
| 233 | g_free (user_home); |
|---|
| 234 | } |
|---|
| 235 | |
|---|
| 236 | static GtkWindow * |
|---|
| 237 | get_window_from_summary_view (NautilusSummaryView *view) |
|---|
| 238 | { |
|---|
| 239 | GtkWidget *parent_window; |
|---|
| 240 | |
|---|
| 241 | g_assert (NAUTILUS_IS_SUMMARY_VIEW (view)); |
|---|
| 242 | |
|---|
| 243 | parent_window = gtk_widget_get_ancestor (GTK_WIDGET (view), GTK_TYPE_WINDOW); |
|---|
| 244 | if (parent_window == NULL) { |
|---|
| 245 | return NULL; |
|---|
| 246 | } |
|---|
| 247 | |
|---|
| 248 | return GTK_WINDOW (parent_window); |
|---|
| 249 | } |
|---|
| 250 | |
|---|
| 251 | static void |
|---|
| 252 | set_dialog_parent (NautilusSummaryView *view, GnomeDialog *dialog) |
|---|
| 253 | { |
|---|
| 254 | GtkWindow *parent_window; |
|---|
| 255 | |
|---|
| 256 | g_assert (NAUTILUS_IS_SUMMARY_VIEW (view)); |
|---|
| 257 | g_assert (GNOME_IS_DIALOG (dialog)); |
|---|
| 258 | |
|---|
| 259 | parent_window = get_window_from_summary_view (view); |
|---|
| 260 | if (parent_window != NULL) { |
|---|
| 261 | gnome_dialog_set_parent (dialog, parent_window); |
|---|
| 262 | } |
|---|
| 263 | } |
|---|
| 264 | |
|---|
| 265 | static void |
|---|
| 266 | name_or_password_field_activated (GtkWidget *caption_table, int active_entry, gpointer user_data) |
|---|
| 267 | { |
|---|
| 268 | g_assert (NAUTILUS_IS_CAPTION_TABLE (caption_table)); |
|---|
| 269 | g_assert (GTK_IS_BUTTON (user_data)); |
|---|
| 270 | |
|---|
| 271 | /* auto-click "OK" button when password activated (via Enter key) */ |
|---|
| 272 | if (active_entry == LOGIN_DIALOG_OK_BUTTON_INDEX) { |
|---|
| 273 | nautilus_gtk_button_auto_click (GTK_BUTTON (user_data)); |
|---|
| 274 | } |
|---|
| 275 | } |
|---|
| 276 | |
|---|