2
Copyright (C) 2013 André Stösel <andre@stoesel.de>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Lesser General Public
6
License as published by the Free Software Foundation; either
7
version 2.1 of the License, or (at your option) any later version.
9
See the file COPYING for the full license text.
13
private class Manager : Midori.Extension {
14
private bool bounce () {
16
Midori.App app = this.get_app ();
17
Midori.Browser? browser = app.browser;
19
if (browser == null || browser.tab == null) {
24
Midori.Database database = new Midori.Database ("flummi.db");
25
unowned Sqlite.Database db = database.db;
27
string sqlcmd = "SELECT id, once, command FROM tasks ORDER BY id;";
29
Sqlite.Statement stmt;
30
if (db.prepare_v2 (sqlcmd, -1, out stmt, null) != Sqlite.OK) {
31
GLib.critical (_("Failed to select from database: %s"), db.errmsg);
35
int result = stmt.step ();
36
if (!(result == Sqlite.DONE || result == Sqlite.ROW)) {
37
GLib.critical (_("Failed to select from database: %s"), db.errmsg);
41
Sqlite.Statement del_stmt;
42
sqlcmd = "DELETE FROM `tasks` WHERE id = :task_id;";
43
if (db.prepare_v2 (sqlcmd, -1, out del_stmt, null) != Sqlite.OK) {
44
critical (_("Failed to update database: %s"), db.errmsg ());
48
while (result == Sqlite.ROW) {
49
int64 id = stmt.column_int64 (0);
50
int64 once = stmt.column_int64 (1);
51
string command = stmt.column_text (2);
53
string[] commands = { command };
55
if (!app.send_command (commands)) {
56
GLib.critical ("Command faild: %s\n", command);
61
del_stmt.bind_int64 (del_stmt.bind_parameter_index (":task_id"), id);
62
if (del_stmt.step () != Sqlite.DONE) {
63
GLib.critical (_("Failed to delete record %lf.\nError: %s"), db.errmsg ());
68
result = stmt.step ();
70
} catch (Midori.DatabaseError schema_error) {
71
GLib.error (schema_error.message);
77
private void activated (Midori.App app) {
78
GLib.Idle.add (this.bounce);
82
GLib.Object (name: _("Flummi"),
83
description: _("This extensions provides a task queue for update jobs or recurring events."),
85
authors: "André Stösel <andre@stoesel.de>");
87
this.activate.connect (this.activated);
92
public Midori.Extension extension_init () {
93
return new Flummi.Manager ();