diff --git a/package/le-edubar@c3sl.ufpr.br/download.sh b/package/le-edubar@c3sl.ufpr.br/download.sh index 32a3821d659ae8e7e0f5c5913394a13e0062552c..e13d225268575122e040ddfb1c6fc0e1331cf162 100755 --- a/package/le-edubar@c3sl.ufpr.br/download.sh +++ b/package/le-edubar@c3sl.ufpr.br/download.sh @@ -29,14 +29,16 @@ file_id=$4 fdir="/var/cache/le-edubar" #Choose or create the download directory -if [ ! -d "$fdir" ];then +if test ! -d "$fdir" ;then mkdir -p "$fdir" fi cd "$fdir" +nautilus + #Create file folder -if [ ! -d "$file_id" ]; then +if test ! -d "$file_id" ; then mkdir "$file_id" fi @@ -44,12 +46,14 @@ fi cd "$fdir/$file_id" wget -T 15 -O "$file_name.$file_ext" "$url" --no-check-certificate -if [ $? -ne 0 ]; then +if test $? -ne 0 ; then cd .. rm -rf "$file_id" exit 4 fi -# Create a JSON file for this learning object. + JSON="`wget -qO- https://api.portalmec.c3sl.ufpr.br/v1/learning_objects/$file_id`" -echo $JSON > ".$file_id.json" \ No newline at end of file +echo $JSON > ".$file_id.json" + + diff --git a/package/le-edubar@c3sl.ufpr.br/edu-dbus b/package/le-edubar@c3sl.ufpr.br/edu-dbus index a463e0c8cf7d4adb2fdfb6319f0f90c5284cf31a..a3543e579fd8f034881ffb40f1f6169eca8f7e2f 100755 --- a/package/le-edubar@c3sl.ufpr.br/edu-dbus +++ b/package/le-edubar@c3sl.ufpr.br/edu-dbus @@ -13,23 +13,77 @@ var obj = service.createObject('/br/ufpr/c3sl/edubar'); /* Create download interface */ var iface_download = obj.createInterface('br.ufpr.c3sl.edubar.Download'); + +var download_pipe = { + + download_queue : new Array(), + + create : function () { + this.download_queue = new Array(); + }, + + push : function(id) { + if (!this.is_queued(id)) { + this.download_queue.push(id); + this.update_json(); + } + }, + + shift : function () { + return this.download_queue.shift(); + }, + + is_queued : function(id) { + if (this.download_queue.indexOf(id) >= 0) { + return true; + } else { + return false; + } + }, + + get_queue : function () { + return this.download_queue; + }, + + update_json : function() { + if (this.download_queue.length <= 0) { + return; + } + if(fs.existsSync(download_dir + '/.learning_objects.json')) { + var result_JSON = JSON.parse( + fs.readFileSync(download_dir + '/.learning_objects.json'). + toString().replace(/(\r\n|\n|\r)/gm,"")); + } + this.shift(); + this.update_json(); + } +} + +download_pipe.create(); + /* Add method */ iface_download.addMethod('Start', { - in: [ DBus.Define(Array) ], + in: [DBus.Define(String), + DBus.Define(String), + DBus.Define(String), + DBus.Define(String), + DBus.Define(String)], out: DBus.Define(Number) - }, function(edu,callback) { - console.log('Fazendo download de id=' + edu[4] + ' ' + edu[2]); + }, function(path,link,name,format,id,callback) { + console.log('Fazendo download de id=' + id + ' ' + name); /*TODO Change to dictionary*/ - exec('sudo ' + edu[0] + ' "' + - edu[1] + '" "' + - edu[2] + '" "' + - edu[3] + '" "' + - edu[4] + '"'); + exec('sudo ' + path + ' "' + + link + '" "' + + name + '" "' + + format + '" "' + + id + '"'); + + iface_download.emit('started',id); - iface_download.emit('started',edu[4]); + download_pipe.push(id); - callback(null,edu[4]); + callback(null,id); }); iface_download.addMethod('Stop', { out: DBus.Define(String) }, function(callback) { @@ -104,30 +158,12 @@ iface_file.addMethod('GetLocalFiles',{ in: [ DBus.Define(Number), DBus.Define(String), DBus.Define(String) ], out: DBus.Define(String) }, function(page, search_text, order_property, callback) { - fs.exists(download_dir, function (exists) { + fs.exists(download_dir + '/.learning_objects.json', function (exists) { if (exists) { - var directories = fs.readdirSync(download_dir).map( function(name) { - return path.join(download_dir,name); - }).filter(function(download_dir){ - return fs.lstatSync(download_dir).isDirectory(); - }); - var result_JSON = "[" - var i = directories.length; - var file_json; - while (i--> 0) { - file_json = directories[i].split("/"); - file_json = file_json[file_json.length -1]; - file_json = directories[i] + "/." + file_json + ".json"; - - if (fs.existsSync(file_json)) { - result_JSON += fs.readFileSync(file_json).toString().replace(/(\r\n|\n|\r)/gm,""); - if (i > 0) { - result_JSON += ","; - } - } - } - result_JSON += "]"; - result_JSON = JSON.parse(result_JSON); + + result_JSON = JSON.parse( + fs.readFileSync(download_dir + '/.learning_objects.json'). + toString().replace(/(\r\n|\n|\r)/gm,"")); result_JSON.sort(function(a,b) { switch (order_property) { @@ -146,7 +182,7 @@ iface_file.addMethod('GetLocalFiles',{ case 'title': return a.name.localeCompare(b.name); break; - case 'likes': + case 'likes': return a.likes_count > b.likes_count; break; default: diff --git a/package/le-edubar@c3sl.ufpr.br/edubus.js b/package/le-edubar@c3sl.ufpr.br/edubus.js index 859a245650892713e6f985eff513d835d01373b7..9763ce9a86741a78fe1ee5bb7d4cec28bfa131ef 100644 --- a/package/le-edubar@c3sl.ufpr.br/edubus.js +++ b/package/le-edubar@c3sl.ufpr.br/edubus.js @@ -3,7 +3,11 @@ const Gio = imports.gi.Gio; const download_interface = '<node>\ <interface name="br.ufpr.c3sl.edubar.Download">\ <method name="Start">\ - <arg type="as" direction="in"/>\ + <arg type="s" direction="in"/>\ + <arg type="s" direction="in"/>\ + <arg type="s" direction="in"/>\ + <arg type="s" direction="in"/>\ + <arg type="s" direction="in"/>\ <arg type="d" direction="out" />\ </method>\ <signal name="started">\ @@ -33,7 +37,7 @@ const file_interface = '<node>\ <arg type="i" direction="in"/>\ <arg type="s" direction="in"/>\ <arg type="s" direction="in"/>\ - <arg type="sd" direction="out" />\ + <arg type="s" direction="out" />\ </method>\ <method name="GetTotalFiles">\ <arg type="d" direction="out" />\ diff --git a/package/le-edubar@c3sl.ufpr.br/extension.js b/package/le-edubar@c3sl.ufpr.br/extension.js index 65b2d41546b6143243014e4ebe33f47d1e0fda29..eac85442fde6867ace673c597c593ba63c94bd57 100644 --- a/package/le-edubar@c3sl.ufpr.br/extension.js +++ b/package/le-edubar@c3sl.ufpr.br/extension.js @@ -309,21 +309,25 @@ function start_local_search() { if (result_screen.get_last_child().name == 'navigation') { result_screen.get_last_child().destroy(); } + var local_text = search_text; + EduBus.file.GetLocalFilesRemote(search_page, + Prefabs.clear_special_chars(local_text), + order_property, + function(result_json) { + if (local_text != search_text) { + return; + } + soup_result = JSON.parse(result_json); + if (search_page == 0) { + max_pages = Math.ceil(EduBus.file.GetTotalFilesSync() /Constants.RESULTS_PER_REQUEST); + } - var result_json = EduBus.file.GetLocalFilesSync(search_page, - Prefabs.clear_special_chars(search_text), - order_property); - - soup_result = JSON.parse(result_json); - if (search_page == 0) { - max_pages = Math.ceil(EduBus.file.GetTotalFilesSync() /Constants.RESULTS_PER_REQUEST); - } + if (soup_result.length > 0) { + show_results(); + } + }); - if (soup_result.length > 0) { - show_results(); - } else { - } } /* @@ -1004,14 +1008,16 @@ function download_button(download,file_name) { })); /* Starts download.*/ - var edubus_edu = new Array(meta_path + '/download.sh', download.link, - download.name,download.format, - download.id.toString()); var file_path = Constants.DOWNLOAD_PATH + download.id + "/" + download.name + "." + download.format; - EduBus.download.StartRemote(edubus_edu); + EduBus.download.StartRemote( + meta_path + '/download.sh', + download.link, + download.name, + download.format, + download.id.toString()); if (on_going_downloads.indexOf(download.id) < 0) { on_going_downloads.push(download.id);