[gnome-video-arcade] audit: Give the audit window its own tree store
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-video-arcade] audit: Give the audit window its own tree store
- Date: Mon, 14 Sep 2015 18:20:20 +0000 (UTC)
commit b4008d46ef7568f9146773cf0e07ad1c840b5c10
Author: Matthew Barnes <mbarnes redhat com>
Date: Mon Sep 14 09:37:07 2015 -0400
audit: Give the audit window its own tree store
I want to convert GvaGameStore back to a list store.
The audit window was the reason I converted GvaGameStore to a tree store,
thinking how neat it would be to reuse the same model class for the main
window and audit window. But I think it suffered a big performance hit
as a result. It was a dumb reason in retrospect.
data/gnome-video-arcade.builder | 20 ++++++
docs/reference/gnome-video-arcade-sections.txt | 1 -
src/gva-audit.c | 83 +++++++++++-------------
src/gva-audit.h | 1 -
src/main.c | 1 -
5 files changed, 59 insertions(+), 47 deletions(-)
---
diff --git a/data/gnome-video-arcade.builder b/data/gnome-video-arcade.builder
index 9010cfe..1aa2410 100644
--- a/data/gnome-video-arcade.builder
+++ b/data/gnome-video-arcade.builder
@@ -3,6 +3,12 @@
<interface>
<requires lib="gtk+" version="3.0"/>
<requires lib="gva" version="0.0"/>
+ <object class="GtkTreeStore" id="audit-tree-store">
+ <columns>
+ <!-- column-name description -->
+ <column type="gchararray"/>
+ </columns>
+ </object>
<object class="GtkActionGroup" id="lockable-actions">
<child>
<object class="GtkAction" id="insert-favorite">
@@ -577,10 +583,24 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK |
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="model">audit-tree-store</property>
<property name="headers_visible">False</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection"/>
</child>
+ <child>
+ <object class="GtkTreeViewColumn" id="audit-tree-view-column">
+ <property name="spacing">3</property>
+ <child>
+ <object class="GtkCellRendererText" id="audit-text-renderer">
+ <property name="ellipsize">end</property>
+ </object>
+ <attributes>
+ <attribute name="text">0</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
</object>
</child>
</object>
diff --git a/docs/reference/gnome-video-arcade-sections.txt b/docs/reference/gnome-video-arcade-sections.txt
index 9d8bc87..ed644b8 100644
--- a/docs/reference/gnome-video-arcade-sections.txt
+++ b/docs/reference/gnome-video-arcade-sections.txt
@@ -1,6 +1,5 @@
<SECTION>
<FILE>gva-audit</FILE>
-gva_audit_init
gva_audit_roms
gva_audit_samples
gva_audit_save_errors
diff --git a/src/gva-audit.c b/src/gva-audit.c
index ae4ecb5..168ba5c 100644
--- a/src/gva-audit.c
+++ b/src/gva-audit.c
@@ -83,27 +83,41 @@ audit_data_free (GvaAuditData *data)
g_slice_free (GvaAuditData, data);
}
-static GtkTreeModel *
-audit_build_model (GvaAuditData *data,
+static gboolean
+audit_build_model (GtkTreeStore *tree_store,
+ GvaAuditData *data,
GError **error)
{
- GtkTreeModel *model;
+ GtkTreeModel *game_store;
GtkTreeIter iter;
gboolean iter_valid;
- model = gva_game_store_new_from_query (SQL_SELECT_BAD_GAMES, error);
- if (model == NULL)
- return NULL;
+ game_store = gva_game_store_new_from_query (
+ SQL_SELECT_BAD_GAMES, error);
+ if (game_store == NULL)
+ return FALSE;
- iter_valid = gtk_tree_model_get_iter_first (model, &iter);
+ gtk_tree_store_clear (tree_store);
+
+ iter_valid = gtk_tree_model_get_iter_first (game_store, &iter);
while (iter_valid)
{
+ GtkTreeIter parent;
GtkTreeIter child;
guint index;
gchar *name;
+ gchar *description;
+
+ gtk_tree_model_get (
+ game_store, &iter,
+ GVA_GAME_STORE_COLUMN_NAME, &name,
+ GVA_GAME_STORE_COLUMN_DESCRIPTION, &description,
+ -1);
+
+ gtk_tree_store_append (tree_store, &parent, NULL);
+ gtk_tree_store_set (tree_store, &parent, 0, description, -1);
- gtk_tree_model_get (model, &iter, 0, &name, -1);
index = GPOINTER_TO_UINT (g_hash_table_lookup (
data->output_index, name));
@@ -116,23 +130,22 @@ audit_build_model (GvaAuditData *data,
if (!g_str_has_prefix (line, name))
break;
- gtk_tree_store_prepend (
- GTK_TREE_STORE (model), &child, &iter);
- gtk_tree_store_set (
- GTK_TREE_STORE (model), &child,
- GVA_GAME_STORE_COLUMN_DESCRIPTION, line, -1);
+ gtk_tree_store_prepend (tree_store, &child, &parent);
+ gtk_tree_store_set (tree_store, &child, 0, line, -1);
}
g_free (name);
+ g_free (description);
- iter_valid = gtk_tree_model_iter_next (model, &iter);
+ iter_valid = gtk_tree_model_iter_next (game_store, &iter);
}
gtk_tree_sortable_set_sort_column_id (
- GTK_TREE_SORTABLE (model),
- GVA_GAME_STORE_COLUMN_DESCRIPTION, GTK_SORT_ASCENDING);
+ GTK_TREE_SORTABLE (tree_store), 0, GTK_SORT_ASCENDING);
- return model;
+ g_object_unref (game_store);
+
+ return TRUE;
}
static void
@@ -283,44 +296,27 @@ audit_show_dialog (GvaProcess *process,
gint status,
GvaAuditData *data)
{
- GtkTreeView *view;
+ GtkTreeView *tree_view;
GtkTreeModel *model;
GError *error = NULL;
if (process->error != NULL)
return;
- model = audit_build_model (data, &error);
- gva_error_handle (&error);
- if (model == NULL)
- return;
+ tree_view = GTK_TREE_VIEW (GVA_WIDGET_AUDIT_TREE_VIEW);
+ model = gtk_tree_view_get_model (tree_view);
- view = GTK_TREE_VIEW (GVA_WIDGET_AUDIT_TREE_VIEW);
- gtk_tree_view_set_model (view, model);
+ if (!audit_build_model (GTK_TREE_STORE (model), data, &error))
+ {
+ gva_error_handle (&error);
+ return;
+ }
if (gtk_tree_model_iter_n_children (model, NULL) > 0)
gtk_window_present (GTK_WINDOW (GVA_WIDGET_AUDIT_WINDOW));
}
/**
- * gva_audit_init:
- *
- * Initializes the ROM audit window.
- *
- * This function should be called once when the application starts.
- **/
-void
-gva_audit_init (void)
-{
- GtkTreeViewColumn *column;
- GtkTreeView *view;
-
- view = GTK_TREE_VIEW (GVA_WIDGET_AUDIT_TREE_VIEW);
- column = gva_columns_new_from_id (GVA_GAME_STORE_COLUMN_DESCRIPTION);
- gtk_tree_view_append_column (view, column);
-}
-
-/**
* gva_audit_roms:
* @error: return location for a #GError, or %NULL
*
@@ -410,8 +406,7 @@ audit_save_errors_foreach (GtkTreeModel *model,
{
gchar *text;
- gtk_tree_model_get (
- model, iter, GVA_GAME_STORE_COLUMN_DESCRIPTION, &text, -1);
+ gtk_tree_model_get (model, iter, 0, &text, -1);
if (gtk_tree_path_get_depth (path) > 1)
g_string_append_len (contents, " ", 2);
g_string_append_printf (contents, "%s\n", text);
diff --git a/src/gva-audit.h b/src/gva-audit.h
index 1544854..6f9b004 100644
--- a/src/gva-audit.h
+++ b/src/gva-audit.h
@@ -32,7 +32,6 @@
G_BEGIN_DECLS
-void gva_audit_init (void);
GvaProcess * gva_audit_roms (GError **error);
GvaProcess * gva_audit_samples (GError **error);
void gva_audit_save_errors (void);
diff --git a/src/main.c b/src/main.c
index 9811a33..34abca0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -449,7 +449,6 @@ main (gint argc, gchar **argv)
if (!gva_db_init (&error))
g_error ("%s", error->message);
- gva_audit_init ();
gva_main_init ();
gva_play_back_init ();
gva_preferences_init ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]