2012-01-26 16:09:05 -05:00
|
|
|
<?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
|
|
|
|
*/
|
2012-01-27 16:57:59 -05:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Main Window Class
|
|
|
|
*
|
|
|
|
* Creates and displays the main interface window
|
|
|
|
*/
|
2012-01-26 16:09:05 -05:00
|
|
|
class Main extends GtkWindow {
|
|
|
|
|
2012-02-02 22:18:50 -05:00
|
|
|
private $settings;
|
2012-01-27 16:57:59 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create and display the main window on startup
|
|
|
|
*/
|
2012-02-21 11:45:42 -05:00
|
|
|
public function __construct()
|
2012-01-26 16:09:05 -05:00
|
|
|
{
|
|
|
|
parent::__construct();
|
2012-01-27 11:57:13 -05:00
|
|
|
|
2012-01-30 18:11:01 -05:00
|
|
|
//Resize to a sane size
|
|
|
|
$this->resize(640, 480);
|
|
|
|
|
2012-02-02 22:18:50 -05:00
|
|
|
$this->set_position(Gtk::WIN_POS_CENTER);
|
|
|
|
$this->settings = new Settings();
|
|
|
|
|
2012-01-27 16:57:59 -05:00
|
|
|
//Layout the interface
|
|
|
|
$this->_main_layout();
|
|
|
|
}
|
|
|
|
|
2012-01-30 13:15:44 -05:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display About menu with version information
|
|
|
|
*/
|
2012-02-21 11:45:42 -05:00
|
|
|
public function about()
|
2012-01-30 13:15:44 -05:00
|
|
|
{
|
|
|
|
$dlg = new GtkAboutDialog();
|
|
|
|
$dlg->set_transient_for($this);
|
|
|
|
|
2012-02-07 10:31:54 -05:00
|
|
|
$dlg->set_program_name($this->get_title());
|
2012-01-30 15:23:38 -05:00
|
|
|
$dlg->set_version('0.1.0pre');
|
2012-01-30 13:15:44 -05:00
|
|
|
|
|
|
|
$dlg->set_copyright("Copyright (c) ".date('Y')." Timothy J. Warren");
|
|
|
|
|
|
|
|
$dlg->set_website('https://github.com/aviat4ion/OpenSQLManager');
|
2012-01-30 18:11:01 -05:00
|
|
|
$dlg->set_website_label('Fork on Github');
|
|
|
|
|
2012-02-01 10:51:06 -05:00
|
|
|
$dlg->set_license(file_get_contents(BASE_DIR . "/LICENSE"));
|
2012-01-30 18:11:01 -05:00
|
|
|
|
|
|
|
$dlg->set_authors(array(
|
|
|
|
'Timothy J. Warren',
|
2012-02-07 10:31:54 -05:00
|
|
|
//'Nathan Dupuie',
|
2012-01-30 18:11:01 -05:00
|
|
|
));
|
|
|
|
|
2012-02-07 10:31:54 -05:00
|
|
|
/*$dlg->set_artists(array(
|
2012-01-30 18:11:01 -05:00
|
|
|
'Nathan Dupuie',
|
2012-02-07 10:31:54 -05:00
|
|
|
));*/
|
2012-01-30 13:15:44 -05:00
|
|
|
|
|
|
|
$dlg->run();
|
|
|
|
|
|
|
|
$dlg->destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Quits the GTK loop
|
|
|
|
*/
|
2012-02-21 11:45:42 -05:00
|
|
|
public function quit()
|
2012-01-30 13:15:44 -05:00
|
|
|
{
|
|
|
|
Gtk::main_quit();
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2012-01-27 16:57:59 -05:00
|
|
|
/**
|
|
|
|
* Layout the main interface
|
|
|
|
*
|
|
|
|
* Create menus, hboxes, vboxs and other widgets
|
|
|
|
*/
|
|
|
|
private function _main_layout()
|
|
|
|
{
|
2012-01-27 11:57:13 -05:00
|
|
|
$this->set_title('OpenSQLManager');
|
|
|
|
|
|
|
|
// Quit when this window is closed
|
|
|
|
$this->connect_simple('destroy', array('gtk', 'main_quit'));
|
2012-01-27 16:57:59 -05:00
|
|
|
|
|
|
|
// Main Vbox that everything is contained in
|
|
|
|
$main_vbox = new GTKVBox();
|
|
|
|
|
2012-02-02 19:40:21 -05:00
|
|
|
// Main Hpaned for columns
|
|
|
|
$hpane = new GTKHPaned();
|
2012-01-27 16:57:59 -05:00
|
|
|
|
|
|
|
// Add the menubar
|
|
|
|
$main_vbox->pack_start($this->_create_menu(), FALSE, FALSE);
|
|
|
|
|
|
|
|
// Add the main interface area hbox
|
2012-02-02 19:40:21 -05:00
|
|
|
$main_vbox->pack_start($hpane);
|
2012-01-27 16:57:59 -05:00
|
|
|
|
2012-02-10 09:55:14 -05:00
|
|
|
$scrolled_win = new GtkScrolledWindow();
|
|
|
|
$scrolled_win->set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_ALWAYS);
|
|
|
|
$scrolled_win->add(new DataGrid());
|
2012-02-07 10:31:54 -05:00
|
|
|
|
|
|
|
|
2012-02-02 19:40:21 -05:00
|
|
|
// Add the left column to the hpane
|
|
|
|
$hpane->pack1($this->_connection_sidebar(), FALSE);
|
2012-02-10 09:55:14 -05:00
|
|
|
$hpane->pack2($scrolled_win);
|
2012-01-30 18:11:01 -05:00
|
|
|
|
2012-01-27 16:57:59 -05:00
|
|
|
// Add the Vbox, and show the window
|
|
|
|
$this->add($main_vbox);
|
|
|
|
$this->show_all();
|
2012-01-26 16:09:05 -05:00
|
|
|
}
|
|
|
|
|
2012-01-30 13:15:44 -05:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2012-01-27 16:57:59 -05:00
|
|
|
/**
|
|
|
|
* Create the menu for the program
|
|
|
|
*
|
|
|
|
* @return GtkMenuBar
|
|
|
|
*/
|
|
|
|
private function _create_menu()
|
|
|
|
{
|
|
|
|
//Menu Bar
|
|
|
|
$menu_bar = new GtkMenuBar();
|
|
|
|
|
|
|
|
//Menu Bar Top Items
|
|
|
|
$top_file_menu = new GtkMenuItem('_File');
|
|
|
|
$top_help_menu = new GtkMenuItem('_Help');
|
|
|
|
|
|
|
|
//Add sub Menus to top items
|
|
|
|
$file_menu = new GtkMenu();
|
|
|
|
$top_file_menu->set_submenu($file_menu);
|
|
|
|
$help_menu = new GtkMenu();
|
|
|
|
$top_help_menu->set_submenu($help_menu);
|
|
|
|
|
|
|
|
|
|
|
|
//File Menu
|
2012-01-31 11:39:30 -05:00
|
|
|
{
|
2012-01-30 11:22:44 -05:00
|
|
|
//Set up the open item
|
2012-01-30 18:11:01 -05:00
|
|
|
//$open = new GtkImageMenuItem(GTK::STOCK_OPEN);
|
|
|
|
//$file_menu->append($open);
|
2012-01-30 11:22:44 -05:00
|
|
|
|
2012-01-27 16:57:59 -05:00
|
|
|
//Set up the quit item
|
|
|
|
$quit = new GtkImageMenuItem(GTK::STOCK_QUIT);
|
|
|
|
$quit->connect_simple('activate', array($this, 'quit'));
|
2012-01-27 21:19:39 -05:00
|
|
|
$file_menu->append($quit);
|
2012-01-27 16:57:59 -05:00
|
|
|
|
|
|
|
// Add the top level menu to the menubar
|
|
|
|
$menu_bar->append($top_file_menu);
|
2012-01-31 11:39:30 -05:00
|
|
|
}
|
2012-01-27 16:57:59 -05:00
|
|
|
|
|
|
|
//Help Menu
|
2012-01-31 11:39:30 -05:00
|
|
|
{
|
2012-01-27 16:57:59 -05:00
|
|
|
//Set up the about item
|
|
|
|
$about = new GtkImageMenuItem(GTK::STOCK_ABOUT);
|
|
|
|
$about->connect_simple('activate', array($this, 'about'));
|
|
|
|
$help_menu->append($about);
|
|
|
|
|
|
|
|
// Add the top level menu to the menubar
|
|
|
|
$menu_bar->append($top_help_menu);
|
2012-01-31 11:39:30 -05:00
|
|
|
}
|
2012-01-27 16:57:59 -05:00
|
|
|
|
|
|
|
|
|
|
|
return $menu_bar;
|
|
|
|
}
|
|
|
|
|
2012-01-30 13:15:44 -05:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2012-01-30 18:11:01 -05:00
|
|
|
/**
|
|
|
|
* Lays out the left sidebar in the main window
|
|
|
|
*
|
|
|
|
* @return GtkVbox
|
|
|
|
*/
|
|
|
|
private function _connection_sidebar()
|
|
|
|
{
|
|
|
|
$dblabel = new GtkLabel('Database Connections');
|
|
|
|
$dblabel->set_alignment(0,0);
|
2012-01-31 11:39:30 -05:00
|
|
|
|
|
|
|
$add_button = new GtkButton();
|
|
|
|
$add_button->set_label("New Connnection");
|
|
|
|
$add_button->set_image(GTKImage::new_from_stock(GTK::STOCK_ADD, Gtk::ICON_SIZE_SMALL_TOOLBAR));
|
|
|
|
|
2012-01-31 12:42:38 -05:00
|
|
|
$add_button->connect_simple('clicked', array($this, 'new_conn'));
|
|
|
|
|
2012-01-30 18:11:01 -05:00
|
|
|
$conn_vbox = new GtkVBox();
|
|
|
|
|
2012-02-02 22:18:50 -05:00
|
|
|
// Treeview to show database connections
|
|
|
|
{
|
|
|
|
// Create a Storage object for connection list
|
|
|
|
$model = new GtkListStore(GObject::TYPE_PHP_VALUE, GObject::TYPE_STRING);
|
|
|
|
|
|
|
|
// Add the existing connections to the model
|
|
|
|
$db_conns = $this->settings->get_dbs();
|
|
|
|
if( ! empty($db_conns))
|
|
|
|
{
|
|
|
|
foreach($db_conns as $name => $props)
|
|
|
|
{
|
|
|
|
$db = $props;
|
2012-02-06 12:14:39 -05:00
|
|
|
$db->name = $name;
|
2012-02-02 22:18:50 -05:00
|
|
|
|
|
|
|
$iter = $model->append();
|
|
|
|
$model->set($iter, 0, $db);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize the treeview with the data
|
|
|
|
$treeview = new GtkTreeView($model);
|
|
|
|
|
|
|
|
$cell_renderer = new GtkCellRendererText();
|
|
|
|
$treeview->insert_column_with_data_func(-1, 'Database Connections', $cell_renderer, array(&$this, 'set_label'));
|
|
|
|
|
|
|
|
$selection = $treeview->get_selection();
|
|
|
|
$selection->set_mode(GTK::SELECTION_SINGLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$conn_vbox->pack_start($treeview);
|
2012-01-31 11:39:30 -05:00
|
|
|
$conn_vbox->pack_start($add_button, FALSE);
|
2012-01-30 18:11:01 -05:00
|
|
|
|
|
|
|
return $conn_vbox;
|
|
|
|
}
|
2012-01-31 12:42:38 -05:00
|
|
|
|
2012-02-02 22:18:50 -05:00
|
|
|
/**
|
|
|
|
* Sets the label of the current db connection
|
|
|
|
*
|
|
|
|
* @param GtkTreeViewColumn $col
|
|
|
|
* @param GtkCellRenderer $cell
|
|
|
|
* @param GtkTreeModel $model
|
|
|
|
* @param GtkTreeIter $iter
|
|
|
|
*/
|
2012-02-21 11:45:42 -05:00
|
|
|
public function set_label($col, $cell, $model, $iter)
|
2012-02-02 22:18:50 -05:00
|
|
|
{
|
|
|
|
$info = $model->get_value($iter, 0);
|
2012-02-06 12:14:39 -05:00
|
|
|
$cell->set_property('text', $info->name);
|
2012-02-02 22:18:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Redraws the data area based on the which connection is selected
|
|
|
|
*
|
|
|
|
* @param $selection
|
|
|
|
*/
|
|
|
|
private function _render_selected($selection)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-02-01 10:51:06 -05:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns window for creating a new database connection
|
|
|
|
*
|
|
|
|
* @return Add_DB object
|
|
|
|
*/
|
2012-02-21 11:45:42 -05:00
|
|
|
public function new_conn()
|
2012-01-31 12:42:38 -05:00
|
|
|
{
|
|
|
|
return new Add_DB();
|
|
|
|
}
|
2012-01-30 13:15:44 -05:00
|
|
|
|
2012-01-27 16:57:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// End of main.php
|