~ubuntu-branches/ubuntu/trusty/gnome-documents/trusty

« back to all changes in this revision

Viewing changes to src/trackerUtils.js

  • Committer: Package Import Robot
  • Author(s): Andreas Henriksson, Thomas Bechtold
  • Date: 2013-04-04 13:32:08 UTC
  • mfrom: (3.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20130404133208-n19gqczi05z31ogb
Tags: 3.8.0-1
[ Thomas Bechtold ]
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 */
21
21
 
22
22
const GLib = imports.gi.GLib;
 
23
const Lang = imports.lang;
23
24
 
24
 
const Global = imports.global;
 
25
const Application = imports.application;
25
26
 
26
27
function setEditedName(newTitle, docId, callback) {
27
28
    let sparql = ('INSERT OR REPLACE { <%s> nie:title \"%s\" }'.format(docId, newTitle));
28
29
 
29
 
    Global.connectionQueue.update(sparql, null,
 
30
    Application.connectionQueue.update(sparql, null,
30
31
        function(object, res) {
31
32
            try {
32
33
                object.update_finish(res);
39
40
        });
40
41
 
41
42
}
 
43
 
 
44
const SingleItemJob = new Lang.Class({
 
45
    Name: 'SingleItemJob',
 
46
 
 
47
    _init: function(urn, queryBuilder) {
 
48
        this._urn = urn;
 
49
        this._cursor = null;
 
50
        this._builder = queryBuilder;
 
51
    },
 
52
 
 
53
    run: function(flags, callback) {
 
54
        this._callback = callback;
 
55
 
 
56
        let query = this._builder.buildSingleQuery(flags, this._urn);
 
57
        Application.connectionQueue.add(query.sparql, null, Lang.bind(this,
 
58
            function(object, res) {
 
59
                try {
 
60
                    let cursor = object.query_finish(res);
 
61
                    cursor.next_async(null, Lang.bind(this, this._onCursorNext));
 
62
                } catch (e) {
 
63
                    log('Unable to query single item ' + e.message);
 
64
                    this._emitCallback();
 
65
                }
 
66
            }));
 
67
    },
 
68
 
 
69
    _onCursorNext: function(cursor, res) {
 
70
        let valid = false;
 
71
 
 
72
        try {
 
73
            valid = cursor.next_finish(res);
 
74
        } catch (e) {
 
75
            log('Unable to query single item ' + e.message);
 
76
        }
 
77
 
 
78
        if (!valid) {
 
79
            cursor.close();
 
80
            this._emitCallback();
 
81
 
 
82
            return;
 
83
        }
 
84
 
 
85
        this._cursor = cursor;
 
86
        this._emitCallback();
 
87
        cursor.close();
 
88
    },
 
89
 
 
90
    _emitCallback: function() {
 
91
        this._callback(this._cursor);
 
92
    }
 
93
});