From 6c4d06d24a8826fb81751d2e83742ffdc71751a1 Mon Sep 17 00:00:00 2001 From: Leonardo Robol Date: Wed, 10 Feb 2010 10:37:17 +0100 Subject: [PATCH] Aggiunto supporto alle dimensione nei file. --- Dizzy/File.cs | 29 +++++++++++++++++++++++++---- Dizzy/FileTreeView.cs | 23 ++++++++++++++++++----- Dizzy/Protocol.cs | 2 ++ 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/Dizzy/File.cs b/Dizzy/File.cs index 1382f3f..4ecc683 100644 --- a/Dizzy/File.cs +++ b/Dizzy/File.cs @@ -50,7 +50,8 @@ namespace Dizzy public FileType type; public File (string path, string user) : this (path, user, 0) {} - public File (string path, string user, int size) + public File (string path, string user, int size) : this (path, user, "", size) {} + public File (string path, string user, string name, int size) { // Determino il tipo di file type = new FileType (path); @@ -63,13 +64,33 @@ namespace Dizzy } this.user = user; this.path = path; - // Console.WriteLine("Path set to: {0}", this.path); - string[] pieces = path.Split ('/'); + this.size = size; - name = pieces[pieces.Length - 1]; + if (name == "") + { + string[] pieces = path.Split ('/'); + name = pieces[pieces.Length - 1]; + } + else + { + this.name = name; + } } + public string SizeToString () { + + // Piccoli bytes + if (size < 1024) + return size.ToString() + " B"; + else if (size < 1024*1024) + { + return (size/1024).ToString () + " KB"; + } + else + return System.Convert.ToString( (size/1024/1024).ToString () + " MB"); + } + } } diff --git a/Dizzy/FileTreeView.cs b/Dizzy/FileTreeView.cs index a0cf207..4fd33aa 100644 --- a/Dizzy/FileTreeView.cs +++ b/Dizzy/FileTreeView.cs @@ -14,6 +14,7 @@ namespace Dizzy // Le colonne che ci servono Gtk.TreeViewColumn filenameColumn; Gtk.TreeViewColumn userColumn; + Gtk.TreeViewColumn sizeColumn; // La listStore per memorizzare i file // che troviamo. @@ -31,12 +32,18 @@ namespace Dizzy this.userColumn = new Gtk.TreeViewColumn (); userColumn.Title = "Utente"; + this.sizeColumn = new Gtk.TreeViewColumn (); + sizeColumn.Title = "Dimensione"; + sizeColumn.Resizable = true; + this.tree.AppendColumn (filenameColumn); + this.tree.AppendColumn (sizeColumn); this.tree.AppendColumn (userColumn); this.fileListStore = new Gtk.ListStore (typeof(string), // Nome del file - typeof(string), // Utente - typeof(string));// Path del file. + typeof(string), // Utente + typeof(string), // Path del file + typeof(string));// Dimensione this.tree.Model = fileListStore; CellSetup (); @@ -52,6 +59,11 @@ namespace Dizzy filenameColumn.PackStart (filenameRenderer, true); filenameColumn.AddAttribute (filenameRenderer, "text", 0); + // Dimensione + Gtk.CellRendererText sizeRenderer = new Gtk.CellRendererText (); + sizeColumn.PackStart (sizeRenderer, true); + sizeColumn.AddAttribute (sizeRenderer, "text", 3); + // Utente Gtk.CellRendererText userRenderer = new Gtk.CellRendererText (); userColumn.Resizable = true; @@ -64,9 +76,10 @@ namespace Dizzy { lock (this) { // Aggiungo i valori effettivi nel liststore. - fileListStore.AppendValues(file.name, - file.user, - file.path); + fileListStore.AppendValues( file.name, + file.user, + file.path, + file.SizeToString ()); } } diff --git a/Dizzy/Protocol.cs b/Dizzy/Protocol.cs index e61738b..4d2c812 100644 --- a/Dizzy/Protocol.cs +++ b/Dizzy/Protocol.cs @@ -454,8 +454,10 @@ namespace Dizzy { matches.Add (new File(reader.GetString(0), // Path reader.GetString(2), // User + reader.GetString(1), // Name reader.GetInt32(3))); // Size } + this.connection.Close (); return matches; } -- 2.1.4