From dfbdab0533ca730b8aff947c90715933d14e0297 Mon Sep 17 00:00:00 2001 From: Leonardo Robol Date: Mon, 1 Feb 2010 13:54:35 +0100 Subject: [PATCH] Aggiunta interfaccia di avvio che chiede nome utente e password e primi passi verso il download dei file. --- File.cs | 23 ++---- FileTreeView.cs | 25 ++++--- Main.cs | 30 +++++++- MainWindow.cs | 11 ++- Protocol.cs | 35 +++++---- gtk-gui/MainWindow.cs | 3 +- gtk-gui/gui.stetic | 191 +++++++++++++++++++++++++++++++++++++++++++++++++- 7 files changed, 264 insertions(+), 54 deletions(-) diff --git a/File.cs b/File.cs index c294d7d..46f7611 100644 --- a/File.cs +++ b/File.cs @@ -42,17 +42,17 @@ namespace Dizzy public class File { - public ulong size; + public string user; public string name; public string path; public FileType type; - public File (string path, ulong size, string user) + public File (string path, string user) { // Determino il tipo di file type = new FileType (path); - this.size = size; + this.user = user; string[] pieces = path.Split ('/'); @@ -60,21 +60,6 @@ namespace Dizzy } - public string SizeToString() - { - ulong t_size = size; - if(t_size < 1024) - return t_size.ToString () + " B"; - t_size /= 1024; - if(t_size < 1024) - return t_size.ToString () + " KB"; - t_size /= 1024; - if(t_size < 1024) - return t_size.ToString () + "MB"; - t_size /= 1024; - if(t_size < 1024) - return t_size.ToString () + "GB"; - return "Unknown"; - } + } } diff --git a/FileTreeView.cs b/FileTreeView.cs index 9a5d2c0..74d47fa 100644 --- a/FileTreeView.cs +++ b/FileTreeView.cs @@ -13,7 +13,6 @@ namespace Dizzy // Le colonne che ci servono Gtk.TreeViewColumn filenameColumn; - Gtk.TreeViewColumn sizeColumn; Gtk.TreeViewColumn userColumn; // La listStore per memorizzare i file @@ -28,18 +27,14 @@ namespace Dizzy this.filenameColumn = new Gtk.TreeViewColumn (); filenameColumn.Title = "Nome del file"; - this.sizeColumn = new Gtk.TreeViewColumn (); - sizeColumn.Title = "Dimensione"; - + this.userColumn = new Gtk.TreeViewColumn (); userColumn.Title = "Utente"; this.tree.AppendColumn (filenameColumn); - this.tree.AppendColumn (sizeColumn); this.tree.AppendColumn (userColumn); this.fileListStore = new Gtk.ListStore (typeof(string), // Nome del file - typeof(string), // Dimensione typeof(string), // Utente typeof(string));// Path del file. @@ -55,22 +50,17 @@ namespace Dizzy filenameColumn.PackStart (filenameRenderer, true); filenameColumn.AddAttribute (filenameRenderer, "text", 0); - // Dimensione del file - Gtk.CellRendererText sizeRenderer = new Gtk.CellRendererText (); - sizeColumn.PackStart (sizeRenderer, true); - sizeColumn.AddAttribute (sizeRenderer, "text", 1); - // Tipo di file + // Utente Gtk.CellRendererText userRenderer = new Gtk.CellRendererText (); userColumn.PackStart (userRenderer, true); - userColumn.AddAttribute (userRenderer, "text", 2); + userColumn.AddAttribute (userRenderer, "text", 1); } public void AddFile(Dizzy.File file) { // Aggiungo i valori effettivi nel liststore. fileListStore.AppendValues(file.name, - file.SizeToString () , file.user, file.path); } @@ -80,5 +70,14 @@ namespace Dizzy fileListStore.Clear (); } + public File GetFileFromPath (TreePath path) + { + TreeIter iter = new TreeIter (); + fileListStore.GetIter(out iter, path); + File f = new File((string) fileListStore.GetValue(iter, 0), + (string) fileListStore.GetValue(iter, 1)); + return f; + } + } } diff --git a/Main.cs b/Main.cs index 23aec21..b5f5c13 100644 --- a/Main.cs +++ b/Main.cs @@ -3,14 +3,38 @@ using Gtk; namespace Dizzy { + class MainClass { + public static void Main (string[] args) { Application.Init (); - MainWindow win = new MainWindow (); - win.Show (); - Application.Run (); + + // Inizializziamo la configurazione generale. + // Forse sarebbe il caso di salvarla su file e + // poi passarla per riferimento a tutte le form. + GlobalConfig config = new GlobalConfig (); + + // Cosa vogliamo fare + MainWindow win; + StartupDialog s; + + s = new StartupDialog (ref config); + s.Run (); + + try + { + win = new MainWindow (config.user, config.password); + win.ShowAll (); + Application.Run (); + } + catch(Exception e) + { + Console.WriteLine(" => Problemi di autenticazione...non riprovo"); + Console.WriteLine(e.Message); + } + } } } diff --git a/MainWindow.cs b/MainWindow.cs index cf17566..72938a8 100644 --- a/MainWindow.cs +++ b/MainWindow.cs @@ -9,7 +9,7 @@ public partial class MainWindow : Gtk.Window FileTreeView files; TaskTreeView tasks; - public MainWindow () : base(Gtk.WindowType.Toplevel) + public MainWindow (string user, string password) : base(Gtk.WindowType.Toplevel) { Build (); @@ -20,7 +20,7 @@ public partial class MainWindow : Gtk.Window // .. e anche quella dei download tasks = new Dizzy.TaskTreeView (tasklist); - this.protocol = new Protocol ("robol", "E2omhj99"); + this.protocol = new Protocol (user, password); } @@ -35,5 +35,12 @@ public partial class MainWindow : Gtk.Window { this.protocol.Search(searchBox.Text, ref this.files); } + + protected virtual void OnRowActivated (object o, Gtk.RowActivatedArgs args) + { + File f = this.files.GetFileFromPath (args.Path); + // this.tasks.AddTask (f.name, 24); + this.protocol.Download(f, ref tasks); + } } diff --git a/Protocol.cs b/Protocol.cs index 2eba354..60043c0 100644 --- a/Protocol.cs +++ b/Protocol.cs @@ -92,12 +92,23 @@ namespace Dizzy this.sftpUpdater.Disconnect (); } + + public void Download(File f, ref TaskTreeView tasks) + { + SFTPConnection sftp = new SFTPConnection(this.user, this.password); + sftp.Connect (); + + } + } public class SFTPConnection { - Sftp sftp; + public Sftp sftp; + + public delegate void Delegate (string src, string dest, + int transferredBytes, int totalBytes, string message); public SFTPConnection (string user, string password) { @@ -106,26 +117,20 @@ namespace Dizzy this.sftp = new Sftp ("poisson.phc.unipi.it", user); this.sftp.Password = password; + } + + public void SetTransferHandlers(Delegate OnTransferStart, + Delegate OnTransferProgress, + Delegate OnTransferEnd) + { + this.sftp.OnTransferStart += new FileTransferEvent (OnTransferStart); this.sftp.OnTransferProgress += new FileTransferEvent (OnTransferProgress); this.sftp.OnTransferEnd += new FileTransferEvent (OnTransferEnd); } - private void OnTransferStart (string src, string dest, int transferredBytes, int totalBytes, string message) - { - System.Console.WriteLine(" => Transfer Starting..."); - } - - private void OnTransferProgress (string src, string dest, int trasferredBytes, int totalBytes, string message) - { - System.Console.WriteLine(" => Tranfer progress...."); - } - private void OnTransferEnd (string src, string dest, int trasferredBytes, int totalBytes, string message) - { - System.Console.WriteLine(" => Tranfer Finished!"); - } public void Connect() { @@ -173,7 +178,7 @@ namespace Dizzy user = folder; if(user.Contains("/")) user = user.Substring(0, user.IndexOf("/")); - f = new File(folder + "/" + entry, 0, user ); + f = new File(folder + "/" + entry, user ); matches.Add(f); } } diff --git a/gtk-gui/MainWindow.cs b/gtk-gui/MainWindow.cs index ae6039d..b2df7e0 100644 --- a/gtk-gui/MainWindow.cs +++ b/gtk-gui/MainWindow.cs @@ -76,7 +76,7 @@ public partial class MainWindow { this.notebook1 = new Gtk.Notebook(); this.notebook1.CanFocus = true; this.notebook1.Name = "notebook1"; - this.notebook1.CurrentPage = 1; + this.notebook1.CurrentPage = 0; // Container child notebook1.Gtk.Notebook+NotebookChild this.vbox3 = new Gtk.VBox(); this.vbox3.Name = "vbox3"; @@ -209,5 +209,6 @@ public partial class MainWindow { this.DeleteEvent += new Gtk.DeleteEventHandler(this.OnDeleteEvent); this.searchBox.Activated += new System.EventHandler(this.OnSearchRequested); this.button1.Clicked += new System.EventHandler(this.OnSearchRequested); + this.filelist.RowActivated += new Gtk.RowActivatedHandler(this.OnRowActivated); } } diff --git a/gtk-gui/gui.stetic b/gtk-gui/gui.stetic index 58d1ecc..86d9e7b 100644 --- a/gtk-gui/gui.stetic +++ b/gtk-gui/gui.stetic @@ -36,7 +36,7 @@ True - 1 + 0 @@ -104,6 +104,7 @@ True True + @@ -221,4 +222,192 @@ + + + DIzzy Login + CenterOnParent + 2 + False + + + + 5 + 5 + + + + 6 + + + + Inserire nome utente e password per autenticarsi su <b>poisson.phc.unipi.it</b> + True + + + 0 + True + False + False + + + + + + + + 1 + True + False + False + + + + + + 2 + 2 + 6 + 6 + 5 + + + + True + True + + + + 1 + 2 + 1 + 2 + True + Fill + True + True + False + False + True + False + + + + + + True + True + + + + 1 + 2 + True + Fill + True + True + False + False + True + False + + + + + + Utente + + + True + Fill + Fill + False + True + False + False + True + False + + + + + + Password + + + 1 + 2 + True + Fill + Fill + False + True + False + False + True + False + + + + + 2 + True + False + False + + + + + 0 + True + False + False + + + + + + + + 10 + 5 + 2 + End + + + + True + True + True + StockItem + gtk-cancel + -6 + gtk-cancel + + + False + False + + + + + + True + True + True + StockItem + gtk-ok + -5 + + + gtk-ok + + + 1 + False + False + + + + + \ No newline at end of file -- 2.1.4