diff --git a/index.php b/index.php index d7e1bd2..f50c43d 100644 --- a/index.php +++ b/index.php @@ -30,6 +30,7 @@ date_default_timezone_set('GMT'); define('BASE_DIR', dirname(__FILE__).'/sys'); define('SETTINGS_DIR', dirname(__FILE__)); define('PROGRAM_NAME', 'OpenSQLManager'); +define('VERSION', '0.1.0pre'); // -------------------------------------------------------------------------- diff --git a/sys/common/functions.php b/sys/common/functions.php index 9aca17a..96f0319 100644 --- a/sys/common/functions.php +++ b/sys/common/functions.php @@ -120,7 +120,7 @@ function about() $dlg = new GtkAboutDialog(); $dlg->set_program_name(PROGRAM_NAME); - $dlg->set_version('0.1.0pre'); + $dlg->set_version(VERSION); $dlg->set_copyright("Copyright (c) ".date('Y')." Timothy J. Warren"); diff --git a/sys/db/dbreg.php b/sys/db/dbreg.php index 70f4c39..8ab347d 100644 --- a/sys/db/dbreg.php +++ b/sys/db/dbreg.php @@ -66,5 +66,18 @@ class DB_Reg { { return array_keys(self::$instance); } + + // -------------------------------------------------------------------------- + + /** + * Remove a database connection + * + * @param string $key + * @return void + */ + public static function remove_db($key) + { + unset(self::$instance[$key]); + } } // End of dbreg.php \ No newline at end of file diff --git a/sys/windows/widgets/connection_sidebar.php b/sys/windows/widgets/connection_sidebar.php index 9221cb8..1a1d15f 100644 --- a/sys/windows/widgets/connection_sidebar.php +++ b/sys/windows/widgets/connection_sidebar.php @@ -47,8 +47,8 @@ class Connection_Sidebar extends GtkVBox { $this->settings =& Settings::get_instance(); - $dblabel = new GtkLabel('Database Connections'); - $dblabel->set_alignment(0,0); + //$dblabel = new GtkLabel('Database Connections'); + //$dblabel->set_alignment(0,0); $add_button = new GtkButton(); $add_button->set_label("New Connnection"); @@ -56,7 +56,7 @@ class Connection_Sidebar extends GtkVBox { $add_button->connect_simple('clicked', array($this, 'new_conn')); - $this->pack_start($dblabel, FALSE, FALSE); + //$this->pack_start($dblabel, FALSE, FALSE); // Treeview to show database connections { @@ -115,7 +115,7 @@ class Connection_Sidebar extends GtkVBox { // Label column $cell_renderer = new GtkCellRendererText(); - $this->treeview->insert_column_with_data_func(1, 'Connection name', $cell_renderer, array($this, 'set_label')); + $this->treeview->insert_column_with_data_func(1, 'Name', $cell_renderer, array($this, 'set_label')); // Status column $cell_renderer = new GtkCellRendererPixbuf(); @@ -187,18 +187,14 @@ class Connection_Sidebar extends GtkVBox { $conns = DB_Reg::get_connections(); - /*if(in_array($info->name, $conns)) + if(in_array($info->name, $conns)) { - $img = new GTKImage(); - $img->set_from_stock(GTK::STOCK_YES, Gtk::ICON_SIZE_SMALL_TOOLBAR); - $cell->set_property('pixbuf', $img->get_pixbuf()); + $cell->set_property('stock-id', 'gtk-yes'); } else { - $img = new GTKImage(); - $img->set_from_stock(GTK::STOCK_NO, Gtk::ICON_SIZE_SMALL_TOOLBAR); - $cell->set_property('pixbuf', $img->get_pixbuf()); - }*/ + $cell->set_property('stock-id', 'gtk-no'); + } } // -------------------------------------------------------------------------- @@ -260,11 +256,24 @@ class Connection_Sidebar extends GtkVBox { { $this->menu = new GtkMenu(); + $data = $this->treeview->get(0); + $conns = DB_Reg::get_connections(); + // Set up menu items { - $connect = new GtkImageMenuItem('Connect'); - $connect->set_image(GtkImage::new_from_stock(GTK::STOCK_CONNECT, GTK::ICON_SIZE_MENU)); - $connect->connect_simple('activate', array($this, 'db_connect')); + // Show disconnect + if (in_array($data->name, $conns)) + { + $connect = new GtkImageMenuItem('Disconnect'); + $connect->set_image(GtkImage::new_from_stock(GTK::STOCK_DISCONNECT, GTK::ICON_SIZE_MENU)); + $connect->connect_simple('activate', array($this, 'db_disconnect')); + } + else + { + $connect = new GtkImageMenuItem('Connect'); + $connect->set_image(GtkImage::new_from_stock(GTK::STOCK_CONNECT, GTK::ICON_SIZE_MENU)); + $connect->connect_simple('activate', array($this, 'db_connect')); + } $this->menu->append($connect); @@ -356,5 +365,19 @@ class Connection_Sidebar extends GtkVBox { DB_Tabs::get_instance()->get_db_tabs($conn); } + + // -------------------------------------------------------------------------- + + /** + * Disconnect from a database + */ + public function db_disconnect() + { + $data = $this->treeview->get(0); + + DB_Reg::remove_db($data->name); + + $this->refresh(); + } } // End of connection_sidebar.php diff --git a/sys/windows/widgets/db_info_widget.php b/sys/windows/widgets/db_info_widget.php index a520535..2bbcaf3 100644 --- a/sys/windows/widgets/db_info_widget.php +++ b/sys/windows/widgets/db_info_widget.php @@ -419,7 +419,7 @@ class DB_Info_Widget extends GtkTable { $params->pass = $this->pass->get_text(); $params->port = $this->port->get_text(); $params->file = $this->db_file->get_filename(); - $params->database = $this->conn_db->get_text(); + $params->conn_db = $this->conn_db->get_text(); // Return early if a db type isn't selected. // Better to bail out then crash because of diff --git a/sys/windows/widgets/db_tabs.php b/sys/windows/widgets/db_tabs.php index 15fbd56..151370a 100644 --- a/sys/windows/widgets/db_tabs.php +++ b/sys/windows/widgets/db_tabs.php @@ -17,6 +17,10 @@ */ class DB_tabs extends GTKNotebook { + /** + * Current Tab Widget object + * @var DB_Tabs + */ private static $instance; /** @@ -44,7 +48,7 @@ class DB_tabs extends GTKNotebook { parent::__construct(); // Move the tab bar to the bottom - $this->set_tab_pos(Gtk::POS_BOTTOM); + //$this->set_tab_pos(Gtk::POS_BOTTOM); } // -------------------------------------------------------------------------- @@ -74,7 +78,7 @@ class DB_tabs extends GTKNotebook { * * @return DB_tabs */ - public function reset() + public static function reset() { unset(self::$instance); return self::get_instance();