From d0c1810818c2a647ad7699fb9ec658da27e76c6d Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Wed, 1 Feb 2012 10:51:06 -0500 Subject: [PATCH] Various Updates Added settings class, abstracted path, abstracted adding rows to db add table in add_db.php --- src/common/settings.php | 69 ++++++++++++++++++++++++++++++++++++++ src/databases/firebird.php | 3 +- src/index.php | 8 +++-- src/windows/add_db.php | 29 +++++++++------- src/windows/main.php | 9 ++++- 5 files changed, 101 insertions(+), 17 deletions(-) create mode 100644 src/common/settings.php diff --git a/src/common/settings.php b/src/common/settings.php new file mode 100644 index 0000000..d8e66a7 --- /dev/null +++ b/src/common/settings.php @@ -0,0 +1,69 @@ +current = new stdClass(); + } + else + { + $this->current = json_decode(file_get_contents($path)); + } + + } + + // -------------------------------------------------------------------------- + + /** + * Save the settings file on close, just to be safe + */ + function __destruct() + { + file_put_contents(json_encode($this->current), BASE_DIR.'/settings.json'); + } + + // -------------------------------------------------------------------------- + + /** + * Add a database connection + * + * @param string $type + * @param string $host + * @param string $user + * @param string $pass + */ + function add_db($type, $host, $user, $pass) + { + + } +} +// End of settings.php \ No newline at end of file diff --git a/src/databases/firebird.php b/src/databases/firebird.php index 0da6156..b7b4912 100644 --- a/src/databases/firebird.php +++ b/src/databases/firebird.php @@ -46,4 +46,5 @@ class firebird { { @ibase_close($this->conn); } -} \ No newline at end of file +} +// End of firebird.php \ No newline at end of file diff --git a/src/index.php b/src/index.php index abbb2ef..071c71f 100644 --- a/src/index.php +++ b/src/index.php @@ -57,12 +57,14 @@ function do_include($path) require_once($path); } -$dir = dirname(__FILE__); +define('BASE_DIR', dirname(__FILE__)); // Load modules +// Load everything so that we don't have to do requires later { - array_map('do_include', glob("{$dir}/databases/*.php")); - array_map('do_include', glob("{$dir}/windows/*.php")); + array_map('do_include', glob(BASE_DIR . "/common/*.php")); + array_map('do_include', glob(BASE_DIR . "/databases/*.php")); + array_map('do_include', glob(BASE_DIR . "/windows/*.php")); } // Create the main window diff --git a/src/windows/add_db.php b/src/windows/add_db.php index 2c4b9e2..a2cd161 100644 --- a/src/windows/add_db.php +++ b/src/windows/add_db.php @@ -44,7 +44,12 @@ class Add_DB extends GtkWindow { //Table attach //$tbl->attach(left_start, right_stop, top_start, bottom_stop) - //Row 1 - Database type + // Placeholder vars for y values, so that rows can be + // easily moved + $y1 = -1; + $y2 = 0; + + // Database type { $dbtypelbl = new GtkLabel("Database Type"); $this->dbtype = GtkComboBox::new_text(); @@ -56,42 +61,42 @@ class Add_DB extends GtkWindow { $this->dbtype->append_text($t); } - $table->attach($typealign, 0, 1, 0, 1); - $table->attach($this->dbtype, 1, 2, 0, 1); + $table->attach($typealign, 0, 1, ++$y1, ++$y2); + $table->attach($this->dbtype, 1, 2, $y1, $y2); } - //Row 2 - Host + // Host { $hostlbl = new GtkLabel("DB Host"); $this->host = new GtkEntry(); $hostalign = new GtkAlignment(0, 0.5, 0, 0); $hostalign->add($hostlbl); - $table->attach($hostalign, 0, 1, 1, 2); - $table->attach($this->host, 1, 2, 1, 2); + $table->attach($hostalign, 0, 1, ++$y1, ++$y2); + $table->attach($this->host, 1, 2, $y1, $y2); } - //Row 3 - Username + // Username { $userlbl = new GtkLabel("DB User"); $this->user = new GtkEntry(); $useralign = new GtkAlignment(0, 0.5, 0, 0); $useralign->add($userlbl); - $table->attach($useralign, 0, 1, 2, 3); - $table->attach($this->user, 1, 2, 2, 3); + $table->attach($useralign, 0, 1, ++$y1, ++$y2); + $table->attach($this->user, 1, 2, $y1, $y2); } - //Row 4 - Password + // Password { $passlbl = new GtkLabel("DB Password"); $this->pass = new GtkEntry(); $passalign = new GtkAlignment(0, 0.5, 0, 0); $passalign->add($passlbl); - $table->attach($passalign, 0, 1, 3, 4); - $table->attach($this->pass, 1, 2, 3, 4); + $table->attach($passalign, 0, 1, ++$y1, ++$y2); + $table->attach($this->pass, 1, 2, $y1, $y2); } diff --git a/src/windows/main.php b/src/windows/main.php index 21e1e79..6110055 100644 --- a/src/windows/main.php +++ b/src/windows/main.php @@ -53,7 +53,7 @@ class Main extends GtkWindow { $dlg->set_website('https://github.com/aviat4ion/OpenSQLManager'); $dlg->set_website_label('Fork on Github'); - $dlg->set_license(file_get_contents("LICENSE")); + $dlg->set_license(file_get_contents(BASE_DIR . "/LICENSE")); $dlg->set_authors(array( 'Timothy J. Warren', @@ -220,6 +220,13 @@ class Main extends GtkWindow { return $conn_vbox; } + // -------------------------------------------------------------------------- + + /** + * Returns window for creating a new database connection + * + * @return Add_DB object + */ function new_conn() { return new Add_DB();