linux controller uihelpers window: fix whitespace, style, and remove obsolete code

This commit is contained in:
Hylke Bons 2011-05-14 00:41:53 +01:00
parent c16b883ab2
commit 9901ca56ba
3 changed files with 263 additions and 387 deletions

View file

@ -14,8 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using Mono.Unix;
using SparkleLib;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@ -24,6 +23,9 @@ using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using Mono.Unix;
using SparkleLib;
namespace SparkleShare {
public class SparkleLinController : SparkleController {
@ -38,12 +40,10 @@ namespace SparkleShare {
// 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);
@ -63,9 +63,7 @@ namespace SparkleShare {
file_info.Create (FileAccessPermissions.UserReadWriteExecute);
SparkleHelpers.DebugInfo ("Controller", "Created: " + desktopfile_path);
}
}
@ -73,12 +71,10 @@ namespace 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);
@ -98,9 +94,7 @@ namespace SparkleShare {
file_info.FileAccessPermissions = FileAccessPermissions.UserReadWriteExecute;
SparkleHelpers.DebugInfo ("Controller", "Created '" + desktopfile_path + "'");
}
}
@ -108,39 +102,30 @@ namespace SparkleShare {
// 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);
@ -154,73 +139,55 @@ namespace SparkleShare {
// 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 override string EventLogHTML {
get {
string path = SparkleHelpers.CombineMore (Defines.PREFIX,
"share", "sparkleshare", "html", "event-log.html");
return String.Join (Environment.NewLine, File.ReadAllLines (path));
}
}
public override string DayEntryHTML {
get {
string path = SparkleHelpers.CombineMore (Defines.PREFIX,
"share", "sparkleshare", "html", "day-entry.html");
return String.Join (Environment.NewLine, File.ReadAllLines (path));
}
}
public override string EventEntryHTML {
get {
string path = SparkleHelpers.CombineMore (Defines.PREFIX,
"share", "sparkleshare", "html", "event-entry.html");
return String.Join (Environment.NewLine, File.ReadAllLines (path));
}
}
public override void OpenSparkleShareFolder (string subfolder)
{
string open_command_path = SparkleHelpers.CombineMore (Path.VolumeSeparatorChar.ToString (),
"usr", "bin", "xdg-open");
@ -233,9 +200,6 @@ namespace SparkleShare {
process.StartInfo.Arguments = folder.Replace (" ", "\\ "); // Escape space-characters
process.StartInfo.FileName = "xdg-open";
process.Start ();
}
}
}

View file

@ -36,90 +36,22 @@ namespace SparkleShare {
}
// Gets the avatar for a specific email address and size
public static string GetAvatar (string email, int size)
{
string avatar_path = SparkleHelpers.CombineMore (SparklePaths.SparkleLocalIconPath,
size + "x" + size, "status");
if (!Directory.Exists (avatar_path)) {
Directory.CreateDirectory (avatar_path);
SparkleHelpers.DebugInfo ("Config", "Created '" + avatar_path + "'");
}
string avatar_file_path = SparkleHelpers.CombineMore (avatar_path, "avatar-" + email);
if (File.Exists (avatar_file_path)) {
return avatar_file_path;
} else {
// Let's try to get the person's gravatar for next time
WebClient web_client = new WebClient ();
Uri uri = new Uri ("http://www.gravatar.com/avatar/" + GetMD5 (email) +
".jpg?s=" + size + "&d=404");
string tmp_file_path = SparkleHelpers.CombineMore (SparklePaths.SparkleTmpPath, email + size);
if (!File.Exists (tmp_file_path)) {
web_client.DownloadFileAsync (uri, tmp_file_path);
web_client.DownloadFileCompleted += delegate {
if (File.Exists (avatar_file_path))
File.Delete (avatar_file_path);
FileInfo tmp_file_info = new FileInfo (tmp_file_path);
if (tmp_file_info.Length > 255)
File.Move (tmp_file_path, avatar_file_path);
};
}
// Fall back to a generic icon if there is no gravatar
if (File.Exists (avatar_file_path))
return avatar_file_path;
else
return null;
}
}
// Looks up an icon from the system's theme
public static Gdk.Pixbuf GetIcon (string name, int size)
{
IconTheme icon_theme = new IconTheme ();
icon_theme.AppendSearchPath (SparklePaths.SparkleIconPath);
icon_theme.AppendSearchPath (SparklePaths.SparkleLocalIconPath);
try {
return icon_theme.LoadIcon (name, size, IconLookupFlags.GenericFallback);
} catch {
try {
return icon_theme.LoadIcon ("gtk-missing-image", size, IconLookupFlags.GenericFallback);
} catch {
return null;
}
}
}
@ -127,14 +59,10 @@ namespace SparkleShare {
// Example: from "rgb:0,0,0" to "#000000"
public static string GdkColorToHex (Gdk.Color color)
{
return String.Format ("#{0:X2}{1:X2}{2:X2}",
(int) Math.Truncate (color.Red / 256.00),
(int) Math.Truncate (color.Green / 256.00),
(int) Math.Truncate (color.Blue / 256.00));
}
}
}

View file

@ -14,9 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using Gtk;
using Mono.Unix;
using SparkleLib;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@ -24,6 +22,10 @@ using System.IO;
using System.Text.RegularExpressions;
using System.Timers;
using Gtk;
using Mono.Unix;
using SparkleLib;
namespace SparkleShare {
public class SparkleWindow : Window {
@ -36,7 +38,6 @@ namespace SparkleShare {
public SparkleWindow () : base ("")
{
Title = "SparkleShare Setup";
BorderWidth = 0;
IconName = "folder-sparkleshare";
@ -46,10 +47,8 @@ namespace SparkleShare {
SetSizeRequest (680, 440);
DeleteEvent += delegate (object o, DeleteEventArgs args) {
args.RetVal = true;
Close ();
};
HBox = new HBox (false, 6);
@ -83,43 +82,35 @@ namespace SparkleShare {
HBox.PackStart (VBox, true, true, 0);
base.Add (HBox);
}
private HButtonBox CreateButtonBox ()
{
return new HButtonBox () {
BorderWidth = 12,
Layout = ButtonBoxStyle.End,
Spacing = 6
};
}
public void AddButton (Button button)
{
Buttons.Add (button);
ShowAll ();
}
new public void Add (Widget widget)
{
Wrapper.PackStart (widget, true, true, 0);
ShowAll ();
}
public void Reset ()
{
if (Wrapper.Children.Length > 0)
Wrapper.Remove (Wrapper.Children [0]);
@ -127,24 +118,17 @@ namespace SparkleShare {
Buttons.Remove (button);
ShowAll ();
}
new public void ShowAll ()
{
Present ();
base.ShowAll ();
}
public void Close ()
{
HideAll ();
}
}
}