diff --git a/sys/common/query_builder.php b/sys/common/query_builder.php index 38198b9..6ba6038 100644 --- a/sys/common/query_builder.php +++ b/sys/common/query_builder.php @@ -31,7 +31,7 @@ class Query_Builder { // Add some flexibility for testing if(class_exists('settings')) { - $this->settings =& Settings::get_instance(); + $this->settings = Settings::get_instance(); $params = (is_scalar($conn_name)) ? $this->settings->get_db($conn_name) diff --git a/sys/windows/widgets/connection_sidebar.php b/sys/windows/widgets/connection_sidebar.php index d5f5a8b..04d9841 100644 --- a/sys/windows/widgets/connection_sidebar.php +++ b/sys/windows/widgets/connection_sidebar.php @@ -169,11 +169,25 @@ class Connection_Sidebar extends GtkVBox { */ public function on_button($view, $event) { + if ($event->button !== 3 || empty($view)) + { + return; + } + // Right click - if($event->button == 3) + if ($event->button == 3) { // get the row and column list($path_array, $col, $x, $y)= $view->get_path_at_pos($event->x, $event->y); + + // Don't try to get values for an item that doesn't exist. Instead, return, + // so that the program doesn't crash because someone thought it funny + // to click on the empty area of the treeview. + if(empty($col)) + { + return; + } + $path = $path_array[0]; //$col = $path_array[1]; $col_title = $col->get_title(); @@ -197,7 +211,14 @@ class Connection_Sidebar extends GtkVBox { $this->menu = new GtkMenu(); // Set up menu items + { + $remove = new GtkImageMenuItem('Delete Connection'); + $remove->set_image(GtkImage::new_from_stock(GTK::STOCK_CANCEL, Gtk::ICON_SIZE_MENU)); + + $this->menu->append($remove); + } + // Popup the menu $this->menu->show_all(); $this->menu->popup(); } @@ -212,6 +233,7 @@ class Connection_Sidebar extends GtkVBox { */ public function remove_connection($key) { + //@todo implement $model = $this->treeview->get_model(); } @@ -226,6 +248,7 @@ class Connection_Sidebar extends GtkVBox { */ public function add_connection($key, $vals) { + //@todo implement $model = $this->treeview->get_model(); } diff --git a/sys/windows/widgets/db_info_widget.php b/sys/windows/widgets/db_info_widget.php index 8d6a243..b17362d 100644 --- a/sys/windows/widgets/db_info_widget.php +++ b/sys/windows/widgets/db_info_widget.php @@ -112,9 +112,17 @@ class DB_Info_Widget extends GtkTable { $add_button->set_label("Add Connnection"); $add_button->set_image(GTKImage::new_from_stock(GTK::STOCK_ADD, Gtk::ICON_SIZE_SMALL_TOOLBAR)); - $this->attach($add_button, 0, 3, ++$y1, ++$y2); + $this->attach($add_button, 0, 1, ++$y1, ++$y2); $add_button->connect_simple("clicked", array($this, 'db_add')); } + + // Test connection button + { + $test_button = new GtkButton(); + $test_button->set_label("Test Connection"); + $this->attach($test_button, 1, 2, $y1, $y2); + $test_button->connect_simple("clicked", array($this, 'test_conn')); + } } /** @@ -210,6 +218,7 @@ class DB_Info_Widget extends GtkTable { 'host' => $this->host->get_text(), 'user' => $this->user->get_text(), 'pass' => $this->pass->get_text(), + 'port' => $this->port->get_text(), 'file' => $this->db_file->get_filename(), ); @@ -224,6 +233,53 @@ class DB_Info_Widget extends GtkTable { $parent_window->destroy(); } + /** + * Test a db connection, and display a popup with the result of the test + */ + public function test_conn() + { + $params = new stdClass(); + + $params->type = strtolower($this->dbtype->get_active_text()); + $params->host = $this->host->get_text(); + $params->user = $this->user->get_text(); + $params->pass = $this->pass->get_text(); + $params->port = $this->port->get_text(); + $params->file = $this->db_file->get_filename(); + + try + { + $db = new Query_Builder($params); + } + catch (PDOException $e) + { + $dialog = new GTKMessageDialog( + NULL, + Gtk::DIALOG_MODAL, + Gtk::MESSAGE_ERROR, + Gtk::BUTTONS_OK, + "Error connecting to database: \n\n" . $e->getMessage() + ); + $dialog->run(); + $dialog->destroy(); + + return; + } + + $dialog = new GTKMessageDialog( + NULL, + Gtk::DIALOG_MODAL, + Gtk::MESSAGE_INFO, + Gtk::BUTTONS_OK, + "Successfully connected" + ); + + $dialog->run(); + $dialog->destroy(); + + return; + } + /** * Checks what database drivers are available *