~alexlauni/do-plugins/jolicloud

« back to all changes in this revision

Viewing changes to Dropbox/src/DropboxShareAction.cs

  • Committer: Alex Launi
  • Date: 2009-06-24 13:17:29 UTC
  • mfrom: (618.1.17 do-plugins)
  • Revision ID: alex.launi@gmail.com-20090624131729-1l9g76ejqq4leka4
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// DropboxShareAction.cs
 
3
// 
 
4
// GNOME Do is the legal property of its developers. Please refer to the
 
5
// COPYRIGHT file distributed with this
 
6
// source distribution.
 
7
// 
 
8
// This program is free software: you can redistribute it and/or modify
 
9
// it under the terms of the GNU General Public License as published by
 
10
// the Free Software Foundation, either version 3 of the License, or
 
11
// (at your option) any later version.
 
12
// 
 
13
// This program is distributed in the hope that it will be useful,
 
14
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
// GNU General Public License for more details.
 
17
// 
 
18
// You should have received a copy of the GNU General Public License
 
19
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
// 
 
21
 
 
22
using System;
 
23
using System.IO;
 
24
using System.Linq;
 
25
using System.Collections.Generic;
 
26
 
 
27
using Mono.Addins;
 
28
 
 
29
using Do.Universe;
 
30
using Do.Universe.Common;
 
31
using Do.Platform;
 
32
 
 
33
 
 
34
namespace Dropbox
 
35
{
 
36
        
 
37
        
 
38
        public class DropboxShareAction : DropboxAbstractAction
 
39
        {
 
40
                                
 
41
                public override string Name {
 
42
                        get { return AddinManager.CurrentLocalizer.GetString ("Share with Dropbox");  }
 
43
                }
 
44
                
 
45
                public override string Description {
 
46
                        get { return AddinManager.CurrentLocalizer.GetString ("Links a file to your Dropbox public folder."); }
 
47
                }
 
48
                
 
49
                public override string Icon {
 
50
                        get { return ("dropbox-share.png@") + GetType ().Assembly.FullName; }
 
51
                }
 
52
                
 
53
                public override bool SupportsItem (Item item) 
 
54
                {
 
55
                        string path = GetPath (item);
 
56
                        
 
57
                        return File.Exists (path) && 
 
58
                                !path.StartsWith (Dropbox.PublicPath) && 
 
59
                                !HasLink (path);
 
60
                }
 
61
                
 
62
                public override IEnumerable<Item> Perform (IEnumerable<Item> items, IEnumerable<Item> modItems)
 
63
                {
 
64
                        string target, extension, filename, linkName, url;
 
65
                        
 
66
                        foreach (Item item in items) {
 
67
                                target = GetPath (item);
 
68
                                extension = Path.GetExtension (target);
 
69
                                filename = Path.GetFileNameWithoutExtension (target);
 
70
                                linkName = Path.Combine (Dropbox.DoSharedPath, 
 
71
                                        String.Format ("{0}-{1}{2}", filename, rand.Next (), extension));
 
72
                                
 
73
                                Directory.CreateDirectory (Dropbox.DoSharedPath);
 
74
                                
 
75
                                if (MakeLink (target, linkName)) {
 
76
                                        
 
77
                                        url = Dropbox.GetPubUrl (linkName);     
 
78
                                        yield return new BookmarkItem (url, url);
 
79
                                }
 
80
                        }
 
81
                }
 
82
 
 
83
        }
 
84
}
 
85