~ubuntu-branches/ubuntu/jaunty/beagle/jaunty-security

« back to all changes in this revision

Viewing changes to search/Tiles/File.cs

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Ebner
  • Date: 2008-05-04 00:31:32 UTC
  • mfrom: (1.1.21 upstream)
  • Revision ID: james.westby@ubuntu.com-20080504003132-2tkm5o8moo5952ri
Tags: 0.3.7-2ubuntu1
 * Merge from Debian unstable. (LP: #225746) Remaining Ubuntu changes:
  - debian/control:
    + Rename ice{weasel,dove}-beagle to {mozilla,thunderbird}-beagle and
      and update the dependencies accordingly.
    + Change Maintainer to Ubuntu Mono Team.
  - debian/rules:
    + Install the mozilla-beagle and thunderbird-beagle extensions.
  - ice{dove,weasel}.dirs:
    + Renamed to {mozilla,thunderbird}-beagle.dirs.
    + Fixed paths to point to usr/lib/{firefox,thunderbird}

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
using System;
2
 
using System.Diagnostics;
3
 
using System.Runtime.InteropServices;
4
 
using Mono.Unix;
5
 
using Beagle.Util;
6
 
 
7
 
namespace Search.Tiles {
8
 
 
9
 
        public class FileActivator : TileActivator {
10
 
 
11
 
                public FileActivator () : base ()
12
 
                {
13
 
                        AddSupportedFlavor (new HitFlavor (null, "File", null));
14
 
                }
15
 
 
16
 
                public override Tile BuildTile (Beagle.Hit hit, Beagle.Query query)
17
 
                {
18
 
                        return new TileFile (hit, query);
19
 
                }
20
 
        }
21
 
 
22
 
        public class TileFile : TileTemplate {
23
 
 
24
 
                public TileFile (Beagle.Hit hit, Beagle.Query query) : base (hit, query)
25
 
                {
26
 
                        Title = GetTitle (hit);
27
 
                        
28
 
                        if (Hit.FileInfo != null) {
29
 
                                Timestamp = Hit.FileInfo.LastWriteTimeUtc;
30
 
                                Description = Utils.NiceShortDate (Timestamp);
31
 
                        }
32
 
 
33
 
                        AddAction (new TileAction (Catalog.GetString ("Reveal in Folder"), RevealInFolder));
34
 
                        AddAction (new TileAction (Catalog.GetString ("E-Mail"), Email));
35
 
                        // AddAction (new TileAction (Catalog.GetString ("Instant-Message"), InstantMessage));
36
 
                        AddAction (new TileAction (Catalog.GetString ("Move to Trash"), Gtk.Stock.Delete, MoveToTrash));
37
 
 
38
 
                        if (! String.IsNullOrEmpty (Hit.GetFirstProperty("dc:author"))) {
39
 
                                AddAction(new TileAction ("Find Documents From Same Author", Gtk.Stock.Find, FindSameAuthor));
40
 
                        }
41
 
 
42
 
                        EnableOpenWith = true;
43
 
                }
44
 
 
45
 
                static ThumbnailFactory thumbnailer = new ThumbnailFactory ();
46
 
 
47
 
                protected override void LoadIcon (Gtk.Image image, int size)
48
 
                {
49
 
                        // The File tile doesn't respect the icon size because
50
 
                        // 48 is too small for thumbnails
51
 
                        if (!thumbnailer.SetThumbnailIcon (image, Hit, size))
52
 
                                base.LoadIcon (image, size);
53
 
 
54
 
                        // FIXME: Multiple emblems
55
 
                        string emblem = Hit.GetFirstProperty ("nautilus:emblem");
56
 
                        if (emblem == null)
57
 
                                return;
58
 
 
59
 
                        Gdk.Pixbuf icon_pixbuf = image.Pixbuf.Copy ();
60
 
                        Gdk.Pixbuf emblem_pixbuf = WidgetFu.LoadThemeIcon ("emblem-" + emblem, 24);
61
 
 
62
 
                        if (icon_pixbuf == null || emblem_pixbuf == null) {
63
 
                                if (icon_pixbuf != null)
64
 
                                        icon_pixbuf.Dispose ();
65
 
 
66
 
                                if (emblem_pixbuf == null)
67
 
                                        emblem_pixbuf.Dispose ();
68
 
 
69
 
                                return;
70
 
                        }
71
 
 
72
 
                        // If the icon itself is smaller than our requested
73
 
                        // emblem, just display the emblem.
74
 
                        if (icon_pixbuf.Height < emblem_pixbuf.Height || icon_pixbuf.Width < emblem_pixbuf.Width) {
75
 
                                icon_pixbuf.Dispose ();
76
 
                                image.Pixbuf.Dispose ();
77
 
                                image.Pixbuf = emblem_pixbuf;
78
 
                                return;
79
 
                        }
80
 
 
81
 
                        emblem_pixbuf.Composite (icon_pixbuf, 0, 0,
82
 
                                                 emblem_pixbuf.Width, emblem_pixbuf.Height,
83
 
                                                 0, 0, 1, 1, Gdk.InterpType.Bilinear, 255);
84
 
                        image.Pixbuf.Dispose ();
85
 
                        image.Pixbuf = icon_pixbuf;
86
 
                }
87
 
 
88
 
                protected static string GetTitle (Beagle.Hit hit, bool get_parent)
89
 
                {
90
 
                        string title;
91
 
 
92
 
                        if (get_parent)
93
 
                                title = Utils.GetFirstPropertyOfParent (hit, "dc:title");
94
 
                        else
95
 
                                title = hit.GetFirstProperty ("dc:title");
96
 
 
97
 
                        if (title == null || title == "") {
98
 
                                if (get_parent)
99
 
                                        title = Utils.GetFirstPropertyOfParent (hit, "beagle:ExactFilename");
100
 
                                else
101
 
                                        title = hit.GetFirstProperty ("beagle:ExactFilename");
102
 
                        }
103
 
 
104
 
                        return title;
105
 
                }
106
 
 
107
 
                protected static string GetTitle (Beagle.Hit hit)
108
 
                {
109
 
                        return GetTitle (hit, false);
110
 
                }
111
 
 
112
 
                public override void Open ()
113
 
                {
114
 
                        base.OpenFromMime (Hit);
115
 
                }
116
 
 
117
 
                public void OpenWith ()
118
 
                {
119
 
                        // FIXME: base.OpenWith
120
 
                }
121
 
 
122
 
                public void RevealInFolder ()
123
 
                {
124
 
                        string path = Hit.FileInfo.DirectoryName;
125
 
 
126
 
                        // FIXME: When nautilus implements this, then we should
127
 
                        // also select the file in the folder.
128
 
 
129
 
                        SafeProcess p = new SafeProcess ();
130
 
 
131
 
#if ENABLE_DESKTOP_LAUNCH
132
 
                        p.Arguments = new string [] { "desktop-launch", path };
133
 
#elif ENABLE_XDG_OPEN
134
 
                        p.Arguments = new string [] { "xdg-open", path };
135
 
#else
136
 
                        p.Arguments = new string [] { "nautilus", "--no-desktop", path };
137
 
#endif
138
 
                        try {
139
 
                                p.Start ();
140
 
                        } catch (Exception e) {
141
 
                                Console.WriteLine ("Cannot open folder: " + e);
142
 
                        }
143
 
                }
144
 
 
145
 
                public void Email ()
146
 
                {
147
 
                        try {
148
 
                                OpenFromUri (String.Format ("mailto:?attach={0}", Hit.FileInfo.FullName));
149
 
                        } catch (Exception e) {
150
 
                                Console.WriteLine ("Error sending email: " + e);
151
 
                        }
152
 
                }
153
 
 
154
 
                public void InstantMessage ()
155
 
                {
156
 
                        // FIXME: base.InstantMessage
157
 
                }
158
 
 
159
 
                public void MoveToTrash ()
160
 
                {
161
 
                        // FIXME: Ask for confirmation
162
 
 
163
 
                        try {
164
 
                                // FIXME: Check if KDE uses ~/.Trash too (there is a spec at fd.o)
165
 
                                string trash_dir = System.IO.Path.Combine (Beagle.Util.PathFinder.HomeDir, ".Trash");
166
 
 
167
 
                                // FIXME: This throws an exception if the file exists
168
 
                                Hit.FileInfo.MoveTo (System.IO.Path.Combine (trash_dir, Hit.FileInfo.Name));
169
 
                        } catch (Exception e) {
170
 
                                Console.WriteLine (e);
171
 
                        }
172
 
                }       
173
 
 
174
 
                protected override DetailsPane GetDetails ()
175
 
                {
176
 
                        DetailsPane details = new DetailsPane ();
177
 
 
178
 
                        details.AddLabelPair (Catalog.GetString ("Title:"), GetTitle (Hit));
179
 
                        details.AddLabelPair (Catalog.GetString ("Last Edited:"), Utils.NiceLongDate (Timestamp));
180
 
 
181
 
                        if (Hit ["dc:author"] != null)
182
 
                                details.AddLabelPair (Catalog.GetString ("Author:"), Hit ["dc:author"]);
183
 
 
184
 
                        details.AddLabelPair (Catalog.GetString ("Full Path:"), Hit.Uri.LocalPath);
185
 
                        details.AddSnippet ();
186
 
 
187
 
                        return details;
188
 
                }
189
 
                
190
 
                public void FindSameAuthor()
191
 
                {
192
 
                        SafeProcess p = new SafeProcess ();
193
 
                        string author = Hit.GetFirstProperty("dc:author");
194
 
                        if( String.IsNullOrEmpty(author))
195
 
                                 author = Hit.GetFirstProperty("dc:creator");
196
 
                        p.Arguments = new string [] { "beagle-search", String.Format ("author:{0} OR creator:{0}", author) };
197
 
                        try {
198
 
                                p.Start () ;
199
 
                        } catch (Exception e) {
200
 
                                Console.WriteLine ("Error launching new search: " + e.Message);
201
 
                        }
202
 
                        
203
 
                }
204
 
        }
205
 
}