root/trunk/third/nautilus/components/rpmview/nautilus-rpm-view-install.c @ 15547

Revision 15547, 16.0 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 * Copyright (C) 2000 Eazel, Inc
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
19 *
20 * Authors: Eskil Heyn Olsen <eskil@eazel.com>
21 */
22
23#include "nautilus-rpm-view-install.h"
24#include "libtrilobite/libtrilobite.h"
25#include "libeazelinstall.h"
26#include <libnautilus-extensions/nautilus-stock-dialogs.h>
27#include <libnautilus-extensions/nautilus-password-dialog.h>
28#include "libtrilobite/libtrilobite.h"
29#include "nautilus-rpm-view-private.h"
30
31#define OAF_ID "OAFIID:trilobite_eazel_install_service:8ff6e815-1992-437c-9771-d932db3b4a17"
32
33static void 
34nautilus_rpm_view_download_progress_signal (EazelInstallCallback *service, 
35                                            const PackageData *pack,
36                                            int amount, 
37                                            int total,
38                                            NautilusRPMView *rpm_view) 
39{
40#if 0
41        fprintf (stdout, "DEBUG: Download progress - %s %% %f\r",  name,
42                 (total ? ((float)
43                           ((((float) amount) / total) * 100))
44                  : 100.0));
45        fflush (stdout);
46        if (amount == total && total!=0) {
47                fprintf (stdout, "\n");
48        }
49        nautilus_view_report_load_underway (nautilus_rpm_view_get_view (rpm_view));
50#endif
51}
52
53static void 
54nautilus_rpm_view_install_progress_signal (EazelInstallCallback *service, 
55                                           const PackageData *pack,
56                                           int package_num, int num_packages, 
57                                           int amount, int total,
58                                           int total_size_completed, int total_size, 
59                                           NautilusRPMView *rpm_view) 
60{
61#if 0
62        double progress;
63
64        fprintf (stdout, "DEBUG: Install progress - %s (%d/%d), (%d/%d)b - (%d/%d) %% %f\r",
65                 pack->name,
66                 package_num, num_packages,
67                 total_size_completed, total_size,
68                 amount, total,
69                 (total ? ((float)
70                           ((((float) amount) / total) * 100))
71                  : 100.0));
72        fflush (stdout);
73
74        if (amount == total && total!=0) {
75                fprintf (stdout, "\n");
76        }
77
78        nautilus_view_report_load_underway (nautilus_rpm_view_get_view (rpm_view));
79
80        progress = total==amount ? 1.0 : (double)(((double)amount)/total);
81        /* nautilus_view_report_load_progress (nautilus_rpm_view_get_view (rpm_view), progress); */
82#endif
83}
84
85static void
86nautilus_rpm_view_download_failed (EazelInstallCallback *service, 
87                                   const PackageData *pack,
88                                   NautilusRPMView *rpm_view)
89{
90        g_assert (pack->name != NULL);
91        trilobite_debug ("Download of %s FAILED", pack->name);
92}
93
94static void
95get_detailed_errors_foreach (const PackageData *pack, GString *message)
96{
97        switch (pack->status) {
98        case PACKAGE_UNKNOWN_STATUS:
99                break;
100        case PACKAGE_SOURCE_NOT_SUPPORTED:
101                break;
102        case PACKAGE_FILE_CONFLICT:
103        case PACKAGE_DEPENDENCY_FAIL:
104                g_string_sprintfa (message, _("%s would not work anymore\n"), pack->name);
105                break;
106        case PACKAGE_BREAKS_DEPENDENCY:
107                g_string_sprintfa (message, _("%s would break other installed packages\n"), pack->name);
108                break;
109        case PACKAGE_INVALID:
110                break;
111        case PACKAGE_CANNOT_OPEN:
112                g_string_sprintfa (message, _("%s is needed, but could not be found\n"), pack->name);
113                break;
114        case PACKAGE_PARTLY_RESOLVED:
115                break;
116        case PACKAGE_ALREADY_INSTALLED:
117                g_string_sprintfa (message, _("%s was already installed\n"), pack->name);
118                break;
119        case PACKAGE_CIRCULAR_DEPENDENCY:
120                g_string_sprintfa (message, _("%s causes a circular dependency problem\n"), pack->name);
121                break;
122        case PACKAGE_RESOLVED:
123                break;
124        }
125        g_list_foreach (pack->soft_depends, (GFunc)get_detailed_errors_foreach, message);
126        g_list_foreach (pack->hard_depends, (GFunc)get_detailed_errors_foreach, message);
127        g_list_foreach (pack->modifies, (GFunc)get_detailed_errors_foreach, message);
128        g_list_foreach (pack->breaks, (GFunc)get_detailed_errors_foreach, message);
129}
130
131static char*
132get_detailed_errors (const PackageData *pack, int installing)
133{
134        char *result;
135        GString *message;
136
137        message = g_string_new ("");
138        if (installing) {
139                g_string_sprintfa (message, _("Installing %s failed because of the following issue(s):\n"), pack->name);
140        } else {
141                g_string_sprintfa (message, _("Uninstalling %s failed because of the following issue(s):\n"), pack->name);
142        }
143        g_list_foreach (pack->soft_depends, (GFunc)get_detailed_errors_foreach, message);
144        g_list_foreach (pack->hard_depends, (GFunc)get_detailed_errors_foreach, message);
145        g_list_foreach (pack->modifies, (GFunc)get_detailed_errors_foreach, message);
146        g_list_foreach (pack->breaks, (GFunc)get_detailed_errors_foreach, message);
147
148        result = message->str;
149        g_string_free (message, FALSE);
150        return result;
151}
152
153static void
154nautilus_rpm_view_install_failed (EazelInstallCallback *service,
155                                  const PackageData *pd,
156                                  NautilusRPMView *rpm_view)
157{
158        char *detailed;
159
160        detailed = get_detailed_errors (pd, 1);
161        gtk_object_set_data (GTK_OBJECT (rpm_view), "details", detailed);
162}
163
164static void
165nautilus_rpm_view_uninstall_failed (EazelInstallCallback *service,
166                                    const PackageData *pd,
167                                    NautilusRPMView *rpm_view)
168{
169        char *detailed;
170
171        detailed = get_detailed_errors (pd, 0);
172        gtk_object_set_data (GTK_OBJECT (rpm_view), "details", detailed);
173}
174
175static void
176nautilus_rpm_view_dependency_check (EazelInstallCallback *service,
177                                    const PackageData *package,
178                                    const PackageData *needs,
179                                    NautilusRPMView *rpm_view) 
180{
181        if (needs->name && needs->version) {
182                g_message ("Doing dependency check for %s-%s - need %s-%s\n", 
183                         package->name, package->version,
184                         needs->name, needs->version);
185        } else if (needs->name) {
186                g_message ("Doing dependency check for %s-%s - need %s\n", 
187                         package->name, package->version,
188                         needs->name);
189        } else if (needs->provides) {
190                GList *iterator;
191                g_message ("Doing dependency check for %s-%s - need :", 
192                         package->name, package->version);
193                for (iterator = needs->provides; iterator; iterator = g_list_next (iterator)) {
194                        g_message ("- %s", (char*)iterator->data);
195                }
196        } else {
197                g_message ("Doing dependency check for %s-%s - needs something, but I don't know what it was...\n", 
198                           package->name, package->version);
199        }
200#if 0
201        nautilus_view_report_load_underway (nautilus_rpm_view_get_view (rpm_view));
202#endif
203}
204
205/* get rid of the installer and root client, and reactivate buttons */
206static void
207nautilus_rpm_view_finished_working (NautilusRPMView *rpm_view)
208{
209        eazel_install_callback_unref (GTK_OBJECT (rpm_view->details->installer));
210        rpm_view->details->installer = NULL;
211        trilobite_root_client_unref (GTK_OBJECT (rpm_view->details->root_client));
212        rpm_view->details->root_client = NULL;
213
214        gtk_widget_set_sensitive (GTK_WIDGET (rpm_view->details->package_install_button), TRUE);
215        gtk_widget_set_sensitive (GTK_WIDGET (rpm_view->details->package_uninstall_button), TRUE);
216
217        rpm_view->details->password_attempts = 0;
218}
219
220static void
221nautilus_rpm_view_install_done (EazelInstallCallback *service,
222                                gboolean result,
223                                NautilusRPMView *rpm_view)
224{
225        char *tmp;     
226
227        if (!result) {
228                char *dialog_title;
229                char *terse;
230                char *detailed;
231
232                GnomeDialog *d;
233                GtkWidget *window;
234
235                detailed = (char *) gtk_object_get_data (GTK_OBJECT (rpm_view), "details");
236       
237                if (nautilus_rpm_view_get_installed (rpm_view)) {
238                        terse = g_strdup (_("Uninstall failed..."));
239                        dialog_title = g_strdup (_("Uninstall Failed"));
240                } else {
241                        terse = g_strdup (_("Install failed..."));
242                        dialog_title = g_strdup (_("Install Failed"));
243                }
244
245                window = gtk_widget_get_toplevel (GTK_WIDGET (rpm_view));
246                g_assert (window);
247                g_assert (GTK_IS_WINDOW (window));
248                d = nautilus_error_dialog_with_details (terse, 
249                                                        dialog_title,
250                                                        detailed,
251                                                        GTK_WINDOW (window));
252                                                       
253                gnome_dialog_run_and_close (d);
254                g_free (terse);
255                g_free (dialog_title);
256                g_free (detailed);
257                nautilus_view_report_load_failed (nautilus_rpm_view_get_view (rpm_view));
258        } else {
259                nautilus_view_report_load_complete (nautilus_rpm_view_get_view (rpm_view));
260        }
261
262        {
263                CORBA_Environment ev;
264                CORBA_exception_init (&ev);
265                eazel_install_callback_delete_files (service, &ev);
266                CORBA_exception_free (&ev);
267        }
268       
269        nautilus_rpm_view_finished_working (rpm_view);
270       
271        tmp = g_strdup (nautilus_rpm_view_get_uri (rpm_view));
272        nautilus_rpm_view_load_uri (rpm_view, tmp);
273        g_free (tmp);
274}
275
276/* BEGIN code chunk from nautilus-install-view.c */
277
278/* signal callback -- ask the user for the root password (for installs) */
279static char *
280nautilus_service_need_password (GtkObject *object, const char *prompt, 
281                                NautilusRPMView *view)
282{
283        char *message = NULL;
284        GtkWidget *dialog;
285        gboolean okay;
286        char *out;
287
288        if (view->details->remembered_password) {
289                return g_strdup (view->details->remembered_password);
290        }
291
292        if (view->details->password_attempts > 0) {
293                message = _("Incorrect password.");
294        }
295
296        dialog = nautilus_password_dialog_new ("Authenticate Me", message, prompt, "", TRUE);
297        okay = nautilus_password_dialog_run_and_block (NAUTILUS_PASSWORD_DIALOG (dialog));
298
299        if (! okay) {
300                /* cancel */
301                view->details->password_attempts = 0;
302                out = g_strdup ("");
303        } else {
304                out = nautilus_password_dialog_get_password (NAUTILUS_PASSWORD_DIALOG (dialog));
305                if (nautilus_password_dialog_get_remember (NAUTILUS_PASSWORD_DIALOG (dialog))) {
306                        view->details->remembered_password = g_strdup (out);
307                }
308        }
309
310        gtk_widget_destroy (dialog);
311        gtk_main_iteration ();
312
313        if (okay) {
314                view->details->password_attempts++;
315        }
316
317        return out;
318}
319
320/* bad password -- let em try again? */
321static gboolean
322nautilus_service_try_again (GtkObject *object, 
323                            NautilusRPMView*view)
324{
325        if (view->details->password_attempts == 0) {
326                /* user hit "cancel" */
327                return FALSE;
328        }
329
330        /* a wrong password shouldn't be remembered :) */
331        g_free (view->details->remembered_password);
332        view->details->remembered_password = NULL;
333
334        if (view->details->password_attempts >= 3) {
335                /* give up. */
336                view->details->password_attempts = 0;
337                return FALSE;
338        }
339        return TRUE;
340}
341
342static TrilobiteRootClient *
343set_root_client (BonoboObjectClient *service, 
344                 NautilusRPMView *view)
345{
346        TrilobiteRootClient *root_client = NULL;
347        CORBA_Environment ev;
348
349        CORBA_exception_init (&ev);
350
351        if (bonobo_object_client_has_interface (service, "IDL:Trilobite/PasswordQuery:1.0", &ev)) {
352                root_client = trilobite_root_client_new ();
353                if (! trilobite_root_client_attach (root_client, service)) {
354                        g_warning ("unable to attach root client to Trilobite/PasswordQuery!");
355                }
356
357                gtk_signal_connect (GTK_OBJECT (root_client), "need_password",
358                                    GTK_SIGNAL_FUNC (nautilus_service_need_password),
359                                    view);
360                gtk_signal_connect (GTK_OBJECT (root_client), "try_again",
361                                    GTK_SIGNAL_FUNC (nautilus_service_try_again),
362                                    view);
363        } else {
364                g_warning ("Object does not support IDL:Trilobite/PasswordQuery:1.0");
365        }
366
367        CORBA_exception_free (&ev);
368        return root_client;
369}
370
371/* END code chunk from nautilus-install-view.c */
372
373static gboolean
374delete_files (EazelInstallCallback *service,
375              gpointer unused)
376{
377        return FALSE;
378}
379
380/* we don't really need this confirmation stage */
381static gboolean
382preflight_check (EazelInstallCallback *cb, const GList *packages,
383                 int total_bytes, int total_packages, void *unused)
384{
385        return TRUE;
386}
387
388static void
389nautilus_rpm_view_set_server (NautilusRPMView *rpm_view,
390                              EazelInstallCallback *cb,
391                              CORBA_Environment *ev)
392{
393        int port;
394        char *host, *p;
395
396        /* get default host/port */
397        host = g_strdup (trilobite_get_services_address ());
398        if ((p = strchr (host, ':')) != NULL) {
399                *p = 0;
400        }
401        /* always go for the no auth port */
402        port = 80;
403
404        GNOME_Trilobite_Eazel_Install__set_server (eazel_install_callback_corba_objref (cb), host, ev);
405        GNOME_Trilobite_Eazel_Install__set_server_port (eazel_install_callback_corba_objref (cb), port, ev);
406
407        /* For now always set auth to FALSE, so users are not required to
408           login to services to install local rpm files */
409        GNOME_Trilobite_Eazel_Install__set_auth (eazel_install_callback_corba_objref (cb), FALSE, ev);
410}
411
412void 
413nautilus_rpm_view_install_package_callback (GtkWidget *widget,
414                                            NautilusRPMView *rpm_view)
415{
416        GList *categories;
417        CategoryData *category;
418        CORBA_Environment ev;
419        EazelInstallCallback *cb;
420
421        CORBA_exception_init (&ev);
422
423        categories = NULL;
424
425        gtk_widget_set_sensitive (GTK_WIDGET (rpm_view->details->package_install_button), FALSE);
426        gtk_widget_set_sensitive (GTK_WIDGET (rpm_view->details->package_uninstall_button), FALSE);
427        nautilus_view_report_load_underway (nautilus_rpm_view_get_view (rpm_view));
428
429        g_assert (rpm_view->details->package);
430        category = categorydata_new ();
431        category->packages = g_list_prepend (NULL, rpm_view->details->package);
432        categories = g_list_prepend (NULL, category);
433
434        cb = eazel_install_callback_new ();
435
436        rpm_view->details->installer = cb;
437        rpm_view->details->root_client = set_root_client (eazel_install_callback_bonobo (cb), rpm_view);
438       
439        GNOME_Trilobite_Eazel_Install__set_protocol (eazel_install_callback_corba_objref (cb), GNOME_Trilobite_Eazel_PROTOCOL_HTTP, &ev);
440        nautilus_rpm_view_set_server (rpm_view, cb, &ev);
441
442        gtk_signal_connect (GTK_OBJECT (cb), "download_progress", nautilus_rpm_view_download_progress_signal, rpm_view);
443        gtk_signal_connect (GTK_OBJECT (cb), "install_progress", nautilus_rpm_view_install_progress_signal, rpm_view);
444        gtk_signal_connect (GTK_OBJECT (cb), "dependency_check", nautilus_rpm_view_dependency_check, rpm_view);
445        gtk_signal_connect (GTK_OBJECT (cb), "install_failed", nautilus_rpm_view_install_failed, rpm_view);
446        gtk_signal_connect (GTK_OBJECT (cb), "uninstall_failed", nautilus_rpm_view_install_failed, rpm_view);
447        gtk_signal_connect (GTK_OBJECT (cb), "download_failed", nautilus_rpm_view_download_failed, rpm_view);
448        gtk_signal_connect (GTK_OBJECT (cb), "done", nautilus_rpm_view_install_done, rpm_view);
449        gtk_signal_connect (GTK_OBJECT (cb), "preflight_check", GTK_SIGNAL_FUNC (preflight_check), NULL);
450
451        eazel_install_callback_install_packages (cb, categories, NULL, &ev);
452
453        /* Leak the categories here */
454
455        CORBA_exception_free (&ev);               
456}
457
458void 
459nautilus_rpm_view_uninstall_package_callback (GtkWidget *widget,
460                                              NautilusRPMView *rpm_view)
461{
462        CategoryData *category;
463        GList *categories;
464        CORBA_Environment ev;
465        EazelInstallCallback *cb;               
466
467        CORBA_exception_init (&ev);
468
469        categories = NULL;
470
471        gtk_widget_set_sensitive (GTK_WIDGET (rpm_view->details->package_install_button), FALSE);
472        gtk_widget_set_sensitive (GTK_WIDGET (rpm_view->details->package_uninstall_button), FALSE);
473        nautilus_view_report_load_underway (nautilus_rpm_view_get_view (rpm_view));
474
475        g_assert (rpm_view->details->package);
476        category = categorydata_new ();
477        category->packages = g_list_prepend (NULL, rpm_view->details->package);
478        categories = g_list_prepend (NULL, category);
479
480        cb = eazel_install_callback_new ();
481
482        rpm_view->details->installer = cb;
483        rpm_view->details->root_client = set_root_client (eazel_install_callback_bonobo (cb), rpm_view);
484       
485        GNOME_Trilobite_Eazel_Install__set_protocol (eazel_install_callback_corba_objref (cb), GNOME_Trilobite_Eazel_PROTOCOL_HTTP, &ev);
486        GNOME_Trilobite_Eazel_Install__set_tmp_dir (eazel_install_callback_corba_objref (cb), "/tmp/eazel-install", &ev);
487        gtk_signal_connect (GTK_OBJECT (cb), "download_progress", nautilus_rpm_view_download_progress_signal, rpm_view);
488        gtk_signal_connect (GTK_OBJECT (cb), "uninstall_progress", nautilus_rpm_view_install_progress_signal, rpm_view);
489        gtk_signal_connect (GTK_OBJECT (cb), "uninstall_failed", nautilus_rpm_view_uninstall_failed, rpm_view);
490        gtk_signal_connect (GTK_OBJECT (cb), "dependency_check", nautilus_rpm_view_dependency_check, rpm_view);
491        gtk_signal_connect (GTK_OBJECT (cb), "done", nautilus_rpm_view_install_done, rpm_view);
492        gtk_signal_connect (GTK_OBJECT (cb), "delete_files", GTK_SIGNAL_FUNC (delete_files), NULL);
493        gtk_signal_connect (GTK_OBJECT (cb), "preflight_check", GTK_SIGNAL_FUNC (preflight_check), NULL);
494       
495        eazel_install_callback_uninstall_packages (cb, categories, NULL, &ev);
496        /* Leak the categories here */
497       
498        CORBA_exception_free (&ev);               
499}
Note: See TracBrowser for help on using the browser.