From 7573226bf0298e82a21c84e0aa112e008763e5b8 Mon Sep 17 00:00:00 2001 From: Leonardo Robol Date: Wed, 17 Feb 2010 20:59:25 +0100 Subject: [PATCH] Aggiunte opzioni per connettersi ad un server diverso da poisson. --- Dizzy/GlobalConfig.cs | 32 +++++++ Dizzy/MainWindow.cs | 26 +++++- Dizzy/Protocol.cs | 2 +- Dizzy/SFTPConnection.cs | 55 ++---------- gtk-gui/Dizzy.AuthDialog.cs | 1 - gtk-gui/MainWindow.cs | 161 ++++++++++++++++++++++++++++++---- gtk-gui/gui.stetic | 206 +++++++++++++++++++++++++++++++++++++++++++- 7 files changed, 411 insertions(+), 72 deletions(-) diff --git a/Dizzy/GlobalConfig.cs b/Dizzy/GlobalConfig.cs index 1170a10..dcfcf67 100644 --- a/Dizzy/GlobalConfig.cs +++ b/Dizzy/GlobalConfig.cs @@ -8,7 +8,13 @@ namespace Dizzy public static class GlobalConfig { + /* La password non può venire memorizzata nel database (o almeno + * non per ora) per motivi di sicurezza, e quindi viene memorizzata + * temporaneamente qui */ public static string password; + + /* Questa proprietà ci permette di capire se abbiamo effettuato + * l'autenticazione, ovvero se i dati di autenticazione sono presenti */ private static bool _authenticated; public static bool authenticated { get { @@ -18,8 +24,13 @@ namespace Dizzy lock(typeof(GlobalConfig)) { _authenticated = value; } } } + + + + /* Alcune variabili che ci torneranno utili in seguito */ private static SQLiteConnection conn; + /* Piccolo buffer */ private static string val; static GlobalConfig () @@ -30,6 +41,27 @@ namespace Dizzy Init (); } + /* Carichiamo i valori di default senza sovrascrivere personalizzazioni + * già esistenti */ + public static void LoadDefaults () { + + /* Il server di default */ + if (GetValue("server") == "") + InsertValue("server", "poisson.phc.unipi.it"); + + /* La cartella dove trovare le cartelle di tutti gli utenti, + * o più genericamente i file */ + if (GetValue("folder") == "") + InsertValue("folder", "/nobackup"); + + /* Dove si trova l'indice */ + if (GetValue("index") == "") + InsertValue("index", "/nobackup/robol/index.db"); + + } + + + public static string GetValue(string field) { diff --git a/Dizzy/MainWindow.cs b/Dizzy/MainWindow.cs index 07cf962..26d4da9 100644 --- a/Dizzy/MainWindow.cs +++ b/Dizzy/MainWindow.cs @@ -29,14 +29,25 @@ public partial class MainWindow : Gtk.Window if (downloadpath != "") downloadpathchooser.SetFilename(downloadpath); - - this.protocol = new Protocol (); Log.StatusBarUpdate += this.OnStatusBarUpdate; + + /* Carichiamo i valori di default della configurazione */ + GlobalConfig.LoadDefaults (); + + /* Facciamo in modo che il pannello di configurazione rispecchi + * le scelte dell'utente */ + RefreshConfigPanel (); } + public void RefreshConfigPanel () { + entryConfigurationFolder.Text = GlobalConfig.GetValue("folder"); + entryConfigurationIndex.Text = GlobalConfig.GetValue("index"); + entryConfigurationServer.Text = GlobalConfig.GetValue("server"); + } + public void OnStatusBarUpdate (string message) { dizzystatus.Push(0, message); @@ -132,6 +143,17 @@ public partial class MainWindow : Gtk.Window Search (); } + protected virtual void OnButtonUpdateConfigurationClicked (object sender, System.EventArgs e) + { + /* Salviamo il contenuto delle entry nel database */ + GlobalConfig.InsertValue("server", entryConfigurationServer.Text); + GlobalConfig.InsertValue("folder", entryConfigurationFolder.Text); + GlobalConfig.InsertValue("index", entryConfigurationIndex.Text ); + } + + + + diff --git a/Dizzy/Protocol.cs b/Dizzy/Protocol.cs index 399b661..3189547 100644 --- a/Dizzy/Protocol.cs +++ b/Dizzy/Protocol.cs @@ -155,7 +155,7 @@ namespace Dizzy try { lock(typeof(GlobalConfig)){ Log.Info ("Aggiornamento della lista avviato"); - s.Get("/nobackup/robol/index.db", GlobalConfig.ListFileName()); + s.Get(GlobalConfig.GetValue("index"), GlobalConfig.ListFileName()); Log.Info ("Lista Aggiornata"); s.Close (); }} diff --git a/Dizzy/SFTPConnection.cs b/Dizzy/SFTPConnection.cs index f407a78..6ab1810 100644 --- a/Dizzy/SFTPConnection.cs +++ b/Dizzy/SFTPConnection.cs @@ -27,7 +27,7 @@ namespace Dizzy // Inizializziamo il protocollo this.user = user; - this.sftp = new Sftp ("poisson.phc.unipi.it", user); + this.sftp = new Sftp (GlobalConfig.GetValue("server"), user); this.sftp.Password = password; this.sftp.OnTransferStart += new FileTransferEvent(this.TransferStartedHandler); @@ -66,53 +66,6 @@ namespace Dizzy sftp.Connect (22); } - public ArrayList SearchFiles() - { - ArrayList matches = new ArrayList (); - Console.WriteLine(" => Scan della nobackup"); - // ArrayList users = sftp.GetFileList ("/nobackup/"); - ArrayList users = new ArrayList(); - users.Add("robol"); - users.Add("bianchi"); - foreach(string folder in users) - { - if (folder == ".") - continue; - else if (folder == "..") - continue; - Console.WriteLine(" => Scan di {0}", folder); - try { matches.AddRange (GetFolderContent(folder)); } - catch(Exception e) { Console.WriteLine (e.Message); } - } - Console.WriteLine(" => Scan terminato"); - return matches; - } - - protected ArrayList GetFolderContent(string folder) - { - ArrayList matches, files; - File f; - string user; - files = sftp.GetFileList("/nobackup/" + folder + "/"); - matches = new ArrayList (); - foreach(string entry in files) - { - // Controllo che non sia una cartella. Evidentemente - // questo metodo non è affidabile, ma per ora è il meglio - // che SFTP ci permetta di fare. - if(entry.IndexOf(".") == -1) - matches.AddRange(GetFolderContent(folder + "/" + entry)); - else if(!entry.StartsWith(".")) - { - user = folder; - if(user.Contains("/")) - user = user.Substring(0, user.IndexOf("/")); - f = new File("/nobackup/" + folder + "/" + entry, user ); - matches.Add(f); - } - } - return matches; - } public void Download(File f, string downloadFolder) { @@ -121,7 +74,11 @@ namespace Dizzy public void Upload(string filename) { - this.sftp.Put(filename, "/nobackup/" + this.user + "/"); + /* Normalizziamo il nome della cartella sul server */ + string folder = GlobalConfig.GetValue("folder"); + if (!folder.EndsWith("/")) + folder = folder + "/"; + this.sftp.Put(filename, folder + this.user + "/"); } public void Disconnect () diff --git a/gtk-gui/Dizzy.AuthDialog.cs b/gtk-gui/Dizzy.AuthDialog.cs index a657f08..15fef70 100644 --- a/gtk-gui/Dizzy.AuthDialog.cs +++ b/gtk-gui/Dizzy.AuthDialog.cs @@ -69,7 +69,6 @@ namespace Dizzy { w3.Fill = false; // Container child vbox2.Gtk.Box+BoxChild this.table1 = new Gtk.Table(((uint)(2)), ((uint)(2)), false); - this.table1.Name = "table1"; this.table1.RowSpacing = ((uint)(6)); this.table1.ColumnSpacing = ((uint)(6)); // Container child table1.Gtk.Table+TableChild diff --git a/gtk-gui/MainWindow.cs b/gtk-gui/MainWindow.cs index ed15da2..9fc6b09 100644 --- a/gtk-gui/MainWindow.cs +++ b/gtk-gui/MainWindow.cs @@ -78,6 +78,24 @@ public partial class MainWindow { private Gtk.Button button184; + private Gtk.Button ButtonUpdateConfiguration; + + private Gtk.Label label11; + + private Gtk.Table table3; + + private Gtk.Entry entryConfigurationFolder; + + private Gtk.Entry entryConfigurationIndex; + + private Gtk.Entry entryConfigurationServer; + + private Gtk.Label label12; + + private Gtk.Label label13; + + private Gtk.Label label14; + private Gtk.FileChooserButton uploadChooserButton; private Gtk.Label label7; @@ -102,14 +120,13 @@ public partial class MainWindow { this.notebook1 = new Gtk.Notebook(); this.notebook1.CanFocus = true; this.notebook1.Name = "notebook1"; - this.notebook1.CurrentPage = 0; + this.notebook1.CurrentPage = 2; // Container child notebook1.Gtk.Notebook+NotebookChild this.vbox3 = new Gtk.VBox(); this.vbox3.Name = "vbox3"; this.vbox3.Spacing = 6; // Container child vbox3.Gtk.Box+BoxChild this.table1 = new Gtk.Table(((uint)(2)), ((uint)(3)), false); - this.table1.Name = "table1"; this.table1.RowSpacing = ((uint)(6)); this.table1.ColumnSpacing = ((uint)(6)); this.table1.BorderWidth = ((uint)(5)); @@ -271,7 +288,7 @@ public partial class MainWindow { this.notebook1.SetTabLabel(this.vbox2, this.label3); this.label3.ShowAll(); // Container child notebook1.Gtk.Notebook+NotebookChild - this.table2 = new Gtk.Table(((uint)(5)), ((uint)(2)), false); + this.table2 = new Gtk.Table(((uint)(7)), ((uint)(2)), false); this.table2.Name = "table2"; this.table2.RowSpacing = ((uint)(6)); this.table2.ColumnSpacing = ((uint)(6)); @@ -380,17 +397,128 @@ public partial class MainWindow { w28.XOptions = ((Gtk.AttachOptions)(4)); w28.YOptions = ((Gtk.AttachOptions)(4)); // Container child table2.Gtk.Table+TableChild + this.ButtonUpdateConfiguration = new Gtk.Button(); + this.ButtonUpdateConfiguration.CanFocus = true; + this.ButtonUpdateConfiguration.Name = "ButtonUpdateConfiguration"; + this.ButtonUpdateConfiguration.UseUnderline = true; + this.ButtonUpdateConfiguration.Label = Mono.Unix.Catalog.GetString("Aggiorna\nconfigurazione"); + this.table2.Add(this.ButtonUpdateConfiguration); + Gtk.Table.TableChild w29 = ((Gtk.Table.TableChild)(this.table2[this.ButtonUpdateConfiguration])); + w29.TopAttach = ((uint)(6)); + w29.BottomAttach = ((uint)(7)); + w29.LeftAttach = ((uint)(1)); + w29.RightAttach = ((uint)(2)); + w29.XOptions = ((Gtk.AttachOptions)(4)); + w29.YOptions = ((Gtk.AttachOptions)(4)); + // Container child table2.Gtk.Table+TableChild + this.label11 = new Gtk.Label(); + this.label11.Name = "label11"; + this.label11.Xalign = 0F; + this.label11.LabelProp = Mono.Unix.Catalog.GetString("Opzioni di connessione"); + this.label11.UseMarkup = true; + this.table2.Add(this.label11); + Gtk.Table.TableChild w30 = ((Gtk.Table.TableChild)(this.table2[this.label11])); + w30.TopAttach = ((uint)(5)); + w30.BottomAttach = ((uint)(6)); + w30.XOptions = ((Gtk.AttachOptions)(4)); + w30.YOptions = ((Gtk.AttachOptions)(4)); + // Container child table2.Gtk.Table+TableChild + this.table3 = new Gtk.Table(((uint)(3)), ((uint)(2)), false); + this.table3.Name = "table3"; + this.table3.RowSpacing = ((uint)(6)); + this.table3.ColumnSpacing = ((uint)(6)); + // Container child table3.Gtk.Table+TableChild + this.entryConfigurationFolder = new Gtk.Entry(); + this.entryConfigurationFolder.CanFocus = true; + this.entryConfigurationFolder.Name = "entryConfigurationFolder"; + this.entryConfigurationFolder.Text = Mono.Unix.Catalog.GetString("/nobackup"); + this.entryConfigurationFolder.IsEditable = true; + this.entryConfigurationFolder.InvisibleChar = '•'; + this.table3.Add(this.entryConfigurationFolder); + Gtk.Table.TableChild w31 = ((Gtk.Table.TableChild)(this.table3[this.entryConfigurationFolder])); + w31.TopAttach = ((uint)(1)); + w31.BottomAttach = ((uint)(2)); + w31.LeftAttach = ((uint)(1)); + w31.RightAttach = ((uint)(2)); + w31.YOptions = ((Gtk.AttachOptions)(4)); + // Container child table3.Gtk.Table+TableChild + this.entryConfigurationIndex = new Gtk.Entry(); + this.entryConfigurationIndex.CanFocus = true; + this.entryConfigurationIndex.Name = "entryConfigurationIndex"; + this.entryConfigurationIndex.Text = Mono.Unix.Catalog.GetString("/nobackup/robol/index.db"); + this.entryConfigurationIndex.IsEditable = true; + this.entryConfigurationIndex.InvisibleChar = '•'; + this.table3.Add(this.entryConfigurationIndex); + Gtk.Table.TableChild w32 = ((Gtk.Table.TableChild)(this.table3[this.entryConfigurationIndex])); + w32.TopAttach = ((uint)(2)); + w32.BottomAttach = ((uint)(3)); + w32.LeftAttach = ((uint)(1)); + w32.RightAttach = ((uint)(2)); + w32.YOptions = ((Gtk.AttachOptions)(4)); + // Container child table3.Gtk.Table+TableChild + this.entryConfigurationServer = new Gtk.Entry(); + this.entryConfigurationServer.CanFocus = true; + this.entryConfigurationServer.Name = "entryConfigurationServer"; + this.entryConfigurationServer.Text = Mono.Unix.Catalog.GetString("poisson.phc.unipi.it"); + this.entryConfigurationServer.IsEditable = true; + this.entryConfigurationServer.InvisibleChar = '•'; + this.table3.Add(this.entryConfigurationServer); + Gtk.Table.TableChild w33 = ((Gtk.Table.TableChild)(this.table3[this.entryConfigurationServer])); + w33.LeftAttach = ((uint)(1)); + w33.RightAttach = ((uint)(2)); + w33.YOptions = ((Gtk.AttachOptions)(4)); + // Container child table3.Gtk.Table+TableChild + this.label12 = new Gtk.Label(); + this.label12.Name = "label12"; + this.label12.Xalign = 0F; + this.label12.LabelProp = Mono.Unix.Catalog.GetString("Server"); + this.label12.Wrap = true; + this.table3.Add(this.label12); + Gtk.Table.TableChild w34 = ((Gtk.Table.TableChild)(this.table3[this.label12])); + w34.XOptions = ((Gtk.AttachOptions)(4)); + w34.YOptions = ((Gtk.AttachOptions)(4)); + // Container child table3.Gtk.Table+TableChild + this.label13 = new Gtk.Label(); + this.label13.Name = "label13"; + this.label13.Xalign = 0F; + this.label13.LabelProp = Mono.Unix.Catalog.GetString("Cartella condivisa"); + this.label13.Wrap = true; + this.table3.Add(this.label13); + Gtk.Table.TableChild w35 = ((Gtk.Table.TableChild)(this.table3[this.label13])); + w35.TopAttach = ((uint)(1)); + w35.BottomAttach = ((uint)(2)); + w35.XOptions = ((Gtk.AttachOptions)(4)); + w35.YOptions = ((Gtk.AttachOptions)(4)); + // Container child table3.Gtk.Table+TableChild + this.label14 = new Gtk.Label(); + this.label14.Name = "label14"; + this.label14.Xalign = 0F; + this.label14.LabelProp = Mono.Unix.Catalog.GetString("File di indice"); + this.label14.Wrap = true; + this.table3.Add(this.label14); + Gtk.Table.TableChild w36 = ((Gtk.Table.TableChild)(this.table3[this.label14])); + w36.TopAttach = ((uint)(2)); + w36.BottomAttach = ((uint)(3)); + w36.XOptions = ((Gtk.AttachOptions)(4)); + w36.YOptions = ((Gtk.AttachOptions)(4)); + this.table2.Add(this.table3); + Gtk.Table.TableChild w37 = ((Gtk.Table.TableChild)(this.table2[this.table3])); + w37.TopAttach = ((uint)(6)); + w37.BottomAttach = ((uint)(7)); + w37.XOptions = ((Gtk.AttachOptions)(4)); + w37.YOptions = ((Gtk.AttachOptions)(4)); + // Container child table2.Gtk.Table+TableChild this.uploadChooserButton = new Gtk.FileChooserButton(Mono.Unix.Catalog.GetString("Seleziona un file"), ((Gtk.FileChooserAction)(0))); this.uploadChooserButton.Name = "uploadChooserButton"; this.table2.Add(this.uploadChooserButton); - Gtk.Table.TableChild w29 = ((Gtk.Table.TableChild)(this.table2[this.uploadChooserButton])); - w29.TopAttach = ((uint)(4)); - w29.BottomAttach = ((uint)(5)); - w29.XOptions = ((Gtk.AttachOptions)(4)); - w29.YOptions = ((Gtk.AttachOptions)(4)); + Gtk.Table.TableChild w38 = ((Gtk.Table.TableChild)(this.table2[this.uploadChooserButton])); + w38.TopAttach = ((uint)(4)); + w38.BottomAttach = ((uint)(5)); + w38.XOptions = ((Gtk.AttachOptions)(4)); + w38.YOptions = ((Gtk.AttachOptions)(4)); this.notebook1.Add(this.table2); - Gtk.Notebook.NotebookChild w30 = ((Gtk.Notebook.NotebookChild)(this.notebook1[this.table2])); - w30.Position = 2; + Gtk.Notebook.NotebookChild w39 = ((Gtk.Notebook.NotebookChild)(this.notebook1[this.table2])); + w39.Position = 2; // Notebook tab this.label7 = new Gtk.Label(); this.label7.Name = "label7"; @@ -398,17 +526,17 @@ public partial class MainWindow { this.notebook1.SetTabLabel(this.table2, this.label7); this.label7.ShowAll(); this.vbox1.Add(this.notebook1); - Gtk.Box.BoxChild w31 = ((Gtk.Box.BoxChild)(this.vbox1[this.notebook1])); - w31.Position = 0; + Gtk.Box.BoxChild w40 = ((Gtk.Box.BoxChild)(this.vbox1[this.notebook1])); + w40.Position = 0; // Container child vbox1.Gtk.Box+BoxChild this.dizzystatus = new Gtk.Statusbar(); this.dizzystatus.Name = "dizzystatus"; this.dizzystatus.Spacing = 6; this.vbox1.Add(this.dizzystatus); - Gtk.Box.BoxChild w32 = ((Gtk.Box.BoxChild)(this.vbox1[this.dizzystatus])); - w32.Position = 1; - w32.Expand = false; - w32.Fill = false; + Gtk.Box.BoxChild w41 = ((Gtk.Box.BoxChild)(this.vbox1[this.dizzystatus])); + w41.Position = 1; + w41.Expand = false; + w41.Fill = false; this.Add(this.vbox1); if ((this.Child != null)) { this.Child.ShowAll(); @@ -422,6 +550,7 @@ public partial class MainWindow { this.tasklist.CursorChanged += new System.EventHandler(this.OnTasklistCursorChanged); this.downloadpathchooser.SelectionChanged += new System.EventHandler(this.OnDownloadPathSelectionChanged); this.blockTransfer.Clicked += new System.EventHandler(this.OnBlockTransferClicked); + this.ButtonUpdateConfiguration.Clicked += new System.EventHandler(this.OnButtonUpdateConfigurationClicked); this.button184.Clicked += new System.EventHandler(this.OnUploadRequested); this.button183.Clicked += new System.EventHandler(this.OnListUpdateRequired); this.button182.Clicked += new System.EventHandler(this.OnDisconnectionRequested); diff --git a/gtk-gui/gui.stetic b/gtk-gui/gui.stetic index 13e4012..25a4a0c 100644 --- a/gtk-gui/gui.stetic +++ b/gtk-gui/gui.stetic @@ -8,7 +8,7 @@ - + Dizzy 0.1 stock:stock_connect Menu @@ -25,7 +25,7 @@ True - 0 + 2 @@ -298,7 +298,7 @@ Libro - 5 + 7 2 6 6 @@ -310,6 +310,9 @@ Libro + + + @@ -487,6 +490,203 @@ Libro + + + True + TextOnly + Aggiorna +configurazione + True + + + + 6 + 7 + 1 + 2 + True + Fill + Fill + False + True + False + False + True + False + + + + + + 0 + <b>Opzioni di connessione</b> + True + + + 5 + 6 + True + Fill + Fill + False + True + False + False + True + False + + + + + + 3 + 2 + 6 + 6 + + + + True + /nobackup + True + + + + 1 + 2 + 1 + 2 + True + Fill + True + True + False + False + True + False + + + + + + True + /nobackup/robol/index.db + True + + + + 2 + 3 + 1 + 2 + True + Fill + True + True + False + False + True + False + + + + + + True + poisson.phc.unipi.it + True + + + + 1 + 2 + True + Fill + True + True + False + False + True + False + + + + + + 0 + Server + True + + + True + Fill + Fill + False + True + False + False + True + False + + + + + + 0 + Cartella condivisa + True + + + 1 + 2 + True + Fill + Fill + False + True + False + False + True + False + + + + + + 0 + File di indice + True + + + 2 + 3 + True + Fill + Fill + False + True + False + False + True + False + + + + + 6 + 7 + True + Fill + Fill + False + True + False + False + True + False + + + -- 2.1.4