From 099cb94bc766185e9cd0e2ba032dcdc4fc922413 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Tue, 8 Oct 2013 20:18:53 +0200 Subject: [PATCH] ui: Port all the things to GTK+3 --- SparkleShare/Linux/SparkleAbout.cs | 126 ++++++++++------------- SparkleShare/Linux/SparkleBubbles.cs | 16 +-- SparkleShare/Linux/SparkleEventLog.cs | 47 ++++----- SparkleShare/Linux/SparkleSetup.cs | 17 +-- SparkleShare/Linux/SparkleSetupWindow.cs | 20 ++-- SparkleShare/Linux/SparkleUIHelpers.cs | 17 ++- 6 files changed, 115 insertions(+), 128 deletions(-) diff --git a/SparkleShare/Linux/SparkleAbout.cs b/SparkleShare/Linux/SparkleAbout.cs index 37ea660b..189cc348 100755 --- a/SparkleShare/Linux/SparkleAbout.cs +++ b/SparkleShare/Linux/SparkleAbout.cs @@ -32,25 +32,25 @@ namespace SparkleShare { public SparkleAbout () : base ("") { - DefaultSize = new Gdk.Size (600, 260); + SetSizeRequest (600, 260); Resizable = false; BorderWidth = 0; IconName = "folder-sparkleshare"; WindowPosition = WindowPosition.Center; Title = "About SparkleShare"; - AppPaintable = true; - string image_path = new string [] { SparkleUI.AssetsPath, "pixmaps", "about.png" }.Combine (); - - Realize (); - Gdk.Pixbuf buf = new Gdk.Pixbuf (image_path); - Gdk.Pixmap map, map2; - buf.RenderPixmapAndMask (out map, out map2, 255); - GdkWindow.SetBackPixmap (map, false); + CssProvider css_provider = new CssProvider (); + 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;" + + "}"); + + StyleContext.AddProvider (css_provider, 800); CreateAbout (); - DeleteEvent += delegate (object o, DeleteEventArgs args) { Controller.WindowClosed (); args.RetVal = true; @@ -65,9 +65,7 @@ namespace SparkleShare { }; Controller.HideWindowEvent += delegate { - Application.Invoke (delegate { - HideAll (); - }); + Application.Invoke (delegate { Hide (); }); }; Controller.ShowWindowEvent += delegate { @@ -92,13 +90,13 @@ namespace SparkleShare { Markup = string.Format ("version {0}", Controller.RunningVersion), Xalign = 0, - Xpad = 300 + Xpad = 0 }; this.updates = new Label () { - Markup = "Checking for updates...", + Markup = "Checking for updates...", Xalign = 0, - Xpad = 300 + Xpad = 0 }; Label copyright = new Label () { @@ -107,7 +105,7 @@ namespace SparkleShare { "Hylke Bons and others." + "", Xalign = 0, - Xpad = 300 + Xpad = 0 }; Label license = new Label () { @@ -117,66 +115,54 @@ namespace SparkleShare { "SparkleShare is Open Source software. You are free to use, modify, " + "and redistribute it under the GNU General Public License version 3 or later." + "", - WidthRequest = 330, Wrap = true, - Xalign = 0, - Xpad = 300, + Xalign = 0 }; - VBox layout_vertical = new VBox (false, 0) { - BorderWidth = 0, - HeightRequest = 260, - WidthRequest = 640 - }; - - HBox links_layout = new HBox (false, 6); - - SparkleLink website_link = new SparkleLink ("Website", Controller.WebsiteLinkAddress); - SparkleLink credits_link = new SparkleLink ("Credits", Controller.CreditsLinkAddress); + VBox layout_vertical = new VBox (false, 0); + HBox links_layout = new HBox (false, 16); + + SparkleLink website_link = new SparkleLink ("Website", Controller.WebsiteLinkAddress); + SparkleLink credits_link = new SparkleLink ("Credits", Controller.CreditsLinkAddress); SparkleLink report_problem_link = new SparkleLink ("Report a problem", Controller.ReportProblemLinkAddress); 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, 9); - links_layout.PackStart (credits_link, false, false, 9); - links_layout.PackStart (report_problem_link, false, false, 9); - links_layout.PackStart (debug_log_link, false, false, 9); - - layout_vertical.PackStart (new Label (""), false, false, 42); + + links_layout.PackStart (website_link, false, false, 0); + links_layout.PackStart (credits_link, false, false, 0); + links_layout.PackStart (report_problem_link, false, false, 0); + links_layout.PackStart (debug_log_link, false, false, 0); + + layout_vertical.PackStart (new Label (""), true, true, 0); layout_vertical.PackStart (version, false, false, 0); layout_vertical.PackStart (this.updates, false, false, 0); - layout_vertical.PackStart (copyright, false, false, 9); - layout_vertical.PackStart (license, false, false, 0); - layout_vertical.PackStart (links_layout, false, false, 12); - - Add (layout_vertical); + layout_vertical.PackStart (copyright, false, false, 6); + layout_vertical.PackStart (license, false, false, 6); + layout_vertical.PackStart (links_layout, false, false, 16); + + 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); + } + } + + + public class SparkleLink : EventBox { + + public SparkleLink (string text, string url) + { + VisibleWindow = false; + + Label label = new Label () { + Markup = "" + text + "" + }; + + EnterNotifyEvent += delegate { Window.Cursor = new Gdk.Cursor (Gdk.CursorType.Hand1); }; + LeaveNotifyEvent += delegate { Window.Cursor = new Gdk.Cursor (Gdk.CursorType.Arrow); }; + ButtonPressEvent += delegate { Program.Controller.OpenWebsite (url); }; + + Add (label); } } - - - public class SparkleLink : EventBox { - - public SparkleLink (string text, string url) - { - VisibleWindow = false; - - Label label = new Label () { - Markup = "" + text + "" - }; - - EnterNotifyEvent += delegate { - GdkWindow.Cursor = new Gdk.Cursor (Gdk.CursorType.Hand1); - }; - - LeaveNotifyEvent += delegate { - GdkWindow.Cursor = new Gdk.Cursor (Gdk.CursorType.Arrow); - }; - - ButtonPressEvent += delegate { - Program.Controller.OpenWebsite (url); - }; - - Add (label); - } - } } diff --git a/SparkleShare/Linux/SparkleBubbles.cs b/SparkleShare/Linux/SparkleBubbles.cs index dac64f95..08ff02b7 100755 --- a/SparkleShare/Linux/SparkleBubbles.cs +++ b/SparkleShare/Linux/SparkleBubbles.cs @@ -18,7 +18,7 @@ using System; using Gtk; -using Notifications; +//using Notifications; using SparkleLib; namespace SparkleShare { @@ -29,22 +29,12 @@ namespace SparkleShare { public SparkleBubbles () - { + {/* Controller.ShowBubbleEvent += delegate (string title, string subtext, string image_path) { if (!Program.Controller.NotificationsEnabled) return; 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 () { Summary = title, Body = subtext, @@ -67,7 +57,7 @@ namespace SparkleShare { } catch (Exception e) { SparkleLogger.LogInfo ("Notification", "Error showing notification: ", e); } - }; + };*/ } } } diff --git a/SparkleShare/Linux/SparkleEventLog.cs b/SparkleShare/Linux/SparkleEventLog.cs index 3040f278..d2727d8d 100755 --- a/SparkleShare/Linux/SparkleEventLog.cs +++ b/SparkleShare/Linux/SparkleEventLog.cs @@ -21,7 +21,7 @@ using System.Threading; using Gtk; using Mono.Unix; -using WebKit; +// using WebKit; using IO = System.IO; @@ -38,7 +38,7 @@ namespace SparkleShare { private HBox combo_box_wrapper; private EventBox content_wrapper; private ScrolledWindow scrolled_window; - private WebView web_view; +// private WebView web_view; private SparkleSpinner spinner; @@ -90,19 +90,20 @@ namespace SparkleShare { this.content_wrapper = new EventBox (); this.scrolled_window = new ScrolledWindow (); - Gdk.Color white = new Gdk.Color(); - Gdk.Color.Parse ("white", ref white); - - this.content_wrapper.ModifyBg (StateType.Normal, white); + // TODO: check + CssProvider css_provider= new CssProvider (); + css_provider.LoadFromData ("GtkWindow { background-color: #ffffff; }"); + StyleContext.AddProvider (css_provider, 800); +/* this.web_view = new WebView () { Editable = false }; 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.spinner.Start (); @@ -118,7 +119,7 @@ namespace SparkleShare { Controller.HideWindowEvent += delegate { Application.Invoke (delegate { - HideAll (); + Hide (); if (this.content_wrapper.Child != null) this.content_wrapper.Remove (this.content_wrapper.Child); @@ -190,7 +191,7 @@ namespace SparkleShare { }; } - +/* private void WebViewNavigationRequested (object o, WebKit.NavigationRequestedArgs args) { Controller.LinkClicked (args.Request.Uri); @@ -198,7 +199,7 @@ namespace SparkleShare { if (!args.Request.Uri.Equals ("file:")) args.RetVal = 1; } - +*/ public void UpdateChooser (string [] folders) { @@ -235,7 +236,7 @@ namespace SparkleShare { 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); return (item == "---"); }; @@ -266,16 +267,16 @@ namespace SparkleShare { string pixmaps_path = IO.Path.Combine (SparkleUI.AssetsPath, "pixmaps"); string icons_path = new string [] {SparkleUI.AssetsPath, "icons", "hicolor", "12x12", "status"}.Combine (); - html = html.Replace ("", (double) (Style.FontDescription.Size / 1024 + 3) + "px"); - html = html.Replace ("", (Style.FontDescription.Size / 1024 + 3) + "px"); - html = html.Replace ("", "#0085cf"); html = html.Replace ("", "#009ff8"); - html = html.Replace ("", "\"" + Style.FontDescription.Family + "\""); - html = html.Replace ("", SparkleUIHelpers.GdkColorToHex (Style.Foreground (StateType.Normal))); - html = html.Replace ("", SparkleUIHelpers.GdkColorToHex (new TreeView ().Style.Base (StateType.Normal))); - html = html.Replace ("", SparkleUIHelpers.GdkColorToHex (Style.Background (StateType.Normal))); - html = html.Replace ("", SparkleUIHelpers.GdkColorToHex (Style.Foreground (StateType.Insensitive))); - html = html.Replace ("", SparkleUIHelpers.GdkColorToHex (Style.Foreground (StateType.Insensitive))); + html = html.Replace ("", "#0085cf"); + html = html.Replace ("", SparkleUIHelpers.RGBAToHex (new TreeView ().StyleContext.GetBackgroundColor (StateFlags.Normal))); + html = html.Replace ("", SparkleUIHelpers.RGBAToHex (StyleContext.GetColor (StateFlags.Normal))); + html = html.Replace ("", "\"" + StyleContext.GetFont (StateFlags.Normal).Family + "\""); + html = html.Replace ("", (double) (StyleContext.GetFont (StateFlags.Normal).Size / 1024 + 3) + "px"); + html = html.Replace ("", (StyleContext.GetFont (StateFlags.Normal).Size / 1024 + 3) + "px"); + html = html.Replace ("", SparkleUIHelpers.RGBAToHex (StyleContext.GetBackgroundColor (StateFlags.Normal))); + html = html.Replace ("", SparkleUIHelpers.RGBAToHex (StyleContext.GetColor (StateFlags.Insensitive))); + html = html.Replace ("", SparkleUIHelpers.RGBAToHex (StyleContext.GetColor (StateFlags.Insensitive))); html = html.Replace ("", "85%"); html = html.Replace ("", pixmaps_path); html = html.Replace ("", "file://" + IO.Path.Combine (icons_path, "document-added.png")); @@ -284,11 +285,11 @@ namespace SparkleShare { html = html.Replace ("", "file://" + IO.Path.Combine (icons_path, "document-moved.png")); this.spinner.Stop (); - +/* this.web_view.NavigationRequested -= WebViewNavigationRequested; this.web_view.LoadHtmlString (html, "file://"); this.web_view.NavigationRequested += WebViewNavigationRequested; - +*/ this.content_wrapper.Remove (this.content_wrapper.Child); this.content_wrapper.Add (this.scrolled_window); this.content_wrapper.ShowAll (); diff --git a/SparkleShare/Linux/SparkleSetup.cs b/SparkleShare/Linux/SparkleSetup.cs index 8f7f7524..1a556e7b 100755 --- a/SparkleShare/Linux/SparkleSetup.cs +++ b/SparkleShare/Linux/SparkleSetup.cs @@ -29,9 +29,10 @@ namespace SparkleShare { public SparkleSetup () : base () - { + {var about = new SparkleAbout (); + about.ShowAll(); Controller.HideWindowEvent += delegate { - Application.Invoke (delegate { HideAll (); }); + Application.Invoke (delegate { Hide (); }); }; Controller.ShowWindowEvent += delegate { @@ -55,7 +56,7 @@ namespace SparkleShare { { if (type == PageType.Setup) { Header = "Welcome to SparkleShare!"; - Description = "First off, what’s your name and email?\n(Visible only to team members)"; + Description = "First off, what’s your name and email?\n(visible only to team members)"; Table table = new Table (2, 3, true) { RowSpacing = 6, @@ -216,7 +217,7 @@ namespace SparkleShare { // 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) { string address; @@ -272,8 +273,8 @@ namespace SparkleShare { layout_path.PackStart (path_entry, false, false, 0); layout_path.PackStart (path_example, false, false, 0); - layout_fields.PackStart (layout_address); - layout_fields.PackStart (layout_path); + layout_fields.PackStart (layout_address, false, false, 0); + layout_fields.PackStart (layout_path, false, false, 0); layout_vertical.PackStart (new Label (""), false, false, 0); layout_vertical.PackStart (scrolled_window, true, true, 0); @@ -679,7 +680,7 @@ namespace SparkleShare { private void RenderServiceColumn (TreeViewColumn column, CellRenderer cell, - TreeModel model, TreeIter iter) + ITreeModel model, TreeIter iter) { string markup = (string) model.GetValue (iter, 1); TreeSelection selection = (column.TreeView as TreeView).Selection; @@ -704,7 +705,7 @@ namespace SparkleShare { { get { TreeIter iter; - TreeModel model; + ITreeModel model; Selection.GetSelected (out model, out iter); return int.Parse (model.GetPath (iter).ToString ()); diff --git a/SparkleShare/Linux/SparkleSetupWindow.cs b/SparkleShare/Linux/SparkleSetupWindow.cs index 218360b9..ec4eed49 100755 --- a/SparkleShare/Linux/SparkleSetupWindow.cs +++ b/SparkleShare/Linux/SparkleSetupWindow.cs @@ -57,13 +57,14 @@ namespace SparkleShare { args.RetVal = true; }; - SecondaryTextColor = SparkleUIHelpers.GdkColorToHex (Style.Foreground (StateType.Insensitive)); + Gdk.Color color = SparkleUIHelpers.RGBAToColor (StyleContext.GetColor (StateFlags.Insensitive)); + SecondaryTextColor = SparkleUIHelpers.ColorToHex (color); SecondaryTextColorSelected = - SparkleUIHelpers.GdkColorToHex ( + SparkleUIHelpers.ColorToHex ( MixColors ( - new TreeView ().Style.Foreground (StateType.Selected), - new TreeView ().Style.Background (StateType.Selected), + new TreeView ().StyleContext.GetColor (StateFlags.Selected), + new TreeView ().StyleContext.GetBackgroundColor (StateFlags.Selected), 0.15 ) ); @@ -95,17 +96,10 @@ namespace SparkleShare { VBox.PackStart (Wrapper, true, true, 0); 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"); side_splash.Yalign = 1; - box.Add (side_splash); - - HBox.PackStart (box, false, false, 0); + HBox.PackStart (side_splash, false, false, 0); HBox.PackStart (VBox, true, true, 30); 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 ( Convert.ToByte ((255 * (Math.Min (65535, first_color.Red * (1.0 - ratio) + diff --git a/SparkleShare/Linux/SparkleUIHelpers.cs b/SparkleShare/Linux/SparkleUIHelpers.cs index c631cf2f..1fb7d93b 100755 --- a/SparkleShare/Linux/SparkleUIHelpers.cs +++ b/SparkleShare/Linux/SparkleUIHelpers.cs @@ -60,12 +60,27 @@ 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) + public static string ColorToHex (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)); } + + + 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) + }; + } } }