Misc cleanup
This commit is contained in:
parent
407bd26b0f
commit
d86fa948a9
@ -7,11 +7,14 @@
|
|||||||
* @author Timothy J. Warren
|
* @author Timothy J. Warren
|
||||||
* @copyright Copyright (c) 2012
|
* @copyright Copyright (c) 2012
|
||||||
* @link https://github.com/aviat4ion/OpenSQLManager
|
* @link https://github.com/aviat4ion/OpenSQLManager
|
||||||
* @license http://philsturgeon.co.uk/code/dbad-license
|
* @license http://philsturgeon.co.uk/code/dbad-license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Widget managing saved database connections
|
||||||
|
*/
|
||||||
class Connection_Sidebar extends GtkVBox {
|
class Connection_Sidebar extends GtkVBox {
|
||||||
|
|
||||||
protected $settings, $menu, $treeview, $model;
|
protected $settings, $menu, $treeview, $model;
|
||||||
@ -61,7 +64,7 @@ class Connection_Sidebar extends GtkVBox {
|
|||||||
$this->model = new GtkListStore(GObject::TYPE_PHP_VALUE, GObject::TYPE_STRING);
|
$this->model = new GtkListStore(GObject::TYPE_PHP_VALUE, GObject::TYPE_STRING);
|
||||||
|
|
||||||
// Render the treeview
|
// Render the treeview
|
||||||
$this->_render();
|
$this->_render();
|
||||||
|
|
||||||
// Set up context menu event
|
// Set up context menu event
|
||||||
$this->treeview->connect('button-press-event', array($this, 'on_button'));
|
$this->treeview->connect('button-press-event', array($this, 'on_button'));
|
||||||
@ -70,7 +73,7 @@ class Connection_Sidebar extends GtkVBox {
|
|||||||
$selection = $this->treeview->get_selection();
|
$selection = $this->treeview->get_selection();
|
||||||
$selection->set_mode(GTK::SELECTION_SINGLE);
|
$selection->set_mode(GTK::SELECTION_SINGLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$this->pack_start($this->treeview);
|
$this->pack_start($this->treeview);
|
||||||
$this->pack_start($add_button, FALSE);
|
$this->pack_start($add_button, FALSE);
|
||||||
@ -96,7 +99,7 @@ class Connection_Sidebar extends GtkVBox {
|
|||||||
$this->model->set($iter, 0, $db);
|
$this->model->set($iter, 0, $db);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the treeview with the data
|
// Initialize the treeview with the data
|
||||||
$this->treeview = new GtkTreeView($this->model);
|
$this->treeview = new GtkTreeView($this->model);
|
||||||
|
|
||||||
@ -113,8 +116,8 @@ class Connection_Sidebar extends GtkVBox {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the icon for the current db type
|
* Sets the icon for the current db type
|
||||||
*
|
*
|
||||||
* @param GtkTreeView Column $col
|
* @param GtkTreeView Column $col
|
||||||
* @param GtkCellRenderer $cell
|
* @param GtkCellRenderer $cell
|
||||||
* @param GtkTreeModel $this->model
|
* @param GtkTreeModel $this->model
|
||||||
* @param GtkTreeIter $iter
|
* @param GtkTreeIter $iter
|
||||||
@ -142,7 +145,7 @@ class Connection_Sidebar extends GtkVBox {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the label of the current db connection
|
* Sets the label of the current db connection
|
||||||
*
|
*
|
||||||
* @param GtkTreeViewColumn $col
|
* @param GtkTreeViewColumn $col
|
||||||
* @param GtkCellRenderer $cell
|
* @param GtkCellRenderer $cell
|
||||||
* @param GtkTreeModel $this->model
|
* @param GtkTreeModel $this->model
|
||||||
@ -159,7 +162,7 @@ class Connection_Sidebar extends GtkVBox {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns window for creating a new database connection
|
* Returns window for creating a new database connection
|
||||||
*
|
*
|
||||||
* @return Add_DB object
|
* @return Add_DB object
|
||||||
*/
|
*/
|
||||||
public function new_conn()
|
public function new_conn()
|
||||||
@ -171,7 +174,7 @@ class Connection_Sidebar extends GtkVBox {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Event for mouse clicks on connection sidebar
|
* Event for mouse clicks on connection sidebar
|
||||||
*
|
*
|
||||||
* @param GtkTreeView $view
|
* @param GtkTreeView $view
|
||||||
* @param $event
|
* @param $event
|
||||||
* @return void
|
* @return void
|
||||||
@ -207,8 +210,8 @@ class Connection_Sidebar extends GtkVBox {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates and displays a context menu for the selected connection
|
* Creates and displays a context menu for the selected connection
|
||||||
*
|
*
|
||||||
* @param array $pos
|
* @param array $pos
|
||||||
* @param object $event
|
* @param object $event
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
@ -224,7 +227,7 @@ class Connection_Sidebar extends GtkVBox {
|
|||||||
|
|
||||||
$this->menu->append($remove);
|
$this->menu->append($remove);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Popup the menu
|
// Popup the menu
|
||||||
$this->menu->show_all();
|
$this->menu->show_all();
|
||||||
$this->menu->popup();
|
$this->menu->popup();
|
||||||
@ -240,11 +243,11 @@ class Connection_Sidebar extends GtkVBox {
|
|||||||
//@todo implement
|
//@todo implement
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a connection from the connection manager
|
* Remove a connection from the connection manager
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function remove_connection($col)
|
public function remove_connection($col)
|
||||||
@ -262,7 +265,7 @@ class Connection_Sidebar extends GtkVBox {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a connection to the connection manager
|
* Add a connection to the connection manager
|
||||||
*
|
*
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @param array $vals
|
* @param array $vals
|
||||||
* @return void
|
* @return void
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* @author Timothy J. Warren
|
* @author Timothy J. Warren
|
||||||
* @copyright Copyright (c) 2012
|
* @copyright Copyright (c) 2012
|
||||||
* @link https://github.com/aviat4ion/OpenSQLManager
|
* @link https://github.com/aviat4ion/OpenSQLManager
|
||||||
* @license http://philsturgeon.co.uk/code/dbad-license
|
* @license http://philsturgeon.co.uk/code/dbad-license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
@ -19,8 +19,8 @@ class DB_Info_Widget extends GtkTable {
|
|||||||
|
|
||||||
protected $conn, $dbtype, $host, $user, $pass, $database, $settings, $db_file, $port;
|
protected $conn, $dbtype, $host, $user, $pass, $database, $settings, $db_file, $port;
|
||||||
|
|
||||||
public function __construct($conn='', $dbtype='', $host='localhost',
|
public function __construct($conn='', $dbtype='', $host='localhost',
|
||||||
$user='', $pass='', $database='', $db_file=NULL, $port='', $conn_db='')
|
$user='', $pass='', $db_file=NULL, $port='', $conn_db='')
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
@ -38,6 +38,7 @@ class DB_Info_Widget extends GtkTable {
|
|||||||
Gtk::FILE_CHOOSER_ACTION_OPEN);
|
Gtk::FILE_CHOOSER_ACTION_OPEN);
|
||||||
|
|
||||||
// Populate the available database types
|
// Populate the available database types
|
||||||
|
// @todo Select type based on dbtype passed
|
||||||
$db_types = $this->get_available_dbs();
|
$db_types = $this->get_available_dbs();
|
||||||
foreach($db_types as $t)
|
foreach($db_types as $t)
|
||||||
{
|
{
|
||||||
@ -51,6 +52,7 @@ class DB_Info_Widget extends GtkTable {
|
|||||||
$this->pass->set_text($pass);
|
$this->pass->set_text($pass);
|
||||||
$this->conn_db->set_text($conn_db);
|
$this->conn_db->set_text($conn_db);
|
||||||
$this->db_file->set_filename($db_file);
|
$this->db_file->set_filename($db_file);
|
||||||
|
$this->port->set_text($port);
|
||||||
|
|
||||||
// Layout the table
|
// Layout the table
|
||||||
$this->layout();
|
$this->layout();
|
||||||
@ -64,7 +66,7 @@ class DB_Info_Widget extends GtkTable {
|
|||||||
// Reset defaults when changing db types
|
// Reset defaults when changing db types
|
||||||
$this->dbtype->connect_simple("changed", array($this, "change_db"));
|
$this->dbtype->connect_simple("changed", array($this, "change_db"));
|
||||||
|
|
||||||
//Table attach
|
//Table attach
|
||||||
//$tbl->attach(left_start, right_stop, top_start, bottom_stop)
|
//$tbl->attach(left_start, right_stop, top_start, bottom_stop)
|
||||||
|
|
||||||
// Placeholder vars for y values, so that rows can be
|
// Placeholder vars for y values, so that rows can be
|
||||||
@ -120,10 +122,10 @@ class DB_Info_Widget extends GtkTable {
|
|||||||
{
|
{
|
||||||
$add_button = new GtkButton();
|
$add_button = new GtkButton();
|
||||||
$add_button->set_label("Add Connnection");
|
$add_button->set_label("Add Connnection");
|
||||||
$add_button->set_image(GTKImage::new_from_stock(GTK::STOCK_ADD,
|
$add_button->set_image(GTKImage::new_from_stock(GTK::STOCK_ADD,
|
||||||
Gtk::ICON_SIZE_SMALL_TOOLBAR));
|
Gtk::ICON_SIZE_SMALL_TOOLBAR));
|
||||||
$this->attach($add_button, 0, 1, ++$y1, ++$y2);
|
$this->attach($add_button, 0, 1, ++$y1, ++$y2);
|
||||||
$add_button->connect_simple("clicked", array($this, 'db_add'));
|
$add_button->connect_simple("clicked", array($this, 'db_add'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test connection button
|
// Test connection button
|
||||||
@ -137,7 +139,7 @@ class DB_Info_Widget extends GtkTable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set defaults for new database type
|
* Set defaults for new database type
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function change_db()
|
public function change_db()
|
||||||
@ -219,7 +221,7 @@ class DB_Info_Widget extends GtkTable {
|
|||||||
$this->settings->add_db($this->conn->get_text(), $data);
|
$this->settings->add_db($this->conn->get_text(), $data);
|
||||||
|
|
||||||
// Pass to connection sidebar to update
|
// Pass to connection sidebar to update
|
||||||
|
|
||||||
|
|
||||||
// Destroy the parent window
|
// Destroy the parent window
|
||||||
$parent_window =& $this->get_parent_window();
|
$parent_window =& $this->get_parent_window();
|
||||||
@ -249,9 +251,9 @@ class DB_Info_Widget extends GtkTable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Catch connection exceptions, and
|
// Catch connection exceptions, and
|
||||||
// display the error message to the
|
// display the error message to the
|
||||||
// user so they can edit the db
|
// user so they can edit the db
|
||||||
// parameters
|
// parameters
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -262,7 +264,7 @@ class DB_Info_Widget extends GtkTable {
|
|||||||
error("Error connecting to database: \n\n" . $e->getMessage());
|
error("Error connecting to database: \n\n" . $e->getMessage());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Successful Connection?
|
// Successful Connection?
|
||||||
// Tell the user!
|
// Tell the user!
|
||||||
alert("Successfully Connected.");
|
alert("Successfully Connected.");
|
||||||
@ -270,7 +272,7 @@ class DB_Info_Widget extends GtkTable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks what database drivers are available
|
* Checks what database drivers are available
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function get_available_dbs()
|
public function get_available_dbs()
|
||||||
@ -322,7 +324,7 @@ class DB_Info_Widget extends GtkTable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple helper function for adding a row to the GtkTable
|
* Simple helper function for adding a row to the GtkTable
|
||||||
*
|
*
|
||||||
* @param GtkTable &$table
|
* @param GtkTable &$table
|
||||||
* @param string $label
|
* @param string $label
|
||||||
* @param string $vname
|
* @param string $vname
|
||||||
@ -345,7 +347,7 @@ class DB_Info_Widget extends GtkTable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter input based on the requirements of the specified database
|
* Filter input based on the requirements of the specified database
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function _validate()
|
private function _validate()
|
||||||
|
Reference in New Issue
Block a user