[blam] Get rid of MainLoopEmitter
- From: Carlos Martín Nieto <cmartin src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [blam] Get rid of MainLoopEmitter
- Date: Fri, 14 Jun 2013 23:47:03 +0000 (UTC)
commit fe5b8323d5b44d4988b2517e79a537f8684d76dc
Author: Carlos Martín Nieto <cmn dwim me>
Date: Fri Jun 14 22:24:38 2013 +0200
Get rid of MainLoopEmitter
Go explicitly through GLib.Idle.Add when we need it. As a bit of a
side-effect, we now actually try to update all the feeds.
blam.csproj | 1 -
src/Application.cs | 9 ++++++---
src/ChannelCollection.cs | 45 +++++++++++++++++++++++----------------------
src/MainloopEmitter.cs | 45 ---------------------------------------------
src/Makefile.am | 1 -
src/Opml.cs | 5 ++++-
6 files changed, 33 insertions(+), 73 deletions(-)
---
diff --git a/blam.csproj b/blam.csproj
index 4cb67b8..458d4cc 100644
--- a/blam.csproj
+++ b/blam.csproj
@@ -95,7 +95,6 @@
<Compile Include="src\ItemList.cs" />
<Compile Include="src\ItemStore.cs" />
<Compile Include="src\ItemView.cs" />
- <Compile Include="src\MainloopEmitter.cs" />
<Compile Include="src\Opml.cs" />
<Compile Include="src\PreferencesDialog.cs" />
<Compile Include="src\Proxy.cs" />
diff --git a/src/Application.cs b/src/Application.cs
index 7e0b212..cbe3295 100644
--- a/src/Application.cs
+++ b/src/Application.cs
@@ -18,6 +18,7 @@ using System.IO;
using System.Text;
using System.Runtime.InteropServices;
using System.Threading;
+using System.Threading.Tasks;
using WebKit;
#if ENABLE_DBUS
using DBus;
@@ -92,6 +93,7 @@ namespace Imendio.Blam {
private TrayIcon trayIcon;
public static string BaseDir;
+ public static SynchronizationContext Context { get; private set; }
private ChannelDialog channelDialog;
private AddGroupDialog addGroupDialog;
@@ -143,6 +145,7 @@ namespace Imendio.Blam {
SetupDBus();
Gtk.Application.Init ();
+ SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
Proxy.InitProxy ();
@@ -170,7 +173,7 @@ namespace Imendio.Blam {
ShowNextUpdateTime();
} else {
if(Conf.Get(Preference.REFRESH_AT_START, false) == true){
- mCollection.RefreshAllAsync();
+ mCollection.RefreshAll();
}
}
@@ -666,7 +669,7 @@ namespace Imendio.Blam {
/* First move the refresh back */
StartStopAutoRefresh();
/* And pretend a timeout occurred */
- DoRefreshAll(null);
+ DoRefreshAll();
}
private void DragDataReceivedCb(object o, DragDataReceivedArgs args)
@@ -757,7 +760,7 @@ namespace Imendio.Blam {
statusbar.Push(contextId, StatusString);
}
- void DoRefreshAll(object obj)
+ void DoRefreshAll(object obj = null)
{
ShowNextUpdateTime();
mCollection.RefreshAll();
diff --git a/src/ChannelCollection.cs b/src/ChannelCollection.cs
index 3f72314..fb3965f 100644
--- a/src/ChannelCollection.cs
+++ b/src/ChannelCollection.cs
@@ -234,34 +234,35 @@ namespace Imendio.Blam {
MarkAsDirty();
}
- delegate void RefreshAllDelegate();
-
- public Task RefreshAllAsync()
- {
- return Task.Factory.StartNew(RefreshAll);
- }
-
- public void RefreshAll ()
- {
- var all = mChannels.Cast<Channel>();
- foreach(ChannelGroup group in Groups){
- all.Union(group.Channels.Cast<Channel>());
- }
+ public async void RefreshAll()
+ {
+ var all = mChannels.Cast<IChannel>().Union(Groups.Cast<IChannel>());
- Parallel.ForEach(mChannels.Cast<Channel>(), c => {
- if (c.Refresh())
- MarkAsDirty();
- new MainloopEmitter (this.ChannelRefreshFinished, c).Emit ();
- });
- }
+ foreach (var chan in all) {
+ EmitChannelRefreshStarted(chan);
+ await chan.RefreshAsync();
+ EmitChannelRefreshFinished(chan);
+ }
+ }
private void EmitChannelRefreshStarted (IChannel channel)
{
- if (ChannelRefreshStarted != null) {
- ChannelRefreshStarted (channel);
- }
+ if (ChannelRefreshStarted != null)
+ GLib.Idle.Add(() => {
+ ChannelRefreshStarted(channel);
+ return false;
+ });
}
+ void EmitChannelRefreshFinished(IChannel channel)
+ {
+ if (ChannelRefreshFinished != null)
+ GLib.Idle.Add(() => {
+ ChannelRefreshFinished(channel);
+ return false;
+ });
+ }
+
// TODO: this keeps the old semantics of restarting the timer, but we
// might want to simply see if we should start one and not do anything
// if there's already a task enqueued.
diff --git a/src/Makefile.am b/src/Makefile.am
index 2d901fc..bdcf558 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -28,7 +28,6 @@ BLAM_CSFILES = Application.cs \
Item.cs \
ItemList.cs \
ItemView.cs \
- MainloopEmitter.cs \
Opml.cs \
PreferencesDialog.cs \
Theme.cs \
diff --git a/src/Opml.cs b/src/Opml.cs
index dc5c1ee..b4a0080 100644
--- a/src/Opml.cs
+++ b/src/Opml.cs
@@ -347,7 +347,10 @@ namespace Imendio.Blam {
}
Channel channel = new Channel (name, url);
- new MainloopEmitter (this.ChannelRead, channel).Emit ();
+ GLib.Idle.Add(() => {
+ ChannelRead(channel);
+ return false;
+ });
}
}
GLib.Idle.Add (new GLib.IdleHandler (EmitImportFinished));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]