Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature sync size #570

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions CmisSync.Lib/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,24 @@ public static string FormatSize(double byteCount)
return byteCount.ToString() + " bytes";
}

/// <summary>
/// Format a file size nicely with the exact value.
/// Example: 1048576 becomes "1 MB"
/// </summary>
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";
}

/// <summary>
/// Formats the bandwidth in typical 10 based calculation
/// </summary>
Expand Down Expand Up @@ -487,6 +505,15 @@ public static string FormatSize(long byteCount)
return FormatSize((double) byteCount);
}

/// <summary>
/// Format a file size nicely with the exact value.
/// Example: 1048576 becomes "1 MB"
/// </summary>
public static string FormatSizeExact(long byteCount)
{
return FormatSizeExact((double) byteCount);
}

/// <summary>
/// Formats the bandwidth in typical 10 based calculation
/// </summary>
Expand Down
13 changes: 13 additions & 0 deletions CmisSync/ControllerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public abstract class ControllerBase : IActivityListener
/// </summary>
public event Action ShowAboutWindowEvent = delegate { };

/// <summary>
/// Show sync size window event.
/// </summary>
public event Action ShowSyncSizeWindowEvent = delegate { };

/// <summary>
/// Folder list changed.
/// </summary>
Expand Down Expand Up @@ -508,6 +513,14 @@ public void ShowAboutWindow()
ShowAboutWindowEvent();
}

// <summary>
/// Show info about CmisSync
/// </summary>
public void ShowSyncSizeWindow()
{
ShowSyncSizeWindowEvent();
}

/// <summary>
/// Show an alert to the user.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions CmisSync/Linux/CmisSync.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@
<Compile Include="Resources.Designer.cs" />
<Compile Include="Defines.cs" />
<Compile Include="UserNotificationListenerLinux.cs" />
<Compile Include="SyncSize.cs" />
<Compile Include="..\SyncSizeController.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\CmisSync.Lib\CmisSync.Lib.csproj">
Expand Down
2 changes: 2 additions & 0 deletions CmisSync/Linux/GUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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 ();
Expand Down
2 changes: 2 additions & 0 deletions CmisSync/Linux/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ LIBS = $(REF_CMISSYNC) $(LOG4NET_LIBS) $(NOTIFY_SHARP_LIBS) $(LIB_CMISAUTH) $(DO

SOURCES = \
../AboutController.cs \
../SyncSizeController.cs \
../CertPolicyHandler.cs \
../ControllerBase.cs \
../EditController.cs \
../Program.cs \
../SetupController.cs \
../StatusIconController.cs \
About.cs \
SyncSize.cs \
CertPolicyWindow.cs \
CmisTree/CmisTreeStore.cs \
CmisTree/LoadingStatusModel.cs \
Expand Down
8 changes: 8 additions & 0 deletions CmisSync/Linux/StatusIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
126 changes: 126 additions & 0 deletions CmisSync/Linux/SyncSize.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// CmisSync, a collaboration and sharing tool.
// Copyright (C) 2015 Momar DIENE <[email protected]>
//
// 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;
}
}
}
1 change: 1 addition & 0 deletions CmisSync/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ endif
EXTRA_DIST = \
Program.cs \
AboutController.cs \
SyncSizeController.cs \
BubblesController.cs \
ControllerBase.cs \
EditController.cs \
Expand Down
8 changes: 8 additions & 0 deletions CmisSync/StatusIconController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,14 @@ public void AboutClicked()
Program.Controller.ShowAboutWindow();
}

/// <summary>
/// Show the SyncSize dialog.
/// </summary>
public void SyncSizeClicked()
{
Program.Controller.ShowSyncSizeWindow();
}

/// <summary>
/// Quit CmisSync.
/// </summary>
Expand Down
84 changes: 84 additions & 0 deletions CmisSync/SyncSizeController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// CmisSync, a collaboration and sharing tool.
// Copyright (C) 2015 Momar DIENE <[email protected]>
//
// 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.Net;
using System.Threading;
using System.IO;
using System.Linq;

using CmisSync.Lib;
using System.Collections.Generic;

namespace CmisSync {

/// <summary>
/// Controller for the SyncSize dialog.
/// </summary>
public class SyncSizeController {

//===== Actions =====
/// <summary>
/// Show SyncSize Windows Action
/// </summary>
public event Action ShowWindowEvent = delegate { };

/// <summary>
/// Hide SyncSize Windows Action
/// </summary>
public event Action HideWindowEvent = delegate { };


/// <summary>
/// Constructor.
/// </summary>
public SyncSizeController()
{
Program.Controller.ShowSyncSizeWindowEvent += delegate
{
ShowWindowEvent();
};

}


/// <summary>
/// Closing the dialog.
/// </summary>
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;
}
}
}