~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/mono-addins/Mono.Addins.Gui/Mono.Addins.Gui/InstallMonitor.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// AddinInstallDialog.cs
 
3
//  
 
4
// Author:
 
5
//       Lluis Sanchez Gual <lluis@novell.com>
 
6
// 
 
7
// Copyright (c) 2011 Novell, Inc (http://www.novell.com)
 
8
// 
 
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:
 
15
// 
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
// 
 
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
 
25
// THE SOFTWARE.
 
26
 
 
27
using System;
 
28
using System.Text;
 
29
using System.Threading;
 
30
using System.Collections;
 
31
using System.Collections.Specialized;
 
32
using System.Diagnostics;
 
33
using Mono.Unix;
 
34
using Gtk;
 
35
using Mono.Addins.Setup;
 
36
using Mono.Addins.Description;
 
37
namespace Mono.Addins.Gui
 
38
{
 
39
        class InstallMonitor: IProgressStatus, IDisposable
 
40
        {
 
41
                Label progressLabel;
 
42
                ProgressBar progressBar;
 
43
                StringCollection errors = new StringCollection ();
 
44
                StringCollection warnings = new StringCollection ();
 
45
                bool canceled;
 
46
                bool done;
 
47
                string mainOperation;
 
48
                
 
49
                public InstallMonitor (Label progressLabel, ProgressBar progressBar, string mainOperation)
 
50
                {
 
51
                        this.progressLabel = progressLabel;
 
52
                        this.progressBar = progressBar;
 
53
                        this.mainOperation = mainOperation;
 
54
                }
 
55
                
 
56
                public InstallMonitor ()
 
57
                {
 
58
                }
 
59
                
 
60
                public void SetMessage (string msg)
 
61
                {
 
62
                        if (progressLabel != null)
 
63
                                progressLabel.Markup = "<b>" + GLib.Markup.EscapeText (mainOperation) + "</b>\n" + GLib.Markup.EscapeText (msg);
 
64
                        RunPendingEvents ();
 
65
                }
 
66
                
 
67
                public void SetProgress (double progress)
 
68
                {
 
69
                        if (progressBar != null)
 
70
                                progressBar.Fraction = progress;
 
71
                        RunPendingEvents ();
 
72
                }
 
73
                
 
74
                public void Log (string msg)
 
75
                {
 
76
                        Console.WriteLine (msg);
 
77
                }
 
78
                
 
79
                public void ReportWarning (string message)
 
80
                {
 
81
                        warnings.Add (message);
 
82
                }
 
83
                
 
84
                public void ReportError (string message, Exception exception)
 
85
                {
 
86
                        errors.Add (message);
 
87
                }
 
88
                
 
89
                public bool IsCanceled {
 
90
                        get { return canceled; }
 
91
                }
 
92
                
 
93
                public StringCollection Errors {
 
94
                        get { return errors; }
 
95
                }
 
96
                
 
97
                public StringCollection Warnings {
 
98
                        get { return warnings; }
 
99
                }
 
100
                
 
101
                public void Cancel ()
 
102
                {
 
103
                        canceled = true;
 
104
                }
 
105
                
 
106
                public int LogLevel {
 
107
                        get { return 1; }
 
108
                }
 
109
                
 
110
                public void Dispose ()
 
111
                {
 
112
                        done = true;
 
113
                }
 
114
                
 
115
                public void WaitForCompleted ()
 
116
                {
 
117
                        while (!done) {
 
118
                                RunPendingEvents ();
 
119
                                Thread.Sleep (50);
 
120
                        }
 
121
                }
 
122
                
 
123
                public bool Success {
 
124
                        get { return errors.Count == 0; }
 
125
                }
 
126
                
 
127
                void RunPendingEvents ()
 
128
                {
 
129
                        while (Gtk.Application.EventsPending ())
 
130
                                Gtk.Application.RunIteration ();
 
131
                }
 
132
        }
 
133
}