linux controller uihelpers window: fix whitespace, style, and remove obsolete code
This commit is contained in:
parent
c16b883ab2
commit
9901ca56ba
|
@ -14,8 +14,7 @@
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
using Mono.Unix;
|
|
||||||
using SparkleLib;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
@ -24,218 +23,183 @@ using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
|
using Mono.Unix;
|
||||||
|
using SparkleLib;
|
||||||
|
|
||||||
namespace SparkleShare {
|
namespace SparkleShare {
|
||||||
|
|
||||||
public class SparkleLinController : SparkleController {
|
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
|
||||||
|
UnixFileInfo file_info = new UnixFileInfo (desktopfile_path);
|
||||||
|
file_info.Create (FileAccessPermissions.UserReadWriteExecute);
|
||||||
|
|
||||||
|
SparkleHelpers.DebugInfo ("Controller", "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
|
||||||
|
UnixFileInfo file_info = new UnixFileInfo (desktopfile_path);
|
||||||
|
file_info.FileAccessPermissions = FileAccessPermissions.UserReadWriteExecute;
|
||||||
|
|
||||||
|
SparkleHelpers.DebugInfo ("Controller", "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 ("Controller", "Created '" + SparklePaths.SparklePath + "'");
|
||||||
|
|
||||||
|
string icon_file_path = SparkleHelpers.CombineMore (Defines.DATAROOTDIR, "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 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 SparkleLinController () : base ()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
public override void OpenSparkleShareFolder (string subfolder)
|
||||||
|
{
|
||||||
|
string open_command_path = SparkleHelpers.CombineMore (Path.VolumeSeparatorChar.ToString (),
|
||||||
|
"usr", "bin", "xdg-open");
|
||||||
|
|
||||||
|
if (!File.Exists (open_command_path))
|
||||||
|
return;
|
||||||
|
|
||||||
// Creates a .desktop entry in autostart folder to
|
string folder = SparkleHelpers.CombineMore (SparklePaths.SparklePath, subfolder);
|
||||||
// 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
|
|
||||||
UnixFileInfo file_info = new UnixFileInfo (desktopfile_path);
|
|
||||||
file_info.Create (FileAccessPermissions.UserReadWriteExecute);
|
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Controller", "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
|
|
||||||
UnixFileInfo file_info = new UnixFileInfo (desktopfile_path);
|
|
||||||
file_info.FileAccessPermissions = FileAccessPermissions.UserReadWriteExecute;
|
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Controller", "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 ("Controller", "Created '" + SparklePaths.SparklePath + "'");
|
|
||||||
|
|
||||||
string icon_file_path = SparkleHelpers.CombineMore (Defines.DATAROOTDIR, "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 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");
|
|
||||||
|
|
||||||
if (!File.Exists (open_command_path))
|
|
||||||
return;
|
|
||||||
|
|
||||||
string folder = SparkleHelpers.CombineMore (SparklePaths.SparklePath, subfolder);
|
|
||||||
|
|
||||||
Process process = new Process ();
|
|
||||||
process.StartInfo.Arguments = folder.Replace (" ", "\\ "); // Escape space-characters
|
|
||||||
process.StartInfo.FileName = "xdg-open";
|
|
||||||
process.Start ();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Process process = new Process ();
|
||||||
|
process.StartInfo.Arguments = folder.Replace (" ", "\\ "); // Escape space-characters
|
||||||
|
process.StartInfo.FileName = "xdg-open";
|
||||||
|
process.Start ();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,117 +24,45 @@ using System.Text;
|
||||||
|
|
||||||
namespace SparkleShare {
|
namespace SparkleShare {
|
||||||
|
|
||||||
public static class SparkleUIHelpers {
|
public static class SparkleUIHelpers {
|
||||||
|
|
||||||
// Creates an MD5 hash of input
|
// Creates an MD5 hash of input
|
||||||
public static string GetMD5 (string s)
|
public static string GetMD5 (string s)
|
||||||
{
|
{
|
||||||
MD5 md5 = new MD5CryptoServiceProvider ();
|
MD5 md5 = new MD5CryptoServiceProvider ();
|
||||||
Byte[] bytes = ASCIIEncoding.Default.GetBytes (s);
|
Byte[] bytes = ASCIIEncoding.Default.GetBytes (s);
|
||||||
Byte[] encodedBytes = md5.ComputeHash (bytes);
|
Byte[] encodedBytes = md5.ComputeHash (bytes);
|
||||||
return BitConverter.ToString (encodedBytes).ToLower ().Replace ("-", "");
|
return BitConverter.ToString (encodedBytes).ToLower ().Replace ("-", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Gets the avatar for a specific email address and size
|
// Looks up an icon from the system's theme
|
||||||
public static string GetAvatar (string email, int size)
|
public static Gdk.Pixbuf GetIcon (string name, int size)
|
||||||
{
|
{
|
||||||
|
IconTheme icon_theme = new IconTheme ();
|
||||||
|
icon_theme.AppendSearchPath (SparklePaths.SparkleIconPath);
|
||||||
|
icon_theme.AppendSearchPath (SparklePaths.SparkleLocalIconPath);
|
||||||
|
|
||||||
string avatar_path = SparkleHelpers.CombineMore (SparklePaths.SparkleLocalIconPath,
|
try {
|
||||||
size + "x" + size, "status");
|
return icon_theme.LoadIcon (name, size, IconLookupFlags.GenericFallback);
|
||||||
|
} catch {
|
||||||
if (!Directory.Exists (avatar_path)) {
|
try {
|
||||||
|
return icon_theme.LoadIcon ("gtk-missing-image", size, IconLookupFlags.GenericFallback);
|
||||||
Directory.CreateDirectory (avatar_path);
|
} catch {
|
||||||
SparkleHelpers.DebugInfo ("Config", "Created '" + avatar_path + "'");
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
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
|
// Converts a Gdk RGB color to a hex value.
|
||||||
public static Gdk.Pixbuf GetIcon (string name, int size)
|
// Example: from "rgb:0,0,0" to "#000000"
|
||||||
{
|
public static string GdkColorToHex (Gdk.Color color)
|
||||||
|
{
|
||||||
IconTheme icon_theme = new IconTheme ();
|
return String.Format ("#{0:X2}{1:X2}{2:X2}",
|
||||||
icon_theme.AppendSearchPath (SparklePaths.SparkleIconPath);
|
(int) Math.Truncate (color.Red / 256.00),
|
||||||
icon_theme.AppendSearchPath (SparklePaths.SparkleLocalIconPath);
|
(int) Math.Truncate (color.Green / 256.00),
|
||||||
|
(int) Math.Truncate (color.Blue / 256.00));
|
||||||
try {
|
}
|
||||||
|
}
|
||||||
return icon_theme.LoadIcon (name, size, IconLookupFlags.GenericFallback);
|
|
||||||
|
|
||||||
} catch {
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
return icon_theme.LoadIcon ("gtk-missing-image", size, IconLookupFlags.GenericFallback);
|
|
||||||
|
|
||||||
} catch {
|
|
||||||
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Converts a Gdk RGB color to a hex value.
|
|
||||||
// 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));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,7 @@
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
using Gtk;
|
|
||||||
using Mono.Unix;
|
|
||||||
using SparkleLib;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
@ -24,127 +22,113 @@ using System.IO;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Timers;
|
using System.Timers;
|
||||||
|
|
||||||
|
using Gtk;
|
||||||
|
using Mono.Unix;
|
||||||
|
using SparkleLib;
|
||||||
|
|
||||||
namespace SparkleShare {
|
namespace SparkleShare {
|
||||||
|
|
||||||
public class SparkleWindow : Window {
|
public class SparkleWindow : Window {
|
||||||
|
|
||||||
private HBox HBox;
|
private HBox HBox;
|
||||||
private VBox VBox;
|
private VBox VBox;
|
||||||
private VBox Wrapper;
|
private VBox Wrapper;
|
||||||
private HButtonBox Buttons;
|
private HButtonBox Buttons;
|
||||||
|
|
||||||
|
|
||||||
public SparkleWindow () : base ("")
|
public SparkleWindow () : base ("")
|
||||||
{
|
{
|
||||||
|
Title = "SparkleShare Setup";
|
||||||
|
BorderWidth = 0;
|
||||||
|
IconName = "folder-sparkleshare";
|
||||||
|
Resizable = false;
|
||||||
|
WindowPosition = WindowPosition.Center;
|
||||||
|
|
||||||
Title = "SparkleShare Setup";
|
SetSizeRequest (680, 440);
|
||||||
BorderWidth = 0;
|
|
||||||
IconName = "folder-sparkleshare";
|
|
||||||
Resizable = false;
|
|
||||||
WindowPosition = WindowPosition.Center;
|
|
||||||
|
|
||||||
SetSizeRequest (680, 440);
|
DeleteEvent += delegate (object o, DeleteEventArgs args) {
|
||||||
|
args.RetVal = true;
|
||||||
|
Close ();
|
||||||
|
};
|
||||||
|
|
||||||
DeleteEvent += delegate (object o, DeleteEventArgs args) {
|
HBox = new HBox (false, 6);
|
||||||
|
|
||||||
args.RetVal = true;
|
VBox = new VBox (false, 0);
|
||||||
Close ();
|
|
||||||
|
|
||||||
};
|
Wrapper = new VBox (false, 0) {
|
||||||
|
BorderWidth = 30
|
||||||
|
};
|
||||||
|
|
||||||
HBox = new HBox (false, 6);
|
Buttons = CreateButtonBox ();
|
||||||
|
|
||||||
VBox = new VBox (false, 0);
|
VBox.PackStart (Wrapper, true, true, 0);
|
||||||
|
VBox.PackStart (Buttons, false, false, 0);
|
||||||
|
|
||||||
Wrapper = new VBox (false, 0) {
|
EventBox box = new EventBox ();
|
||||||
BorderWidth = 30
|
Gdk.Color bg_color = new Gdk.Color ();
|
||||||
};
|
Gdk.Color.Parse ("#2e3336", ref bg_color);
|
||||||
|
box.ModifyBg (StateType.Normal, bg_color);
|
||||||
|
|
||||||
Buttons = CreateButtonBox ();
|
string image_path = SparkleHelpers.CombineMore (Defines.DATAROOTDIR, "sparkleshare",
|
||||||
|
"pixmaps", "side-splash.png");
|
||||||
|
|
||||||
VBox.PackStart (Wrapper, true, true, 0);
|
Image side_splash = new Image (image_path) {
|
||||||
VBox.PackStart (Buttons, false, false, 0);
|
Yalign = 1
|
||||||
|
};
|
||||||
|
|
||||||
EventBox box = new EventBox ();
|
box.Add (side_splash);
|
||||||
Gdk.Color bg_color = new Gdk.Color ();
|
|
||||||
Gdk.Color.Parse ("#2e3336", ref bg_color);
|
|
||||||
box.ModifyBg (StateType.Normal, bg_color);
|
|
||||||
|
|
||||||
string image_path = SparkleHelpers.CombineMore (Defines.DATAROOTDIR, "sparkleshare",
|
HBox.PackStart (box, false, false, 0);
|
||||||
"pixmaps", "side-splash.png");
|
HBox.PackStart (VBox, true, true, 0);
|
||||||
|
|
||||||
Image side_splash = new Image (image_path) {
|
base.Add (HBox);
|
||||||
Yalign = 1
|
}
|
||||||
};
|
|
||||||
|
|
||||||
box.Add (side_splash);
|
|
||||||
|
|
||||||
HBox.PackStart (box, false, false, 0);
|
|
||||||
HBox.PackStart (VBox, true, true, 0);
|
|
||||||
|
|
||||||
base.Add (HBox);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private HButtonBox CreateButtonBox ()
|
private HButtonBox CreateButtonBox ()
|
||||||
{
|
{
|
||||||
|
return new HButtonBox () {
|
||||||
return new HButtonBox () {
|
BorderWidth = 12,
|
||||||
BorderWidth = 12,
|
Layout = ButtonBoxStyle.End,
|
||||||
Layout = ButtonBoxStyle.End,
|
Spacing = 6
|
||||||
Spacing = 6
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void AddButton (Button button)
|
public void AddButton (Button button)
|
||||||
{
|
{
|
||||||
|
Buttons.Add (button);
|
||||||
Buttons.Add (button);
|
ShowAll ();
|
||||||
ShowAll ();
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
new public void Add (Widget widget)
|
new public void Add (Widget widget)
|
||||||
{
|
{
|
||||||
|
Wrapper.PackStart (widget, true, true, 0);
|
||||||
Wrapper.PackStart (widget, true, true, 0);
|
ShowAll ();
|
||||||
ShowAll ();
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void Reset ()
|
public void Reset ()
|
||||||
{
|
{
|
||||||
|
if (Wrapper.Children.Length > 0)
|
||||||
|
Wrapper.Remove (Wrapper.Children [0]);
|
||||||
|
|
||||||
if (Wrapper.Children.Length > 0)
|
foreach (Button button in Buttons)
|
||||||
Wrapper.Remove (Wrapper.Children [0]);
|
Buttons.Remove (button);
|
||||||
|
|
||||||
foreach (Button button in Buttons)
|
ShowAll ();
|
||||||
Buttons.Remove (button);
|
}
|
||||||
|
|
||||||
ShowAll ();
|
new public void ShowAll ()
|
||||||
|
{
|
||||||
}
|
Present ();
|
||||||
|
base.ShowAll ();
|
||||||
new public void ShowAll ()
|
}
|
||||||
{
|
|
||||||
|
|
||||||
Present ();
|
|
||||||
base.ShowAll ();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Close ()
|
|
||||||
{
|
|
||||||
|
|
||||||
HideAll ();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public void Close ()
|
||||||
|
{
|
||||||
|
HideAll ();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue