4
using System.Diagnostics;
5
using System.Collections.Generic;
8
using Do.Universe.Common;
18
public class DropboxPuburlAction : Act
21
private string dropbox_dir = Environment.GetFolderPath (Environment.SpecialFolder.Personal) + "/Dropbox";
23
public override string Name {
24
get { return "Public URL"; }
27
public override string Description {
28
get { return "Get public url of a file in your dropbox."; }
31
public override string Icon {
32
get { return "dropbox"; }
35
public override IEnumerable<Type> SupportedItemTypes {
36
get { yield return typeof (IFileItem); }
39
public override bool SupportsItem (Item item)
41
return (item as IFileItem).Path.StartsWith (dropbox_dir);
44
public override IEnumerable<Item> Perform (IEnumerable<Item> items, IEnumerable<Item> modItems)
46
string path = (items.First () as IFileItem).Path;
47
string url = GetPubUrl (path);
51
string msg = String.Format ("Sorry, the file \"{0}\" is not public",
52
UnixPath.GetFileName (path));
54
Log<DropboxPuburlAction>.Debug (msg);
55
Notification notification = new Notification ("Dropbox", msg, "dropbox");
56
Services.Notifications.Notify (notification);
59
yield return new BookmarkItem (url, url);
64
private string GetPubUrl (string path)
69
ProcessStartInfo cmd = new ProcessStartInfo ();
70
cmd.FileName = "dropbox";
71
cmd.Arguments = String.Format ("puburl \"{0}\"", path);
72
cmd.UseShellExecute = false;
73
cmd.RedirectStandardOutput = true;
75
Process run = Process.Start (cmd);
78
url = run.StandardOutput.ReadLine ();
79
if (!url.StartsWith ("http")) { url = ""; }