From 805a725fe25188db8cb1586eeb5bc4edf0e5a54d Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Tue, 15 Jun 2010 23:17:43 +0100 Subject: [PATCH] Move autostart .desktop file creation to code --- Makefile | 4 -- SparkleShare/SparkleUI.cs | 90 +++++++++++++++++++++++++----------- data/sparkleshare.desktop.in | 6 --- 3 files changed, 63 insertions(+), 37 deletions(-) delete mode 100644 data/sparkleshare.desktop.in diff --git a/Makefile b/Makefile index 4c392cbe..93491b9e 100644 --- a/Makefile +++ b/Makefile @@ -11,10 +11,6 @@ install: cp sparkleshare /usr/local/bin/ chmod 755 /usr/local/bin/sparkleshare cp data/icons /usr/share/ -R - mkdir -p ~/.config/autostart -# TODO: doesn't start on login - cp data/sparkleshare.desktop.in ~/.config/autostart/sparkleshare.desktop - chmod 775 ~/.config/autostart/sparkleshare.desktop gtk-update-icon-cache /usr/share/icons/hicolor -f uninstall: diff --git a/SparkleShare/SparkleUI.cs b/SparkleShare/SparkleUI.cs index 289da593..97ca0bff 100644 --- a/SparkleShare/SparkleUI.cs +++ b/SparkleShare/SparkleUI.cs @@ -23,18 +23,21 @@ using System.IO; namespace SparkleShare { - public class SparkleUI { + public class SparkleUI + { private Process Process; // Short alias for the translations - public static string _ (string s) { + public static string _ (string s) + { return Catalog.GetString (s); } public static SparkleStatusIcon NotificationIcon; - public SparkleUI (bool HideUI) { + public SparkleUI (bool HideUI) + { Process = new Process (); Process.EnableRaisingEvents = true; @@ -43,24 +46,53 @@ namespace SparkleShare { string SparklePath = SparklePaths.SparklePath; + + // Create .desktop entry in autostart folder to + // start SparkleShare on each login + switch (SparklePlatform.Name) { + case "GNOME": + + string autostart_path = SparkleHelpers.CombineMore (SparklePaths.HomePath, ".config", "autostart"); + string desktopfile_path = SparkleHelpers.CombineMore (autostart_path, "sparkleshare.desktop"); + + if (!File.Exists (desktopfile_path)) { + if (!Directory.Exists (autostart_path)) + Directory.CreateDirectory (autostart_path); + TextWriter writer = new StreamWriter (desktopfile_path); + writer.WriteLine ("[Desktop Entry]\n" + + "Name=SparkleShare\n" + + "Exec=sparkleshare start\n" + + "Icon=folder-sparkleshare\n" + + "Terminal=false\n" + + "X-GNOME-Autostart-enabled=true"); + writer.Close (); + SparkleHelpers.DebugInfo ("Config", " Created '" + desktopfile_path + "'"); + } + + break; + + } + + // Create 'SparkleShare' folder in the user's home folder // if it's not there already if (!Directory.Exists (SparklePath)) { Directory.CreateDirectory (SparklePath); - SparkleHelpers.DebugInfo ("Config", - "Created '" + SparklePath + "'"); + SparkleHelpers.DebugInfo ("Config", " Created '" + SparklePath + "'"); // Add a special icon to the SparkleShare folder switch (SparklePlatform.Name) { case "GNOME": + Process.StartInfo.FileName = "gvfs-set-attribute"; - Process.StartInfo.Arguments = - SparklePath + " metadata::custom-icon " + - "file:///usr/share/icons/hicolor/48x48/places/" + - "folder-sparkleshare.png"; + Process.StartInfo.Arguments = SparklePath + " metadata::custom-icon " + + "file:///usr/share/icons/hicolor/48x48/places/" + + "folder-sparkleshare.png"; Process.Start (); + break; + } // Add the SparkleShare folder to the bookmarks @@ -82,13 +114,12 @@ namespace SparkleShare { } + // Create a directory to store temporary files in if (!Directory.Exists (SparklePaths.SparkleTmpPath)) Directory.CreateDirectory (SparklePaths.SparkleTmpPath); - if (!HideUI) { - // Create the status icon + if (!HideUI) NotificationIcon = new SparkleStatusIcon (); - } UpdateRepositories (); @@ -156,56 +187,61 @@ namespace SparkleShare { if (!Directory.Exists (ConfigPath)) { Directory.CreateDirectory (ConfigPath); - SparkleHelpers.DebugInfo ("Config", - "Created '" + ConfigPath + "'"); + SparkleHelpers.DebugInfo ("Config", " Created '" + ConfigPath + "'"); // Create a place to store the avatars Directory.CreateDirectory (AvatarPath); - SparkleHelpers.DebugInfo ("Config", - "Created '" + AvatarPath + "'"); + SparkleHelpers.DebugInfo ("Config", " Created '" + AvatarPath + "'"); } - string NotifySettingFile = - SparkleHelpers.CombineMore (SparklePaths.SparkleConfigPath, - "sparkleshare.notify"); + string NotifySettingFile = SparkleHelpers.CombineMore (SparklePaths.SparkleConfigPath, + "sparkleshare.notify"); // Enable notifications by default if (!File.Exists (NotifySettingFile)) File.Create (NotifySettingFile); } - public void UpdateRepositories () { + + + public void UpdateRepositories () + { + string SparklePath = SparklePaths.SparklePath; // Get all the repos in ~/SparkleShare - SparkleRepo [] TmpRepos = - new SparkleRepo [Directory.GetDirectories (SparklePath).Length]; + SparkleRepo [] TmpRepos = new SparkleRepo [Directory.GetDirectories (SparklePath).Length]; int FolderCount = 0; foreach (string Folder in Directory.GetDirectories (SparklePath)) { // Check if the folder is a git repo - if (Directory.Exists (SparkleHelpers.CombineMore (Folder, - ".git"))) { + if (Directory.Exists (SparkleHelpers.CombineMore (Folder, ".git"))) { + TmpRepos [FolderCount] = new SparkleRepo (Folder); FolderCount++; - // TODO: emblems don't work in nautilus + // TODO: emblems don't show up in nautilus // Attach emblems switch (SparklePlatform.Name) { case "GNOME": + Process.StartInfo.FileName = "gvfs-set-attribute"; - Process.StartInfo.Arguments = - "-t string \"" + Folder + "\" metadata::emblems [synced]"; + Process.StartInfo.Arguments = "-t string \"" + Folder + + "\" metadata::emblems [synced]"; Process.Start (); + break; + } } } + SparkleShare.Repositories = new SparkleRepo [FolderCount]; Array.Copy (TmpRepos, SparkleShare.Repositories, FolderCount); + } } diff --git a/data/sparkleshare.desktop.in b/data/sparkleshare.desktop.in deleted file mode 100644 index 9cc77d6d..00000000 --- a/data/sparkleshare.desktop.in +++ /dev/null @@ -1,6 +0,0 @@ -[Desktop Entry] -Name=SparkleShare -Exec=sparkleshare start -Icon=folder-sparkleshare -Terminal=false -X-GNOME-Autostart-enabled=true