From a6908b607e09dcd9a689b1e86b8909405524f2ba Mon Sep 17 00:00:00 2001 From: Jonathan Haines Date: Tue, 25 Oct 2016 20:25:34 +1100 Subject: [PATCH 1/6] windows --- SparkleShare/Common/BaseController.cs | 8 +- SparkleShare/Linux/Controller.cs | 13 +- SparkleShare/Mac/Controller.cs | 6 +- SparkleShare/SparkleShare.exe.config | 3 + SparkleShare/SparkleShare.vshost.exe.config | 3 + .../Windows/{SparkleAbout.cs => About.cs} | 6 +- .../Windows/{SparkleBubbles.cs => Bubbles.cs} | 6 +- .../{SparkleController.cs => Controller.cs} | 93 ++--- SparkleShare/Windows/EventLog.cs | 350 ++++++++++++++++ .../Windows/{SparkleNote.xaml => Note.xaml} | 2 +- .../{SparkleNote.xaml.cs => Note.xaml.cs} | 6 +- .../{SparkleNotifyIcon.cs => NotifyIcon.cs} | 376 ++++++++--------- .../Windows/{SparkleSetup.cs => Setup.cs} | 170 +------- .../{SparkleSetupWindow.cs => SetupWindow.cs} | 386 +++++++++--------- .../{SparkleShortcut.cs => Shortcut.cs} | 0 .../Windows/SparkleEventLogWindow.xaml | 38 -- .../Windows/SparkleEventLogWindow.xaml.cs | 262 ------------ .../SparkleLib/Git/SparkleLib.Git.csproj | 71 ---- .../Windows/SparkleLib/SparkleLib.csproj | 97 ----- .../Windows/SparkleShare.Windows.csproj | 172 ++++---- .../Windows/{SparkleSpinner.cs => Spinner.cs} | 182 ++++----- .../{SparkleStatusIcon.cs => StatusIcon.cs} | 10 +- .../{SparkleUI.cs => UserInterface.cs} | 32 +- SparkleShare/Windows/app.config | 3 + .../AuthenticationInfo.cs | 0 .../SSHAuthenticationInfo.cs | 2 +- Sparkles/{ => Fetcher}/BaseFetcher.cs | 0 Sparkles/{ => Fetcher}/SSHFetcher.cs | 4 +- Sparkles/Git/GitCommand.cs | 17 +- Sparkles/Git/GitFetcher.cs | 12 +- Sparkles/Git/GitRepository.cs | 11 +- Sparkles/{ => Listener}/BaseListener.cs | 0 Sparkles/{ => Listener}/ListenerFactory.cs | 0 Sparkles/{ => Listener}/TcpListener.cs | 0 Sparkles/{ => Repository}/BaseRepository.cs | 0 Sparkles/{ => Repository}/ChangeSet.cs | 0 Sparkles/{ => Repository}/User.cs | 0 Sparkles/{ => Repository}/Watcher.cs | 0 Sparkles/SSHCommand.cs | 41 ++ 39 files changed, 1083 insertions(+), 1299 deletions(-) create mode 100644 SparkleShare/SparkleShare.exe.config create mode 100644 SparkleShare/SparkleShare.vshost.exe.config rename SparkleShare/Windows/{SparkleAbout.cs => About.cs} (97%) rename SparkleShare/Windows/{SparkleBubbles.cs => Bubbles.cs} (88%) rename SparkleShare/Windows/{SparkleController.cs => Controller.cs} (70%) create mode 100644 SparkleShare/Windows/EventLog.cs rename SparkleShare/Windows/{SparkleNote.xaml => Note.xaml} (98%) rename SparkleShare/Windows/{SparkleNote.xaml.cs => Note.xaml.cs} (96%) rename SparkleShare/Windows/{SparkleNotifyIcon.cs => NotifyIcon.cs} (79%) rename SparkleShare/Windows/{SparkleSetup.cs => Setup.cs} (82%) rename SparkleShare/Windows/{SparkleSetupWindow.cs => SetupWindow.cs} (95%) rename SparkleShare/Windows/{SparkleShortcut.cs => Shortcut.cs} (100%) delete mode 100644 SparkleShare/Windows/SparkleEventLogWindow.xaml delete mode 100644 SparkleShare/Windows/SparkleEventLogWindow.xaml.cs delete mode 100644 SparkleShare/Windows/SparkleLib/Git/SparkleLib.Git.csproj delete mode 100644 SparkleShare/Windows/SparkleLib/SparkleLib.csproj rename SparkleShare/Windows/{SparkleSpinner.cs => Spinner.cs} (93%) rename SparkleShare/Windows/{SparkleStatusIcon.cs => StatusIcon.cs} (97%) rename SparkleShare/Windows/{SparkleUI.cs => UserInterface.cs} (71%) create mode 100644 SparkleShare/Windows/app.config rename Sparkles/{ => AuthenticationInfo}/AuthenticationInfo.cs (100%) rename Sparkles/{ => AuthenticationInfo}/SSHAuthenticationInfo.cs (98%) rename Sparkles/{ => Fetcher}/BaseFetcher.cs (100%) rename Sparkles/{ => Fetcher}/SSHFetcher.cs (97%) rename Sparkles/{ => Listener}/BaseListener.cs (100%) rename Sparkles/{ => Listener}/ListenerFactory.cs (100%) rename Sparkles/{ => Listener}/TcpListener.cs (100%) rename Sparkles/{ => Repository}/BaseRepository.cs (100%) rename Sparkles/{ => Repository}/ChangeSet.cs (100%) rename Sparkles/{ => Repository}/User.cs (100%) rename Sparkles/{ => Repository}/Watcher.cs (100%) create mode 100644 Sparkles/SSHCommand.cs diff --git a/SparkleShare/Common/BaseController.cs b/SparkleShare/Common/BaseController.cs index 4a370041..10333255 100644 --- a/SparkleShare/Common/BaseController.cs +++ b/SparkleShare/Common/BaseController.cs @@ -167,7 +167,7 @@ namespace SparkleShare { public abstract void SetFolderIcon (); // Creates the SparkleShare folder in the user's home folder - public abstract bool CreateSparkleShareFolder (); + public abstract void CreateSparkleShareFolder (); // Opens the SparkleShare folder or an (optional) subfolder public abstract void OpenFolder (string path); @@ -206,9 +206,6 @@ namespace SparkleShare { Config = new Configuration (config_path, "projects.xml"); Configuration.DefaultConfiguration = Config; - UserAuthenticationInfo = new SSHAuthenticationInfo (); - SSHAuthenticationInfo.DefaultAuthenticationInfo = UserAuthenticationInfo; - FoldersPath = Config.FoldersPath; } @@ -227,6 +224,9 @@ namespace SparkleShare { // TODO: ToString() with nice os version names (Mac OS X Yosemite, Fedora 24, Ubuntu 16.04, etc.) Logger.LogInfo ("Environment", InstallationInfo.OperatingSystem + " (" + Environment.OSVersion + ")"); + UserAuthenticationInfo = new SSHAuthenticationInfo(); + SSHAuthenticationInfo.DefaultAuthenticationInfo = UserAuthenticationInfo; + Preset.PresetsPath = PresetsPath; InstallProtocolHandler (); diff --git a/SparkleShare/Linux/Controller.cs b/SparkleShare/Linux/Controller.cs index 4f6333fa..2cc1f47c 100644 --- a/SparkleShare/Linux/Controller.cs +++ b/SparkleShare/Linux/Controller.cs @@ -33,15 +33,12 @@ namespace SparkleShare { } - public override bool CreateSparkleShareFolder () + public override void CreateSparkleShareFolder () { - if (Directory.Exists (Configuration.DefaultConfiguration.FoldersPath)) - return false; - - Directory.CreateDirectory (Configuration.DefaultConfiguration.FoldersPath); - Syscall.chmod (Configuration.DefaultConfiguration.FoldersPath, (FilePermissions) 448); // 448 -> 700 - - return false; + if (!Directory.Exists (Configuration.DefaultConfiguration.FoldersPath)) { + Directory.CreateDirectory (Configuration.DefaultConfiguration.FoldersPath); + Syscall.chmod (Configuration.DefaultConfiguration.FoldersPath, (FilePermissions) 448); // 448 -> 700 + } } diff --git a/SparkleShare/Mac/Controller.cs b/SparkleShare/Mac/Controller.cs index b97c05b4..b53c7012 100644 --- a/SparkleShare/Mac/Controller.cs +++ b/SparkleShare/Mac/Controller.cs @@ -61,16 +61,12 @@ namespace SparkleShare { } - public override bool CreateSparkleShareFolder () + public override void CreateSparkleShareFolder () { if (!Directory.Exists (SparkleShare.Controller.FoldersPath)) { Directory.CreateDirectory (SparkleShare.Controller.FoldersPath); Syscall.chmod (SparkleShare.Controller.FoldersPath, (FilePermissions) 448); // 448 -> 700 - - return true; } - - return false; } diff --git a/SparkleShare/SparkleShare.exe.config b/SparkleShare/SparkleShare.exe.config new file mode 100644 index 00000000..51278a45 --- /dev/null +++ b/SparkleShare/SparkleShare.exe.config @@ -0,0 +1,3 @@ + + + diff --git a/SparkleShare/SparkleShare.vshost.exe.config b/SparkleShare/SparkleShare.vshost.exe.config new file mode 100644 index 00000000..51278a45 --- /dev/null +++ b/SparkleShare/SparkleShare.vshost.exe.config @@ -0,0 +1,3 @@ + + + diff --git a/SparkleShare/Windows/SparkleAbout.cs b/SparkleShare/Windows/About.cs similarity index 97% rename from SparkleShare/Windows/SparkleAbout.cs rename to SparkleShare/Windows/About.cs index 6d34ed73..a0e2d2f0 100644 --- a/SparkleShare/Windows/SparkleAbout.cs +++ b/SparkleShare/Windows/About.cs @@ -27,14 +27,14 @@ using System.Xaml; namespace SparkleShare { - public class SparkleAbout : Window { + public class About : Window { - public SparkleAboutController Controller = new SparkleAboutController (); + public AboutController Controller = new AboutController (); private Label updates; - public SparkleAbout () + public About () { Title = "About SparkleShare"; ResizeMode = ResizeMode.NoResize; diff --git a/SparkleShare/Windows/SparkleBubbles.cs b/SparkleShare/Windows/Bubbles.cs similarity index 88% rename from SparkleShare/Windows/SparkleBubbles.cs rename to SparkleShare/Windows/Bubbles.cs index e9b07136..bac2a3b4 100644 --- a/SparkleShare/Windows/SparkleBubbles.cs +++ b/SparkleShare/Windows/Bubbles.cs @@ -19,12 +19,12 @@ using System; namespace SparkleShare { - public class SparkleBubbles { + public class Bubbles { - public SparkleBubblesController Controller = new SparkleBubblesController (); + public BubblesController Controller = new BubblesController (); - public SparkleBubbles () + public Bubbles () { Controller.ShowBubbleEvent += delegate (string title, string subtext, string image_path) { if (!SparkleShare.Controller.NotificationsEnabled) diff --git a/SparkleShare/Windows/SparkleController.cs b/SparkleShare/Windows/Controller.cs similarity index 70% rename from SparkleShare/Windows/SparkleController.cs rename to SparkleShare/Windows/Controller.cs index 9c030b4c..b34914ff 100644 --- a/SparkleShare/Windows/SparkleController.cs +++ b/SparkleShare/Windows/Controller.cs @@ -30,12 +30,13 @@ using Forms = System.Windows.Forms; using Microsoft.Win32; using Sparkles; +using Sparkles.Git; namespace SparkleShare { - public class SparkleController : SparkleControllerBase { + public class Controller : BaseController { - public SparkleController () + public Controller () { } @@ -43,7 +44,7 @@ namespace SparkleShare { public override string PresetsPath { get { - return Path.Combine (Path.GetDirectoryName (Assembly.GetExecutingAssembly ().Location), "plugins"); + return Path.Combine (Path.GetDirectoryName (Assembly.GetExecutingAssembly ().Location), "Presets"); } } @@ -55,15 +56,11 @@ namespace SparkleShare { string executable_path = Path.GetDirectoryName (Forms.Application.ExecutablePath); string msysgit_path = Path.Combine (executable_path, "msysgit"); - string new_PATH = msysgit_path + @"\bin" + ";" + - msysgit_path + @"\mingw\bin" + ";" + - msysgit_path + @"\cmd" + ";" + - Environment.ExpandEnvironmentVariables ("%PATH%"); - - Environment.SetEnvironmentVariable ("PATH", new_PATH); Environment.SetEnvironmentVariable ("HOME", Environment.GetFolderPath (Environment.SpecialFolder.UserProfile)); - Sparkles.Git.SparkleGit.SSHPath = Path.Combine (msysgit_path, "bin", "ssh.exe"); + SSHCommand.SSHPath = Path.Combine (msysgit_path, "usr", "bin"); + SSHFetcher.SSHKeyScan = Path.Combine(msysgit_path, "usr", "bin", "ssh-keyscan.exe"); + GitCommand.GitPath = Path.Combine(msysgit_path, "bin", "git.exe"); base.Initialize (); } @@ -91,6 +88,38 @@ namespace SparkleShare { } + public override void SetFolderIcon () + { + string app_path = Path.GetDirectoryName(Forms.Application.ExecutablePath); + string icon_file_path = Path.Combine(app_path, "Images", "sparkleshare-folder.ico"); + + if (!File.Exists(icon_file_path)) + { + string ini_file_path = Path.Combine(FoldersPath, "desktop.ini"); + string n = Environment.NewLine; + + string ini_file = "[.ShellClassInfo]" + n + + "IconFile=" + icon_file_path + n + + "IconIndex=0" + n + + "InfoTip=SparkleShare"; + + try + { + File.Create(ini_file_path).Close(); + File.WriteAllText(ini_file_path, ini_file); + + File.SetAttributes(ini_file_path, + File.GetAttributes(ini_file_path) | FileAttributes.Hidden | FileAttributes.System); + + } + catch (IOException e) + { + Logger.LogInfo("Config", "Failed setting icon for '" + FoldersPath + "': " + e.Message); + } + } + } + + public override void CreateStartupItem () { string startup_folder_path = Environment.GetFolderPath (Environment.SpecialFolder.Startup); @@ -112,7 +141,7 @@ namespace SparkleShare { } - public override void AddToBookmarks () + public void AddToBookmarks () { string user_profile_path = Environment.GetFolderPath (Environment.SpecialFolder.UserProfile); string shortcut_path = Path.Combine (user_profile_path, "Links", "SparkleShare.lnk"); @@ -125,43 +154,15 @@ namespace SparkleShare { } - public override bool CreateSparkleShareFolder () + public override void CreateSparkleShareFolder () { - if (Directory.Exists (FoldersPath)) - return false; + if (!Directory.Exists (FoldersPath)) + { + Directory.CreateDirectory(FoldersPath); - Directory.CreateDirectory (FoldersPath); - - File.SetAttributes (FoldersPath, File.GetAttributes (FoldersPath) | FileAttributes.System); - SparkleLogger.LogInfo ("Config", "Created '" + FoldersPath + "'"); - - string app_path = Path.GetDirectoryName (Forms.Application.ExecutablePath); - string icon_file_path = Path.Combine (app_path, "Images", "sparkleshare-folder.ico"); - - if (!File.Exists (icon_file_path)) { - string ini_file_path = Path.Combine (FoldersPath, "desktop.ini"); - string n = Environment.NewLine; - - string ini_file = "[.ShellClassInfo]" + n + - "IconFile=" + icon_file_path + n + - "IconIndex=0" + n + - "InfoTip=SparkleShare"; - - try { - File.Create (ini_file_path).Close (); - File.WriteAllText (ini_file_path, ini_file); - - File.SetAttributes (ini_file_path, - File.GetAttributes (ini_file_path) | FileAttributes.Hidden | FileAttributes.System); - - } catch (IOException e) { - SparkleLogger.LogInfo ("Config", "Failed setting icon for '" + FoldersPath + "': " + e.Message); - } - - return true; + File.SetAttributes(FoldersPath, File.GetAttributes(FoldersPath) | FileAttributes.System); + Logger.LogInfo("Config", "Created '" + FoldersPath + "'"); } - - return false; } @@ -189,7 +190,7 @@ namespace SparkleShare { Clipboard.SetData (DataFormats.Text, text); } catch (COMException e) { - SparkleLogger.LogInfo ("Controller", "Copy to clipboard failed", e); + Logger.LogInfo ("Controller", "Copy to clipboard failed", e); } } diff --git a/SparkleShare/Windows/EventLog.cs b/SparkleShare/Windows/EventLog.cs new file mode 100644 index 00000000..c7d1213f --- /dev/null +++ b/SparkleShare/Windows/EventLog.cs @@ -0,0 +1,350 @@ +// SparkleShare, a collaboration and sharing tool. +// 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 System; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Linq; +using System.Security.Permissions; +using System.Text; +using System.Runtime.InteropServices; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +using Microsoft.Win32; +using System.Windows.Data; + +namespace SparkleShare +{ + public class EventLog : Window { + + public EventLogController Controller = new EventLogController (); + + private Label label_Size; + private Label label_History; + + private WebBrowser webbrowser; + + private Spinner spinner; + + private ComboBox combobox; + + private Grid grid_Base; + + [DllImport("urlmon.dll")] + [PreserveSig] + [return: MarshalAs(UnmanagedType.Error)] + static extern int CoInternetSetFeatureEnabled(int feature, [MarshalAs(UnmanagedType.U4)] int flags, bool enable); + + public EventLog() + { + CreateEventLog(); + + Background = new SolidColorBrush(Color.FromRgb(240, 240, 240)); + AllowsTransparency = false; + Icon = SparkleUIHelpers.GetImageSource("sparkleshare-app", "ico"); + WindowStartupLocation = WindowStartupLocation.CenterScreen; + + WriteOutImages(); + + this.label_Size.Content = "Size: " + Controller.Size; + this.label_History.Content = "History: " + Controller.HistorySize; + + this.webbrowser.ObjectForScripting = new SparkleScriptingObject(); + + // Disable annoying IE clicking sound + CoInternetSetFeatureEnabled(21, 0x00000002, true); + + Closing += this.OnClosing; + + Controller.ShowWindowEvent += delegate { + Dispatcher.BeginInvoke((Action)(() => { + Show(); + Activate(); + BringIntoView(); + })); + }; + + Controller.HideWindowEvent += delegate { + Dispatcher.BeginInvoke((Action)(() => { + Hide(); + this.spinner.Visibility = Visibility.Visible; + this.webbrowser.Visibility = Visibility.Collapsed; + })); + }; + + Controller.UpdateSizeInfoEvent += delegate (string size, string history_size) { + Dispatcher.BeginInvoke((Action)(() => { + this.label_Size.Content = "Size: " + size; + this.label_History.Content = "History: " + history_size; + })); + }; + + Controller.UpdateChooserEvent += delegate (string[] folders) { + Dispatcher.BeginInvoke((Action)(() => + UpdateChooser(folders)) + ); + }; + + Controller.UpdateChooserEnablementEvent += delegate (bool enabled) { + Dispatcher.BeginInvoke((Action)(() => + this.combobox.IsEnabled = enabled + )); + }; + + Controller.UpdateContentEvent += delegate (string html) { + Dispatcher.BeginInvoke((Action)(() => { + UpdateContent(html); + + this.spinner.Visibility = Visibility.Collapsed; + this.webbrowser.Visibility = Visibility.Visible; + })); + }; + + Controller.ContentLoadingEvent += () => this.Dispatcher.BeginInvoke( + (Action)(() => { + this.spinner.Visibility = Visibility.Visible; + this.spinner.Start(); + this.webbrowser.Visibility = Visibility.Collapsed; + })); + + Controller.ShowSaveDialogEvent += delegate (string file_name, string target_folder_path) { + Dispatcher.BeginInvoke((Action)(() => { + SaveFileDialog dialog = new SaveFileDialog() + { + FileName = file_name, + InitialDirectory = target_folder_path, + Title = "Restore from History", + DefaultExt = "." + System.IO.Path.GetExtension(file_name), + Filter = "All Files|*.*" + }; + + bool? result = dialog.ShowDialog(this); + + if (result == true) + Controller.SaveDialogCompleted(dialog.FileName); + else + Controller.SaveDialogCancelled(); + })); + }; + } + + + private void CreateEventLog () { + grid_Base = new Grid { Background = Brushes.White }; + + label_Size = new Label { + Content = "Size: ?", + Height = 28, + HorizontalAlignment = HorizontalAlignment.Left, + Margin = new Thickness(20, 0, 0, 0), + FontWeight = FontWeights.Bold + }; + + label_History = new Label { + Content = "History: ?", + Height = 28, + HorizontalAlignment = HorizontalAlignment.Left, + Margin = new Thickness(100, 0, 0, 0), + FontWeight = FontWeights.Bold + }; + + combobox = new ComboBox { + HorizontalAlignment = HorizontalAlignment.Right, + VerticalAlignment = VerticalAlignment.Center, + Margin = new Thickness(0, 0, 6, 0), + MinWidth = 120 + }; + + spinner = new Spinner { Name = "spinner" }; + webbrowser = new WebBrowser { Name = "webbrowser" }; + + Border border = new Border { + VerticalAlignment = VerticalAlignment.Top, + Height = 35, + Background = new SolidColorBrush(Color.FromArgb(255, 240, 240, 240)), + BorderBrush = new SolidColorBrush(Color.FromArgb(255, 223, 223, 223)), + BorderThickness = new Thickness(0, 0, 0, 1) + }; + + Grid borderGrid = new Grid(); + + borderGrid.Children.Add(this.label_Size); + borderGrid.Children.Add(this.label_History); + borderGrid.Children.Add(this.combobox); + + border.Child = borderGrid; + + Grid browserGrid = new Grid { Margin = new Thickness(0, 35, 0, 0) }; + + browserGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }); + browserGrid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); + + browserGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); + browserGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); + + browserGrid.Children.Add(this.spinner); + browserGrid.Children.Add(this.webbrowser); + + Rectangle sizingControlHeight = new Rectangle { + Name = "sizingControlHeight", + Visibility = Visibility.Hidden + }; + + Grid.SetColumn(sizingControlHeight, 1); + + Rectangle sizingControlWidth = new Rectangle { + Name = "sizingControlHeight", + Visibility = Visibility.Hidden + }; + + Grid.SetColumn(sizingControlWidth, 0); + Grid.SetRow(sizingControlWidth, 0); + + browserGrid.Children.Add(sizingControlHeight); + browserGrid.Children.Add(sizingControlWidth); + + webbrowser.SetBinding(HeightProperty, new Binding("ActualHeightProperty") { ElementName = sizingControlHeight.Name }); + webbrowser.SetBinding(WidthProperty, new Binding("ActualWidthProperty") { ElementName = sizingControlWidth.Name }); + + grid_Base.Children.Add(border); + } + + private void OnClosing(object sender, CancelEventArgs cancel_event_args) + { + Controller.WindowClosed(); + cancel_event_args.Cancel = true; + } + + + private void UpdateContent(string html) + { + string pixmaps_path = System.IO.Path.Combine(Sparkles.Configuration.DefaultConfiguration.TmpPath, "Images"); + pixmaps_path = pixmaps_path.Replace("\\", "/"); + + html = html.Replace("", "Segoe UI"); + html = html.Replace("", "13px"); + html = html.Replace("", "12px"); + html = html.Replace("", "#bbb"); + html = html.Replace("", "#ddd"); + html = html.Replace("", "90%"); + html = html.Replace("", "#f5f5f5"); + html = html.Replace("", "#0085cf"); + html = html.Replace("", "#009ff8"); + html = html.Replace("", pixmaps_path); + html = html.Replace("", pixmaps_path + "/document-added-12.png"); + html = html.Replace("", pixmaps_path + "/document-edited-12.png"); + html = html.Replace("", pixmaps_path + "/document-deleted-12.png"); + html = html.Replace("", pixmaps_path + "/document-moved-12.png"); + + this.spinner.Stop(); + + this.webbrowser.ObjectForScripting = new SparkleScriptingObject(); + this.webbrowser.NavigateToString(html); + } + + + public void UpdateChooser(string[] folders) + { + if (folders == null) + { + folders = Controller.Folders; + } + + this.combobox.Items.Clear(); + this.combobox.Items.Add(new ComboBoxItem() { Content = "Summary" }); + this.combobox.Items.Add(new Separator()); + this.combobox.SelectedItem = combobox.Items[0]; + + int row = 2; + foreach (string folder in folders) + { + this.combobox.Items.Add(new ComboBoxItem() { Content = folder }); + + if (folder.Equals(Controller.SelectedFolder)) + this.combobox.SelectedItem = this.combobox.Items[row]; + + row++; + } + + this.combobox.SelectionChanged += delegate { + Dispatcher.BeginInvoke((Action)delegate { + int index = this.combobox.SelectedIndex; + + if (index == 0) + Controller.SelectedFolder = null; + else + Controller.SelectedFolder = (string)((ComboBoxItem)this.combobox.Items[index]).Content; + }); + }; + } + + + private void WriteOutImages() + { + string tmp_path = Sparkles.Configuration.DefaultConfiguration.TmpPath; + string pixmaps_path = System.IO.Path.Combine(tmp_path, "Images"); + + if (!Directory.Exists(pixmaps_path)) + { + Directory.CreateDirectory(pixmaps_path); + + File.SetAttributes(tmp_path, File.GetAttributes(tmp_path) | FileAttributes.Hidden); + } + + BitmapSource image = SparkleUIHelpers.GetImageSource("user-icon-default"); + string file_path = System.IO.Path.Combine(pixmaps_path, "user-icon-default.png"); + + using (FileStream stream = new FileStream(file_path, FileMode.Create)) + { + BitmapEncoder encoder = new PngBitmapEncoder(); + encoder.Frames.Add(BitmapFrame.Create(image)); + encoder.Save(stream); + } + + string[] actions = new string[] { "added", "deleted", "edited", "moved" }; + + foreach (string action in actions) + { + image = SparkleUIHelpers.GetImageSource("document-" + action + "-12"); + file_path = System.IO.Path.Combine(pixmaps_path, "document-" + action + "-12.png"); + + using (FileStream stream = new FileStream(file_path, FileMode.Create)) + { + BitmapEncoder encoder = new PngBitmapEncoder(); + encoder.Frames.Add(BitmapFrame.Create(image)); + encoder.Save(stream); + } + } + } + } + + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + [ComVisible(true)] + public class SparkleScriptingObject + { + public void LinkClicked(string url) + { + SparkleShare.UI.EventLog.Controller.LinkClicked(url); + } + } +} \ No newline at end of file diff --git a/SparkleShare/Windows/SparkleNote.xaml b/SparkleShare/Windows/Note.xaml similarity index 98% rename from SparkleShare/Windows/SparkleNote.xaml rename to SparkleShare/Windows/Note.xaml index 355b2cd2..76ffd742 100644 --- a/SparkleShare/Windows/SparkleNote.xaml +++ b/SparkleShare/Windows/Note.xaml @@ -1,4 +1,4 @@ - -// -// 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 System; -using System.ComponentModel; -using System.Runtime.InteropServices; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Input; -using System.Windows.Markup; - -using Drawing = System.Drawing; -using Forms = System.Windows.Forms; - -namespace SparkleShare { - - [ContentProperty("Text")] - [DefaultEvent("MouseDoubleClick")] - public class SparkleNotifyIcon : UIElement, IAddChild { - - [DllImport("user32.dll", EntryPoint = "DestroyIcon")] - static extern bool DestroyIcon(IntPtr h_icon); - - public Drawing.Bitmap Icon { - set { - NotifyIcon.Icon = GetIconFromBitmap(value); - } - } - - public string Text { - get { - return (string) GetValue(TextProperty); - } - set { - var text = value; - - if(!string.IsNullOrEmpty(HeaderText)) - text = HeaderText + "\n" + text; - - SetValue(TextProperty, text); - } - } - - public ContextMenu ContextMenu { - get; - set; - } - - public string HeaderText { - get; - set; - } - - private Forms.NotifyIcon NotifyIcon { - get; - set; - } - - public readonly RoutedEvent MouseClickEvent = EventManager.RegisterRoutedEvent( - "MouseClick", RoutingStrategy.Bubble, typeof(MouseButtonEventHandler), typeof(SparkleNotifyIcon)); - - public readonly RoutedEvent MouseDoubleClickEvent = EventManager.RegisterRoutedEvent( - "MouseDoubleClick", RoutingStrategy.Bubble, typeof(MouseButtonEventHandler), typeof(SparkleNotifyIcon)); - - public readonly DependencyProperty TextProperty = DependencyProperty.Register( - "Text", typeof(string), typeof(SparkleNotifyIcon), new PropertyMetadata(OnTextChanged)); - - public SparkleNotifyIcon() { - VisibilityProperty.OverrideMetadata(typeof(SparkleNotifyIcon), new PropertyMetadata(OnVisibilityChanged)); - - NotifyIcon = new Forms.NotifyIcon { - Text = Text, - Visible = true, - ContextMenu = new Forms.ContextMenu() - }; - NotifyIcon.MouseDown += OnMouseDown; - NotifyIcon.MouseUp += OnMouseUp; - NotifyIcon.MouseClick += OnMouseClick; - NotifyIcon.MouseDoubleClick += OnMouseDoubleClick; - } - - public void ShowBalloonTip(string title, string subtext, string image_path) { - // TODO: - // - Use the image pointed to by image_path - // - Find a way to use the prettier (Win7?) balloons - NotifyIcon.ShowBalloonTip(5 * 1000, title, subtext, Forms.ToolTipIcon.Info); - } - - public void Dispose() { - NotifyIcon.Dispose(); - } - - - void IAddChild.AddChild(object value) { - throw new InvalidOperationException(); - } - - void IAddChild.AddText(string text) { - if(text == null) - throw new ArgumentNullException(); - - Text = text; - } - - private static MouseButtonEventArgs CreateMouseButtonEventArgs(RoutedEvent handler, Forms.MouseButtons button) { - MouseButton mouse_button; - - if(button == Forms.MouseButtons.Left) { - mouse_button = MouseButton.Left; - - } else if(button == Forms.MouseButtons.Right) { - mouse_button = MouseButton.Right; - - } else if(button == Forms.MouseButtons.Middle) { - mouse_button = MouseButton.Middle; - - } else if(button == Forms.MouseButtons.XButton1) { - mouse_button = MouseButton.XButton1; - - } else if(button == Forms.MouseButtons.XButton2) { - mouse_button = MouseButton.XButton2; - - } else { - throw new InvalidOperationException(); - } - - return new MouseButtonEventArgs(InputManager.Current.PrimaryMouseDevice, 0, mouse_button) { - RoutedEvent = handler - }; - } - - private void OnVisibilityChanged(DependencyObject target, DependencyPropertyChangedEventArgs args) { - SparkleNotifyIcon control = (SparkleNotifyIcon) target; - control.NotifyIcon.Visible = (control.Visibility == Visibility.Visible); - } - - private void OnMouseDown(object sender, Forms.MouseEventArgs args) { - RaiseEvent(CreateMouseButtonEventArgs(MouseDownEvent, args.Button)); - } - - private void OnMouseClick(object sender, Forms.MouseEventArgs args) { - RaiseEvent(CreateMouseButtonEventArgs(MouseClickEvent, args.Button)); - } - - private void OnMouseDoubleClick(object sender, Forms.MouseEventArgs args) { - RaiseEvent(CreateMouseButtonEventArgs(MouseDoubleClickEvent, args.Button)); - } - - private void OnMouseUp(object sender, Forms.MouseEventArgs args) { - - if(args.Button == Forms.MouseButtons.Right) { - - ContextMenu.IsOpen = true; - ContextMenu.StaysOpen = false; - } - - RaiseEvent(CreateMouseButtonEventArgs(MouseUpEvent, args.Button)); - } - - private static void OnTextChanged(DependencyObject target, DependencyPropertyChangedEventArgs args) { - SparkleNotifyIcon control = (SparkleNotifyIcon) target; - control.NotifyIcon.Text = control.Text; - } - - - private static Drawing.Icon GetIconFromBitmap(Drawing.Bitmap bitmap) { - IntPtr unmanaged_icon = bitmap.GetHicon(); - Drawing.Icon icon = (Drawing.Icon) Drawing.Icon.FromHandle(unmanaged_icon).Clone(); - DestroyIcon(unmanaged_icon); - - return icon; - } - } -} +// SparkleShare, a collaboration and sharing tool. +// 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 System; +using System.ComponentModel; +using System.Runtime.InteropServices; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; +using System.Windows.Markup; + +using Drawing = System.Drawing; +using Forms = System.Windows.Forms; + +namespace SparkleShare { + + [ContentProperty("Text")] + [DefaultEvent("MouseDoubleClick")] + public class NotifyIcon : UIElement, IAddChild { + + [DllImport("user32.dll", EntryPoint = "DestroyIcon")] + static extern bool DestroyIcon(IntPtr h_icon); + + public Drawing.Bitmap Icon { + set { + Notification.Icon = GetIconFromBitmap(value); + } + } + + public string Text { + get { + return (string) GetValue(TextProperty); + } + set { + var text = value; + + if(!string.IsNullOrEmpty(HeaderText)) + text = HeaderText + "\n" + text; + + SetValue(TextProperty, text); + } + } + + public ContextMenu ContextMenu { + get; + set; + } + + public string HeaderText { + get; + set; + } + + private Forms.NotifyIcon Notification { + get; + set; + } + + public readonly RoutedEvent MouseClickEvent = EventManager.RegisterRoutedEvent( + "MouseClick", RoutingStrategy.Bubble, typeof(MouseButtonEventHandler), typeof(NotifyIcon)); + + public readonly RoutedEvent MouseDoubleClickEvent = EventManager.RegisterRoutedEvent( + "MouseDoubleClick", RoutingStrategy.Bubble, typeof(MouseButtonEventHandler), typeof(NotifyIcon)); + + public readonly DependencyProperty TextProperty = DependencyProperty.Register( + "Text", typeof(string), typeof(NotifyIcon), new PropertyMetadata(OnTextChanged)); + + public NotifyIcon() { + VisibilityProperty.OverrideMetadata(typeof(NotifyIcon), new PropertyMetadata(OnVisibilityChanged)); + + Notification = new Forms.NotifyIcon { + Text = Text, + Visible = true, + ContextMenu = new Forms.ContextMenu() + }; + Notification.MouseDown += OnMouseDown; + Notification.MouseUp += OnMouseUp; + Notification.MouseClick += OnMouseClick; + Notification.MouseDoubleClick += OnMouseDoubleClick; + } + + public void ShowBalloonTip(string title, string subtext, string image_path) { + // TODO: + // - Use the image pointed to by image_path + // - Find a way to use the prettier (Win7?) balloons + Notification.ShowBalloonTip(5 * 1000, title, subtext, Forms.ToolTipIcon.Info); + } + + public void Dispose() { + Notification.Dispose(); + } + + + void IAddChild.AddChild(object value) { + throw new InvalidOperationException(); + } + + void IAddChild.AddText(string text) { + if(text == null) + throw new ArgumentNullException(); + + Text = text; + } + + private static MouseButtonEventArgs CreateMouseButtonEventArgs(RoutedEvent handler, Forms.MouseButtons button) { + MouseButton mouse_button; + + if(button == Forms.MouseButtons.Left) { + mouse_button = MouseButton.Left; + + } else if(button == Forms.MouseButtons.Right) { + mouse_button = MouseButton.Right; + + } else if(button == Forms.MouseButtons.Middle) { + mouse_button = MouseButton.Middle; + + } else if(button == Forms.MouseButtons.XButton1) { + mouse_button = MouseButton.XButton1; + + } else if(button == Forms.MouseButtons.XButton2) { + mouse_button = MouseButton.XButton2; + + } else { + throw new InvalidOperationException(); + } + + return new MouseButtonEventArgs(InputManager.Current.PrimaryMouseDevice, 0, mouse_button) { + RoutedEvent = handler + }; + } + + private void OnVisibilityChanged(DependencyObject target, DependencyPropertyChangedEventArgs args) { + NotifyIcon control = (NotifyIcon) target; + control.Notification.Visible = (control.Visibility == Visibility.Visible); + } + + private void OnMouseDown(object sender, Forms.MouseEventArgs args) { + RaiseEvent(CreateMouseButtonEventArgs(MouseDownEvent, args.Button)); + } + + private void OnMouseClick(object sender, Forms.MouseEventArgs args) { + RaiseEvent(CreateMouseButtonEventArgs(MouseClickEvent, args.Button)); + } + + private void OnMouseDoubleClick(object sender, Forms.MouseEventArgs args) { + RaiseEvent(CreateMouseButtonEventArgs(MouseDoubleClickEvent, args.Button)); + } + + private void OnMouseUp(object sender, Forms.MouseEventArgs args) { + + if(args.Button == Forms.MouseButtons.Right) { + + ContextMenu.IsOpen = true; + ContextMenu.StaysOpen = false; + } + + RaiseEvent(CreateMouseButtonEventArgs(MouseUpEvent, args.Button)); + } + + private static void OnTextChanged(DependencyObject target, DependencyPropertyChangedEventArgs args) { + NotifyIcon control = (NotifyIcon) target; + control.Notification.Text = control.Text; + } + + + private static Drawing.Icon GetIconFromBitmap(Drawing.Bitmap bitmap) { + IntPtr unmanaged_icon = bitmap.GetHicon(); + Drawing.Icon icon = (Drawing.Icon) Drawing.Icon.FromHandle(unmanaged_icon).Clone(); + DestroyIcon(unmanaged_icon); + + return icon; + } + } +} diff --git a/SparkleShare/Windows/SparkleSetup.cs b/SparkleShare/Windows/Setup.cs similarity index 82% rename from SparkleShare/Windows/SparkleSetup.cs rename to SparkleShare/Windows/Setup.cs index 1cd7b6cf..4064f0c7 100644 --- a/SparkleShare/Windows/SparkleSetup.cs +++ b/SparkleShare/Windows/Setup.cs @@ -15,6 +15,7 @@ // along with this program. If not, see . +using Sparkles; using System; using System.Collections.Generic; using System.ComponentModel; @@ -36,12 +37,12 @@ using WPF = System.Windows.Controls; namespace SparkleShare { - public class SparkleSetup : SparkleSetupWindow { + public class Setup : SetupWindow { - public SparkleSetupController Controller = new SparkleSetupController (); + public SetupController Controller = new SetupController (); - public SparkleSetup () + public Setup () { Controller.ShowWindowEvent += delegate { Dispatcher.BeginInvoke ((Action) delegate { @@ -268,7 +269,7 @@ namespace SparkleShare { header_style.Setters.Add (new Setter (GridViewColumnHeader.VisibilityProperty, Visibility.Collapsed)); grid_view.ColumnHeaderContainerStyle = header_style; - foreach (SparklePreset plugin in Controller.Presets) { + foreach (Preset plugin in Controller.Presets) { // FIXME: images are blurry BitmapFrame image = BitmapFrame.Create ( new Uri (plugin.ImagePath) @@ -814,167 +815,6 @@ namespace SparkleShare { break; } - - case PageType.Tutorial: { - switch (Controller.TutorialPageNumber) { - case 1: { - Header = "What’s happening next?"; - Description = "SparkleShare creates a special folder on your computer " + - "that will keep track of your projects."; - - - WPF.Image slide_image = new WPF.Image () { - Width = 324, - Height = 200 - }; - - slide_image.Source = SparkleUIHelpers.GetImageSource ("tutorial-slide-1"); - - Button skip_tutorial_button = new Button () { - Content = "Skip tutorial" - }; - - Button continue_button = new Button () { - Content = "Continue" - }; - - - ContentCanvas.Children.Add (slide_image); - Canvas.SetLeft (slide_image, 228); - Canvas.SetTop (slide_image, 130); - - Buttons.Add (skip_tutorial_button); - Buttons.Add (continue_button); - - - skip_tutorial_button.Click += delegate { - Controller.TutorialSkipped (); - }; - - continue_button.Click += delegate { - Controller.TutorialPageCompleted (); - }; - - break; - } - - case 2: { - Header = "Sharing files with others"; - Description = "All files added to your project folders are synced automatically with " + - "the host and your team members."; - - - Button continue_button = new Button () { - Content = "Continue" - }; - - WPF.Image slide_image = new WPF.Image () { - Width = 324, - Height = 200 - }; - - slide_image.Source = SparkleUIHelpers.GetImageSource ("tutorial-slide-2"); - - - ContentCanvas.Children.Add (slide_image); - Canvas.SetLeft (slide_image, 228); - Canvas.SetTop (slide_image, 130); - - Buttons.Add (continue_button); - - - continue_button.Click += delegate { - Controller.TutorialPageCompleted (); - }; - - break; - } - - case 3: { - Header = "The status icon helps you"; - Description = "It shows the syncing progress, provides easy access to " + - "your projects, and lets you view recent changes."; - - Button continue_button = new Button () { - Content = "Continue" - }; - - WPF.Image slide_image = new WPF.Image () { - Width = 324, - Height = 200 - }; - - slide_image.Source = SparkleUIHelpers.GetImageSource ("tutorial-slide-3"); - - - ContentCanvas.Children.Add (slide_image); - Canvas.SetLeft (slide_image, 228); - Canvas.SetTop (slide_image, 130); - - Buttons.Add (continue_button); - - - continue_button.Click += delegate { - Controller.TutorialPageCompleted (); - }; - - break; - } - - case 4: { - Header = "Here’s your unique Client ID"; - Description = "You’ll need it whenever you want to link this computer to a host. " + - "You can also find it in the status icon menu."; - - - TextBox link_code_text_box = new TextBox () { - Text = SparkleShare.Controller.CurrentUser.PublicKey, - Width = 250, - MaxLines = 1, - TextWrapping = TextWrapping.NoWrap, - IsEnabled = false - }; - - Button copy_button = new Button () { - Content = "Copy", - Width = 60 - }; - - Button finish_button = new Button () { - Content = "Finish" - }; - - CheckBox check_box = new CheckBox () { - Content = "Add SparkleShare to startup items", - IsChecked = true - }; - - - ContentCanvas.Children.Add (link_code_text_box); - Canvas.SetLeft (link_code_text_box, 235); - Canvas.SetTop (link_code_text_box, 190); - - ContentCanvas.Children.Add (copy_button); - Canvas.SetLeft (copy_button, 490); - Canvas.SetTop (copy_button, 190); - - ContentCanvas.Children.Add (check_box); - Canvas.SetLeft (check_box, 185); - Canvas.SetBottom (check_box, 12); - - Buttons.Add (finish_button); - - - check_box.Click += delegate { Controller.StartupItemChanged (check_box.IsChecked.Value); }; - finish_button.Click += delegate { Controller.TutorialPageCompleted (); }; - copy_button.Click += delegate { Controller.CopyToClipboardClicked(); }; - - break; - } - } - - break; - } } ShowAll (); diff --git a/SparkleShare/Windows/SparkleSetupWindow.cs b/SparkleShare/Windows/SetupWindow.cs similarity index 95% rename from SparkleShare/Windows/SparkleSetupWindow.cs rename to SparkleShare/Windows/SetupWindow.cs index 87607e24..c4e47eab 100644 --- a/SparkleShare/Windows/SparkleSetupWindow.cs +++ b/SparkleShare/Windows/SetupWindow.cs @@ -1,193 +1,193 @@ -// SparkleShare, a collaboration and sharing tool. -// 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 System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Forms.Integration; -using System.Windows.Media; -using System.Windows.Shapes; -using System.Windows.Shell; -using System.Runtime.InteropServices; -using System.Windows.Interop; - -namespace SparkleShare { - - public class SparkleSetupWindow : Window { - - public Canvas ContentCanvas = new Canvas (); - public List