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

Source for file Packages.php

Documentation is available at Packages.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: Packages.php,v 1.16 2005/02/01 15:26:01 cellog Exp $
  20. */
  21. require('PEAR/Frontend/Gtk/PackageData.php');
  22. /**
  23.  * Gtk Frontend - Section that deals with package lists
  24.  *
  25.  * @author Alan Knowles <alan@akbkhome.com>
  26.  */
  27.  
  28.  
  29. class PEAR_Frontend_Gtk_Packages {
  30.  
  31.     var $ui// main interface
  32.     var $widget// the list widget
  33.     var $config// reference to config;
  34.     
  35.     
  36.     function PEAR_Frontend_Gtk_Packages(&$ui{
  37.         $this->ui &$ui;
  38.         $this->_loadLocalPackages();
  39.         $this->_loadRemotePackages();
  40.         $this->_mergePackages();
  41.     }
  42.     
  43.               
  44.     
  45.      
  46.     
  47.     /*
  48.     * call back when a row is pressed - hide/show the details and check it's isntalled status
  49.     *  
  50.     */
  51.     function callbackSelectRow($widget,$node,$col{
  52.         //echo "GOT CALLBACK?";
  53.         $package $this->widget->node_get_row_data($node);
  54.         if (!$packagereturn;
  55.         
  56.         switch ($col{
  57.          
  58.             case 1:
  59.                 $this->ui->_summary->hide();
  60.                 $this->packages[$package]->toggleRemove();
  61.                 break;
  62.             case 0:
  63.             case 2: // install/ toggled
  64.                 $this->ui->_summary->hide();
  65.                 $this->packages[$package]->toggleInstall();
  66.                 break;
  67.             case 3: // info selected
  68.                 if (!$package)  {
  69.                     $this->ui->_summary->hide();
  70.                     return;
  71.                 
  72.                  
  73.                 $this->ui->_summary->toggle($this->packages[$package]);
  74.                 break;
  75.             case -1: // startup!
  76.                 return;
  77.             default:
  78.                 $this->ui->_summary->hide();
  79.                 break;
  80.         }
  81.         $packages $this->getQueue();
  82.          $this->ui->_widget_packages_install->set_sensitive(0);
  83.         if ($packages)  $this->ui->_widget_packages_install->set_sensitive(1);
  84.         
  85.     }
  86.      
  87.      
  88.       /*
  89.     * Menu Callback - expand all
  90.     */
  91.     function expandAll({
  92.         $this->widget->expand_recursive();
  93.     }
  94.     /*
  95.     * Menu Callback - colllapse all
  96.     */
  97.     function collapseAll({
  98.         $this->widget->collapse_recursive();
  99.     }
  100.     
  101.     var $_remotePackageCache;  // array of remote packages.
  102.     var $_localPackageCache;   // array of local packages
  103.     var $packages;              // associative array of packagename : package
  104.     
  105.     
  106.     
  107.     /*
  108.     * Load the local packages into this->_localPackageCache
  109.     *  
  110.     */
  111.     function _loadLocalPackages ({
  112.         clearstatcache();
  113.         $reg &$this->ui->config->getRegistry();
  114.         $installed $reg->packageInfo();
  115.         $this->_localPackageCache = array();
  116.         foreach($installed as $packagear{
  117.             $package = PEAR_Frontend_Gtk_PackageData::staticNewFromArray($packagear);
  118.             $this->_localPackageCache[$package;
  119.         }
  120.         
  121.     }
  122.     /*
  123.     * Load the remote packages into this->_remotePackageCache
  124.     *  
  125.     */
  126.     function _loadRemotePackages ({
  127.         $r = new PEAR_Remote($this->ui->config);
  128.         $options = false;
  129.         if ($this->ui->config->get('preferred_state'== 'stable')
  130.             $options = true;
  131.         $remote $r->call('package.listAll'$options$optionstrue);
  132.         if (PEAR::isError($remote)) {
  133.             $this->ui->displayFatalError($remote);
  134.             return;
  135.         }
  136.         foreach ($remote as  $name => $packagear{
  137.             $package = PEAR_Frontend_Gtk_PackageData::staticNewFromArray($packagear);
  138.             $package->name = $name;
  139.             $this->_remotePackageCache[$package;
  140.         }
  141.         
  142.     }
  143.     /*
  144.     * Add local and remote together and store in this->packages
  145.     * Not: remembers installation status.
  146.     */
  147.     function _mergePackages (// builds a mreged package list
  148.         // start with remote list.
  149.         
  150.         //if (!$this->packages)
  151.         foreach ($this->_remotePackageCache as $package
  152.             $this->packages[$package->name$package;
  153.      
  154.         // merge local.    
  155.         foreach ($this->_localPackageCache as  $package{
  156.             if (@$this->packages[$package->name]{
  157.                 $this->packages[$package->name]->merge($package);
  158.             else {
  159.                 $this->packages[$package->name$package;
  160.             }
  161.             $this->packages[$package->name]->isInstalled = TRUE;
  162.         }
  163.         //merge existing status stuff..
  164.         /*if ($this->packages) 
  165.             foreach ($this->packages as $name=>$package) {
  166.                 $this->packages[$name]->QueueInstall = $package->QueueInstall;
  167.                 $this->packages[$name]->QueueRemove = $package->QueueRemove;
  168.             }
  169.          */
  170.         ksort($this->packages);
  171.         
  172.     }
  173.     
  174.     /*
  175.     * Reset the Queues on all objects
  176.     */
  177.     function resetQueue({
  178.         foreach(array_keys($this->packagesas $packagename{
  179.             $this->packages[$packagename]->QueueInstall = FALSE;
  180.             $this->packages[$packagename]->QueueRemove = FALSE;
  181.         }
  182.     }
  183.     /*
  184.     * Get the List of packages to install
  185.     *
  186.     *@return array  array of PackageData objects
  187.     */
  188.     function &getQueue({
  189.         $ret = array();
  190.         foreach(array_keys($this->packagesas $packagename{
  191.             if ($this->packages[$packagename]->QueueInstall
  192.                 $ret[&$this->packages[$packagename];
  193.         }
  194.         foreach(array_keys($this->packagesas $packagename{
  195.             if ($this->packages[$packagename]->QueueRemove
  196.                 $ret[&$this->packages[$packagename];
  197.         }
  198.         return $ret;
  199.     }
  200.     /*
  201.     * Get the Packages to Remove.
  202.     *
  203.     *@return array  array of PackageData objects
  204.     */
  205.     
  206.     
  207.     /*
  208.     * Nodes in a CTreeNodes
  209.     *
  210.     * @var array of Category Nodes
  211.     *
  212.     */
  213.     var $_categoryNodes = array();
  214.     
  215.     /*
  216.     * Load the package list into the clist.
  217.     *
  218.     *@return array  array of PackageData objects
  219.     */
  220.     function loadPackageList({
  221.         $this->ui->_widget_packages_install->set_sensitive(0);
  222.         $this->widget->set_row_height(18);
  223.         $this->widget->set_expander_style(GTK_CTREE_EXPANDER_TRIANGLE);
  224.         $this->widget->set_line_styleGTK_CTREE_LINES_NONE);
  225.      
  226.         for($i=0;$i<4;$i++)
  227.             $this->widget->set_column_auto_resize($i,TRUE);
  228.         
  229.         //while(gtk::events_pending()) gtk::main_iteration();
  230.         $this->widget->clear();
  231.         $this->widget->freeze();
  232.         $this->_categoryNodes = array();
  233.         foreach (array_keys($this->packagesas $packagename{
  234.              
  235.             $package &$this->packages[$packagename];
  236.             $parent $this->_getCategoryNode($package);
  237.             //echo serialize($parent);
  238.             $package->ui = &$this->ui;
  239.             $package->createNode($parent);
  240.         }
  241.         $this->widget->thaw();
  242.       
  243.     }
  244.     /*
  245.     * Load the package list into the clist.
  246.     *
  247.     *@return array  array of PackageData objects
  248.     */
  249.     function &_getCategoryNode(&$package{
  250.         $ret = NULL;
  251.         
  252.         // work out category if it does not exist!!!!
  253.         $category $package->name;
  254.         $parts explode('_',$package->name);
  255.         if ($parts[0])
  256.             $category $parts[0];
  257.         $categoryName $category;
  258.         if ($package->category)  
  259.             $categoryName $package->category;
  260.         
  261.         
  262.         //echo "GOT: {$package->name}:$categoryName:$category:\n";
  263.         
  264.         
  265.         if ($category == $package->name
  266.             return $ret;
  267.             
  268.         if (@$this->_categoryNodes[$category]
  269.             return $this->_categoryNodes[$category];
  270.         
  271.         if (@$this->packages[$category])
  272.             return $this->packages[$category]->gtknode;
  273.             
  274.             
  275.         $this->_categoryNodes[$category$this->widget->insert_node(
  276.             NULLNULL//parent, sibling
  277.             array($categoryName'','',''),5
  278.             $this->ui->_pixmaps['folder_closed.xpm'][0],
  279.             $this->ui->_pixmaps['folder_closed.xpm'][1],  
  280.             $this->ui->_pixmaps['folder_open.xpm'][0],
  281.             $this->ui->_pixmaps['folder_open.xpm'][1],
  282.             false,true
  283.         )
  284.                
  285.         return $this->_categoryNodes[$category];
  286.         
  287.     }
  288.     
  289.     
  290. }
  291. ?>

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