2
// AddinInstallDialog.cs
7
// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
9
// Permission is hereby granted, free of charge, to any person obtaining
10
// a copy of this software and associated documentation files (the
11
// "Software"), to deal in the Software without restriction, including
12
// without limitation the rights to use, copy, modify, merge, publish,
13
// distribute, sublicense, and/or sell copies of the Software, and to
14
// permit persons to whom the Software is furnished to do so, subject to
15
// the following conditions:
17
// The above copyright notice and this permission notice shall be
18
// included in all copies or substantial portions of the Software.
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32
using System.Threading;
33
using System.Collections;
34
using System.Collections.Specialized;
35
using System.Diagnostics;
40
using Mono.Addins.Setup;
41
using Mono.Addins.Description;
43
namespace Mono.Addins.Gui
45
partial class AddinInstallDialog : Dialog
51
PackageCollection packagesToInstall;
54
InstallMonitor installMonitor;
58
public AddinInstallDialog (SetupService service)
61
this.service = service;
62
wizardNotebook.ShowTabs = false;
65
tree = new InstallAddinTreeWidget (addinTree);
66
tree.AllowSelection = true;
67
tree.SelectionChanged += new EventHandler (OnAddinSelectionChanged);
69
repoStore = new ListStore (typeof(string), typeof(string));
70
repoCombo.Model = repoStore;
71
CellRendererText crt = new CellRendererText ();
72
repoCombo.PackStart (crt, true);
73
repoCombo.AddAttribute (crt, "text", 0);
74
filterComboBox.Active = 1;
76
imageInstall.Stock = "md-software-update";
77
imageInstall.IconSize = (int)IconSize.Dialog;
86
public override void Dispose ()
94
int i = repoCombo.Active;
97
repoStore.AppendValues (Catalog.GetString ("All registered repositories"), "");
99
foreach (AddinRepository rep in service.Repositories.GetRepositories ()) {
100
repoStore.AppendValues (rep.Title, rep.Url);
102
repoCombo.Active = i;
107
object s = tree.SaveStatus ();
112
if (!repoCombo.GetActiveIter (out iter))
115
bool showUpdates = filterComboBox.Active >= 1;
116
bool showNotInstalled = filterComboBox.Active <= 1;
118
string rep = (string) repoStore.GetValue (iter, 1);
120
AddinRepositoryEntry[] reps;
122
reps = service.Repositories.GetAvailableAddins ();
124
reps = service.Repositories.GetAvailableAddins (rep);
126
foreach (AddinRepositoryEntry arep in reps)
128
if (!Services.InApplicationNamespace (service, arep.Addin.Id))
131
// Find whatever version is installed
132
Addin sinfo = AddinManager.Registry.GetAddin (Addin.GetIdName (arep.Addin.Id));
135
if (showNotInstalled)
136
tree.AddAddin (arep.Addin, arep, true);
140
if (showUpdates && Addin.CompareVersions (sinfo.Version, arep.Addin.Version) <= 0)
143
tree.AddAddin (arep.Addin, arep, true);
147
// Only show the select all button when "Show updates only" is selected
148
btnSelectAll.Visible = filterComboBox.Active == 2;
149
btnUnselectAll.Visible = filterComboBox.Active == 2;
151
tree.RestoreStatus (s);
154
void OnAddinSelectionChanged (object o, EventArgs e)
156
UpdateAddinSelection ();
159
void UpdateAddinSelection ()
161
btnNext.Sensitive = (tree.GetSelectedAddins().Length != 0);
164
protected void OnActiveAddinChanged (object o, EventArgs e)
169
protected void OnNextPage (object sender, EventArgs e)
171
wizardNotebook.NextPage ();
175
protected void OnPrevPage (object sender, EventArgs e)
177
wizardNotebook.PrevPage ();
181
protected void OnCancel (object sender, EventArgs e)
184
if (Services.AskQuestion (Catalog.GetString ("Are you sure you want to cancel the installation?")))
185
installMonitor.Cancel ();
187
Respond (ResponseType.Cancel);
190
protected void OnOk (object sender, EventArgs e)
192
Respond (ResponseType.Ok);
195
protected void OnManageSites (object sender, EventArgs e)
197
ManageSitesDialog dlg = new ManageSitesDialog (service);
198
dlg.TransientFor = this;
210
protected void OnUpdateRepo (object sender, EventArgs e)
212
Thread t = new Thread (new ThreadStart (RunUpdate));
215
while (!updateDone) {
216
while (Gtk.Application.EventsPending ())
217
Gtk.Application.RunIteration ();
226
service.Repositories.UpdateAllRepositories (null);
232
protected void OnRepoChanged (object sender, EventArgs e)
237
public void OnPageChanged ()
239
switch (wizardNotebook.CurrentPage) {
241
btnPrev.Sensitive = false;
242
btnNext.Sensitive = (tree.GetSelectedAddins().Length != 0);
259
protected void OnGotoWeb (object sender, EventArgs e)
261
AddinHeader info = tree.ActiveAddin;
266
Process.Start (info.Url);
269
protected void OnShowInfo (object sender, EventArgs e)
271
AddinHeader info = tree.ActiveAddin;
275
AddinInfoDialog dlg = new AddinInfoDialog (info);
283
protected void OnFilterChanged (object sender, EventArgs e)
286
UpdateAddinSelection ();
289
protected void OnSelectAll (object sender, EventArgs e)
294
protected void OnUnselectAll (object sender, EventArgs e)
299
public void SetUninstallMode (AddinHeader info)
302
btnNext.Sensitive = true;
304
uninstallId = info.Id;
305
wizardNotebook.CurrentPage = 1;
307
StringBuilder sb = new StringBuilder ();
308
sb.Append ("<b>").Append (Catalog.GetString ("The following packages will be uninstalled:")).Append ("</b>\n\n");
309
sb.Append (info.Name + "\n\n");
311
Addin[] sinfos = service.GetDependentAddins (info.Id, true);
312
if (sinfos.Length > 0) {
313
sb.Append ("<b>").Append (Catalog.GetString ("There are other extensions that depend on the previous ones which will also be uninstalled:")).Append ("</b>\n\n");
314
foreach (Addin si in sinfos)
315
sb.Append (si.Description.Name + "\n");
318
labelSummary.Markup = sb.ToString ();
321
void FillAddinInfo ()
323
AddinHeader info = tree.ActiveAddin;
324
btnInfo.Sensitive = info != null;
326
/* if (info == null) {
327
infoLabel.Markup = "";
328
linkLabel.Visible = false;
332
StringBuilder sb = new StringBuilder ();
333
sb.Append ("<b><big>" + info.Name + "</big></b>\n\n");
335
if (info.Description != "")
336
sb.Append (info.Description + "\n\n");
338
sb.Append ("<small>");
340
sb.Append ("<b>").Append (Catalog.GetString ("Version:")).Append ("</b>\n").Append (info.Version).Append ("\n\n");
342
if (info.Author != "")
343
sb.Append ("<b>").Append (Catalog.GetString ("Author:")).Append ("</b>\n").Append (info.Author).Append ("\n\n");
345
if (info.Copyright != "")
346
sb.Append ("<b>").Append (Catalog.GetString ("Copyright:")).Append ("</b>\n").Append (info.Copyright).Append ("\n\n");
348
if (info.Dependencies.Count > 0) {
349
sb.Append ("<b>").Append (Catalog.GetString ("Extension Dependencies:")).Append ("</b>\n");
350
foreach (PackageDependency dep in info.Dependencies)
351
sb.Append (dep.Name + "\n");
354
sb.Append ("</small>");
356
linkLabel.Visible = info.Url != "";
358
infoLabel.Markup = sb.ToString ();*/
362
void FillSummaryPage ()
364
btnPrev.Sensitive = true;
366
AddinHeader[] infos = tree.GetSelectedAddins ();
367
PackageCollection packs = new PackageCollection ();
368
foreach (AddinHeader info in infos) {
369
AddinRepositoryEntry arep = (AddinRepositoryEntry) tree.GetAddinData (info);
370
packs.Add (Package.FromRepository (arep));
373
packagesToInstall = new PackageCollection (packs);
375
PackageCollection toUninstall;
376
DependencyCollection unresolved;
379
InstallMonitor m = new InstallMonitor ();
380
res = service.ResolveDependencies (m, packs, out toUninstall, out unresolved);
382
StringBuilder sb = new StringBuilder ();
384
sb.Append ("<b><span foreground=\"red\">").Append (Catalog.GetString ("The selected extensions can't be installed because there are dependency conflicts.")).Append ("</span></b>\n");
385
foreach (string s in m.Errors) {
386
sb.Append ("<b><span foreground=\"red\">" + s + "</span></b>\n");
391
if (m.Warnings.Count != 0) {
392
foreach (string w in m.Warnings) {
393
sb.Append ("<b><span foreground=\"red\">" + w + "</span></b>\n");
398
sb.Append ("<b>").Append (Catalog.GetString ("The following packages will be installed:")).Append ("</b>\n\n");
399
foreach (Package p in packs) {
401
if (!p.SharedInstall)
402
sb.Append (Catalog.GetString (" (in user directory)"));
407
if (toUninstall.Count > 0) {
408
sb.Append ("<b>").Append (Catalog.GetString ("The following packages need to be uninstalled:")).Append ("</b>\n\n");
409
foreach (Package p in toUninstall) {
410
sb.Append (p.Name + "\n");
415
if (unresolved.Count > 0) {
416
sb.Append ("<b>").Append (Catalog.GetString ("The following dependencies could not be resolved:")).Append ("</b>\n\n");
417
foreach (Dependency p in unresolved) {
418
sb.Append (p.Name + "\n");
422
btnNext.Sensitive = res;
423
labelSummary.Markup = sb.ToString ();
428
btnPrev.Sensitive = false;
429
btnNext.Sensitive = false;
436
installMonitor = new InstallMonitor (progressLabel, progressBar, mainProgressBar);
439
if (uninstallId == null) {
440
oper = new ThreadStart (RunInstall);
441
okmessage = Catalog.GetString ("The installation has been successfully completed.");
442
errmessage = Catalog.GetString ("The installation failed!");
443
warnmessage = Catalog.GetString ("The installation has completed with warnings.");
445
oper = new ThreadStart (RunUninstall);
446
okmessage = Catalog.GetString ("The uninstallation has been successfully completed.");
447
errmessage = Catalog.GetString ("The uninstallation failed!");
448
warnmessage = Catalog.GetString ("The uninstallation has completed with warnings.");
451
Thread t = new Thread (oper);
455
installMonitor.WaitForCompleted ();
458
wizardNotebook.NextPage ();
460
if (installMonitor.Success && installMonitor.Warnings.Count == 0) {
461
imageWarn.Visible = false;
462
imageError.Visible = false;
463
imageInfo.Visible = true;
464
txt = "<b>" + okmessage + "</b>\n\n";
465
} else if (installMonitor.Success) {
466
imageWarn.Visible = true;
467
imageInfo.Visible = false;
468
imageError.Visible = false;
469
txt = "<b>" + warnmessage + "</b>\n\n";
470
foreach (string s in installMonitor.Warnings)
471
txt += GLib.Markup.EscapeText (s) + "\n";
473
imageWarn.Visible = false;
474
imageInfo.Visible = false;
475
imageError.Visible = true;
476
txt = "<span foreground=\"red\"><b>" + errmessage + "</b></span>\n\n";
477
foreach (string s in installMonitor.Errors)
478
txt += GLib.Markup.EscapeText (s) + "\n";
481
labelResult.Markup = txt;
488
service.Install (installMonitor, packagesToInstall);
492
installMonitor.Dispose ();
499
service.Uninstall (installMonitor, uninstallId);
503
installMonitor.Dispose ();
508
class InstallMonitor: IProgressStatus, IDisposable
511
ProgressBar progressBar;
512
ProgressBar mainProgressBar;
513
StringCollection errors = new StringCollection ();
514
StringCollection warnings = new StringCollection ();
518
public InstallMonitor (Label progressLabel, ProgressBar progressBar, ProgressBar mainProgressBar)
520
this.progressLabel = progressLabel;
521
this.progressBar = progressBar;
522
this.mainProgressBar = mainProgressBar;
525
public InstallMonitor ()
529
public void SetMessage (string msg)
531
if (progressLabel != null)
532
progressLabel.Text = msg;
535
public void SetProgress (double progress)
537
if (mainProgressBar != null)
538
mainProgressBar.Fraction = progress;
539
if (progressBar != null)
540
progressBar.Fraction = progress;
543
public void Log (string msg)
545
Console.WriteLine (msg);
548
public void ReportWarning (string message)
550
warnings.Add (message);
553
public void ReportError (string message, Exception exception)
555
errors.Add (message);
558
public bool IsCanceled {
559
get { return canceled; }
562
public StringCollection Errors {
563
get { return errors; }
566
public StringCollection Warnings {
567
get { return warnings; }
570
public void Cancel ()
575
public int LogLevel {
579
public void Dispose ()
584
public void WaitForCompleted ()
587
while (Gtk.Application.EventsPending ())
588
Gtk.Application.RunIteration ();
593
public bool Success {
594
get { return errors.Count == 0; }
598
class InstallAddinTreeWidget: AddinTreeWidget
601
public InstallAddinTreeWidget (Gtk.TreeView treeView): base (treeView)
605
protected override void AddStoreTypes (ArrayList list)
607
base.AddStoreTypes (list);
609
list.Add (typeof(string));
612
protected override void CreateColumns ()
614
base.CreateColumns ();
615
TreeViewColumn col = new TreeViewColumn ();
616
col.Title = Catalog.GetString ("Repository");
617
CellRendererText crt = new CellRendererText ();
618
col.PackStart (crt, true);
619
col.AddAttribute (crt, "text", ncol);
620
treeView.AppendColumn (col);
623
protected override void UpdateRow (TreeIter iter, AddinHeader info, object dataItem, bool enabled, Gdk.Pixbuf icon)
625
base.UpdateRow (iter, info, dataItem, enabled, icon);
626
AddinRepositoryEntry arep = (AddinRepositoryEntry) dataItem;
627
treeStore.SetValue (iter, ncol, arep.RepositoryName);