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.
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
)
39 entry
= rhythmdb_entry_new (db
, RHYTHMDB_ENTRY_TYPE_SONG
, location
);
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
);
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
);
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
);
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
);
65 completed_cb (RhythmDBQueryModel
*model
, gboolean
*complete
)
67 rb_debug ("query complete");
72 wait_for_model_completion (RhythmDBQueryModel
*model
)
74 gboolean complete
= FALSE
;
76 g_signal_connect (G_OBJECT (model
), "complete",
77 G_CALLBACK (completed_cb
), &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);
90 main (int argc
, char **argv
)
92 GtkWidget
*main_window
;
93 GtkTreeModel
*main_model
;
99 gtk_init (&argc
, &argv
);
100 g_thread_init (NULL
);
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
,
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
));
144 rhythmdb_shutdown (db
);
145 g_object_unref (G_OBJECT (db
));
146 GDK_THREADS_LEAVE ();