udapted vi.po
[rhythmbox.git] / tests / test-rhythmdb-view.c
blobedbffb9d4e4d2b9a82a041d970650d4c734b5656
1 /*
2 * arch-tag: Simple test for the RBEntryView widget
4 * Copyright (C) 2003 Colin Walters <walters@verbum.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include <glib.h>
22 #include <gtk/gtk.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include "rb-debug.h"
26 #include "rb-thread-helpers.h"
27 #include "rb-file-helpers.h"
28 #include "rb-stock-icons.h"
29 #include "rb-entry-view.h"
31 static RhythmDBEntry *
32 create_entry (RhythmDB *db,
33 const char *location, const char *name, const char *album,
34 const char *artist, const char *genre)
36 RhythmDBEntry *entry;
37 GValue val = {0, };
39 entry = rhythmdb_entry_new (db, RHYTHMDB_ENTRY_TYPE_SONG, location);
40 g_assert (entry);
41 g_value_init (&val, G_TYPE_STRING);
42 g_value_set_static_string (&val, genre);
43 rhythmdb_entry_set (db, entry, RHYTHMDB_PROP_GENRE, &val);
44 g_value_unset (&val);
46 g_value_init (&val, G_TYPE_STRING);
47 g_value_set_static_string (&val, artist);
48 rhythmdb_entry_set (db, entry, RHYTHMDB_PROP_ARTIST, &val);
49 g_value_unset (&val);
51 g_value_init (&val, G_TYPE_STRING);
52 g_value_set_static_string (&val, album);
53 rhythmdb_entry_set (db, entry, RHYTHMDB_PROP_ALBUM, &val);
54 g_value_unset (&val);
56 g_value_init (&val, G_TYPE_STRING);
57 g_value_set_static_string (&val, name);
58 rhythmdb_entry_set (db, entry, RHYTHMDB_PROP_TITLE, &val);
59 g_value_unset (&val);
61 return entry;
64 static void
65 completed_cb (RhythmDBQueryModel *model, gboolean *complete)
67 rb_debug ("query complete");
68 *complete = TRUE;
71 static void
72 wait_for_model_completion (RhythmDBQueryModel *model)
74 gboolean complete = FALSE;
75 GTimeVal timeout;
76 g_signal_connect (G_OBJECT (model), "complete",
77 G_CALLBACK (completed_cb), &complete);
79 while (!complete) {
80 g_get_current_time (&timeout);
81 g_time_val_add (&timeout, G_USEC_PER_SEC);
83 rb_debug ("polling model for changes");
84 rhythmdb_query_model_sync (model, &timeout);
85 g_usleep (G_USEC_PER_SEC / 10.0);
89 int
90 main (int argc, char **argv)
92 GtkWidget *main_window;
93 GtkTreeModel *main_model;
94 GtkTreeIter iter;
95 RBEntryView *view;
96 RhythmDB *db;
97 RhythmDBEntry *entry;
99 gtk_init (&argc, &argv);
100 g_thread_init (NULL);
101 gdk_threads_init ();
102 rb_thread_helpers_init ();
103 rb_file_helpers_init ();
104 rb_stock_icons_init ();
105 rb_debug_init (TRUE);
107 GDK_THREADS_ENTER ();
109 db = rhythmdb_tree_new ("test");
111 rhythmdb_write_lock (db);
113 entry = create_entry (db, "file:///sin.mp3",
114 "Sin", "Pretty Hate Machine", "Nine Inch Nails", "Rock");
116 rhythmdb_write_unlock (db);
118 rhythmdb_read_lock (db);
120 main_model = GTK_TREE_MODEL (rhythmdb_query_model_new_empty (db));
121 rhythmdb_do_full_query (db, main_model,
122 RHYTHMDB_QUERY_PROP_EQUALS,
123 RHYTHMDB_PROP_TYPE, RHYTHMDB_ENTRY_TYPE_SONG,
124 RHYTHMDB_QUERY_END);
126 wait_for_model_completion (RHYTHMDB_QUERY_MODEL (main_model));
127 g_assert (gtk_tree_model_get_iter_first (main_model, &iter));
129 main_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
131 view = rb_entry_view_new (db, rb_file ("rb-entry-view-library.xml"));
133 rb_entry_view_set_query_model (view, RHYTHMDB_QUERY_MODEL (main_model));
135 gtk_container_add (GTK_CONTAINER (main_window), GTK_WIDGET (view));
137 g_signal_connect (G_OBJECT (main_window), "destroy",
138 G_CALLBACK (gtk_main_quit), NULL);
140 gtk_widget_show_all (GTK_WIDGET (main_window));
142 gtk_main ();
144 rhythmdb_shutdown (db);
145 g_object_unref (G_OBJECT (db));
146 GDK_THREADS_LEAVE ();
148 exit (0);