~ubuntu-branches/ubuntu/precise/gnome-do/precise-proposed

« back to all changes in this revision

Viewing changes to Do/src/Do.UI/DoAddinInstallerDialog.cs

  • Committer: Bazaar Package Importer
  • Author(s): Christopher James Halse Rogers
  • Date: 2008-09-14 10:09:40 UTC
  • mto: (0.1.8 sid)
  • mto: This revision was merged to the branch mainline in revision 7.
  • Revision ID: james.westby@ubuntu.com-20080914100940-kyghudg7py14bu2z
Tags: upstream-0.6.0.0
ImportĀ upstreamĀ versionĀ 0.6.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* DoAddinInstallerDialog.cs
 
2
 *
 
3
 * GNOME Do is the legal property of its developers. Please refer to the
 
4
 * COPYRIGHT file distributed with this
 
5
 * source distribution.
 
6
 *
 
7
 * This program is free software: you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation, either version 3 of the License, or
 
10
 * (at your option) any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
 */
 
20
 
 
21
using System;
 
22
using System.Threading;
 
23
using System.Collections;
 
24
using Mono.Addins.Setup;
 
25
using Mono.Addins.Description;
 
26
using Mono.Unix;
 
27
using Do.Core;
 
28
using Mono.Addins.Gui;
 
29
using Mono.Addins;
 
30
using Mono;
 
31
 
 
32
namespace Do.UI
 
33
{
 
34
        public partial class DoAddinInstallerDialog : Gtk.Dialog, IProgressStatus
 
35
        {
 
36
                PackageCollection entries = new PackageCollection ();
 
37
                PluginUpdateNodeView plugins_view;
 
38
                
 
39
                string[] addin_ids;
 
40
                string err_message;
 
41
                bool addins_not_found;
 
42
                SetupService setup;
 
43
                
 
44
                public DoAddinInstallerDialog (AddinRegistry reg, string message, string[] addinIds)
 
45
                {
 
46
                        addin_ids = addinIds;
 
47
                        
 
48
                        Build();
 
49
                        
 
50
                        plugins_view = new PluginUpdateNodeView (reg, addin_ids);
 
51
                        plugin_scroll.Add (plugins_view);
 
52
                        plugin_scroll.ShowAll ();
 
53
                        
 
54
                        setup = new SetupService (reg);                 
 
55
 
 
56
                        if (!CheckAddins (true))
 
57
                                UpdateRepos ();
 
58
                }
 
59
                
 
60
                bool CheckAddins (bool updating)
 
61
                {
 
62
                        entries.Clear ();
 
63
                        bool addinsNotFound = false;
 
64
                        foreach (string id in addin_ids) {
 
65
                                string name = Addin.GetIdName (id);
 
66
                                string version = Addin.GetIdVersion (id);
 
67
                                AddinRepositoryEntry[] ares = setup.Repositories.GetAvailableAddin (name, version);
 
68
                                if (ares.Length == 0) {
 
69
                                        addinsNotFound = true;
 
70
                                } else {
 
71
                                        entries.Add (Package.FromRepository (ares[0]));
 
72
                                }
 
73
                        }
 
74
                        
 
75
                        DependencyCollection unresolved;
 
76
                        PackageCollection toUninstall;
 
77
                        
 
78
                        if (!setup.ResolveDependencies (this, entries, out toUninstall, out unresolved)) {
 
79
                                /* Change this to some way of notifying that there are missing deps
 
80
                                foreach (Dependency dep in unresolved) {
 
81
                                        txt += "<span foreground='red'><b>" + dep.Name + "</b> (not found)</span>\n";
 
82
                                }
 
83
                                */
 
84
                                addinsNotFound = true;
 
85
                        }
 
86
                        return !addinsNotFound;
 
87
                }
 
88
                
 
89
                void UpdateRepos ()
 
90
                {
 
91
                        progress_bar.Show ();
 
92
                        setup.Repositories.UpdateAllRepositories (this);
 
93
                        progress_bar.Hide ();
 
94
                        addins_not_found = CheckAddins (false);
 
95
                        if (err_message != null) {
 
96
                                err_message = null;
 
97
                        }
 
98
                }
 
99
                
 
100
                public int LogLevel {
 
101
                        get {
 
102
                                return 1;
 
103
                        }
 
104
                }
 
105
 
 
106
                public bool IsCanceled {
 
107
                        get {
 
108
                                return false;
 
109
                        }
 
110
                }
 
111
 
 
112
                public bool AddinsNotFound {
 
113
                        get {
 
114
                                return addins_not_found;
 
115
                        }
 
116
                }
 
117
 
 
118
                public string ErrMessage {
 
119
                        get {
 
120
                                return err_message;
 
121
                        }
 
122
                }
 
123
 
 
124
                public void SetMessage (string msg)
 
125
                {
 
126
                        progress_bar.Text = msg;
 
127
                        while (Gtk.Application.EventsPending ())
 
128
                                Gtk.Application.RunIteration ();
 
129
                }
 
130
                               
 
131
                public void SetProgress (double progress)
 
132
                {
 
133
                        progress_bar.Fraction = progress;
 
134
                        while (Gtk.Application.EventsPending ())
 
135
                                Gtk.Application.RunIteration ();
 
136
                }
 
137
 
 
138
                public void ReportError (string message, System.Exception exception)
 
139
                {
 
140
                        err_message = message;
 
141
                }
 
142
                
 
143
                public void Log (string msg)
 
144
                {
 
145
                }
 
146
 
 
147
                public void ReportWarning (string message)
 
148
                {
 
149
                }
 
150
 
 
151
                public void Cancel ()
 
152
                {
 
153
                        Respond (Gtk.ResponseType.Cancel);
 
154
                }
 
155
 
 
156
                protected virtual void OnButtonOKClick (object sender, System.EventArgs e)
 
157
                {
 
158
                        if (addins_not_found) {
 
159
                                err_message = Catalog.GetString ("Some of the required add-ins were not found");
 
160
                                Respond (Gtk.ResponseType.Ok);
 
161
                        }
 
162
                        else {
 
163
                                progress_bar.Visible = true;
 
164
                                err_message = null;
 
165
                                progress_bar.Show ();
 
166
                                progress_bar.Fraction = 0;
 
167
                                progress_bar.Text = "";
 
168
                                bool res = setup.Install (this, entries);
 
169
                                if (!res) {
 
170
                                        button_cancel.Sensitive = button_ok.Sensitive = false;
 
171
                                        if (err_message == null)
 
172
                                                Catalog.GetString ("Installation failed");
 
173
                                }
 
174
                        }
 
175
                        Respond (Gtk.ResponseType.Ok);
 
176
                }
 
177
        }
 
178
}