From ba18208b14d64e473f0319e6776206d1af07f3ba Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Wed, 21 Nov 2007 13:49:26 +0000 Subject: [PATCH] CS fixes git-svn-id: http://svn.php.net/repository/pear/packages/Gtk2_FileDrop/trunk@246605 c90b9560-bf6c-de11-be94-00142212c4b1 --- FileDrop.php | 269 ++++++++++++++++++++++++++++----------------------- 1 file changed, 146 insertions(+), 123 deletions(-) diff --git a/FileDrop.php b/FileDrop.php index 1f246f4..d036adf 100644 --- a/FileDrop.php +++ b/FileDrop.php @@ -1,48 +1,49 @@ | -// +----------------------------------------------------------------------+ -// -// $Id$ +/** +* Indexed Gtk2 combo box similar to the HTML select box. +* +* PHP Versions 5 +* +* @category Gtk2 +* @package Gtk2_FileDrop +* @author Christian Weiske +* @license http://www.php.net/license PHP License +* @version CVS: $Id$ +* @link http://pear.php.net/package/Gtk2_FileDrop +*/ require_once 'MIME/Type.php'; require_once 'PEAR.php'; /** -* A class which makes it easy to -* make a GtkWidget accept the dropping -* of files or folders +* A class which makes it easy to +* make a GtkWidget accept the dropping +* of files or folders +* +* @category Gtk2 +* @package Gtk2 +* @author Christian Weiske +* @license http://www.php.net/license PHP License +* @link http://pear.php.net/package/Gtk2_FileDrop * -* @author Christian Weiske -* @package Gtk2 +* @todo +* - reject files when moving the dragging mouse over the widget, +* just like opera does how does this work? +* I don't know, but I suppose I should * -* @date 2006-05-16 -* @license PHP +* @example +* Usage: +* Simply change the text of a widget +* (accept files with MIME-Types text/plain and text/html +* and files with .sgml extension): * -* @todo -* - reject files when moving the dragging mouse over the widget, just like opera does -* how does this work? I don't know, but I suppose I should +* Gtk2_FileDrop::attach($entry, array('text/plain', 'text/html', '.sgml')); * -* @example -* Usage: -* Simply change the text of a widget -* (accept files with MIME-Types text/plain and text/html and files with .sgml extension): -* Gtk2_FileDrop::attach($entry, array('text/plain', 'text/html', '.sgml')); -* Call a callback, and don't change the text (accept directories only): -* Gtk2_FileDrop::attach($entry, array( 'inode/directory'), array( $this, 'callback'), false); +* +* Call a callback, and don't change the text (accept directories only): +* Gtk2_FileDrop::attach( +* $entry, array( 'inode/directory'), array( $this, 'callback'), false +* ); */ class Gtk2_FileDrop { @@ -55,50 +56,59 @@ class Gtk2_FileDrop /** - * Prepares a widget to accept file drops. + * Prepares a widget to accept file drops. * - * @static - * @param GtkWidget The widget which shall accept files - * @param array List of MIME-Types to accept OR extensions, beginning with a dot "." - * @param mixed Callback to call when a drop with valid files happened - * @param boolean If the widget's text/label/content shall be changed automatically + * @param GtkWidget $widget The widget which shall accept files + * @param array $arTypes List of MIME-Types to accept OR extensions, + * beginning with a dot "." + * @param mixed $objCallback Callback to call when a drop with + * valid files happened + * @param boolean $bSetText If the widget's text/label/content shall + * be changed automatically * - * @return boolean If all was ok + * @return boolean If all was ok */ static function attach($widget, $arTypes, $objCallback = null, $bSetText = true) { - $widget->drag_dest_set(Gtk::DEST_DEFAULT_ALL, array(array('text/uri-list', 0, 0)), Gdk::ACTION_COPY | Gdk::ACTION_MOVE); + $widget->drag_dest_set( + Gtk::DEST_DEFAULT_ALL, + array(array('text/uri-list', 0, 0)), + Gdk::ACTION_COPY | Gdk::ACTION_MOVE + ); $fd = new Gtk2_FileDrop( $arTypes, $objCallback, $bSetText); $widget->connect('drag-data-received', array($fd, 'dragDataReceived')); return true; - }//static function attach($widget, $arTypes, $objCallback = null, $bSetText = true) + }//static function attach(...) /** - * Use attach() instead. + * Use attach() instead. + * + * @param array $arTypes Array of accepted types + * @param callback $objCallback Callback method + * @param boolean $bSetText If the text shall be set * - * @access private + * @return void */ - private function Gtk2_FileDrop( $arTypes, $objCallback = null, $bSetText = true) + private function Gtk2_FileDrop($arTypes, $objCallback = null, $bSetText = true) { $this->arTypes = $arTypes; $this->objCallback = $objCallback; $this->bSetText = $bSetText; - }//private function Gtk2_FileDrop( $arTypes, $objCallback = null, $bSetText = true) + }//private function Gtk2_FileDrop...) /** - * Prepares a widget to accept directories only. - * Just a shortcut for the exhausted programmer. + * Prepares a widget to accept directories only. + * Just a shortcut for the exhausted programmer. * - * @static - * @param GtkWidget The widget which shall accept directories + * @param GtkWidget $widget The widget which shall accept directories * - * @return boolean If all was ok + * @return boolean If all was ok */ static function attachDirectory($widget) { @@ -108,36 +118,43 @@ static function attachDirectory($widget) /** - * Data have been dropped over the widget. + * Data have been dropped over the widget. + * + * @param GtkWidget $widget The widget on which the data have been dropped + * @param GdkDragContext $context The context of the drop + * @param int $x X position + * @param int $y Y position + * @param mixed $data data + * @param int $info Info parameter (0 in our case) + * @param int $time The time on which the event happened * - * @param GtkWidget The widget on which the data have been dropped - * @param GdkDragContext The context of the drop - * @param int X position - * @param int Y position - * @param int Info parameter (0 in our case) - * @param int The time on which the event happened + * @return void */ function dragDataReceived($widget, $context , $x, $y, $data , $info, $time) { - $arData = explode("\n", $data->data); - $arAccepted = array(); - $arRejected = array(); + $arData = explode("\n", $data->data); + $arAccepted = array(); + $arRejected = array(); $bDirectories = false; foreach ($arData as $strLine) { $strLine = trim($strLine); - if ($strLine == '') { - continue; + if ($strLine == '') { + continue; } $strFile = self::getPathFromUrilistEntry($strLine); $strFileMime = self::getMimeType($strFile); $bAccepted = false; foreach ($this->arTypes as $strType) { - if ($strType == 'inode/directory') { - $bDirectories = true; + if ($strType == 'inode/directory') { + $bDirectories = true; } - if (($strType[0] == '.' && self::getFileExtension($strFile) == $strType) + if (($strType[0] == '.' + && self::getFileExtension($strFile) == $strType + ) || $strType == $strFileMime - || (strpos($strType, '/') !== false && MIME_Type::wildcardMatch($strType, $strFileMime)) + || (strpos($strType, '/') !== false + && MIME_Type::wildcardMatch($strType, $strFileMime) + ) ) { $arAccepted[] = $strFile; $bAccepted = true; @@ -153,7 +170,7 @@ function dragDataReceived($widget, $context , $x, $y, $data , $info, $time) //this is done here to give native directories first places on the list if ($bDirectories && count($arRejected) > 0) { foreach ($arRejected as $strFile) { - $arAccepted[] = dirname( $strFile); + $arAccepted[] = dirname($strFile); } } @@ -174,7 +191,7 @@ function dragDataReceived($widget, $context , $x, $y, $data , $info, $time) case 'GtkCheckButton': case 'GtkRadioButton': $childs = $widget->get_children(); - $child = $childs[0]; + $child = $childs[0]; if (get_class($child) == 'GtkLabel') { $child->set_text($arAccepted[0]); } else { @@ -196,36 +213,41 @@ function dragDataReceived($widget, $context , $x, $y, $data , $info, $time) $widget->show_all(); break; default: - PEAR::raiseError( 'Widget class "' . $strClass . '" is not supported', self::WIDGET_NOT_SUPPORTED, PEAR_ERROR_TRIGGER, E_USER_WARNING); + PEAR::raiseError( + 'Widget class "' . $strClass . '" is not supported', + self::WIDGET_NOT_SUPPORTED, + PEAR_ERROR_TRIGGER, + E_USER_WARNING + ); break; } }//if bSetText if ($this->objCallback !== null) { - call_user_func( $this->objCallback, $widget, $arAccepted); + call_user_func($this->objCallback, $widget, $arAccepted); }//objCallback !== null }//function dragDataReceived($widget, $context , $x, $y, $data , $info, $time) /** - * Converts a file path gotten from a text/uri-list - * drop to a usable local filepath. + * Converts a file path gotten from a text/uri-list + * drop to a usable local filepath. * - * Php functions like parse_url can't be used as it is - * likely that the dropped URI is no real URI but a - * strange thing which tries to look like one - * See the explanation at: - * http://gtk.php.net/manual/en/tutorials.filednd.urilist.php + * Php functions like parse_url can't be used as it is + * likely that the dropped URI is no real URI but a + * strange thing which tries to look like one + * See the explanation at: + * http://gtk.php.net/manual/en/tutorials.filednd.urilist.php * - * @static - * @param string The line from the uri-list - * @return string The usable local filepath + * @param string $strUriFile The line from the uri-list + * + * @return string The usable local filepath */ static function getPathFromUrilistEntry($strUriFile) { $strUriFile = urldecode($strUriFile);//should be URL-encoded - $bUrl = false; + $bUrl = false; if (substr($strUriFile, 0, 5) == 'file:') { //(maybe buggy) file protocol if (substr($strUriFile, 0, 17) == 'file://localhost/') { @@ -238,9 +260,9 @@ static function getPathFromUrilistEntry($strUriFile) //theoretically, the hostname should be the first //but no one implements it $strUriFile = substr($strUriFile, 5); - for( $n = 1; $n < 5; $n++) { - if ($strUriFile[$n] != '/') { - break; + for ($n = 1; $n < 5; $n++) { + if ($strUriFile[$n] != '/') { + break; } } $strUriFile = substr($strUriFile, $n - 1); @@ -255,7 +277,7 @@ static function getPathFromUrilistEntry($strUriFile) $strFile = $strUriFile; } else { //NO slash after "file:" - what is that for a crappy program? - $strFile = substr ($strUriFile, 5); + $strFile = substr($strUriFile, 5); } } else if (strstr($strUriFile, '://')) { //real protocol, but not file @@ -275,17 +297,17 @@ static function getPathFromUrilistEntry($strUriFile) /** - * Returns the extension if a filename - * including the leading dot. + * Returns the extension if a filename + * including the leading dot. + * + * @param string $strFile The filename * - * @static - * @param string The filename - * @return string The extension with a leading dot + * @return string The extension with a leading dot */ static function getFileExtension($strFile) { $strExt = strrchr($strFile, '.'); - if ($strExt == false) { + if ($strExt == false) { return ''; } $strExt = str_replace('\\', '/', $strExt); @@ -298,16 +320,16 @@ static function getFileExtension($strFile) /** - * Determines the mime-type for the given file. + * Determines the mime-type for the given file. * - * @static - * @param string The file name - * @return string The MIME type or FALSE in the case of an error + * @param string $strFile The file name + * + * @return string The MIME type or FALSE in the case of an error */ static function getMimeType($strFile) { //MIME_Type doesn't return the right type for directories - //The underlying functions MIME_Type used don't return it right, + //The underlying functions MIME_Type used don't return it right, //so there is no chance to fix MIME_Type itself if ((file_exists($strFile) && is_dir($strFile)) || substr($strFile, -1) == '/') { @@ -318,32 +340,33 @@ static function getMimeType($strFile) return $strMime; } - //determine by extension | as MIME_TYPE doesn't support this, I have to do this myself + //determine by extension | as MIME_TYPE doesn't support this, + // I have to do this myself $strExtension = self::getFileExtension($strFile); switch ($strExtension) { - case '.txt' : - $strType = 'text/plain'; - break; - case '.gif' : - $strType = 'image/gif'; - break; - case '.jpg' : - case '.jpeg': - $strType = 'image/jpg'; - break; - case '.png' : - $strType = 'image/png'; - break; - case '.xml' : - $strType = 'text/xml'; - break; - case '.htm' : - case '.html': - $strType = 'text/html'; - break; - default: - $strType = false; - break; + case '.txt' : + $strType = 'text/plain'; + break; + case '.gif' : + $strType = 'image/gif'; + break; + case '.jpg' : + case '.jpeg': + $strType = 'image/jpg'; + break; + case '.png' : + $strType = 'image/png'; + break; + case '.xml' : + $strType = 'text/xml'; + break; + case '.htm' : + case '.html': + $strType = 'text/html'; + break; + default: + $strType = false; + break; } return $strType; }//static function getMimeType($strFile)