Remove connections, edit connection window
This commit is contained in:
parent
069837ae35
commit
5c78737767
@ -162,6 +162,8 @@ function alert($message)
|
|||||||
Gtk::BUTTONS_OK,
|
Gtk::BUTTONS_OK,
|
||||||
$message
|
$message
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$dialog->set_position(Gtk::WIN_POS_CENTER);
|
||||||
$dialog->run();
|
$dialog->run();
|
||||||
$dialog->destroy();
|
$dialog->destroy();
|
||||||
}
|
}
|
||||||
@ -183,6 +185,8 @@ function error($message)
|
|||||||
Gtk::BUTTONS_OK,
|
Gtk::BUTTONS_OK,
|
||||||
$message
|
$message
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$dialog->set_position(Gtk::WIN_POS_CENTER);
|
||||||
$dialog->run();
|
$dialog->run();
|
||||||
$dialog->destroy();
|
$dialog->destroy();
|
||||||
}
|
}
|
||||||
@ -205,6 +209,7 @@ function confirm($message)
|
|||||||
$message
|
$message
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$dialog->set_position(Gtk::WIN_POS_CENTER);
|
||||||
$answer = $dialog->run();
|
$answer = $dialog->run();
|
||||||
$dialog->destroy();
|
$dialog->destroy();
|
||||||
|
|
||||||
|
@ -125,6 +125,8 @@ class Settings {
|
|||||||
{
|
{
|
||||||
if( ! isset($this->current->dbs->{$name}))
|
if( ! isset($this->current->dbs->{$name}))
|
||||||
{
|
{
|
||||||
|
$params['name'] = $name;
|
||||||
|
|
||||||
$this->current->dbs->{$name} = array();
|
$this->current->dbs->{$name} = array();
|
||||||
$this->current->dbs->{$name} = $params;
|
$this->current->dbs->{$name} = $params;
|
||||||
}
|
}
|
||||||
@ -142,14 +144,13 @@ class Settings {
|
|||||||
/**
|
/**
|
||||||
* Edit a database connection
|
* Edit a database connection
|
||||||
*
|
*
|
||||||
* @param string $name
|
|
||||||
* @param array $params
|
* @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
|
else
|
||||||
{
|
{
|
||||||
|
@ -20,9 +20,9 @@ class Edit_DB extends GtkWindow {
|
|||||||
/**
|
/**
|
||||||
* Connection editing window
|
* Connection editing window
|
||||||
*
|
*
|
||||||
* @param string $db
|
* @param object $db_params
|
||||||
*/
|
*/
|
||||||
public function __construct($db)
|
public function __construct($db_params)
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ class Edit_DB extends GtkWindow {
|
|||||||
$this->set_title("Edit Database Connection");
|
$this->set_title("Edit Database Connection");
|
||||||
|
|
||||||
// Create the layout table
|
// 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
|
// Add the Vbox, and show the window
|
||||||
$this->add($connection_form);
|
$this->add($connection_form);
|
||||||
|
@ -265,7 +265,7 @@ class Connection_Sidebar extends GtkVBox {
|
|||||||
*/
|
*/
|
||||||
public function edit_connection()
|
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
|
// Refresh the sidebar
|
||||||
$this->refresh();
|
$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
|
// End of connection_sidebar.php
|
||||||
|
86
sys/windows/widgets/data_grid.php
Normal file
86
sys/windows/widgets/data_grid.php
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* OpenSQLManager
|
||||||
|
*
|
||||||
|
* Free Database manager for Open Source Databases
|
||||||
|
*
|
||||||
|
* @author Timothy J. Warren
|
||||||
|
* @copyright Copyright (c) 2012
|
||||||
|
* @link https://github.com/aviat4ion/OpenSQLManager
|
||||||
|
* @license http://philsturgeon.co.uk/code/dbad-license
|
||||||
|
*/
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
*Class to simplify dealing with GtkTreeView
|
||||||
|
*/
|
||||||
|
class Data_Grid extends GtkTreeView {
|
||||||
|
|
||||||
|
protected $model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the object
|
||||||
|
*
|
||||||
|
* @param object $model
|
||||||
|
*/
|
||||||
|
public function __construct($model = null)
|
||||||
|
{
|
||||||
|
$this->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
|
@ -19,26 +19,27 @@ 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_name="")
|
/**
|
||||||
|
* No params = add, params = edit
|
||||||
|
*
|
||||||
|
* @param object $db
|
||||||
|
*/
|
||||||
|
public function __construct($db=null)
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->settings =& Settings::get_instance();
|
$this->settings =& Settings::get_instance();
|
||||||
|
|
||||||
if ( ! empty($conn_name))
|
if (is_null($db))
|
||||||
{
|
|
||||||
$db = $this->settings->get_db($conn_name);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
$db = new StdClass();
|
$db = new StdClass();
|
||||||
$db->conn = '';
|
$db->name = '';
|
||||||
$db->host = '';
|
$db->host = '';
|
||||||
$db->user = '';
|
$db->user = '';
|
||||||
$db->pass = '';
|
$db->pass = '';
|
||||||
$db->port = '';
|
$db->port = '';
|
||||||
$db->conn_db = '';
|
$db->conn_db = '';
|
||||||
$db->dbtype = '';
|
$db->type = '';
|
||||||
$db->file = NULL;
|
$db->file = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,24 +55,38 @@ 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)
|
||||||
{
|
{
|
||||||
$this->dbtype->append_text($t);
|
$this->dbtype->append_text($t);
|
||||||
}
|
}
|
||||||
|
$lower_db_types = array_map('strtolower', $db_types);
|
||||||
|
|
||||||
// Populate the text fields with default values
|
// 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->host->set_text($db->host);
|
||||||
$this->user->set_text($db->user);
|
$this->user->set_text($db->user);
|
||||||
$this->pass->set_text($db->pass);
|
$this->pass->set_text($db->pass);
|
||||||
$this->conn_db->set_text($db->conn_db);
|
$this->conn_db->set_text($db->conn_db);
|
||||||
$this->db_file->set_filename($db->file);
|
|
||||||
$this->port->set_text($db->port);
|
$this->port->set_text($db->port);
|
||||||
|
|
||||||
// Layout the table
|
// Layout the table
|
||||||
$this->layout();
|
$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
|
// Add/Edit connection button
|
||||||
{
|
{
|
||||||
$conn_name = $this->conn->get_text();
|
$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 = new GtkButton();
|
||||||
$add_button->set_label($caption);
|
$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);
|
$this->attach($add_button, 0, 1, ++$y1, ++$y2);
|
||||||
|
|
||||||
if ( ! empty($conn_name))
|
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
|
* Adds the database to the settings file
|
||||||
*/
|
*/
|
||||||
@ -275,14 +335,19 @@ class DB_Info_Widget extends GtkTable {
|
|||||||
'name' => $this->conn->get_text(),
|
'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
|
// Pass to connection sidebar to update
|
||||||
Connection_Sidebar::get_instance()->refresh();
|
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
|
// Destroy the parent window
|
||||||
$parent_window =& $this->get_parent_window();
|
$parent_window =& $this->get_parent_window();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user