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

Source for file Gtk.php

Documentation is available at Gtk.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: Gtk.php,v 1.20 2005/03/14 07:20:36 alan_k Exp $
  20. */
  21.  
  22. require_once "PEAR/Frontend.php";
  23. require_once "PEAR/Frontend/Gtk/Packages.php";
  24. require_once "PEAR/Frontend/Gtk/Summary.php";
  25. require_once "PEAR/Frontend/Gtk/Install.php";
  26. require_once "PEAR/Frontend/Gtk/Config.php";
  27. require_once "PEAR/Frontend/Gtk/DirSelect.php";
  28. require_once "PEAR/Frontend/Gtk/Info.php";
  29. require_once "PEAR/Frontend/Gtk/Documentation.php";
  30. /**
  31.  * Core Gtk Frontend Class
  32.  * All the real work is done in the child classes (Gtk/*.php)
  33.  *
  34.  * @author Alan Knowles <alan@akbkhome.com>
  35.  */
  36.  
  37. class PEAR_Frontend_Gtk extends PEAR_Frontend
  38. {
  39.     // {{{ properties
  40.  
  41.     /**
  42.      * What type of user interface this frontend is for.
  43.      * @var string 
  44.      * @access public
  45.      */
  46.     var $type 'Gtk';
  47.  
  48.     var $omode 'plain';
  49.     var $params = array();
  50.     
  51.     /**
  52.     * master glade object
  53.     * @var object GladeXML 
  54.     * @access private
  55.     */
  56.     var $_glade;
  57.     /**
  58.     * current config? - is this really neccessay - just use Config::singleton?
  59.     * @var object PEAR_Config 
  60.     * @access private
  61.     */
  62.     
  63.     var $config// object PEAR_Config
  64.     // }}}
  65.  
  66.     // {{{ constructor
  67.     /**
  68.     * Gtk Frontend Constructor
  69.     *
  70.     * Makes calls to load the glade file, and connect signals.
  71.     *
  72.     * @access private
  73.     */
  74.     
  75.     function PEAR_Frontend_Gtk()
  76.     {
  77.         parent::PEAR();
  78.         if (!extension_loaded('php_gtk')) {
  79.             dl('php_gtk.' (OS_WINDOWS ? 'dll' 'so'));
  80.         }
  81.         //echo "LOADED?";
  82.     }
  83.     // }}}
  84.     
  85.     function setConfig(&$config)
  86.     {
  87.         $this->config &$config;
  88.         $this->_summary      &new PEAR_Frontend_Gtk_Summary($this);
  89.         $this->_install      &new PEAR_Frontend_Gtk_Install($this);
  90.         $this->_packages     &new PEAR_Frontend_Gtk_Packages($this);
  91.         $this->_config       &new PEAR_Frontend_Gtk_Config($this);
  92.         $this->_dirselect    &new PEAR_Frontend_Gtk_DirSelect($this);
  93.         $this->_info         &new PEAR_Frontend_Gtk_Info($this);
  94.         $this->_documentation&new PEAR_Frontend_Gtk_Documentation($this);
  95.         $this->_loadGlade();
  96.         $this->_initInterface();
  97.     }
  98.  
  99.     /**
  100.     * Load the Glade file (and automake widget vars and connect signals)
  101.     *
  102.     * Loads the glade file and also maps all widgets 'NAME' in glade file
  103.     * to _widget_NAME
  104.     *
  105.     * Straight maps all handles to 'this object'
  106.     *
  107.     * #TODO  - base the widgets on 'documented/defined widgets in this file' rather than
  108.     * grepping the glade file...
  109.     *
  110.     * @access private
  111.     */ 
  112.     
  113.     function _loadGlade({
  114.         
  115.         $file dirname(__FILE__).'/Gtk/installer.glade';
  116.         if (!class_exists('GladeXML')) 
  117.             return PEAR::raiseError('Glade is currently required for the installer to work, please see php GTK install instructions for more information',null,PEAR_ERROR_DIE);
  118.          
  119.         $this->_glade &new GladeXML($file);
  120.         $data implode('',file($file));
  121.         preg_match_all('/\<name\>([^\<]+)\<\/name\>/',$data,$items);
  122.         foreach ($items[1as $widgetname{   
  123.             $args = array();
  124.             if (preg_match('/^(_install|_packages|_summary|_config|_dirselect|_info|_documentation)_(.*)$/',$widgetname,$args)) {
  125.                 $obj $args[1];
  126.                 $varname$args[2];
  127.                 //echo "ASSIGN $obj $varname to $widgetname\n";
  128.                 $this->$obj->$varname $this->_glade->get_widget($widgetname);
  129.                 continue;
  130.             }
  131.             $varname "_widget_".$widgetname;
  132.             $this->$varname $this->_glade->get_widget($widgetname);
  133.         }
  134.         $items = array();
  135.         preg_match_all('/\<handler\>([^\<]+)\<\/handler\>/',$data,$items)
  136.         //print_r($items[1]);
  137.         foreach ($items[1as $handler)  {
  138.             $args = array();
  139.             if (preg_match('/^(_install|_packages|_summary|_config|_dirselect|_info|_documentation)_(.*)$/',$handler,$args)) {
  140.                 $obj $args[1];
  141.                 $method$args[2];
  142.                 //echo "CONNECT $obj $method to $handler\n";
  143.                 if (!method_exists($this->$obj,$method)) 
  144.                     exit; // programming error!
  145.                 $this->_glade->signal_connect($handler ,array(&$this->$obj,$method));
  146.                 continue;
  147.             }
  148.             if (method_exists($this,$handler))
  149.                 $this->_glade->signal_connect$handler ,array(&$this,$handler));
  150.         }
  151.  
  152.         
  153.         
  154.     }
  155.     /**
  156.      * the class that manages the class list
  157.      * @var object PEAR_Frontend_Gtk_Packages 
  158.      * @access private
  159.      */
  160.     var $_packages
  161.     
  162.       /**
  163.      * the class that manages the Package summary
  164.      * @var object PEAR_Frontend_Gtk_Summray 
  165.      * @access private
  166.      */
  167.     var $_summary
  168.       /**
  169.      * the class manages package installation
  170.      * @var object PEAR_Frontend_Gtk_Install 
  171.      * @access private
  172.      */
  173.     var $_install
  174.  
  175.     /**
  176.      * the class manages directory selection
  177.      * @var object PEAR_Frontend_Gtk_DirSelect 
  178.      * @access private
  179.      */
  180.     var $_dirselect
  181.     
  182.      /**
  183.      * the class manages simple info prompts
  184.      * @var object PEAR_Frontend_Gtk_Info 
  185.      * @access private
  186.      */
  187.     var $_info
  188.     
  189.     /**
  190.     * Load and initialize the sub modules
  191.     *
  192.     * @access private
  193.     */ 
  194.     
  195.     
  196.     function _initInterface({
  197.         // must be a better way - still needs to read -c -C optss
  198.         // initialize child objects
  199.       
  200.         $this->_widget_window->connect_after('realize',array(&$this,'_callbackWindowConfigure'));
  201.         $this->_widget_window->connect_after('configure_event',array(&$this,'_callbackWindowConfigure'));
  202.  
  203.         $this->_widget_details_area->hide();
  204.         $this->_widget_window->show();
  205.     
  206.     }
  207.     /**
  208.     * has the window been configured (eg. pixmaps loaded etc.)
  209.     * @var boolean 
  210.     * @access private
  211.     */
  212.     var $_windowConfiguredFlag = FALSE;
  213.       
  214.     /**
  215.     * Set up images, styles etc.
  216.     *
  217.     * @param object gtkwindow 
  218.     * @access private
  219.     */ 
  220.     function _callbackWindowConfigure($window{
  221.         // must be a better way - still needs to read -c -C optss
  222.         
  223.         
  224.         $this->_initPixmaps($window);
  225.         
  226.         if ($this->_windowConfiguredFlagreturn;
  227.         $this->_windowConfiguredFlag = TRUE;
  228.         /* main package selection tab */
  229.         $this->_setStyle('nav_bar','','#7b7d7a',FALSE);
  230.     
  231.         $this->_setStyle('pear_installer_button','#000000','#7b7d7a');
  232.         $this->_setStyle('config_button','#000000','#7b7d7a');
  233.         $this->_setStyle('documentation_button','#000000','#7b7d7a');
  234.         
  235.         /* package stuff */
  236.          
  237.         $this->_packages->loadPackageList();
  238.         
  239.         $this->_setStyle('black_bg1','#FFFFFF','#000000',FALSE);
  240.         $this->_setStyle('black_bg2','#FFFFFF','#000000',FALSE);
  241.         $this->_setStyle('black_bg3','#FFFFFF','#000000',FALSE);
  242.         $this->_setStyle('black_bg4','#FFFFFF','#000000',TRUE);
  243.         
  244.         //$this->_setStyle('download_list','#000000','#FFFFFF',TRUE);
  245.         
  246.         //$this->_widget_close_details->set_style($newstyle);
  247.         $this->_setStyle('close_details','#FFFFFF','#000000',FALSE);
  248.         $this->_loadButton('close_details' ,        'black_close_icon.xpm',TRUE);
  249.         
  250.         
  251.          
  252.         
  253.         // sort out the text.
  254.         $this->_setStyle('summary'   ,'#FFFFFF','#000000',TRUE);
  255.         $this->_setFont('summary','-*-helvetica-bold-r-normal-*-*-80-*-*-p-*-iso8859-1')
  256.         
  257.         $this->_setStyle('black_msg1','#FFFFFF','#000000',FALSE);
  258.         
  259.         $newstyle &new GtkStyle();
  260.         $this->_widget_packages_install->set_style($newstyle);
  261.         
  262.         $this->_loadButton('pear_installer_button' ,'nav_installer.xpm');
  263.         $this->_loadButton('config_button' ,        'nav_configuration.xpm');
  264.         $this->_loadButton('documentation_button' 'nav_documentation.xpm');
  265.         
  266.         //$this->_setStyleWidget($pixmap,'#000000','#339900',FALSE);
  267.         
  268.         
  269.         $this->_setStyle('package_logo','#000000','#339900',TRUE);
  270.         $this->_setStyle('package_logo_text','#FFFFFF','#339900')
  271.         $this->_setFont('package_logo_text','-*-helvetica-bold-r-normal-*-*-100-*-*-p-*-iso8859-1')
  272.         
  273.          
  274.         
  275.         $package_logo &new GtkPixmap(
  276.             $this->_pixmaps['pear.xpm'][0],
  277.             $this->_pixmaps['pear.xpm'][1]);
  278.         $this->_widget_package_logo->put($package_logo,0,0);
  279.         $package_logo->show();
  280.         
  281.         
  282.         /* downloding tab */
  283.         $this->_setStyle('white_bg1','#000000','#FFFFFF',TRUE);
  284.         $download_icon  &new GtkPixmap(
  285.             $this->_pixmaps['downloading_image.xpm'][0],
  286.             $this->_pixmaps['downloading_image.xpm'][1]);
  287.         $this->_widget_white_bg1->put($download_icon,0,0);
  288.         $download_icon->show();
  289.         $this->_setStyle('downloading_logo','#000000','#339900',TRUE);
  290.         $this->_setStyle('downloading_logo_text','#FFFFFF','#339900')
  291.         $this->_setFont('downloading_logo_text','-*-helvetica-bold-r-normal-*-*-100-*-*-p-*-iso8859-1')
  292.         $this->_widget_downloading_logo_text->set_justifyGTK_JUSTIFY_LEFT );
  293.         $installer_logo &new GtkPixmap(
  294.             $this->_pixmaps['pear.xpm'][0],
  295.             $this->_pixmaps['pear.xpm'][1]);
  296.         $this->_widget_downloading_logo->put($installer_logo,0,0);
  297.         $installer_logo->show();
  298.         
  299.         /* configuration loading */
  300.         
  301.         $this->_config->loadConfig();
  302.        
  303.         $this->_setStyle('config_logo','#000000','#339900',TRUE);
  304.         $this->_setStyle('config_logo_text','#FFFFFF','#339900')
  305.         $this->_setFont('config_logo_text','-*-helvetica-bold-r-normal-*-*-100-*-*-p-*-iso8859-1')
  306.         $config_logo &new GtkPixmap(
  307.             $this->_pixmaps['pear.xpm'][0],
  308.             $this->_pixmaps['pear.xpm'][1]);
  309.         
  310.         $this->_widget_config_logo->put($config_logo,0,0);
  311.         $config_logo->show();
  312.         
  313.         
  314.         /* documentation loading */
  315.         $this->_setStyle('documentation_logo','#000000','#339900',TRUE);
  316.         $this->_setStyle('documentation_logo_text','#FFFFFF','#339900')
  317.         $this->_setFont('documentation_logo_text','-*-helvetica-bold-r-normal-*-*-100-*-*-p-*-iso8859-1')
  318.         $documentation_logo &new GtkPixmap(
  319.             $this->_pixmaps['pear.xpm'][0],
  320.             $this->_pixmaps['pear.xpm'][1]);
  321.         
  322.         $this->_widget_documentation_logo->put($documentation_logo,0,0);
  323.         $documentation_logo->show();
  324.         $this->_documentation->init();
  325.         $this->_setStyle('documentation_view_label'   ,'#FFFFFF','#000000',TRUE);
  326.         $this->_setFont('documentation_view_label','-*-helvetica-bold-r-normal-*-*-80-*-*-p-*-iso8859-1')
  327.         $this->_setStyle('documentation_package_label'   ,'#FFFFFF','#000000',TRUE);
  328.         $this->_setFont('documentation_package_label','-*-helvetica-bold-r-normal-*-*-80-*-*-p-*-iso8859-1')
  329.         
  330.          
  331.     }
  332.    /**
  333.     * Set up images, styles etc.
  334.     * Load an image into a button as glade does not support this!
  335.     *
  336.     * @param string widget name
  337.     * @param string  icon name
  338.     * @param boolean relief - the left menu is FALSE, other buttons are TRUE
  339.     * @access private
  340.     */ 
  341.     
  342.     function &_loadButton($widgetname$icon$relief=FALSE{
  343.         //echo $widgetname;
  344.         $widget_fullname "_widget_"$widgetname;
  345.         $widget &$this->$widget_fullname;
  346.         
  347.         $child $widget->child;
  348.         //if ($child)
  349.         //    if (get_class($child) == "GtkVBox") return;
  350.         if (!$relief
  351.             $widget->set_relief(GTK_RELIEF_NONE);
  352.           
  353.         //$widget->set_usize(150,100);
  354.         $vbox = new GtkVBox; 
  355.         
  356.       // this stuff only gets done once
  357.         if ($child)
  358.             $widget->remove($child);
  359.         $pixmap &new GtkPixmap($this->_pixmaps[$icon][0],$this->_pixmaps[$icon][1]);
  360.         $vbox->pack_start$pixmaptrue  true  2);
  361.         if ($child)
  362.             $vbox->pack_end($child,true,true,2);
  363.         $widget->add($vbox);
  364.         //$widget->set_usize(150,100);
  365.         $vbox->show();
  366.         $pixmap->show();
  367.         return $vbox;
  368.      
  369.     }
  370.     
  371.     /**
  372.     * Funky routine to set the style(colours) of Gtkwidgets
  373.     * 
  374.     *
  375.     * @param string widget name
  376.     * @param string  foreground color
  377.     * @param string  background color
  378.     * @param booloean  Base style of (TRUE)existing or create a new style(FALSE)
  379.     * @access private
  380.     */ 
  381.     function _setStyle($widgetname,$fgcolor='',$bgcolor='',$copy=FALSE{
  382.         //echo "SET: $widgetname: $fgcolor/$bgcolor ". ((int) $copy) . "\n";
  383.         $widget_fullname "_widget_"$widgetname;
  384.       
  385.         $this->_setStyleWidget($this->$widget_fullname,$fgcolor,$bgcolor,$copy;
  386.     }
  387.     function _setStyleWidget(&$widget,$fgcolor='',$bgcolor='',$copy=FALSE{
  388.         if ($copy{
  389.             $oldstyle $widget->get_style();
  390.             $newstyle $oldstyle->copy();
  391.         else {
  392.             $newstyle &new GtkStyle();
  393.         }
  394.         if ($fgcolor// set foreground color
  395.             $fg &new GdkColor($fgcolor);
  396.             $newstyle->fg[GTK_STATE_PRELIGHT$fg;
  397.             $newstyle->fg[GTK_STATE_NORMAL$fg;
  398.             $newstyle->fg[GTK_STATE_ACTIVE$fg;
  399.             $newstyle->fg[GTK_STATE_SELECTED$fg;
  400.             $newstyle->fg[GTK_STATE_INSENSITIVE$fg;
  401.             //$newstyle->bg_pixmap=NULL;
  402.         }
  403.         if ($bgcolor// set background color
  404.  
  405.             $bg &new GdkColor($bgcolor);
  406.             $newstyle->bg[GTK_STATE_PRELIGHT$bg;
  407.             $newstyle->bg[GTK_STATE_NORMAL$bg;
  408.             $newstyle->bg[GTK_STATE_ACTIVE$bg;
  409.             $newstyle->bg[GTK_STATE_SELECTED$bg;
  410.             $newstyle->bg[GTK_STATE_INSENSITIVE$bg;
  411.             //$newstyle->bg_pixmap=NULL;
  412.         }
  413.         $widget->set_style($newstyle);
  414.     
  415.     
  416.     }
  417.     
  418.     function _setFont($widgetname,$fontname{
  419.         $font = gdk::font_load($fontname);
  420.         $widget_fullname "_widget_"$widgetname;
  421.         $widget &$this->$widget_fullname;
  422.         $oldstyle $widget->get_style();
  423.         $newstyle $oldstyle->copy();
  424.         $newstyle->font = $font;
  425.         $widget->set_style($newstyle);
  426.     }
  427.  
  428.     
  429.     /**
  430.     * All the pixmaps from the xpm directory
  431.     * @var boolean 
  432.     * @access private
  433.     */
  434.     var $_pixmaps = array()// associative array of filename -> pixmaps|mask array objects used by application
  435.     
  436.     /*
  437.     * initialize the pixmaps - load the into $this->_pixmaps[name][0|1]
  438.     *  
  439.     * @param object gtkwindow the window from the realize event.
  440.     */
  441.     function _initPixmaps(&$window{
  442.         
  443.         if ($this->_pixmapsreturn;
  444.         $dir dirname(__FILE__).'/Gtk/xpm';
  445.         $dh opendir($dir);
  446.         if (!$dhreturn;
  447.         while (($file readdir($dh)) !== FALSE{
  448.             if (@$file{0== '.'continue;
  449.             if (!preg_match('/\.xpm$/',$file)) continue;
  450.             //echo "loading {$dir}/{$file}";
  451.             $this->_pixmaps[$file=  
  452.                 Gdk::pixmap_create_from_xpm($window->windowNULL"{$dir}/{$file}");
  453.                 
  454.         }
  455.     }
  456.      
  457.   
  458.     /*
  459.     * Menu Callback - Exit/Quit
  460.     */
  461.     function _onQuit({
  462.         gtk::main_quit();
  463.         exit;
  464.     }
  465.     /*
  466.     * Left button callback - goto installer
  467.     */
  468.     function _callbackShowInstaller({
  469.         $this->_widget_pages->set_page(0);
  470.     }
  471.     /*
  472.     * Left button callback - goto config page
  473.     */
  474.     
  475.     function _callbackShowConfig({
  476.         $this->_widget_pages->set_page(2);
  477.     }
  478.     /*-------------------------------------Downloading --------------------------------*/
  479.      /*
  480.     * PEAR_Command Callback - used by downloader
  481.     * @param string message type
  482.     * @param string message data
  483.     */
  484.     
  485.     function _downloadCallback($msg,  $params{
  486.         $this->_install->_downloadCallback($msg,  $params);
  487.     }
  488.     
  489.      /*---------------- Dir Seleciton stuff -----------------------*/
  490.     
  491.    
  492.     
  493.     //-------------------------- BASE Installer methods --------------------------
  494.      /**
  495.     * Callback from command API, that sends data back from config-show
  496.     *
  497.     * @param   mixed data requeted by another part of this program
  498.     * @param   string the command that was sent to result in this
  499.     *
  500.     */
  501.     function outputData($data,$command=''){
  502.         switch ($command{
  503.             case 'config-show':
  504.                 $this->_config->buildConfig($data['data'])
  505.                 break;
  506.             case 'uninstall':
  507.                 $this->_install->uninstallOutputData($data);
  508.                 return;
  509.             default:
  510.                 $this->_info->show($data['data']);
  511.                 //echo "COMMAND : $command\n";
  512.                 //echo "DATA: ".print_r($data,true)."\n";
  513.         }
  514.     }
  515.  
  516.     function log($msg,$command=''{
  517.         
  518.         return $this->_info->show("LOG: $msg$command");
  519.     }
  520.  
  521.     // {{{ displayLine(text)
  522.  
  523.     function displayLine($msg,$args)
  524.     {
  525.        return $this->_info->show("DISPLAYLINE: $msg$args");
  526.     }
  527.  
  528.     function display($text,$command='')
  529.     {
  530.      return $this->_info->show("TEXT: $text$command");
  531.     }
  532.  
  533.     // }}}
  534.     // {{{ displayError(eobj)
  535.  
  536.     function displayError($eobj)
  537.     {
  538.         //echo "ERROR: ".$eobj->getMessage();
  539.         return $this->_info->show("ERROR: "$eobj->getMessage())
  540.         
  541.     }
  542.  
  543.     // }}}
  544.     // {{{ displayFatalError(eobj)
  545.  
  546.     function displayFatalError($eobj)
  547.     {
  548.           if (!$this->_info{
  549.           echo "FATAL ERROR: "$eobj->getMessage();
  550.         exit;
  551.       }
  552.       return $this->_info->show("FATAL ERROR: "$eobj->getMessage())
  553.         //exit(1);
  554.     }
  555.  
  556.     // }}}
  557.     // {{{ displayHeading(title)
  558.  
  559.     function displayHeading($title)
  560.     {
  561.     }
  562.  
  563.     // }}}
  564.     // {{{ userDialog(prompt, [type], [default])
  565.  
  566.     function userDialog($prompt$type 'text'$default '')
  567.     {
  568.         
  569.         echo "Dialog?" $prompt;
  570.     }
  571.  
  572.     // }}}
  573.     // {{{ userConfirm(prompt, [default])
  574.  
  575.     function userConfirm($prompt$default 'yes')
  576.     {
  577.           echo "\nConfirm?" $prompt;
  578.     }
  579.  
  580.     // }}}
  581.     // {{{ startTable([params])
  582.  
  583.     function startTable($params = array())
  584.     {
  585.     }
  586.  
  587.     // }}}
  588.     // {{{ tableRow(columns, [rowparams], [colparams])
  589.  
  590.     function tableRow($columns$rowparams = array()$colparams = array())
  591.     {
  592.     }
  593.  
  594.     // }}}
  595.     // {{{ endTable()
  596.  
  597.     function endTable()
  598.     {
  599.     }
  600.  
  601.     // }}}
  602.     // {{{ bold($text)
  603.  
  604.     function bold($text)
  605.     {
  606.     echo "\nBOLD?" $prompt;
  607.     }
  608.  
  609.     // }}}
  610. }
  611.  
  612. ?>

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