diff options
author | Thomas Tanghus <thomas@tanghus.net> | 2012-02-09 19:07:54 +0100 |
---|---|---|
committer | Thomas Tanghus <thomas@tanghus.net> | 2012-02-09 19:07:54 +0100 |
commit | 25f1263c11f5704b8e429262341416fbe7081f9a (patch) | |
tree | bfd4fc6326d08442bdb17764f3607c3ef28992ad /apps | |
parent | ff53b0c2097ae5d0390336238454dc1792158905 (diff) | |
parent | 25381ac5b145390102e359462f9f99cc7e7802e0 (diff) | |
download | nextcloud-server-25f1263c11f5704b8e429262341416fbe7081f9a.tar.gz nextcloud-server-25f1263c11f5704b8e429262341416fbe7081f9a.zip |
Merge gitorious.org:owncloud/owncloud into tanghus_contacts
Diffstat (limited to 'apps')
-rw-r--r-- | apps/calendar/js/calendar.js | 12 | ||||
-rwxr-xr-x | apps/files_pdfviewer/js/viewer.js | 16 | ||||
-rw-r--r-- | apps/files_sharing/appinfo/app.php | 1 | ||||
-rw-r--r-- | apps/files_sharing/js/share.js | 1 | ||||
-rw-r--r-- | apps/files_sharing/lib_share.php | 4 | ||||
-rw-r--r-- | apps/files_sharing/sharedstorage.php | 91 | ||||
-rw-r--r-- | apps/files_texteditor/ajax/loadfile.php | 2 | ||||
-rw-r--r-- | apps/files_texteditor/ajax/savefile.php | 3 | ||||
-rw-r--r-- | apps/gallery/ajax/galleryOp.php | 7 | ||||
-rw-r--r-- | apps/gallery/ajax/thumbnail.php | 59 | ||||
-rw-r--r-- | apps/gallery/lib/photo.php | 33 | ||||
-rw-r--r-- | apps/gallery/lib/scanner.php | 7 | ||||
-rw-r--r-- | apps/media/ajax/api.php | 28 | ||||
-rw-r--r-- | apps/media/js/scanner.js | 88 | ||||
-rw-r--r-- | apps/media/lib_scanner.php | 36 |
15 files changed, 127 insertions, 261 deletions
diff --git a/apps/calendar/js/calendar.js b/apps/calendar/js/calendar.js index 64c029404cb..92a8ba20205 100644 --- a/apps/calendar/js/calendar.js +++ b/apps/calendar/js/calendar.js @@ -668,8 +668,18 @@ $(document).ready(function(){ agenda: agendatime, '': defaulttime }, + columnFormat: { + month: t('calendar', 'ddd'), // Mon + week: t('calendar', 'ddd M/d'), // Mon 9/7 + day: t('calendar', 'dddd M/d') // Monday 9/7 + }, titleFormat: { - list: 'yyyy/MMM/d dddd' + month: t('calendar', 'MMMM yyyy'), + // September 2009 + week: t('calendar', "MMM d[ yyyy]{ '—'[ MMM] d yyyy}"), + // Sep 7 - 13 2009 + day: t('calendar', 'dddd, MMM d, yyyy'), + // Tuesday, Sep 8, 2009 }, axisFormat: defaulttime, monthNames: monthNames, diff --git a/apps/files_pdfviewer/js/viewer.js b/apps/files_pdfviewer/js/viewer.js index 7f6766c67dd..85bbf09362e 100755 --- a/apps/files_pdfviewer/js/viewer.js +++ b/apps/files_pdfviewer/js/viewer.js @@ -49,13 +49,15 @@ showPDFviewer.lastTitle=''; showPDFviewer.loaded=false; $(document).ready(function(){ - if(location.href.indexOf("files")!=-1) { - PDFJS.workerSrc = OC.filePath('files_pdfviewer','js','pdfjs/build/pdf.js'); - if(typeof FileActions!=='undefined'){ - FileActions.register('application/pdf','Edit','',function(filename){ - showPDFviewer($('#dir').val(),filename); - }); - FileActions.setDefault('application/pdf','Edit'); + if(!$.browser.msie){//doesnt work on IE + if(location.href.indexOf("files")!=-1) { + PDFJS.workerSrc = OC.filePath('files_pdfviewer','js','pdfjs/build/pdf.js'); + if(typeof FileActions!=='undefined'){ + FileActions.register('application/pdf','Edit','',function(filename){ + showPDFviewer($('#dir').val(),filename); + }); + FileActions.setDefault('application/pdf','Edit'); + } } } }); diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php index 8d589ea5e2e..8049e9b0ae3 100644 --- a/apps/files_sharing/appinfo/app.php +++ b/apps/files_sharing/appinfo/app.php @@ -6,7 +6,6 @@ OC::$CLASSPATH['OC_Share'] = "apps/files_sharing/lib_share.php"; OC_Hook::connect("OC_Filesystem", "post_delete", "OC_Share", "deleteItem"); OC_Hook::connect("OC_Filesystem", "post_rename", "OC_Share", "renameItem"); OC_Hook::connect("OC_Filesystem", "post_write", "OC_Share", "updateItem"); -OC_Filesystem::registerStorageType("shared", "OC_Filestorage_Shared", array("datadir" => "string")); OC_Util::addScript("files_sharing", "share"); OC_Util::addScript("3rdparty", "chosen/chosen.jquery.min"); OC_Util::addStyle( 'files_sharing', 'sharing' ); diff --git a/apps/files_sharing/js/share.js b/apps/files_sharing/js/share.js index 4457dddbe15..d01a07447a6 100644 --- a/apps/files_sharing/js/share.js +++ b/apps/files_sharing/js/share.js @@ -2,6 +2,7 @@ $(document).ready(function() { var shared_status = {}; if (typeof FileActions !== 'undefined') { FileActions.register('all', 'Share', function(filename) { + if (scanFiles.scanning){return;}//workaround to prevent aditional http request block scanning feedback var icon; var file = $('#dir').val()+'/'+filename; if(shared_status[file]) diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index 0eb0e5bf85d..049a74278b3 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -89,8 +89,8 @@ class OC_Share { } $query->execute(array($uid_owner, $uid, $source, $target, $permissions)); // Clear the folder size cache for the 'Shared' folder - $clearFolderSize = OC_DB::prepare("DELETE FROM *PREFIX*foldersize WHERE path = ?"); - $clearFolderSize->execute(array($sharedFolder)); +// $clearFolderSize = OC_DB::prepare("DELETE FROM *PREFIX*foldersize WHERE path = ?"); +// $clearFolderSize->execute(array($sharedFolder)); // Emit post_create and post_write hooks to notify of a new file in the user's filesystem OC_Hook::emit("OC_Filesystem", "post_create", array('path' => $target)); OC_Hook::emit("OC_Filesystem", "post_write", array('path' => $target)); diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index b0eaeecf723..cb641e68a84 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -22,10 +22,10 @@ require_once( 'lib_share.php' ); -if (!OC_Filesystem::is_dir('/Shared')) { +if (OC_Filesystem::$loaded and !OC_Filesystem::is_dir('/Shared')) { OC_Filesystem::mkdir('/Shared'); } -OC_Filesystem::mount('shared',array('datadir'=>'/'.OC_User::getUser().'/files/Shared'),'/'.OC_User::getUser().'/files/Shared/'); +OC_Filesystem::mount('OC_Filestorage_Shared',array('datadir'=>'/'.OC_User::getUser().'/files/Shared'),'/'.OC_User::getUser().'/files/Shared/'); /** * Convert target path to source path and pass the function call to the correct storage provider @@ -168,19 +168,9 @@ class OC_Filestorage_Shared extends OC_Filestorage { // TODO fill in other components of array public function stat($path) { if ($path == "" || $path == "/") { - $stat["dev"] = ""; - $stat["ino"] = ""; - $stat["mode"] = ""; - $stat["nlink"] = ""; - $stat["uid"] = ""; - $stat["gid"] = ""; - $stat["rdev"] = ""; $stat["size"] = $this->filesize($path); - $stat["atime"] = $this->fileatime($path); $stat["mtime"] = $this->filemtime($path); $stat["ctime"] = $this->filectime($path); - $stat["blksize"] = ""; - $stat["blocks"] = ""; return $stat; } else { $source = $this->getSource($path); @@ -217,18 +207,7 @@ class OC_Filestorage_Shared extends OC_Filestorage { } public function getFolderSize($path) { - // Shared folder sizes are cached separately from the source folder sizes because folders can have different names - $path = rtrim($path, "/"); - $path = ltrim($path, "/"); - $path = preg_replace('{(/)\1+}', "/", $path); - $dbpath = rtrim($this->datadir.$path, "/"); - $query = OC_DB::prepare("SELECT size FROM *PREFIX*foldersize WHERE path = ?"); - $size = $query->execute(array($dbpath))->fetchAll(); - if (count($size) > 0) { - return $size[0]['size']; - } else { - return $this->calculateFolderSize($path); - } + return 0; //depricated } private function calculateFolderSize($path) { @@ -249,8 +228,8 @@ class OC_Filestorage_Shared extends OC_Filestorage { } if ($size > 0) { $dbpath = rtrim($this->datadir.$path, "/"); - $query = OC_DB::prepare("INSERT INTO *PREFIX*foldersize VALUES(?,?)"); - $result = $query->execute(array($dbpath, $size)); +// $query = OC_DB::prepare("INSERT INTO *PREFIX*foldersize VALUES(?,?)"); +// $result = $query->execute(array($dbpath, $size)); } } return $size; @@ -263,8 +242,8 @@ class OC_Filestorage_Shared extends OC_Filestorage { $path = dirname($path); } $dbpath = rtrim($this->datadir.$path, "/"); - $query = OC_DB::prepare("DELETE FROM *PREFIX*foldersize WHERE path = ?"); - $result = $query->execute(array($dbpath)); +// $query = OC_DB::prepare("DELETE FROM *PREFIX*/*foldersize*/ WHERE path = ?"); +// $result = $query->execute(array($dbpath)); if ($path != "/" && $path != "") { $parts = explode("/", $path); $part = array_pop($parts); @@ -280,7 +259,7 @@ class OC_Filestorage_Shared extends OC_Filestorage { return true; } - public function is_writeable($path) { + public function is_writable($path) { if($path == "" || $path == "/"){ return false; }elseif (OC_Share::getPermissions($this->datadir.$path) & OC_Share::WRITE) { @@ -320,8 +299,8 @@ class OC_Filestorage_Shared extends OC_Filestorage { $ctime = $tempctime; } } - return $ctime; } + return $ctime; } else { $source = $this->getSource($path); if ($source) { @@ -341,8 +320,8 @@ class OC_Filestorage_Shared extends OC_Filestorage { $mtime = $tempmtime; } } - return $mtime; } + return $mtime; } else { $source = $this->getSource($path); if ($source) { @@ -352,27 +331,6 @@ class OC_Filestorage_Shared extends OC_Filestorage { } } - public function fileatime($path) { - if ($path == "" || $path == "/") { - $atime = 0; - if ($dh = $this->opendir($path)) { - while (($filename = readdir($dh)) !== false) { - $tempatime = $this->fileatime($filename); - if ($tempatime > $atime) { - $atime = $tempatime; - } - } - return $atime; - } - } else { - $source = $this->getSource($path); - if ($source) { - $storage = OC_Filesystem::getStorage($source); - return $storage->fileatime($this->getInternalPath($source)); - } - } - } - public function file_get_contents($path) { $source = $this->getSource($path); if ($source) { @@ -382,7 +340,7 @@ class OC_Filestorage_Shared extends OC_Filestorage { } public function file_put_contents($path, $data) { - if ($this->is_writeable($path)) { + if ($this->is_writable($path)) { $source = $this->getSource($path); if ($source) { $storage = OC_Filesystem::getStorage($source); @@ -426,7 +384,7 @@ class OC_Filestorage_Shared extends OC_Filestorage { if ($root1 !== $root2) { return false; // Check if both paths have write permission - } else if ($this->is_writeable($path1) && $this->is_writeable($path2)) { + } else if ($this->is_writable($path1) && $this->is_writable($path2)) { $oldSource = $this->getSource($path1); $newSource = $folders['source'].substr($newTarget, strlen($folders['target'])); if ($oldSource) { @@ -456,7 +414,7 @@ class OC_Filestorage_Shared extends OC_Filestorage { if ($path2 == "" || $path2 == "/") { // TODO Construct new shared item or should this not be allowed? } else { - if ($this->is_writeable($path2)) { + if ($this->is_writable($path2)) { $tmpFile = $this->toTmpFile($path1); $result = $this->fromTmpFile($tmpFile, $path2); if ($result) { @@ -486,7 +444,7 @@ class OC_Filestorage_Shared extends OC_Filestorage { } public function fromTmpFile($tmpFile, $path) { - if ($this->is_writeable($path)) { + if ($this->is_writable($path)) { $source = $this->getSource($path); if ($source) { $storage = OC_Filesystem::getStorage($source); @@ -501,23 +459,10 @@ class OC_Filestorage_Shared extends OC_Filestorage { } } - public function fromUploadedFile($tmpFile, $path) { - if ($this->is_writeable($path)) { - $source = $this->getSource($path); - if ($source) { - $storage = OC_Filesystem::getStorage($source); - $result = $storage->fromUploadedFile($tmpFile, $this->getInternalPath($source)); - if ($result) { - $this->clearFolderSizeCache($path); - } - return $result; - } - } else { - return false; - } - } - public function getMimeType($path) { + if ($path == "" || $path == "/") { + return 'httpd/unix-directory'; + } $source = $this->getSource($path); if ($source) { $storage = OC_Filesystem::getStorage($source); @@ -572,4 +517,4 @@ class OC_Filestorage_Shared extends OC_Filestorage { } -?>
\ No newline at end of file +?> diff --git a/apps/files_texteditor/ajax/loadfile.php b/apps/files_texteditor/ajax/loadfile.php index 64e016be8c2..8ece844aa29 100644 --- a/apps/files_texteditor/ajax/loadfile.php +++ b/apps/files_texteditor/ajax/loadfile.php @@ -33,7 +33,7 @@ $filename = isset($_GET['file']) ? $_GET['file'] : ''; if(!empty($filename)) { $path = $dir.'/'.$filename; - if(OC_Filesystem::is_writeable($path)) + if(OC_Filesystem::is_writable($path)) { $mtime = OC_Filesystem::filemtime($path); $filecontents = OC_Filesystem::file_get_contents($path); diff --git a/apps/files_texteditor/ajax/savefile.php b/apps/files_texteditor/ajax/savefile.php index 3d0771ea983..589428d1862 100644 --- a/apps/files_texteditor/ajax/savefile.php +++ b/apps/files_texteditor/ajax/savefile.php @@ -32,7 +32,6 @@ $filecontents = htmlspecialchars_decode($_POST['filecontents']); $path = isset($_POST['path']) ? $_POST['path'] : ''; $mtime = isset($_POST['mtime']) ? $_POST['mtime'] : ''; - if($path != '' && $mtime != '') { // Get file mtime @@ -47,7 +46,7 @@ if($path != '' && $mtime != '') { // File same as when opened // Save file - if(OC_Filesystem::is_writeable($path)) + if(OC_Filesystem::is_writable($path)) { OC_Filesystem::file_put_contents($path, $filecontents); // Clear statcache diff --git a/apps/gallery/ajax/galleryOp.php b/apps/gallery/ajax/galleryOp.php index f819d87f666..8df692c7735 100644 --- a/apps/gallery/ajax/galleryOp.php +++ b/apps/gallery/ajax/galleryOp.php @@ -45,6 +45,11 @@ function handleGetThumbnails($albumname) { OC_JSON::checkLoggedIn(); $photo = new OC_Image(); $photo->loadFromFile(OC::$CONFIG_DATADIRECTORY.'/../gallery/'.$albumname.'.png'); + $offset = 3600 * 24; // 24 hour + // calc the string in GMT not localtime and add the offset + header("Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT"); + header('Cache-Control: max-age='.$offset.', must-revalidate'); + header('Pragma: public'); $photo->show(); } @@ -69,7 +74,7 @@ function handlePartialCreate($path) { if (!OC_Filesystem::is_dir($path)) OC_JSON::error(array('cause' => 'Invalid path given')); $album = OC_Gallery_Album::find(OC_User::getUser(), null, $path); - $albums; + $albums = array(); OC_Gallery_Scanner::scanDir($path, $albums); OC_JSON::success(array('album_details' => $albums)); } diff --git a/apps/gallery/ajax/thumbnail.php b/apps/gallery/ajax/thumbnail.php index 6d25c7a2536..2dfe936d9dd 100644 --- a/apps/gallery/ajax/thumbnail.php +++ b/apps/gallery/ajax/thumbnail.php @@ -25,65 +25,14 @@ require_once('../../../lib/base.php'); OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('gallery'); -function CroppedThumbnail($imgSrc,$thumbnail_width,$thumbnail_height) { //$imgSrc is a FILE - Returns an image resource. - //getting the image dimensions - if(! function_exists('imagecreatefromjpeg')) - OC_Log::write('gallery','GD module not installed',OC_Log::ERROR); - - list($width_orig, $height_orig) = getimagesize($imgSrc); - switch (strtolower(substr($imgSrc, strrpos($imgSrc, '.')+1))) { - case "jpeg": - case "jpg": - case "tiff": - $myImage = imagecreatefromjpeg($imgSrc); - break; - case "png": - $myImage = imagecreatefrompng($imgSrc); - break; - default: - exit(); - } - if(!$myImage) exit(); - $ratio_orig = $width_orig/$height_orig; - - if ($thumbnail_width/$thumbnail_height > $ratio_orig) { - $new_height = $thumbnail_width/$ratio_orig; - $new_width = $thumbnail_width; - } else { - $new_width = $thumbnail_height*$ratio_orig; - $new_height = $thumbnail_height; - } - - $x_mid = $new_width/2; //horizontal middle - $y_mid = $new_height/2; //vertical middle - - $process = imagecreatetruecolor(round($new_width), round($new_height)); - - imagecopyresampled($process, $myImage, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig); - $thumb = imagecreatetruecolor($thumbnail_width, $thumbnail_height); - imagecopyresampled($thumb, $process, 0, 0, ($x_mid-($thumbnail_width/2)), ($y_mid-($thumbnail_height/2)), $thumbnail_width, $thumbnail_height, $thumbnail_width, $thumbnail_height); - - imagedestroy($process); - imagedestroy($myImage); - return $thumb; -} - -$box_size = 200; $img = $_GET['img']; -$imagePath = OC_Filesystem::getLocalFile($img); - -if(file_exists($imagePath)) -{ - $image = CroppedThumbnail($imagePath, $box_size, $box_size); - - header('Content-Type: image/png'); - $offset = 3600 * 24; +$image = OC_Gallery_Photo::getThumbnail($img); +if ($image) { + $offset = 3600 * 24; // 24 hour // calc the string in GMT not localtime and add the offset header("Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT"); header('Cache-Control: max-age='.$offset.', must-revalidate'); header('Pragma: public'); - - imagepng($image); - imagedestroy($image); + $image->show(); } diff --git a/apps/gallery/lib/photo.php b/apps/gallery/lib/photo.php index d1fb166aee9..15783cb341a 100644 --- a/apps/gallery/lib/photo.php +++ b/apps/gallery/lib/photo.php @@ -21,7 +21,7 @@ * */ -class OC_Gallery_Photo{ +class OC_Gallery_Photo { public static function create($albumId, $img){ $stmt = OC_DB::prepare('INSERT INTO *PREFIX*gallery_photos (album_id, file_path) VALUES (?, ?)'); $stmt->execute(array($albumId, $img)); @@ -65,5 +65,34 @@ class OC_Gallery_Photo{ $stmt = OC_DB::prepare("UPDATE *PREFIX*gallery_photos SET file_path = ?, album_id = ? WHERE album_id = ? and file_path = ?"); $stmt->execute(array($newpath, $newAlbumId, $oldAlbumId, $oldpath)); } -} + public static function getThumbnail($image_name) { + $imagePath = OC_Filesystem::getLocalFile($image_name); + if(!file_exists($imagePath)) { + return null; + } + $save_dir = OC_Config::getValue("datadirectory").'/'. OC_User::getUser() .'/gallery/'; + $save_dir .= dirname($image_name). '/'; + $image_name = basename($image_name); + $thumb_file = $save_dir . $image_name; + if (file_exists($thumb_file)) { + $image = new OC_Image($thumb_file); + } else { + $image = new OC_Image($imagePath); + if ($image->valid()) { + $image->centerCrop(); + $image->resize(200); + $image->fixOrientation(); + if (!is_dir($save_dir)) { + mkdir($save_dir, 0777, true); + } + $image->save($thumb_file); + } + } + if ($image->valid()) { + //var_dump($image, $image->resource()); + return $image; + } + return null; + } +} diff --git a/apps/gallery/lib/scanner.php b/apps/gallery/lib/scanner.php index 3aae94d1a4f..9fdadbe38c7 100644 --- a/apps/gallery/lib/scanner.php +++ b/apps/gallery/lib/scanner.php @@ -89,8 +89,11 @@ class OC_Gallery_Scanner { $file_count = min(count($files), 10); $thumbnail = imagecreatetruecolor($file_count*200, 200); for ($i = 0; $i < $file_count; $i++) { - $imagePath = OC_Filesystem::getLocalFile($files[$i]); - CroppedThumbnail($imagePath, 200, 200, $thumbnail, $i*200); + $image = OC_Gallery_Photo::getThumbnail($files[$i]); + if ($image && $image->valid()) { + imagecopyresampled($thumbnail, $image->resource(), $i*200, 0, 0, 0, 200, 200, 200, 200); + } + unset($image); // unset $image here to control the lifetime of image::$resource } imagepng($thumbnail, OC_Config::getValue("datadirectory").'/'. OC_User::getUser() .'/gallery/' . $albumName.'.png'); } diff --git a/apps/media/ajax/api.php b/apps/media/ajax/api.php index 4a93e84910e..ac6739a1386 100644 --- a/apps/media/ajax/api.php +++ b/apps/media/ajax/api.php @@ -70,10 +70,10 @@ if($arguments['action']){ case 'scan': OC_DB::beginTransaction(); set_time_limit(0); //recursive scan can take a while - $path=$arguments['path']; - echo OC_MEDIA_SCANNER::scanFolder($path); + $eventSource=new OC_EventSource(); + OC_MEDIA_SCANNER::scanCollection($eventSource); + $eventSource->close(); OC_DB::commit(); - flush(); break; case 'scanFile': echo (OC_MEDIA_SCANNER::scanFile($arguments['path']))?'true':'false'; @@ -127,29 +127,9 @@ if($arguments['action']){ OC_Filesystem::readfile($arguments['path']); exit; case 'find_music': - OC_JSON::encodedPrint(findMusic()); + OC_JSON::encodedPrint(OC_FileCache::searchByMime('audio')); exit; } } -function findMusic($path=''){ - $music=array(); - $dh=OC_Filesystem::opendir($path); - if($dh){ - while($filename=readdir($dh)){ - if($filename[0]!='.'){ - $file=$path.'/'.$filename; - if(OC_Filesystem::is_dir($file)){ - $music=array_merge($music,findMusic($file)); - }else{ - if(OC_MEDIA_SCANNER::isMusic($filename)){ - $music[]=$file; - } - } - } - } - } - return $music; -} - ?> diff --git a/apps/media/js/scanner.js b/apps/media/js/scanner.js index ed2046dd7a6..0baa9db419a 100644 --- a/apps/media/js/scanner.js +++ b/apps/media/js/scanner.js @@ -1,90 +1,44 @@ Scanner={ songsFound:0, + eventSource:null, songsScanned:0, - songsChecked:0, - startTime:null, - endTime:null, - stopScanning:false, - currentIndex:0, - songs:[], findSongs:function(ready){ $.getJSON(OC.linkTo('media','ajax/api.php')+'?action=find_music',function(songs){ Scanner.songsFound=songs.length; - Scanner.currentIndex=-1 if(ready){ - ready(songs) } }); }, - scanFile:function(path,ready){ - path=encodeURIComponent(path); - $.getJSON(OC.linkTo('media','ajax/api.php')+'?action=get_path_info&path='+path,function(song){ - Scanner.songsChecked++; - if(ready){ - ready(song); - } - if(song){//do this after the ready call so we dont hold up the next ajax call - var artistId=song.song_artist; - Scanner.songsScanned++; - $('#scan span.songCount').text(Scanner.songsScanned); - var progress=(Scanner.songsChecked/Scanner.songsFound)*100; - $('#scanprogressbar').progressbar('value',progress) - Collection.addSong(song); - } - }); - }, scanCollection:function(ready){ $('#scanprogressbar').progressbar({ value:0, }); $('#scanprogressbar').show(); - Scanner.songsChecked=0; - Scanner.currentIndex=0; Scanner.songsScanned=0; - Scanner.startTime=new Date().getTime()/1000; - Scanner.findSongs(function(songs){ - Scanner.songs=songs; - Scanner.start(function(){ - $('#scan input.start').show(); - $('#scan input.stop').hide(); - $('#scanprogressbar').hide(); - Collection.display(); - if(ready){ - ready(); - } - }); + Scanner.eventSource=new OC.EventSource(OC.linkTo('media','ajax/api.php'),{action:'scan'}); + Scanner.eventSource.listen('count',function(total){ + Scanner.songsFound=total; + }); + Scanner.eventSource.listen('scanned',function(data){ + Scanner.songsScanned=data.count; + $('#scan span.songCount').text(Scanner.songsScanned); + var progress=(Scanner.songsScanned/Scanner.songsFound)*100; + $('#scanprogressbar').progressbar('value',progress) }); + Scanner.eventSource.listen('done',function(count){ + $('#scan input.start').show(); + $('#scan input.stop').hide(); + $('#scanprogressbar').hide(); + Collection.load(Collection.display) + if(ready){ + ready(); + } + }); + $('#scancount').show(); }, stop:function(){ - Scanner.stopScanning=true; - }, - start:function(ready){ - Scanner.stopScanning=false; - $('#scancount').show(); - var scanSong=function(){ - if(!Scanner.stopScanning && Scanner.currentIndex<=Scanner.songs.length){ - Scanner.scanFile(Scanner.songs[Scanner.currentIndex],scanSong) - }else if(!Scanner.stopScanning){ - Scanner.endTime=new Date().getTime()/1000; - if(ready){ - ready(); - ready=null;//only call ready once - } - } - Scanner.currentIndex++; - } - scanSong(); - scanSong(); + Scanner.close(); }, - toggle:function(){ - if(Scanner.stopScanning){ - Scanner.start(); - $('#scan input.stop').val(t('media','Pause')); - }else{ - Scanner.stop(); - $('#scan input.stop').val(t('media','Resume')); - } - } } diff --git a/apps/media/lib_scanner.php b/apps/media/lib_scanner.php index 8b659c73b6e..ea594ee8e3c 100644 --- a/apps/media/lib_scanner.php +++ b/apps/media/lib_scanner.php @@ -33,32 +33,22 @@ class OC_MEDIA_SCANNER{ /** * scan a folder for music - * @param string $path + * @param OC_EventSource eventSource (optional) * @return int the number of songs found */ - public static function scanFolder($path){ - if (OC_Filesystem::is_dir($path)) { - $songs=0; - if ($dh = OC_Filesystem::opendir($path)) { - while (($filename = readdir($dh)) !== false) { - if($filename<>'.' and $filename<>'..' and substr($filename,0,1)!='.'){ - $file=$path.'/'.$filename; - if(OC_Filesystem::is_dir($file)){ - $songs+=self::scanFolder($file); - }elseif(OC_Filesystem::is_file($file)){ - $data=self::scanFile($file); - if($data){ - $songs++; - } - } - } - } + public static function scanCollection($eventSource=null){ + $music=OC_FileCache::searchByMime('audio'); + $eventSource->send('count',count($music)); + $songs=0; + foreach($music as $file){ + self::scanFile($file); + $songs++; + if($eventSource){ + $eventSource->send('scanned',array('file'=>$file,'count'=>$songs)); } - }elseif(OC_Filesystem::is_file($path)){ - $songs=1; - self::scanFile($path); - }else{ - $songs=0; + } + if($eventSource){ + $eventSource->send('done',$songs); } return $songs; } |