~ubuntu-branches/ubuntu/saucy/blam/saucy

« back to all changes in this revision

Viewing changes to src/ChannelCollection.cs

  • Committer: Bazaar Package Importer
  • Author(s): Carlos Martín Nieto
  • Date: 2011-05-31 01:36:47 UTC
  • mto: (1.1.8 upstream) (2.2.5 sid)
  • mto: This revision was merged to the branch mainline in revision 17.
  • Revision ID: james.westby@ubuntu.com-20110531013647-dt9ij4zj9f9wg6uk
Import upstream version 1.8.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
            }
66
66
        }
67
67
 
 
68
        public int NrOfNewItems {
 
69
            get {
 
70
                int new_items = 0;
 
71
 
 
72
                foreach(Channel channel in mChannels){
 
73
                    new_items += channel.NrOfNewItems;
 
74
                }
 
75
 
 
76
                foreach(ChannelGroup changrp in Groups){
 
77
                    new_items += changrp.NrOfNewItems;
 
78
                }
 
79
 
 
80
                return new_items;
 
81
            }
 
82
        }
 
83
 
68
84
        public ChannelCollection ()
69
85
        {
70
86
            mQueue = Queue.Synchronized (new Queue ());
270
286
 
271
287
            StartRefreshThreads (nrOfChannels);
272
288
        }
273
 
 
274
 
        public void RefreshAll (int refreshRate) 
275
 
        {
276
 
            int nrOfChannels = 0;
277
 
 
278
 
            foreach (Channel channel in mChannels) {
279
 
                TimeSpan span = DateTime.Now.Subtract (channel.LastRefreshed);
280
 
                
281
 
                if (span.TotalSeconds >= refreshRate * 60) {
282
 
                    QueueChannelRefresh (channel);
283
 
                    nrOfChannels++;
284
 
                }
285
 
            }
286
 
 
287
 
        foreach(ChannelGroup group in Groups){
288
 
            if(group.Channels.Count == 0)
289
 
                    continue;
290
 
            foreach(Channel channel in group.Channels){
291
 
                TimeSpan span = DateTime.Now.Subtract(channel.LastRefreshed);
292
 
                if(span.TotalSeconds >= refreshRate * 60){
293
 
                    QueueChannelRefresh(channel);
294
 
                    nrOfChannels++;
295
 
                }
296
 
            }
297
 
        }
298
 
 
299
 
            StartRefreshThreads (nrOfChannels);
300
 
        }
301
289
        
302
290
        /* Used to cross-mark as read */
303
291
        public void MarkItemIdAsReadInAllChannels (Channel channel, string id)
331
319
        {
332
320
            while (true) {
333
321
                try {
334
 
                    Channel channel = (Channel) mQueue.Dequeue ();
335
 
                    bool updated = FeedUpdater.Update (channel);
 
322
                    IChannel tmp = (IChannel) mQueue.Dequeue ();
 
323
            Channel channel;
 
324
 
 
325
           if(tmp is ChannelGroup){
 
326
               mRunningList.Remove(Thread.CurrentThread);
 
327
               return;
 
328
            }
 
329
 
 
330
            channel = tmp as Channel;
 
331
            bool updated = FeedUpdater.Update (channel);
336
332
 
337
333
                    if (updated) {
338
334
                        MarkAsDirty (true);
339
335
                    }   
340
336
 
341
337
                    new MainloopEmitter (this.ChannelRefreshFinished, channel).Emit ();
 
338
#if ENABLE_NOTIFY
 
339
            /* Make sure we have something to say and the user isn't watching us */
 
340
            if(mQueue.Count == 0 &&
 
341
                    NrOfUnreadItems != 0 && Application.TheApp.Window.IsActive == false){
 
342
                UnreadNotification.NotifyUnreadPosts(NrOfUnreadItems, NrOfNewItems);
 
343
            }
 
344
#endif
342
345
                } catch (InvalidOperationException) {
343
346
                    break;
344
347
                }