From 677ec408e8aa24553e3b933e6a75b077cd84adda Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Thu, 7 Oct 2010 20:25:26 +0100 Subject: [PATCH] [infobar] new class [uihelpers] add GdkColorToHex [ui] cleanup --- SparkleShare/Makefile.am | 1 + SparkleShare/SparkleInfobar.cs | 55 ++++++++++++++++++++++ SparkleShare/SparkleIntro.cs | 15 +----- SparkleShare/SparkleLog.cs | 46 ++++--------------- SparkleShare/SparkleUI.cs | 79 +++++++++++++++++--------------- SparkleShare/SparkleUIHelpers.cs | 13 ++++++ SparkleShare/TODO_Luis.txt | 3 -- 7 files changed, 119 insertions(+), 93 deletions(-) create mode 100644 SparkleShare/SparkleInfobar.cs delete mode 100644 SparkleShare/TODO_Luis.txt diff --git a/SparkleShare/Makefile.am b/SparkleShare/Makefile.am index e898ceff..7dbf791a 100644 --- a/SparkleShare/Makefile.am +++ b/SparkleShare/Makefile.am @@ -10,6 +10,7 @@ LINK = $(REF_SPARKLESHARE) SOURCES = \ SparkleBubble.cs \ SparkleEntry.cs \ + SparkleInfobar.cs \ SparkleIntro.cs \ SparkleInvitation.cs \ SparkleLink.cs \ diff --git a/SparkleShare/SparkleInfobar.cs b/SparkleShare/SparkleInfobar.cs new file mode 100644 index 00000000..17d853f7 --- /dev/null +++ b/SparkleShare/SparkleInfobar.cs @@ -0,0 +1,55 @@ +// 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 Gtk; + +namespace SparkleShare { + + // An infobar + public class SparkleInfobar : EventBox + { + + public SparkleInfobar (string icon_name, string title, string text) + { + + Window window = new Window (WindowType.Popup) { + Name = "gtk-tooltip" + }; + + window.EnsureStyle (); + + Style = window.Style; + + Label label = new Label () { + Markup = "" + title + "\n" + text + }; + + HBox hbox = new HBox (false, 12) { + BorderWidth = 12 + }; + + hbox.PackStart (new Image (SparkleUIHelpers.GetIcon (icon_name, 24)), + false, false, 0); + + hbox.PackStart (label, false, false, 0); + + Add (hbox); + + } + + } + +} diff --git a/SparkleShare/SparkleIntro.cs b/SparkleShare/SparkleIntro.cs index 40b654d3..75f94dcc 100644 --- a/SparkleShare/SparkleIntro.cs +++ b/SparkleShare/SparkleIntro.cs @@ -47,7 +47,7 @@ namespace SparkleShare { { ServerFormOnly = false; - SecondaryTextColor = GdkColorToHex (Style.Foreground (StateType.Insensitive)); + SecondaryTextColor = SparkleUIHelpers.GdkColorToHex (Style.Foreground (StateType.Insensitive)); ShowAccountForm (); @@ -817,19 +817,6 @@ namespace SparkleShare { } - - // Converts a Gdk RGB color to a hex value. - // Example: from "rgb:0,0,0" to "#000000" - public 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)); - - } - } } diff --git a/SparkleShare/SparkleLog.cs b/SparkleShare/SparkleLog.cs index f5e99913..9d257fcc 100644 --- a/SparkleShare/SparkleLog.cs +++ b/SparkleShare/SparkleLog.cs @@ -236,30 +236,12 @@ namespace SparkleShare { if ((SparkleUI.Repositories.Find (delegate (SparkleRepo r) { return r.LocalPath.Equals (LocalPath); }) as SparkleRepo).HasUnsyncedChanges == true) { - Window window = new Window (WindowType.Popup) { - Name = "gtk-tooltip" - }; + string title = _("This folder has unsynced changes"); + string text = _("We will sync these once connected again"); - window.EnsureStyle (); + SparkleInfobar infobar = new SparkleInfobar ("dialog-warning", title, text); - EventBox warning_box = new EventBox () { - Style = window.Style - }; - - Label label = new Label () { - Markup = "" + _("This folder has unsynced changes") + "\n" + - _("We will sync these once connected again") - }; - - HBox warning_hbox = new HBox (false, 12) { - BorderWidth = 12 - }; - warning_hbox.PackStart (new Image (SparkleUIHelpers.GetIcon ("dialog-warning", 24)), false, false, 0); - - warning_hbox.PackStart (label, false, false, 0); - warning_box.Add (warning_hbox); - - layout_vertical.PackStart (warning_box, false, false, 0); + layout_vertical.PackStart (infobar, false, false, 0); } @@ -302,7 +284,7 @@ namespace SparkleShare { layout_vertical.PackStart (box, false, false, 0); Gdk.Color color = Style.Foreground (StateType.Insensitive); - string secondary_text_color = GdkColorToHex (color); + string secondary_text_color = SparkleUIHelpers.GdkColorToHex (color); foreach (SparkleCommit change_set in activity_day) { @@ -456,7 +438,7 @@ namespace SparkleShare { hbox.PackStart (vbox, true, true, 0); hbox.PackStart (new Label (""), false, false, 12); - + layout_vertical.PackStart (hbox, false, false, 18); } @@ -478,22 +460,10 @@ namespace SparkleShare { } - - // 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)); - - } - } - + + // All commits that happened on a day public class ActivityDay : List { diff --git a/SparkleShare/SparkleUI.cs b/SparkleShare/SparkleUI.cs index be60b0d0..39b16878 100644 --- a/SparkleShare/SparkleUI.cs +++ b/SparkleShare/SparkleUI.cs @@ -44,35 +44,30 @@ namespace SparkleShare { public SparkleUI (bool HideUI) { + // Initialize the application Gtk.Application.Init (); + // Set the process name to something differen than 'mono' SetProcessName ("sparkleshare"); // The list of repositories Repositories = new List (); - EnableSystemAutostart (); InstallLauncher (); - + EnableSystemAutostart (); // Create the SparkleShare folder and add it to the bookmarks - if (!Directory.Exists (SparklePaths.SparklePath)) { - - CreateSparkleShareFolder (); + if (CreateSparkleShareFolder ()) AddToBookmarks (); - } - - // Watch the SparkleShare folder and update the repo list - // when a deletion occurs. + // Watch the SparkleShare folder FileSystemWatcher watcher = new FileSystemWatcher (SparklePaths.SparklePath) { IncludeSubdirectories = false, EnableRaisingEvents = true, Filter = "*" }; - // Remove the repository when a delete event occurs watcher.Deleted += delegate (object o, FileSystemEventArgs args) { @@ -141,7 +136,7 @@ namespace SparkleShare { } - // Runs the main loop + // Runs the application public void Run () { @@ -151,7 +146,7 @@ namespace SparkleShare { // Creates a folder in the user's home folder to store configuration - public void CreateConfigurationFolders () + private void CreateConfigurationFolders () { if (!Directory.Exists (SparklePaths.SparkleTmpPath)) @@ -183,7 +178,7 @@ namespace SparkleShare { // Creates a .desktop entry in autostart folder to // start SparkleShare automatically at login - public void EnableSystemAutostart () + private void EnableSystemAutostart () { string autostart_path = SparkleHelpers.CombineMore (SparklePaths.HomePath, ".config", "autostart"); @@ -217,7 +212,7 @@ namespace SparkleShare { // Installs a launcher so the user can launch SparkleShare // from the Internet category if needed - public void InstallLauncher () + private void InstallLauncher () { string apps_path = SparkleHelpers.CombineMore (SparklePaths.HomePath, ".local", "share", "applications"); @@ -252,7 +247,7 @@ namespace SparkleShare { // Adds the SparkleShare folder to the user's // list of bookmarked places - public void AddToBookmarks () + private void AddToBookmarks () { string bookmarks_file_path = Path.Combine (SparklePaths.HomePath, ".gtk-bookmarks"); @@ -284,32 +279,40 @@ namespace SparkleShare { // Creates the SparkleShare folder in the user's home folder - public void CreateSparkleShareFolder () + private bool CreateSparkleShareFolder () { + + if (!Directory.Exists (SparklePaths.SparklePath)) { - Directory.CreateDirectory (SparklePaths.SparklePath); - SparkleHelpers.DebugInfo ("Config", "Created '" + 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 icon_file_path = SparkleHelpers.CombineMore (Defines.PREFIX, "share", "icons", "hicolor", + "48x48", "apps", "folder-sparkleshare.png"); - Process process = new Process (); + Process process = new Process (); - process.StartInfo.RedirectStandardOutput = true; - process.StartInfo.UseShellExecute = false; + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.UseShellExecute = false; + + // Add a special icon to the SparkleShare folder + process.StartInfo.FileName = "gvfs-set-attribute"; + process.StartInfo.Arguments = SparklePaths.SparklePath + " metadata::custom-icon " + + "file://" + icon_file_path; + process.Start (); + + return true; + + } + + return false; - // Add a special icon to the SparkleShare folder - process.StartInfo.FileName = "gvfs-set-attribute"; - process.StartInfo.Arguments = SparklePaths.SparklePath + " metadata::custom-icon " + - "file://" + icon_file_path; - process.Start (); - } // Shows a notification bubble when someone // made a change to the repository - public void ShowNewCommitBubble (string author, string email, string message, string repository_name) { + private void ShowNewCommitBubble (string author, string email, string message, string repository_name) { string notify_settings_file = SparkleHelpers.CombineMore (SparklePaths.SparkleConfigPath, "sparkleshare.notify"); @@ -338,7 +341,7 @@ namespace SparkleShare { // Shows a notification bubble when there // was a conflict - public void ShowConflictBubble (object o, EventArgs args) + private void ShowConflictBubble (object o, EventArgs args) { string title = _("Ouch! Mid-air collision!"); @@ -351,7 +354,7 @@ namespace SparkleShare { // Tells the statusicon to update its state - public void UpdateStatusIcon (object o, EventArgs args) + private void UpdateStatusIcon (object o, EventArgs args) { StatusIcon.ShowState (); @@ -360,7 +363,7 @@ namespace SparkleShare { // Updates the statusicon to the error state - public void UpdateStatusIconToError (object o, EventArgs args) + private void UpdateStatusIconToError (object o, EventArgs args) { StatusIcon.ShowState (true); @@ -370,7 +373,7 @@ namespace SparkleShare { // Adds a repository to the list of repositories and // updates the statusicon menu - public void AddRepository (string folder_path) + private void AddRepository (string folder_path) { // Check if the folder is a git repo @@ -412,7 +415,7 @@ namespace SparkleShare { Application.Invoke (UpdateStatusIcon); }; - repo.PushingFailed += delegate { + repo.PushingFailed += delegate { // TODO: use UpdateStatusIcon and check for HasUnsyncedChanges in SparkleStatusIcon Application.Invoke (UpdateStatusIconToError); }; @@ -436,7 +439,7 @@ namespace SparkleShare { // Removes a repository from the list of repositories and // updates the statusicon menu - public void RemoveRepository (string folder_path) + private void RemoveRepository (string folder_path) { string repo_name = Path.GetFileName (folder_path); @@ -470,7 +473,7 @@ namespace SparkleShare { // Updates the list of repositories with all the // folders in the SparkleShare folder - public void PopulateRepositories () + private void PopulateRepositories () { Repositories = new List (); @@ -485,7 +488,7 @@ namespace SparkleShare { // Warns the user implicitly that unicorns are actually lethal creatures - public static void CheckForUnicorns (string message) { + private static void CheckForUnicorns (string message) { message = message.ToLower (); diff --git a/SparkleShare/SparkleUIHelpers.cs b/SparkleShare/SparkleUIHelpers.cs index d9163527..288877bf 100644 --- a/SparkleShare/SparkleUIHelpers.cs +++ b/SparkleShare/SparkleUIHelpers.cs @@ -121,6 +121,19 @@ namespace SparkleShare { } + + // 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)); + + } + } } diff --git a/SparkleShare/TODO_Luis.txt b/SparkleShare/TODO_Luis.txt deleted file mode 100644 index 915312e9..00000000 --- a/SparkleShare/TODO_Luis.txt +++ /dev/null @@ -1,3 +0,0 @@ -so, i would like to be able to close the Event Log windows with ESC and CTRL+W -i think it can be done wit GtkAccelletor or in that area -GtkAccellerator