1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
3 * Copyright (C) 2006 Jonathan Matthew <jonathan@kaolin.hn.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22 * Test client for out-of-process metadata reader.
31 #include "rb-metadata.h"
32 #include "rb-metadata-dbus.h"
35 static RBMetaData
*md
= NULL
;
37 static gboolean debug
= FALSE
;
38 static gboolean can_save
= FALSE
;
40 static GOptionEntry entries
[] = {
41 { "debug", 0, 0, G_OPTION_ARG_NONE
, &debug
, NULL
, NULL
},
42 { "can-save", 0, 0, G_OPTION_ARG_NONE
, &can_save
, NULL
, NULL
},
47 print_metadata_string (RBMetaData
*md
, RBMetaDataField field
, const char *name
)
50 if (rb_metadata_get (md
, field
, &v
)) {
53 s
= g_strdup_value_contents (&v
);
54 printf ("%s: %s\n", name
, s
);
61 check_can_save_cb (gpointer mt
)
63 char *mimetype
= (char *)mt
;
65 if (rb_metadata_can_save (md
, mimetype
)) {
66 printf ("Can save %s\n", mimetype
);
68 printf ("Unable to save %s\n", mimetype
);
75 load_metadata_cb (gpointer file
)
77 char *uri
= (char *)file
;
80 if (strncmp (uri
, "file://", 7)) {
82 uri
= g_strdup_printf ("file://%s", uri
);
85 if (getcwd (buf
, sizeof (buf
)) != NULL
)
86 uri
= g_strdup_printf ("file://%s/%s", buf
, uri
);
89 printf ("%s\n", (const char *)uri
);
91 rb_metadata_load (md
, (const char *)uri
, &error
);
94 switch (error
->code
) {
95 case RB_METADATA_ERROR_NOT_AUDIO_IGNORE
:
96 printf ("file ignored: %s\n", error
->message
);
99 printf ("error: %s\n", error
->message
);
102 g_clear_error (&error
);
106 printf ("type: %s\n", rb_metadata_get_mime (md
));
107 for (f
=(RBMetaDataField
)0; f
< RB_METADATA_FIELD_LAST
; f
++)
108 print_metadata_string (md
, f
, rb_metadata_get_field_name (f
));
117 g_main_loop_quit ((GMainLoop
*)nah
);
121 int main(int argc
, char **argv
)
125 GOptionContext
*context
;
127 GError
*error
= NULL
;
131 context
= g_option_context_new (NULL
);
132 g_option_context_add_main_entries (context
, entries
, NULL
);
133 retval
= g_option_context_parse (context
, &argc
, &argv
, &error
);
135 g_option_context_free (context
);
138 g_warning ("%s", error
->message
);
139 g_error_free (error
);
144 rb_debug_init (TRUE
);
148 g_idle_add (check_can_save_cb
, argv
[2]);
151 loop
= g_main_loop_new (NULL
, FALSE
);
152 md
= rb_metadata_new ();
153 while (argv
[1] != NULL
) {
154 g_idle_add (load_metadata_cb
, argv
[1]);
158 g_idle_add (bye
, loop
);
160 g_main_loop_run (loop
);
162 printf ("%d file(s) read\n", filecount
);
163 g_object_unref (G_OBJECT (md
));