SQLite è ora funzionante per le uniche impostazioni che ci
Leonardo Robol [2010-02-03 09:43]
SQLite è ora funzionante per le uniche impostazioni che ci
interessano. Manca da implementare la memorizzazione della
lista.
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 @@
</configuration>
<import>
<widget-library name="glade-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
- <widget-library name="../bin/Release/Dizzy.exe" internal="true" />
+ <widget-library name="../bin/Debug/Dizzy.exe" internal="true" />
</import>
<widget class="Gtk.Window" id="MainWindow" design-size="474 300">
<property name="MemberName" />
@@ -272,6 +272,7 @@
<child>
<widget class="Gtk.Entry" id="entryPassword">
<property name="MemberName" />
+ <property name="CanDefault">True</property>
<property name="CanFocus">True</property>
<property name="IsEditable">True</property>
<property name="InvisibleChar">•</property>
@@ -294,7 +295,6 @@
<child>
<widget class="Gtk.Entry" id="entryUser">
<property name="MemberName" />
- <property name="CanFocus">True</property>
<property name="IsEditable">True</property>
<property name="InvisibleChar">•</property>
</widget>
@@ -392,6 +392,7 @@
<widget class="Gtk.Button" id="buttonOk">
<property name="MemberName" />
<property name="CanDefault">True</property>
+ <property name="HasDefault">True</property>
<property name="CanFocus">True</property>
<property name="UseStock">True</property>
<property name="Type">StockItem</property>