diff --git a/CmisSync.Lib/Utils.cs b/CmisSync.Lib/Utils.cs index 2896aaf8e..4b7f63f3c 100755 --- a/CmisSync.Lib/Utils.cs +++ b/CmisSync.Lib/Utils.cs @@ -455,6 +455,24 @@ public static string FormatSize(double byteCount) return byteCount.ToString() + " bytes"; } + /// + /// Format a file size nicely with the exact value. + /// Example: 1048576 becomes "1 MB" + /// + public static string FormatSizeExact(double byteCount) + { + if (byteCount >= 1099511627776) + return String.Format("{0:##.##} TB", (double)(byteCount / 1099511627776)); + else if (byteCount >= 1073741824) + return String.Format("{0:##.##} GB", (double)(byteCount / 1073741824)); + else if (byteCount >= 1048576) + return String.Format("{0:##.##} MB", (double)(byteCount / 1048576)); + else if (byteCount >= 1024) + return String.Format("{0:##.##} KB", (double)(byteCount / 1024)); + else + return byteCount.ToString() + " bytes"; + } + /// /// Formats the bandwidth in typical 10 based calculation /// @@ -487,6 +505,15 @@ public static string FormatSize(long byteCount) return FormatSize((double) byteCount); } + /// + /// Format a file size nicely with the exact value. + /// Example: 1048576 becomes "1 MB" + /// + public static string FormatSizeExact(long byteCount) + { + return FormatSizeExact((double) byteCount); + } + /// /// Formats the bandwidth in typical 10 based calculation /// diff --git a/CmisSync/ControllerBase.cs b/CmisSync/ControllerBase.cs index 11737c0a4..43ea631ea 100755 --- a/CmisSync/ControllerBase.cs +++ b/CmisSync/ControllerBase.cs @@ -84,6 +84,11 @@ public abstract class ControllerBase : IActivityListener /// public event Action ShowAboutWindowEvent = delegate { }; + /// + /// Show sync size window event. + /// + public event Action ShowSyncSizeWindowEvent = delegate { }; + /// /// Folder list changed. /// @@ -508,6 +513,14 @@ public void ShowAboutWindow() ShowAboutWindowEvent(); } + // + /// Show info about CmisSync + /// + public void ShowSyncSizeWindow() + { + ShowSyncSizeWindowEvent(); + } + /// /// Show an alert to the user. /// diff --git a/CmisSync/Linux/CmisSync.csproj b/CmisSync/Linux/CmisSync.csproj index d877d0a9e..050d0edb9 100644 --- a/CmisSync/Linux/CmisSync.csproj +++ b/CmisSync/Linux/CmisSync.csproj @@ -95,6 +95,8 @@ + + diff --git a/CmisSync/Linux/GUI.cs b/CmisSync/Linux/GUI.cs index 49ad5827f..1724817af 100644 --- a/CmisSync/Linux/GUI.cs +++ b/CmisSync/Linux/GUI.cs @@ -27,6 +27,7 @@ public class GUI { public StatusIcon StatusIcon; public Setup Setup; public About About; + public SyncSize SyncSize; public static string AssetsPath = (null != Environment.GetEnvironmentVariable("CMISSYNC_ASSETS_DIR")) @@ -38,6 +39,7 @@ public GUI () Setup = new Setup (); About = new About (); + SyncSize = new SyncSize (); StatusIcon = new StatusIcon (); CmisSync.Lib.Utils.SetUserNotificationListener (new UserNotificationListenerLinux (StatusIcon)); Program.Controller.UIHasLoaded (); diff --git a/CmisSync/Linux/Makefile.am b/CmisSync/Linux/Makefile.am index 1fa2d34c2..e71b34a70 100644 --- a/CmisSync/Linux/Makefile.am +++ b/CmisSync/Linux/Makefile.am @@ -9,6 +9,7 @@ LIBS = $(REF_CMISSYNC) $(LOG4NET_LIBS) $(NOTIFY_SHARP_LIBS) $(LIB_CMISAUTH) $(DO SOURCES = \ ../AboutController.cs \ + ../SyncSizeController.cs \ ../CertPolicyHandler.cs \ ../ControllerBase.cs \ ../EditController.cs \ @@ -16,6 +17,7 @@ SOURCES = \ ../SetupController.cs \ ../StatusIconController.cs \ About.cs \ + SyncSize.cs \ CertPolicyWindow.cs \ CmisTree/CmisTreeStore.cs \ CmisTree/LoadingStatusModel.cs \ diff --git a/CmisSync/Linux/StatusIcon.cs b/CmisSync/Linux/StatusIcon.cs index 8aebd4af7..1012b0206 100644 --- a/CmisSync/Linux/StatusIcon.cs +++ b/CmisSync/Linux/StatusIcon.cs @@ -260,6 +260,14 @@ public void CreateMenu () }; this.menu.Add (about_item); + // Sync size Menu + MenuItem Syncsize_item = new MenuItem ( + "Syncing size"); + Syncsize_item.Activated += delegate { + Controller.SyncSizeClicked (); + }; + this.menu.Add (Syncsize_item); + this.quit_item = new MenuItem ( CmisSync.Properties_Resources.Exit) { Sensitive = true diff --git a/CmisSync/Linux/SyncSize.cs b/CmisSync/Linux/SyncSize.cs new file mode 100644 index 000000000..3962fb029 --- /dev/null +++ b/CmisSync/Linux/SyncSize.cs @@ -0,0 +1,126 @@ +// CmisSync, a collaboration and sharing tool. +// Copyright (C) 2015 Momar DIENE +// +// 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 Gtk; +using Mono.Unix; +using CmisSync.Lib; +using System.IO; +using System.Collections.Generic; + +namespace CmisSync { + + public class SyncSize : Window { + + public SyncSizeController Controller = new SyncSizeController (); + + private Label reponame; + + + public SyncSize () : base ("") + { + DeleteEvent += delegate (object o, DeleteEventArgs args) { + Controller.WindowClosed (); + args.RetVal = true; + }; + + DefaultSize = new Gdk.Size (600, 260); + Resizable = false; + BorderWidth = 0; + IconName = "folder-cmissync"; + WindowPosition = WindowPosition.Center; + Title = "Syncing Size"; + AppPaintable = true; + + string image_path = System.IO.Path.Combine(GUI.AssetsPath, "pixmaps", "about.png"); + + Realize (); + Gdk.Pixbuf buf = new Gdk.Pixbuf (image_path); + Gdk.Pixmap map, map2; + buf.RenderPixmapAndMask (out map, out map2, 255); + GdkWindow.SetBackPixmap (map, false); + + + CreateSyncSize (); + + Controller.HideWindowEvent += delegate { + Application.Invoke (delegate { + HideAll (); + }); + }; + + Controller.ShowWindowEvent += delegate { + Application.Invoke (delegate { + ShowAll (); + Present (); + }); + }; + + } + + + private void CreateSyncSize () + { + + VBox layout_vertical = new VBox (false, 0); + double totalsize = 0; + + foreach (Config.SyncConfig.Folder f in ConfigManager.CurrentConfig.Folders) { + //Lrepobase.Add(new CmisSync.Lib.Sync.CmisRepo(f.GetRepoInfo (),new ActivityListenerAggregator(Program.Controller))); + + double size = 0; + size = SyncSizeController.GetDirectorySize (new DirectoryInfo (f.LocalPath), true); + totalsize += size; + reponame = new Label () { + Markup = string.Format("{0,-10}",f.DisplayName.ToString())+string.Format("{0,10}",CmisSync.Lib.Utils.FormatSizeExact(size).ToString()), + Xalign = 0.5f + }; + + layout_vertical.PackStart (new Label (""), false, false, 0); + layout_vertical.PackStart (reponame, false, false, 0); + + } + + + layout_vertical.PackStart (new Label ("========================="), false, false, 20); + layout_vertical.PackStart (new Label ("Total "+CmisSync.Lib.Utils.FormatSizeExact(totalsize)), false, false, 0); + + + HBox layout_horizontal = new HBox (false, 0) { + BorderWidth = 0, + HeightRequest = 260, + WidthRequest = 640 + }; + layout_horizontal.PackStart (new Label (""), false, false, 140); + layout_horizontal.PackStart (createScrolledWindow(layout_vertical), true, true, 0); + + Add (layout_horizontal); + } + + private static Widget createScrolledWindow(Widget child) + { + ScrolledWindow scrolledWindow = new ScrolledWindow(); + scrolledWindow.SetPolicy(PolicyType.Never, PolicyType.Automatic); + + scrolledWindow.AddWithViewport(child); + scrolledWindow.ShadowType=ShadowType.None; + + return scrolledWindow; + } + } +} diff --git a/CmisSync/Makefile.am b/CmisSync/Makefile.am index 2b3b23d8f..72db7aad9 100644 --- a/CmisSync/Makefile.am +++ b/CmisSync/Makefile.am @@ -9,6 +9,7 @@ endif EXTRA_DIST = \ Program.cs \ AboutController.cs \ + SyncSizeController.cs \ BubblesController.cs \ ControllerBase.cs \ EditController.cs \ diff --git a/CmisSync/StatusIconController.cs b/CmisSync/StatusIconController.cs index d7219ad09..8bf962bca 100755 --- a/CmisSync/StatusIconController.cs +++ b/CmisSync/StatusIconController.cs @@ -352,6 +352,14 @@ public void AboutClicked() Program.Controller.ShowAboutWindow(); } + /// + /// Show the SyncSize dialog. + /// + public void SyncSizeClicked() + { + Program.Controller.ShowSyncSizeWindow(); + } + /// /// Quit CmisSync. /// diff --git a/CmisSync/SyncSizeController.cs b/CmisSync/SyncSizeController.cs new file mode 100644 index 000000000..256ba3689 --- /dev/null +++ b/CmisSync/SyncSizeController.cs @@ -0,0 +1,84 @@ +// CmisSync, a collaboration and sharing tool. +// Copyright (C) 2015 Momar DIENE +// +// 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.Net; +using System.Threading; +using System.IO; +using System.Linq; + +using CmisSync.Lib; +using System.Collections.Generic; + +namespace CmisSync { + + /// + /// Controller for the SyncSize dialog. + /// + public class SyncSizeController { + + //===== Actions ===== + /// + /// Show SyncSize Windows Action + /// + public event Action ShowWindowEvent = delegate { }; + + /// + /// Hide SyncSize Windows Action + /// + public event Action HideWindowEvent = delegate { }; + + + /// + /// Constructor. + /// + public SyncSizeController() + { + Program.Controller.ShowSyncSizeWindowEvent += delegate + { + ShowWindowEvent(); + }; + + } + + + /// + /// Closing the dialog. + /// + public void WindowClosed () + { + HideWindowEvent (); + } + + + public static long GetDirectorySize(DirectoryInfo dInfo, bool includeSubDir) + { + // Enumerate all the files + long totalSize = dInfo.EnumerateFiles() + .Sum(file => file.Length); + + // If Subdirectories are to be included + if (includeSubDir) + { + // Enumerate all sub-directories + totalSize += dInfo.EnumerateDirectories() + .Sum(dir => GetDirectorySize(dir, true)); + } + return totalSize; + } + } +}