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

Source for file ChannelDialog.php

Documentation is available at ChannelDialog.php

  1. <?php
  2. /**
  3. *   Channel list with buttons to add and remove
  4. *   channels
  5. *
  6. *   @author Christian Weiske <cweiske@php.net>
  7. */
  8. class PEAR_Frontend_Gtk2_ChannelDialog
  9. {
  10.     /**
  11.     *   The widgets which shall be loaded from the glade
  12.     *   file into the $arWidgets array
  13.     *   @var array 
  14.     */
  15.     protected static $arRequestedWidgets = array(
  16.         'dlgChannels''lstChannels''btnClose''btnAdd',
  17.         'btnUpdate''btnDelete'
  18.     );
  19.  
  20.     /**
  21.     *   Requested widgets are loaded from glade into this array.
  22.     *   So this is an associative array with all required widgets
  23.     *   from the glade file: name => widget object
  24.     *   @var array 
  25.     */
  26.     protected $arWidgets;
  27.  
  28.     /**
  29.     *   The PEAR channels command object
  30.     *   @var PEAR_Command_Channels 
  31.     */
  32.     protected $channels;
  33.  
  34.     /**
  35.     *   The pear gtk2 frontend object
  36.     *   @var PEAR_Frontend_Gtk2 
  37.     */
  38.     protected $frontend;
  39.  
  40.  
  41.  
  42.     /**
  43.     *   Initialize the dialog
  44.     *
  45.     *   @param GladeXML             $glade      The glade to load the widgets from
  46.     *   @param PEAR_Frontend_Gtk2   $frontend   The gtk2 frontend object
  47.     */
  48.     public function __construct(GladeXML $gladePEAR_Frontend_Gtk2 $frontend)
  49.     {
  50.         $this->frontend $frontend;
  51.         $this->buildDialog($glade);
  52.     }//public function __construct(GladeXML $glade, PEAR_Frontend_Gtk2 $frontend)
  53.  
  54.  
  55.  
  56.     protected function buildDialog(GladeXML $glade)
  57.     {
  58.         foreach (self::$arRequestedWidgets as $strWidgetName{
  59.             $this->arWidgets[$strWidgetName$glade->get_widget($strWidgetName);
  60.         }
  61.         $model = new GtkListStore(Gtk::TYPE_STRINGGtk::TYPE_STRINGGtk::TYPE_STRING);
  62.         $this->arWidgets['lstChannels']->set_model($model);
  63.  
  64.         $cell_renderer = new GtkCellRendererText();
  65.  
  66.         $colName = new GtkTreeViewColumn('Channel'$cell_renderer"text"0);
  67.         $colName->set_resizable(true);
  68.         $colName->set_sort_column_id(0);
  69.         $this->arWidgets['lstChannels']->append_column($colName);
  70.  
  71.         $colAlias = new GtkTreeViewColumn('Alias'$cell_renderer"text"1);
  72.         $colAlias->set_resizable(true);
  73.         $colAlias->set_sort_column_id(1);
  74.         $this->arWidgets['lstChannels']->append_column($colAlias);
  75.  
  76.         $colSummary = new GtkTreeViewColumn('Summary'$cell_renderer"text"2);
  77.         $colSummary->set_resizable(true);
  78.         $colSummary->set_sort_column_id(2);
  79.         $this->arWidgets['lstChannels']->append_column($colSummary);
  80.  
  81.         $selection $this->arWidgets['lstChannels']->get_selection();
  82.         $selection->connect('changed'array($this'onSelectionChanged'));
  83.  
  84.         $this->arWidgets['btnClose'->connect_simple('clicked'array($this'onClose'));
  85.         $this->arWidgets['btnAdd']   ->connect_simple('clicked'array($this'onAdd'));
  86.         $this->arWidgets['btnUpdate']->connect_simple('clicked'array($this'onUpdate'));
  87.         $this->arWidgets['btnDelete']->connect_simple('clicked'array($this'onDelete'));
  88.     }//protected function buildDialog(GladeXML $glade)
  89.  
  90.  
  91.  
  92.     public function show()
  93.     {
  94.         $this->loadChannels();
  95.         $this->arWidgets['dlgChannels']->show();
  96.     }//public function show()
  97.  
  98.  
  99.  
  100.     /**
  101.     *   The close button has been pressed -> just the dialog only
  102.     */
  103.     public function onClose()
  104.     {
  105.         $this->arWidgets['dlgChannels']->hide();
  106.     }//public function onClose()
  107.  
  108.  
  109.  
  110.     /**
  111.     *   The add button has been pressed
  112.     */
  113.     public function onAdd()
  114.     {
  115.         require_once 'Gtk2/EntryDialog.php';
  116.  
  117.         $id = new Gtk2_EntryDialog($this->arWidgets['dlgChannels'],
  118.             Gtk::DIALOG_MODALGtk::MESSAGE_QUESTION,
  119.             Gtk::BUTTONS_OK'Please type the channel url'''
  120.         );
  121.         $id->run();
  122.         $strUrl $id->getText();
  123.         $id->destroy();
  124.         if ($strUrl == '' || $strUrl === null{
  125.             return;
  126.         }
  127.  
  128.         $this->frontend->getInstaller()->channelCommand('discover'$strUrl);
  129.         $this->reloadChannels();
  130.     }//public function onAdd()
  131.  
  132.  
  133.  
  134.     /**
  135.     *   The update button has been pressed
  136.     */
  137.     public function onUpdate()
  138.     {
  139.         $strChannel $this->getSelectedChannelName();
  140.         if ($strChannel === null{
  141.             return;
  142.         }
  143.         $this->frontend->getInstaller()->channelCommand('update'$strChannel);
  144.         $this->reloadChannels();
  145.     }//public function onUpdate()
  146.  
  147.  
  148.  
  149.     /**
  150.     *   The delete button has been pressed
  151.     */
  152.     public function onDelete()
  153.     {
  154.         $strChannel $this->getSelectedChannelName();
  155.         if ($strChannel === null{
  156.             return;
  157.         }
  158.  
  159.         $dialog = new GtkMessageDialog(
  160.             $this->arWidgets['dlgChannels']Gtk::DIALOG_MODALGtk::MESSAGE_QUESTION,
  161.             Gtk::BUTTONS_YES_NO'Do you want to remove channel "' $strChannel '"'
  162.         );
  163.         $answer $dialog->run();
  164.         $dialog->destroy();
  165.  
  166.         if ($answer== Gtk::RESPONSE_YES{
  167.             $this->frontend->getInstaller()->channelCommand('delete'$strChannel);
  168.             $this->reloadChannels();
  169.         }
  170.     }//public function onDelete()
  171.  
  172.  
  173.  
  174.     public function onSelectionChanged($selection)
  175.     {
  176.         $this->arWidgets['btnDelete']->set_sensitive($selection->count_selected_rows(> 0);
  177.         $this->arWidgets['btnUpdate']->set_sensitive($selection->count_selected_rows(> 0);
  178.     }//public function onSelectionChanged($selection)
  179.  
  180.  
  181.  
  182.     /**
  183.     *   Returns the name of the selected channel.
  184.     *
  185.     *   @return string  The name of the channel, or NULL if none is selected
  186.     */
  187.     protected function getSelectedChannelName()
  188.     {
  189.         $selection $this->arWidgets['lstChannels']->get_selection();
  190.         if ($selection->count_selected_rows(== 0{
  191.             return null;
  192.         }
  193.         list($model$iter$selection->get_selected();
  194.         return $model->get_value($iter0);
  195.     }//protected function getSelectedChannelName()
  196.  
  197.  
  198.  
  199.     /**
  200.     *   Loads the channel list from PEAR into the model.
  201.     */
  202.     protected function loadChannels()
  203.     {
  204.         $model $this->arWidgets['lstChannels']->get_model();
  205.         $model->clear();
  206.  
  207.         $arChannels = PEAR_Config::singleton()->getRegistry()->getChannels();
  208.         foreach ($arChannels as $nId => $channel{
  209.             $model->append(array(
  210.                 $channel->getName(),
  211.                 $channel->getAlias(),
  212.                 $channel->getSummary()
  213.             ));
  214.         }
  215.  
  216.         $this->onSelectionChanged($this->arWidgets['lstChannels']->get_selection());
  217.     }//protected function loadChannels()
  218.  
  219.  
  220.  
  221.     /**
  222.     *   Call this method if channels have changed.
  223.     *   (added, deleted, updated)
  224.     */
  225.     protected function reloadChannels()
  226.     {
  227.         $this->loadChannels();
  228.         $this->frontend->loadChannels();
  229.     }//protected function reloadChannels()
  230.  
  231.  
  232. }//class PEAR_Frontend_Gtk2_ChannelDialog
  233. ?>

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