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(
  62.             Gobject::TYPE_STRINGGobject::TYPE_STRINGGobject::TYPE_STRING
  63.         );
  64.         $this->arWidgets['lstChannels']->set_model($model);
  65.  
  66.         $cell_renderer = new GtkCellRendererText();
  67.  
  68.         $colName = new GtkTreeViewColumn('Channel'$cell_renderer"text"0);
  69.         $colName->set_resizable(true);
  70.         $colName->set_sort_column_id(0);
  71.         $this->arWidgets['lstChannels']->append_column($colName);
  72.  
  73.         $colAlias = new GtkTreeViewColumn('Alias'$cell_renderer"text"1);
  74.         $colAlias->set_resizable(true);
  75.         $colAlias->set_sort_column_id(1);
  76.         $this->arWidgets['lstChannels']->append_column($colAlias);
  77.  
  78.         $colSummary = new GtkTreeViewColumn('Summary'$cell_renderer"text"2);
  79.         $colSummary->set_resizable(true);
  80.         $colSummary->set_sort_column_id(2);
  81.         $this->arWidgets['lstChannels']->append_column($colSummary);
  82.  
  83.         $selection $this->arWidgets['lstChannels']->get_selection();
  84.         $selection->connect('changed'array($this'onSelectionChanged'));
  85.  
  86.         $this->arWidgets['btnClose'->connect_simple('clicked'array($this'onClose'));
  87.         $this->arWidgets['btnAdd']   ->connect_simple('clicked'array($this'onAdd'));
  88.         $this->arWidgets['btnUpdate']->connect_simple('clicked'array($this'onUpdate'));
  89.         $this->arWidgets['btnDelete']->connect_simple('clicked'array($this'onDelete'));
  90.     }//protected function buildDialog(GladeXML $glade)
  91.  
  92.  
  93.  
  94.     public function show()
  95.     {
  96.         $this->loadChannels();
  97.         $this->arWidgets['dlgChannels']->show();
  98.     }//public function show()
  99.  
  100.  
  101.  
  102.     /**
  103.     *   The close button has been pressed -> just the dialog only
  104.     */
  105.     public function onClose()
  106.     {
  107.         $this->arWidgets['dlgChannels']->hide();
  108.     }//public function onClose()
  109.  
  110.  
  111.  
  112.     /**
  113.     *   The add button has been pressed
  114.     */
  115.     public function onAdd()
  116.     {
  117.         require_once 'Gtk2/EntryDialog.php';
  118.  
  119.         $id = new Gtk2_EntryDialog($this->arWidgets['dlgChannels'],
  120.             Gtk::DIALOG_MODALGtk::MESSAGE_QUESTION,
  121.             Gtk::BUTTONS_OK'Please type the channel url'''
  122.         );
  123.         $id->run();
  124.         $strUrl $id->getText();
  125.         $id->destroy();
  126.         if ($strUrl == '' || $strUrl === null{
  127.             return;
  128.         }
  129.  
  130.         $this->frontend->getInstaller()->channelCommand('discover'$strUrl);
  131.         $this->reloadChannels();
  132.     }//public function onAdd()
  133.  
  134.  
  135.  
  136.     /**
  137.     *   The update button has been pressed
  138.     */
  139.     public function onUpdate()
  140.     {
  141.         $strChannel $this->getSelectedChannelName();
  142.         if ($strChannel === null{
  143.             return;
  144.         }
  145.         $this->frontend->getInstaller()->channelCommand('update'$strChannel);
  146.         $this->reloadChannels();
  147.     }//public function onUpdate()
  148.  
  149.  
  150.  
  151.     /**
  152.     *   The delete button has been pressed
  153.     */
  154.     public function onDelete()
  155.     {
  156.         $strChannel $this->getSelectedChannelName();
  157.         if ($strChannel === null{
  158.             return;
  159.         }
  160.  
  161.         $dialog = new GtkMessageDialog(
  162.             $this->arWidgets['dlgChannels']Gtk::DIALOG_MODALGtk::MESSAGE_QUESTION,
  163.             Gtk::BUTTONS_YES_NO'Do you want to remove channel "' $strChannel '"'
  164.         );
  165.         $answer $dialog->run();
  166.         $dialog->destroy();
  167.  
  168.         if ($answer== Gtk::RESPONSE_YES{
  169.             $this->frontend->getInstaller()->channelCommand('delete'$strChannel);
  170.             $this->reloadChannels();
  171.         }
  172.     }//public function onDelete()
  173.  
  174.  
  175.  
  176.     public function onSelectionChanged($selection)
  177.     {
  178.         $this->arWidgets['btnDelete']->set_sensitive($selection->count_selected_rows(> 0);
  179.         $this->arWidgets['btnUpdate']->set_sensitive($selection->count_selected_rows(> 0);
  180.     }//public function onSelectionChanged($selection)
  181.  
  182.  
  183.  
  184.     /**
  185.     *   Returns the name of the selected channel.
  186.     *
  187.     *   @return string  The name of the channel, or NULL if none is selected
  188.     */
  189.     protected function getSelectedChannelName()
  190.     {
  191.         $selection $this->arWidgets['lstChannels']->get_selection();
  192.         if ($selection->count_selected_rows(== 0{
  193.             return null;
  194.         }
  195.         list($model$iter$selection->get_selected();
  196.         return $model->get_value($iter0);
  197.     }//protected function getSelectedChannelName()
  198.  
  199.  
  200.  
  201.     /**
  202.     *   Loads the channel list from PEAR into the model.
  203.     */
  204.     protected function loadChannels()
  205.     {
  206.         $model $this->arWidgets['lstChannels']->get_model();
  207.         $model->clear();
  208.  
  209.         $arChannels = PEAR_Config::singleton()->getRegistry()->getChannels();
  210.         foreach ($arChannels as $nId => $channel{
  211.             $model->append(array(
  212.                 $channel->getName(),
  213.                 $channel->getAlias(),
  214.                 $channel->getSummary()
  215.             ));
  216.         }
  217.  
  218.         $this->onSelectionChanged($this->arWidgets['lstChannels']->get_selection());
  219.     }//protected function loadChannels()
  220.  
  221.  
  222.  
  223.     /**
  224.     *   Call this method if channels have changed.
  225.     *   (added, deleted, updated)
  226.     */
  227.     protected function reloadChannels()
  228.     {
  229.         $this->loadChannels();
  230.         $this->frontend->loadChannels();
  231.     }//protected function reloadChannels()
  232.  
  233.  
  234. }//class PEAR_Frontend_Gtk2_ChannelDialog
  235. ?>

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