| 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 <gnome-xml/tree.h> |
|---|
| 27 | #include <bonobo/bonobo-control.h> |
|---|
| 28 | #include <libgnomevfs/gnome-vfs-utils.h> |
|---|
| 29 | |
|---|
| 30 | #include <libnautilus-extensions/nautilus-background.h> |
|---|
| 31 | #include <libnautilus-extensions/nautilus-bonobo-extensions.h> |
|---|
| 32 | #include <libnautilus-extensions/nautilus-caption-table.h> |
|---|
| 33 | #include <libnautilus-extensions/nautilus-file-utilities.h> |
|---|
| 34 | #include <libnautilus-extensions/nautilus-font-factory.h> |
|---|
| 35 | #include <libnautilus-extensions/nautilus-gdk-extensions.h> |
|---|
| 36 | #include <libnautilus-extensions/nautilus-glib-extensions.h> |
|---|
| 37 | #include <libnautilus-extensions/nautilus-global-preferences.h> |
|---|
| 38 | #include <libnautilus-extensions/nautilus-gnome-extensions.h> |
|---|
| 39 | #include <libnautilus-extensions/nautilus-gtk-extensions.h> |
|---|
| 40 | #include <libnautilus-extensions/nautilus-gtk-macros.h> |
|---|
| 41 | #include <libnautilus-extensions/nautilus-stock-dialogs.h> |
|---|
| 42 | #include <libnautilus-extensions/nautilus-string.h> |
|---|
| 43 | #include <libnautilus-extensions/nautilus-tabs.h> |
|---|
| 44 | |
|---|
| 45 | #include <libgnomeui/gnome-stock.h> |
|---|
| 46 | #include <stdio.h> |
|---|
| 47 | #include <unistd.h> |
|---|
| 48 | |
|---|
| 49 | #include <orb/orbit.h> |
|---|
| 50 | #include <liboaf/liboaf.h> |
|---|
| 51 | #include <libtrilobite/trilobite-redirect.h> |
|---|
| 52 | #include <libtrilobite/eazelproxy.h> |
|---|
| 53 | #include <libtrilobite/libammonite.h> |
|---|
| 54 | #include <bonobo/bonobo-main.h> |
|---|
| 55 | |
|---|
| 56 | #include "nautilus-summary-view.h" |
|---|
| 57 | #include "eazel-summary-shared.h" |
|---|
| 58 | |
|---|
| 59 | #include "eazel-services-footer.h" |
|---|
| 60 | #include "eazel-services-header.h" |
|---|
| 61 | #include "eazel-services-extensions.h" |
|---|
| 62 | |
|---|
| 63 | #include "nautilus-summary-callbacks.h" |
|---|
| 64 | #include "nautilus-summary-dialogs.h" |
|---|
| 65 | #include "nautilus-summary-menu-items.h" |
|---|
| 66 | #include "nautilus-summary-view-private.h" |
|---|
| 67 | |
|---|
| 68 | #define notDEBUG_PEPPER 1 |
|---|
| 69 | |
|---|
| 70 | static void bonobo_register_callback (BonoboUIComponent *ui, |
|---|
| 71 | gpointer user_data, |
|---|
| 72 | const char *verb); |
|---|
| 73 | static void bonobo_login_callback (BonoboUIComponent *ui, |
|---|
| 74 | gpointer user_data, |
|---|
| 75 | const char *verb); |
|---|
| 76 | static void bonobo_logout_callback (BonoboUIComponent *ui, |
|---|
| 77 | gpointer user_data, |
|---|
| 78 | const char *verb); |
|---|
| 79 | static void bonobo_preferences_callback (BonoboUIComponent *ui, |
|---|
| 80 | gpointer user_data, |
|---|
| 81 | const char *verb); |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | /* update the visibility of the menu items according to the login state */ |
|---|
| 85 | void |
|---|
| 86 | update_menu_items (NautilusSummaryView *view, gboolean logged_in) |
|---|
| 87 | { |
|---|
| 88 | BonoboUIComponent *ui; |
|---|
| 89 | |
|---|
| 90 | ui = bonobo_control_get_ui_component |
|---|
| 91 | (nautilus_view_get_bonobo_control |
|---|
| 92 | (view->details->nautilus_view)); |
|---|
| 93 | |
|---|
| 94 | nautilus_bonobo_set_hidden (ui, |
|---|
| 95 | "/commands/Register", |
|---|
| 96 | logged_in); |
|---|
| 97 | |
|---|
| 98 | nautilus_bonobo_set_hidden (ui, |
|---|
| 99 | "/commands/Login", |
|---|
| 100 | logged_in); |
|---|
| 101 | |
|---|
| 102 | nautilus_bonobo_set_hidden (ui, |
|---|
| 103 | "/commands/Preferences", |
|---|
| 104 | !logged_in); |
|---|
| 105 | |
|---|
| 106 | nautilus_bonobo_set_hidden (ui, |
|---|
| 107 | "/commands/Logout", |
|---|
| 108 | !logged_in); |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | /* this routine is invoked when the view is activated to merge in our menu items */ |
|---|
| 112 | void |
|---|
| 113 | merge_bonobo_menu_items (BonoboControl *control, gboolean state, gpointer user_data) |
|---|
| 114 | { |
|---|
| 115 | NautilusSummaryView *view; |
|---|
| 116 | BonoboUIVerb verbs [] = { |
|---|
| 117 | BONOBO_UI_VERB ("Register", bonobo_register_callback), |
|---|
| 118 | BONOBO_UI_VERB ("Login", bonobo_login_callback), |
|---|
| 119 | BONOBO_UI_VERB ("Logout", bonobo_logout_callback), |
|---|
| 120 | BONOBO_UI_VERB ("Preferences", bonobo_preferences_callback), |
|---|
| 121 | BONOBO_UI_VERB_END |
|---|
| 122 | }; |
|---|
| 123 | |
|---|
| 124 | g_assert (BONOBO_IS_CONTROL (control)); |
|---|
| 125 | |
|---|
| 126 | view = NAUTILUS_SUMMARY_VIEW (user_data); |
|---|
| 127 | |
|---|
| 128 | if (state) { |
|---|
| 129 | gboolean logged_in; |
|---|
| 130 | char * user_name; |
|---|
| 131 | |
|---|
| 132 | nautilus_view_set_up_ui (view->details->nautilus_view, |
|---|
| 133 | DATADIR, |
|---|
| 134 | "nautilus-summary-view-ui.xml", |
|---|
| 135 | "nautilus-summary-view"); |
|---|
| 136 | |
|---|
| 137 | bonobo_ui_component_add_verb_list_with_data |
|---|
| 138 | (bonobo_control_get_ui_component (control), verbs, view); |
|---|
| 139 | |
|---|
| 140 | user_name = ammonite_get_default_user_username (view->details->user_control); |
|---|
| 141 | logged_in = (NULL != user_name); |
|---|
| 142 | update_menu_items (view, logged_in); |
|---|
| 143 | g_free (user_name); |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | /* Note that we do nothing if state is FALSE. Nautilus content |
|---|
| 147 | * views are never explicitly deactivated |
|---|
| 148 | */ |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | /* here are the callbacks to handle bonobo menu items */ |
|---|
| 152 | static void |
|---|
| 153 | bonobo_register_callback (BonoboUIComponent *ui, gpointer user_data, const char *verb) |
|---|
| 154 | { |
|---|
| 155 | NautilusSummaryView *view; |
|---|
| 156 | |
|---|
| 157 | view = NAUTILUS_SUMMARY_VIEW (user_data); |
|---|
| 158 | register_button_cb (NULL, view); |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | static void |
|---|
| 162 | bonobo_login_callback (BonoboUIComponent *ui, gpointer user_data, const char *verb) |
|---|
| 163 | { |
|---|
| 164 | NautilusSummaryView *view; |
|---|
| 165 | |
|---|
| 166 | view = NAUTILUS_SUMMARY_VIEW (user_data); |
|---|
| 167 | generate_login_dialog (view); |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | static void |
|---|
| 171 | bonobo_logout_callback (BonoboUIComponent *ui, gpointer user_data, const char *verb) |
|---|
| 172 | { |
|---|
| 173 | NautilusSummaryView *view; |
|---|
| 174 | |
|---|
| 175 | view = NAUTILUS_SUMMARY_VIEW (user_data); |
|---|
| 176 | logout_button_cb (NULL, view); |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | static void |
|---|
| 180 | bonobo_preferences_callback (BonoboUIComponent *ui, gpointer user_data, const char *verb) |
|---|
| 181 | { |
|---|
| 182 | NautilusSummaryView *view; |
|---|
| 183 | |
|---|
| 184 | view = NAUTILUS_SUMMARY_VIEW (user_data); |
|---|
| 185 | preferences_button_cb (NULL, view); |
|---|
| 186 | } |
|---|
| 187 | |
|---|