~ubuntu-branches/ubuntu/vivid/liferea/vivid-proposed

« back to all changes in this revision

Viewing changes to src/update.c

  • Committer: Package Import Robot
  • Author(s): bojo42
  • Date: 2012-03-29 14:17:21 UTC
  • mfrom: (1.3.9) (3.2.5 sid)
  • Revision ID: package-import@ubuntu.com-20120329141721-tbfopcrc5797wxt7
Tags: 1.8.3-0.1ubuntu1
* New upstream release (LP: #290666, #371754, #741543, #716688)
* Merge from Debian unstable (LP: #935147), remaining changes:
* debian/patches:
  - drop gtk-status-icon.patch & notification-append as in upstream
  - drop fix_systray_behavior as mostly upstreamed and rest seems unused
  - 01_ubuntu_feedlists: update & rename, move planets to "Open Source"  
  - add_X-Ubuntu-Gettext-Domain: rebase
  - libunity.patch: rebase, apply before indicator patch (liferea_shell.c)
  - libindicate_increase_version.patch: exclude from libindicate.patch
  - deactivate libindicate.patch, seems partly upstreamed and needs rework
* debian/control: libindicate-dev, libindicate-gtk-dev & libunity-dev
* debian/liferea.indicate & liferea.install: ship indicator desktop file
* debian/rules: enable libindicate

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
#include "update.h"
24
24
 
25
 
#ifdef HAVE_CONFIG_H
26
 
#  include <config.h>
27
 
#endif
28
 
 
29
25
#include <libxml/parser.h>
30
26
#include <libxslt/xslt.h>
31
27
#include <libxslt/xsltInternals.h>
37
33
#include <sys/wait.h>
38
34
#include <string.h>
39
35
 
40
 
#ifdef USE_NM
41
 
#include <dbus/dbus.h>
42
 
#include <libnm_glib.h>
43
 
#endif
44
 
 
45
36
#include "common.h"
46
 
#include "conf.h"
47
37
#include "debug.h"
48
38
#include "net.h"
49
39
#include "xml.h"
50
 
#include "ui/liferea_htmlview.h"
51
40
#include "ui/liferea_shell.h"
52
41
#include "ui/ui_tray.h"
53
42
 
54
43
/** global update job list, used for lookups when cancelling */
55
44
static GSList   *jobs = NULL;
56
45
 
57
 
/* We use a communication queue for limiting the number 
58
 
   of concurrent requests to avoid hitting the file descriptor
59
 
   limit of the glibcurl code. */
60
46
static GAsyncQueue *pendingHighPrioJobs = NULL;
61
47
static GAsyncQueue *pendingJobs = NULL;
62
48
static guint numberOfActiveJobs = 0;
63
49
#define MAX_ACTIVE_JOBS 5
64
50
 
65
 
#ifdef USE_NM
66
 
/* State for NM support */
67
 
static libnm_glib_ctx *nm_ctx = NULL;
68
 
static guint nm_id = 0;
69
 
#endif
70
 
 
71
51
/* update state interface */
72
52
 
73
53
updateStatePtr
321
301
        g_assert (NULL != job->result);
322
302
        
323
303
        do {
324
 
                srcDoc = xml_parse (job->result->data, job->result->size, FALSE, NULL);
 
304
                srcDoc = xml_parse (job->result->data, job->result->size, NULL);
325
305
                if (!srcDoc) {
326
306
                        g_warning("fatal: parsing request result XML source failed (%s)!", job->request->filtercmd);
327
307
                        break;
490
470
        if (!pendingJobs)
491
471
                return FALSE;   /* we must be in shutdown */
492
472
                
493
 
        if (numberOfActiveJobs >= MAX_ACTIVE_JOBS)
494
 
                return TRUE;    /* let's continue later */
 
473
        if (numberOfActiveJobs >= MAX_ACTIVE_JOBS) 
 
474
                return FALSE;   /* we'll be called again when a job finishes */
 
475
        
495
476
 
496
477
        job = (updateJobPtr)g_async_queue_try_pop(pendingHighPrioJobs);
497
478
 
499
480
                job = (updateJobPtr)g_async_queue_try_pop(pendingJobs);
500
481
 
501
482
        if(!job)
502
 
                return TRUE;    /* no request at the moment */
 
483
                return FALSE;   /* no request at the moment */
503
484
 
504
485
        numberOfActiveJobs++;
505
486
 
512
493
                update_job_run (job);
513
494
        }
514
495
                
515
 
        return TRUE;
 
496
        return TRUE; /* since I got a job now, there may be more in the queue */
516
497
}
517
498
 
518
499
updateJobPtr
532
513
 
533
514
        if (flags & FEED_REQ_PRIORITY_HIGH) {
534
515
                g_async_queue_push (pendingHighPrioJobs, (gpointer)job);
535
 
                update_dequeue_job (NULL);
536
516
        } else {
537
517
                g_async_queue_push (pendingJobs, (gpointer)job);
538
518
        }
539
519
 
 
520
        g_idle_add (update_dequeue_job, NULL);
540
521
        return job;
541
522
}
542
523
 
573
554
        
574
555
        g_assert(numberOfActiveJobs > 0);
575
556
        numberOfActiveJobs--;
 
557
        g_idle_add (update_dequeue_job, NULL);
576
558
 
577
559
        /* Handling abandoned requests (e.g. after feed deletion) */
578
560
        if (job->callback == NULL) {    
588
570
        g_idle_add (update_process_result_idle_cb, job);
589
571
}
590
572
 
591
 
#ifdef USE_NM
592
 
static void
593
 
update_network_monitor (libnm_glib_ctx *ctx, gpointer user_data)
594
 
{
595
 
        libnm_glib_state        state;
596
 
        gboolean online;
597
 
 
598
 
        g_return_if_fail (ctx != NULL);
599
 
 
600
 
        state = libnm_glib_get_network_state (ctx);
601
 
        online = network_is_online ();
602
 
 
603
 
        if (online && state == LIBNM_NO_NETWORK_CONNECTION) {
604
 
                debug0 (DEBUG_UPDATE, "network manager: no network connection -> going offline");
605
 
                network_set_online (FALSE);
606
 
        } else if (!online && state == LIBNM_ACTIVE_NETWORK_CONNECTION) {
607
 
                debug0 (DEBUG_UPDATE, "network manager: active connection -> going online");
608
 
                network_set_online (TRUE);
609
 
        }
610
 
}
611
 
 
612
 
static gboolean
613
 
update_nm_initialize (void)
614
 
{
615
 
        debug0 (DEBUG_UPDATE, "network manager: registering network state change callback");
616
 
        
617
 
        if (!nm_ctx) {
618
 
                nm_ctx = libnm_glib_init ();
619
 
                if (!nm_ctx) {
620
 
                        fprintf (stderr, "Could not initialize libnm.\n");
621
 
                        return FALSE;
622
 
                }       
623
 
        }
624
 
 
625
 
        nm_id = libnm_glib_register_callback (nm_ctx, update_network_monitor, NULL, NULL);
626
 
        
627
 
        return TRUE;
628
 
}
629
 
 
630
 
static void
631
 
update_nm_cleanup (void)
632
 
{
633
 
        debug0 (DEBUG_UPDATE, "network manager: unregistering network state change callback");
634
 
        
635
 
        if (nm_id != 0 && nm_ctx != NULL) {
636
 
                libnm_glib_unregister_callback (nm_ctx, nm_id);
637
 
                libnm_glib_shutdown (nm_ctx);
638
 
                nm_ctx = NULL;
639
 
                nm_id = 0;
640
 
        }
641
 
}
642
 
#endif
643
573
 
644
574
void
645
575
update_init (void)
646
576
{
647
577
        pendingJobs = g_async_queue_new ();
648
578
        pendingHighPrioJobs = g_async_queue_new ();
649
 
        network_init ();
650
 
        
651
 
        g_timeout_add (500, update_dequeue_job, NULL);
652
 
        
653
 
#ifdef USE_NM
654
 
        {
655
 
                DBusConnection *connection;
656
 
 
657
 
                connection = dbus_bus_get (DBUS_BUS_SYSTEM, NULL);
658
 
 
659
 
                if (connection) {
660
 
                        dbus_connection_set_exit_on_disconnect (connection, FALSE);
661
 
 
662
 
                        if (dbus_bus_name_has_owner (connection, "org.freedesktop.NetworkManager", NULL)) {
663
 
                                update_nm_initialize ();
664
 
                                /* network manager will set online state right after initialization... */
665
 
                        } else {
666
 
                                network_set_online (TRUE);
667
 
                        }
668
 
 
669
 
                        dbus_connection_unref(connection);
670
 
 
671
 
                        return;
672
 
                }
673
 
        }
674
 
#endif
675
 
        network_set_online (TRUE);
676
579
}
677
580
 
678
581
void
680
583
{
681
584
        GSList  *iter = jobs;
682
585
 
683
 
        debug_enter ("update_deinit");
684
 
 
685
 
#ifdef USE_NM   
686
 
        update_nm_cleanup ();
687
 
#endif  
688
 
        network_deinit ();
689
 
        
690
586
        /* Cancel all jobs, to avoid async callbacks accessing the GUI */
691
587
        while (iter) {
692
588
                updateJobPtr job = (updateJobPtr)iter->data;
699
595
        
700
596
        g_slist_free (jobs);
701
597
        jobs = NULL;
702
 
        
703
 
        debug_exit ("update_deinit");
704
598
}