PEAR_Frontend_Gtk
[ class tree: PEAR_Frontend_Gtk ] [ index: PEAR_Frontend_Gtk ] [ all elements ]

Source for file Config.php

Documentation is available at Config.php

  1. <?php
  2. /*
  3.   +----------------------------------------------------------------------+
  4.   | PHP Version 4                                                        |
  5.   +----------------------------------------------------------------------+
  6.   | Copyright (c) 1997-2003 The PHP Group                                |
  7.   +----------------------------------------------------------------------+
  8.   | This source file is subject to version 2.02 of the PHP license,      |
  9.   | that is bundled with this package in the file LICENSE, and is        |
  10.   | available at through the world-wide-web at                           |
  11.   | http://www.php.net/license/2_02.txt.                                 |
  12.   | If you did not receive a copy of the PHP license and are unable to   |
  13.   | obtain it through the world-wide-web, please send a note to          |
  14.   | license@php.net so we can mail you a copy immediately.               |
  15.   +----------------------------------------------------------------------+
  16.   | Author: Alan Knowles <alan@akbkhome.com>                             |
  17.   +----------------------------------------------------------------------+
  18.  
  19.   $Id: Config.php,v 1.5 2003/01/04 11:55:55 mj Exp $
  20. */
  21.  
  22. /**
  23.  * Gtk Frontend - Configuration
  24.  *
  25.  * @author Alan Knowles <alan@akbkhome.com>
  26.  */
  27.  
  28.  
  29. class PEAR_Frontend_Gtk_Config {
  30.     var $ui// main interface
  31.     /**
  32.     * The GtkLabel that shows the help config
  33.     *
  34.     * @var object GtkLabel configuration help text
  35.     * @access private
  36.     */
  37.     var $help;
  38.        /**
  39.     * The GtkNotebook that has all the tabs
  40.     *
  41.     * @var object Gtknotebook 
  42.     * @access private
  43.     */
  44.     var $notebook;
  45.    /**
  46.     * The Save GtkButton
  47.     *
  48.     * @var object GtkButton 
  49.     * @access private
  50.     */
  51.     var $save;
  52.     /**
  53.     * The Reset GtkButton
  54.     *
  55.     * @var object GtkButton 
  56.     * @access private
  57.     */
  58.     var $reset;
  59.     /**
  60.     * The New configuration
  61.     *
  62.     * @var array asssociative key=>value
  63.     * @access private
  64.     */
  65.     var $NewConfig;
  66.     /**
  67.     * Constructor
  68.     *
  69.     * @param array see config-show for more details.
  70.     */
  71.     
  72.     function PEAR_Frontend_Gtk_Config(&$ui{
  73.         $this->ui &$ui;
  74.     }
  75.     
  76.     /**
  77.     * Load Configuration into widgets (Initialize)
  78.     *
  79.     * Clear current config tabs, and calls the Command Show-config
  80.     *
  81.     * @param  object getbutton  from the reset button!
  82.     * @param  string            no idea yet!
  83.     */
  84.     function loadConfig($widget=NULL,$what=NULL{
  85.         $this->NewConfig= array();
  86.         if ($this->_configTabs
  87.             foreach (array_keys($this->_configTabsas $k{
  88.                 $page $this->notebook->page_num($this->_configTabs[$k]);
  89.                 $this->notebook->remove_page($page);
  90.                 $this->_configTabs[$k]->destroy();
  91.             }
  92.         
  93.         // delete any other pages;
  94.         if ($widget $this->notebook->get_nth_page(0)) {
  95.             $this->notebook->remove_page(0);
  96.             $widget->destroy();
  97.         }
  98.         $this->_configTabs = array();
  99.         $cmd = PEAR_Command::factory('config-show',$this->ui->config);
  100.         $cmd->ui = &$this->ui;
  101.         $cmd->run('config-show' ,''array());
  102.         $this->save->set_sensitive(FALSE)
  103.         $this->reset->set_sensitive(FALSE);
  104.     }
  105.     
  106.     /**
  107.     * Build the widgets based on the return 'data' array from config-show
  108.     *
  109.     * @param array see config-show for more details.
  110.     */
  111.     function buildConfig(&$array{
  112.         if (!$arrayreturn;
  113.         foreach ($array as $group=>$items
  114.             foreach ($items as $v{
  115.                 $this->_buildConfigItem($v[1],$v[2]);
  116.             }
  117.  
  118.     }
  119.     /**
  120.     * Build the widgets for a configuration item
  121.     *
  122.     * @param string  configuration 'key'
  123.     * @param string  configuration 'value'
  124.     */
  125.     function _buildConfigItem($k,$v{
  126.         //echo "BUIDLING CONF ITME $k $v\n";
  127.         $group $this->ui->config->getGroup($k);
  128.         $gtktable =  $this->_getConfigTab($group);
  129.         $prompt $this->ui->config->getPrompt($k);
  130.         $gtklabel &new GtkLabel();
  131.         $gtklabel->set_text($prompt);
  132.         $gtklabel->set_justify(GTK_JUSTIFY_LEFT);
  133.         $gtklabel->set_alignment(0.00.5);
  134.         $gtklabel->show();
  135.         $r $gtktable->nrows;
  136.         $gtktable->attach($gtklabel01$r$r+1GTK_FILL,GTK_FILL);
  137.         if ($v == '<not set>'
  138.             $v '';
  139.         
  140.         $type $this->ui->config->getType($k);
  141.         switch ($type{
  142.             case 'string':
  143.             case 'password':
  144.             //case 'int': // umask: should really be checkboxes..
  145.                 $gtkentry &new GtkEntry();
  146.                 $gtkentry->set_text($v);
  147.                 
  148.                 $gtkentry->connect_object_after('enter_notify_event',
  149.                     array(&$this,'_setConfigHelp'),$this->ui->config->getDocs($k));
  150.                 $gtkentry->connect_after('changed'array(&$this,'_textChanged'),$k,$v);
  151.                 if ($type == 'password')
  152.                     $gtkentry->set_visibility(FALSE);
  153.                 $gtkentry->show();
  154.                 $gtktable->attach($gtkentry12$r$r+1GTK_FILL|GTK_EXPAND,GTK_FILL);
  155.                 break;
  156.             case 'directory':    
  157.                 $gtkentry &new GtkEntry();
  158.                 $gtkentry->set_text($v);
  159.                 $gtkentry->set_editable(FALSE);
  160.                 $gtkentry->connect_object_after('enter_notify_event',
  161.                     array(&$this,'_setConfigHelp'),$this->ui->config->getDocs($k));
  162.                 // store in object data the configuration tag
  163.                 $gtkentry->set_data('key',$k);
  164.                 $gtkentry->show();
  165.                 $gtktable->attach($gtkentry12$r$r+1GTK_FILL|GTK_EXPAND,GTK_FILL);
  166.                 $gtkbutton &new GtkButton('...');
  167.                 $gtkbutton->connect_object_after('clicked'array(&$this->ui->_dirselect,'onDirSelect'),$gtkentry,$k);
  168.                 $gtkbutton->show();
  169.                 $gtktable->attach($gtkbutton23$r$r+1GTK_SHRINK,GTK_SHRINK);
  170.                 break;
  171.             case 'set':
  172.                 $options $this->ui->config->getSetValues($k);
  173.                 $gtkmenu &new GtkMenu();
  174.                 $items = array();
  175.                 $sel = 0;
  176.                 foreach($options as $i=>$option{
  177.                     $items[$i&new GtkMenuItem($option);
  178.                     $items[$i]->connect_object_after('activate'array(&$this'_optionSelect'),$k,$option$v);
  179.                     $gtkmenu->append($items[$i]);
  180.                     if ($option == $v
  181.                         $sel $i;
  182.                 }
  183.                 $gtkmenu->set_active($sel);
  184.                 $gtkmenu->show_all();
  185.                 $gtkoptionmenu &new GtkOptionMenu();
  186.                 $gtkoptionmenu->set_menu($gtkmenu);
  187.                 $gtkoptionmenu->connect_object_after('enter_notify_event',
  188.                     array(&$this,'_setConfigHelp'),$this->ui->config->getDocs($k));
  189.                 
  190.                 $gtkoptionmenu->show();
  191.                 $gtktable->attach($gtkoptionmenu12$r$r+1GTK_FILL|GTK_EXPAND,GTK_FILL);
  192.                 break;
  193.             // debug: shourd  really be 
  194.             case 'integer'// debug : should really be a set?
  195.                 $gtkadj &new GtkAdjustment((double) $v0.03.01.01.00.0);
  196.                 $gtkspinbutton &new GtkSpinButton($gtkadj);
  197.                 $gtkspinbutton->show();
  198.                 $gtkspinbutton->connect_object_after('enter_notify_event',
  199.                     array(&$this,'_setConfigHelp'),$this->ui->config->getDocs($k));
  200.                 $gtkspinbutton->connect_after('changed'array(&$this,'_SpinChanged'),$k,$v);
  201.                
  202.                 $gtktable->attach($gtkspinbutton12$r$r+1GTK_FILL|GTK_EXPAND,GTK_FILL);
  203.                 break;
  204.                 
  205.             case 'mask'// unix file mask -- a table with lots of checkboxes...
  206.                  ;
  207.                 $gtklabel->set_alignment(0.00.1);
  208.                 $masktable =  &new GtkTable();
  209.                 $masktable->set_row_spacings(0);
  210.                 $masktable->set_col_spacings(10);
  211.                 $masktable->set_border_width(0);
  212.                 $masktable->show();
  213.                 $rows = array('User','Group','Everybody');
  214.                 $cols = array('Read','Write','Execute');
  215.                 $mult = 64;
  216.                 foreach($rows as $i=>$string{
  217.                     
  218.                     $label &new GtkLabel($string);
  219.                     $label->set_justify(GTK_JUSTIFY_LEFT);
  220.                     $label->set_alignment(0.00.5);
  221.                     $label->show();
  222.                     $masktable->attach($label01$i$i+1GTK_FILL|GTK_EXPAND,GTK_FILL);
  223.                     $add =4;
  224.                     foreach($cols as $j=>$string{
  225.                         
  226.                         if ($i$string ''// first row show text only!
  227.                         $gtkcheckbutton = new GtkCheckButton($string);
  228.                         if (($mult $add$v$gtkcheckbutton->set_active(TRUE);
  229.                         $gtkcheckbutton->show();
  230.                         $gtkcheckbutton->connect_object_after('enter_notify_event',
  231.                             array(&$this,'_setConfigHelp'),$this->ui->config->getDocs($k));
  232.                         $gtkcheckbutton->connect_after('toggled',array(&$this,'_maskToggled'),$k,$mult $add,$v);
  233.                         $masktable->attach($gtkcheckbutton $j+1$j+2$i$i+1GTK_FILL|GTK_EXPAND,GTK_FILL);
  234.                         $add $add/2;
  235.                     }
  236.                     $mult $mult/8;
  237.                 }
  238.                 
  239.                 
  240.                 $gtktable->attach($masktable12$r$r+1GTK_FILL|GTK_EXPAND,GTK_FILL);
  241.                 break;
  242.             default:
  243.                 echo "$prompt : ". $this->ui->config->getType($k"\n";    
  244.         }
  245.         
  246.     }
  247.     
  248.     /**
  249.     * Show the help text for a widget
  250.     *
  251.     * @param  object gtkevent            name of group tab
  252.     * @param  string                     help text
  253.     */
  254.     function _setConfigHelp($event,$string{
  255.         $this->help->set_text($string);
  256.     }
  257.     /**
  258.     * The GtkTables relating to the groups
  259.     *
  260.     * @var array  associative array of groupname -> gtktable
  261.     * @access private
  262.     */
  263.     var $_configTabs = array()// associative array of configGroup -> GtkTable
  264.     /**
  265.     * Get (or Make) A 'Group' Config Tab on the config notebook
  266.     *
  267.     * @param  string            name of group tab
  268.     * @param  string            no idea yet!
  269.     * @return object GtkTable   table which config elements are added to.
  270.     */
  271.     function &_getConfigTab($group{
  272.         if (@$this->_configTabs[$group]
  273.             return $this->_configTabs[$group];
  274.         $this->_configTabs[$group&new GtkTable();
  275.         $this->_configTabs[$group]->set_row_spacings(10);
  276.         $this->_configTabs[$group]->set_col_spacings(10);
  277.         $this->_configTabs[$group]->set_border_width(15);
  278.         $this->_configTabs[$group]->show();
  279.         $gtklabel &new GtkLabel($group);
  280.  
  281.         $gtklabel->show();
  282.         $this->notebook->append_page($this->_configTabs[$group],$gtklabel);
  283.         return $this->_configTabs[$group];
  284.     }
  285.    
  286.     
  287.     
  288.     function _textChanged($widget,$key,$original{
  289.         $this->NewConfig[$key]  $widget->get_text();
  290.         if ($this->NewConfig[$key]  == $original
  291.             unset($this->NewConfig[$key);
  292.         
  293.         $this->ActivateConfigSave();
  294.         
  295.     }
  296.     
  297.      function _optionSelect($key,$value,$original{
  298.         $this->NewConfig[$key]  $value;
  299.         if ($this->NewConfig[$key]  == $original
  300.             unset($this->NewConfig[$key);
  301.         
  302.         $this->ActivateConfigSave();
  303.         
  304.     }
  305.     function _spinChanged($widget,$key,$original{
  306.         $this->NewConfig[$key]  $widget->get_value_as_int();
  307.         if ($this->NewConfig[$key]  == $original
  308.             unset($this->NewConfig[$key);
  309.         
  310.         $this->ActivateConfigSave();
  311.         
  312.     }
  313.     function _maskToggled($widget,$key,$value,$original{
  314.         if (!@$this->NewConfig[$key]$this->NewConfig[$key$original;
  315.         // set:
  316.         if ($widget->get_active()) {
  317.             if (!($value $this->NewConfig[$key])) $this->NewConfig[$key+= $value;
  318.         else // unset
  319.             if ($value $this->NewConfig[$key]$this->NewConfig[$key-= $value;
  320.         }
  321.         if ($this->NewConfig[$key]  == $original
  322.             unset($this->NewConfig[$key);
  323.         $this->ActivateConfigSave();
  324.     }    
  325.     
  326.     
  327.     
  328.     /**
  329.     * Make the Save and reset buttons pressable.
  330.     *
  331.     */
  332.     function ActivateConfigSave({
  333.         $set = TRUE;
  334.         if (!$this->NewConfig$set = FALSE;
  335.         $this->save->set_sensitive($set)
  336.         $this->reset->set_sensitive($set);
  337.     }
  338.     
  339.     function saveConfig({
  340.         
  341.         //mmh now what :)
  342.         $cmd = PEAR_Command::factory('config-set',$this->ui->config);
  343.         foreach ($this->NewConfig as $k=>$v
  344.             $cmd->doConfigSet('config-set' ,''array($k,$v));
  345.         $this->loadConfig();
  346.     
  347.     }
  348.     
  349. }
  350. ?>

Documentation generated on Mon, 11 Mar 2019 14:28:56 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.