[infobar] new class [uihelpers] add GdkColorToHex [ui] cleanup

This commit is contained in:
Hylke Bons 2010-10-07 20:25:26 +01:00
parent 71f1252157
commit 677ec408e8
7 changed files with 119 additions and 93 deletions

View file

@ -10,6 +10,7 @@ LINK = $(REF_SPARKLESHARE)
SOURCES = \
SparkleBubble.cs \
SparkleEntry.cs \
SparkleInfobar.cs \
SparkleIntro.cs \
SparkleInvitation.cs \
SparkleLink.cs \

View file

@ -0,0 +1,55 @@
// SparkleShare, an instant update workflow to Git.
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
//
// 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 <http://www.gnu.org/licenses/>.
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 = "<b>" + title + "</b>\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);
}
}
}

View file

@ -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));
}
}
}

View file

@ -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 = "<b>" + _("This folder has unsynced changes") + "</b>\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 <SparkleCommit>
{

View file

@ -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 <SparkleRepo> ();
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 <SparkleRepo> ();
@ -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 ();

View file

@ -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));
}
}
}

View file

@ -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