Exemplo n.º 1
0
 /**
  * @see File_Archive_Predicate::isTrue()
  */
 function isTrue(&$source)
 {
     $sourceMIME = $source->getMIME();
     foreach ($this->mimes as $mime) {
         if (MIME_Type::isWildcard($mime)) {
             $result = MIME_Type::wildcardMatch($mime, $sourceMIME);
         } else {
             $result = $mime == $sourceMIME;
         }
         if ($result !== false) {
             return $result;
         }
     }
     return false;
 }
Exemplo n.º 2
0
 /**
  *
  */
 public function testWildcardMatch()
 {
     $this->assertTrue(MIME_Type::wildcardMatch('*/*', 'image/png'));
     $this->assertTrue(MIME_Type::wildcardMatch('image/*', 'image/png'));
     $this->assertFalse(MIME_Type::wildcardMatch('image/*', 'text/plain'));
 }
Exemplo n.º 3
0
 /**
  *   Data have been dropped over the widget
  *   @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
  */
 function dragDataReceived($widget, $context, $x, $y, $data, $info, $time)
 {
     $arData = explode("\n", $data->data);
     $arAccepted = array();
     $arRejected = array();
     $bDirectories = false;
     foreach ($arData as $strLine) {
         $strLine = trim($strLine);
         if ($strLine == '') {
             continue;
         }
         $strFile = Gtk_FileDrop::getPathFromUrilistEntry($strLine);
         $strFileMime = Gtk_FileDrop::getMimeType($strFile);
         $bAccepted = false;
         foreach ($this->arTypes as $strType) {
             if ($strType == 'inode/directory') {
                 $bDirectories = true;
             }
             if ($strType[0] == '.' && Gtk_FileDrop::getFileExtension($strFile) == $strType || $strType == $strFileMime || MIME_Type::wildcardMatch($strType, $strFileMime)) {
                 $arAccepted[] = $strFile;
                 $bAccepted = true;
                 break;
             }
         }
         //foreach type
         if (!$bAccepted) {
             $arRejected[] = $strFile;
         }
     }
     //foreach line
     //make directories from the files if dirs are accepted
     //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);
         }
     }
     if (count($arAccepted) == 0) {
         //no matching files
         return;
     }
     if ($this->bSetText) {
         $strClass = get_class($widget);
         switch ($strClass) {
             case 'GtkEntry':
             case 'GtkLabel':
                 $widget->set_text($arAccepted[0]);
                 break;
             case 'GtkButton':
             case 'GtkToggleButton':
             case 'GtkCheckButton':
             case 'GtkRadioButton':
                 $childs = $widget->children();
                 $child = $childs[0];
                 if (get_class($child) == 'GtkLabel') {
                     $child->set_text($arAccepted[0]);
                 } else {
                     trigger_error('No label found on widget.');
                 }
                 break;
             case 'GtkCombo':
                 $entry = $widget->entry;
                 $entry->set_text($arAccepted[0]);
                 break;
             case 'GtkFileSelection':
                 $widget->set_filename($arAccepted[0]);
                 break;
             case 'GtkList':
                 foreach ($arAccepted as $strFile) {
                     $items[] =& new GtkListItem($strFile);
                 }
                 $widget->append_items($items);
                 $widget->show_all();
                 break;
             default:
                 PEAR::raiseError('Widget class "' . $strClass . '" is not supported', GTK_FILEDROP_WIDGET_NOT_SUPPORTED, PEAR_ERROR_TRIGGER, E_USER_WARNING);
                 break;
         }
     }
     //if bSetText
     if ($this->objCallback !== null) {
         call_user_func($this->objCallback, $widget, $arAccepted);
     }
     //objCallback !== null
 }
Exemplo n.º 4
0
 public function testWildcardMatchNoWildcard()
 {
     $this->assertFalse(MIME_Type::wildcardMatch('image/foo', 'image/png'));
 }