Pgma_View.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * Php-Gtk MySQL administrator - Main application view
  4. *
  5. * @license CeCILL 2.0
  6. * @copyright 2008 Ouest Systemes Informatiques
  7. * @author Frederic G. MARAND
  8. * @version $Id: Pgma_View.php,v 1.2 2008-05-25 20:31:40 cvs Exp $
  9. */
  10. /**
  11. * Main application view
  12. */
  13. class Pgma_View extends Glade_Window
  14. {
  15. /**
  16. * The application model (config file)
  17. * @see Pgma_Model
  18. * @var array
  19. */
  20. protected $model;
  21. /**
  22. * @var Server_Controller
  23. */
  24. protected $serverController;
  25. /**
  26. * @var GtkFrame
  27. */
  28. public $activeDetailView;
  29. /**
  30. * Prepare the view and its initial data
  31. *
  32. * @return void
  33. */
  34. public function __construct()
  35. {
  36. /**
  37. * 1. Load the view fixed structure
  38. */
  39. parent::__construct('winPgma'); // not the standard top-level name
  40. $this->top->set_size_request(640, 480);
  41. /**
  42. * 2. Restore session info
  43. */
  44. $this->model = new Pgma_Model(); // load configuration info
  45. /**
  46. * @todo Apply layout info restored at this point to the top-level window
  47. */
  48. /**
  49. * 3. connect
  50. */
  51. $this->serverController = new Server_Controller($this->model->properties['Auth']);
  52. try
  53. {
  54. $this->serverController->login();
  55. }
  56. catch (PDOException $e)
  57. {
  58. die('Failed login to the DB server: ' . PHP_EOL
  59. . $e->getMessage() . PHP_EOL);
  60. }
  61. /**
  62. * Populate the DB view
  63. */
  64. $dbStore = new GtkListStore(GObject::TYPE_STRING);
  65. $arDatabases = $this->serverController->getDatabases();
  66. foreach ($arDatabases as $dbName)
  67. {
  68. $dbStore->append(array($dbName));
  69. }
  70. $dbView = $this->glade->get_widget('tvNavigation');
  71. $dbView->set_model($dbStore);
  72. $dbNameRenderer = new GtkCellRendererText();
  73. $dbNameRenderer->set_property('width', -1);
  74. $dbNameRenderer->set_property('text', $dbName);
  75. $dbCol = new GtkTreeViewColumn('Database', $dbNameRenderer, 'text', 0);
  76. $dbCol->set_cell_data_func($dbNameRenderer, array($this, 'zebraTreeViewCallback'));
  77. $dbView->append_column($dbCol);
  78. }
  79. }