diff --git a/index.php b/index.php index 4494595..613e9ed 100644 --- a/index.php +++ b/index.php @@ -162,6 +162,8 @@ function alert($message) Gtk::BUTTONS_OK, $message ); + + $dialog->set_position(Gtk::WIN_POS_CENTER); $dialog->run(); $dialog->destroy(); } @@ -183,6 +185,8 @@ function error($message) Gtk::BUTTONS_OK, $message ); + + $dialog->set_position(Gtk::WIN_POS_CENTER); $dialog->run(); $dialog->destroy(); } @@ -205,6 +209,7 @@ function confirm($message) $message ); + $dialog->set_position(Gtk::WIN_POS_CENTER); $answer = $dialog->run(); $dialog->destroy(); diff --git a/sys/common/settings.php b/sys/common/settings.php index f0d881d..c31effa 100644 --- a/sys/common/settings.php +++ b/sys/common/settings.php @@ -125,6 +125,8 @@ class Settings { { if( ! isset($this->current->dbs->{$name})) { + $params['name'] = $name; + $this->current->dbs->{$name} = array(); $this->current->dbs->{$name} = $params; } @@ -142,14 +144,13 @@ class Settings { /** * Edit a database connection * - * @param string $name * @param array $params */ - public function edit_db($name, $params) + public function edit_db($params) { - if(isset($this->current->dbs->{$name})) + if(isset($this->current->dbs->{$params['name']})) { - $this->current->dbs->{$name} = $params; + $this->current->dbs->{$params['name']} = $params; } else { diff --git a/sys/windows/edit_db.php b/sys/windows/edit_db.php index 6697283..34f83fd 100644 --- a/sys/windows/edit_db.php +++ b/sys/windows/edit_db.php @@ -20,9 +20,9 @@ class Edit_DB extends GtkWindow { /** * Connection editing window * - * @param string $db + * @param object $db_params */ - public function __construct($db) + public function __construct($db_params) { parent::__construct(); @@ -30,7 +30,7 @@ class Edit_DB extends GtkWindow { $this->set_title("Edit Database Connection"); // Create the layout table - $connection_form = new DB_Info_Widget(Settings::get_instance()->get_db($db)); + $connection_form = new DB_Info_Widget($db_params); // Add the Vbox, and show the window $this->add($connection_form); diff --git a/sys/windows/widgets/connection_sidebar.php b/sys/windows/widgets/connection_sidebar.php index 16f4d20..b30e0ec 100644 --- a/sys/windows/widgets/connection_sidebar.php +++ b/sys/windows/widgets/connection_sidebar.php @@ -265,7 +265,7 @@ class Connection_Sidebar extends GtkVBox { */ public function edit_connection() { - //@todo implement + return new Edit_Db($this->treeview->get(0)); } // -------------------------------------------------------------------------- @@ -291,21 +291,5 @@ class Connection_Sidebar extends GtkVBox { // Refresh the sidebar $this->refresh(); } - - // -------------------------------------------------------------------------- - - /** - * Add a connection to the connection manager - * - * @param string $key - * @param array $vals - * @return void - */ - public function add_connection($key, $vals) - { - //@todo implement - $model = $this->treeview->get_model(); - } - } // End of connection_sidebar.php diff --git a/sys/windows/widgets/data_grid.php b/sys/windows/widgets/data_grid.php new file mode 100644 index 0000000..b9ae42f --- /dev/null +++ b/sys/windows/widgets/data_grid.php @@ -0,0 +1,86 @@ +model = ( ! is_null($model)) + ? $model + : new GtkTreeStore(Gobject::TYPE_PHP_VALUE); + + parent::__construct($this->model); + } + + // -------------------------------------------------------------------------- + + /** + * Get the value of the model for the current selection + * + * @param int pos + * @return mixed + */ + public function get($pos = 0) + { + // Get the selection object of the row + $sel = $this->get_selection(); + + // Get the model and iterator for the selected row + list($model, $iter) = $sel->get_selected(); + + // Get the data from the model + return $model->get_value($iter, $pos); + } + + // -------------------------------------------------------------------------- + + /** + * Set the value of the cell at the provided coordinate array + * + * @param array $coord + * @param mixed $val + */ + public function set(array $coord, $val) + { + // @todo implement + } + + // -------------------------------------------------------------------------- + + /** + * Empty the model + */ + public function reset() + { + $this->model->clear(); + + $cols = $this->get_columns(); + + foreach($cols as $c) + { + $this->remove_column($c); + } + } +} +// End of data_grid.php \ No newline at end of file diff --git a/sys/windows/widgets/db_info_widget.php b/sys/windows/widgets/db_info_widget.php index bf842a5..eba43e9 100644 --- a/sys/windows/widgets/db_info_widget.php +++ b/sys/windows/widgets/db_info_widget.php @@ -19,26 +19,27 @@ class DB_Info_Widget extends GtkTable { protected $conn, $dbtype, $host, $user, $pass, $database, $settings, $db_file, $port; - public function __construct($conn_name="") + /** + * No params = add, params = edit + * + * @param object $db + */ + public function __construct($db=null) { parent::__construct(); $this->settings =& Settings::get_instance(); - if ( ! empty($conn_name)) - { - $db = $this->settings->get_db($conn_name); - } - else + if (is_null($db)) { $db = new StdClass(); - $db->conn = ''; + $db->name = ''; $db->host = ''; $db->user = ''; $db->pass = ''; $db->port = ''; $db->conn_db = ''; - $db->dbtype = ''; + $db->type = ''; $db->file = NULL; } @@ -54,24 +55,38 @@ class DB_Info_Widget extends GtkTable { Gtk::FILE_CHOOSER_ACTION_OPEN); // Populate the available database types - // @todo Select type based on dbtype passed $db_types = $this->get_available_dbs(); foreach($db_types as $t) { $this->dbtype->append_text($t); } + $lower_db_types = array_map('strtolower', $db_types); // Populate the text fields with default values - $this->conn->set_text($db->conn); + $this->conn->set_text($db->name); $this->host->set_text($db->host); $this->user->set_text($db->user); $this->pass->set_text($db->pass); $this->conn_db->set_text($db->conn_db); - $this->db_file->set_filename($db->file); $this->port->set_text($db->port); // Layout the table $this->layout(); + + // Select the proper db type if editing + if ( ! empty($db->type)) + { + $dbtype = strtolower($db->type); + $this->dbtype->set_active(array_search($dbtype, $lower_db_types)); + + // Set default path + if ( ! empty($db->file)) + { + $this->db_file->set_filename($db->file); + } + + $this->set_db($dbtype); + } } /** @@ -137,12 +152,17 @@ class DB_Info_Widget extends GtkTable { // Add/Edit connection button { $conn_name = $this->conn->get_text(); - $caption = (empty($conn_name)) ? 'Add Connection' : 'Edit Connection'; + $caption = (empty($conn_name)) ? 'Add Connection' : 'Update Connection'; $add_button = new GtkButton(); $add_button->set_label($caption); - $add_button->set_image(GTKImage::new_from_stock(GTK::STOCK_ADD, - Gtk::ICON_SIZE_SMALL_TOOLBAR)); + + ( ! empty($conn_name)) + ? $add_button->set_image(GTKImage::new_from_stock(GTK::STOCK_SAVE, + GTK::ICON_SIZE_SMALL_TOOLBAR)) + : $add_button->set_image(GTKImage::new_from_stock(GTK::STOCK_ADD, + Gtk::ICON_SIZE_SMALL_TOOLBAR)); + $this->attach($add_button, 0, 1, ++$y1, ++$y2); if ( ! empty($conn_name)) @@ -232,6 +252,46 @@ class DB_Info_Widget extends GtkTable { } } + /** + * Like change_db function, but save current values + */ + public function set_db($dbtype) + { + + // Reset + $this->db_file->hide(); + $this->lbldb_file->hide(); + + switch($dbtype) + { + default: + break; + + case "firebird": + $this->lbldb_file->show(); + $this->db_file->show(); + $this->conn_db->hide(); + $this->lblconn_db->hide(); + break; + + case "odbc": + $this->lbldb_file->show(); + $this->db_file->show(); + break; + + case "sqlite": + $this->lbldb_file->show(); + $this->db_file->show(); + $this->port->hide(); + $this->lblport->hide(); + $this->host->hide(); + $this->lblhost->hide(); + $this->conn_db->hide(); + $this->lblconn_db->hide(); + break; + } + } + /** * Adds the database to the settings file */ @@ -275,14 +335,19 @@ class DB_Info_Widget extends GtkTable { 'name' => $this->conn->get_text(), ); - $this->settings->update_db($data['name'], $data); + if ($this->settings->edit_db($data)) + { + // Let the user know the connection has been updated + alert("Changes to database connection have been saved"); + } + else + { + error("Error saving changes"); + } // Pass to connection sidebar to update Connection_Sidebar::get_instance()->refresh(); - // Let the user know the connection has been updated - alert("Changes to database connection have been saved"); - // Destroy the parent window $parent_window =& $this->get_parent_window();