diff options
author | James Bottomley <JBottomley@Parallels.com> | 2013-05-10 23:08:13 -0700 |
---|---|---|
committer | James Bottomley <JBottomley@Parallels.com> | 2013-05-10 23:09:38 -0700 |
commit | 6a37be5f964f840966e899b620ac06583b3d72ea (patch) | |
tree | ffa4d3da930869c211fb433c47d2ab1980472ceb | |
parent | bbf40e92faf8891b1d6a3937e18093885ba22a13 (diff) | |
download | asterisk-aastra-6a37be5f964f840966e899b620ac06583b3d72ea.tar.gz |
TextScreen: refactor to eliminate dependence on AastraIPPhone classes
Begin building a device independent representation object
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | include/AastraIPPhoneFormattedTextScreen.class.php | 9 | ||||
-rw-r--r-- | include/BaseList.class.php | 14 | ||||
-rw-r--r-- | include/Blacklist.class.php | 8 | ||||
-rw-r--r-- | include/TextScreen.class.php | 165 | ||||
-rw-r--r-- | include/Voicemail.class.php | 16 |
6 files changed, 193 insertions, 22 deletions
@@ -36,7 +36,8 @@ base-files = \ include/BaseAastra.class.php \ include/BaseList.class.php \ include/DatabaseListManager.class.php \ - include/ConfigFile.class.php + include/ConfigFile.class.php \ + include/TextScreen.class.php base-doc-files = \ etc/apache-asterisk \ diff --git a/include/AastraIPPhoneFormattedTextScreen.class.php b/include/AastraIPPhoneFormattedTextScreen.class.php index eeb7e0c..258cc5b 100644 --- a/include/AastraIPPhoneFormattedTextScreen.class.php +++ b/include/AastraIPPhoneFormattedTextScreen.class.php @@ -107,7 +107,7 @@ class AastraIPPhoneFormattedTextScreen extends AastraIPPhone { foreach($pieces as $value) $this->_entries[] = new AastraIPPhoneFormattedTextScreenEntry($value, $size, $align, $color, 'normal'); } - function setScrollStart($height) + function setScrollStart($height = '') { $this->_entries[] = new AastraIPPhoneFormattedTextScreenEntry(NULL, $height, NULL, NULL, 'scrollstart'); } @@ -203,6 +203,13 @@ class AastraIPPhoneFormattedTextScreen extends AastraIPPhone { $out .= ">\n"; # Lines + if ($this->_title!='') + { + $title = $this->escape($this->_title); + $out .= "<Line Size=\"double\" Align=\"center\">"; + $out .= $title."</Line>\n"; + } + if (isset($this->_entries) && is_array($this->_entries)) { foreach ($this->_entries as $entry) $out .= $entry->render(); diff --git a/include/BaseList.class.php b/include/BaseList.class.php index b3fcedc..9c981fe 100644 --- a/include/BaseList.class.php +++ b/include/BaseList.class.php @@ -4,11 +4,10 @@ ## # Class implementing a wrapper for List objects ## -require_once('AastraIPPhoneTextMenu.class.php'); +require_once('TextScreen.class.php'); -class BaseList extends AastraIPPhoneTextMenu { +class BaseList extends TextScreen { var $data; - var $window = 4; var $page; var $title; var $url; @@ -30,8 +29,8 @@ class BaseList extends AastraIPPhoneTextMenu { } function build() { - $pages = intval((count($this->data)+3)/$this->window); - $down = $this->page + 1 == $pages ? null : $this->url.'&page='.($this->page + 1).'&index='.$this->window; + $pages = intval((count($this->data)+3)/$this->_phone['entries']); + $down = $this->page + 1 == $pages ? null : $this->url.'&page='.($this->page + 1).'&index='.$this->_phone['entries']; $up = $this->page == 0 ? null : $this->url.'&page='.($this->page - 1).'&index=0'; parent::setTitle($this->title.' Page: '.($this->page+1).'/'.$pages); $this->setStyle('none'); @@ -44,9 +43,8 @@ class BaseList extends AastraIPPhoneTextMenu { if (isset($_GET['index'])) { $this->setDefaultIndex($_GET['index']); } - $this->setUnitScroll(); - $start = $this->page * $this->window; - $end = ($this->page + 1) * $this->window; + $start = $this->page * $this->_phone['entries']; + $end = ($this->page + 1) * $this->_phone['entries']; if ($end > count($this->data)) { $end = count($this->data); } diff --git a/include/Blacklist.class.php b/include/Blacklist.class.php index bc917e3..2e30fce 100644 --- a/include/Blacklist.class.php +++ b/include/Blacklist.class.php @@ -5,7 +5,7 @@ # Blacklist handling class ## require_once('BaseAastra.class.php'); -require_once('AastraIPPhoneTextScreen.class.php'); +require_once('TextScreen.class.php'); require_once('AastraIPPhoneInputScreen.class.php'); class Blacklist extends BaseAastra { @@ -34,7 +34,7 @@ class Blacklist extends BaseAastra { } return; } - $this->displayObject(new AastraIPPhoneTextScreen()); + $this->displayObject(new TextScreen()); $this->do->SetText('Are you sure you want to remove '.$this->lastnumber.' from the '.$list.'?'); $this->yesno(); } @@ -51,7 +51,7 @@ class Blacklist extends BaseAastra { } return; } - $this->displayObject(new AastraIPPhoneTextScreen()); + $this->displayObject(new TextScreen()); $this->do->SetText('Are you sure you want to blacklist '.$this->lastnumber.'?'); $this->yesno(); } @@ -91,7 +91,7 @@ class Blacklist extends BaseAastra { } function start() { - $this->displayObject(new AastraIPPhoneTextScreen()); + $this->displayObject(new TextScreen()); $text = 'The last number was '.$this->lastnumber; if ($this->blacklist) { $text .= ' which is already blacklisted'; diff --git a/include/TextScreen.class.php b/include/TextScreen.class.php new file mode 100644 index 0000000..f8fed55 --- /dev/null +++ b/include/TextScreen.class.php @@ -0,0 +1,165 @@ +<?php +## +# Copyright 2013 by James Bottomley +## +# Phone Independent text screen handling class +## +require_once('AastraIPPhoneTextScreen.class.php'); +require_once('AastraIPPhoneFormattedTextScreen.class.php'); +require_once('AastraIPPhoneTextMenu.class.php'); + +class TextScreen { + var $_phone = array( + # notional: the 6739i uses a variable width font + 'width' => 38, + 'height' => 14, + 'entries' => 4, + 'formatted' => true, + 'unitscrollbug' => true, + ); + var $_softkeys = array(); + var $_entries = array(); + var $_text = array(); + var $_title; + var $_destroyOnExit; + var $_cancelAction; + var $_style; + var $_scrollUp; + var $_scrollDown; + var $_defaultIndex; + var $_allowDrop; + + function __construct() { + } + + function addSoftKey($index, $label, $url, $icon = null) { + $this->_softkeys[$index] = array( + 'label' => $label, + 'url' => $url, + 'icon' => $icon, + ); + } + + function setTitle($title) { + $this->_title = $title; + } + + function setStyle($style) { + $this->_style = $style; + } + + function setCancelAction($cancelAction) { + $this->_cancelAction=$cancelAction; + } + + function setDestroyOnExit() { + $this->_destroyOnExit = 'yes'; + } + + function setAllowDrop() { + $this->_allowDrop = 'yes'; + } + + function setDefaultIndex($index) { + $this->_defaultIndex = $index; + } + + function setScrollUp($uri) { + $this->_scrollUp = $uri; + } + + function setScrollDown($uri) { + $this->_scrollDown = $uri; + } + + function addEntry($name, $url, $selection = null, $icon = null, + $dial = null, $line = null) { + $this->_entries[] = array( + 'name' => $name, + 'url' => $url, + 'selection' => $selection, + 'icon' => $icon, + ); + } + + function setText($text) { + $this->_text = array($text); + } + + function addtext($text) { + $this->_text[] = $text; + } + + function output() { + if (count($this->_entries) == 0) { + if ($this->_phone['formatted']) { + $o = new AastraIpPhoneFormattedTextScreen(); + } else { + $o = new AastraIPPhoneTextScreen(); + } + } else { + $o = new AastraIPPhoneTextMenu(); + } + $o->setTitle($this->_title); + if ($this->_destroyOnExit) { + $o->setDestroyOnExit(); + } + if ($this->_allowDrop) { + $o->setAllowDrop(); + } + if ($this->_phone['unitscrollbug'] && method_exists($o, 'setUnitScroll')) { + $o->setUnitScroll(); + } + if ($this->_cancelAction) { + $o->setCancelAction($this->_cancelAction); + } + if ($this->_style) { + $o->setStyle($this->_style); + } + if ($this->_scrollUp) { + $o->setScrollUp($this->_scrollUp); + } + if ($this->_scrollDown) { + $o->setScrollDown($this->_scrollDown); + } + if ($this->_defaultIndex) { + $o->setDefaultIndex($this->_defaultIndex); + } + foreach($this->_entries as $e) { + $name = $e['name']; + $url = $e['url']; + $selection = $e['selection']; + $icon = $e['icon']; + $o->addEntry($name, $url, $selection, $icon); + } + foreach($this->_softkeys as $k=>$e) { + $label = $e['label']; + $url = $e['url']; + $icon = $e['icon']; + $o->addSoftKey($k, $label, $url, $icon); + } + $o->setTitle($this->_title); + if (count($this->_entries) != 0) { + #do nothing + } else if (count($this->_text) == 0) { + $o->setText($this->_text[0]); + } else if ($this->_phone['formatted']) { + foreach($this->_text as $t) { + $s = preg_split('/\n/',wordwrap($t, $this->_phone['width'], "\n\xa0\xa0")); + foreach($s as $l) { + $o->addLine($l); + } + } + } else { + $text = ''; + foreach($this->_text as $t) { + $c = strlen($t) % $this->_phone['width']; + $c = $c ? $this->_phone['width'] - $c : 0; + error_log("length of t is ".strlen($t).' c='.$c); + $text .= $t . str_repeat("\xa0", $c).'|'; + } + $o->setText($text); + } + $o->output(); + } +} diff --git a/include/Voicemail.class.php b/include/Voicemail.class.php index 37c58ec..483f018 100644 --- a/include/Voicemail.class.php +++ b/include/Voicemail.class.php @@ -1,8 +1,8 @@ <?php require_once('BaseAastra.class.php'); -require_once('AastraIPPhoneTextScreen.class.php'); require_once('VoicemailListManager.class.php'); require_once('AastraIPPhoneExecute.class.php'); +require_once('TextScreen.class.php'); class Voicemail extends BaseAastra { @@ -221,7 +221,7 @@ class Voicemail extends BaseAastra { function message() { $box = $_GET['box']; if (count($this->box[$box]) == 0) { - $this->displayObject(new AastraIPPhoneTextScreen()); + $this->displayObject(new TextScreen()); $this->title = 'Mailbox '.$box; $this->do->setText('is empty'); $this->back = $this->url; @@ -252,8 +252,10 @@ class Voicemail extends BaseAastra { } $c = new ConfigFile($this->path.'/'.$box.'/'.$msg.'.txt'); $m = $c->section('message'); - $this->displayObject(new AastraIPPhoneTextScreen()); - $this->do->setText('Received: '.$m['origdate'].' From: '.$m['callerid'].' length '.$m['duration'].' seconds'); + $this->displayObject(new TextScreen()); + $this->do->addText('Received: '.$m['origdate']); + $this->do->addText('From: '.$m['callerid']); + $this->do->addText('Length '.$m['duration'].' seconds'); $this->$ordinary($box, $msg, $i); } @@ -265,18 +267,16 @@ class Voicemail extends BaseAastra { } function start() { - $text = 'Voicemail has'; - $this->displayObject(new AastraIPPhoneTextScreen()); + $this->displayObject(new TextScreen()); $softkey = 1; foreach ($this->mapping as $k => $v) { $c = count($this->box[$k]); - $text .= ' '.$c.' '.$v; + $this->do->addText($c.' '.$v); if ($c) { $this->do->addSoftkey($softkey, $v, $this->url.'?action=mailbox&box='.$k); } $softkey++; } - $this->do->setText($text); } } ?> |