]> git.wh0rd.org Git - tt-rss.git/commitdiff
add dialog to download articles for offline reading; start implementation
authorAndrew Dolgov <fox@bah.org.ru>
Tue, 3 Feb 2009 12:28:37 +0000 (15:28 +0300)
committerAndrew Dolgov <fox@bah.org.ru>
Tue, 3 Feb 2009 12:28:37 +0000 (15:28 +0300)
feedlist.js
functions.js
modules/backend-rpc.php
modules/popup-dialog.php
tt-rss.css
tt-rss.js
tt-rss.php

index 582509e402bc88f6060e94059103f0a34da1776c..4a892a9076904f5b9712cacba699fd65d2232c52 100644 (file)
@@ -30,6 +30,14 @@ function viewCategory(cat) {
        return false;
 }
 
+function render_offline_feedlist() {
+       try {
+               // FIXME
+       } catch (e) {
+               exception_error("render_offline_feedlist", e);
+       }
+}
+
 function render_feedlist(data) {
        try {
 
index 786023ffea0b86326d7a9fd070dd6c139efbeacc..ecb41db2ee135e57f8f7b5d9ca5b2580e5825c3a 100644 (file)
@@ -579,11 +579,11 @@ function parse_counters(reply, scheduled_call) {
                                setTimeout('updateFeedList(false, false)', 50);
                        }
                } else {
-                       var fl = document.getElementById("feeds-frame").innerHTML;
+/*                     var fl = document.getElementById("feeds-frame").innerHTML;
                        if (fl) {
                                cache_invalidate("FEEDLIST");
                                cache_inject("FEEDLIST", fl, getInitParam("num_feeds"));
-                       }
+                       } */
                }
 
        } catch (e) {
index 04e2858ca4474601a81d28d1612a77ec04a0a01a..55ab73a20f61d54c4249f884e5bf37ca236cbc79 100644 (file)
                        return;
                }
 
+               if ($subop == "download") {
+                       $stage = (int) $_REQUEST["stage"];
+
+                       print "<rpc-reply>";
+
+                       if ($stage == 0) {
+                               print "<feeds>";
+
+                               $reply = array();
+
+                               $result = db_query($link, "SELECT id, title FROM
+                                       ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"]);
+
+                               while ($line = db_fetch_assoc($result)) {
+                                       print "<feed id=\"".$line["id"]."\"><![CDATA[";
+                                       print $line["title"];
+                                       print "]]></feed>";
+                               }
+
+                               print "</feeds>";
+
+                       }
+
+                       print "</rpc-reply>";
+
+                       return;
+               }
+
                print "<rpc-reply><error>Unknown method: $subop</error></rpc-reply>";
        }
 ?>
index 465d3bcd9cdb6ed8caf8c659d74a47e0c29587a1..d89547fe9291346039c53943d0279bec9db10386 100644 (file)
                        return;
                }
 
+               if ($id == "offlineDownload") {
+                       print "<div id=\"infoBoxTitle\">".__('Download articles')."</div>";
+                       print "<div class=\"infoBoxContents\">";
+
+                       print "<form name='download_ops_form' id='download_ops_form'>";
+
+                       print "<div class=\"dlgSec\">".__("Download")."</div>";
+
+                       print "<div class=\"dlgSecCont\">";
+
+                       $amount = array(
+                               50  => 50,
+                               100 => 100,
+                               0   => "All unread");
+
+                       print_select_hash("amount", 50, $amount);
+
+                       print " " . __("newest articles for offline reading.");
+
+                       print "</div>";
+
+                       print "</form>";
+
+                       print "<div class=\"dlgButtons\">
+                       <div id=\"d_progress_o\" style=\"display : none\">
+                               <div id=\"d_progress_i\"></div>
+                       </div>
+                               <input class=\"button\"                                 
+                                       type=\"submit\" onclick=\"return initiate_offline_download()\" value=\"".__('Download')."\">
+                               <input class=\"button\"
+                                       type=\"submit\" onclick=\"return closeInfoBox()\" 
+                                       value=\"".__('Cancel')."\"></div>";
+
+                       print "</div>";
+
+                       return;
+               }
+
+
                print "<div id='infoBoxTitle'>Internal Error</div>
                        <div id='infoBoxContents'>
                        <p>Unknown dialog <b>$id</b></p>
index 95938bc910cb02a89e5f4725b8593526f83c9847..4909b20a3bb746b3a5a4c27255b0e210ba0c8777 100644 (file)
@@ -1976,6 +1976,20 @@ div#l_progress_i {
        height : 10px;
 }
 
+div#d_progress_o {
+       width : 100px;
+       border : 1px solid black;
+       background-color : white;
+       float : left;
+       margin-left : 10px;
+}
+
+div#d_progress_i {
+       width : 10px;
+       background-color : #88b0f0;
+       height : 10px;
+}
+
 #content-insert {
        background-color : white;
        overflow : auto;
index 24c80435b3c133c4c102911c88b97eb7c6d7cc65..3a44867078d1739cf733f0c0245d5e6bdb8d4c46 100644 (file)
--- a/tt-rss.js
+++ b/tt-rss.js
@@ -23,6 +23,7 @@ var offline_mode = false;
 var store = false;
 var localServer = false;
 var db = false;
+var download_progress_last = 0;
 
 function activeFeedIsCat() {
        return _active_feed_is_cat;
@@ -135,7 +136,7 @@ function backend_sanity_check_callback(transport) {
                }
 
                if (!transport.responseXML) {
-                       if (!google.gears) {
+                       if (!window.google && !google.gears) {
                                fatalError(3, "Sanity check: Received reply is not XML", transport.responseText);
                        } else {
                                init_offline();
@@ -662,6 +663,11 @@ function quickMenuGo(opid) {
                        resize_headlines();
                }
 
+               if (opid == "qmcDownload") {
+                       displayDlg("offlineDownload");
+                       return;
+               }
+
                if (opid == "qmcResetCats") {
 
                        if (confirm(__("Reset category order?"))) {
@@ -1295,6 +1301,16 @@ function hotkey_handler(e) {
                                }
                        }
 
+                       if (keycode == 68 && shift_key) { // D
+                               initiate_offline_download();
+                               return false;
+                       }
+
+                       if (keycode == 68) { // d
+                               displayDlg("offlineDownload");
+                               return false;
+                       }
+
                        if (keycode == 87) { // w
                                feeds_sort_by_unread = !feeds_sort_by_unread;
                                return resort_feedlist();
@@ -1486,6 +1502,14 @@ function init_gears() {
                        db.open('tt-rss');
 
                        db.execute("CREATE TABLE IF NOT EXISTS cache (id text, article text, param text, added text)");
+
+                       db.execute("CREATE TABLE if not exists offline_feeds (id integer, title text)");
+
+                       db.execute("CREATE TABLE if not exists offline_data (id integer, feed_id integer, title text, updated text, content text, tags text)");
+
+                       var qmcDownload = document.getElementById("qmcDownload");
+                       if (qmcDownload) Element.show(qmcDownload);
+
                }       
        
                cache_expire();
@@ -1499,8 +1523,7 @@ function init_offline() {
        try {
                offline_mode = true;
 
-               render_feedlist(cache_find("FEEDLIST"));
-               document.getElementById("quickMenuChooser").disabled = true;
+               render_offline_feedlist();
 
                remove_splash();
        } catch (e) {
@@ -1508,3 +1531,77 @@ function init_offline() {
        }
 }
 
+function offline_download_parse(stage, transport) {
+       try {
+               if (transport.responseXML) {
+
+                       if (stage == 0) {
+
+                               var feeds = transport.responseXML.getElementsByTagName("feed");
+
+                               if (feeds.length > 0) {
+                                       db.execute("DELETE FROM offline_feeds");
+                               }
+
+                               for (var i = 0; i < feeds.length; i++) {
+                                       var id = feeds[i].getAttribute("id");
+                                       var title = feeds[i].firstChild.nodeValue;
+       
+                                       db.execute("INSERT INTO offline_feeds (id,title) VALUES (?,?)",
+                                               [id, title]);
+                               }
+               
+                               window.setTimeout("initiate_offline_download("+(stage+1)+")", 50);
+                       }
+
+                       notify_info("All done.");
+
+               }
+       } catch (e) {
+               exception_error("offline_download_parse", e);
+       }
+}
+
+function download_set_progress(p) {
+       try {
+               var o = document.getElementById("d_progress_i");
+
+               if (!o) return;
+
+               Element.show(o);
+
+               new Effect.Scale(o, p, { 
+                       scaleY : false,
+                       scaleFrom : download_progress_last,
+                       scaleMode: { originalWidth : 100 },
+                       queue: { position: 'end', scope: 'LSP-Q', limit: 3 } }); 
+
+               download_progress_last = p;
+       } catch (e) {
+               exception_error("download_progress", e);
+       }
+}
+
+function initiate_offline_download(stage) {
+       try {
+
+               if (!stage) stage = 0;
+
+               notify_progress("Loading, please wait... S" + stage, true);
+               download_set_progress(20);
+
+               var query = "backend.php?op=rpc&subop=download&stage=" + stage;
+
+               if (document.getElementById("download_ops_form")) {
+                       query = query + "&" + Form.serialize("download_ops_form");
+               }
+
+               new Ajax.Request(query, {
+                       onComplete: function(transport) { 
+                               offline_download_parse(stage, transport);                               
+                       } });
+
+       } catch (e) {
+               exception_error("initiate_offline_download", e);
+       }
+}
index 09e7d1bc9121692632df008b60c1e8b7a8ffe9b7..bb5ecc2878504758d96d192c07dfda5ed400dace 100644 (file)
@@ -174,8 +174,9 @@ window.onload = init;
                                        <option value="qmcAddFilter">&nbsp;&nbsp;<?php echo __('Create filter...') ?></option>
                                        <option value="qmcResetUI">&nbsp;&nbsp;<?php echo __('Reset UI layout') ?></option>
                                        <option value="qmcResetCats">&nbsp;&nbsp;<?php echo __('Reset category order') ?></option>
-
+                                       <option id="qmcDownload" style="display : none" value="qmcDownload"><?php echo __('&nbsp;&nbsp;Download new articles...') ?></option>
                                        <option value="qmcHKhelp"><?php echo __('&nbsp;&nbsp;Keyboard shortcuts') ?></option>
+
                        </select>
                </div>