~walkerlee/totem/pre-interview

« back to all changes in this revision

Viewing changes to src/plugins/publish/totem-publish.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-05-26 00:07:51 UTC
  • mfrom: (1.6.1) (24.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20130526000751-kv8ap3x1di4qq8j2
Tags: 3.8.2-0ubuntu1
* Sync with Debian. Remaining changes: 
* debian/control.in:
  - Drop build-depends on libepc-ui-dev and libgrilo-0.2-dev (in universe)
  - Drop libxtst-dev build-depends so that the (redundant) fake key presses
    for inhibiting the screensaver are disabled (LP: #1007438)
  - Build-depend on libzeitgeist-dev
  - Suggest rather than recommend gstreamer components in universe
  - Add totem-plugins-extra
  - Add XB-Npp-Description and XB-Npp-Filename header to the 
    totem-mozilla package to improve ubufox/ubuntu plugin db integration 
  - Refer to Firefox in totem-mozilla description instead of Iceweasel
  - Don't have totem-mozilla recommend any particular browser
  - Drop obsolete python library dependencies since iplayer is no longer
    included
* debian/totem-common.install, debian/source_totem.py:
  - Install Ubuntu apport debugging hook
* debian/totem-plugins-extra.install:
  - Universe plugins split out of totem-plugins (currently only gromit)
* debian/totem-plugins.install:    
  - Skip the plugins split to -extra and add the zeitgeist plugin
* debian/rules:
  - Build with --fail-missing, to ensure we install everything. 
    + Ignore libtotem.{,l}a since we delibrately don't install these.
  - Re-enable hardening, make sure both PIE and BINDNOW are used
    by setting hardening=+all. (LP: #1039604)
* debian/patches/91_quicklist_entries.patch:
  - Add static quicklist
* debian/patches/92_gst-plugins-good.patch:
  - Build without unnecessary gstreamer1.0-bad dependency
* debian/patches/93_grilo_optional.patch:
  - Allow building without grilo while grilo MIR is still pending
* debian/patches/correct_desktop_mimetypes.patch:
  - Don't list the mimetypes after the unity lists
* debian/patches/revert_shell_menu.patch: 
  - revert the use of a shell menu until indicator-appmenu can handle
    the mixed shell/traditional menus itself
* New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* * -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
 
/*
3
 
 * Copyright (C) 2007 Openismus GmbH
4
 
 *
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.
9
 
 *
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.
14
 
 *
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 Street, Fifth Floor, Boston, MA 02110-1301  USA.
18
 
 *
19
 
 * The Totem project hereby grant permission for non-gpl compatible GStreamer
20
 
 * plugins to be used and distributed together with GStreamer and Totem. This
21
 
 * permission are above and beyond the permissions granted by the GPL license
22
 
 * Totem is covered by.
23
 
 *
24
 
 * See license_change file for details.
25
 
 *
26
 
 * Author:
27
 
 *      Mathias Hasselmann
28
 
 *
29
 
 */
30
 
 
31
 
#include "config.h"
32
 
 
33
 
#include <glib-object.h>
34
 
#include <glib/gi18n-lib.h>
35
 
#include <gio/gio.h>
36
 
 
37
 
#include <libepc/consumer.h>
38
 
#include <libepc/enums.h>
39
 
#include <libepc/publisher.h>
40
 
#include <libepc/service-monitor.h>
41
 
#include <libepc-ui/progress-window.h>
42
 
 
43
 
#include <libpeas/peas-extension-base.h>
44
 
#include <libpeas/peas-object-module.h>
45
 
#include <libpeas/peas-activatable.h>
46
 
#include <libpeas-gtk/peas-gtk-configurable.h>
47
 
 
48
 
#include "totem-plugin.h"
49
 
#include "totem-private.h"
50
 
#include "totem-dirs.h"
51
 
#include "totem.h"
52
 
 
53
 
#define TOTEM_TYPE_PUBLISH_PLUGIN               (totem_publish_plugin_get_type ())
54
 
#define TOTEM_PUBLISH_PLUGIN(o)                 (G_TYPE_CHECK_INSTANCE_CAST ((o), TOTEM_TYPE_PUBLISH_PLUGIN, TotemPublishPlugin))
55
 
#define TOTEM_PUBLISH_PLUGIN_CLASS(k)           (G_TYPE_CHECK_CLASS_CAST((k), TOTEM_TYPE_PUBLISH_PLUGIN, TotemPublishPluginClass))
56
 
#define TOTEM_IS_PUBLISH_PLUGIN(o)              (G_TYPE_CHECK_INSTANCE_TYPE ((o), TOTEM_TYPE_PUBLISH_PLUGIN))
57
 
#define TOTEM_IS_PUBLISH_PLUGIN_CLASS(k)        (G_TYPE_CHECK_CLASS_TYPE ((k), TOTEM_TYPE_PUBLISH_PLUGIN))
58
 
#define TOTEM_PUBLISH_PLUGIN_GET_CLASS(o)       (G_TYPE_INSTANCE_GET_CLASS ((o), TOTEM_TYPE_PUBLISH_PLUGIN, TotemPublishPluginClass))
59
 
 
60
 
#define TOTEM_PUBLISH_SCHEMA                    TOTEM_GSETTINGS_SCHEMA ".plugins.publish"
61
 
 
62
 
enum
63
 
{
64
 
        NAME_COLUMN,
65
 
        INFO_COLUMN,
66
 
        LAST_COLUMN
67
 
};
68
 
 
69
 
typedef struct {
70
 
        TotemObject       *totem;
71
 
        GSettings         *gsettings;
72
 
        GtkWidget         *settings;
73
 
        GtkWidget         *scanning;
74
 
        GtkBuilder        *ui;
75
 
 
76
 
        EpcPublisher      *publisher;
77
 
        EpcServiceMonitor *monitor;
78
 
        GtkListStore      *neighbours;
79
 
        GSList            *playlist;
80
 
 
81
 
        guint scanning_id;
82
 
 
83
 
        gulong item_added_id;
84
 
        gulong item_removed_id;
85
 
} TotemPublishPluginPrivate;
86
 
 
87
 
TOTEM_PLUGIN_REGISTER_CONFIGURABLE (TOTEM_TYPE_PUBLISH_PLUGIN, TotemPublishPlugin, totem_publish_plugin);
88
 
 
89
 
void totem_publish_plugin_service_name_entry_changed_cb    (GtkEntry        *entry,
90
 
                                                            TotemPublishPlugin *self);
91
 
void totem_publish_plugin_encryption_button_toggled_cb     (GtkToggleButton *button,
92
 
                                                            TotemPublishPlugin *self);
93
 
void totem_publish_plugin_dialog_response_cb               (GtkDialog       *dialog,
94
 
                                                            gint             response,
95
 
                                                            gpointer         data);
96
 
void totem_publish_plugin_neighbours_list_row_activated_cb (GtkTreeView       *view,
97
 
                                                            GtkTreePath       *path,
98
 
                                                            GtkTreeViewColumn *column,
99
 
                                                            gpointer           data);
100
 
 
101
 
G_LOCK_DEFINE_STATIC(totem_publish_plugin_lock);
102
 
 
103
 
static void
104
 
totem_publish_plugin_name_changed_cb (GSettings *settings, const gchar *key, TotemPublishPlugin *self)
105
 
{
106
 
        gchar *pattern, *name;
107
 
 
108
 
        pattern = g_settings_get_string (settings, "name-format");
109
 
        name = epc_publisher_expand_name (pattern, NULL);
110
 
        g_free (pattern);
111
 
 
112
 
        epc_publisher_set_service_name (self->priv->publisher, name);
113
 
 
114
 
        g_free (name);
115
 
}
116
 
 
117
 
void
118
 
totem_publish_plugin_service_name_entry_changed_cb (GtkEntry *entry, TotemPublishPlugin *self)
119
 
{
120
 
        g_settings_set_string (self->priv->gsettings, "name-format", gtk_entry_get_text (entry));
121
 
}
122
 
 
123
 
void
124
 
totem_publish_plugin_encryption_button_toggled_cb (GtkToggleButton *button, TotemPublishPlugin *self)
125
 
{
126
 
        g_settings_set_string (self->priv->gsettings, "protocol", gtk_toggle_button_get_active (button) ? "https" : "http");
127
 
}
128
 
 
129
 
static void
130
 
totem_publish_plugin_protocol_changed_cb (GSettings *settings, const gchar *key, TotemPublishPlugin *self)
131
 
{
132
 
        gchar *protocol_name;
133
 
        EpcProtocol protocol;
134
 
        GError *error = NULL;
135
 
 
136
 
        protocol_name = g_settings_get_string (settings, "protocol");
137
 
        protocol = epc_protocol_from_name (protocol_name, EPC_PROTOCOL_HTTPS);
138
 
        g_free (protocol_name);
139
 
 
140
 
        epc_publisher_quit (self->priv->publisher);
141
 
        epc_publisher_set_protocol (self->priv->publisher, protocol);
142
 
        epc_publisher_run_async (self->priv->publisher, &error);
143
 
 
144
 
        if (error) {
145
 
                g_warning ("%s: %s", G_STRFUNC, error->message);
146
 
                g_error_free (error);
147
 
        }
148
 
}
149
 
 
150
 
static gchar*
151
 
totem_publish_plugin_build_key (const gchar *filename)
152
 
{
153
 
        return g_strconcat ("media/", filename, NULL);
154
 
}
155
 
 
156
 
static EpcContents*
157
 
totem_publish_plugin_playlist_cb (EpcPublisher *publisher,
158
 
                                  const gchar  *key,
159
 
                                  gpointer      data)
160
 
{
161
 
        TotemPublishPlugin *self = TOTEM_PUBLISH_PLUGIN (data);
162
 
        GString *buffer = g_string_new (NULL);
163
 
        EpcContents *contents = NULL;
164
 
        GSList *iter;
165
 
        gint i;
166
 
 
167
 
        G_LOCK (totem_publish_plugin_lock);
168
 
 
169
 
        g_string_append_printf (buffer,
170
 
                                "[playlist]\nNumberOfEntries=%d\n",
171
 
                                g_slist_length (self->priv->playlist));
172
 
 
173
 
        for (iter = self->priv->playlist, i = 1; iter; iter = iter->next, ++i) {
174
 
                gchar *file_key = iter->data;
175
 
                gchar *uri;
176
 
 
177
 
                uri = epc_publisher_get_uri (publisher, file_key, NULL);
178
 
 
179
 
                g_string_append_printf (buffer,
180
 
                                        "File%d=%s\nTitle%d=%s\n",
181
 
                                        i, uri, i, file_key + 6);
182
 
 
183
 
                g_free (uri);
184
 
        }
185
 
 
186
 
        G_UNLOCK (totem_publish_plugin_lock);
187
 
 
188
 
        contents = epc_contents_new ("audio/x-scpls",
189
 
                                     buffer->str, buffer->len,
190
 
                                     g_free);
191
 
 
192
 
        g_string_free (buffer, FALSE);
193
 
 
194
 
        return contents;
195
 
}
196
 
 
197
 
static gboolean
198
 
totem_publish_plugin_stream_cb (EpcContents *contents,
199
 
                                gpointer     buffer,
200
 
                                gsize       *length,
201
 
                                gpointer     data)
202
 
{
203
 
        GInputStream *stream = data;
204
 
        gssize size = 65536;
205
 
 
206
 
        g_return_val_if_fail (NULL != contents, FALSE);
207
 
        g_return_val_if_fail (NULL != length, FALSE);
208
 
 
209
 
        if (NULL == data || *length < (gsize)size) {
210
 
                *length = MAX (*length, (gsize)size);
211
 
                return FALSE;
212
 
        }
213
 
 
214
 
        size = g_input_stream_read (stream, buffer, size, NULL, NULL);
215
 
        if (size == -1) {
216
 
                g_input_stream_close (stream, NULL, NULL);
217
 
                size = 0;
218
 
        }
219
 
 
220
 
        *length = size;
221
 
 
222
 
        return size > 0;
223
 
}
224
 
 
225
 
static EpcContents*
226
 
totem_publish_plugin_media_cb (EpcPublisher *publisher,
227
 
                               const gchar  *key,
228
 
                               gpointer      data)
229
 
{
230
 
        GFileInputStream *stream;
231
 
        const gchar *url = data;
232
 
        GFile *file;
233
 
 
234
 
        file = g_file_new_for_uri (url);
235
 
        stream = g_file_read (file, NULL, NULL);
236
 
        g_object_unref (file);
237
 
 
238
 
        if (stream) {
239
 
                EpcContents *output = epc_contents_stream_new (
240
 
                        NULL, totem_publish_plugin_stream_cb,
241
 
                        stream, g_object_unref);
242
 
 
243
 
                return output;
244
 
        }
245
 
 
246
 
        return NULL;
247
 
}
248
 
 
249
 
static void
250
 
totem_publish_plugin_rebuild_playlist_cb (TotemPlaylist *playlist,
251
 
                                          const gchar   *filename,
252
 
                                          const gchar   *url,
253
 
                                          gpointer       data)
254
 
{
255
 
        TotemPublishPlugin *self = TOTEM_PUBLISH_PLUGIN (data);
256
 
        gchar *key = totem_publish_plugin_build_key (filename);
257
 
        self->priv->playlist = g_slist_prepend (self->priv->playlist, key);
258
 
}
259
 
 
260
 
static void
261
 
totem_publish_plugin_playlist_changed_cb (TotemPlaylist *playlist,
262
 
                                          gpointer       data)
263
 
{
264
 
        TotemPublishPlugin *self = TOTEM_PUBLISH_PLUGIN (data);
265
 
 
266
 
        G_LOCK (totem_publish_plugin_lock);
267
 
 
268
 
        g_slist_foreach (self->priv->playlist, (GFunc) g_free, NULL);
269
 
        g_slist_free (self->priv->playlist);
270
 
        self->priv->playlist = NULL;
271
 
 
272
 
        totem_playlist_foreach (playlist,
273
 
                                totem_publish_plugin_rebuild_playlist_cb,
274
 
                                self);
275
 
 
276
 
        self->priv->playlist = g_slist_reverse (self->priv->playlist);
277
 
 
278
 
        G_UNLOCK (totem_publish_plugin_lock);
279
 
}
280
 
 
281
 
static void
282
 
totem_publish_plugin_playlist_item_added_cb (TotemPlaylist *playlist,
283
 
                                             const gchar   *filename,
284
 
                                             const gchar   *url,
285
 
                                             gpointer       data)
286
 
{
287
 
        TotemPublishPlugin *self = TOTEM_PUBLISH_PLUGIN (data);
288
 
        gchar *key = totem_publish_plugin_build_key (filename);
289
 
 
290
 
        epc_publisher_add_handler (self->priv->publisher, key,
291
 
                                   totem_publish_plugin_media_cb,
292
 
                                   g_strdup (url), g_free);
293
 
 
294
 
        g_free (key);
295
 
 
296
 
}
297
 
 
298
 
static void
299
 
totem_publish_plugin_playlist_item_removed_cb (TotemPlaylist *playlist,
300
 
                                      const gchar   *filename,
301
 
                                      const gchar   *url,
302
 
                                      gpointer       data)
303
 
{
304
 
        TotemPublishPlugin *self = TOTEM_PUBLISH_PLUGIN (data);
305
 
        gchar *key = totem_publish_plugin_build_key (filename);
306
 
        epc_publisher_remove (self->priv->publisher, key);
307
 
        g_free (key);
308
 
}
309
 
 
310
 
static void
311
 
totem_publish_plugin_service_found_cb (TotemPublishPlugin *self,
312
 
                                       const gchar        *name,
313
 
                                       EpcServiceInfo     *info)
314
 
{
315
 
        GtkTreeIter iter;
316
 
 
317
 
        gtk_list_store_append (self->priv->neighbours, &iter);
318
 
        gtk_list_store_set (self->priv->neighbours, &iter, NAME_COLUMN, name,
319
 
                                                     INFO_COLUMN, info,
320
 
                                                     -1);
321
 
}
322
 
 
323
 
static void
324
 
totem_publish_plugin_service_removed_cb (TotemPublishPlugin *self,
325
 
                                         const gchar        *name,
326
 
                                         const gchar        *type)
327
 
{
328
 
        GtkTreeModel *model = GTK_TREE_MODEL (self->priv->neighbours);
329
 
        GtkTreeIter iter;
330
 
 
331
 
        if (gtk_tree_model_get_iter_first (model, &iter)) {
332
 
                GSList *path_list = NULL, *path_iter;
333
 
                GtkTreePath *path;
334
 
                gchar *stored;
335
 
 
336
 
                do {
337
 
                        gtk_tree_model_get (model, &iter, NAME_COLUMN, &stored, -1);
338
 
 
339
 
                        if (g_str_equal (stored, name)) {
340
 
                                path = gtk_tree_model_get_path (model, &iter);
341
 
                                path_list = g_slist_prepend (path_list, path);
342
 
                        }
343
 
                } while (gtk_tree_model_iter_next (model, &iter));
344
 
 
345
 
                for (path_iter = path_list; path_iter; path_iter = path_iter->next) {
346
 
                        path = path_iter->data;
347
 
 
348
 
                        if (gtk_tree_model_get_iter (model, &iter, path))
349
 
                                gtk_list_store_remove (self->priv->neighbours, &iter);
350
 
 
351
 
                        gtk_tree_path_free (path);
352
 
                }
353
 
 
354
 
                g_slist_free (path_list);
355
 
        }
356
 
}
357
 
 
358
 
static void
359
 
totem_publish_plugin_scanning_done_cb (TotemPublishPlugin *self,
360
 
                                       const gchar        *type)
361
 
{
362
 
        if (self->priv->scanning_id) {
363
 
                g_source_remove (self->priv->scanning_id);
364
 
                self->priv->scanning_id = 0;
365
 
        }
366
 
 
367
 
        if (self->priv->scanning)
368
 
                gtk_widget_hide (self->priv->scanning);
369
 
}
370
 
 
371
 
static void
372
 
totem_publish_plugin_load_playlist (TotemPublishPlugin   *self,
373
 
                                    const EpcServiceInfo *info)
374
 
{
375
 
        EpcConsumer *consumer = epc_consumer_new (info);
376
 
        GKeyFile *keyfile = g_key_file_new ();
377
 
        gchar *contents = NULL;
378
 
        GError *error = NULL;
379
 
        gsize length = 0;
380
 
 
381
 
        contents = epc_consumer_lookup (consumer, "playlist.pls", &length, &error);
382
 
 
383
 
        if (contents && g_key_file_load_from_data (keyfile, contents, length, G_KEY_FILE_NONE, &error)) {
384
 
                gint i, n_entries;
385
 
                GList *mrl_list = NULL;
386
 
 
387
 
                /* returns zero in case of errors */
388
 
                n_entries = g_key_file_get_integer (keyfile, "playlist", "NumberOfEntries", &error);
389
 
 
390
 
                if (error)
391
 
                        goto out;
392
 
 
393
 
                /* FIXME
394
 
                ev_sidebar_set_current_page (EV_SIDEBAR (self->priv->totem->sidebar), "playlist"); */
395
 
                totem_playlist_clear (self->priv->totem->playlist);
396
 
 
397
 
                for (i = 0; i < n_entries; ++i) {
398
 
                        gchar *key, *mrl, *title;
399
 
 
400
 
                        key = g_strdup_printf ("File%d", i + 1);
401
 
                        mrl = g_key_file_get_string (keyfile, "playlist", key, NULL);
402
 
                        g_free (key);
403
 
 
404
 
                        key = g_strdup_printf ("Title%d", i + 1);
405
 
                        title = g_key_file_get_string (keyfile, "playlist", key, NULL);
406
 
                        g_free (key);
407
 
 
408
 
                        if (mrl)
409
 
                                mrl_list = g_list_prepend (mrl_list, totem_playlist_mrl_data_new (mrl, title));
410
 
 
411
 
                        g_free (title);
412
 
                        g_free (mrl);
413
 
                }
414
 
 
415
 
                /* Add the MRLs to the playlist asynchronously and in order */
416
 
                if (mrl_list != NULL)
417
 
                        totem_playlist_add_mrls (self->priv->totem->playlist, g_list_reverse (mrl_list), FALSE, NULL, NULL, NULL);
418
 
        }
419
 
 
420
 
out:
421
 
        if (error) {
422
 
                g_warning ("Cannot load playlist: %s", error->message);
423
 
                g_error_free (error);
424
 
        }
425
 
 
426
 
        g_key_file_free (keyfile);
427
 
        g_free (contents);
428
 
 
429
 
        g_object_unref (consumer);
430
 
}
431
 
 
432
 
void
433
 
totem_publish_plugin_neighbours_list_row_activated_cb (GtkTreeView       *view,
434
 
                                                       GtkTreePath       *path,
435
 
                                                       GtkTreeViewColumn *column,
436
 
                                                       gpointer           data)
437
 
{
438
 
        TotemPublishPlugin *self = TOTEM_PUBLISH_PLUGIN (data);
439
 
        EpcServiceInfo *info = NULL;
440
 
        GtkTreeIter iter;
441
 
 
442
 
        if (gtk_tree_model_get_iter (GTK_TREE_MODEL (self->priv->neighbours), &iter, path)) {
443
 
                gtk_tree_model_get (GTK_TREE_MODEL (self->priv->neighbours),
444
 
                                    &iter, INFO_COLUMN, &info, -1);
445
 
                totem_publish_plugin_load_playlist (self, info);
446
 
                epc_service_info_unref (info);
447
 
        }
448
 
}
449
 
 
450
 
static gboolean
451
 
totem_publish_plugin_scanning_cb (gpointer data)
452
 
{
453
 
        gtk_progress_bar_pulse (GTK_PROGRESS_BAR (data));
454
 
        return TRUE;
455
 
}
456
 
 
457
 
static GtkWidget*
458
 
totem_publish_plugin_create_neigbours_page (TotemPublishPlugin *self, GtkBuilder *builder)
459
 
{
460
 
        GtkWidget *page, *list;
461
 
 
462
 
        page = GTK_WIDGET (gtk_builder_get_object (builder, "neighbours-page"));
463
 
        list = GTK_WIDGET (gtk_builder_get_object (builder, "neighbours-list"));
464
 
 
465
 
        self->priv->scanning = GTK_WIDGET (gtk_builder_get_object (builder, "neighbours-scanning"));
466
 
        self->priv->scanning_id = g_timeout_add (100, totem_publish_plugin_scanning_cb, self->priv->scanning);
467
 
 
468
 
        g_signal_connect_swapped (self->priv->monitor, "service-found",
469
 
                                  G_CALLBACK (totem_publish_plugin_service_found_cb),
470
 
                                  self);
471
 
        g_signal_connect_swapped (self->priv->monitor, "service-removed",
472
 
                                  G_CALLBACK (totem_publish_plugin_service_removed_cb),
473
 
                                  self);
474
 
        g_signal_connect_swapped (self->priv->monitor, "scanning-done",
475
 
                                  G_CALLBACK (totem_publish_plugin_scanning_done_cb),
476
 
                                  self);
477
 
 
478
 
        self->priv->neighbours = gtk_list_store_new (LAST_COLUMN, G_TYPE_STRING, EPC_TYPE_SERVICE_INFO);
479
 
 
480
 
        gtk_tree_view_set_model (GTK_TREE_VIEW (list),
481
 
                                 GTK_TREE_MODEL (self->priv->neighbours));
482
 
 
483
 
        gtk_tree_view_append_column (GTK_TREE_VIEW (list),
484
 
                gtk_tree_view_column_new_with_attributes (
485
 
                        NULL, gtk_cell_renderer_text_new (),
486
 
                        "text", NAME_COLUMN, NULL));
487
 
 
488
 
        g_object_ref (page);
489
 
        gtk_widget_unparent (page);
490
 
 
491
 
        return page;
492
 
}
493
 
 
494
 
static void
495
 
impl_activate (PeasActivatable *plugin)
496
 
{
497
 
        TotemPublishPlugin *self = TOTEM_PUBLISH_PLUGIN (plugin);
498
 
        TotemPublishPluginPrivate *priv = self->priv;
499
 
        EpcProtocol protocol = EPC_PROTOCOL_HTTPS;
500
 
        GtkWindow *window;
501
 
        GtkBuilder *builder;
502
 
        GError *internal_error = NULL;
503
 
 
504
 
        gchar *protocol_name;
505
 
 
506
 
        gchar *service_pattern;
507
 
        gchar *service_name;
508
 
 
509
 
        g_return_if_fail (NULL == priv->publisher);
510
 
        g_return_if_fail (NULL == priv->totem);
511
 
 
512
 
        G_LOCK (totem_publish_plugin_lock);
513
 
 
514
 
        priv->totem = g_object_ref (g_object_get_data (G_OBJECT (plugin), "object"));
515
 
 
516
 
        window = totem_get_main_window (priv->totem);
517
 
        builder = totem_plugin_load_interface ("publish", "publish-plugin.ui", TRUE, window, self);
518
 
        epc_progress_window_install (window);
519
 
        g_object_unref (window);
520
 
 
521
 
        priv->gsettings = g_settings_new (TOTEM_PUBLISH_SCHEMA);
522
 
 
523
 
        protocol_name = g_settings_get_string (priv->gsettings, "protocol");
524
 
        service_pattern = g_settings_get_string (priv->gsettings, "name-format");
525
 
 
526
 
        if (*protocol_name == '\0') {
527
 
                protocol_name = g_strdup ("http");
528
 
                g_settings_set_string (priv->gsettings, "protocol", protocol_name);
529
 
        }
530
 
 
531
 
        if (*service_pattern == '\0') {
532
 
                service_pattern = g_strdup ("%a of %u on %h");
533
 
                g_settings_set_string (priv->gsettings, "name-format", service_pattern);
534
 
        }
535
 
 
536
 
        g_signal_connect (priv->gsettings, "changed::name", (GCallback) totem_publish_plugin_name_changed_cb, self);
537
 
        g_signal_connect (priv->gsettings, "changed::protocol", (GCallback) totem_publish_plugin_protocol_changed_cb, self);
538
 
 
539
 
        protocol = epc_protocol_from_name (protocol_name, EPC_PROTOCOL_HTTPS);
540
 
        service_name = epc_publisher_expand_name (service_pattern, &internal_error);
541
 
        g_free (service_pattern);
542
 
 
543
 
        if (internal_error) {
544
 
                g_warning ("%s: %s", G_STRFUNC, internal_error->message);
545
 
                g_clear_error (&internal_error);
546
 
        }
547
 
 
548
 
        priv->monitor = epc_service_monitor_new ("totem", NULL, EPC_PROTOCOL_UNKNOWN);
549
 
        epc_service_monitor_set_skip_our_own (priv->monitor, TRUE);
550
 
 
551
 
        /* Translators: computers on the local network which are publishing their playlists over the network */
552
 
        totem_add_sidebar_page (priv->totem, "neighbours", _("Neighbors"),
553
 
                                totem_publish_plugin_create_neigbours_page (self, builder));
554
 
        g_object_unref (builder);
555
 
 
556
 
        priv->publisher = epc_publisher_new (service_name, "totem", NULL);
557
 
        epc_publisher_set_protocol (priv->publisher, protocol);
558
 
 
559
 
        g_free (protocol_name);
560
 
        g_free (service_name);
561
 
 
562
 
        epc_publisher_add_handler (priv->publisher, "playlist.pls",
563
 
                                   totem_publish_plugin_playlist_cb,
564
 
                                   self, NULL);
565
 
        epc_publisher_add_bookmark (priv->publisher, "playlist.pls", NULL);
566
 
 
567
 
        priv->item_added_id = g_signal_connect (priv->totem->playlist, "changed",
568
 
                G_CALLBACK (totem_publish_plugin_playlist_changed_cb), self);
569
 
        priv->item_added_id = g_signal_connect (priv->totem->playlist, "item-added",
570
 
                G_CALLBACK (totem_publish_plugin_playlist_item_added_cb), self);
571
 
        priv->item_removed_id = g_signal_connect (priv->totem->playlist, "item-removed",
572
 
                G_CALLBACK (totem_publish_plugin_playlist_item_removed_cb), self);
573
 
 
574
 
        G_UNLOCK (totem_publish_plugin_lock);
575
 
 
576
 
        totem_playlist_foreach (priv->totem->playlist,
577
 
                                totem_publish_plugin_playlist_item_added_cb, self);
578
 
 
579
 
        totem_publish_plugin_playlist_changed_cb (priv->totem->playlist, self);
580
 
 
581
 
        epc_publisher_run_async (priv->publisher, NULL);
582
 
 
583
 
        return;
584
 
}
585
 
 
586
 
static void
587
 
impl_deactivate (PeasActivatable *plugin)
588
 
{
589
 
        TotemPublishPlugin *self = TOTEM_PUBLISH_PLUGIN (plugin);
590
 
        TotemPublishPluginPrivate *priv = self->priv;
591
 
        TotemPlaylist *playlist = NULL;
592
 
 
593
 
        G_LOCK (totem_publish_plugin_lock);
594
 
 
595
 
        if (priv->totem)
596
 
                playlist = priv->totem->playlist;
597
 
 
598
 
        if (priv->scanning_id) {
599
 
                g_source_remove (priv->scanning_id);
600
 
                priv->scanning_id = 0;
601
 
        }
602
 
 
603
 
        if (playlist && priv->item_added_id) {
604
 
                g_signal_handler_disconnect (playlist, priv->item_added_id);
605
 
                priv->item_added_id = 0;
606
 
        }
607
 
 
608
 
        if (playlist && priv->item_removed_id) {
609
 
                g_signal_handler_disconnect (playlist, priv->item_removed_id);
610
 
                priv->item_removed_id = 0;
611
 
        }
612
 
 
613
 
        if (priv->monitor) {
614
 
                g_object_unref (priv->monitor);
615
 
                priv->monitor = NULL;
616
 
        }
617
 
 
618
 
        if (priv->publisher) {
619
 
                epc_publisher_quit (priv->publisher);
620
 
                g_object_unref (priv->publisher);
621
 
                priv->publisher = NULL;
622
 
        }
623
 
 
624
 
        if (priv->gsettings != NULL)
625
 
                g_object_unref (priv->gsettings);
626
 
        priv->gsettings = NULL;
627
 
 
628
 
        if (priv->totem) {
629
 
                totem_remove_sidebar_page (priv->totem, "neighbours");
630
 
 
631
 
                g_object_unref (priv->totem);
632
 
                priv->totem = NULL;
633
 
        }
634
 
 
635
 
        if (priv->settings) {
636
 
                gtk_widget_destroy (priv->settings);
637
 
                priv->settings = NULL;
638
 
        }
639
 
 
640
 
        if (priv->playlist) {
641
 
                g_slist_foreach (priv->playlist, (GFunc) g_free, NULL);
642
 
                g_slist_free (priv->playlist);
643
 
                priv->playlist = NULL;
644
 
        }
645
 
 
646
 
        G_UNLOCK (totem_publish_plugin_lock);
647
 
 
648
 
        priv->scanning = NULL;
649
 
}
650
 
 
651
 
static GtkWidget *
652
 
impl_create_configure_widget (PeasGtkConfigurable *configurable)
653
 
{
654
 
        TotemPublishPlugin *self = TOTEM_PUBLISH_PLUGIN (configurable);
655
 
        gchar *service_name, *protocol_name;
656
 
        GtkBuilder *builder;
657
 
        GtkWidget *widget;
658
 
        EpcProtocol protocol;
659
 
        GSettings *settings;
660
 
 
661
 
        /* This function has to be independent of the rest of the plugin, as it's executed under a different plugin instance.
662
 
         * FIXME: bgo#624073 */
663
 
        builder = totem_plugin_load_interface ("publish", "publish-plugin.ui", TRUE, NULL, self);
664
 
 
665
 
        settings = g_settings_new (TOTEM_PUBLISH_SCHEMA);
666
 
        service_name = g_settings_get_string (settings, "name-format");
667
 
        protocol_name = g_settings_get_string (settings, "protocol");
668
 
        g_object_unref (settings);
669
 
 
670
 
        protocol = epc_protocol_from_name (protocol_name, EPC_PROTOCOL_HTTPS);
671
 
        g_free (protocol_name);
672
 
 
673
 
        widget = g_object_ref (gtk_builder_get_object (builder, "publish-settings-vbox"));
674
 
 
675
 
        gtk_entry_set_text (GTK_ENTRY (gtk_builder_get_object (builder, "service-name-entry")), service_name);
676
 
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "encryption-button")), EPC_PROTOCOL_HTTPS == protocol);
677
 
 
678
 
        g_free (service_name);
679
 
 
680
 
        return widget;
681
 
}