~qqworini/ubuntu-rssreader-app/alpha-1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import QtQuick 2.0

QtObject {
    id: rootObject

    property var __doc: null
    property bool inProgress: __doc != null

    signal findResult(var result)
    signal loadResult(var result)

    /* Find feed by keywords.
     */
    function findFeeds(searchKeywords) {
        abort()

        __doc = new XMLHttpRequest()
        var doc = __doc

        doc.onreadystatechange = function() {

            if (doc.readyState === XMLHttpRequest.DONE) {

                var resObj
                if (doc.status == 200) {
                    resObj = JSON.parse(doc.responseText)
                } else { // Error
                    resObj = {"responseDetails" : doc.statusText,
                        "responseStatus" : doc.status}
                }

                __doc = null
                findResult(resObj)
            }
        }

        var searchKeywordsEncoded = encodeURIComponent(searchKeywords)

        var baseUrl = "https://ajax.googleapis.com/ajax/services/feed/find?v=1.0&q="
        var finalRequest = baseUrl + searchKeywordsEncoded

        doc.open("GET", finalRequest, true);
        doc.send();
    }

    /* Load feed by URL.
     */
    function loadFeed(feedUrl, num) {
        abort()

        if (num)
            num = Math.min(num, 100)
        else num = 50

        __doc = new XMLHttpRequest()
        var doc = __doc

        doc.onreadystatechange = function() {

            if (doc.readyState === XMLHttpRequest.DONE) {

                var resObj
                if (doc.status == 200) {
                    resObj = JSON.parse(doc.responseText)
                } else { // Error
                    resObj = {"responseDetails" : doc.statusText,
                        "responseStatus" : doc.status}
                }

                __doc = null
                loadResult(resObj)
            }
        }

        var encodedUrl = encodeURIComponent(feedUrl)
        var baseUrl = "https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q="
        var finalRequest = baseUrl + encodedUrl

        /* Number of articles to download.
         */
        finalRequest += "&num=" + num

        /* Add some optional params.
         * May be usable:
         * hl       - host language, for example "hl=ru", default en.
         * num      - number of entries, for example "num=50", default 4, maximum 100.
         * output   - format of output, for example "output=json", may be xml, json_xml, json.
         */
        doc.open("GET", finalRequest, true);
        doc.send();
    }

    function abort() {
        if (__doc != null) {
            __doc.abort()
            //__doc = null // ?
        }
    }
} // QtObject googleFeedApi