]> git.wh0rd.org Git - tt-rss.git/blob - tt-rss.js
preffiltertree: hide generic document icon
[tt-rss.git] / tt-rss.js
1 var total_unread = 0;
2 var global_unread = -1;
3 var firsttime_update = true;
4 var _active_feed_id = 0;
5 var _active_feed_is_cat = false;
6 var number_of_feeds = 0;
7 var hotkey_prefix = false;
8 var hotkey_prefix_pressed = false;
9 var init_params = {};
10 var _force_scheduled_update = false;
11 var last_scheduled_update = false;
12
13 var _rpc_seq = 0;
14
15 function next_seq() {
16         _rpc_seq += 1;
17         return _rpc_seq;
18 }
19
20 function get_seq() {
21         return _rpc_seq;
22 }
23
24 function activeFeedIsCat() {
25         return _active_feed_is_cat;
26 }
27
28 function getActiveFeedId() {
29         try {
30                 //console.log("gAFID: " + _active_feed_id);
31                 return _active_feed_id;
32         } catch (e) {
33                 exception_error("getActiveFeedId", e);
34         }
35 }
36
37 function setActiveFeedId(id, is_cat) {
38         try {
39                 _active_feed_id = id;
40
41                 if (is_cat != undefined) {
42                         _active_feed_is_cat = is_cat;
43                 }
44
45                 selectFeed(id, is_cat);
46
47         } catch (e) {
48                 exception_error("setActiveFeedId", e);
49         }
50 }
51
52
53 function dlg_frefresh_callback(transport, deleted_feed) {
54         if (getActiveFeedId() == deleted_feed) {
55                 setTimeout("viewfeed(-5)", 100);
56         }
57
58         setTimeout('updateFeedList()', 50);
59         closeInfoBox();
60 }
61
62 function updateFeedList() {
63         try {
64
65 //              $("feeds-holder").innerHTML = "<div id=\"feedlistLoading\">" + 
66 //                      __("Loading, please wait...") + "</div>";
67
68                 Element.show("feedlistLoading");
69
70                 if (dijit.byId("feedTree")) {
71                         dijit.byId("feedTree").destroyRecursive();
72                 }
73
74                 var store = new dojo.data.ItemFileWriteStore({
75          url: "backend.php?op=feeds"});
76
77                 var treeModel = new fox.FeedStoreModel({
78                         store: store,
79                         query: {
80                                 "type": "feed"
81                         },
82                         rootId: "root",
83                         rootLabel: "Feeds",
84                         childrenAttrs: ["items"]
85                 });
86
87                 var tree = new fox.FeedTree({
88                 model: treeModel,
89                 onOpen: function (item, node) {
90                         var id = String(item.id);
91                         var cat_id = id.substr(id.indexOf(":")+1);
92
93                         new Ajax.Request("backend.php", 
94                                 { parameters: "backend.php?op=feeds&subop=collapse&cid=" + 
95                                         param_escape(cat_id) + "&mode=1" } );
96            },
97                 onClose: function (item, node) {
98                         var id = String(item.id);
99                         var cat_id = id.substr(id.indexOf(":")+1);
100
101                         new Ajax.Request("backend.php", 
102                                 { parameters: "backend.php?op=feeds&subop=collapse&cid=" + 
103                                         param_escape(cat_id) + "&mode=0" } );
104
105            },
106                 onClick: function (item, node) {
107                         var id = String(item.id);
108                         var is_cat = id.match("^CAT:");
109                         var feed = id.substr(id.indexOf(":")+1);
110                         viewfeed(feed, '', is_cat);
111                         return false;
112                 },
113                 openOnClick: false,
114                 showRoot: false,
115                 id: "feedTree",
116                 }, "feedTree");
117
118                 $("feeds-holder").appendChild(tree.domNode);
119
120                 var tmph = dojo.connect(tree, 'onLoad', function() {
121                 dojo.disconnect(tmph);
122                         Element.hide("feedlistLoading");
123                         loading_set_progress(25);
124                 });
125
126                 tree.startup();
127
128         } catch (e) {
129                 exception_error("updateFeedList", e);
130         }
131 }
132
133 function catchupAllFeeds() {
134
135         var str = __("Mark all articles as read?");
136
137         if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
138
139                 var query_str = "backend.php?op=feeds&subop=catchupAll";
140
141                 notify_progress("Marking all feeds as read...");
142
143                 //console.log("catchupAllFeeds Q=" + query_str);
144
145                 new Ajax.Request("backend.php", {
146                         parameters: query_str,
147                         onComplete: function(transport) { 
148                                 feedlist_callback2(transport); 
149                         } });
150
151                 global_unread = 0;
152                 updateTitle("");
153         }
154 }
155
156 function viewCurrentFeed(subop) {
157
158         if (getActiveFeedId() != undefined) {
159                 viewfeed(getActiveFeedId(), subop, activeFeedIsCat());
160         }
161         return false; // block unneeded form submits
162 }
163
164 function timeout() {
165         if (getInitParam("bw_limit") == "1") return;
166
167         try {
168            var date = new Date();
169       var ts = Math.round(date.getTime() / 1000);
170
171                 if (ts - last_scheduled_update > 10 || _force_scheduled_update) {
172
173                         //console.log("timeout()");
174
175                         window.clearTimeout(counter_timeout_id);
176                 
177                         var query_str = "?op=rpc&subop=getAllCounters&seq=" + next_seq();
178                 
179                         var omode;
180                 
181                         if (firsttime_update && !navigator.userAgent.match("Opera")) {
182                                 firsttime_update = false;
183                                 omode = "T";
184                         } else {
185                                 omode = "flc";
186                         }
187                         
188                         query_str = query_str + "&omode=" + omode;
189
190                         if (!_force_scheduled_update)
191                                 query_str = query_str + "&last_article_id=" + getInitParam("last_article_id");
192                 
193                         //console.log("[timeout]" + query_str);
194                 
195                         new Ajax.Request("backend.php", {
196                                 parameters: query_str,
197                                 onComplete: function(transport) { 
198                                                 handle_rpc_reply(transport, !_force_scheduled_update);
199                                                 _force_scheduled_update = false;
200                                         } });
201
202                         last_scheduled_update = ts;
203                 }
204
205         } catch (e) {
206                 exception_error("timeout", e);
207         }
208
209         setTimeout("timeout()", 3000);
210 }
211
212 function search() {
213         closeInfoBox(); 
214         viewCurrentFeed();
215 }
216
217 function updateTitle() {
218         var tmp = "Tiny Tiny RSS";
219
220         if (global_unread > 0) {
221                 tmp = tmp + " (" + global_unread + ")";
222         }
223
224         if (window.fluid) {
225                 if (global_unread > 0) {
226                         window.fluid.dockBadge = global_unread;
227                 } else {
228                         window.fluid.dockBadge = "";
229                 }
230         }
231
232         document.title = tmp;
233 }
234
235 function genericSanityCheck() {
236         setCookie("ttrss_test", "TEST");
237         
238         if (getCookie("ttrss_test") != "TEST") {
239                 fatalError(2);
240         }
241
242         return true;
243 }
244
245 function init() {
246         try {
247                 Form.disable("main_toolbar_form");
248
249                 dojo.require("dijit.layout.BorderContainer");
250                 dojo.require("dijit.layout.TabContainer");
251                 dojo.require("dijit.layout.ContentPane");
252                 dojo.require("dijit.Dialog");
253                 dojo.require("dijit.form.Button");
254                 dojo.require("dojo.data.ItemFileWriteStore");
255                 dojo.require("dijit.Tree");
256                 dojo.require("dijit.form.Select");
257                 dojo.require("dijit.Toolbar");
258                 dojo.require("dijit.ProgressBar");
259                 dojo.require("dojo.parser");
260
261                 dojo.registerModulePath("fox", "../..");
262
263                 dojo.require("fox.FeedTree");
264
265                 if (typeof themeBeforeLayout == 'function') {
266                         themeBeforeLayout();
267                 }
268
269                 dojo.addOnLoad(function() {
270                         updateFeedList();
271                         closeArticlePanel();
272
273                         if (typeof themeAfterLayout == 'function') {
274                                 themeAfterLayout();
275                         }
276
277                 });
278
279                 if (!genericSanityCheck()) 
280                         return;
281
282                 var params = "&ua=" + param_escape(navigator.userAgent);
283
284                 loading_set_progress(20);
285
286                 new Ajax.Request("backend.php", {
287                         parameters: "backend.php?op=rpc&subop=sanityCheck" + params,
288                         onComplete: function(transport) {
289                                         backend_sanity_check_callback(transport);
290                                 } });
291
292         } catch (e) {
293                 exception_error("init", e);
294         }
295 }
296
297 function init_second_stage() {
298
299         try {
300
301                 delCookie("ttrss_test");
302
303                 var toolbar = document.forms["main_toolbar_form"];
304
305                 dropboxSelect(toolbar.view_mode, getInitParam("default_view_mode"));
306                 dropboxSelect(toolbar.order_by, getInitParam("default_view_order_by"));
307
308                 feeds_sort_by_unread = getInitParam("feeds_sort_by_unread") == 1;
309
310                 loading_set_progress(30);
311
312                 if (has_local_storage())
313                         localStorage.clear();
314
315                 feedlist_init();
316                 setTimeout("timeout()", 3000);
317
318                 console.log("second stage ok");
319
320         } catch (e) {
321                 exception_error("init_second_stage", e);
322         }
323 }
324
325 function quickMenuChange() {
326         var chooser = $("quickMenuChooser");
327         var opid = chooser[chooser.selectedIndex].value;
328
329         chooser.selectedIndex = 0;
330         quickMenuGo(opid);
331 }
332
333 function quickMenuGo(opid) {
334         try {
335
336                 if (opid == "qmcPrefs") {
337                         gotoPreferences();
338                 }
339         
340                 if (opid == "qmcTagCloud") {
341                         displayDlg("printTagCloud");
342                 }
343
344                 if (opid == "qmcSearch") {
345                         displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat(), 
346                                 function() { 
347                                         document.forms['search_form'].query.focus();
348                                 });
349                         return;
350                 }
351         
352                 if (opid == "qmcAddFeed") {
353                         quickAddFeed();
354                         return;
355                 }
356
357                 if (opid == "qmcEditFeed") {
358                         editFeedDlg(getActiveFeedId());
359                 }
360         
361                 if (opid == "qmcRemoveFeed") {
362                         var actid = getActiveFeedId();
363
364                         if (activeFeedIsCat()) {
365                                 alert(__("You can't unsubscribe from the category."));
366                                 return;
367                         }       
368
369                         if (!actid) {
370                                 alert(__("Please select some feed first."));
371                                 return;
372                         }
373
374                         var fn = getFeedName(actid);
375
376                         var pr = __("Unsubscribe from %s?").replace("%s", fn);
377
378                         if (confirm(pr)) {
379                                 unsubscribeFeed(actid);
380                         }
381                 
382                         return;
383                 }
384
385                 if (opid == "qmcCatchupAll") {
386                         catchupAllFeeds();
387                         return;
388                 }
389         
390                 if (opid == "qmcShowOnlyUnread") {
391                         toggleDispRead();
392                         return;
393                 }
394         
395                 if (opid == "qmcAddFilter") {
396                         displayDlg('quickAddFilter', '',
397                            function () {document.forms['filter_add_form'].reg_exp.focus();});
398                 }
399
400                 if (opid == "qmcAddLabel") {
401                         addLabel();
402                 }
403
404                 if (opid == "qmcRescoreFeed") {
405                         rescoreCurrentFeed();
406                 }
407
408                 if (opid == "qmcHKhelp") {
409                         //Element.show("hotkey_help_overlay");
410                         Effect.Appear("hotkey_help_overlay", {duration : 0.3});
411                 }
412
413         } catch (e) {
414                 exception_error("quickMenuGo", e);
415         }
416 }
417
418 function toggleDispRead() {
419         try {
420
421                 var hide = !(getInitParam("hide_read_feeds") == "1");
422
423                 hideOrShowFeeds(hide);
424
425                 var query = "?op=rpc&subop=setpref&key=HIDE_READ_FEEDS&value=" + 
426                         param_escape(hide);
427
428                 setInitParam("hide_read_feeds", hide);
429
430                 new Ajax.Request("backend.php", {
431                         parameters: query,
432                         onComplete: function(transport) { 
433                         } });
434                                 
435         } catch (e) {
436                 exception_error("toggleDispRead", e);
437         }
438 }
439
440 function parse_runtime_info(elem) {
441
442         if (!elem || !elem.firstChild) {
443                 console.warn("parse_runtime_info: invalid node passed");
444                 return;
445         }
446
447         var data = JSON.parse(elem.firstChild.nodeValue);
448
449         //console.log("parsing runtime info...");
450
451         for (k in data) {
452                 var v = data[k];
453
454                 // console.log("RI: " + k + " => " + v);
455
456                 if (k == "new_version_available") {
457                         var icon = $("newVersionIcon");
458                         if (icon) {
459                                 if (v == "1") {
460                                         icon.style.display = "inline";
461                                 } else {
462                                         icon.style.display = "none";
463                                 }
464                         }
465                         return;
466                 }
467
468                 var error_flag;
469
470                 if (k == "daemon_is_running" && v != 1) {
471                         notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not running.</span>", true);
472                         return;
473                 }
474
475                 if (k == "daemon_stamp_ok" && v != 1) {
476                         notify_error("<span onclick=\"javascript:explainError(3)\">Update daemon is not updating feeds.</span>", true);
477                         return;
478                 }
479
480                 init_params[k] = v;                                     
481                 notify('');
482         }
483 }
484
485 function catchupCurrentFeed() {
486
487         var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
488         
489         var str = __("Mark all articles in %s as read?").replace("%s", fn);
490
491         if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
492                 return viewCurrentFeed('MarkAllRead')
493         }
494 }
495
496 function catchupFeedInGroup(id) {
497
498         try {
499
500                 var title = getFeedName(id);
501
502                 var str = __("Mark all articles in %s as read?").replace("%s", title);
503
504                 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
505                         return viewCurrentFeed('MarkAllReadGR:' + id)
506                 }
507
508         } catch (e) {
509                 exception_error("catchupFeedInGroup", e);
510         }
511 }
512
513 function editFeedDlg(feed) {
514         try {
515
516                 if (!feed) {
517                         alert(__("Please select some feed first."));
518                         return;
519                 }
520         
521                 if ((feed <= 0) || activeFeedIsCat()) {
522                         alert(__("You can't edit this kind of feed."));
523                         return;
524                 }
525         
526                 var query = "";
527         
528                 if (feed > 0) {
529                         query = "?op=pref-feeds&subop=editfeed&id=" +   param_escape(feed);
530                 } else {
531                         query = "?op=pref-labels&subop=edit&id=" +      param_escape(-feed-11);
532                 }
533
534                 disableHotkeys();
535
536                 notify_progress("Loading, please wait...", true);
537
538                 new Ajax.Request("backend.php", {
539                         parameters: query,
540                         onComplete: function(transport) { 
541                                 infobox_callback2(transport); 
542                                 document.forms["edit_feed_form"].title.focus();
543                         } });
544
545         } catch (e) {
546                 exception_error("editFeedDlg", e);
547         }
548 }
549
550 /* this functions duplicate those of prefs.js feed editor, with
551         some differences because there is no feedlist */
552
553 function feedEditCancel() {
554         closeInfoBox();
555         return false;
556 }
557
558 function feedEditSave() {
559
560         try {
561         
562                 // FIXME: add parameter validation
563
564                 var query = Form.serialize("edit_feed_form");
565
566                 notify_progress("Saving feed...");
567
568                 new Ajax.Request("backend.php", {
569                         parameters: query,
570                         onComplete: function(transport) { 
571                                 dlg_frefresh_callback(transport); 
572                         } });
573
574                 cache_flush();
575                 closeInfoBox();
576
577                 return false;
578
579         } catch (e) {
580                 exception_error("feedEditSave (main)", e);
581         } 
582 }
583
584 function collapse_feedlist() {
585         try {
586
587                 if (!Element.visible('feeds-holder')) {
588                         Element.show('feeds-holder');
589                         $("collapse_feeds_btn").innerHTML = "&lt;&lt;";
590                 } else {
591                         Element.hide('feeds-holder');
592                         $("collapse_feeds_btn").innerHTML = "&gt;&gt;";
593                 }
594
595                 dijit.byId("main").resize();
596
597                 query = "?op=rpc&subop=setpref&key=_COLLAPSED_FEEDLIST&value=true";
598                 new Ajax.Request("backend.php", { parameters: query });
599
600         } catch (e) {
601                 exception_error("collapse_feedlist", e);
602         }
603 }
604
605 function viewModeChanged() {
606         cache_flush();
607         return viewCurrentFeed('')
608 }
609
610 function viewLimitChanged() {
611         cache_flush();
612         return viewCurrentFeed('')
613 }
614
615 /* function adjustArticleScore(id, score) {
616         try {
617
618                 var pr = prompt(__("Assign score to article:"), score);
619
620                 if (pr != undefined) {
621                         var query = "?op=rpc&subop=setScore&id=" + id + "&score=" + pr;
622
623                         new Ajax.Request("backend.php", {
624                         parameters: query,
625                         onComplete: function(transport) {
626                                         viewCurrentFeed();
627                                 } });
628
629                 }
630         } catch (e) {
631                 exception_error("adjustArticleScore", e);
632         }
633 } */
634
635 function rescoreCurrentFeed() {
636
637         var actid = getActiveFeedId();
638
639         if (activeFeedIsCat() || actid < 0) {
640                 alert(__("You can't rescore this kind of feed."));
641                 return;
642         }       
643
644         if (!actid) {
645                 alert(__("Please select some feed first."));
646                 return;
647         }
648
649         var fn = getFeedName(actid);
650         var pr = __("Rescore articles in %s?").replace("%s", fn);
651
652         if (confirm(pr)) {
653                 notify_progress("Rescoring articles...");
654
655                 var query = "?op=pref-feeds&subop=rescore&quiet=1&ids=" + actid;
656
657                 new Ajax.Request("backend.php", {
658                         parameters: query,
659                         onComplete: function(transport) {
660                                 viewCurrentFeed();
661                         } });
662         }
663 }
664
665 function hotkey_handler(e) {
666
667         try {
668
669                 var keycode;
670                 var shift_key = false;
671
672                 var cmdline = $('cmdline');
673
674                 try {
675                         shift_key = e.shiftKey;
676                 } catch (e) {
677
678                 }
679         
680                 if (window.event) {
681                         keycode = window.event.keyCode;
682                 } else if (e) {
683                         keycode = e.which;
684                 }
685
686                 var keychar = String.fromCharCode(keycode);
687
688                 if (keycode == 27) { // escape
689                         if (Element.visible("hotkey_help_overlay")) {
690                                 Element.hide("hotkey_help_overlay");
691                         }
692                         hotkey_prefix = false;
693                         closeInfoBox();
694                 } 
695
696                 var dialog = dijit.byId("infoBox");
697                 var dialog_visible = false;
698
699                 if (dialog)
700                         dialog_visible = Element.visible(dialog.domNode);
701
702                 if (dialog_visible || !hotkeys_enabled) {
703                         console.log("hotkeys disabled");
704                         return;
705                 }
706
707                 if (keycode == 16) return; // ignore lone shift
708                 if (keycode == 17) return; // ignore lone ctrl
709
710                 if ((keycode == 70 || keycode == 67 || keycode == 71) 
711                                 && !hotkey_prefix) {
712
713                         var date = new Date();
714                         var ts = Math.round(date.getTime() / 1000);
715
716                         hotkey_prefix = keycode;
717                         hotkey_prefix_pressed = ts;
718
719                         cmdline.innerHTML = keychar;
720                         Element.show(cmdline);
721
722                         console.log("KP: PREFIX=" + keycode + " CHAR=" + keychar + " TS=" + ts);
723                         return true;
724                 }
725
726                 if (Element.visible("hotkey_help_overlay")) {
727                         Element.hide("hotkey_help_overlay");
728                 }
729
730                 /* Global hotkeys */
731
732                 Element.hide(cmdline);
733
734                 if (!hotkey_prefix) {
735
736                         if ((keycode == 191 || keychar == '?') && shift_key) { // ?
737                                 if (!Element.visible("hotkey_help_overlay")) {
738                                         Effect.Appear("hotkey_help_overlay", {duration : 0.3});
739                                 } else {
740                                         Element.hide("hotkey_help_overlay");
741                                 }
742                                 return false;
743                         }
744
745                         if (keycode == 191 || keychar == '/') { // /
746                                 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat(), 
747                                         function() { 
748                                                 document.forms['search_form'].query.focus();
749                                         });
750                                 return false;
751                         }
752
753                         if (keycode == 74) { // j
754                                 // TODO: move to previous feed
755                                 return;
756                         }
757         
758                         if (keycode == 75) { // k
759                                 // TODO: move to next feed
760                                 return;
761                         }
762
763                         if (shift_key && keycode == 40) { // shift-down
764                                 catchupRelativeToArticle(1);
765                                 return;
766                         }
767
768                         if (shift_key && keycode == 38) { // shift-up
769                                 catchupRelativeToArticle(0);
770                                 return;
771                         }
772
773                         if (shift_key && keycode == 78) { // N
774                                 scrollArticle(50);      
775                                 return;
776                         }
777
778                         if (shift_key && keycode == 80) { // P
779                                 scrollArticle(-50);     
780                                 return;
781                         }
782
783                         if (keycode == 68 && shift_key) { // shift-D
784                                 dismissSelectedArticles();
785                         }
786
787                         if (keycode == 88 && shift_key) { // shift-X
788                                 dismissReadArticles();
789                         }
790
791                         if (keycode == 78 || keycode == 40) { // n, down
792                                 if (typeof moveToPost != 'undefined') {
793                                         moveToPost('next');
794                                         return false;
795                                 }
796                         }
797         
798                         if (keycode == 80 || keycode == 38) { // p, up
799                                 if (typeof moveToPost != 'undefined') {
800                                         moveToPost('prev');
801                                         return false;
802                                 }
803                         }
804
805                         if (keycode == 83 && shift_key) { // S
806                                 selectionTogglePublished(undefined, false, true);
807                                 return;
808                         }
809
810                         if (keycode == 83) { // s
811                                 selectionToggleMarked(undefined, false, true);
812                                 return;
813                         }
814
815
816                         if (keycode == 85) { // u
817                                 selectionToggleUnread(undefined, false, true)
818                                 return;
819                         }
820
821                         if (keycode == 84 && shift_key) { // T
822                                 var id = getActiveArticleId();
823                                 if (id) {
824                                         editArticleTags(id, getActiveFeedId(), isCdmMode());
825                                         return;
826                                 }
827                         }
828
829                         if (keycode == 9) { // tab
830                                 var id = getArticleUnderPointer();
831                                 if (id) {                               
832                                         var cb = $("RCHK-" + id);
833
834                                         if (cb) {
835                                                 cb.checked = !cb.checked;
836                                                 toggleSelectRowById(cb, "RROW-" + id);
837                                                 return false;
838                                         }
839                                 }
840                         }
841
842                         if (keycode == 79) { // o
843                                 if (getActiveArticleId()) {
844                                         openArticleInNewWindow(getActiveArticleId());
845                                         return;
846                                 }
847                         }
848
849                         if (keycode == 81 && shift_key) { // Q
850                                 if (typeof catchupAllFeeds != 'undefined') {
851                                         catchupAllFeeds();
852                                         return;
853                                 }
854                         }
855
856                         if (keycode == 88) { // x
857                                 if (activeFeedIsCat()) {
858                                         toggleCollapseCat(getActiveFeedId());
859                                 }
860                         }
861                 }
862
863                 /* Prefix f */
864
865                 if (hotkey_prefix == 70) { // f 
866
867                         hotkey_prefix = false;
868
869                         if (keycode == 81) { // q
870                                 if (getActiveFeedId()) {
871                                         catchupCurrentFeed();
872                                         return;
873                                 }
874                         }
875
876                         if (keycode == 82) { // r
877                                 if (getActiveFeedId()) {
878                                         viewfeed(getActiveFeedId(), "ForceUpdate", activeFeedIsCat());
879                                         return;
880                                 }
881                         }
882
883                         if (keycode == 65) { // a
884                                 toggleDispRead();
885                                 return false;
886                         }
887
888                         if (keycode == 85) { // u
889                                 if (getActiveFeedId()) {
890                                         viewfeed(getActiveFeedId(), "ForceUpdate");
891                                         return false;
892                                 }
893                         }
894
895                         if (keycode == 69) { // e
896                                 editFeedDlg(getActiveFeedId());
897                                 return false;
898                         }
899
900                         if (keycode == 83) { // s
901                                 quickAddFeed();
902                                 return false;
903                         }
904
905                         if (keycode == 67 && shift_key) { // C
906                                 if (typeof catchupAllFeeds != 'undefined') {
907                                         catchupAllFeeds();
908                                         return false;
909                                 }
910                         }
911
912                         if (keycode == 67) { // c
913                                 if (getActiveFeedId()) {
914                                         catchupCurrentFeed();
915                                         return false;
916                                 }
917                         }
918
919                         if (keycode == 87) { // w
920                                 feeds_sort_by_unread = !feeds_sort_by_unread;
921                                 return resort_feedlist();
922                         }
923
924                         if (keycode == 88) { // x
925                                 reverseHeadlineOrder();
926                                 return;
927                         }
928                 }
929
930                 /* Prefix c */
931
932                 if (hotkey_prefix == 67) { // c
933                         hotkey_prefix = false;
934
935                         if (keycode == 70) { // f
936                                 displayDlg('quickAddFilter', '',
937                                    function () {document.forms['filter_add_form'].reg_exp.focus();});
938                                 return false;
939                         }
940
941                         if (keycode == 76) { // l
942                                 addLabel();
943                                 return false;
944                         }
945
946                         if (keycode == 83) { // s
947                                 if (typeof collapse_feedlist != 'undefined') {
948                                         collapse_feedlist();
949                                         return false;
950                                 }
951                         }
952
953                         if (keycode == 77) { // m
954                                 // TODO: sortable feedlist
955                                 return;
956                         }
957
958                         if (keycode == 78) { // n
959                                 catchupRelativeToArticle(1);
960                                 return;
961                         }
962
963                         if (keycode == 80) { // p
964                                 catchupRelativeToArticle(0);
965                                 return;
966                         }
967
968
969                 }
970
971                 /* Prefix g */
972
973                 if (hotkey_prefix == 71) { // g
974
975                         hotkey_prefix = false;
976
977
978                         if (keycode == 65) { // a
979                                 viewfeed(-4);
980                                 return false;
981                         }
982
983                         if (keycode == 83) { // s
984                                 viewfeed(-1);
985                                 return false;
986                         }
987
988                         if (keycode == 80 && shift_key) { // P
989                                 gotoPreferences();
990                                 return false;
991                         }
992
993                         if (keycode == 80) { // p
994                                 viewfeed(-2);
995                                 return false;
996                         }
997
998                         if (keycode == 70) { // f
999                                 viewfeed(-3);
1000                                 return false;
1001                         }
1002
1003                         if (keycode == 84 && shift_key) { // T
1004                                 toggleTags();
1005                                 return false;
1006                         }
1007                 }
1008
1009                 /* Cmd */
1010
1011                 if (hotkey_prefix == 224 || hotkey_prefix == 91) { // f 
1012                         hotkey_prefix = false;
1013                         return;
1014                 }
1015
1016                 if (hotkey_prefix) {
1017                         console.log("KP: PREFIX=" + hotkey_prefix + " CODE=" + keycode + " CHAR=" + keychar);
1018                 } else {
1019                         console.log("KP: CODE=" + keycode + " CHAR=" + keychar);
1020                 }
1021
1022
1023         } catch (e) {
1024                 exception_error("hotkey_handler", e);
1025         }
1026 }
1027
1028 function inPreferences() {
1029         return false;
1030 }
1031
1032 function reverseHeadlineOrder() {
1033         try {
1034
1035                 var query_str = "?op=rpc&subop=togglepref&key=REVERSE_HEADLINES";
1036
1037                 new Ajax.Request("backend.php", {
1038                         parameters: query_str,
1039                         onComplete: function(transport) { 
1040                                         viewCurrentFeed();
1041                                 } });
1042
1043         } catch (e) {
1044                 exception_error("reverseHeadlineOrder", e);
1045         }
1046 }
1047
1048 function showFeedsWithErrors() {
1049         displayDlg('feedUpdateErrors');
1050 }
1051
1052 function handle_rpc_reply(transport, scheduled_call) {
1053         try {
1054                 if (transport.responseXML) {
1055
1056                         if (!transport_error_check(transport)) return false;
1057
1058                         var seq = transport.responseXML.getElementsByTagName("seq")[0];
1059
1060                         if (seq) {
1061                                 seq = seq.firstChild.nodeValue;
1062
1063                                 if (get_seq() != seq) {
1064                                         //console.log("[handle_rpc_reply] sequence mismatch: " + seq);
1065                                         return true;
1066                                 }
1067                         }
1068
1069                         var message = transport.responseXML.getElementsByTagName("message")[0];
1070
1071                         if (message) {
1072                                 message = message.firstChild.nodeValue;
1073
1074                                 if (message == "UPDATE_COUNTERS") {
1075                                         console.log("need to refresh counters...");
1076                                         setInitParam("last_article_id", -1);
1077                                         _force_scheduled_update = true;
1078                                 }
1079                         }
1080
1081                         var counters = transport.responseXML.getElementsByTagName("counters")[0];
1082         
1083                         if (counters)
1084                                 parse_counters(counters, scheduled_call);
1085
1086                         var runtime_info = transport.responseXML.getElementsByTagName("runtime-info")[0];
1087
1088                         if (runtime_info)
1089                                 parse_runtime_info(runtime_info);
1090
1091                         hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
1092
1093                 } else {
1094                         notify_error("Error communicating with server.");
1095                 }
1096
1097         } catch (e) {
1098                 exception_error("handle_rpc_reply", e, transport);
1099         }
1100
1101         return true;
1102 }
1103
1104 function scheduleFeedUpdate() {
1105         try {
1106
1107                 if (!getActiveFeedId()) {
1108                         alert(__("Please select some feed first."));
1109                         return;
1110                 }
1111
1112                 var query = "?op=rpc&subop=scheduleFeedUpdate&id=" + 
1113                         param_escape(getActiveFeedId()) +
1114                         "&is_cat=" + param_escape(activeFeedIsCat());
1115
1116                 console.log(query);
1117
1118                 new Ajax.Request("backend.php", {
1119                         parameters: query,
1120                         onComplete: function(transport) { 
1121
1122                                 if (transport.responseXML) {
1123                                         var message = transport.responseXML.getElementsByTagName("message")[0];
1124
1125                                         if (message) {
1126                                                 notify_info(message.firstChild.nodeValue);
1127                                                 return;
1128                                         }
1129                                 }
1130
1131                                 notify_error("Error communicating with server.");
1132
1133                         } });
1134
1135
1136         } catch (e) {
1137                 exception_error("scheduleFeedUpdate", e);
1138         }
1139 }