Minor tweaks

This commit is contained in:
Timothy Warren 2012-06-01 11:55:59 -04:00
parent 2eed1a7207
commit 4709afd878
2 changed files with 447 additions and 446 deletions

View File

@ -1,259 +1,261 @@
<?php <?php
/** /**
* OpenSQLManager * OpenSQLManager
* *
* Free Database manager for Open Source Databases * Free Database manager for Open Source Databases
* *
* @package OpenSQLManager * @package OpenSQLManager
* @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
*/ */
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
namespace OpenSQLManager; namespace OpenSQLManager;
/** /**
* Widget for adding / Editing Connections * Widget for adding / Editing Connections
* *
* @package OpenSQLManager * @package OpenSQLManager
* @subpackage Widgets * @subpackage Widgets
*/ */
class Connection_Manager extends \wxFrame { class Connection_Manager extends \wxFrame {
const TXT_CONN_NAME = 1; const TXT_CONN_NAME = 1;
const COMBO_DB_TYPE = 2; const COMBO_DB_TYPE = 2;
const FILE_DB_FILE = 3; const FILE_DB_FILE = 3;
const TXT_DB_NAME = 4; const TXT_DB_NAME = 4;
const TXT_DB_HOST = 5; const TXT_DB_HOST = 5;
const TXT_DB_PORT = 6; const TXT_DB_PORT = 6;
const TXT_DB_USER = 7; const TXT_DB_USER = 7;
const TXT_DB_PASS = 8; const TXT_DB_PASS = 8;
const BTN_TEST = 9; const BTN_TEST = 9;
/** /**
* Array of fields for Connection Information manipulation * Array of fields for Connection Information manipulation
* *
* @var array * @var array
*/ */
protected $fields = array(); protected $fields = array();
/** /**
* Create the window * Create the window
* *
* @param wxWindow * @param wxWindow
* @param mixed * @param mixed
*/ */
public function __construct($parent, $params = array()) public function __construct($parent, $params = array())
{ {
parent::__construct($parent, 32, "Connection Manager", wxDefaultPosition); parent::__construct($parent, 32, "Connection Manager", wxDefaultPosition);
// Layout the window // Layout the window
$this->_layout($params); $this->_layout($params);
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** /**
* Layout fields on the form * Layout fields on the form
* *
* @param array * @param array
*/ */
protected function _layout($params) protected function _layout($params)
{ {
$container_sizer = new \wxBoxSizer(wxVERTICAL); $container_sizer = new \wxBoxSizer(wxVERTICAL);
// Use a table-like sizer // Use a table-like sizer
$sizer = new \wxFlexGridSizer(2, 5, 5); $sizer = new \wxFlexGridSizer(2, 5, 5);
$sizer->SetHGap(5); $sizer->SetHGap(5);
$sizer->SetVGap(5); $sizer->SetVGap(5);
$sizer->SetFlexibleDirection(wxBOTH); $sizer->SetFlexibleDirection(wxBOTH);
$sizer->AddGrowableCol(0, 1); $sizer->AddGrowableCol(0, 1);
$sizer->AddGrowableCol(1, 1); $sizer->AddGrowableCol(1, 1);
$db_types = $this->get_available_dbs(); $db_types = $this->get_available_dbs();
if ($db_types === FALSE) if ($db_types === FALSE)
{ {
error("No valid databases set up in PHP"); error("No valid databases set up in PHP");
return; return;
} }
// Create the controls // Create the controls
// label => control // label => control
$this->fields = array( $this->fields = array(
'Connection Name' => new \wxTextCtrl($this, self::TXT_CONN_NAME), 'Connection Name' => new \wxTextCtrl($this, self::TXT_CONN_NAME),
'Database Type' => $choice = new \wxChoice(), 'Database Type' => $choice = new \wxChoice(),
'Database File' => new \wxFilePickerCtrl($this, self::FILE_DB_FILE, wxEmptyString, "Select the database file", '*.*'), 'Database File' => new \wxFilePickerCtrl($this, self::FILE_DB_FILE, wxEmptyString, "Select the database file", '*.*'),
'Database Name' => new \wxTextCtrl($this, self::TXT_DB_NAME), 'Database Name' => new \wxTextCtrl($this, self::TXT_DB_NAME),
'Host' => new \wxTextCtrl($this, self::TXT_DB_HOST), 'Host' => new \wxTextCtrl($this, self::TXT_DB_HOST),
'Port' => new \wxTextCtrl($this, self::TXT_DB_PORT), 'Port' => new \wxTextCtrl($this, self::TXT_DB_PORT),
'User' => new \wxTextCtrl($this, self::TXT_DB_USER), 'User' => new \wxTextCtrl($this, self::TXT_DB_USER),
'Password' => new \wxTextCtrl($this, self::TXT_DB_PASS) 'Password' => new \wxTextCtrl($this, self::TXT_DB_PASS)
); );
$choice->Create($this, self::COMBO_DB_TYPE, wxDefaultPosition, wxDefaultSize, $db_types); $choice->Create($this, self::COMBO_DB_TYPE, wxDefaultPosition, wxDefaultSize, $db_types);
// Add the controls to the sizer // Add the controls to the sizer
$i = 1; $i = 1;
foreach ($this->fields as $lbl => $ctrl) foreach ($this->fields as $lbl => $ctrl)
{ {
$label = new \wxStaticText($this, $i, $lbl); $label = new \wxStaticText($this, $i, $lbl);
$sizer->Add($label, 0, wxALIGN_LEFT); $sizer->Add($label, 0, wxALIGN_LEFT);
$sizer->Add($ctrl, 1, wxALIGN_RIGHT|wxEXPAND); $sizer->Add($ctrl, 1, wxALIGN_RIGHT|wxEXPAND);
$i++; $i++;
} }
// Test Connection Button // Test Connection Button
$test_button = new \wxButton($this, self::BTN_TEST, 'Test Connection'); $test_button = new \wxButton($this, self::BTN_TEST, 'Test Connection');
$test_button->Connect(wxEVT_COMMAND_BUTTON_CLICKED, array($this, 'test_conn')); $test_button->Connect(wxEVT_COMMAND_BUTTON_CLICKED, array($this, 'test_conn'));
// Add Connection Button // Add Connection Button
// TODO: Add connection button // TODO: Add connection button
// Add the buttons to the sizer // Add the buttons to the sizer
$sizer->Add($test_button, 1, wxEXPAND); $sizer->Add($test_button, 1, wxEXPAND);
// Add the sizer to the window // Add the sizer to the window
// Add it inside of another sizer for padding. // Add it inside of another sizer for padding.
$container_sizer->Add($sizer, 1, wxALL|wxEXPAND, 10); $container_sizer->Add($sizer, 1, wxALL|wxEXPAND, 10);
$this->SetSizer($container_sizer); $this->SetSizer($container_sizer);
$this->Layout(); $this->Layout();
// Autosize the window to fit the controls // Autosize the window to fit the controls
$this->Fit(); $this->Fit();
$this->CenterOnScreen(wxBOTH); $this->CenterOnScreen(wxBOTH);
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** /**
* Get the list of available database types * Get the list of available database types
* *
* return array * return array
*/ */
protected function get_available_dbs() protected function get_available_dbs()
{ {
$drivers = array(""); $drivers = array("");
$pdo_drivers = \pdo_drivers(); $pdo_drivers = \pdo_drivers();
// Add PDO drivers // Add PDO drivers
foreach ($pdo_drivers as &$d) foreach ($pdo_drivers as &$d)
{ {
// Skip sqlite2 as opposed to sqlite3 // Skip sqlite2 as opposed to sqlite3
if ($d === 'sqlite2' && (in_array('sqlite', $pdo_drivers) || in_array('sqlite3', $pdo_drivers))) if ($d === 'sqlite2' && (in_array('sqlite', $pdo_drivers) || in_array('sqlite3', $pdo_drivers)))
{ {
continue; continue;
} }
// Use the ibase_functions over PDO::Firebird, at least for now // Use the ibase_functions over PDO::Firebird, at least for now
if ($d === 'firebird') if ($d === 'firebird')
{ {
continue; continue;
} }
// Replace default capitalization with something that looks better. // Replace default capitalization with something that looks better.
$d = str_replace("sql", "SQL", $d); $d = str_replace("sql", "SQL", $d);
$d = str_ireplace("pg", "Postgre", $d); $d = str_ireplace("pg", "Postgre", $d);
$d = str_ireplace("odbc", "ODBC", $d); $d = str_ireplace("odbc", "ODBC", $d);
$d = ucfirst($d); $d = ucfirst($d);
$drivers[] = $d; $drivers[] = $d;
} }
// Add firebird support, if exists // Add firebird support, if exists
if (function_exists('fbird_connect')) if (function_exists('fbird_connect'))
{ {
$drivers[] = "Firebird"; $drivers[] = "Firebird";
} }
sort($drivers); sort($drivers);
return $drivers; return $drivers;
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** /**
* Set defaults for new database type * Set defaults for new database type
* *
* @return void * @return void
*/ */
public function change_db() public function change_db()
{ {
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** /**
* Test a db connection, and display a popup with the result * Test a db connection, and display a popup with the result
* *
* @return void * @return void
*/ */
public function test_conn() public function test_conn()
{ {
// Get the connection parameters // Get the connection parameters
$params = $this->_get_vals(); $params = $this->_get_vals();
// Smart alek error for smart alek behavior // Smart alek error for smart alek behavior
if (empty($params->type)) if (empty($params->type))
{ {
error("You need to select the correct database type"); error("You need to select the correct database type");
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
{ {
new \Query_Builder($params); new \Query_Builder($params);
} }
catch (\PDOException $e) catch (\PDOException $e)
{ {
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.");
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** /**
* Get the values of the widgets in the window * Get the values of the widgets in the window
* *
* @return object * @return object
*/ */
private function _get_vals() private function _get_vals()
{ {
$params = new \stdClass(); $params = new \stdClass();
$fields =& $this->fields; $fields =& $this->fields;
$types = $this->get_available_dbs(); $types = $this->get_available_dbs();
$type_id = $fields['Database Type']->GetSelection(); $type_id = $fields['Database Type']->GetSelection();
$type = $types[$type_id]; $type = (isset($types[$type_id]))
? $types[$type_id]
$params->name = $fields['Connection Name']->GetValue(); : "";
$params->type = $type;
$params->file = $fields['Database File']->GetPath(); $params->name = $fields['Connection Name']->GetValue();
$params->conn_db = $fields['Database Name']->GetValue(); $params->type = $type;
$params->host = $fields['Host']->GetValue(); $params->file = $fields['Database File']->GetPath();
$params->port = $fields['Port']->GetValue(); $params->conn_db = $fields['Database Name']->GetValue();
$params->user = $fields['User']->GetValue(); $params->host = $fields['Host']->GetValue();
$params->pass = $fields['Password']->GetValue(); $params->port = $fields['Port']->GetValue();
$params->user = $fields['User']->GetValue();
return $params; $params->pass = $fields['Password']->GetValue();
}
} return $params;
}
}
// End of connection_manager.php // End of connection_manager.php

View File

@ -1,189 +1,188 @@
<?php <?php
/** /**
* OpenSQLManager * OpenSQLManager
* *
* Free Database manager for Open Source Databases * Free Database manager for Open Source Databases
* *
* @package OpenSQLManager * @package OpenSQLManager
* @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
*/ */
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
namespace OpenSQLManager; namespace OpenSQLManager;
/** /**
* Main Window Class * Main Window Class
* *
* Creates and displays the main interface window * Creates and displays the main interface window
* *
* @package OpenSQLManager * @package OpenSQLManager
* @subpackage Windows * @subpackage Windows
*/ */
class Main extends \wxFrame { class Main extends \wxFrame {
/** /**
* Reference to settings instance * Reference to settings instance
* *
* @var Settings * @var Settings
*/ */
private $settings; private $settings;
/** /**
* Reference to connection sidebar instance * Reference to connection sidebar instance
* *
* @var Connection_Sidebar * @var Connection_Sidebar
*/ */
private $connection_sidebar; private $connection_sidebar;
/** /**
* Reference to split window * Reference to split window
* *
* @var wxSplitterWindow * @var wxSplitterWindow
*/ */
protected $split; protected $split;
/** /**
* Create and display the main window on startup * Create and display the main window on startup
*/ */
public function __construct() public function __construct()
{ {
parent::__construct(NULL, NULL, PROGRAM_NAME, \wxDefaultPosition, new \wxSize(800, 600)); parent::__construct(NULL, NULL, PROGRAM_NAME, \wxDefaultPosition,new \wxSize(800, 480));
$this->_create_menu();
$this->_create_menu();
$sbar = $this->CreateStatusBar(2);
$sbar = $this->CreateStatusBar(2); $sbar->SetStatusText("OpenSQLManager");
$sbar->SetStatusText("OpenSQLManager");
$this->settings =& Settings::get_instance();
$this->settings =& Settings::get_instance();
// Layout the interface
// Layout the interface $this->_main_layout();
$this->_main_layout(); $this->CenterOnScreen(wxBOTH);
$this->SetThemeEnabled(TRUE); }
$this->CenterOnScreen(wxBOTH);
} // --------------------------------------------------------------------------
// -------------------------------------------------------------------------- /**
* Some cleanup for when the main window is closed
/** *
* Some cleanup for when the main window is closed * @return void
* */
* @return void public function __destruct()
*/ {
public function __destruct() $this->Destroy();
{ }
$this->Destroy();
} // --------------------------------------------------------------------------
// -------------------------------------------------------------------------- /**
* Exits the wx loop
/** *
* Exits the wx loop * @return void
* */
* @return void public function quit()
*/ {
public function quit() $this->Destroy();
{ }
$this->Destroy();
} // --------------------------------------------------------------------------
// -------------------------------------------------------------------------- /**
* Display About menu with version information
/** *
* Display About menu with version information * @return void
* */
* @return void function about()
*/ {
function about() $dlg = new \wxAboutDialogInfo();
{
$dlg = new \wxAboutDialogInfo(); $dlg->SetName(PROGRAM_NAME);
$dlg->SetVersion(VERSION);
$dlg->SetName(PROGRAM_NAME);
$dlg->SetVersion(VERSION); $dlg->SetCopyright("Copyright (c) ".date('Y')." Timothy J. Warren");
$dlg->SetCopyright("Copyright (c) ".date('Y')." Timothy J. Warren"); $dlg->SetWebSite('https://github.com/aviat4ion/OpenSQLManager','Fork on Github');
$dlg->SetWebSite('https://github.com/aviat4ion/OpenSQLManager','Fork on Github'); $dlg->SetLicense(file_get_contents(BASE_DIR . "/LICENSE"));
$dlg->SetLicense(file_get_contents(BASE_DIR . "/LICENSE")); $dlg->SetDevelopers(array(
'Timothy J. Warren',
$dlg->SetDevelopers(array( ));
'Timothy J. Warren',
)); \wxAboutBox($dlg);
}
\wxAboutBox($dlg);
} // --------------------------------------------------------------------------
// -------------------------------------------------------------------------- /**
* Layout the main interface
/** * Create menus, hboxes, vboxs and other widgets
* Layout the main interface *
* Create menus, hboxes, vboxs and other widgets * @return void
* */
* @return void private function _main_layout()
*/ {
private function _main_layout() // Set up the main menu
{ $this->_create_menu();
// Set up the main menu
$this->_create_menu(); // Create a split window
$win = new \wxSplitterWindow($this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_THIN_SASH);
// Create a split window $win->setSplitMode(wxSPLIT_HORIZONTAL);
$win = new \wxSplitterWindow($this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_THIN_SASH);
$win->setSplitMode(wxSPLIT_HORIZONTAL); // Add the connection sidebar
$this->connection_sidebar =& Connection_Sidebar::get_instance($win);
// Add the connection sidebar $win2 = new Data_Grid($win);
$this->connection_sidebar =& Connection_Sidebar::get_instance($win);
$win2 = new Data_Grid($win); // Add the widgets to the split window
$win->SplitVertically($this->connection_sidebar, $win2);
// Add the widgets to the split window $win->SetSashPosition(200, TRUE);
$win->SplitVertically($this->connection_sidebar, $win2);
$win->SetSashPosition(200, TRUE); // Save a reference for later use
$this->split =& $win;
// Save a reference for later use }
$this->split =& $win;
} // --------------------------------------------------------------------------
// -------------------------------------------------------------------------- /**
* Create the menu for the program
/** *
* Create the menu for the program * @return void
* */
* @return GtkMenuBar private function _create_menu()
*/ {
private function _create_menu() // Menu Bar
{ $menu_bar = new \wxMenuBar();
// Menu Bar
$menu_bar = new \wxMenuBar(); // Menu Bar Top Items
$top_file_menu = new \wxMenu();
// Menu Bar Top Items $top_help_menu = new \wxMenu();
$top_file_menu = new \wxMenu();
$top_help_menu = new \wxMenu(); // File Menu
{
// File Menu // Set up the quit item
{ $top_file_menu->Append(2, "&Quit", "Exit the program");
// Set up the quit item $this->Connect(2, wxEVT_COMMAND_MENU_SELECTED, array($this, "quit"));
$top_file_menu->Append(2, "&Quit", "Exit the program");
$this->Connect(2, wxEVT_COMMAND_MENU_SELECTED, array($this, "quit")); // Add the top level menu to the menubar
$menu_bar->Append($top_file_menu, "&File");
// Add the top level menu to the menubar }
$menu_bar->Append($top_file_menu, "&File");
} // Help Menu
{
// Help Menu // Set up the about item
{ $top_help_menu->Append(4, "&About", "About this program");
// Set up the about item $this->Connect(4, wxEVT_COMMAND_MENU_SELECTED, array($this, "about"));
$top_help_menu->Append(4, "&About", "About this program");
$this->Connect(4, wxEVT_COMMAND_MENU_SELECTED, array($this, "about")); // Add the top level menu to the menubar
$menu_bar->Append($top_help_menu, "&Help");
// Add the top level menu to the menubar }
$menu_bar->Append($top_help_menu, "&Help");
}
$this->SetMenuBar($menu_bar);
}
$this->SetMenuBar($menu_bar); }
}
}
// End of main.php // End of main.php