~cszikszoy/do-plugins/fix-confluence

« back to all changes in this revision

Viewing changes to DiskMounter/src/DriveItem.cs

  • Committer: Peng Deng
  • Date: 2009-06-17 01:07:23 UTC
  • Revision ID: dengpeng@gmail.com-20090617010723-wopvd2omtyp4rwfv
Clean up DiskMounter, make DiskItem using IUriItem interface, and let FileAndFolder support browsing IUriItem

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
//
18
18
 
19
19
using System;
 
20
 
20
21
using Do.Universe;
 
22
using Do.Platform;
21
23
 
22
24
using Gnome.Vfs;
23
25
 
24
26
namespace DiskMounter
25
27
{
26
 
        public class DriveItem : Item
 
28
        public class DriveItem : Item, IUriItem
27
29
        {
28
30
                private Drive drive;
29
31
                
33
35
                }
34
36
                
35
37
                public override string Name {
36
 
                        get { return drive.DisplayName; }               
 
38
                        get { return drive.DisplayName; }
37
39
                }
38
40
                
39
41
                public override string Description {
40
 
                        get { return String.Format("{0}",drive.DeviceType); }
 
42
                        get {
 
43
                                string status = IsMounted ? Uri : "Unmounted";
 
44
                                return drive.DeviceType.ToString () + " (" + status + ")";
 
45
                        }
41
46
                }
42
47
                
43
48
                public override string Icon {
44
 
                        get { return drive.Icon; }
 
49
                        get { return IsMounted ? drive.MountedVolume.Icon : drive.Icon; }
45
50
                }
46
51
                
47
 
                public string Path {
48
 
                        get { return drive.ActivationUri.ToString(); }
 
52
                public string Uri {
 
53
                        get { return IsMounted ? drive.MountedVolume.ActivationUri : ""; }
49
54
                }
50
55
                
51
56
                public void Unmount ()
52
57
                {
53
58
                        try {
54
 
                                drive.Unmount (VolumeOpCallback);
55
 
                        } catch
56
 
                        {    // error message will be handled by VolumeOpCallback                                                     
 
59
                                if (drive.NeedsEject ())
 
60
                                        drive.Eject (new VolumeOpCallback (OnEject));
 
61
                                else 
 
62
                                        drive.Unmount (new VolumeOpCallback (OnUnmount));
 
63
                        } catch {
 
64
                            // error message will be handled by VolumeOpCallback                                                     
57
65
                        }
58
66
                }
59
67
                
60
68
                public void Mount ()
61
69
                {
62
70
                        try {
63
 
                                drive.Mount (VolumeOpCallback);
64
 
                        } catch
65
 
                        {  // error message will be handled by VolumeOpCallback    
 
71
                                drive.Mount (new VolumeOpCallback (OnMount));
 
72
                        } catch (Exception ex) {
 
73
                                Log.Debug ("An error occurred while executing the Mount operation.");
 
74
                                Log.Error (ex.Message);
66
75
                        }
67
76
                }
68
77
                
69
78
                public bool IsMounted
70
79
                {
71
80
                        get {
72
 
                                return drive.IsMounted;
 
81
                                return drive.IsMounted && drive.MountedVolumes.Count > 0;
73
82
                        }
74
83
                }
75
 
                                        
76
 
                public void VolumeOpCallback (bool succeeded, string error, string detailed_error)
77
 
                {
78
 
                        if ( succeeded )
79
 
                                Console.WriteLine("Unmount operation succeeded");
80
 
                        else
81
 
                                Console.Error.WriteLine("Unmount operation failed {0}, detail : {1}" , error, detailed_error );
 
84
                
 
85
                void OnMount (bool succeeded, string error, string detailed_error)
 
86
                {
 
87
                        if (succeeded)
 
88
                                Log.Debug ("Mount operation succeeded");
 
89
                        else
 
90
                                Log.Error ("Mountt operation failed {0}, detail: {1}", error, detailed_error);
 
91
                }
 
92
 
 
93
                void OnUnmount (bool succeeded, string error, string detailed_error)
 
94
                {
 
95
                        if (succeeded)
 
96
                                Log.Debug ("Unmount operation succeeded");
 
97
                        else
 
98
                                Log.Error ("Unmount operation failed {0}, detail: {1}", error, detailed_error);
 
99
                }
 
100
                
 
101
                void OnEject (bool succeeded, string error, string detailed_error)
 
102
                {
 
103
                        if (succeeded)
 
104
                                Log.Debug ("Eject operation succeeded");
 
105
                        else
 
106
                                Log.Error ("Eject operation failed {0}, detail: {1}", error, detailed_error);
82
107
                }
83
108
        }
84
109
}