From 8ec306bf6ae01df48c51a1b1602f5383720a4ef5 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Tue, 16 Nov 2010 00:24:47 +0000 Subject: [PATCH] [controller] Make Controller an abstract class and provide a Linux implementation --- SparkleShare/Makefile.am | 1 + SparkleShare/SparkleController.cs | 135 +------------------- SparkleShare/SparkleLinController.cs | 180 +++++++++++++++++++++++++++ SparkleShare/SparkleShare.cs | 22 +++- 4 files changed, 203 insertions(+), 135 deletions(-) create mode 100644 SparkleShare/SparkleLinController.cs diff --git a/SparkleShare/Makefile.am b/SparkleShare/Makefile.am index 28025497..07e6643e 100644 --- a/SparkleShare/Makefile.am +++ b/SparkleShare/Makefile.am @@ -10,6 +10,7 @@ LINK = $(REF_SPARKLESHARE) SOURCES = \ SparkleBubble.cs \ SparkleController.cs \ + SparkleLinController.cs \ SparkleDialog.cs \ SparkleEntry.cs \ SparkleInfobar.cs \ diff --git a/SparkleShare/SparkleController.cs b/SparkleShare/SparkleController.cs index b7b0257b..10b7867f 100644 --- a/SparkleShare/SparkleController.cs +++ b/SparkleShare/SparkleController.cs @@ -27,7 +27,7 @@ using System.Threading; namespace SparkleShare { - public class SparkleController { + public abstract class SparkleController { public List Repositories; public string FolderSize; @@ -169,143 +169,18 @@ namespace SparkleShare { // Creates a .desktop entry in autostart folder to // start SparkleShare automatically at login - private void EnableSystemAutostart () - { - - 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" + - "Type=Application\n" + - "Name=SparkleShare\n" + - "Exec=sparkleshare start\n" + - "Icon=folder-sparkleshare\n" + - "Terminal=false\n" + - "X-GNOME-Autostart-enabled=true\n" + - "Categories=Network"); - writer.Close (); - - // Give the launcher the right permissions so it can be launched by the user - Syscall.chmod (desktopfile_path, FilePermissions.S_IRWXU); - - SparkleHelpers.DebugInfo ("Config", "Created '" + desktopfile_path + "'"); - - } - - } - + public abstract void EnableSystemAutostart (); // Installs a launcher so the user can launch SparkleShare // from the Internet category if needed - private void InstallLauncher () - { - - string apps_path = SparkleHelpers.CombineMore (SparklePaths.HomePath, ".local", "share", "applications"); - string desktopfile_path = SparkleHelpers.CombineMore (apps_path, "sparkleshare.desktop"); - - if (!File.Exists (desktopfile_path)) { - - if (!Directory.Exists (apps_path)) - - Directory.CreateDirectory (apps_path); - - TextWriter writer = new StreamWriter (desktopfile_path); - writer.WriteLine ("[Desktop Entry]\n" + - "Type=Application\n" + - "Name=SparkleShare\n" + - "Comment=Share documents\n" + - "Exec=sparkleshare start\n" + - "Icon=folder-sparkleshare\n" + - "Terminal=false\n" + - "Categories=Network;"); - writer.Close (); - - // Give the launcher the right permissions so it can be launched by the user - Syscall.chmod (desktopfile_path, FilePermissions.S_IRWXU); - - SparkleHelpers.DebugInfo ("Config", "Created '" + desktopfile_path + "'"); - - } - - } - + public abstract void InstallLauncher (); // Adds the SparkleShare folder to the user's // list of bookmarked places - private void AddToBookmarks () - { - - string bookmarks_file_path = Path.Combine (SparklePaths.HomePath, ".gtk-bookmarks"); - string sparkleshare_bookmark = "file://" + SparklePaths.SparklePath + " SparkleShare"; - - if (File.Exists (bookmarks_file_path)) { - - StreamReader reader = new StreamReader (bookmarks_file_path); - string bookmarks = reader.ReadToEnd (); - reader.Close (); - - if (!bookmarks.Contains (sparkleshare_bookmark)) { - - TextWriter writer = File.AppendText (bookmarks_file_path); - writer.WriteLine ("file://" + SparklePaths.SparklePath + " SparkleShare"); - writer.Close (); - - } - - } else { - - StreamWriter writer = new StreamWriter (bookmarks_file_path); - writer.WriteLine ("file://" + SparklePaths.SparklePath + " SparkleShare"); - writer.Close (); - - } - - } - + public abstract void AddToBookmarks (); // Creates the SparkleShare folder in the user's home folder - private bool CreateSparkleShareFolder () - { - - if (!Directory.Exists (SparklePaths.SparklePath)) { - - Directory.CreateDirectory (SparklePaths.SparklePath); - SparkleHelpers.DebugInfo ("Config", "Created '" + SparklePaths.SparklePath + "'"); - - string icon_file_path = SparkleHelpers.CombineMore (Defines.PREFIX, "share", "icons", "hicolor", - "48x48", "apps", "folder-sparkleshare.png"); - - string gvfs_command_path = SparkleHelpers.CombineMore (Path.VolumeSeparatorChar.ToString (), - "usr", "bin", "gvfs-set-attribute"); - - // Add a special icon to the SparkleShare folder - if (File.Exists (gvfs_command_path)) { - - Process process = new Process (); - - process.StartInfo.RedirectStandardOutput = true; - process.StartInfo.UseShellExecute = false; - - process.StartInfo.FileName = "gvfs-set-attribute"; - process.StartInfo.Arguments = SparklePaths.SparklePath + " metadata::custom-icon " + - "file://" + icon_file_path; - process.Start (); - - } - - return true; - - } - - return false; - - } + public abstract bool CreateSparkleShareFolder (); // Fires events for the current syncing state diff --git a/SparkleShare/SparkleLinController.cs b/SparkleShare/SparkleLinController.cs new file mode 100644 index 00000000..70b261c1 --- /dev/null +++ b/SparkleShare/SparkleLinController.cs @@ -0,0 +1,180 @@ +// SparkleShare, an instant update workflow to Git. +// Copyright (C) 2010 Hylke Bons +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using Mono.Unix; +using Mono.Unix.Native; +using SparkleLib; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading; + +namespace SparkleShare { + + public class SparkleLinController : SparkleController { + + public SparkleLinController () : base () + { + + } + + + // Creates a .desktop entry in autostart folder to + // start SparkleShare automatically at login + public override void EnableSystemAutostart () + { + + 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" + + "Type=Application\n" + + "Name=SparkleShare\n" + + "Exec=sparkleshare start\n" + + "Icon=folder-sparkleshare\n" + + "Terminal=false\n" + + "X-GNOME-Autostart-enabled=true\n" + + "Categories=Network"); + writer.Close (); + + // Give the launcher the right permissions so it can be launched by the user + Syscall.chmod (desktopfile_path, FilePermissions.S_IRWXU); + + SparkleHelpers.DebugInfo ("Config", "Created '" + desktopfile_path + "'"); + + } + + } + + + // Installs a launcher so the user can launch SparkleShare + // from the Internet category if needed + public override void InstallLauncher () + { + + string apps_path = SparkleHelpers.CombineMore (SparklePaths.HomePath, ".local", "share", "applications"); + string desktopfile_path = SparkleHelpers.CombineMore (apps_path, "sparkleshare.desktop"); + + if (!File.Exists (desktopfile_path)) { + + if (!Directory.Exists (apps_path)) + + Directory.CreateDirectory (apps_path); + + TextWriter writer = new StreamWriter (desktopfile_path); + writer.WriteLine ("[Desktop Entry]\n" + + "Type=Application\n" + + "Name=SparkleShare\n" + + "Comment=Share documents\n" + + "Exec=sparkleshare start\n" + + "Icon=folder-sparkleshare\n" + + "Terminal=false\n" + + "Categories=Network;"); + writer.Close (); + + // Give the launcher the right permissions so it can be launched by the user + Syscall.chmod (desktopfile_path, FilePermissions.S_IRWXU); + + SparkleHelpers.DebugInfo ("Config", "Created '" + desktopfile_path + "'"); + + } + + } + + + // Adds the SparkleShare folder to the user's + // list of bookmarked places + public override void AddToBookmarks () + { + + string bookmarks_file_path = Path.Combine (SparklePaths.HomePath, ".gtk-bookmarks"); + string sparkleshare_bookmark = "file://" + SparklePaths.SparklePath + " SparkleShare"; + + if (File.Exists (bookmarks_file_path)) { + + StreamReader reader = new StreamReader (bookmarks_file_path); + string bookmarks = reader.ReadToEnd (); + reader.Close (); + + if (!bookmarks.Contains (sparkleshare_bookmark)) { + + TextWriter writer = File.AppendText (bookmarks_file_path); + writer.WriteLine ("file://" + SparklePaths.SparklePath + " SparkleShare"); + writer.Close (); + + } + + } else { + + StreamWriter writer = new StreamWriter (bookmarks_file_path); + writer.WriteLine ("file://" + SparklePaths.SparklePath + " SparkleShare"); + writer.Close (); + + } + + } + + + // Creates the SparkleShare folder in the user's home folder + public override bool CreateSparkleShareFolder () + { + + if (!Directory.Exists (SparklePaths.SparklePath)) { + + Directory.CreateDirectory (SparklePaths.SparklePath); + SparkleHelpers.DebugInfo ("Config", "Created '" + SparklePaths.SparklePath + "'"); + + string icon_file_path = SparkleHelpers.CombineMore (Defines.PREFIX, "share", "icons", "hicolor", + "48x48", "apps", "folder-sparkleshare.png"); + + string gvfs_command_path = SparkleHelpers.CombineMore (Path.VolumeSeparatorChar.ToString (), + "usr", "bin", "gvfs-set-attribute"); + + // Add a special icon to the SparkleShare folder + if (File.Exists (gvfs_command_path)) { + + Process process = new Process (); + + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.UseShellExecute = false; + + process.StartInfo.FileName = "gvfs-set-attribute"; + process.StartInfo.Arguments = SparklePaths.SparklePath + " metadata::custom-icon " + + "file://" + icon_file_path; + process.Start (); + + } + + return true; + + } + + return false; + + } + + } + +} diff --git a/SparkleShare/SparkleShare.cs b/SparkleShare/SparkleShare.cs index 36e39d53..46365136 100644 --- a/SparkleShare/SparkleShare.cs +++ b/SparkleShare/SparkleShare.cs @@ -84,11 +84,23 @@ namespace SparkleShare { if (show_help) ShowHelp (p); - Controller = new SparkleController (); -if (!hide_ui){ - UI = new SparkleUI (); -UI.Run (); -} + // TODO: Detect this properly + string Platform = "Lin"; + + if (Platform.Equals ("Lin")) + Controller = new SparkleLinController (); +// else if (Platform.Equals ("Mac")) +// Controller = new SparkleMacController (); +// else if (Platform.Equals ("Win")) +// Controller = new SparkleWinController (); + + if (!hide_ui) { + + UI = new SparkleUI (); + UI.Run (); + + } + }