Browse Source

Initial import

Frederic G. Marand 17 năm trước cách đây
commit
213a6c6834
6 tập tin đã thay đổi với 516 bổ sung0 xóa
  1. 50 0
      Glade_Window.php
  2. 113 0
      Pgma_Model.php
  3. 288 0
      Pgma_View.glade
  4. 38 0
      Pgma_View.php
  5. 4 0
      pgma.ini
  6. 23 0
      pgma.phpg

+ 50 - 0
Glade_Window.php

@@ -0,0 +1,50 @@
+<?php
+/**
+ * 
+ */
+
+/**
+ * Auto-loading Glade window
+ */
+class Glade_Window
+  {
+  /**
+   * The top widget. It does not have to be
+   * a top-level object if this is loaded
+   * within another UI
+   *
+   * @var unknown_type
+   */
+  public $top; 
+  
+  /**
+   * Load the fixed structure for the actual class invoking the constructor
+   * 
+   * @param void
+   * @return void
+   */
+  public function __construct($topName = 'top')
+    {
+    $uiDescriptionFileName = get_class($this) . '.glade';
+    try
+      {
+      $glade = new GladeXML($uiDescriptionFileName);
+      $glade->signal_autoconnect_instance($this);
+      $this->win = $glade->get_widget('winPgma');
+      }
+    catch (Exception $e)
+      {
+      echo "Glade_Windows/__construct(): " . $e->getMessage();
+      die();
+      }
+    }
+    
+  /**
+   * callback wrapper around Gtk::main_quit() for Glade
+   */
+  public function quit()
+    {
+    Gtk::main_quit();
+    }
+
+  }

+ 113 - 0
Pgma_Model.php

@@ -0,0 +1,113 @@
+<?php
+/**
+ * Php-Gtk MySQL administrator - Main application data storage
+ * 
+ * This is just a plain text file
+ *
+ * @license CeCILL 2.0
+ * @copyright 2008 Ouest  Systemes Informatiques
+ * @author Frederic G. MARAND
+ * @version $Id: Pgma_Model.php,v 1.1 2008-05-23 09:42:27 cvs Exp $
+ */
+
+class Pgma_Model
+  {
+  /**
+   * Program properties. This is an array of sections and value
+   * from the <program>.ini file
+   * Sections include:
+   * - Layout
+   *
+   * @var array
+   */
+  public $properties;
+  /**
+   * Sign properties to detect any change
+   *
+   * @var string
+   */
+  protected $hash;
+
+  /**
+   * Obtain the file name of the configuration
+   * file, without the directory
+   *
+   * Why static ? Because it is instance-independent
+   * 
+   * @return string
+   */
+  static protected function getConfigFileName()
+    {
+    /**
+     * Why not just use basename ? Because in PHP-GTK
+     * the PHP filename extension can be any .php*,
+     */
+    $name = $_SERVER['SCRIPT_NAME'];
+    $name = pathinfo($name, PATHINFO_FILENAME);
+    $name .= '.ini';
+    return $name;  
+    }
+    
+  /**
+   * Auto-load configuration
+   * 
+   * @return void
+   */
+  function __construct()
+    {
+    $name = self::getConfigFileName();
+    $this->properties = file_exists($name) ? parse_ini_file($name, TRUE) : NULL;
+    $this->hash = md5(var_export($this->properties, TRUE));
+    }
+    
+  /**
+   * Auto-save configuration
+   * 
+   * @return void
+   */
+  function __destruct()
+    {
+    /**
+     * No need to save if properties haven't been changed
+     */
+    if ($this->hash == md5(var_export($this->properties, TRUE)))
+      {
+      return;
+      }
+    else
+      {
+      echo "Saving application settings\n";
+      }
+      
+    $name = self::getConfigFileName();
+    $s = '';
+    foreach ($this->properties as $sectionKey => $sectionValue)
+      {
+      $s .= "[$sectionKey]" . PHP_EOL;
+      foreach ($sectionValue as $key => $value)
+        {
+        $s .= $key . ' = ';
+        if (is_bool($value))
+          {
+          $s .= $value ? 'TRUE' : 'FALSE';
+          }
+        elseif (is_numeric($value))
+          {
+          $s .= $value;
+          }
+        elseif (is_string($value))
+          {
+          $s .= '"' . $value . '"';
+          }
+        else
+          {
+          die('Unsupported property type for '
+            . "$sectionKey/$key: " . gettype($value)
+            );
+          }
+        $s .= PHP_EOL;
+        }
+      }
+    file_put_contents($name, $s);
+    }
+  }

+ 288 - 0
Pgma_View.glade

@@ -0,0 +1,288 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
+<!--Generated with glade3 3.4.3 on Thu May 22 18:54:44 2008 -->
+<glade-interface>
+  <widget class="GtkWindow" id="winPgma">
+    <signal name="destroy" handler="quit"/>
+    <child>
+      <widget class="GtkVBox" id="vboxPgma">
+        <property name="visible">True</property>
+        <child>
+          <widget class="GtkMenuBar" id="menubar">
+            <property name="visible">True</property>
+            <child>
+              <widget class="GtkMenuItem" id="menuitem1">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">_Fichier</property>
+                <property name="use_underline">True</property>
+                <child>
+                  <widget class="GtkMenu" id="menu1">
+                    <property name="visible">True</property>
+                    <child>
+                      <widget class="GtkImageMenuItem" id="imagemenuitem1">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">gtk-new</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </widget>
+                    </child>
+                    <child>
+                      <widget class="GtkImageMenuItem" id="imagemenuitem2">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">gtk-open</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </widget>
+                    </child>
+                    <child>
+                      <widget class="GtkImageMenuItem" id="imagemenuitem3">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">gtk-save</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </widget>
+                    </child>
+                    <child>
+                      <widget class="GtkImageMenuItem" id="imagemenuitem4">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">gtk-save-as</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </widget>
+                    </child>
+                    <child>
+                      <widget class="GtkSeparatorMenuItem" id="separatormenuitem1">
+                        <property name="visible">True</property>
+                      </widget>
+                    </child>
+                    <child>
+                      <widget class="GtkImageMenuItem" id="imagemenuitem5">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">gtk-quit</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                        <signal name="activate" handler="quit"/>
+                      </widget>
+                    </child>
+                  </widget>
+                </child>
+              </widget>
+            </child>
+            <child>
+              <widget class="GtkMenuItem" id="menuitem2">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">É_dition</property>
+                <property name="use_underline">True</property>
+                <child>
+                  <widget class="GtkMenu" id="menu2">
+                    <property name="visible">True</property>
+                    <child>
+                      <widget class="GtkImageMenuItem" id="imagemenuitem6">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">gtk-cut</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </widget>
+                    </child>
+                    <child>
+                      <widget class="GtkImageMenuItem" id="imagemenuitem7">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">gtk-copy</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </widget>
+                    </child>
+                    <child>
+                      <widget class="GtkImageMenuItem" id="imagemenuitem8">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">gtk-paste</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </widget>
+                    </child>
+                    <child>
+                      <widget class="GtkImageMenuItem" id="imagemenuitem9">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">gtk-delete</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </widget>
+                    </child>
+                  </widget>
+                </child>
+              </widget>
+            </child>
+            <child>
+              <widget class="GtkMenuItem" id="menuitem3">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">_Affichage</property>
+                <property name="use_underline">True</property>
+              </widget>
+            </child>
+            <child>
+              <widget class="GtkMenuItem" id="menuitem4">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">Aid_e</property>
+                <property name="use_underline">True</property>
+                <child>
+                  <widget class="GtkMenu" id="menu3">
+                    <property name="visible">True</property>
+                    <child>
+                      <widget class="GtkImageMenuItem" id="imagemenuitem10">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">gtk-about</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </widget>
+                    </child>
+                  </widget>
+                </child>
+              </widget>
+            </child>
+          </widget>
+          <packing>
+            <property name="expand">False</property>
+          </packing>
+        </child>
+        <child>
+          <widget class="GtkHBox" id="hboxPgma">
+            <property name="visible">True</property>
+            <child>
+              <widget class="GtkScrolledWindow" id="swNavigationView">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+                <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+                <child>
+                  <widget class="GtkTreeView" id="tvNavigation">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="headers_clickable">True</property>
+                  </widget>
+                </child>
+              </widget>
+            </child>
+            <child>
+              <widget class="GtkNotebook" id="nbViews">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <child>
+                  <widget class="GtkScrolledWindow" id="swServerView">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+                    <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+                    <child>
+                      <placeholder/>
+                    </child>
+                  </widget>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="label1">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">page 1</property>
+                  </widget>
+                  <packing>
+                    <property name="type">tab</property>
+                    <property name="tab_fill">False</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkScrolledWindow" id="swDbView">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+                    <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+                    <child>
+                      <placeholder/>
+                    </child>
+                  </widget>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="label2">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">page 2</property>
+                  </widget>
+                  <packing>
+                    <property name="type">tab</property>
+                    <property name="position">1</property>
+                    <property name="tab_fill">False</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkScrolledWindow" id="swTableView">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+                    <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+                    <child>
+                      <placeholder/>
+                    </child>
+                  </widget>
+                  <packing>
+                    <property name="position">2</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="label3">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">page 3</property>
+                  </widget>
+                  <packing>
+                    <property name="type">tab</property>
+                    <property name="position">2</property>
+                    <property name="tab_fill">False</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkScrolledWindow" id="swFieldView">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+                    <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+                    <child>
+                      <placeholder/>
+                    </child>
+                  </widget>
+                  <packing>
+                    <property name="position">3</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="label4">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">page 4</property>
+                  </widget>
+                  <packing>
+                    <property name="type">tab</property>
+                    <property name="position">3</property>
+                    <property name="tab_fill">False</property>
+                  </packing>
+                </child>
+              </widget>
+              <packing>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </widget>
+          <packing>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <widget class="GtkStatusbar" id="sb">
+            <property name="visible">True</property>
+            <property name="spacing">2</property>
+          </widget>
+          <packing>
+            <property name="expand">False</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
+      </widget>
+    </child>
+  </widget>
+</glade-interface>

+ 38 - 0
Pgma_View.php

@@ -0,0 +1,38 @@
+<?php
+/**
+ * Php-Gtk MySQL administrator - Main application view
+ *
+ * @license CeCILL 2.0
+ * @copyright 2008 Ouest  Systemes Informatiques
+ * @author Frederic G. MARAND
+ * @version $Id: Pgma_View.php,v 1.1 2008-05-23 09:42:27 cvs Exp $
+ */
+
+/**
+ * Main application view
+ */
+class Pgma_View extends Glade_Window 
+  {
+  /**
+   * The application model (config file)
+   * @see Pgma_Model
+   * @var array
+   */
+  protected $model;
+  
+  /**
+   * @var GtkFrame
+   */
+  public $activeDetailView;
+
+  /**
+   * Load the view fixed structure, then reload session info
+   * 
+   * @return void
+   */
+  public function __construct()
+    {
+    parent::__construct('winPgma'); // not the standard top-level name
+    $this->model = new Pgma_Model(); // load configuration info
+    }
+  }

+ 4 - 0
pgma.ini

@@ -0,0 +1,4 @@
+[Layout]
+maximized = TRUE
+width = 800
+height = 600

+ 23 - 0
pgma.phpg

@@ -0,0 +1,23 @@
+<?php
+error_reporting(E_ALL);
+
+/**
+ * @FIXME Make it safe. It needs consistency checks, escaping...
+ *
+ * @param string $name
+ * @return void
+ */
+function __autoload($name)
+  {
+  echo "Autoloading $name\n";
+  require_once("$name.php");
+  }
+ 
+if (version_compare(phpversion(), '5.2.4', '<='))
+ {
+ die('This program needs PHP 5.2.4 at a minimum. Current version is ' . PHP_VERSION);  
+ }
+ 
+$pgmaView = new Pgma_View();
+$pgmaView->win->show_all();
+Gtk::main();