Ejemplo n.º 1
0
static void
audit_exit (GvaProcess *process,
            gint status,
            GvaAuditData *data)
{
        gchar *sql;
        GError *error = NULL;

        if (process->error != NULL)
                return;

        gva_db_transaction_begin (&error);
        gva_error_handle (&error);

        sql = g_strdup_printf ("UPDATE game SET %s=NULL", data->column);
        gva_db_execute (sql, &error);
        gva_error_handle (&error);
        g_free (sql);

        g_hash_table_foreach (
                data->status_index, (GHFunc) audit_exit_foreach, data);

        gva_db_transaction_commit (&error);
        gva_error_handle (&error);
}
Ejemplo n.º 2
0
static gboolean
wnck_window_timeout_cb (WnckWindow *window)
{
        const gchar *game;
        gint x, y;
        gint width, height;
        gchar *sql;
        GError *error = NULL;

        if (wnck_window_is_fullscreen (window))
                goto exit;

        game = wnck_window_get_game (window);
        wnck_window_get_geometry (window, &x, &y, &width, &height);

        if (wnck_window_is_maximized (window))
                sql = g_strdup_printf (
                        "UPDATE window SET maximized = 1 "
                        "WHERE name = '%s'", game);
        else
                sql = g_strdup_printf (
                        "UPDATE window SET x = %d, y = %d, width = %d, "
                        "height = %d, maximized = 0 WHERE name = '%s'",
                        x, y, width, height, game);

        gva_db_execute (sql, &error);
        gva_error_handle (&error);
        g_free (sql);

exit:
        g_object_set_data (G_OBJECT (window), TIMEOUT_SOURCE_ID_KEY, NULL);

        return FALSE;
}
Ejemplo n.º 3
0
/* Helper for audit_exit() */
static void
audit_exit_foreach (gchar *status,
                    GString *names,
                    GvaAuditData *data)
{
        gchar *sql;
        GError *error = NULL;

        sql = g_strdup_printf (
                "UPDATE game SET %s=\"%s\" WHERE name IN (%s)",
                data->column, status, names->str);
        gva_db_execute (sql, &error);
        gva_error_handle (&error);
        g_free (sql);
}
Ejemplo n.º 4
0
/**
 * gva_play_back_window_hide_cb:
 * @window: the "Recorded Games" window
 *
 * Handler for #GtkWidget::hide signals to the "Recorded Games" window.
 *
 * Saves the contents of the "Recorded Games" tree view to the game database.
 **/
void
gva_play_back_window_hide_cb (GtkWindow *window)
{
        GtkTreeView *view;
        GtkTreeModel *model;
        GtkTreeIter iter;
        sqlite3_stmt *stmt;
        gboolean valid;
        GError *error = NULL;

        view = GTK_TREE_VIEW (GVA_WIDGET_PLAY_BACK_TREE_VIEW);
        model = gtk_tree_view_get_model (view);
        valid = gtk_tree_model_get_iter_first (model, &iter);

        if (!gva_db_transaction_begin (&error))
                goto exit;

        if (!gva_db_execute (SQL_DELETE_PLAY_BACK, &error))
                goto rollback;

        if (!gva_db_prepare (SQL_INSERT_PLAY_BACK, &stmt, &error))
                goto rollback;

        while (valid)
        {
                gchar *comment;
                gchar *name;
                gchar *utf8;
                gint64 inode;
                gint index;
                gint errcode;

                gtk_tree_model_get (
                        model, &iter,
                        GVA_GAME_STORE_COLUMN_NAME, &name,
                        GVA_GAME_STORE_COLUMN_INODE, &inode,
                        GVA_GAME_STORE_COLUMN_COMMENT, &comment,
                        -1);

                index = sqlite3_bind_parameter_index (stmt, "@name");
                utf8 = g_locale_to_utf8 (name, -1, NULL, NULL, &error);
                gva_error_handle (&error);

                if (utf8 == NULL)
                {
                        g_free (name);
                        g_free (comment);
                        sqlite3_finalize (stmt);
                        goto rollback;
                }

                errcode = sqlite3_bind_text (stmt, index, utf8, -1, g_free);

                if (errcode != SQLITE_OK)
                {
                        g_free (name);
                        g_free (comment);
                        sqlite3_finalize (stmt);
                        goto rollback;
                }

                index = sqlite3_bind_parameter_index (stmt, "@inode");
                errcode = sqlite3_bind_int64 (stmt, index, inode);

                if (errcode != SQLITE_OK)
                {
                        g_free (name);
                        g_free (comment);
                        sqlite3_finalize (stmt);
                        goto rollback;
                }

                index = sqlite3_bind_parameter_index (stmt, "@comment");
                utf8 = g_locale_to_utf8 (comment, -1, NULL, NULL, &error);
                gva_error_handle (&error);

                if (utf8 == NULL)
                {
                        g_free (name);
                        g_free (comment);
                        sqlite3_finalize (stmt);
                        goto rollback;
                }

                errcode = sqlite3_bind_text (stmt, index, utf8, -1, g_free);

                if (errcode != SQLITE_OK)
                {
                        g_free (name);
                        g_free (comment);
                        sqlite3_finalize (stmt);
                        goto rollback;
                }

                g_free (name);
                g_free (comment);

                if (sqlite3_step (stmt) != SQLITE_DONE)
                {
                        gva_db_set_error (&error, 0, NULL);
                        gva_error_handle (&error);
                        sqlite3_finalize (stmt);
                        goto rollback;
                }

                sqlite3_reset (stmt);
                sqlite3_clear_bindings (stmt);

                valid = gtk_tree_model_iter_next (model, &iter);
        }

        sqlite3_finalize (stmt);

        if (!gva_db_transaction_commit (&error))
                goto rollback;

        goto exit;

rollback:
        gva_error_handle (&error);
        gva_db_transaction_rollback (&error);

exit:
        gva_error_handle (&error);
}
Ejemplo n.º 5
0
static void
wnck_window_initialize (WnckWindow *window)
{
        const gchar *game;
        sqlite3_stmt *stmt;
        gchar *sql;
        gint errcode;
        gboolean success;
        GError *error = NULL;

        game = wnck_window_get_game (window);

        sql = g_strdup_printf (SQL_SELECT_GAME_WINDOW, game);
        success = gva_db_prepare (sql, &stmt, &error);
        gva_error_handle (&error);
        g_free (sql);

        if (!success)
                return;

        errcode = sqlite3_step (stmt);

        /* Restore the window's previous geometry. */
        if (errcode == SQLITE_ROW)
        {
                gint x, y;
                gint width, height;
                gboolean maximized;

                x = sqlite3_column_int (stmt, COLUMN_X);
                y = sqlite3_column_int (stmt, COLUMN_Y);
                width = sqlite3_column_int (stmt, COLUMN_WIDTH);
                height = sqlite3_column_int (stmt, COLUMN_HEIGHT);
                maximized = sqlite3_column_int (stmt, COLUMN_MAXIMIZED);

                wnck_window_set_geometry (
                        window, WNCK_WINDOW_GRAVITY_CURRENT,
                        WNCK_WINDOW_CHANGE_X | WNCK_WINDOW_CHANGE_Y |
                        WNCK_WINDOW_CHANGE_WIDTH | WNCK_WINDOW_CHANGE_HEIGHT,
                        x, y, width, height);

                if (maximized)
                        wnck_window_maximize (window);
                else
                        wnck_window_unmaximize (window);
        }

        /* Create a new record using the current geometry. */
        else if (errcode == SQLITE_DONE)
        {
                gint x, y;
                gint width, height;
                gboolean maximized;

                maximized = wnck_window_is_maximized (window);
                wnck_window_get_geometry (window, &x, &y, &width, &height);

                sql = g_strdup_printf (
                        "INSERT INTO window VALUES "
                        "('%s', %d, %d, %d, %d, %d)",
                        game, x, y, width, height, maximized);
                gva_db_execute (sql, &error);
                gva_error_handle (&error);
                g_free (sql);
        }

        /* Something went wrong. */
        else
        {
                gva_db_set_error (&error, 0, NULL);
                gva_error_handle (&error);
        }

        sqlite3_finalize (stmt);
}