1 // 2 // AddinInstallerDialog.cs 3 // 4 // Author: 5 // Lluis Sanchez Gual 6 // 7 // Copyright (C) 2007 Novell, Inc (http://www.novell.com) 8 // 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: 16 // 17 // The above copyright notice and this permission notice shall be 18 // included in all copies or substantial portions of the Software. 19 // 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. 27 // 28 29 using System; 30 using System.Threading; 31 using System.Collections; 32 using Mono.Addins.Setup; 33 using Mono.Addins.Description; 34 using Mono.Unix; 35 36 namespace Mono.Addins.Gui 37 { 38 internal partial class AddinInstallerDialog : Gtk.Dialog, IProgressStatus 39 { 40 PackageCollection entries = new PackageCollection (); 41 string[] addinIds; 42 bool addinsNotFound; 43 string errMessage; 44 SetupService setup; 45 AddinInstallerDialog(AddinRegistry reg, string message, string[] addinIds)46 public AddinInstallerDialog (AddinRegistry reg, string message, string[] addinIds) 47 { 48 this.Build(); 49 50 this.addinIds = addinIds; 51 setup = new SetupService (reg); 52 53 if (!CheckAddins (true)) 54 UpdateRepos (); 55 } 56 CheckAddins(bool updating)57 bool CheckAddins (bool updating) 58 { 59 string txt = ""; 60 entries.Clear (); 61 bool addinsNotFound = false; 62 foreach (string id in addinIds) { 63 string name = Addin.GetIdName (id); 64 string version = Addin.GetIdVersion (id); 65 AddinRepositoryEntry[] ares = setup.Repositories.GetAvailableAddin (name, version); 66 if (ares.Length == 0) { 67 addinsNotFound = true; 68 if (updating) 69 txt += "<span foreground='grey'><b>" + name + " " + version + "</b> (searching add-in)</span>\n"; 70 else 71 txt += "<span foreground='red'><b>" + name + " " + version + "</b> (not found)</span>\n"; 72 } else { 73 entries.Add (Package.FromRepository (ares[0])); 74 txt += "<b>" + ares[0].Addin.Name + " " + ares[0].Addin.Version + "</b>\n"; 75 } 76 } 77 PackageCollection toUninstall; 78 DependencyCollection unresolved; 79 if (!setup.ResolveDependencies (this, entries, out toUninstall, out unresolved)) { 80 foreach (Dependency dep in unresolved) { 81 txt += "<span foreground='red'><b>" + dep.Name + "</b> (not found)</span>\n"; 82 } 83 addinsNotFound = true; 84 } 85 addinList.Markup = txt; 86 return !addinsNotFound; 87 } 88 UpdateRepos()89 void UpdateRepos () 90 { 91 progressBar.Show (); 92 setup.Repositories.UpdateAllRepositories (this); 93 progressBar.Hide (); 94 addinsNotFound = CheckAddins (false); 95 if (errMessage != null) { 96 Services.ShowError (null, errMessage, this, true); 97 errMessage = null; 98 } 99 } 100 101 public int LogLevel { 102 get { 103 return 1; 104 } 105 } 106 107 public bool IsCanceled { 108 get { 109 return false; 110 } 111 } 112 113 public bool AddinsNotFound { 114 get { 115 return addinsNotFound; 116 } 117 } 118 119 public string ErrMessage { 120 get { 121 return errMessage; 122 } 123 } 124 SetMessage(string msg)125 public void SetMessage (string msg) 126 { 127 progressBar.Text = msg; 128 while (Gtk.Application.EventsPending ()) 129 Gtk.Application.RunIteration (); 130 } 131 SetProgress(double progress)132 public void SetProgress (double progress) 133 { 134 progressBar.Fraction = progress; 135 while (Gtk.Application.EventsPending ()) 136 Gtk.Application.RunIteration (); 137 } 138 Log(string msg)139 public void Log (string msg) 140 { 141 } 142 ReportWarning(string message)143 public void ReportWarning (string message) 144 { 145 } 146 ReportError(string message, System.Exception exception)147 public void ReportError (string message, System.Exception exception) 148 { 149 errMessage = message; 150 } 151 Cancel()152 public void Cancel () 153 { 154 } 155 OnButtonOkClicked(object sender, System.EventArgs e)156 protected virtual void OnButtonOkClicked (object sender, System.EventArgs e) 157 { 158 if (addinsNotFound) { 159 errMessage = Catalog.GetString ("Some of the required add-ins were not found"); 160 Respond (Gtk.ResponseType.Ok); 161 } 162 else { 163 errMessage = null; 164 progressBar.Show (); 165 progressBar.Fraction = 0; 166 progressBar.Text = ""; 167 bool res = setup.Install (this, entries); 168 if (!res) { 169 buttonCancel.Sensitive = buttonOk.Sensitive = false; 170 if (errMessage == null) 171 errMessage = Catalog.GetString ("Installation failed"); 172 Services.ShowError (null, errMessage, this, true); 173 } 174 } 175 Respond (Gtk.ResponseType.Ok); 176 } 177 } 178 } 179