From f2191c9ae41cec0cb4b5c938d9763827041d5299 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 2 Apr 2012 13:04:53 -0400 Subject: [PATCH] Fix loading of existing database info for editing Move global function to their own file --- index.php | 99 +---------------- sys/common/functions.php | 146 +++++++++++++++++++++++++ sys/windows/main.php | 40 +------ sys/windows/widgets/db_info_widget.php | 3 + sys/windows/widgets/db_tabs.php | 34 +++++- 5 files changed, 185 insertions(+), 137 deletions(-) create mode 100644 sys/common/functions.php diff --git a/index.php b/index.php index 613e9ed..d7e1bd2 100644 --- a/index.php +++ b/index.php @@ -29,6 +29,7 @@ date_default_timezone_set('GMT'); // Set the current directory as the base for included files define('BASE_DIR', dirname(__FILE__).'/sys'); define('SETTINGS_DIR', dirname(__FILE__)); +define('PROGRAM_NAME', 'OpenSQLManager'); // -------------------------------------------------------------------------- @@ -118,104 +119,6 @@ if(function_exists('fbird_connect')) require_once("{$path}firebird_sql.php"); } -// -------------------------------------------------------------------------- -// ! Global Functions -// -------------------------------------------------------------------------- - -/** - * Convert an array to an object - * - * @param array $array - * @return object - */ -function array_to_object($array) -{ - if (is_object($array)) - { - return $array; - } - - $obj = new StdClass(); - - foreach($array as $k => $v) - { - $obj->$k = $v; - } - - return $obj; -} - -// -------------------------------------------------------------------------- - -/** - * Create info dialog to retun an informational message - * - * @param string $message - * @return void - */ -function alert($message) -{ - $dialog = new GTKMessageDialog( - NULL, - Gtk::DIALOG_MODAL, - Gtk::MESSAGE_INFO, - Gtk::BUTTONS_OK, - $message - ); - - $dialog->set_position(Gtk::WIN_POS_CENTER); - $dialog->run(); - $dialog->destroy(); -} - -// -------------------------------------------------------------------------- - -/** - * Create info dialog to retun an informational message - * - * @param string $message - * @return void - */ -function error($message) -{ - $dialog = new GTKMessageDialog( - NULL, - Gtk::DIALOG_MODAL, - Gtk::MESSAGE_ERROR, - Gtk::BUTTONS_OK, - $message - ); - - $dialog->set_position(Gtk::WIN_POS_CENTER); - $dialog->run(); - $dialog->destroy(); -} - -// -------------------------------------------------------------------------- - -/** - * Creates a binary confirmation dialog - * - * @param string $message - * @return bool - */ -function confirm($message) -{ - $dialog = new GTKMessageDialog( - NULL, - Gtk::DIALOG_MODAL, - Gtk::MESSAGE_QUESTION, - Gtk::BUTTONS_YES_NO, - $message - ); - - $dialog->set_position(Gtk::WIN_POS_CENTER); - $answer = $dialog->run(); - $dialog->destroy(); - - return ($answer === Gtk::RESPONSE_YES) ? TRUE : FALSE; -} - // -------------------------------------------------------------------------- // Create the main window diff --git a/sys/common/functions.php b/sys/common/functions.php new file mode 100644 index 0000000..9aca17a --- /dev/null +++ b/sys/common/functions.php @@ -0,0 +1,146 @@ + $v) + { + $obj->$k = $v; + } + + return $obj; +} + +// -------------------------------------------------------------------------- + +/** + * Create info dialog to retun an informational message + * + * @param string $message + * @return void + */ +function alert($message) +{ + $dialog = new GTKMessageDialog( + NULL, + Gtk::DIALOG_MODAL, + Gtk::MESSAGE_INFO, + Gtk::BUTTONS_OK, + $message + ); + + $dialog->set_position(Gtk::WIN_POS_CENTER); + $dialog->run(); + $dialog->destroy(); +} + +// -------------------------------------------------------------------------- + +/** + * Create info dialog to retun an informational message + * + * @param string $message + * @return void + */ +function error($message) +{ + $dialog = new GTKMessageDialog( + NULL, + Gtk::DIALOG_MODAL, + Gtk::MESSAGE_ERROR, + Gtk::BUTTONS_OK, + $message + ); + + $dialog->set_position(Gtk::WIN_POS_CENTER); + $dialog->run(); + $dialog->destroy(); +} + +// -------------------------------------------------------------------------- + +/** + * Creates a binary confirmation dialog + * + * @param string $message + * @return bool + */ +function confirm($message) +{ + $dialog = new GTKMessageDialog( + NULL, + Gtk::DIALOG_MODAL, + Gtk::MESSAGE_QUESTION, + Gtk::BUTTONS_YES_NO, + $message + ); + + $dialog->set_position(Gtk::WIN_POS_CENTER); + $answer = $dialog->run(); + $dialog->destroy(); + + return ($answer === Gtk::RESPONSE_YES) ? TRUE : FALSE; +} + +// -------------------------------------------------------------------------- + +/** + * Display About menu with version information + * + * @return void + */ +function about() +{ + $dlg = new GtkAboutDialog(); + + $dlg->set_program_name(PROGRAM_NAME); + $dlg->set_version('0.1.0pre'); + + $dlg->set_copyright("Copyright (c) ".date('Y')." Timothy J. Warren"); + + $dlg->set_website('https://github.com/aviat4ion/OpenSQLManager'); + $dlg->set_website_label('Fork on Github'); + + $dlg->set_license(file_get_contents(BASE_DIR . "/LICENSE")); + + $dlg->set_authors(array( + 'Timothy J. Warren', + //'Nathan Dupuie', + )); + + /*$dlg->set_artists(array( + 'Nathan Dupuie', + ));*/ + + $dlg->run(); + + $dlg->destroy(); +} + +// End of functions.php \ No newline at end of file diff --git a/sys/windows/main.php b/sys/windows/main.php index 0b9b592..9ec9be1 100644 --- a/sys/windows/main.php +++ b/sys/windows/main.php @@ -77,42 +77,6 @@ class Main extends GtkWindow { // -------------------------------------------------------------------------- - /** - * Display About menu with version information - * - * @return void - */ - public function about() - { - $dlg = new GtkAboutDialog(); - $dlg->set_transient_for($this); - - $dlg->set_program_name($this->get_title()); - $dlg->set_version('0.1.0pre'); - - $dlg->set_copyright("Copyright (c) ".date('Y')." Timothy J. Warren"); - - $dlg->set_website('https://github.com/aviat4ion/OpenSQLManager'); - $dlg->set_website_label('Fork on Github'); - - $dlg->set_license(file_get_contents(BASE_DIR . "/LICENSE")); - - $dlg->set_authors(array( - 'Timothy J. Warren', - //'Nathan Dupuie', - )); - - /*$dlg->set_artists(array( - 'Nathan Dupuie', - ));*/ - - $dlg->run(); - - $dlg->destroy(); - } - - // -------------------------------------------------------------------------- - /** * Quits the GTK loop */ @@ -131,7 +95,7 @@ class Main extends GtkWindow { */ private function _main_layout() { - $this->set_title('OpenSQLManager'); + $this->set_title(PROGRAM_NAME); // Quit when this window is closed $this->connect_simple('destroy', array('gtk', 'main_quit')); @@ -202,7 +166,7 @@ class Main extends GtkWindow { { // Set up the about item $about = new GtkImageMenuItem(GTK::STOCK_ABOUT); - $about->connect_simple('activate', array($this, 'about')); + $about->connect_simple('activate', 'about'); $help_menu->append($about); // Add the top level menu to the menubar diff --git a/sys/windows/widgets/db_info_widget.php b/sys/windows/widgets/db_info_widget.php index dcb2f52..a520535 100644 --- a/sys/windows/widgets/db_info_widget.php +++ b/sys/windows/widgets/db_info_widget.php @@ -120,6 +120,9 @@ class DB_Info_Widget extends GtkTable { { $this->db_file->set_filename($db->file); } + + $this->pass->set_text($db->pass); + $this->conn_db->set_text($db->conn_db); } } diff --git a/sys/windows/widgets/db_tabs.php b/sys/windows/widgets/db_tabs.php index 897fd2c..15fbd56 100644 --- a/sys/windows/widgets/db_tabs.php +++ b/sys/windows/widgets/db_tabs.php @@ -90,7 +90,39 @@ class DB_tabs extends GTKNotebook { */ public function get_db_tabs(&$conn) { - print_r($conn->get_tables()); + $tables = new Data_Grid(); + $table_model = $tables->get_model(); + $table_data = $conn->get_tables(); + + foreach($table_data as $t) + { + $iter = $table_model->append(); + $table_model->set($iter, 0, $t); + } + + $cell_renderer = new GtkCellRendererText(); + $tables->insert_column_with_data_func(0, 'Table Name', $cell_renderer, array($this, 'add_data_col')); + + $this->add_tab('Tables', $tables); + + } + + // -------------------------------------------------------------------------- + + /** + * Adds a column of data to the model + * + * @param GtkTreeViewColumn $col + * @param GtkCellRenderer $cell + * @param GtkTreeModel $model + * @param GtkTreeIter $iter + * @param int $i + * @return void + */ + public function add_data_col($col, $cell, $model, $iter, $i=0) + { + $data = $model->get_value($iter, $i); + $cell->set_property('text', $data); } } // End of db_tabs.php