Пример #1
0
static void
test_input (const gchar* input,
            const gchar* expected)
{
    static KatzeArray* search_engines = NULL;
    if (G_UNLIKELY (!search_engines))
    {
        KatzeItem* item;

        search_engines = katze_array_new (KATZE_TYPE_ITEM);
        item = g_object_new (KATZE_TYPE_ITEM,
                             "uri", SM "%s",
                             "token", "sm", NULL);
        katze_array_add_item (search_engines, item);
        g_object_unref (item);
        item = g_object_new (KATZE_TYPE_ITEM,
                             "uri", SM,
                             "token", "se", NULL);
        katze_array_add_item (search_engines, item);
        g_object_unref (item);
    }

    gchar* uri = sokoke_magic_uri (input, search_engines);
    if (g_strcmp0 (uri, expected))
    {
        g_error ("Input: %s\nExpected: %s\nResult: %s",
                 input ? input : "NULL",
                 expected ? expected : "NULL",
                 uri ? uri : "NULL");
    }
    g_free (uri);
}
Пример #2
0
static void midorator_history_fill(KatzeArray *a, sqlite3 *db, const char *table, const char *field) {
    sqlite3_stmt* stmt;
    char *cmd = g_strdup_printf("SELECT %s FROM %s ORDER BY id;", field, table);
    sqlite3_prepare_v2(db, cmd, -1, &stmt, NULL);
    g_free(cmd);
    while (sqlite3_step(stmt) == SQLITE_ROW) {
        char *cmd = g_strdup(sqlite3_column_text(stmt, 0));
        katze_array_add_item(a, cmd);
    }
    sqlite3_finalize(stmt);
}
Пример #3
0
static void midorator_entry_history_add(MidoratorEntry* e, const char *str) {
	if (!str)
		str = gtk_entry_get_text(GTK_ENTRY(e));
	KatzeArray *c = e->command_history;
	if (!c)
		return;
	if (!katze_array_is_a(c, G_TYPE_STRING))
		return;
	int i, l = katze_array_get_length(c);
	for (i = 0; i < l; i++)
		if (strcmp(katze_array_get_nth_item(c, i), str) == 0) {
			katze_array_move_item(c, katze_array_get_nth_item(c, i), l);
			return;
		}
	katze_array_add_item(c, g_strdup(str));
	while (katze_array_get_length(c) > 256) {
		char *i = katze_array_get_nth_item(c, 0);
		g_free(i);
		katze_array_remove_item(c, i);
	}
}
Пример #4
0
KatzeArray* midorator_history_get_bookmarks(MidoriApp* app) {
    KatzeArray *bookmarks = NULL;
    KatzeArray *ret = katze_array_new(KATZE_TYPE_ITEM);
    g_object_get(app, "bookmarks", &bookmarks, NULL);
    sqlite3 *db = g_object_get_data(bookmarks, "db");
    if (!db)
        return g_object_ref(bookmarks);
    sqlite3_stmt* stmt;
    sqlite3_prepare_v2(db, "SELECT title, uri, desc FROM bookmarks;", -1, &stmt, NULL);
    while (sqlite3_step(stmt) == SQLITE_ROW) {
        const char *title = sqlite3_column_text(stmt, 0);
        const char *uri = sqlite3_column_text(stmt, 1);
        const char *desc = sqlite3_column_text(stmt, 2);
        KatzeItem *it = katze_item_new();
        katze_item_set_uri(it, uri);
        katze_item_set_text(it, desc);
        katze_item_set_name(it, title);
        katze_array_add_item(ret, it);
        g_object_unref(it);
    }
    sqlite3_finalize(stmt);
    return ret;
}