Move autostart .desktop file creation to code

This commit is contained in:
Hylke Bons 2010-06-15 23:17:43 +01:00
parent 539562a5a1
commit 805a725fe2
3 changed files with 63 additions and 37 deletions

View file

@ -11,10 +11,6 @@ install:
cp sparkleshare /usr/local/bin/ cp sparkleshare /usr/local/bin/
chmod 755 /usr/local/bin/sparkleshare chmod 755 /usr/local/bin/sparkleshare
cp data/icons /usr/share/ -R 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 gtk-update-icon-cache /usr/share/icons/hicolor -f
uninstall: uninstall:

View file

@ -23,18 +23,21 @@ using System.IO;
namespace SparkleShare { namespace SparkleShare {
public class SparkleUI { public class SparkleUI
{
private Process Process; private Process Process;
// Short alias for the translations // Short alias for the translations
public static string _ (string s) { public static string _ (string s)
{
return Catalog.GetString (s); return Catalog.GetString (s);
} }
public static SparkleStatusIcon NotificationIcon; public static SparkleStatusIcon NotificationIcon;
public SparkleUI (bool HideUI) { public SparkleUI (bool HideUI)
{
Process = new Process (); Process = new Process ();
Process.EnableRaisingEvents = true; Process.EnableRaisingEvents = true;
@ -43,24 +46,53 @@ namespace SparkleShare {
string SparklePath = SparklePaths.SparklePath; 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 // Create 'SparkleShare' folder in the user's home folder
// if it's not there already // if it's not there already
if (!Directory.Exists (SparklePath)) { if (!Directory.Exists (SparklePath)) {
Directory.CreateDirectory (SparklePath); Directory.CreateDirectory (SparklePath);
SparkleHelpers.DebugInfo ("Config", SparkleHelpers.DebugInfo ("Config", " Created '" + SparklePath + "'");
"Created '" + SparklePath + "'");
// Add a special icon to the SparkleShare folder // Add a special icon to the SparkleShare folder
switch (SparklePlatform.Name) { switch (SparklePlatform.Name) {
case "GNOME": case "GNOME":
Process.StartInfo.FileName = "gvfs-set-attribute"; Process.StartInfo.FileName = "gvfs-set-attribute";
Process.StartInfo.Arguments = Process.StartInfo.Arguments = SparklePath + " metadata::custom-icon " +
SparklePath + " metadata::custom-icon " + "file:///usr/share/icons/hicolor/48x48/places/" +
"file:///usr/share/icons/hicolor/48x48/places/" + "folder-sparkleshare.png";
"folder-sparkleshare.png";
Process.Start (); Process.Start ();
break; break;
} }
// Add the SparkleShare folder to the bookmarks // 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)) if (!Directory.Exists (SparklePaths.SparkleTmpPath))
Directory.CreateDirectory (SparklePaths.SparkleTmpPath); Directory.CreateDirectory (SparklePaths.SparkleTmpPath);
if (!HideUI) { if (!HideUI)
// Create the status icon
NotificationIcon = new SparkleStatusIcon (); NotificationIcon = new SparkleStatusIcon ();
}
UpdateRepositories (); UpdateRepositories ();
@ -156,56 +187,61 @@ namespace SparkleShare {
if (!Directory.Exists (ConfigPath)) { if (!Directory.Exists (ConfigPath)) {
Directory.CreateDirectory (ConfigPath); Directory.CreateDirectory (ConfigPath);
SparkleHelpers.DebugInfo ("Config", SparkleHelpers.DebugInfo ("Config", " Created '" + ConfigPath + "'");
"Created '" + ConfigPath + "'");
// Create a place to store the avatars // Create a place to store the avatars
Directory.CreateDirectory (AvatarPath); Directory.CreateDirectory (AvatarPath);
SparkleHelpers.DebugInfo ("Config", SparkleHelpers.DebugInfo ("Config", " Created '" + AvatarPath + "'");
"Created '" + AvatarPath + "'");
} }
string NotifySettingFile = string NotifySettingFile = SparkleHelpers.CombineMore (SparklePaths.SparkleConfigPath,
SparkleHelpers.CombineMore (SparklePaths.SparkleConfigPath, "sparkleshare.notify");
"sparkleshare.notify");
// Enable notifications by default // Enable notifications by default
if (!File.Exists (NotifySettingFile)) if (!File.Exists (NotifySettingFile))
File.Create (NotifySettingFile); File.Create (NotifySettingFile);
} }
public void UpdateRepositories () {
public void UpdateRepositories ()
{
string SparklePath = SparklePaths.SparklePath; string SparklePath = SparklePaths.SparklePath;
// Get all the repos in ~/SparkleShare // Get all the repos in ~/SparkleShare
SparkleRepo [] TmpRepos = SparkleRepo [] TmpRepos = new SparkleRepo [Directory.GetDirectories (SparklePath).Length];
new SparkleRepo [Directory.GetDirectories (SparklePath).Length];
int FolderCount = 0; int FolderCount = 0;
foreach (string Folder in Directory.GetDirectories (SparklePath)) { foreach (string Folder in Directory.GetDirectories (SparklePath)) {
// Check if the folder is a git repo // Check if the folder is a git repo
if (Directory.Exists (SparkleHelpers.CombineMore (Folder, if (Directory.Exists (SparkleHelpers.CombineMore (Folder, ".git"))) {
".git"))) {
TmpRepos [FolderCount] = new SparkleRepo (Folder); TmpRepos [FolderCount] = new SparkleRepo (Folder);
FolderCount++; FolderCount++;
// TODO: emblems don't work in nautilus // TODO: emblems don't show up in nautilus
// Attach emblems // Attach emblems
switch (SparklePlatform.Name) { switch (SparklePlatform.Name) {
case "GNOME": case "GNOME":
Process.StartInfo.FileName = "gvfs-set-attribute"; Process.StartInfo.FileName = "gvfs-set-attribute";
Process.StartInfo.Arguments = Process.StartInfo.Arguments = "-t string \"" + Folder +
"-t string \"" + Folder + "\" metadata::emblems [synced]"; "\" metadata::emblems [synced]";
Process.Start (); Process.Start ();
break; break;
} }
} }
} }
SparkleShare.Repositories = new SparkleRepo [FolderCount]; SparkleShare.Repositories = new SparkleRepo [FolderCount];
Array.Copy (TmpRepos, SparkleShare.Repositories, FolderCount); Array.Copy (TmpRepos, SparkleShare.Repositories, FolderCount);
} }
} }

View file

@ -1,6 +0,0 @@
[Desktop Entry]
Name=SparkleShare
Exec=sparkleshare start
Icon=folder-sparkleshare
Terminal=false
X-GNOME-Autostart-enabled=true