2
* Copyright (C) 2007 Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
4
* Authors: Zeeshan Ali (Khattak) <zeeshanak@gnome.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 along
17
* with this program; if not, write to the Free Software Foundation,
18
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
#include <libgupnp/gupnp.h>
26
#include "control_point.h"
27
#include "item-creation.h"
29
#include "container-search.h"
32
static GMainLoop *main_loop;
33
static GUPnPContext *upnp_context;
34
static GUPnPServiceProxy *cds_proxy;
36
static GList *files = NULL;
39
static char *title = NULL;
40
static char *dest_container = NULL;
41
static guint search_timeout = 0;
43
static GOptionEntry entries[] =
45
{ "search-timeout", 't', 0,
46
G_OPTION_ARG_INT, &search_timeout,
47
"Search Timeout", "seconds" },
48
{ "container-id", 'c', 0,
49
G_OPTION_ARG_STRING, &dest_container,
50
"Destination Container ID", "CONTAINER_ID" },
52
G_OPTION_ARG_STRING, &title,
53
"Title for item", "TITLE" },
60
files = g_list_next (files);
63
create_item ((char *) files->data,
69
/* Exit if there are no more files to upload */
75
transfer_completed (void)
81
container_found (const char *container_id)
83
dest_container = container_id;
85
/* Now create the item container */
86
create_item ((char *) files->data,
94
item_created (const char *import_uri) {
95
if (import_uri == NULL) {
96
/* Item creation failed, lets try next file */
99
start_transfer ((char *) files->data,
107
target_cds_found (GUPnPServiceProxy *target_cds_proxy)
109
cds_proxy = target_cds_proxy;
111
if (dest_container != NULL) {
112
container_found (dest_container);
114
/* Find a suitable container */
115
search_container (target_cds_proxy);
120
application_exit (void)
122
g_main_loop_quit (main_loop);
133
GOptionContext *context;
135
/* First thing initialize the thread system */
136
g_thread_init (NULL);
138
context = g_option_context_new ("- Upload file to UPnP MediaServer");
139
g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
140
if (!g_option_context_parse (context, &argc, &argv, &error))
142
g_print ("option parsing failed: %s\n", error->message);
147
g_print ("Usage: %s UDN FILE_PATH...\n", argv[0]);
154
/* Get the list of files to upload */
155
for (i = 2; i < argc; i++) {
156
if (!g_file_test (argv[i],
158
G_FILE_TEST_IS_REGULAR)) {
159
g_critical ("File %s does not exist", argv[i]);
161
files = g_list_append (files, argv[i]);
172
upnp_context = gupnp_context_new (NULL, NULL, 0, &error);
174
g_critical (error->message);
175
g_error_free (error);
180
if (!init_control_point (upnp_context, udn, search_timeout)) {
184
main_loop = g_main_loop_new (NULL, FALSE);
186
g_main_loop_run (main_loop);
189
g_main_loop_unref (main_loop);
190
deinit_control_point ();
191
g_object_unref (upnp_context);
192
g_option_context_free (context);