ui: Port all the things to GTK+3

This commit is contained in:
Hylke Bons 2013-10-08 20:18:53 +02:00
parent 32aa9f909e
commit c94b5d57c9
6 changed files with 115 additions and 128 deletions

View file

@ -32,25 +32,25 @@ namespace SparkleShare {
public SparkleAbout () : base ("") public SparkleAbout () : base ("")
{ {
DefaultSize = new Gdk.Size (600, 260); SetSizeRequest (600, 260);
Resizable = false; Resizable = false;
BorderWidth = 0; BorderWidth = 0;
IconName = "folder-sparkleshare"; IconName = "folder-sparkleshare";
WindowPosition = WindowPosition.Center; WindowPosition = WindowPosition.Center;
Title = "About SparkleShare"; Title = "About SparkleShare";
AppPaintable = true;
CssProvider css_provider = new CssProvider ();
string image_path = new string [] { SparkleUI.AssetsPath, "pixmaps", "about.png" }.Combine (); string image_path = new string [] { SparkleUI.AssetsPath, "pixmaps", "about.png" }.Combine ();
css_provider.LoadFromData ("GtkWindow {" +
"background-image: url('" + image_path + "');" +
"background-repeat: no-repeat;" +
"background-position: left bottom;" +
"}");
Realize (); StyleContext.AddProvider (css_provider, 800);
Gdk.Pixbuf buf = new Gdk.Pixbuf (image_path);
Gdk.Pixmap map, map2;
buf.RenderPixmapAndMask (out map, out map2, 255);
GdkWindow.SetBackPixmap (map, false);
CreateAbout (); CreateAbout ();
DeleteEvent += delegate (object o, DeleteEventArgs args) { DeleteEvent += delegate (object o, DeleteEventArgs args) {
Controller.WindowClosed (); Controller.WindowClosed ();
args.RetVal = true; args.RetVal = true;
@ -65,9 +65,7 @@ namespace SparkleShare {
}; };
Controller.HideWindowEvent += delegate { Controller.HideWindowEvent += delegate {
Application.Invoke (delegate { Application.Invoke (delegate { Hide (); });
HideAll ();
});
}; };
Controller.ShowWindowEvent += delegate { Controller.ShowWindowEvent += delegate {
@ -92,13 +90,13 @@ namespace SparkleShare {
Markup = string.Format ("<span font_size='small' fgcolor='white'>version {0}</span>", Markup = string.Format ("<span font_size='small' fgcolor='white'>version {0}</span>",
Controller.RunningVersion), Controller.RunningVersion),
Xalign = 0, Xalign = 0,
Xpad = 300 Xpad = 0
}; };
this.updates = new Label () { this.updates = new Label () {
Markup = "<span font_size='small' fgcolor='#729fcf'>Checking for updates...</span>", Markup = "<span font_size='small' fgcolor='#a8bbcf'>Checking for updates...</span>",
Xalign = 0, Xalign = 0,
Xpad = 300 Xpad = 0
}; };
Label copyright = new Label () { Label copyright = new Label () {
@ -107,7 +105,7 @@ namespace SparkleShare {
"Hylke Bons and others." + "Hylke Bons and others." +
"</span>", "</span>",
Xalign = 0, Xalign = 0,
Xpad = 300 Xpad = 0
}; };
Label license = new Label () { Label license = new Label () {
@ -117,39 +115,35 @@ namespace SparkleShare {
"SparkleShare is Open Source software. You are free to use, modify, " + "SparkleShare is Open Source software. You are free to use, modify, " +
"and redistribute it under the GNU General Public License version 3 or later." + "and redistribute it under the GNU General Public License version 3 or later." +
"</span>", "</span>",
WidthRequest = 330,
Wrap = true, Wrap = true,
Xalign = 0, Xalign = 0
Xpad = 300,
}; };
VBox layout_vertical = new VBox (false, 0) { VBox layout_vertical = new VBox (false, 0);
BorderWidth = 0, HBox links_layout = new HBox (false, 16);
HeightRequest = 260,
WidthRequest = 640
};
HBox links_layout = new HBox (false, 6);
SparkleLink website_link = new SparkleLink ("Website", Controller.WebsiteLinkAddress); SparkleLink website_link = new SparkleLink ("Website", Controller.WebsiteLinkAddress);
SparkleLink credits_link = new SparkleLink ("Credits", Controller.CreditsLinkAddress); SparkleLink credits_link = new SparkleLink ("Credits", Controller.CreditsLinkAddress);
SparkleLink report_problem_link = new SparkleLink ("Report a problem", Controller.ReportProblemLinkAddress); SparkleLink report_problem_link = new SparkleLink ("Report a problem", Controller.ReportProblemLinkAddress);
SparkleLink debug_log_link = new SparkleLink ("Debug log", Controller.DebugLogLinkAddress); SparkleLink debug_log_link = new SparkleLink ("Debug log", Controller.DebugLogLinkAddress);
links_layout.PackStart (new Label (""), false, false, 143); links_layout.PackStart (website_link, false, false, 0);
links_layout.PackStart (website_link, false, false, 9); links_layout.PackStart (credits_link, false, false, 0);
links_layout.PackStart (credits_link, false, false, 9); links_layout.PackStart (report_problem_link, false, false, 0);
links_layout.PackStart (report_problem_link, false, false, 9); links_layout.PackStart (debug_log_link, false, false, 0);
links_layout.PackStart (debug_log_link, false, false, 9);
layout_vertical.PackStart (new Label (""), false, false, 42); layout_vertical.PackStart (new Label (""), true, true, 0);
layout_vertical.PackStart (version, false, false, 0); layout_vertical.PackStart (version, false, false, 0);
layout_vertical.PackStart (this.updates, false, false, 0); layout_vertical.PackStart (this.updates, false, false, 0);
layout_vertical.PackStart (copyright, false, false, 9); layout_vertical.PackStart (copyright, false, false, 6);
layout_vertical.PackStart (license, false, false, 0); layout_vertical.PackStart (license, false, false, 6);
layout_vertical.PackStart (links_layout, false, false, 12); layout_vertical.PackStart (links_layout, false, false, 16);
Add (layout_vertical); HBox layout_horizontal = new HBox (false, 0);
layout_horizontal.PackStart (new Label (""), false, false, 149);
layout_horizontal.PackStart (layout_vertical, false, false, 0);
Add (layout_horizontal);
} }
} }
@ -164,17 +158,9 @@ namespace SparkleShare {
Markup = "<span size='small' fgcolor='#729fcf' underline='single'>" + text + "</span>" Markup = "<span size='small' fgcolor='#729fcf' underline='single'>" + text + "</span>"
}; };
EnterNotifyEvent += delegate { EnterNotifyEvent += delegate { Window.Cursor = new Gdk.Cursor (Gdk.CursorType.Hand1); };
GdkWindow.Cursor = new Gdk.Cursor (Gdk.CursorType.Hand1); LeaveNotifyEvent += delegate { Window.Cursor = new Gdk.Cursor (Gdk.CursorType.Arrow); };
}; ButtonPressEvent += delegate { Program.Controller.OpenWebsite (url); };
LeaveNotifyEvent += delegate {
GdkWindow.Cursor = new Gdk.Cursor (Gdk.CursorType.Arrow);
};
ButtonPressEvent += delegate {
Program.Controller.OpenWebsite (url);
};
Add (label); Add (label);
} }

View file

@ -18,7 +18,7 @@
using System; using System;
using Gtk; using Gtk;
using Notifications; //using Notifications;
using SparkleLib; using SparkleLib;
namespace SparkleShare { namespace SparkleShare {
@ -29,22 +29,12 @@ namespace SparkleShare {
public SparkleBubbles () public SparkleBubbles ()
{ {/*
Controller.ShowBubbleEvent += delegate (string title, string subtext, string image_path) { Controller.ShowBubbleEvent += delegate (string title, string subtext, string image_path) {
if (!Program.Controller.NotificationsEnabled) if (!Program.Controller.NotificationsEnabled)
return; return;
try { try {
// Debug information for https://github.com/hbons/SparkleShare/issues/1362
if (title.Length > 255) {
SparkleLogger.LogInfo ("Notification", "Long string detected, truncating 'title'");
title = title.Substring (0, 255) + "...";
} else if (subtext.Length > 255) {
SparkleLogger.LogInfo ("Notification", "Long string detected, truncating 'subtext'");
title = title.Substring (0, 255) + "...";
}
Notification notification = new Notification () { Notification notification = new Notification () {
Summary = title, Summary = title,
Body = subtext, Body = subtext,
@ -67,7 +57,7 @@ namespace SparkleShare {
} catch (Exception e) { } catch (Exception e) {
SparkleLogger.LogInfo ("Notification", "Error showing notification: ", e); SparkleLogger.LogInfo ("Notification", "Error showing notification: ", e);
} }
}; };*/
} }
} }
} }

View file

@ -21,7 +21,7 @@ using System.Threading;
using Gtk; using Gtk;
using Mono.Unix; using Mono.Unix;
using WebKit; // using WebKit;
using IO = System.IO; using IO = System.IO;
@ -38,7 +38,7 @@ namespace SparkleShare {
private HBox combo_box_wrapper; private HBox combo_box_wrapper;
private EventBox content_wrapper; private EventBox content_wrapper;
private ScrolledWindow scrolled_window; private ScrolledWindow scrolled_window;
private WebView web_view; // private WebView web_view;
private SparkleSpinner spinner; private SparkleSpinner spinner;
@ -90,19 +90,20 @@ namespace SparkleShare {
this.content_wrapper = new EventBox (); this.content_wrapper = new EventBox ();
this.scrolled_window = new ScrolledWindow (); this.scrolled_window = new ScrolledWindow ();
Gdk.Color white = new Gdk.Color(); // TODO: check
Gdk.Color.Parse ("white", ref white); CssProvider css_provider= new CssProvider ();
css_provider.LoadFromData ("GtkWindow { background-color: #ffffff; }");
this.content_wrapper.ModifyBg (StateType.Normal, white); StyleContext.AddProvider (css_provider, 800);
/*
this.web_view = new WebView () { this.web_view = new WebView () {
Editable = false Editable = false
}; };
this.web_view.NavigationRequested += WebViewNavigationRequested; this.web_view.NavigationRequested += WebViewNavigationRequested;
*/
this.scrolled_window.Add (this.web_view); this.scrolled_window.Add (new Button ("WebView"));
this.content_wrapper.Add (this.spinner); this.content_wrapper.Add (this.spinner);
this.spinner.Start (); this.spinner.Start ();
@ -118,7 +119,7 @@ namespace SparkleShare {
Controller.HideWindowEvent += delegate { Controller.HideWindowEvent += delegate {
Application.Invoke (delegate { Application.Invoke (delegate {
HideAll (); Hide ();
if (this.content_wrapper.Child != null) if (this.content_wrapper.Child != null)
this.content_wrapper.Remove (this.content_wrapper.Child); this.content_wrapper.Remove (this.content_wrapper.Child);
@ -190,7 +191,7 @@ namespace SparkleShare {
}; };
} }
/*
private void WebViewNavigationRequested (object o, WebKit.NavigationRequestedArgs args) { private void WebViewNavigationRequested (object o, WebKit.NavigationRequestedArgs args) {
Controller.LinkClicked (args.Request.Uri); Controller.LinkClicked (args.Request.Uri);
@ -198,7 +199,7 @@ namespace SparkleShare {
if (!args.Request.Uri.Equals ("file:")) if (!args.Request.Uri.Equals ("file:"))
args.RetVal = 1; args.RetVal = 1;
} }
*/
public void UpdateChooser (string [] folders) public void UpdateChooser (string [] folders)
{ {
@ -235,7 +236,7 @@ namespace SparkleShare {
row++; row++;
} }
this.combo_box.RowSeparatorFunc = delegate (TreeModel model, TreeIter iter) { this.combo_box.RowSeparatorFunc = delegate (ITreeModel model, TreeIter iter) {
string item = (string) this.combo_box.Model.GetValue (iter, 0); string item = (string) this.combo_box.Model.GetValue (iter, 0);
return (item == "---"); return (item == "---");
}; };
@ -266,16 +267,16 @@ namespace SparkleShare {
string pixmaps_path = IO.Path.Combine (SparkleUI.AssetsPath, "pixmaps"); string pixmaps_path = IO.Path.Combine (SparkleUI.AssetsPath, "pixmaps");
string icons_path = new string [] {SparkleUI.AssetsPath, "icons", "hicolor", "12x12", "status"}.Combine (); string icons_path = new string [] {SparkleUI.AssetsPath, "icons", "hicolor", "12x12", "status"}.Combine ();
html = html.Replace ("<!-- $body-font-size -->", (double) (Style.FontDescription.Size / 1024 + 3) + "px");
html = html.Replace ("<!-- $day-entry-header-font-size -->", (Style.FontDescription.Size / 1024 + 3) + "px");
html = html.Replace ("<!-- $a-color -->", "#0085cf");
html = html.Replace ("<!-- $a-hover-color -->", "#009ff8"); html = html.Replace ("<!-- $a-hover-color -->", "#009ff8");
html = html.Replace ("<!-- $body-font-family -->", "\"" + Style.FontDescription.Family + "\""); html = html.Replace ("<!-- $a-color -->", "#0085cf");
html = html.Replace ("<!-- $body-color -->", SparkleUIHelpers.GdkColorToHex (Style.Foreground (StateType.Normal))); html = html.Replace ("<!-- $body-background-color -->", SparkleUIHelpers.RGBAToHex (new TreeView ().StyleContext.GetBackgroundColor (StateFlags.Normal)));
html = html.Replace ("<!-- $body-background-color -->", SparkleUIHelpers.GdkColorToHex (new TreeView ().Style.Base (StateType.Normal))); html = html.Replace ("<!-- $body-color -->", SparkleUIHelpers.RGBAToHex (StyleContext.GetColor (StateFlags.Normal)));
html = html.Replace ("<!-- $day-entry-header-background-color -->", SparkleUIHelpers.GdkColorToHex (Style.Background (StateType.Normal))); html = html.Replace ("<!-- $body-font-family -->", "\"" + StyleContext.GetFont (StateFlags.Normal).Family + "\"");
html = html.Replace ("<!-- $secondary-font-color -->", SparkleUIHelpers.GdkColorToHex (Style.Foreground (StateType.Insensitive))); html = html.Replace ("<!-- $body-font-size -->", (double) (StyleContext.GetFont (StateFlags.Normal).Size / 1024 + 3) + "px");
html = html.Replace ("<!-- $small-color -->", SparkleUIHelpers.GdkColorToHex (Style.Foreground (StateType.Insensitive))); html = html.Replace ("<!-- $day-entry-header-font-size -->", (StyleContext.GetFont (StateFlags.Normal).Size / 1024 + 3) + "px");
html = html.Replace ("<!-- $day-entry-header-background-color -->", SparkleUIHelpers.RGBAToHex (StyleContext.GetBackgroundColor (StateFlags.Normal)));
html = html.Replace ("<!-- $secondary-font-color -->", SparkleUIHelpers.RGBAToHex (StyleContext.GetColor (StateFlags.Insensitive)));
html = html.Replace ("<!-- $small-color -->", SparkleUIHelpers.RGBAToHex (StyleContext.GetColor (StateFlags.Insensitive)));
html = html.Replace ("<!-- $small-font-size -->", "85%"); html = html.Replace ("<!-- $small-font-size -->", "85%");
html = html.Replace ("<!-- $pixmaps-path -->", pixmaps_path); html = html.Replace ("<!-- $pixmaps-path -->", pixmaps_path);
html = html.Replace ("<!-- $document-added-background-image -->", "file://" + IO.Path.Combine (icons_path, "document-added.png")); html = html.Replace ("<!-- $document-added-background-image -->", "file://" + IO.Path.Combine (icons_path, "document-added.png"));
@ -284,11 +285,11 @@ namespace SparkleShare {
html = html.Replace ("<!-- $document-moved-background-image -->", "file://" + IO.Path.Combine (icons_path, "document-moved.png")); html = html.Replace ("<!-- $document-moved-background-image -->", "file://" + IO.Path.Combine (icons_path, "document-moved.png"));
this.spinner.Stop (); this.spinner.Stop ();
/*
this.web_view.NavigationRequested -= WebViewNavigationRequested; this.web_view.NavigationRequested -= WebViewNavigationRequested;
this.web_view.LoadHtmlString (html, "file://"); this.web_view.LoadHtmlString (html, "file://");
this.web_view.NavigationRequested += WebViewNavigationRequested; this.web_view.NavigationRequested += WebViewNavigationRequested;
*/
this.content_wrapper.Remove (this.content_wrapper.Child); this.content_wrapper.Remove (this.content_wrapper.Child);
this.content_wrapper.Add (this.scrolled_window); this.content_wrapper.Add (this.scrolled_window);
this.content_wrapper.ShowAll (); this.content_wrapper.ShowAll ();

View file

@ -29,9 +29,10 @@ namespace SparkleShare {
public SparkleSetup () : base () public SparkleSetup () : base ()
{ {var about = new SparkleAbout ();
about.ShowAll();
Controller.HideWindowEvent += delegate { Controller.HideWindowEvent += delegate {
Application.Invoke (delegate { HideAll (); }); Application.Invoke (delegate { Hide (); });
}; };
Controller.ShowWindowEvent += delegate { Controller.ShowWindowEvent += delegate {
@ -55,7 +56,7 @@ namespace SparkleShare {
{ {
if (type == PageType.Setup) { if (type == PageType.Setup) {
Header = "Welcome to SparkleShare!"; Header = "Welcome to SparkleShare!";
Description = "First off, whats your name and email?\n(Visible only to team members)"; Description = "First off, whats your name and email?\n(visible only to team members)";
Table table = new Table (2, 3, true) { Table table = new Table (2, 3, true) {
RowSpacing = 6, RowSpacing = 6,
@ -216,7 +217,7 @@ namespace SparkleShare {
// TODO: Scroll to selected row when using arrow keys // TODO: Scroll to selected row when using arrow keys
}; };
tree.Model.Foreach (new TreeModelForeachFunc (delegate (TreeModel model, tree.Model.Foreach (new TreeModelForeachFunc (delegate (ITreeModel model,
TreePath path, TreeIter iter) { TreePath path, TreeIter iter) {
string address; string address;
@ -272,8 +273,8 @@ namespace SparkleShare {
layout_path.PackStart (path_entry, false, false, 0); layout_path.PackStart (path_entry, false, false, 0);
layout_path.PackStart (path_example, false, false, 0); layout_path.PackStart (path_example, false, false, 0);
layout_fields.PackStart (layout_address); layout_fields.PackStart (layout_address, false, false, 0);
layout_fields.PackStart (layout_path); layout_fields.PackStart (layout_path, false, false, 0);
layout_vertical.PackStart (new Label (""), false, false, 0); layout_vertical.PackStart (new Label (""), false, false, 0);
layout_vertical.PackStart (scrolled_window, true, true, 0); layout_vertical.PackStart (scrolled_window, true, true, 0);
@ -679,7 +680,7 @@ namespace SparkleShare {
private void RenderServiceColumn (TreeViewColumn column, CellRenderer cell, private void RenderServiceColumn (TreeViewColumn column, CellRenderer cell,
TreeModel model, TreeIter iter) ITreeModel model, TreeIter iter)
{ {
string markup = (string) model.GetValue (iter, 1); string markup = (string) model.GetValue (iter, 1);
TreeSelection selection = (column.TreeView as TreeView).Selection; TreeSelection selection = (column.TreeView as TreeView).Selection;
@ -704,7 +705,7 @@ namespace SparkleShare {
{ {
get { get {
TreeIter iter; TreeIter iter;
TreeModel model; ITreeModel model;
Selection.GetSelected (out model, out iter); Selection.GetSelected (out model, out iter);
return int.Parse (model.GetPath (iter).ToString ()); return int.Parse (model.GetPath (iter).ToString ());

View file

@ -57,13 +57,14 @@ namespace SparkleShare {
args.RetVal = true; args.RetVal = true;
}; };
SecondaryTextColor = SparkleUIHelpers.GdkColorToHex (Style.Foreground (StateType.Insensitive)); Gdk.Color color = SparkleUIHelpers.RGBAToColor (StyleContext.GetColor (StateFlags.Insensitive));
SecondaryTextColor = SparkleUIHelpers.ColorToHex (color);
SecondaryTextColorSelected = SecondaryTextColorSelected =
SparkleUIHelpers.GdkColorToHex ( SparkleUIHelpers.ColorToHex (
MixColors ( MixColors (
new TreeView ().Style.Foreground (StateType.Selected), new TreeView ().StyleContext.GetColor (StateFlags.Selected),
new TreeView ().Style.Background (StateType.Selected), new TreeView ().StyleContext.GetBackgroundColor (StateFlags.Selected),
0.15 0.15
) )
); );
@ -95,17 +96,10 @@ namespace SparkleShare {
VBox.PackStart (Wrapper, true, true, 0); VBox.PackStart (Wrapper, true, true, 0);
VBox.PackStart (layout_horizontal, false, false, 15); VBox.PackStart (layout_horizontal, false, false, 15);
EventBox box = new EventBox ();
Gdk.Color bg_color = new Gdk.Color ();
Gdk.Color.Parse ("#000", ref bg_color);
box.ModifyBg (StateType.Normal, bg_color);
Image side_splash = SparkleUIHelpers.GetImage ("side-splash.png"); Image side_splash = SparkleUIHelpers.GetImage ("side-splash.png");
side_splash.Yalign = 1; side_splash.Yalign = 1;
box.Add (side_splash); HBox.PackStart (side_splash, false, false, 0);
HBox.PackStart (box, false, false, 0);
HBox.PackStart (VBox, true, true, 30); HBox.PackStart (VBox, true, true, 30);
base.Add (HBox); base.Add (HBox);
@ -197,7 +191,7 @@ namespace SparkleShare {
} }
private Gdk.Color MixColors (Gdk.Color first_color, Gdk.Color second_color, double ratio) private Gdk.Color MixColors (Gdk.RGBA first_color, Gdk.RGBA second_color, double ratio)
{ {
return new Gdk.Color ( return new Gdk.Color (
Convert.ToByte ((255 * (Math.Min (65535, first_color.Red * (1.0 - ratio) + Convert.ToByte ((255 * (Math.Min (65535, first_color.Red * (1.0 - ratio) +

View file

@ -60,12 +60,27 @@ namespace SparkleShare {
// Converts a Gdk RGB color to a hex value. // Converts a Gdk RGB color to a hex value.
// Example: from "rgb:0,0,0" to "#000000" // Example: from "rgb:0,0,0" to "#000000"
public static string GdkColorToHex (Gdk.Color color) public static string ColorToHex (Gdk.Color color)
{ {
return String.Format ("#{0:X2}{1:X2}{2:X2}", return String.Format ("#{0:X2}{1:X2}{2:X2}",
(int) Math.Truncate (color.Red / 256.00), (int) Math.Truncate (color.Red / 256.00),
(int) Math.Truncate (color.Green / 256.00), (int) Math.Truncate (color.Green / 256.00),
(int) Math.Truncate (color.Blue / 256.00)); (int) Math.Truncate (color.Blue / 256.00));
} }
public static string RGBAToHex (Gdk.RGBA rgba)
{
return ColorToHex (RGBAToColor (rgba));
}
public static Gdk.Color RGBAToColor (Gdk.RGBA rgba) {
return new Gdk.Color () {
Red = (ushort) (rgba.Red * 65535),
Green = (ushort) (rgba.Green * 65535),
Blue = (ushort)(rgba.Blue * 65535)
};
}
} }
} }