5
// Lluis Sanchez Gual <lluis@novell.com>
7
// Copyright (c) 2011 Novell, Inc (http://www.novell.com)
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27
using Mono.Addins.Setup;
28
using Mono.Addins.Description;
31
using System.Threading;
33
using System.Collections.Generic;
35
namespace Mono.Addins.Gui
37
internal partial class InstallDialog : Gtk.Dialog
39
string[] filesToInstall;
40
AddinRepositoryEntry[] addinsToInstall;
41
PackageCollection packagesToInstall;
43
Gtk.ResponseType response = Gtk.ResponseType.None;
44
IEnumerable<string> uninstallIds;
45
InstallMonitor installMonitor;
47
const int MaxHeight = 350;
49
public InstallDialog (Gtk.Window parent, SetupService service)
52
this.service = service;
53
TransientFor = parent;
54
WindowPosition = Gtk.WindowPosition.CenterOnParent;
55
Services.PlaceDialog (this, parent);
56
boxProgress.Visible = false;
60
public void InitForInstall (AddinRepositoryEntry[] addinsToInstall)
62
this.addinsToInstall = addinsToInstall;
64
Services.PlaceDialog (this, TransientFor);
67
public void InitForInstall (string[] filesToInstall)
69
this.filesToInstall = filesToInstall;
71
Services.PlaceDialog (this, TransientFor);
74
public void InitForUninstall (Addin[] info)
76
this.uninstallIds = info.Select (a => a.Id);
77
buttonOk.Label = Catalog.GetString ("Uninstall");
79
HashSet<Addin> sinfos = new HashSet<Addin> ();
81
StringBuilder sb = new StringBuilder ();
82
sb.Append ("<b>").Append (Catalog.GetString ("The following packages will be uninstalled:")).Append ("</b>\n\n");
83
foreach (var a in info) {
84
sb.Append (a.Name + "\n\n");
85
sinfos.UnionWith (service.GetDependentAddins (a.Id, true));
88
if (sinfos.Count > 0) {
89
sb.Append ("<b>").Append (Catalog.GetString ("There are other add-ins that depend on the previous ones which will also be uninstalled:")).Append ("</b>\n\n");
90
foreach (Addin si in sinfos)
91
sb.Append (si.Description.Name + "\n");
94
ShowMessage (sb.ToString ());
95
Services.PlaceDialog (this, TransientFor);
98
void FillSummaryPage ()
100
PackageCollection packs = new PackageCollection ();
102
if (filesToInstall != null) {
103
foreach (string file in filesToInstall) {
104
packs.Add (Package.FromFile (file));
108
foreach (AddinRepositoryEntry arep in addinsToInstall) {
109
packs.Add (Package.FromRepository (arep));
113
packagesToInstall = new PackageCollection (packs);
115
PackageCollection toUninstall;
116
DependencyCollection unresolved;
119
InstallMonitor m = new InstallMonitor ();
120
res = service.ResolveDependencies (m, packs, out toUninstall, out unresolved);
122
StringBuilder sb = new StringBuilder ();
124
sb.Append ("<b><span foreground=\"red\">").Append (Catalog.GetString ("The selected add-ins can't be installed because there are dependency conflicts.")).Append ("</span></b>\n");
125
foreach (string s in m.Errors) {
126
sb.Append ("<b><span foreground=\"red\">" + s + "</span></b>\n");
131
if (m.Warnings.Count != 0) {
132
foreach (string w in m.Warnings) {
133
sb.Append ("<b><span foreground=\"red\">" + w + "</span></b>\n");
138
sb.Append ("<b>").Append (Catalog.GetString ("The following packages will be installed:")).Append ("</b>\n\n");
139
foreach (Package p in packs) {
141
if (!p.SharedInstall)
142
sb.Append (Catalog.GetString (" (in user directory)"));
147
if (toUninstall.Count > 0) {
148
sb.Append ("<b>").Append (Catalog.GetString ("The following packages need to be uninstalled:")).Append ("</b>\n\n");
149
foreach (Package p in toUninstall) {
150
sb.Append (p.Name + "\n");
155
if (unresolved.Count > 0) {
156
sb.Append ("<b>").Append (Catalog.GetString ("The following dependencies could not be resolved:")).Append ("</b>\n\n");
157
foreach (Dependency p in unresolved) {
158
sb.Append (p.Name + "\n");
162
buttonOk.Sensitive = res;
163
ShowMessage (sb.ToString ());
166
void ShowMessage (string txt)
168
labelInfo.Markup = txt.TrimEnd ('\n','\t',' ');
169
if (labelInfo.SizeRequest ().Height > MaxHeight) {
170
scrolledwindow1.VscrollbarPolicy = Gtk.PolicyType.Automatic;
171
scrolledwindow1.HeightRequest = MaxHeight;
174
scrolledwindow1.HeightRequest = labelInfo.SizeRequest ().Height;
178
protected virtual void OnButtonOkClicked (object sender, System.EventArgs e)
180
if (response != Gtk.ResponseType.None) {
187
protected virtual void OnButtonCancelClicked (object sender, System.EventArgs e)
190
if (Services.AskQuestion (Catalog.GetString ("Are you sure you want to cancel the installation?")))
191
installMonitor.Cancel ();
193
Respond (Gtk.ResponseType.Cancel);
198
insSeparator.Visible = true;
199
boxProgress.Visible = true;
200
buttonOk.Sensitive = false;
208
if (uninstallIds == null) {
209
installMonitor = new InstallMonitor (globalProgressLabel, mainProgressBar, Catalog.GetString ("Installing Add-ins"));
210
oper = new ThreadStart (RunInstall);
211
errmessage = Catalog.GetString ("The installation failed!");
212
warnmessage = Catalog.GetString ("The installation has completed with warnings.");
214
installMonitor = new InstallMonitor (globalProgressLabel, mainProgressBar, Catalog.GetString ("Uninstalling Add-ins"));
215
oper = new ThreadStart (RunUninstall);
216
errmessage = Catalog.GetString ("The uninstallation failed!");
217
warnmessage = Catalog.GetString ("The uninstallation has completed with warnings.");
224
buttonCancel.Visible = false;
225
buttonOk.Label = Gtk.Stock.Close;
226
buttonOk.UseStock = true;
228
if (installMonitor.Success && installMonitor.Warnings.Count == 0) {
229
Respond (Gtk.ResponseType.Ok);
231
} else if (installMonitor.Success) {
232
txt = "<b>" + warnmessage + "</b>\n\n";
233
foreach (string s in installMonitor.Warnings)
234
txt += GLib.Markup.EscapeText (s) + "\n";
235
response = Gtk.ResponseType.Ok;
236
buttonOk.Sensitive = true;
238
buttonCancel.Label = Gtk.Stock.Close;
239
buttonCancel.UseStock = true;
240
txt = "<span foreground=\"red\"><b>" + errmessage + "</b></span>\n\n";
241
foreach (string s in installMonitor.Errors)
242
txt += GLib.Markup.EscapeText (s) + "\n";
243
response = Gtk.ResponseType.Cancel;
244
buttonOk.Sensitive = true;
253
if (filesToInstall != null)
254
service.Install (installMonitor, filesToInstall);
256
service.Install (installMonitor, packagesToInstall);
257
} catch (Exception ex) {
258
installMonitor.Errors.Add (ex.Message);
260
installMonitor.Dispose ();
267
service.Uninstall (installMonitor, uninstallIds);
268
} catch (Exception ex) {
269
installMonitor.Errors.Add (ex.Message);
271
installMonitor.Dispose ();