From 0af56ca87f5e00e70a39c0bdcb150ab9434b1df7 Mon Sep 17 00:00:00 2001 From: Leonardo Robol Date: Wed, 3 Feb 2010 10:43:16 +0100 Subject: [PATCH] =?UTF-8?q?SQLite=20=C3=A8=20ora=20funzionante=20per=20le?= =?UTF-8?q?=20uniche=20impostazioni=20che=20ci=20interessano.=20Manca=20da?= =?UTF-8?q?=20implementare=20la=20memorizzazione=20della=20lista.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FileTreeView.cs | 1 - GlobalConfig.cs | 54 ++++++++++++++++++++++++++++++++++++++++-- Main.cs | 3 ++- MainWindow.cs | 1 - StartupDialog.cs | 5 +++- TaskTreeView.cs | 1 - gtk-gui/Dizzy.StartupDialog.cs | 3 ++- gtk-gui/gui.stetic | 5 ++-- 8 files changed, 63 insertions(+), 10 deletions(-) diff --git a/FileTreeView.cs b/FileTreeView.cs index 4ee55e2..2cb6d57 100644 --- a/FileTreeView.cs +++ b/FileTreeView.cs @@ -50,7 +50,6 @@ namespace Dizzy filenameColumn.PackStart (filenameRenderer, true); filenameColumn.AddAttribute (filenameRenderer, "text", 0); - // Utente Gtk.CellRendererText userRenderer = new Gtk.CellRendererText (); userColumn.PackStart (userRenderer, true); diff --git a/GlobalConfig.cs b/GlobalConfig.cs index cf201ed..79088b1 100644 --- a/GlobalConfig.cs +++ b/GlobalConfig.cs @@ -19,22 +19,72 @@ namespace Dizzy Init (); } + public string GetValue(string field) + { + string val; + + SQLiteCommand sqlCmd; + this.conn.Open (); + sqlCmd = this.conn.CreateCommand (); + + sqlCmd.CommandText = "SELECT value FROM config WHERE field = '" + field + "';"; + SQLiteDataReader reader = sqlCmd.ExecuteReader (); + if (reader.Read()) + val = reader.GetString(0); + else + val = ""; + this.conn.Close (); + return val; + + } + + public void InsertValue(string field, string val) + { + SQLiteCommand sqlCmd; + + this.conn.Open (); + sqlCmd = this.conn.CreateCommand (); + + sqlCmd.CommandText = "INSERT OR REPLACE INTO config VALUES ('" + field + "', '" + val + "');"; + sqlCmd.ExecuteNonQuery (); + this.conn.Close (); + } + protected void Init () { SQLiteCommand sqlCmd; this.conn.Open (); sqlCmd = this.conn.CreateCommand (); - sqlCmd.CommandText = "SELECT * from sqlite_master WHERE type='table';"; + sqlCmd.CommandText = "SELECT * FROM sqlite_master WHERE type='table';"; SQLiteDataReader reader = sqlCmd.ExecuteReader (); if(!reader.HasRows) + { + this.conn.Close (); InitialSetup (); + } + else + this.conn.Close (); } protected void InitialSetup () { + // Dobbiamo creare la struttura del database + SQLiteCommand sqlCmd; + this.conn.Open (); + + // Tabelle delle configurazioni + sqlCmd = this.conn.CreateCommand (); + sqlCmd.CommandText = "CREATE TABLE config (field TEXT, value TEXT);"; + sqlCmd.ExecuteNonQuery (); + + // Tabella della lista + sqlCmd = this.conn.CreateCommand (); + sqlCmd.CommandText = "CREATE TABLE list (path TEXT, user TEXT);"; + sqlCmd.ExecuteNonQuery (); + this.conn.Close (); } protected string DataBaseName () @@ -55,7 +105,7 @@ namespace Dizzy if (!System.IO.Directory.Exists(dir)) System.IO.Directory.CreateDirectory (dir); - string db = dir + System.IO.Path.DirectorySeparatorChar + "list.sqlite"; + string db = dir + System.IO.Path.DirectorySeparatorChar + "config.sqlite"; if (!System.IO.File.Exists (db)) System.IO.File.Create (db); return db; diff --git a/Main.cs b/Main.cs index b5f5c13..87d8ac5 100644 --- a/Main.cs +++ b/Main.cs @@ -25,9 +25,10 @@ namespace Dizzy try { - win = new MainWindow (config.user, config.password); + win = new MainWindow (config.GetValue("user"), config.password); win.ShowAll (); Application.Run (); + } catch(Exception e) { diff --git a/MainWindow.cs b/MainWindow.cs index 7d55d6d..cf245d4 100644 --- a/MainWindow.cs +++ b/MainWindow.cs @@ -14,7 +14,6 @@ public partial class MainWindow : Gtk.Window Build (); - // Inizializziamo la vista dei file. files = new Dizzy.FileTreeView (filelist); diff --git a/StartupDialog.cs b/StartupDialog.cs index 0d633ec..8d4cb96 100644 --- a/StartupDialog.cs +++ b/StartupDialog.cs @@ -13,7 +13,7 @@ namespace Dizzy protected virtual void OnOkClicked (object sender, System.EventArgs e) { - config.user = entryUser.Text; + config.InsertValue("user", entryUser.Text); config.password = entryPassword.Text; this.Destroy (); } @@ -23,10 +23,13 @@ namespace Dizzy this.Build (); this.config = config; + this.entryUser.Text = config.GetValue("user"); + // Dobbiamo fare in modo di ottenere utente e password dall' // utente e poi caricare la finestra principale connettendoci // al server entryPassword.Visibility = false; + entryPassword.ActivatesDefault = true; } } diff --git a/TaskTreeView.cs b/TaskTreeView.cs index a79ce13..cba9ab1 100644 --- a/TaskTreeView.cs +++ b/TaskTreeView.cs @@ -12,7 +12,6 @@ namespace Dizzy TreeViewColumn fileColumn; TreeViewColumn progressColumn; - // Gtk.TreeViewColumn statusColumn; ListStore tasklist; diff --git a/gtk-gui/Dizzy.StartupDialog.cs b/gtk-gui/Dizzy.StartupDialog.cs index b57d15e..a4dc919 100644 --- a/gtk-gui/Dizzy.StartupDialog.cs +++ b/gtk-gui/Dizzy.StartupDialog.cs @@ -74,6 +74,7 @@ namespace Dizzy { this.table1.BorderWidth = ((uint)(5)); // Container child table1.Gtk.Table+TableChild this.entryPassword = new Gtk.Entry(); + this.entryPassword.CanDefault = true; this.entryPassword.CanFocus = true; this.entryPassword.Name = "entryPassword"; this.entryPassword.IsEditable = true; @@ -87,7 +88,6 @@ namespace Dizzy { w4.YOptions = ((Gtk.AttachOptions)(4)); // Container child table1.Gtk.Table+TableChild this.entryUser = new Gtk.Entry(); - this.entryUser.CanFocus = true; this.entryUser.Name = "entryUser"; this.entryUser.IsEditable = true; this.entryUser.InvisibleChar = '•'; @@ -160,6 +160,7 @@ namespace Dizzy { } this.DefaultWidth = 508; this.DefaultHeight = 178; + this.buttonOk.HasDefault = true; this.Show(); this.buttonOk.Activated += new System.EventHandler(this.OnOkClicked); this.buttonOk.Clicked += new System.EventHandler(this.OnOkClicked); diff --git a/gtk-gui/gui.stetic b/gtk-gui/gui.stetic index bf8c5bc..dead1a3 100644 --- a/gtk-gui/gui.stetic +++ b/gtk-gui/gui.stetic @@ -6,7 +6,7 @@ - + @@ -272,6 +272,7 @@ + True True True @@ -294,7 +295,6 @@ - True True @@ -392,6 +392,7 @@ True + True True True StockItem -- 2.1.4