[statusicon] Show size in menu and fix list not updating after clone (626013)
This commit is contained in:
parent
69bb7d62a0
commit
719893183f
|
@ -259,10 +259,17 @@ namespace SparkleLib {
|
||||||
public void Fetch ()
|
public void Fetch ()
|
||||||
{
|
{
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
FetchTimer.Stop ();
|
FetchTimer.Stop ();
|
||||||
|
|
||||||
|
Process process = new Process () {
|
||||||
|
EnableRaisingEvents = true
|
||||||
|
};
|
||||||
|
|
||||||
|
process.StartInfo.FileName = "git";
|
||||||
|
process.StartInfo.RedirectStandardOutput = true;
|
||||||
|
process.StartInfo.UseShellExecute = false;
|
||||||
|
process.StartInfo.WorkingDirectory = LocalPath;
|
||||||
|
|
||||||
SparkleEventArgs args;
|
SparkleEventArgs args;
|
||||||
args = new SparkleEventArgs ("FetchingStarted");
|
args = new SparkleEventArgs ("FetchingStarted");
|
||||||
|
|
||||||
|
@ -271,14 +278,16 @@ namespace SparkleLib {
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Fetching changes...");
|
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Fetching changes...");
|
||||||
|
|
||||||
Process.StartInfo.Arguments = "fetch";
|
process.StartInfo.Arguments = "fetch";
|
||||||
|
|
||||||
Process.Start ();
|
process.Start ();
|
||||||
|
|
||||||
Process.Exited += delegate {
|
process.Exited += delegate {
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes fetched.");
|
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes fetched.");
|
||||||
|
|
||||||
|
// TODO: this doesn't exit sometimes
|
||||||
|
|
||||||
args = new SparkleEventArgs ("FetchingFinished");
|
args = new SparkleEventArgs ("FetchingFinished");
|
||||||
|
|
||||||
if (FetchingFinished != null)
|
if (FetchingFinished != null)
|
||||||
|
@ -286,13 +295,9 @@ namespace SparkleLib {
|
||||||
|
|
||||||
Rebase ();
|
Rebase ();
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
|
|
||||||
FetchTimer.Start ();
|
FetchTimer.Start ();
|
||||||
|
|
||||||
}
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,8 @@ namespace SparkleShare {
|
||||||
private string StateText;
|
private string StateText;
|
||||||
private Gdk.Pixbuf [] AnimationFrames;
|
private Gdk.Pixbuf [] AnimationFrames;
|
||||||
private int FrameNumber;
|
private int FrameNumber;
|
||||||
|
private Gtk.Action FolderAction;
|
||||||
|
private double FolderSize;
|
||||||
|
|
||||||
|
|
||||||
// Short alias for the translations
|
// Short alias for the translations
|
||||||
|
@ -46,6 +48,8 @@ namespace SparkleShare {
|
||||||
public SparkleStatusIcon () : base ()
|
public SparkleStatusIcon () : base ()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
FolderSize = GetFolderSize (new DirectoryInfo (SparklePaths.SparklePath));
|
||||||
|
|
||||||
CreateAnimationFrames ();
|
CreateAnimationFrames ();
|
||||||
CreateTimer ();
|
CreateTimer ();
|
||||||
|
|
||||||
|
@ -112,9 +116,48 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private double GetFolderSize (DirectoryInfo parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
double size = 0;
|
||||||
|
|
||||||
|
FileInfo [] files = parent.GetFiles();
|
||||||
|
|
||||||
|
foreach (FileInfo file in files)
|
||||||
|
size += file.Length;
|
||||||
|
|
||||||
|
foreach (DirectoryInfo directory in parent.GetDirectories())
|
||||||
|
size += GetFolderSize (directory);
|
||||||
|
|
||||||
|
return size;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private string GetSize (double byte_count)
|
||||||
|
{
|
||||||
|
|
||||||
|
string size = "";
|
||||||
|
|
||||||
|
if (byte_count >= 1099511627776)
|
||||||
|
size = String.Format ("{0:##.##}", Math.Round (byte_count / 1099511627776, 1)) + " TB";
|
||||||
|
else if (byte_count >= 1073741824)
|
||||||
|
size = String.Format ("{0:##.##}", Math.Round (byte_count / 1073741824, 1)) + " GB";
|
||||||
|
else if (byte_count >= 1048576)
|
||||||
|
size = String.Format ("{0:##.##}", Math.Round (byte_count / 1048576, 1)) + " MB";
|
||||||
|
else if (byte_count >= 1024)
|
||||||
|
size = String.Format ("{0:##.##}", Math.Round (byte_count / 1024, 1)) + " KB";
|
||||||
|
else
|
||||||
|
size = byte_count.ToString () + " bytes";
|
||||||
|
|
||||||
|
return size;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Creates the menu that is popped up when the
|
// Creates the menu that is popped up when the
|
||||||
// user clicks the statusicon
|
// user clicks the statusicon
|
||||||
private void CreateMenu ()
|
public void CreateMenu ()
|
||||||
{
|
{
|
||||||
|
|
||||||
Menu = new Menu ();
|
Menu = new Menu ();
|
||||||
|
@ -127,13 +170,12 @@ namespace SparkleShare {
|
||||||
|
|
||||||
Menu.Add (new SeparatorMenuItem ());
|
Menu.Add (new SeparatorMenuItem ());
|
||||||
|
|
||||||
// TODO: Append folder size in secondary text color
|
FolderAction = new Gtk.Action ("", "SparkleShare Folder (" + GetSize (FolderSize) + ")") {
|
||||||
Gtk.Action folder_action = new Gtk.Action ("", _("SparkleShare Folder")) {
|
|
||||||
IconName = "folder-sparkleshare",
|
IconName = "folder-sparkleshare",
|
||||||
IsImportant = true
|
IsImportant = true
|
||||||
};
|
};
|
||||||
|
|
||||||
folder_action.Activated += delegate {
|
FolderAction.Activated += delegate {
|
||||||
|
|
||||||
Process process = new Process ();
|
Process process = new Process ();
|
||||||
process.StartInfo.FileName = "xdg-open";
|
process.StartInfo.FileName = "xdg-open";
|
||||||
|
@ -142,20 +184,20 @@ namespace SparkleShare {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Menu.Add (folder_action.CreateMenuItem ());
|
Menu.Add (FolderAction.CreateMenuItem ());
|
||||||
|
|
||||||
if (SparkleUI.Repositories.Count > 0) {
|
if (SparkleUI.Repositories.Count > 0) {
|
||||||
|
|
||||||
foreach (SparkleRepo SparkleRepo in SparkleUI.Repositories) {
|
foreach (SparkleRepo SparkleRepo in SparkleUI.Repositories) {
|
||||||
|
|
||||||
folder_action = new Gtk.Action ("", SparkleRepo.Name) {
|
FolderAction = new Gtk.Action ("", SparkleRepo.Name) {
|
||||||
IconName = "folder",
|
IconName = "folder",
|
||||||
IsImportant = true
|
IsImportant = true
|
||||||
};
|
};
|
||||||
|
|
||||||
folder_action.Activated += CreateWindowDelegate (SparkleRepo);
|
FolderAction.Activated += CreateWindowDelegate (SparkleRepo);
|
||||||
|
|
||||||
Menu.Add (folder_action.CreateMenuItem ());
|
Menu.Add (FolderAction.CreateMenuItem ());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,6 +302,8 @@ namespace SparkleShare {
|
||||||
|
|
||||||
UpdateStatusMenuItem ();
|
UpdateStatusMenuItem ();
|
||||||
|
|
||||||
|
Console.WriteLine ("Number of repos syncing: " + SyncingReposCount);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -181,7 +181,7 @@ namespace SparkleShare {
|
||||||
"Exec=sparkleshare start\n" +
|
"Exec=sparkleshare start\n" +
|
||||||
"Icon=folder-sparkleshare\n" +
|
"Icon=folder-sparkleshare\n" +
|
||||||
"Terminal=false\n" +
|
"Terminal=false\n" +
|
||||||
"Categories=Network");
|
"Categories=Network;");
|
||||||
writer.Close ();
|
writer.Close ();
|
||||||
|
|
||||||
// Give the launcher the right permissions so it can be launched by the user
|
// Give the launcher the right permissions so it can be launched by the user
|
||||||
|
@ -199,6 +199,8 @@ namespace SparkleShare {
|
||||||
public void AddToBookmarks ()
|
public void AddToBookmarks ()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// TODO: don't add when the bookmark is already there
|
||||||
|
|
||||||
string bookmarks_file_name = Path.Combine (SparklePaths.HomePath, ".gtk-bookmarks");
|
string bookmarks_file_name = Path.Combine (SparklePaths.HomePath, ".gtk-bookmarks");
|
||||||
|
|
||||||
if (File.Exists (bookmarks_file_name)) {
|
if (File.Exists (bookmarks_file_name)) {
|
||||||
|
@ -327,6 +329,10 @@ namespace SparkleShare {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update the list in the statusicon
|
||||||
|
if (NotificationIcon != null)
|
||||||
|
NotificationIcon.CreateMenu ();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,4 +5,4 @@ Exec=sparkleshare start
|
||||||
Icon=folder-sparkleshare
|
Icon=folder-sparkleshare
|
||||||
Terminal=false
|
Terminal=false
|
||||||
X-GNOME-Autostart-enabled=true
|
X-GNOME-Autostart-enabled=true
|
||||||
Categories=Network
|
Categories=Network;
|
||||||
|
|
Loading…
Reference in a new issue