summaryrefslogtreecommitdiff
path: root/components/services/install-view/nautilus-service-install-view.c
blob: 632c1e28d95322549717aba78e3e5160068b2593 (plain)
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */

/* 
 * Copyright (C) 2000, 2001  Eazel, Inc
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * Authors: J Shane Culpepper <pepper@eazel.com>
 *          Robey Pointer <robey@eazel.com>
 */

#include <config.h>

#include "nautilus-service-install-view.h"
#include "eazel-services-header.h"
#include "eazel-services-extensions.h"
#include <libeazelinstall.h>
#include "eazel-install-metadata.h"		/* eazel_install_configure_check_jump_after_install */
#include "libtrilobite/libtrilobite.h"
#include "libtrilobite/libammonite-gtk.h"

#include <gnome-xml/tree.h>
#include <libgnomevfs/gnome-vfs-utils.h>
#include <libnautilus-extensions/nautilus-background.h>
#include <libnautilus-extensions/nautilus-gtk-extensions.h>
#include <libnautilus-extensions/nautilus-gtk-macros.h>
#include <libnautilus-extensions/nautilus-glib-extensions.h>
#include <libnautilus-extensions/nautilus-global-preferences.h>
#include <libnautilus-extensions/nautilus-file-utilities.h>
#include <libnautilus-extensions/nautilus-string.h>
#include <libnautilus-extensions/nautilus-label.h>
#include <libnautilus-extensions/nautilus-gdk-extensions.h>
#include <libnautilus-extensions/nautilus-password-dialog.h>
#include <libnautilus-extensions/nautilus-stock-dialogs.h>
#include <libnautilus-extensions/nautilus-viewport.h>
#include <libnautilus-extensions/nautilus-preferences.h>
#include <stdio.h>
#include <fcntl.h>
#include <dirent.h>
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>

/* for uname */
#include <sys/utsname.h>

/* number of rows of (label, progressbar) to scroll at the bottom */
#define STATUS_ROWS		2

#define PROGRESS_BAR_HEIGHT	15
#define MESSAGE_BOX_HEIGHT	110

/* This ensures that if the arch is detected as i[3-9]86, the
   requested archtype will be set to i386 */
#define ASSUME_ix86_IS_i386 

/* send the user here after a completed (success or failure) install */
#define NEXT_URL_ANONYMOUS     "eazel:"
#define NEXT_URL               "eazel-services:/catalog"

#define PASSWORD_PROMPT		_("Please enter your root password to continue installing. (This password is not saved or transmitted off your system.)")

static void       nautilus_service_install_view_initialize_class (NautilusServiceInstallViewClass	*klass);
static void       nautilus_service_install_view_initialize       (NautilusServiceInstallView		*view);
static void       nautilus_service_install_view_destroy          (GtkObject				*object);
static void       service_install_load_location_callback         (NautilusView				*nautilus_view,
								  const char				*location,
								  NautilusServiceInstallView		*view);
static void	  service_install_stop_loading_callback		 (NautilusView				*nautilus_view,
								  NautilusServiceInstallView		*view);
    
NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusServiceInstallView, nautilus_service_install_view, GTK_TYPE_EVENT_BOX)


/* gtk rulez */
static void
add_padding_to_box (GtkWidget *box, int pad_x, int pad_y)
{
	GtkWidget *filler;

	filler = gtk_label_new ("");
	gtk_widget_set_usize (filler, pad_x ? pad_x : 1, pad_y ? pad_y : 1);
	gtk_widget_show (filler);
	gtk_box_pack_start (GTK_BOX (box), filler, FALSE, FALSE, 0);
}

static gboolean
line_expose (GtkWidget *widget, GdkEventExpose *event)
{
	gdk_window_clear_area (widget->window, event->area.x, event->area.y, event->area.width, event->area.height);
	gdk_gc_set_clip_rectangle (widget->style->fg_gc[widget->state], &event->area);
	gdk_draw_line (widget->window, widget->style->fg_gc[widget->state],
		       event->area.x, widget->allocation.height/2,
		       event->area.x + event->area.width, widget->allocation.height/2);
	gdk_gc_set_clip_rectangle (widget->style->fg_gc[widget->state], NULL);

	return TRUE;
}

static GtkWidget *
horizontal_line_new (int height)
{
	GtkWidget *line;
	NautilusBackground *background;

	line = gtk_drawing_area_new ();
	gtk_drawing_area_size (GTK_DRAWING_AREA (line), 100, 1);
	gtk_signal_connect (GTK_OBJECT (line), "expose_event", GTK_SIGNAL_FUNC (line_expose), NULL);
	gtk_widget_set_usize (line, -2, height);

	background = nautilus_get_widget_background (line);
	nautilus_background_set_color (background, EAZEL_SERVICES_BACKGROUND_COLOR_SPEC);

	return line;
}

static void
install_message_destroy (InstallMessage *im)
{
	g_free (im->package_name);
	g_free (im);
}

static InstallMessage *
install_message_new (NautilusServiceInstallView *view, const char *package_name)
{
	InstallMessage *im, *im2;
	GtkWidget *bogus_label;
	GList *iter;

	im = NULL;
	
	for (iter = g_list_first (view->details->message); iter != NULL; iter = g_list_next (iter)) {
		im = (InstallMessage *)(iter->data);
		if (strcmp (im->package_name, package_name) == 0) {
			break;
		}
	}
	if (iter != NULL) {
		/* trash the old one */
		gtk_container_remove (GTK_CONTAINER (view->details->message_box), im->hbox);
		if (im->line != NULL) {
			gtk_container_remove (GTK_CONTAINER (view->details->message_box), im->line);
		} else if (iter->prev) {
			/* remove the line from the one above, if present */
			im2 = (InstallMessage *)(iter->prev->data);
			gtk_container_remove (GTK_CONTAINER (view->details->message_box), im2->line);
			im2->line = NULL;
		}
		view->details->message = g_list_remove (view->details->message, im);
		install_message_destroy (im);
	}

	im = g_new0 (InstallMessage, 1);
	im->label = eazel_services_label_new (NULL, 0, 0.0, 0.5, 0, 0,
					      EAZEL_SERVICES_BODY_TEXT_COLOR_RGB,
					      EAZEL_SERVICES_BACKGROUND_COLOR_RGB,
					      NULL, -2, FALSE);
	nautilus_label_set_justify (NAUTILUS_LABEL (im->label), GTK_JUSTIFY_LEFT);
	gtk_widget_show (im->label);
	im->progress_bar = gtk_progress_bar_new ();
	gtk_progress_bar_set_bar_style (GTK_PROGRESS_BAR (im->progress_bar), GTK_PROGRESS_CONTINUOUS);
	gtk_progress_bar_set_orientation (GTK_PROGRESS_BAR (im->progress_bar), GTK_PROGRESS_LEFT_TO_RIGHT);
	gtk_progress_bar_update (GTK_PROGRESS_BAR (im->progress_bar), 0.0);
	gtk_widget_set_usize (im->progress_bar, -2, PROGRESS_BAR_HEIGHT);
	gtk_widget_show (im->progress_bar);

	im->progress_label = eazel_services_label_new (NULL, 0, 0.0, 0.0, 0, 0,
						       EAZEL_SERVICES_BODY_TEXT_COLOR_RGB,
						       EAZEL_SERVICES_BACKGROUND_COLOR_RGB,
						       NULL, -2, TRUE);
	nautilus_label_set_justify (NAUTILUS_LABEL (im->progress_label), GTK_JUSTIFY_LEFT);

	gtk_widget_show (im->progress_label);

	bogus_label = gtk_label_new ("");
	gtk_widget_show (bogus_label);

	im->vbox = gtk_vbox_new (FALSE, 0);
	gtk_box_pack_start (GTK_BOX (im->vbox), im->progress_bar, FALSE, FALSE, 0);
	add_padding_to_box (im->vbox, 0, 5);
	gtk_box_pack_start (GTK_BOX (im->vbox), im->progress_label, FALSE, FALSE, 0);
	gtk_widget_show (im->vbox);

	im->hbox = gtk_hbox_new (FALSE, 0);
	add_padding_to_box (im->hbox, 20, 0);
	gtk_box_pack_start (GTK_BOX (im->hbox), im->label, FALSE, FALSE, 0);
	gtk_box_pack_start (GTK_BOX (im->hbox), bogus_label, TRUE, TRUE, 0);
	gtk_box_pack_start (GTK_BOX (im->hbox), im->vbox, FALSE, FALSE, 0);
	add_padding_to_box (im->hbox, 20, 0);
	gtk_widget_show (im->hbox);

	/* show the middle header in case this is the first install message */
	gtk_widget_show (view->details->middle_title);

#if 0
	if (g_list_length (view->details->message) == STATUS_ROWS) {
		gtk_widget_set_usize (view->details->pane, -2, view->details->pane->allocation.height);
		gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (view->details->pane),
						GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
	}
#endif

	/* add this, and possibly a separating line, to the message box */
	if (g_list_length (view->details->message) > 0) {
		/* draw line */
		im->line = horizontal_line_new (6);
		gtk_widget_show (im->line);
		gtk_box_pack_end (GTK_BOX (view->details->message_box), im->line, FALSE, FALSE, 0);
	} else {
		im->line = NULL;
	}
	gtk_box_pack_end (GTK_BOX (view->details->message_box), im->hbox, FALSE, FALSE, 5);

	gtk_adjustment_changed (gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (view->details->pane)));

	im->package_name = g_strdup (package_name);
	view->details->message = g_list_prepend (view->details->message, im);

	/* unbelievable!  gtk won't redraw correctly unless we poke it in the ass */
	gtk_widget_queue_resize (view->details->form);
	gtk_widget_queue_draw (view->details->form);

	return im;
}

static void
generate_install_form (NautilusServiceInstallView	*view) 
{
	GtkWidget	*temp_box;
	GtkWidget	*title;
	GtkWidget	*viewport;
	GtkWidget	*filler;
	NautilusBackground *background;

	/* allocate the parent box to hold everything */
	view->details->form = gtk_vbox_new (FALSE, 0);
	gtk_container_add (GTK_CONTAINER (view), view->details->form);

	/* Setup the title */
	title = eazel_services_header_title_new (_("Easy Install"));
        gtk_box_pack_start (GTK_BOX (view->details->form), title, FALSE, FALSE, 0);
        gtk_widget_show (title);

	/* Add package information */

	add_padding_to_box (view->details->form, 0, 6);

	/* Package Name */
	temp_box = gtk_hbox_new (FALSE, 0);
	gtk_box_pack_start (GTK_BOX (view->details->form), temp_box, FALSE, FALSE, 0);
	gtk_widget_show (temp_box);
	view->details->package_name = eazel_services_label_new (NULL, 0, 0.0, 0.0, 0, 0,
								EAZEL_SERVICES_BODY_TEXT_COLOR_RGB,
								EAZEL_SERVICES_BACKGROUND_COLOR_RGB,
								NULL, 4, TRUE);
	nautilus_label_set_justify (NAUTILUS_LABEL (view->details->package_name), GTK_JUSTIFY_LEFT);
	gtk_box_pack_start (GTK_BOX (temp_box), view->details->package_name, FALSE, FALSE, 15);
	gtk_widget_show (view->details->package_name);

	/* Package Version */
	temp_box = gtk_hbox_new (FALSE, 0);
	gtk_box_pack_start (GTK_BOX (view->details->form), temp_box, FALSE, FALSE, 2);
	gtk_widget_show (temp_box);
	view->details->package_version = eazel_services_label_new (NULL, 0, 0.0, 0.0, 0, 0,
								   EAZEL_SERVICES_BODY_TEXT_COLOR_RGB,
								   EAZEL_SERVICES_BACKGROUND_COLOR_RGB,
								   NULL, -2, TRUE);
	nautilus_label_set_justify (NAUTILUS_LABEL (view->details->package_version), GTK_JUSTIFY_LEFT);
	gtk_box_pack_start (GTK_BOX (temp_box), view->details->package_version, FALSE, FALSE, 15);
	gtk_widget_show (view->details->package_version);

	add_padding_to_box (view->details->form, 0, 4);

	/* generate the overall progress bar */
	temp_box = gtk_hbox_new (FALSE, 0);
	gtk_box_pack_start (GTK_BOX (view->details->form), temp_box, FALSE, FALSE, 2);
	gtk_widget_show (temp_box);
	view->details->total_progress_bar = gtk_progress_bar_new ();
	gtk_widget_set_usize (view->details->total_progress_bar, -2, PROGRESS_BAR_HEIGHT);
	add_padding_to_box (temp_box, 30, 0);
	gtk_box_pack_start (GTK_BOX (temp_box), view->details->total_progress_bar, FALSE, FALSE, 0);
	gtk_widget_show (view->details->total_progress_bar);

	/* add a label for progress messages, but don't show it until there's a message */
	temp_box = gtk_hbox_new (FALSE, 0);
	gtk_box_pack_start (GTK_BOX (view->details->form), temp_box, FALSE, FALSE, 2);
	gtk_widget_show (temp_box);
	view->details->overall_feedback_text = eazel_services_label_new (NULL, 0, 0.0, 0.0, 0, 0,
									 EAZEL_SERVICES_BODY_TEXT_COLOR_RGB,
									 EAZEL_SERVICES_BACKGROUND_COLOR_RGB,
									 NULL, -2, FALSE);
	nautilus_label_set_justify (NAUTILUS_LABEL (view->details->overall_feedback_text), GTK_JUSTIFY_LEFT);
	nautilus_label_set_text (NAUTILUS_LABEL (view->details->overall_feedback_text), " ");
	gtk_widget_show (view->details->overall_feedback_text);
	add_padding_to_box (temp_box, 30, 0);
	gtk_box_pack_start (GTK_BOX (temp_box), view->details->overall_feedback_text, TRUE, TRUE, 0);

	add_padding_to_box (view->details->form, 0, 10);

	/* Package Description */
	temp_box = gtk_hbox_new (FALSE, 0);
	gtk_box_pack_start (GTK_BOX (view->details->form), temp_box, FALSE, FALSE, 2);
	gtk_widget_show (temp_box);

	view->details->package_details = eazel_services_label_new (NULL, 0, 0.0, 0.0, 0, 0,
								   EAZEL_SERVICES_BODY_TEXT_COLOR_RGB,
								   EAZEL_SERVICES_BACKGROUND_COLOR_RGB,
								   NULL, -2, FALSE);
	nautilus_label_set_justify (NAUTILUS_LABEL (view->details->package_details), GTK_JUSTIFY_LEFT);
	nautilus_label_set_wrap (NAUTILUS_LABEL (view->details->package_details), TRUE);

	gtk_box_pack_start (GTK_BOX (temp_box), view->details->package_details, FALSE, FALSE, 15);
	gtk_widget_show (view->details->package_details);

	/* filler blob to separate the top from the bottom */
	gtk_box_pack_start (GTK_BOX (view->details->form), gtk_label_new (""), TRUE, FALSE, 0);

	/* add a table at the bottom of the screen to hold current progresses */
	view->details->message_box = gtk_vbox_new (FALSE, 0);
	filler = gtk_label_new ("");
	gtk_widget_show (filler);
	gtk_box_pack_end (GTK_BOX (view->details->message_box), filler, TRUE, TRUE, 0);

	view->details->pane = gtk_scrolled_window_new (NULL, NULL);
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (view->details->pane), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
	viewport = nautilus_viewport_new (NULL, NULL);
	gtk_viewport_set_shadow_type (GTK_VIEWPORT (viewport), GTK_SHADOW_NONE);
	gtk_container_add (GTK_CONTAINER (view->details->pane), viewport);
	gtk_widget_show (viewport);
	gtk_container_add (GTK_CONTAINER (viewport), view->details->message_box);
	gtk_widget_show (view->details->message_box);
	background = nautilus_get_widget_background (viewport);
	nautilus_background_set_color (background, EAZEL_SERVICES_BACKGROUND_COLOR_SPEC);
	gtk_widget_set_usize (view->details->pane, -2, MESSAGE_BOX_HEIGHT);
	gtk_widget_show (view->details->pane);
	gtk_box_pack_end (GTK_BOX (view->details->form), view->details->pane, FALSE, FALSE, 2);

	/* Setup the progress header */
	/* FIXME: the middle header is all fubar now, so we just say "messages", but the spec
	 * shows "progress" over the 2nd column of the message box.  it's just too hard to get
	 * it aligned currently.
	 */
	view->details->middle_title = eazel_services_header_middle_new (_("Messages"), "");
        gtk_box_pack_end (GTK_BOX (view->details->form), view->details->middle_title, FALSE, FALSE, 0);
	/* don't show the progress header until there's still to go there */

	gtk_widget_show (view->details->form);
}



/* utility routine to show an error message */
static void
show_overall_feedback (NautilusServiceInstallView *view, char *progress_message)
{
	nautilus_label_set_text (NAUTILUS_LABEL (view->details->overall_feedback_text), progress_message);
}

static void
nautilus_service_install_view_initialize_class (NautilusServiceInstallViewClass *klass)
{

	GtkObjectClass	*object_class;
	GtkWidgetClass	*widget_class;
	
	object_class = GTK_OBJECT_CLASS (klass);
	widget_class = GTK_WIDGET_CLASS (klass);
	parent_class = gtk_type_class (gtk_event_box_get_type ());
	object_class->destroy = nautilus_service_install_view_destroy;
}

static void
nautilus_service_install_view_initialize (NautilusServiceInstallView *view)
{

	NautilusBackground	*background;

	view->details = g_new0 (NautilusServiceInstallViewDetails, 1);
	view->details->nautilus_view = nautilus_view_new (GTK_WIDGET (view));
	gtk_signal_connect (GTK_OBJECT (view->details->nautilus_view), 
			    "load_location",
			    GTK_SIGNAL_FUNC (service_install_load_location_callback), 
			    view);
	gtk_signal_connect (GTK_OBJECT (view->details->nautilus_view),
			    "stop_loading",
			    GTK_SIGNAL_FUNC (service_install_stop_loading_callback),
			    view);

	background = nautilus_get_widget_background (GTK_WIDGET (view));
	nautilus_background_set_color (background, EAZEL_SERVICES_BACKGROUND_COLOR_SPEC);

	view->details->core_package = FALSE;
	view->details->deps = g_hash_table_new (g_str_hash, g_str_equal);

	gtk_widget_show (GTK_WIDGET (view));
}

static gboolean
deps_destroy_foreach (char *key, char *value)
{
	g_free (key);
	g_free (value);
	return TRUE;
}

static void
nautilus_service_install_view_destroy (GtkObject *object)
{
	NautilusServiceInstallView *view;
	GNOME_Trilobite_Eazel_Install	service;
	CORBA_Environment ev;

	view = NAUTILUS_SERVICE_INSTALL_VIEW (object);

	CORBA_exception_init (&ev);
	if (view->details->installer != NULL) {
		service = eazel_install_callback_corba_objref (view->details->installer);
		GNOME_Trilobite_Eazel_Install_stop (service, &ev);
	}
	CORBA_exception_free (&ev);

	g_free (view->details->uri);
	g_free (view->details->current_rpm);
	g_free (view->details->remembered_password);
	g_hash_table_foreach_remove (view->details->deps, (GHRFunc)deps_destroy_foreach, NULL);
	g_hash_table_destroy (view->details->deps);
	g_list_foreach (view->details->message, (GFunc)install_message_destroy, NULL);
	g_list_free (view->details->message);
	g_free (view->details->username);

	if (view->details->root_client) {
		trilobite_root_client_unref (GTK_OBJECT (view->details->root_client));
	}

	if (view->details->installer != NULL) {
		/* this will unref the installer too, which will indirectly cause any ongoing download to abort */
		eazel_install_callback_unref (GTK_OBJECT (view->details->installer));
	}

	g_free (view->details);
	
	NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object));
}

NautilusView *
nautilus_service_install_view_get_nautilus_view (NautilusServiceInstallView *view)
{
	return view->details->nautilus_view;
}


static PackageData *
create_package (char *name, int local_file) 
{
	struct utsname buf;
	PackageData *pack;

	g_assert (name);

	uname (&buf);
	pack = packagedata_new ();
	if (local_file) {
		pack->filename = g_strdup (name);
	} else if (strncmp (name, "rpm_id%3D", 9) == 0) {
		pack->eazel_id = g_strdup (name+9);
	} else if (strncmp (name, "rpm_id=", 7) == 0) {
		pack->eazel_id = g_strdup (name+7);
	} else if (strncmp (name, "product_id%3D", 13) == 0) {
		pack->suite_id = g_strdup_printf ("P:%s", name+13);
	} else if (strncmp (name, "product_id=", 11) == 0) {
		pack->suite_id = g_strdup_printf ("P:%s", name+11);
	} else if (strncmp (name, "suite_id%3D", 11) == 0) {
		pack->suite_id = g_strdup_printf ("S:%s", name+11);
	} else if (strncmp (name, "suite_id=", 9) == 0) {
		pack->suite_id = g_strdup_printf ("S:%s", name+9);
	} else if (strncmp (name, "product_name%3D", 15) == 0) {
		pack->suite_id = g_strdup_printf ("N:%s", name+15);
	} else if (strncmp (name, "product_name=", 13) == 0) {
		pack->suite_id = g_strdup_printf ("N:%s", name+13);
	} else if (strncmp (name, "suite_name%3D", 13) == 0) {
		pack->suite_id = g_strdup_printf ("X:%s", name+13);
	} else if (strncmp (name, "suite_name=", 11) == 0) {
		pack->suite_id = g_strdup_printf ("X:%s", name+11);
	} else {
		pack->name = g_strdup (name);
	}
	pack->archtype = g_strdup (buf.machine);
#ifdef ASSUME_ix86_IS_i386
	if (strlen (pack->archtype)==4 && pack->archtype[0]=='i' &&
	    pack->archtype[1]>='3' && pack->archtype[1]<='9' &&
	    pack->archtype[2]=='8' && pack->archtype[3]=='6') {
		g_free (pack->archtype);
		pack->archtype = g_strdup ("i386");
	}
#endif
	pack->distribution = trilobite_get_distribution ();
	pack->toplevel = TRUE;
	
	return pack;
}

/* quick & dirty: parse the url into (host, port) and a category list */
/* format:
 * "eazel-install:" [ "//" [ username "@" ] [ "hostname" [ ":" port ] ] "/" ] 
 * 	package-name [ "?version=" version ] ( ";" package-name [ "?version=" version ] )*
 *
 * eazel-install:xfig
 * eazel-install://anonymous@/freeamp
 * eazel-install://example.com:8888/nautilus?version=1.0;xpdf;sephiroth?version=0.4
 */
/* returns TRUE if a hostname was parsed from the uri */
static gboolean
nautilus_install_parse_uri (const char *uri, NautilusServiceInstallView *view,
			    char **host, int *port, char **username)
{
	char *p, *q, *pnext, *package_name, *host_spec, *rest, *ptr;
	GList *packages = NULL;
	PackageData *pack;
	gboolean result = FALSE;
	gboolean another_package;

	view->details->categories = NULL;

	p = strchr (uri, ':');
	if (! p) {
		/* bad mojo */
		return result;
	}
	p++;

	/* "//[user@]host[:port]" spec? */
	if ((*p == '/') && (*(p+1) == '/')) {
		p += 2;

		q = strchr (p, '/');
		if (! q) {
			q = p + strlen(p);
		}
		host_spec = g_strndup (p, q - p);

		/* optional "user@" */
		p = strchr (host_spec, '@');
		if (p) {
			*p = 0;
			g_free (*username);
			*username = host_spec;
			if (*(p+1)) {
				g_free (*host);
				*host = g_strdup (p+1);
				result = TRUE;
			}
		} else {
			g_free (*host);
			*host = host_spec;
			result = TRUE;
		}

		if (*host) {
			/* optional ":port" */
			p = strchr (*host, ':');
			if (p) {
				*p = 0;
				*port = atoi (p+1);
			}
		}

		/* push p to past the trailing '/' */
		p = (*q) ? q+1 : q;
	}

	/* full path specified?  local file instead of server */
	if (*p == '/') {
		view->details->using_local_file = 1;
	}

	if (*p) {
		rest = g_strdup (p);
		ptr = rest;
		do {
			pnext = strchr (ptr, ';');
			if ((pnext != NULL) && (*(pnext+1) != '\0')) {
				another_package = TRUE;
				*pnext++ = '\0';
			} else {
				another_package = FALSE;
			}

			trilobite_debug ("package '%s'", ptr);
			/* version name specified? */
			q = strchr (ptr, '?');
			if (q) {
				*q++ = 0;
				if (strncmp (q, "version=", 8) == 0) {
					q += 8;
				}
			}

			package_name = gnome_vfs_unescape_string_for_display (ptr);
			pack = create_package (package_name, view->details->using_local_file);
			if (q) {
				pack->version = g_strdup (q);
			}
			packages = g_list_prepend (packages, pack);
			g_free (package_name);

			if (pnext != NULL) {
				ptr = pnext;
			}
		} while (another_package);
		g_free (rest);
	}

	trilobite_debug ("host '%s:%d' username '%s'", *host ? *host : "(default)", *host ? *port : 0,
			 *username ? *username : "(default)");

	/* add to categories */
	if (packages) {
		CategoryData *category;

		category = categorydata_new ();
		category->packages = packages;
		view->details->categories = g_list_prepend (view->details->categories, category);
	}
	return result;
}

static void
update_package_info_display (NautilusServiceInstallView *view, const PackageData *pack, const char *format)
{
	char *out;

       out = g_strdup_printf (format, pack->name);
       nautilus_label_set_text (NAUTILUS_LABEL (view->details->package_name), out);
       g_free (out);

       if ((pack->description != NULL) && 
           (strchr (pack->description, '\n') != NULL)) {
               nautilus_label_set_wrap (NAUTILUS_LABEL (view->details->package_details), FALSE);
       } else {
               nautilus_label_set_wrap (NAUTILUS_LABEL (view->details->package_details), TRUE);
       }
       nautilus_label_set_text (NAUTILUS_LABEL (view->details->package_details), pack->description);
       out = g_strdup_printf (_("Version: %s"), pack->version);
       nautilus_label_set_text (NAUTILUS_LABEL (view->details->package_version), out);
       g_free (out);
}

/* replace the current progress bar (in the message box) with a centered label saying "Complete!" */
static void
current_progress_bar_complete (NautilusServiceInstallView *view, const char *text)
{
	/* can't figure out a decent way to do this yet... :( */
	if (view->details->current_im != NULL) {
		nautilus_label_set_text (NAUTILUS_LABEL (view->details->current_im->progress_label), text);
		gtk_widget_queue_resize (view->details->message_box);
	}
}

/* keep the user up-to-date on the install service's long-ass contemplations */
static void
nautilus_service_install_conflict_check (EazelInstallCallback *cb, const PackageData *pack,
					 NautilusServiceInstallView *view)
{
	char *out;

	if (view->details->installer == NULL) {
		g_warning ("Got conflict check after unref!");
		return;
	}

	g_assert (pack->name != NULL);
	out = g_strdup_printf (_("Checking \"%s\" for conflicts..."), pack->name);
	show_overall_feedback (view, out);
	g_free (out);
}

static void
nautilus_service_install_downloading (EazelInstallCallback *cb, const PackageData *pack, int amount, int total,
				      NautilusServiceInstallView *view)
{
	char *out;
	const char *needed_by;
	InstallMessage *im = view->details->current_im;
	float fake_amount;

	if (amount > total) {
		/* work around temporary EI bug where amount is sometimes total+1k */
		return;
	}

	if (view->details->installer == NULL) {
		g_warning ("Got download notice after unref!");
		return;
	}

	/* install lib better damn well know the name of the package by the time we download it! */
	g_assert (pack->name != NULL);
	view->details->downloaded_anything = TRUE;

	if (amount == 0) {
		/* could be a redundant zero-trigger for the same rpm... */
		if (view->details->current_rpm && (strcmp (view->details->current_rpm, pack->name) == 0)) {
			return;
		}

		if (view->details->cylon_timer) {
			gtk_timeout_remove (view->details->cylon_timer);
			view->details->cylon_timer = 0;
		}

		g_free (view->details->current_rpm);
		view->details->current_rpm = g_strdup (pack->name);

		if (pack->toplevel) {
			update_package_info_display (view, pack, _("Downloading \"%s\""));
		}

		/* new progress message and bar */
		im = view->details->current_im = install_message_new (view, pack->name);
		gtk_progress_set_percentage (GTK_PROGRESS (im->progress_bar), 0.0);
		out = g_strdup_printf (_("0K of %dK"), total/1024);
		nautilus_label_set_text (NAUTILUS_LABEL (im->progress_label), out);
		g_free (out);
		view->details->last_k = 0;

		needed_by = g_hash_table_lookup (view->details->deps, pack->name);
		if (needed_by != NULL) {
			out = g_strdup_printf (_("The package \"%s\" requires \"%s\" to run.\nDownloading \"%s\" now."),
					       needed_by, pack->name, pack->name);
		} else {
			out = g_strdup_printf (_("Attempting to download package \"%s\"."), pack->name);
		}
		nautilus_label_set_text (NAUTILUS_LABEL (im->label), out);
		g_free (out);
	} else if (amount == total) {
		/* done! */
		current_progress_bar_complete (view, _("Complete"));
		gtk_progress_set_percentage (GTK_PROGRESS (im->progress_bar), 1.0);
		needed_by = g_hash_table_lookup (view->details->deps, pack->name);
		if (needed_by != NULL) {
			out = g_strdup_printf (_("The package \"%s\" requires \"%s\" to run.\n\"%s\" has been successfully downloaded."),
					       needed_by, pack->name, pack->name);
		} else {
			out = g_strdup_printf (_("The package \"%s\" has been successfully downloaded."), pack->name);
		}
		nautilus_label_set_text (NAUTILUS_LABEL (im->label), out);
		g_free (out);
		g_free (view->details->current_rpm);
		view->details->current_rpm = NULL;
		view->details->current_im = NULL;
		/* update downloaded bytes */
		view->details->download_bytes_sofar += (pack->filesize > 0 ? pack->filesize : pack->bytesize);
		gtk_progress_set_percentage (GTK_PROGRESS (view->details->total_progress_bar),
					     (float) view->details->download_bytes_sofar /
					     (float) view->details->download_bytes_total);
	} else {
		/* could be a leftover event, after user hit STOP (in which case, current_im = NULL) */
		if ((im != NULL) && (im->progress_bar != NULL)) {
			gtk_progress_set_percentage (GTK_PROGRESS (im->progress_bar),
						     (float) amount / (float) total);
			if ((amount/1024) >= view->details->last_k + 10) {
				out = g_strdup_printf (_("%dK of %dK"), amount/1024, total/1024);
				nautilus_label_set_text (NAUTILUS_LABEL (im->progress_label), out);
				g_free (out);
				view->details->last_k = (amount/1024);
			}
		}

		/* so, for PR3, we are given a "size" field in the softcat XML which is actually 
		 * the size of the decompressed files.  so this little hocus-pocus scales the
		 * actual size (which we know once we start downloading the file) to match the   
		 * previously-assumed size
		 */
		fake_amount = (float)amount * (float)(pack->filesize > 0 ? pack->filesize : pack->bytesize) / (float)total;
		gtk_progress_set_percentage (GTK_PROGRESS (view->details->total_progress_bar),
					     ((float) view->details->download_bytes_sofar + fake_amount) /
					     (float) view->details->download_bytes_total);
	}
}

/* keep this info for secret later use */
static void
nautilus_service_install_dependency_check (EazelInstallCallback *cb, const PackageData *package,
					   const PackageData *needs, NautilusServiceInstallView *view)
{
	char *key, *value;

	/* add to deps hash for later */
	if (g_hash_table_lookup_extended (view->details->deps, needs->name, (void **)&key, (void **)&value)) {
		g_hash_table_remove (view->details->deps, key);
		g_free (key);
		g_free (value);
	}
	g_hash_table_insert (view->details->deps, g_strdup (needs->name), g_strdup (package->name));

	/* this stuff flies by so fast, it's probably enough to just say "info" */
	value = g_strdup (_("Getting package information ..."));
	show_overall_feedback (view, value);
	g_free (value);
}

static void
nautilus_service_install_check_for_desktop_files (NautilusServiceInstallView *view,
						  EazelInstallCallback *cb,
						  PackageData *package)
{
	GList *iterator;

	for (iterator = package->provides; iterator; iterator = g_list_next (iterator)) {
		char *fname = (char*)(iterator->data);
		char *ptr;

		ptr = strrchr (fname, '.');
		if (ptr && ((strcmp (ptr, ".desktop") == 0) ||
			    (strcmp (ptr, ".kdelink") == 0))) {
			view->details->desktop_files = g_list_prepend (view->details->desktop_files,
								       g_strdup (fname));
		}
	}
}

/* do what gnome ought to do automatically */
static void
reply_callback (int reply, gboolean *answer)
{
	*answer = (reply == 0);
}

static void flatten_package_tree_foreach (PackageData *package, GList **flattened_list);

static void
flatten_package_tree_depends_foreach (PackageDependency *dep, GList **flattened_list)
{
	flatten_package_tree_foreach (dep->package, flattened_list);
}

static void
flatten_package_tree_foreach (PackageData *package, GList **flattened_list)
{
	if (g_list_find (*flattened_list, package) == NULL) {
		/* add it to the flattened list */
		*flattened_list = g_list_prepend (*flattened_list, package);

		g_list_foreach (package->depends, (GFunc)flatten_package_tree_depends_foreach, flattened_list);
	}
}

/* given a package tree containing possibly redundant packages, assemble a new list
 * which contains only those packages with unique <name, version>
 */
static void
flatten_package_tree (GList *package_list_in, GList **flattened_list)
{
	g_list_foreach (package_list_in, (GFunc)flatten_package_tree_foreach, flattened_list);
}

static gboolean
nautilus_service_install_preflight_check (EazelInstallCallback *cb, 
					  EazelInstallCallbackOperation op,
					  const GList *packages,
					  int total_bytes, 
					  int total_packages,
					  NautilusServiceInstallView *view)
{
	GtkWidget *dialog;
	GtkWidget *toplevel;
	GString *message;
	gboolean answer;
	PackageData *package;
	GList *package_list;
	GList *iter;
	char *out;
	char *extra;
	unsigned long total_k;

	if (view->details->cancelled) {
		/* user has already hit the cancel button */
		view->details->cancelled_before_downloads = TRUE;
		return FALSE;
	}

	/* assemble initial list of packages to browse */
	package_list = NULL;
	flatten_package_tree ((GList *)packages, &package_list);
	package_list = g_list_reverse (package_list);

	show_overall_feedback (view, _("Preparing to download packages..."));

	message = g_string_new ("");

	switch (op) {
	case EazelInstallCallbackOperation_INSTALL:
		message = g_string_append (message, 
					   _("These packages are about to be downloaded and installed:\n\n"));	
		break;
	case EazelInstallCallbackOperation_UNINSTALL:
		message = g_string_append (message, 
					   _("These packages are about to be uninstalled:\n\n"));	
		break;
	case EazelInstallCallbackOperation_REVERT:
		message = g_string_append (message, 
					   _("These packages are about to be reverted:\n\n"));	
		break;
	}


	view->details->download_bytes_total = view->details->download_bytes_sofar = 0;
	for (iter = g_list_first (package_list); iter != NULL; iter = g_list_next (iter)) {
		package = (PackageData *)(iter->data);
		out = packagedata_get_readable_name (package);
	        g_string_sprintfa (message, " \xB7 %s\n", out);
		g_free (out);
		view->details->download_bytes_total += (package->filesize > 0 ? package->filesize : package->bytesize);

		if (package->toplevel) {
			nautilus_service_install_check_for_desktop_files (view,
									  cb,
									  package);
		}
	}
	total_k = (view->details->download_bytes_total+512)/1024;
	/* arbitrary dividing line */
	if (total_k > 4096) {
		out = g_strdup_printf (_("for a total of %ld MB."), (total_k+512)/1024);
		extra = g_strdup_printf ("%ld MB", (total_k+512)/1024);
	} else {
		out = g_strdup_printf (_("for a total of %ld KB."), total_k);
		extra = g_strdup_printf ("%ld KB", total_k);
	}
	g_string_sprintfa (message, "\n%s", out);
	g_free (out);

	message = g_string_append (message, _("\nIs this okay?"));
	toplevel = gtk_widget_get_toplevel (view->details->message_box);

#if 0	/* not yet */
	nautilus_label_set_text (NAUTILUS_LABEL (view->details->package_details), message->str);
	gtk_widget_show (view->details->package_details);
#endif

	if (GTK_IS_WINDOW (toplevel)) {
		dialog = gnome_ok_cancel_dialog_parented (message->str, (GnomeReplyCallback)reply_callback,
							  &answer, GTK_WINDOW (toplevel));
	} else {
		dialog = gnome_ok_cancel_dialog (message->str, (GnomeReplyCallback)reply_callback,
						 &answer);
	}
	gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);

	gnome_dialog_run_and_close (GNOME_DIALOG (dialog));
	g_string_free (message, TRUE);

	if (!answer) {
		g_list_free (package_list);
		g_free (extra);
		view->details->cancelled = TRUE;
		view->details->cancelled_before_downloads = TRUE;
		/* EVIL EVIL hack that causes the next dialog to show up instead of being hidden */
		sleep (1);
		while (gtk_events_pending ())
			gtk_main_iteration ();
		return answer;
	}

	if (g_list_length (package_list) == 1) {
		out = g_strdup_printf (_("Downloading 1 package (%s)"), extra);
	} else {
		out = g_strdup_printf (_("Downloading %d packages (%s)"), g_list_length (package_list), extra);
	}
	show_overall_feedback (view, out);
	g_free (out);
	g_free (extra);

	g_list_free (package_list);
	view->details->current_package = 0;
	return answer;
}


static void
nautilus_service_install_download_failed (EazelInstallCallback *cb, const PackageData *pack,
					  NautilusServiceInstallView *view)
{
	char *out, *tmp;

	/* no longer "loading" anything */
	nautilus_view_report_load_complete (view->details->nautilus_view);

	tmp = packagedata_get_readable_name (pack);
	out = g_strdup_printf (_("Download of package \"%s\" failed!"), tmp);
	g_free (tmp);
	if (view->details->current_im != NULL) {
		nautilus_label_set_text (NAUTILUS_LABEL (view->details->current_im->label), out);
	}
	g_free (out);
}

static void
previous_install_finished (NautilusServiceInstallView *view)
{
	InstallMessage *im;
	char *needed_by;
	char *out;

	im = view->details->current_im;
	if (im != NULL) {
		current_progress_bar_complete (view, _("Complete"));
		gtk_progress_set_percentage (GTK_PROGRESS (im->progress_bar), 1.0);

		needed_by = g_hash_table_lookup (view->details->deps, view->details->current_rpm);
		if (needed_by != NULL) {
			out = g_strdup_printf (_("The package \"%s\" requires \"%s\" to run.\n\"%s\" has been successfully downloaded and installed."),
					       needed_by, view->details->current_rpm, view->details->current_rpm);
		} else {
			out = g_strdup_printf (_("\"%s\" has been successfully downloaded and installed."), view->details->current_rpm);
		}
		nautilus_label_set_text (NAUTILUS_LABEL (im->label), out);
		g_free (out);
	}
	g_free (view->details->current_rpm);
	view->details->current_rpm = NULL;
	view->details->current_im = NULL;
}

static void
nautilus_service_install_installing (EazelInstallCallback *cb, const PackageData *pack,
				     int current_package, int total_packages,
				     int package_progress, int package_total,
				     int total_progress, int total_total,
				     NautilusServiceInstallView *view)
{
	InstallMessage *im;
	gfloat overall_complete, complete;
	char *out;
	char *needed_by;

	im = view->details->current_im;
	if (current_package != view->details->current_package) {
		/* no longer "loading" anything */
		nautilus_view_report_load_complete (view->details->nautilus_view);

		/* starting a new package -- create new progress indicator */
		out = g_strdup_printf (_("Installing package %d of %d"), current_package, total_packages);
		show_overall_feedback (view, out);
		g_free (out);

		/* new behavior: sometimes the previous package wasn't quite closed out -- do it now */
		if (im != NULL) {
			previous_install_finished (view);
		}

		/* if you're looking for the place where we notice that one of nautilus's core
		 * packages is being upgraded, this is it.  this is an evil, evil way to do it,
		 * but nobody's come up with anything better yet.
		 */
		if (pack->name) {		
			if ((g_strncasecmp (pack->name, "nautilus", 8) == 0) ||
			    (g_strncasecmp (pack->name, "gnome-vfs", 9) == 0) ||
			    (g_strncasecmp (pack->name, "oaf", 3) == 0)) {
				view->details->core_package = TRUE;
			} 
		}

		g_free (view->details->current_rpm);
		view->details->current_rpm = g_strdup (pack->name);
		view->details->current_im = im = install_message_new (view, pack->name);
		gtk_progress_set_percentage (GTK_PROGRESS (im->progress_bar), 0.0);
		needed_by = g_hash_table_lookup (view->details->deps, pack->name);
		if (needed_by != NULL) {
			out = g_strdup_printf (_("The package \"%s\" requires \"%s\" to run.\n\"%s\" is now being installed."),
					       needed_by, pack->name, pack->name);
		} else {
			out = g_strdup_printf (_("Now installing package \"%s\"."), pack->name);
		}
		nautilus_label_set_text (NAUTILUS_LABEL (im->label), out);
		g_free (out);

		view->details->current_package = current_package;

		if (pack->toplevel) {
			update_package_info_display (view, pack, _("Installing \"%s\""));
		}
	}

	complete = (gfloat) package_progress / package_total;
	overall_complete = (gfloat) total_progress / total_total;
	gtk_progress_set_percentage (GTK_PROGRESS (im->progress_bar), complete);
	gtk_progress_set_percentage (GTK_PROGRESS (view->details->total_progress_bar), overall_complete);
	out = g_strdup_printf (_("%d%%"), (int)(complete*100.0));
	nautilus_label_set_text (NAUTILUS_LABEL (im->progress_label), out);
	g_free (out);

	if ((package_progress == package_total) && (package_total > 0)) {
		/* done with another package! */
		previous_install_finished (view);
	}
}

/* Get a description of the application pointed to by a given dentry and path fragment */
static char*
nautilus_install_service_describe_menu_entry (GnomeDesktopEntry *dentry,
                                              const char        *path_prefix,
                                              const char        *path_fragment)
{
	char *slash;
	char *addition = NULL, *addition_tmp;
	char *fragment_tmp;

	char **pieces;
	char *so_far;
	int i;
	char *dir, *file, *menu;
	GnomeDesktopEntry *dir_dentry;

	fragment_tmp = g_strdup (path_fragment);
	slash = strrchr (fragment_tmp, G_DIR_SEPARATOR);
	if (slash != NULL) {
		*slash = '\0';
	}
	pieces = g_strsplit (fragment_tmp, "/", 128); /* FIXME "/" -> G_DIR_SEPARATOR */
	g_free (fragment_tmp);
	so_far = g_strdup (path_prefix);

	for (i=0; pieces[i] != NULL; i++) {

		dir = g_strconcat (so_far, pieces[i], "/", NULL);
		file = g_strconcat (dir, ".directory", NULL);

		g_free (so_far);
		so_far = dir;

		dir_dentry = gnome_desktop_entry_load (file);
		g_free (file);

		menu = NULL;
		if (dir_dentry != NULL) {
			menu = dir_dentry->name;
		} else {
			menu = pieces[i];
		}

		if (addition == NULL) {
			addition = g_strdup_printf 
					(_(" \xB7 %s is in the Gnome menu under %s"),
					dentry->name, menu);
		} else {
			addition_tmp = g_strconcat (addition, " / ", dir_dentry->name, NULL);
			g_free (addition);
			addition = addition_tmp;
		}

		/* menu doesn't need to be freed, because it points into another structure */

		if (dir_dentry != NULL) {
			gnome_desktop_entry_free (dir_dentry);
		}
	}	
	g_free (so_far);
	g_strfreev (pieces);

	if (addition == NULL) {
		addition = g_strdup_printf (_(" \xB7 %s is in the Gnome menu.\n"), dentry->name);
	} else {
		addition_tmp = g_strconcat (addition, ".\n", NULL);
		g_free (addition);
		addition = addition_tmp;
	}

	return addition;
	
}

/* Get the toplevel menu name for the desktop file installed */
static char*
nautilus_install_service_locate_menu_entries (NautilusServiceInstallView *view) 
{
	GList *iterator;
	char *result;
	
	result = g_strdup ("");

	for (iterator = view->details->desktop_files; iterator; iterator = g_list_next (iterator)) {
		char *fname = (char*)(iterator->data);
		char *addition = NULL;
		char *tmp;
		GnomeDesktopEntry *dentry = gnome_desktop_entry_load (fname);

		if (dentry->is_kde) {
			addition = g_strdup_printf (_(" \xB7 %s is in the KDE menu.\n"), dentry->name);
		} else {
			/* match desktop files against a set of paths that the panel is known to
			 * put in the menu. */
			char *desktop_prefixes[] = {
				"/gnome/apps/",
				"/applnk/"
			};
			int num_prefixes = 2;
			int i;

			for (i=0; i<num_prefixes; i++) {
				char *gnomeapp = desktop_prefixes[i];
				char *apps_ptr = strstr (fname, gnomeapp);
				if (apps_ptr) {
					char *full_prefix = g_strndup (fname, (apps_ptr)-fname + 
							strlen (gnomeapp));
					addition = nautilus_install_service_describe_menu_entry
							(dentry, full_prefix, apps_ptr+strlen (gnomeapp));
					g_free (full_prefix);
					if (addition != NULL) {
						break;
					}
				}
			}
		}
		if (addition) {
			tmp = g_strdup_printf ("%s%s", result, addition);
			g_free (result);
			result = tmp;
			g_free (addition);
		}
		gnome_desktop_entry_free (dentry);
	}
	return result;
}

/* most likely OBSOLETE */
static gboolean
nautilus_service_install_solve_cases (NautilusServiceInstallView *view)
{
	gboolean answer = FALSE;
	GtkWidget *toplevel;
	GString *messages;
	GList *strings;
	GtkWidget *dialog;

	messages = g_string_new ("");

	if (view->details->problem_cases) {
		GList *iterator;
		/* Create string versions to show the user */
		g_string_sprintfa (messages, "%s\n%s\n\n", 
				   _("I ran into problems while installing."), 
				   _("I'd like to try the following :"));
		strings = eazel_install_problem_cases_to_string (view->details->problem,
								 view->details->problem_cases);
		for (iterator = strings; iterator; iterator = g_list_next (iterator)) {
			g_string_sprintfa (messages, " \xB7 %s\n", (char*)(iterator->data));
		}
		g_list_foreach (strings, (GFunc)g_free, NULL);
		g_list_free (strings);
		g_string_sprintfa (messages, "\n%s",  
				   _("Is this ok ?"));
		
		toplevel = gtk_widget_get_toplevel (view->details->message_box);
		if (GTK_IS_WINDOW (toplevel)) {
			dialog = gnome_question_dialog_parented (messages->str, (GnomeReplyCallback)reply_callback,
								 &answer, GTK_WINDOW (toplevel));
		} else {
			dialog = gnome_question_dialog (messages->str, (GnomeReplyCallback)reply_callback, &answer);
		}
		gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
		gnome_dialog_run_and_close (GNOME_DIALOG (dialog));
		g_string_free (messages, TRUE);
	}

	return answer;
}

static void
nautilus_service_install_done (EazelInstallCallback *cb, gboolean success, NautilusServiceInstallView *view)
{
	CORBA_Environment ev;
	GtkWidget *toplevel;
	GtkWidget *dialog;
	char *message;
	char *name;
	GString *real_message;
	gboolean answer = FALSE;
	gboolean question_dialog;
	GList *packlist, *iter;
	PackageData *pack;

	g_assert (NAUTILUS_IS_SERVICE_INSTALL_VIEW (view));

	/* 'success' will be FALSE if even *one* package failed.  need to check for that. */

	packlist = ((CategoryData *) view->details->categories->data)->packages;

#if 1
	for (iter = g_list_first (packlist); iter != NULL; iter = g_list_next (iter)) {
		pack = PACKAGEDATA (iter->data);
		trilobite_debug ("package %s status %d", pack->name, pack->status);
	}
#endif

	/* no longer "loading" anything */
	nautilus_view_report_load_complete (view->details->nautilus_view);

	gtk_progress_set_percentage (GTK_PROGRESS (view->details->total_progress_bar), success ? 1.0 : 0.0);

	g_free (view->details->current_rpm);
	view->details->current_rpm = NULL;

	if (view->details->cancelled) {
		message = _("Installation aborted.");
	} else if (view->details->already_installed) {
		message = _("This package has already been installed.");
	} else if (success) {
		message = _("Installation complete.");
	} else {
		/* FIXME 5906: this isn't really working right yet, so fix it later */
		if (1 || ((guint) view->details->failures == g_list_length (packlist))) {
			message = _("Installation failed.");
			answer = nautilus_service_install_solve_cases (view);
		} else {
			/* some succeeded; some failed */
			real_message = g_string_new (_("Some packages installed successfully:"));
			for (iter = g_list_first (packlist); iter != NULL; iter = g_list_next (iter)) {
				pack = PACKAGEDATA (iter->data);
				if (pack->status == PACKAGE_RESOLVED) {
					name = packagedata_get_readable_name (pack);
					g_string_sprintfa (real_message, "\n  \xB7 %s", name);
					g_free (name);
				}
			}
			g_string_sprintfa (real_message, _("\nSome packages failed:"));
			for (iter = g_list_first (packlist); iter != NULL; iter = g_list_next (iter)) {
				pack = PACKAGEDATA (iter->data);
				if (pack->status != PACKAGE_RESOLVED) {
					name = packagedata_get_readable_name (pack);
					g_string_sprintfa (real_message, "\n  \xB7 %s", name);
					g_free (name);
				}
			}

			message = real_message->str;
			g_string_free (real_message, FALSE);
			answer = nautilus_service_install_solve_cases (view);
		}
	}

	show_overall_feedback (view, message);

	if (answer) {
		eazel_install_problem_handle_cases (view->details->problem, 
						    view->details->installer, 
						    &(view->details->problem_cases), 
						    &(view->details->categories),
						    NULL,
						    NULL);
	} else {
		real_message = g_string_new (message);
		question_dialog = TRUE;
		answer = FALSE;

		if (success && view->details->desktop_files &&
		    !view->details->cancelled &&
		    !view->details->already_installed) {
			g_string_sprintfa (real_message, "\n%s", nautilus_install_service_locate_menu_entries (view));
		}
		if (view->details->cancelled_before_downloads ||
		    view->details->already_installed ||
		    (nautilus_preferences_get_user_level () < NAUTILUS_USER_LEVEL_ADVANCED)) {
			/* don't ask about erasing rpms */
			question_dialog = FALSE;
			answer = TRUE;
		} else if (view->details->downloaded_anything) {
			if (view->details->cancelled || view->details->failures) {
				g_string_sprintfa (real_message, "\n%s", _("Erase the RPM files?"));
			} else {
				g_string_sprintfa (real_message, "\n%s", _("Erase the leftover RPM files?"));
			}
		} else {
			question_dialog = FALSE;
		}

		toplevel = gtk_widget_get_toplevel (view->details->message_box);
		if (GTK_IS_WINDOW (toplevel)) {
			if (question_dialog) {
				dialog = gnome_question_dialog_parented (real_message->str,
									 (GnomeReplyCallback)reply_callback,
									 &answer, GTK_WINDOW (toplevel));
			} else {
				dialog = gnome_ok_dialog_parented (real_message->str, GTK_WINDOW (toplevel));
			}
		} else {
			if (question_dialog) {
				dialog = gnome_question_dialog (real_message->str,
								(GnomeReplyCallback)reply_callback, &answer);
			} else {
				dialog = gnome_ok_dialog (real_message->str);
			}
		}
		gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
		gnome_dialog_run_and_close (GNOME_DIALOG (dialog));
		g_string_free (real_message, TRUE);

		if (answer) {
			CORBA_exception_init (&ev);
			eazel_install_callback_delete_files (cb, &ev);
			CORBA_exception_free (&ev);
		}
		
		if (success && view->details->core_package) {
			message = _("A core package of Nautilus has been\n"
				    "updated.  You should restart Nautilus.\n\n"
				    "Do you wish to do that now?");
			if (GTK_IS_WINDOW (toplevel)) {
				dialog = gnome_question_dialog_parented (message,
									 (GnomeReplyCallback)reply_callback,
									 &answer, GTK_WINDOW (toplevel));
			} else {
				dialog = gnome_question_dialog (message, (GnomeReplyCallback)reply_callback,
								&answer);
			}
			gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
			gnome_dialog_run_and_close (GNOME_DIALOG (dialog));
			
			if (answer) {
				if (execlp ("nautilus", "nautilus", "--restart", NULL) < 0) {
					g_message ("Exec error %s", strerror (errno));
				}
			}
		}

		/* send them to the predetermined "next" url
		 * -- but only if they haven't set jump-after-install off
		 */
		if ((view->details->username != NULL) &&
		    (strcasecmp (view->details->username, EAZELPROXY_USERNAME_ANONYMOUS) == 0)) {
			/* send anonymous users elsewhere, so they won't have to login */
			message = g_strdup (NEXT_URL_ANONYMOUS);
		} else {
			message = g_strdup (NEXT_URL);
		}
		message = NULL;
		if (eazel_install_configure_check_jump_after_install (&message)) {
			if (message != NULL) {
				nautilus_view_open_location_in_this_window (view->details->nautilus_view, message);
			} else {
				g_warning ("attemping to go back");
				nautilus_view_go_back (view->details->nautilus_view);
			}
		}
		g_free (message);
	}
}

static void
nautilus_service_install_failed (EazelInstallCallback *cb, const PackageData *package, NautilusServiceInstallView *view)
{
	char *tmp, *message;

	g_assert (NAUTILUS_IS_SERVICE_INSTALL_VIEW (view));

	if (package->status == PACKAGE_ALREADY_INSTALLED) {
		view->details->already_installed = TRUE;
		return;
	}

	/* override the "success" result for install_done signal */
	view->details->failures++;

	tmp = packagedata_get_readable_name (package);
	message = g_strdup_printf (_("Installation failed on %s"), tmp);
	show_overall_feedback (view, message);
	g_free (tmp);
	g_free (message);

	/* Get the new set of problem cases */
	eazel_install_problem_tree_to_case (view->details->problem,
					    package,
					    FALSE,
					    &(view->details->problem_cases));
}

/* signal callback -- ask the user for the root password (for installs) */
static char *
nautilus_service_need_password (GtkObject *object, const char *prompt, NautilusServiceInstallView *view)
{
	char *message = NULL;
	GtkWidget *dialog;
	gboolean okay;
	char *out;

	if (view->details->remembered_password) {
		return g_strdup (view->details->remembered_password);
	}

	if (view->details->password_attempts > 0) {
		message = g_strdup_printf ("%s\n \n%s", PASSWORD_PROMPT, _("Incorrect password."));
	} else {
		message = g_strdup (PASSWORD_PROMPT);
	}

	dialog = nautilus_password_dialog_new (_("Authenticate as root"), message, prompt, "", TRUE);
	okay = nautilus_password_dialog_run_and_block (NAUTILUS_PASSWORD_DIALOG (dialog));

	if (! okay) {
		/* cancel */
		view->details->password_attempts = 0;
		view->details->cancelled = TRUE;
		out = g_strdup ("");
	} else {
		out = nautilus_password_dialog_get_password (NAUTILUS_PASSWORD_DIALOG (dialog));
		if (nautilus_password_dialog_get_remember (NAUTILUS_PASSWORD_DIALOG (dialog))) {
			view->details->remembered_password = g_strdup (out);
		}
	}

	gtk_widget_destroy (dialog);

	if (okay) {
		view->details->password_attempts++;
	}

	g_free (message);

	return out;
}

/* bad password -- let em try again? */
static gboolean
nautilus_service_try_again (GtkObject *object, NautilusServiceInstallView *view)
{
	if (view->details->password_attempts == 0) {
		/* user hit "cancel" */
		return FALSE;
	}

	/* a wrong password shouldn't be remembered :) */
	g_free (view->details->remembered_password);
	view->details->remembered_password = NULL;

	if (view->details->password_attempts >= 3) {
		/* give up. */
		view->details->password_attempts = 0;
		return FALSE;
	}
	return TRUE;
}

static TrilobiteRootClient *
set_root_client (BonoboObjectClient *service, NautilusServiceInstallView *view)
{
	TrilobiteRootClient *root_client = NULL;
	CORBA_Environment ev;

	CORBA_exception_init (&ev);

	if (bonobo_object_client_has_interface (service, "IDL:Trilobite/PasswordQuery:1.0", &ev)) {
		root_client = trilobite_root_client_new ();
		if (! trilobite_root_client_attach (root_client, service)) {
			g_warning ("unable to attach root client to Trilobite/PasswordQuery!");
		}

		gtk_signal_connect (GTK_OBJECT (root_client), "need_password",
				    GTK_SIGNAL_FUNC (nautilus_service_need_password),
				    view);
		gtk_signal_connect (GTK_OBJECT (root_client), "try_again",
				    GTK_SIGNAL_FUNC (nautilus_service_try_again),
				    view);
	} else {
		g_warning ("Object does not support IDL:Trilobite/PasswordQuery:1.0");
	}

	CORBA_exception_free (&ev);
	return root_client;
}


static void
nautilus_service_install_view_update_from_uri_finish (NautilusServiceInstallView *view, const char *uri)
{
	PackageData		*pack;
	CategoryData		*category_data;
	char			*host;
	int			port;
	GNOME_Trilobite_Eazel_Install	service;
	CORBA_Environment	ev;
	char 			*out, *p;
	gboolean                set_auth;

	/* get default host/port */
	host = g_strdup (trilobite_get_services_address ());
	p = strchr (host, ':');
	if (p != NULL) {
		*p = 0;
		port = atoi (p+1);
	} else {
		port = 80;
	}

	set_auth = !(nautilus_install_parse_uri (uri, view, &host, &port, &view->details->username));

	if (! view->details->categories) {
		return;
	}

	/* NOTE: This adds a libeazelinstall packagedata object to the view */
	pack = (PackageData*) gtk_object_get_data (GTK_OBJECT (view), "packagedata");
	if (pack != NULL) {
		/* Destroy the old */
		gtk_object_unref (GTK_OBJECT (pack));
	}

	/* find the package data for the package we're about to install */
	category_data = (CategoryData *) view->details->categories->data;
	pack = (PackageData *) category_data->packages->data;

	gtk_object_set_data (GTK_OBJECT (view), "packagedata", pack);

	if (g_list_length (category_data->packages) > 1) {
		out = g_strdup_printf (_("Downloading packages"));
	} else if ((pack->eazel_id != NULL) || (pack->suite_id != NULL)) {
		out = g_strdup_printf (_("Downloading remote package"));
	} else if (pack->name != NULL) {
		out = g_strdup_printf (_("Downloading \"%s\""), pack->name);
	} else {
		out = g_strdup_printf (_("Downloading some package"));
	}
	nautilus_label_set_text (NAUTILUS_LABEL (view->details->package_name), out);
	g_free (out);

	CORBA_exception_init (&ev);
	if (view->details->installer) {
		eazel_install_callback_unref (GTK_OBJECT (view->details->installer));
	}
	view->details->installer = eazel_install_callback_new ();
	if (view->details->installer == NULL) {
		GtkWidget *toplevel, *dialog;
		char *message;

		nautilus_view_report_load_complete (view->details->nautilus_view);
		gtk_widget_hide (view->details->form);

		message = g_strdup (_("The Eazel install service is missing:\nInstalls will not work."));
		toplevel = gtk_widget_get_toplevel (view->details->message_box);
		if (GTK_IS_WINDOW (toplevel)) {
			dialog = gnome_error_dialog_parented (message, GTK_WINDOW (toplevel));
		} else {
			dialog = gnome_error_dialog (message);
		}
		gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
		gnome_dialog_run_and_close (GNOME_DIALOG (dialog));
		return;
	}

	view->details->problem = eazel_install_problem_new ();
	view->details->root_client = set_root_client (eazel_install_callback_bonobo (view->details->installer), view);
	service = eazel_install_callback_corba_objref (view->details->installer);
	GNOME_Trilobite_Eazel_Install__set_protocol (service, GNOME_Trilobite_Eazel_PROTOCOL_HTTP, &ev);
	GNOME_Trilobite_Eazel_Install__set_server (service, host, &ev);
	GNOME_Trilobite_Eazel_Install__set_server_port (service, port, &ev);
	GNOME_Trilobite_Eazel_Install__set_auth (service, set_auth, &ev);

	if (view->details->username != NULL) {
		GNOME_Trilobite_Eazel_Install__set_username (service, view->details->username, &ev);
	}
	GNOME_Trilobite_Eazel_Install__set_test_mode (service, FALSE, &ev);

	gtk_signal_connect (GTK_OBJECT (view->details->installer), "file_conflict_check",
			    GTK_SIGNAL_FUNC (nautilus_service_install_conflict_check), view);
	gtk_signal_connect (GTK_OBJECT (view->details->installer), "download_progress",
			    GTK_SIGNAL_FUNC (nautilus_service_install_downloading), view);
	gtk_signal_connect (GTK_OBJECT (view->details->installer), "download_failed",
			    nautilus_service_install_download_failed, view);
	gtk_signal_connect (GTK_OBJECT (view->details->installer), "dependency_check",
			    nautilus_service_install_dependency_check, view);
	gtk_signal_connect (GTK_OBJECT (view->details->installer), "preflight_check",
			    GTK_SIGNAL_FUNC (nautilus_service_install_preflight_check), view);
	gtk_signal_connect (GTK_OBJECT (view->details->installer), "install_progress",
			    nautilus_service_install_installing, view);
	gtk_signal_connect (GTK_OBJECT (view->details->installer), "install_failed",
			    nautilus_service_install_failed, view);
	gtk_signal_connect (GTK_OBJECT (view->details->installer), "done",
			    nautilus_service_install_done, view);
	eazel_install_callback_install_packages (view->details->installer, 
						 view->details->categories, 
						 NULL, &ev);

	CORBA_exception_free (&ev);

	show_overall_feedback (view, _("Contacting the Eazel Software Catalog ..."));

	/* might take a while (leave the throbber on) */
}

static void /* AmmonitePromptLoginCb */
user_login_callback (
	gpointer user_data, 
	const EazelProxy_User *user, 
	const EazelProxy_AuthnFailInfo *fail_info,
	AmmoniteDialogButton button_pressed)
{
	NautilusServiceInstallView *view;

	view = NAUTILUS_SERVICE_INSTALL_VIEW (user_data);

	/* if the view has been destroyed while the callback was gone, just drop everything */
	if (!GTK_OBJECT_DESTROYED (GTK_OBJECT(view))) {
		if (fail_info == NULL) {
			/* login succeeded */
			nautilus_service_install_view_update_from_uri_finish (view, view->details->uri);
		} else {
			if (button_pressed == AMMONITE_BUTTON_REGISTER) {
				nautilus_view_open_location_in_this_window (
					view->details->nautilus_view, 
					EAZEL_ACCOUNT_REGISTER_URI);
			} else if (button_pressed == AMMONITE_BUTTON_FORGOT) {
				nautilus_view_open_location_in_this_window (
					view->details->nautilus_view, 
					EAZEL_ACCOUNT_FORGOTPW_URI);
			} else {
				nautilus_view_open_location_in_this_window (
					view->details->nautilus_view, 
					NEXT_URL_ANONYMOUS);
			}
		}
	}

	gtk_object_unref (GTK_OBJECT(view));
}

static void
nautilus_service_install_view_update_from_uri (NautilusServiceInstallView *view, const char *uri)
{
	char *host;
	int port;

	host = NULL;

	nautilus_install_parse_uri (uri, view, &host, &port, &view->details->username);

	if (host == NULL) {
		/* Ensure that the user is logged in.  Note that the "anonymous" user
		 * will not be prompted
		 */

		gtk_object_ref (GTK_OBJECT(view));

		show_overall_feedback (view, _("Checking for authorization..."));

		/* Cancel a pending login request, if there was one...*/
		ammonite_prompt_login_async_cancel (user_login_callback);
		ammonite_do_prompt_login_async (view->details->username, NULL, NULL, view->details->username == NULL ? TRUE: FALSE, view, user_login_callback);
	} else {
		nautilus_service_install_view_update_from_uri_finish (view, uri);
	}

	g_free (host);
	host = NULL;
}

void
nautilus_service_install_view_load_uri (NautilusServiceInstallView	*view,
			     	        const char			*uri)
{
	/* dispose of any old uri and copy in the new one */	
	g_free (view->details->uri);
	view->details->uri = g_strdup (uri);

	/* dispose of any old form that was installed */
	if (view->details->form != NULL) {
		gtk_widget_destroy (view->details->form);
		view->details->form = NULL;
	}
	if (view->details->message) {
		g_list_foreach (view->details->message, (GFunc)install_message_destroy, NULL);
		g_list_free (view->details->message);
		view->details->message = NULL;
	}
	if (view->details->desktop_files) {
		g_list_foreach (view->details->desktop_files, (GFunc)g_free, NULL);
		g_list_free (view->details->desktop_files);
		view->details->desktop_files = NULL;
	}

	/* clear some variables */
	view->details->already_installed = FALSE;
	view->details->cancelled = FALSE;
	view->details->failures = 0;
	view->details->downloaded_anything = FALSE;

	generate_install_form (view);

	nautilus_view_report_load_underway (NAUTILUS_VIEW (view->details->nautilus_view));

	nautilus_service_install_view_update_from_uri (view, uri);
}

static void
service_install_load_location_callback (NautilusView			*nautilus_view, 
			  	        const char			*location,
			       		NautilusServiceInstallView	*view)
{

	g_assert (nautilus_view == view->details->nautilus_view);
	
	nautilus_view_report_load_underway (nautilus_view);
	
	nautilus_service_install_view_load_uri (view, location);
}

static void
service_install_stop_loading_callback (NautilusView *nautilus_view, NautilusServiceInstallView *view)
{
	GNOME_Trilobite_Eazel_Install service;
	CORBA_Environment ev;
	int i;

	view->details->cancelled = TRUE;
	show_overall_feedback (view, _("Aborting package downloads (please wait) ..."));
	/* on a fast download, the GUI could get stuck here, constantly updating the download progress */
	for (i = 0; i < 10; i++) {
		if (gtk_events_pending ()) {
			gtk_main_iteration ();
		} else {
			i = 11;
		}
	}
	/* have to set these up here, because if they hit STOP before any downloads have started, the
	 * call to _stop below will freeze until we get the preflight signal later.
	 */

	g_assert (nautilus_view == view->details->nautilus_view);

	CORBA_exception_init (&ev);
	service = eazel_install_callback_corba_objref (view->details->installer);
	GNOME_Trilobite_Eazel_Install_stop (service, &ev);
	CORBA_exception_free (&ev);

	show_overall_feedback (view, _("Package download aborted."));
	current_progress_bar_complete (view, _("Aborted"));
}