From e7f1f700182adbd6de1bfcdb45642236dcc80cd7 Mon Sep 17 00:00:00 2001 From: Leonardo Robol Date: Wed, 10 Feb 2010 17:44:36 +0100 Subject: [PATCH] Aggiunto supporto ai filtri nella ricerca. --- Dizzy/File.cs | 12 ++-- Dizzy/Log.cs | 2 +- Dizzy/MainWindow.cs | 2 +- Dizzy/Protocol.cs | 25 +++++--- gtk-gui/Dizzy.AuthDialog.cs | 1 + gtk-gui/MainWindow.cs | 142 ++++++++++++++++++++++++-------------------- gtk-gui/gui.stetic | 142 ++++++++++++++++++++++++++++++-------------- 7 files changed, 202 insertions(+), 124 deletions(-) diff --git a/Dizzy/File.cs b/Dizzy/File.cs index 85e0d17..06c7a74 100644 --- a/Dizzy/File.cs +++ b/Dizzy/File.cs @@ -15,11 +15,13 @@ namespace Dizzy public FileType(string filename) { - if(filename.EndsWith(".avi")) + if(filename.EndsWith(".avi") || filename.EndsWith(".mpeg") || + filename.EndsWith(".mpg")) type = VIDEO; - else if(filename.EndsWith(".pdf")) + else if(filename.EndsWith(".pdf") || filename.EndsWith(".dvi") || + filename.EndsWith(".djvu") || filename.EndsWith(".ps")) type = BOOK; - else if(filename.EndsWith(".mp3")) + else if(filename.EndsWith(".mp3") || filename.EndsWith(".ogg")) type = AUDIO; else type = UNKNOWN; @@ -31,11 +33,11 @@ namespace Dizzy if(type == VIDEO) return "Video"; else if(type == BOOK) - return "Book"; + return "Libro"; else if(type == AUDIO) return "Audio"; else - return "Sconosciuto"; + return "Qualsiasi"; } } diff --git a/Dizzy/Log.cs b/Dizzy/Log.cs index 0f9750a..9e322b0 100644 --- a/Dizzy/Log.cs +++ b/Dizzy/Log.cs @@ -47,7 +47,7 @@ namespace Dizzy Console.WriteLine (message); try {StatusBarUpdate(message);} - catch (Exception e) { Log.Error ("Impossibile loggare sulla statusbar"); } + catch (Exception e) { Log.Error ("Impossibile loggare sulla statusbar" + e.Message); } } public static void Lock (string message) diff --git a/Dizzy/MainWindow.cs b/Dizzy/MainWindow.cs index dac3760..1be172a 100644 --- a/Dizzy/MainWindow.cs +++ b/Dizzy/MainWindow.cs @@ -75,7 +75,7 @@ public partial class MainWindow : Gtk.Window { this.files.Clear (); EventManager.SearchStarted (); - this.protocol.Search (searchBox.Text); + this.protocol.Search (searchBox.Text, searchUserBox.Text, typeBox.ActiveText); } protected virtual void OnRowActivated (object o, Gtk.RowActivatedArgs args) diff --git a/Dizzy/Protocol.cs b/Dizzy/Protocol.cs index ef066a2..fa33361 100644 --- a/Dizzy/Protocol.cs +++ b/Dizzy/Protocol.cs @@ -31,10 +31,10 @@ namespace Dizzy ArrayList threads = new ArrayList (); - Thread finder, listUpdater; + Thread finder; // Dati letti dal thread che cerca per capire cosa cercare - string keyword; + string keyword, user, type; GlobalConfig config; @@ -51,7 +51,7 @@ namespace Dizzy // this.UpdateFileList (); } - public void Search(string keyword) + public void Search(string keyword, string user, string type) { if (this.finder != null && this.finder.IsAlive) { @@ -68,6 +68,8 @@ namespace Dizzy { Log.Info ("Avvio la ricerca nel database"); this.keyword = keyword; + this.user = user; + this.type = type; this.finder = new Thread(new ThreadStart (this._Search)); this.finder.Start (); } @@ -90,7 +92,7 @@ namespace Dizzy FileList list = new FileList (ref this.config); ArrayList files; - try { files = list.Search (this.keyword); } + try { files = list.Search (this.keyword, this.type, this.user); } catch (Exception e) { // Probabilmente stiamo solamente scaricando il database, // ma tant'è. @@ -450,22 +452,29 @@ namespace Dizzy this.connection = new SQLiteConnection(connectionString); } - public ArrayList Search(string keyword) { + public ArrayList Search(string keyword, string type, string user) { this.connection.Open (); ArrayList matches = new ArrayList (); // Eseguiamo la query SQLiteCommand sqlCmd = this.connection.CreateCommand (); - sqlCmd.CommandText = "SELECT * from files WHERE name LIKE '%" + keyword + "%';"; + sqlCmd.CommandText = "SELECT * from files WHERE name LIKE '%" + keyword + "%'"; SQLiteDataReader reader = sqlCmd.ExecuteReader (); + File tmp; while(reader.Read()) { - matches.Add (new File(reader.GetString(0), // Path + tmp = new File(reader.GetString(0), // Path reader.GetString(2), // User reader.GetString(1), // Name - reader.GetInt32(3))); // Size + reader.GetInt32(3)); // Size + + if ( (type == "Qualsiasi" || tmp.type.Name() == type) && + (user == "" || user == tmp.user) ) + { + matches.Add (tmp); + } } this.connection.Close (); diff --git a/gtk-gui/Dizzy.AuthDialog.cs b/gtk-gui/Dizzy.AuthDialog.cs index 220c412..6695d49 100644 --- a/gtk-gui/Dizzy.AuthDialog.cs +++ b/gtk-gui/Dizzy.AuthDialog.cs @@ -59,6 +59,7 @@ namespace Dizzy { w2.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 a626dac..950bdc5 100644 --- a/gtk-gui/MainWindow.cs +++ b/gtk-gui/MainWindow.cs @@ -62,6 +62,14 @@ public partial class MainWindow { private Gtk.Label label5; + private Gtk.Alignment alignment3; + + private Gtk.Label label8; + + private Gtk.Alignment alignment4; + + private Gtk.Label label9; + private Gtk.Button button182; private Gtk.Button button183; @@ -70,10 +78,6 @@ public partial class MainWindow { private Gtk.FileChooserButton filechooserbutton1; - private Gtk.Label label8; - - private Gtk.Label label9; - private Gtk.Label label7; private Gtk.Statusbar dizzystatus; @@ -82,7 +86,7 @@ public partial class MainWindow { Stetic.Gui.Initialize(this); // Widget MainWindow this.Name = "MainWindow"; - this.Title = Mono.Unix.Catalog.GetString("Dizzy PreRelease"); + this.Title = Mono.Unix.Catalog.GetString("Dizzy 0.1"); this.Icon = Stetic.IconLoader.LoadIcon(this, "stock_connect", Gtk.IconSize.Menu, 16); this.WindowPosition = ((Gtk.WindowPosition)(4)); this.DefaultWidth = 640; @@ -96,13 +100,14 @@ public partial class MainWindow { this.notebook1 = new Gtk.Notebook(); this.notebook1.CanFocus = true; this.notebook1.Name = "notebook1"; - this.notebook1.CurrentPage = 2; + this.notebook1.CurrentPage = 0; // 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)); @@ -164,7 +169,7 @@ public partial class MainWindow { w5.YOptions = ((Gtk.AttachOptions)(4)); // Container child table1.Gtk.Table+TableChild this.typeBox = Gtk.ComboBox.NewText(); - this.typeBox.AppendText(Mono.Unix.Catalog.GetString("Qualsias")); + this.typeBox.AppendText(Mono.Unix.Catalog.GetString("Qualsiasi")); this.typeBox.AppendText(Mono.Unix.Catalog.GetString("Audio")); this.typeBox.AppendText(Mono.Unix.Catalog.GetString("Video")); this.typeBox.AppendText(Mono.Unix.Catalog.GetString("Libro")); @@ -255,7 +260,7 @@ public partial class MainWindow { this.table2.Name = "table2"; this.table2.RowSpacing = ((uint)(6)); this.table2.ColumnSpacing = ((uint)(6)); - this.table2.BorderWidth = ((uint)(5)); + this.table2.BorderWidth = ((uint)(15)); // Container child table2.Gtk.Table+TableChild this.alignment1 = new Gtk.Alignment(0.5F, 0.5F, 1F, 1F); this.alignment1.Name = "alignment1"; @@ -263,7 +268,7 @@ public partial class MainWindow { this.label10 = new Gtk.Label(); this.label10.Name = "label10"; this.label10.Xalign = 0F; - this.label10.LabelProp = Mono.Unix.Catalog.GetString("Utility"); + this.label10.LabelProp = Mono.Unix.Catalog.GetString("Carica nuovi file"); this.label10.UseMarkup = true; this.alignment1.Add(this.label10); this.table2.Add(this.alignment1); @@ -287,19 +292,50 @@ public partial class MainWindow { w20.XOptions = ((Gtk.AttachOptions)(4)); w20.YOptions = ((Gtk.AttachOptions)(4)); // Container child table2.Gtk.Table+TableChild + this.alignment3 = new Gtk.Alignment(0F, 0.5F, 1F, 1F); + this.alignment3.Name = "alignment3"; + // Container child alignment3.Gtk.Container+ContainerChild + this.label8 = new Gtk.Label(); + this.label8.Name = "label8"; + this.label8.Xalign = 0F; + this.label8.LabelProp = Mono.Unix.Catalog.GetString("La password verrà richiesta alla prima necessità di connessione, ma le connessioni già attive non verranno terminate. "); + this.label8.Wrap = true; + this.alignment3.Add(this.label8); + this.table2.Add(this.alignment3); + Gtk.Table.TableChild w22 = ((Gtk.Table.TableChild)(this.table2[this.alignment3])); + w22.TopAttach = ((uint)(1)); + w22.BottomAttach = ((uint)(2)); + w22.YOptions = ((Gtk.AttachOptions)(4)); + // Container child table2.Gtk.Table+TableChild + this.alignment4 = new Gtk.Alignment(0.5F, 0.5F, 1F, 1F); + this.alignment4.Name = "alignment4"; + // Container child alignment4.Gtk.Container+ContainerChild + this.label9 = new Gtk.Label(); + this.label9.Name = "label9"; + this.label9.Xalign = 0F; + this.label9.LabelProp = Mono.Unix.Catalog.GetString("La lista sul server viene aggiornata in automatico ogni ora. Aggiornare quando si è alla ricerca di novità."); + this.label9.Wrap = true; + this.alignment4.Add(this.label9); + this.table2.Add(this.alignment4); + Gtk.Table.TableChild w24 = ((Gtk.Table.TableChild)(this.table2[this.alignment4])); + w24.TopAttach = ((uint)(2)); + w24.BottomAttach = ((uint)(3)); + w24.XOptions = ((Gtk.AttachOptions)(4)); + w24.YOptions = ((Gtk.AttachOptions)(4)); + // Container child table2.Gtk.Table+TableChild this.button182 = new Gtk.Button(); this.button182.CanFocus = true; this.button182.Name = "button182"; this.button182.UseUnderline = true; this.button182.Label = Mono.Unix.Catalog.GetString("Disconnetti"); this.table2.Add(this.button182); - Gtk.Table.TableChild w21 = ((Gtk.Table.TableChild)(this.table2[this.button182])); - w21.TopAttach = ((uint)(1)); - w21.BottomAttach = ((uint)(2)); - w21.LeftAttach = ((uint)(1)); - w21.RightAttach = ((uint)(2)); - w21.XOptions = ((Gtk.AttachOptions)(4)); - w21.YOptions = ((Gtk.AttachOptions)(4)); + Gtk.Table.TableChild w25 = ((Gtk.Table.TableChild)(this.table2[this.button182])); + w25.TopAttach = ((uint)(1)); + w25.BottomAttach = ((uint)(2)); + w25.LeftAttach = ((uint)(1)); + w25.RightAttach = ((uint)(2)); + w25.XOptions = ((Gtk.AttachOptions)(4)); + w25.YOptions = ((Gtk.AttachOptions)(4)); // Container child table2.Gtk.Table+TableChild this.button183 = new Gtk.Button(); this.button183.CanFocus = true; @@ -307,13 +343,13 @@ public partial class MainWindow { this.button183.UseUnderline = true; this.button183.Label = Mono.Unix.Catalog.GetString("Aggiorna lista"); this.table2.Add(this.button183); - Gtk.Table.TableChild w22 = ((Gtk.Table.TableChild)(this.table2[this.button183])); - w22.TopAttach = ((uint)(2)); - w22.BottomAttach = ((uint)(3)); - w22.LeftAttach = ((uint)(1)); - w22.RightAttach = ((uint)(2)); - w22.XOptions = ((Gtk.AttachOptions)(4)); - w22.YOptions = ((Gtk.AttachOptions)(4)); + Gtk.Table.TableChild w26 = ((Gtk.Table.TableChild)(this.table2[this.button183])); + w26.TopAttach = ((uint)(2)); + w26.BottomAttach = ((uint)(3)); + w26.LeftAttach = ((uint)(1)); + w26.RightAttach = ((uint)(2)); + w26.XOptions = ((Gtk.AttachOptions)(4)); + w26.YOptions = ((Gtk.AttachOptions)(4)); // Container child table2.Gtk.Table+TableChild this.button184 = new Gtk.Button(); this.button184.CanFocus = true; @@ -321,45 +357,25 @@ public partial class MainWindow { this.button184.UseUnderline = true; this.button184.Label = Mono.Unix.Catalog.GetString("Carica file"); this.table2.Add(this.button184); - Gtk.Table.TableChild w23 = ((Gtk.Table.TableChild)(this.table2[this.button184])); - w23.TopAttach = ((uint)(4)); - w23.BottomAttach = ((uint)(5)); - w23.LeftAttach = ((uint)(1)); - w23.RightAttach = ((uint)(2)); - w23.XOptions = ((Gtk.AttachOptions)(4)); - w23.YOptions = ((Gtk.AttachOptions)(4)); + Gtk.Table.TableChild w27 = ((Gtk.Table.TableChild)(this.table2[this.button184])); + w27.TopAttach = ((uint)(4)); + w27.BottomAttach = ((uint)(5)); + w27.LeftAttach = ((uint)(1)); + w27.RightAttach = ((uint)(2)); + w27.XOptions = ((Gtk.AttachOptions)(4)); + w27.YOptions = ((Gtk.AttachOptions)(4)); // Container child table2.Gtk.Table+TableChild this.filechooserbutton1 = new Gtk.FileChooserButton(Mono.Unix.Catalog.GetString("Seleziona un file"), ((Gtk.FileChooserAction)(0))); this.filechooserbutton1.Name = "filechooserbutton1"; this.table2.Add(this.filechooserbutton1); - Gtk.Table.TableChild w24 = ((Gtk.Table.TableChild)(this.table2[this.filechooserbutton1])); - w24.TopAttach = ((uint)(4)); - w24.BottomAttach = ((uint)(5)); - w24.XOptions = ((Gtk.AttachOptions)(4)); - w24.YOptions = ((Gtk.AttachOptions)(4)); - // Container child table2.Gtk.Table+TableChild - this.label8 = new Gtk.Label(); - this.label8.Name = "label8"; - this.label8.LabelProp = Mono.Unix.Catalog.GetString("Il programma chiederà nuovamente utente e password quando necessario"); - this.label8.Wrap = true; - this.table2.Add(this.label8); - Gtk.Table.TableChild w25 = ((Gtk.Table.TableChild)(this.table2[this.label8])); - w25.TopAttach = ((uint)(1)); - w25.BottomAttach = ((uint)(2)); - w25.YOptions = ((Gtk.AttachOptions)(4)); - // Container child table2.Gtk.Table+TableChild - this.label9 = new Gtk.Label(); - this.label9.Name = "label9"; - this.label9.LabelProp = Mono.Unix.Catalog.GetString("Aggiornare la lista permette di trovare i file più recenti. Ogni volta che il programma viene avviato cerca di farlo autonomamente. La lista sul server viene aggiornata ogni ora."); - this.label9.Wrap = true; - this.table2.Add(this.label9); - Gtk.Table.TableChild w26 = ((Gtk.Table.TableChild)(this.table2[this.label9])); - w26.TopAttach = ((uint)(2)); - w26.BottomAttach = ((uint)(3)); - w26.YOptions = ((Gtk.AttachOptions)(4)); + Gtk.Table.TableChild w28 = ((Gtk.Table.TableChild)(this.table2[this.filechooserbutton1])); + w28.TopAttach = ((uint)(4)); + w28.BottomAttach = ((uint)(5)); + w28.XOptions = ((Gtk.AttachOptions)(4)); + w28.YOptions = ((Gtk.AttachOptions)(4)); this.notebook1.Add(this.table2); - Gtk.Notebook.NotebookChild w27 = ((Gtk.Notebook.NotebookChild)(this.notebook1[this.table2])); - w27.Position = 2; + Gtk.Notebook.NotebookChild w29 = ((Gtk.Notebook.NotebookChild)(this.notebook1[this.table2])); + w29.Position = 2; // Notebook tab this.label7 = new Gtk.Label(); this.label7.Name = "label7"; @@ -367,17 +383,17 @@ public partial class MainWindow { this.notebook1.SetTabLabel(this.table2, this.label7); this.label7.ShowAll(); this.vbox1.Add(this.notebook1); - Gtk.Box.BoxChild w28 = ((Gtk.Box.BoxChild)(this.vbox1[this.notebook1])); - w28.Position = 0; + Gtk.Box.BoxChild w30 = ((Gtk.Box.BoxChild)(this.vbox1[this.notebook1])); + w30.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 w29 = ((Gtk.Box.BoxChild)(this.vbox1[this.dizzystatus])); - w29.Position = 1; - w29.Expand = false; - w29.Fill = false; + Gtk.Box.BoxChild w31 = ((Gtk.Box.BoxChild)(this.vbox1[this.dizzystatus])); + w31.Position = 1; + w31.Expand = false; + w31.Fill = false; this.Add(this.vbox1); if ((this.Child != null)) { this.Child.ShowAll(); diff --git a/gtk-gui/gui.stetic b/gtk-gui/gui.stetic index 27c0187..4d2582b 100644 --- a/gtk-gui/gui.stetic +++ b/gtk-gui/gui.stetic @@ -8,9 +8,9 @@ - + - Dizzy PreRelease + Dizzy 0.1 stock:stock_connect Menu CenterOnParent 640 @@ -25,7 +25,7 @@ True - 2 + 0 @@ -145,7 +145,7 @@ True - Qualsias + Qualsiasi Audio Video Libro @@ -281,7 +281,7 @@ Libro 2 6 6 - 5 + 15 @@ -295,7 +295,7 @@ Libro 0 - <b>Utility</b> + <b>Carica nuovi file</b> True @@ -339,6 +339,58 @@ Libro + + + 0 + + + + 0 + La password verrà richiesta alla prima necessità di connessione, ma le connessioni già attive non verranno terminate. + True + + + + + 1 + 2 + False + Fill + True + True + False + False + True + False + + + + + + + + + 0 + La lista sul server viene aggiornata in automatico ogni ora. Aggiornare quando si è alla ricerca di novità. + True + + + + + 2 + 3 + True + Fill + Fill + False + True + False + False + True + False + + + True @@ -430,44 +482,6 @@ Libro False - - - - Il programma chiederà nuovamente utente e password quando necessario - True - - - 1 - 2 - False - Fill - True - True - False - False - True - False - - - - - - Aggiornare la lista permette di trovare i file più recenti. Ogni volta che il programma viene avviato cerca di farlo autonomamente. La lista sul server viene aggiornata ogni ora. - True - - - 2 - 3 - False - Fill - True - True - False - False - True - False - - 2 @@ -691,7 +705,7 @@ Libro - + CenterOnParent 2 @@ -701,7 +715,43 @@ Libro 2 - + + + 6 + + + + 64 + 64 + stock:gtk-dialog-error Menu + + + 0 + True + False + False + + + + + + label4 + True + + + 1 + True + False + False + + + + + 0 + True + False + False + -- 2.1.4