Merge lp://qastaging/~cszikszoy/do-plugins/fix-flickr-upload into lp://qastaging/do-plugins

Proposed by Chris S.
Status: Merged
Approved by: Alex Launi
Approved revision: 601
Merged at revision: not available
Proposed branch: lp://qastaging/~cszikszoy/do-plugins/fix-flickr-upload
Merge into: lp://qastaging/do-plugins
Diff against target: None lines
To merge this branch: bzr merge lp://qastaging/~cszikszoy/do-plugins/fix-flickr-upload
Reviewer Review Type Date Requested Status
Do Plugins Team Pending
Review via email: mp+6034@code.qastaging.launchpad.net
To post a comment you must log in.
Revision history for this message
Chris S. (cszikszoy) wrote :

Fixes to a couple of Flickr bugs out there. The most significant is the use of a sort of thread pool and a job queue to upload flickr images, instead of creating a new thread for each upload. The second bug fix is a problem with the "Authorization" button being to small to fit the entire text.

When uploading, progress is displayed on a small GTK upload dialog, that can be closed at any time. If the dialog is closed, the user will be notified about the status and completion of their image uploads through notifications.

Currently 4 upload threads are being used. I suppose this could be bumped up a bit, but 4 seems about right. Feedback on this point is appreciated.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Flickr/Flickr.mdp'
2--- Flickr/Flickr.mdp 2009-02-28 16:16:48 +0000
3+++ Flickr/Flickr.mdp 2009-04-18 01:51:21 +0000
4@@ -27,6 +27,9 @@
5 <File name="gtk-gui/Flickr.AccountConfig.cs" subtype="Code" buildaction="Compile" />
6 <File name="Resources/Flickr.addin.xml" subtype="Code" buildaction="EmbedAsResource" />
7 <File name="Resources/icons/flickr.png" subtype="Code" buildaction="EmbedAsResource" />
8+ <File name="src/UploadPool.cs" subtype="Code" buildaction="Compile" />
9+ <File name="src/UploadDialog.cs" subtype="Code" buildaction="Compile" />
10+ <File name="gtk-gui/Flickr.UploadDialog.cs" subtype="Code" buildaction="Compile" />
11 </Contents>
12 <References>
13 <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
14@@ -38,5 +41,9 @@
15 <ProjectReference type="Gac" localcopy="True" refto="Do.Universe, Version=0.8.0.0, Culture=neutral, PublicKeyToken=null" />
16 <ProjectReference type="Gac" localcopy="True" refto="Do.Platform, Version=0.8.0.0, Culture=neutral, PublicKeyToken=null" />
17 <ProjectReference type="Gac" localcopy="True" refto="Do.Platform.Linux, Version=0.8.0.0, Culture=neutral, PublicKeyToken=null" />
18+ <ProjectReference type="Assembly" localcopy="True" specificVersion="False" refto="../../../../../../usr/local/lib/gnome-do/Do.Platform.dll" />
19+ <ProjectReference type="Assembly" localcopy="True" specificVersion="False" refto="../../../../../../usr/local/lib/gnome-do/Do.Universe.dll" />
20+ <ProjectReference type="Assembly" localcopy="True" specificVersion="False" refto="../../../../../../usr/local/lib/gnome-do/Do.Interface.Linux.dll" />
21+ <ProjectReference type="Gac" localcopy="True" refto="glib-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
22 </References>
23 </Project>
24\ No newline at end of file
25
26=== modified file 'Flickr/Makefile.am'
27--- Flickr/Makefile.am 2009-01-09 07:45:01 +0000
28+++ Flickr/Makefile.am 2009-04-17 20:57:18 +0000
29@@ -5,10 +5,13 @@
30 FILES = \
31 gtk-gui/Flickr.AccountConfig.cs \
32 gtk-gui/Flickr.UploadConfig.cs \
33+ gtk-gui/Flickr.UploadDialog.cs \
34 gtk-gui/generated.cs \
35 src/AccountConfig.cs \
36 src/FlickrItemSource.cs \
37 src/UploadAction.cs \
38+ src/UploadPool.cs \
39+ src/UploadDialog.cs \
40 src/UploadConfig.cs
41
42 RESOURCES = \
43
44=== modified file 'Flickr/Resources/icons/flickr.png' (properties changed: -x to +x)
45=== modified file 'Flickr/gtk-gui/Flickr.AccountConfig.cs'
46--- Flickr/gtk-gui/Flickr.AccountConfig.cs 2008-12-29 18:23:07 +0000
47+++ Flickr/gtk-gui/Flickr.AccountConfig.cs 2009-04-24 01:15:22 +0000
48@@ -1,7 +1,7 @@
49 // ------------------------------------------------------------------------------
50 // <autogenerated>
51 // This code was generated by a tool.
52-// Mono Runtime Version: 2.0.50727.42
53+//
54 //
55 // Changes to this file may cause incorrect behavior and will be lost if
56 // the code is regenerated.
57@@ -102,7 +102,6 @@
58 this.hbuttonbox1.Name = "hbuttonbox1";
59 // Container child hbuttonbox1.Gtk.ButtonBox+ButtonBoxChild
60 this.auth_btn = new Gtk.Button();
61- this.auth_btn.WidthRequest = 174;
62 this.auth_btn.CanFocus = true;
63 this.auth_btn.Name = "auth_btn";
64 this.auth_btn.UseUnderline = true;
65
66=== modified file 'Flickr/gtk-gui/Flickr.UploadConfig.cs'
67--- Flickr/gtk-gui/Flickr.UploadConfig.cs 2009-01-09 07:25:58 +0000
68+++ Flickr/gtk-gui/Flickr.UploadConfig.cs 2009-04-19 02:03:26 +0000
69@@ -1,7 +1,7 @@
70 // ------------------------------------------------------------------------------
71 // <autogenerated>
72 // This code was generated by a tool.
73-// Mono Runtime Version: 2.0.50727.42
74+//
75 //
76 // Changes to this file may cause incorrect behavior and will be lost if
77 // the code is regenerated.
78
79=== added file 'Flickr/gtk-gui/Flickr.UploadDialog.cs'
80--- Flickr/gtk-gui/Flickr.UploadDialog.cs 1970-01-01 00:00:00 +0000
81+++ Flickr/gtk-gui/Flickr.UploadDialog.cs 2009-04-24 00:44:55 +0000
82@@ -0,0 +1,164 @@
83+// ------------------------------------------------------------------------------
84+// <autogenerated>
85+// This code was generated by a tool.
86+//
87+//
88+// Changes to this file may cause incorrect behavior and will be lost if
89+// the code is regenerated.
90+// </autogenerated>
91+// ------------------------------------------------------------------------------
92+
93+namespace Flickr {
94+
95+
96+ public partial class UploadDialog {
97+
98+ private Gtk.Alignment alignment1;
99+
100+ private Gtk.HBox hbox1;
101+
102+ private Gtk.Image FlickrImage;
103+
104+ private Gtk.VBox vbox2;
105+
106+ private Gtk.Label TextLabel;
107+
108+ private Gtk.ProgressBar uploadProgress;
109+
110+ private Gtk.Button HideButton;
111+
112+ private Gtk.Button OKButton;
113+
114+ protected virtual void Build() {
115+ Stetic.Gui.Initialize(this);
116+ // Widget Flickr.UploadDialog
117+ this.Name = "Flickr.UploadDialog";
118+ this.Title = Mono.Unix.Catalog.GetString("Flickr Upload");
119+ this.Icon = Gdk.Pixbuf.LoadFromResource("flickr.png");
120+ this.WindowPosition = ((Gtk.WindowPosition)(4));
121+ this.Resizable = false;
122+ this.AllowGrow = false;
123+ this.SkipTaskbarHint = true;
124+ this.HasSeparator = false;
125+ // Internal child Flickr.UploadDialog.VBox
126+ Gtk.VBox w1 = this.VBox;
127+ w1.Name = "dialog1_VBox";
128+ w1.BorderWidth = ((uint)(2));
129+ // Container child dialog1_VBox.Gtk.Box+BoxChild
130+ this.alignment1 = new Gtk.Alignment(0.5F, 0.5F, 1F, 1F);
131+ this.alignment1.Name = "alignment1";
132+ this.alignment1.LeftPadding = ((uint)(10));
133+ this.alignment1.TopPadding = ((uint)(10));
134+ this.alignment1.RightPadding = ((uint)(10));
135+ this.alignment1.BottomPadding = ((uint)(10));
136+ // Container child alignment1.Gtk.Container+ContainerChild
137+ this.hbox1 = new Gtk.HBox();
138+ this.hbox1.Name = "hbox1";
139+ this.hbox1.Spacing = 6;
140+ // Container child hbox1.Gtk.Box+BoxChild
141+ this.FlickrImage = new Gtk.Image();
142+ this.FlickrImage.Name = "FlickrImage";
143+ this.hbox1.Add(this.FlickrImage);
144+ Gtk.Box.BoxChild w2 = ((Gtk.Box.BoxChild)(this.hbox1[this.FlickrImage]));
145+ w2.Position = 0;
146+ w2.Expand = false;
147+ w2.Fill = false;
148+ // Container child hbox1.Gtk.Box+BoxChild
149+ this.vbox2 = new Gtk.VBox();
150+ this.vbox2.Name = "vbox2";
151+ this.vbox2.Spacing = 6;
152+ // Container child vbox2.Gtk.Box+BoxChild
153+ this.TextLabel = new Gtk.Label();
154+ this.TextLabel.Name = "TextLabel";
155+ this.TextLabel.Justify = ((Gtk.Justification)(2));
156+ this.TextLabel.Ellipsize = ((Pango.EllipsizeMode)(3));
157+ this.TextLabel.WidthChars = 40;
158+ this.vbox2.Add(this.TextLabel);
159+ Gtk.Box.BoxChild w3 = ((Gtk.Box.BoxChild)(this.vbox2[this.TextLabel]));
160+ w3.Position = 0;
161+ w3.Expand = false;
162+ w3.Fill = false;
163+ // Container child vbox2.Gtk.Box+BoxChild
164+ this.uploadProgress = new Gtk.ProgressBar();
165+ this.uploadProgress.Name = "uploadProgress";
166+ this.vbox2.Add(this.uploadProgress);
167+ Gtk.Box.BoxChild w4 = ((Gtk.Box.BoxChild)(this.vbox2[this.uploadProgress]));
168+ w4.Position = 1;
169+ w4.Expand = false;
170+ w4.Fill = false;
171+ this.hbox1.Add(this.vbox2);
172+ Gtk.Box.BoxChild w5 = ((Gtk.Box.BoxChild)(this.hbox1[this.vbox2]));
173+ w5.Position = 1;
174+ this.alignment1.Add(this.hbox1);
175+ w1.Add(this.alignment1);
176+ Gtk.Box.BoxChild w7 = ((Gtk.Box.BoxChild)(w1[this.alignment1]));
177+ w7.Position = 0;
178+ w7.Expand = false;
179+ w7.Fill = false;
180+ // Internal child Flickr.UploadDialog.ActionArea
181+ Gtk.HButtonBox w8 = this.ActionArea;
182+ w8.Name = "dialog1_ActionArea";
183+ w8.Spacing = 6;
184+ w8.BorderWidth = ((uint)(5));
185+ w8.LayoutStyle = ((Gtk.ButtonBoxStyle)(4));
186+ // Container child dialog1_ActionArea.Gtk.ButtonBox+ButtonBoxChild
187+ this.HideButton = new Gtk.Button();
188+ this.HideButton.CanDefault = true;
189+ this.HideButton.CanFocus = true;
190+ this.HideButton.Name = "HideButton";
191+ this.HideButton.UseUnderline = true;
192+ // Container child HideButton.Gtk.Container+ContainerChild
193+ Gtk.Alignment w9 = new Gtk.Alignment(0.5F, 0.5F, 0F, 0F);
194+ // Container child GtkAlignment.Gtk.Container+ContainerChild
195+ Gtk.HBox w10 = new Gtk.HBox();
196+ w10.Spacing = 2;
197+ // Container child GtkHBox.Gtk.Container+ContainerChild
198+ Gtk.Image w11 = new Gtk.Image();
199+ w11.Pixbuf = Stetic.IconLoader.LoadIcon(this, "gtk-leave-fullscreen", Gtk.IconSize.LargeToolbar, 24);
200+ w10.Add(w11);
201+ // Container child GtkHBox.Gtk.Container+ContainerChild
202+ Gtk.Label w13 = new Gtk.Label();
203+ w13.LabelProp = Mono.Unix.Catalog.GetString("_Hide");
204+ w13.UseUnderline = true;
205+ w10.Add(w13);
206+ w9.Add(w10);
207+ this.HideButton.Add(w9);
208+ this.AddActionWidget(this.HideButton, 0);
209+ Gtk.ButtonBox.ButtonBoxChild w17 = ((Gtk.ButtonBox.ButtonBoxChild)(w8[this.HideButton]));
210+ w17.Expand = false;
211+ w17.Fill = false;
212+ // Container child dialog1_ActionArea.Gtk.ButtonBox+ButtonBoxChild
213+ this.OKButton = new Gtk.Button();
214+ this.OKButton.CanFocus = true;
215+ this.OKButton.Name = "OKButton";
216+ this.OKButton.UseUnderline = true;
217+ // Container child OKButton.Gtk.Container+ContainerChild
218+ Gtk.Alignment w18 = new Gtk.Alignment(0.5F, 0.5F, 0F, 0F);
219+ // Container child GtkAlignment1.Gtk.Container+ContainerChild
220+ Gtk.HBox w19 = new Gtk.HBox();
221+ w19.Spacing = 2;
222+ // Container child GtkHBox1.Gtk.Container+ContainerChild
223+ Gtk.Image w20 = new Gtk.Image();
224+ w20.Pixbuf = Stetic.IconLoader.LoadIcon(this, "gtk-ok", Gtk.IconSize.LargeToolbar, 24);
225+ w19.Add(w20);
226+ // Container child GtkHBox1.Gtk.Container+ContainerChild
227+ Gtk.Label w22 = new Gtk.Label();
228+ w22.LabelProp = Mono.Unix.Catalog.GetString("_OK");
229+ w22.UseUnderline = true;
230+ w19.Add(w22);
231+ w18.Add(w19);
232+ this.OKButton.Add(w18);
233+ this.AddActionWidget(this.OKButton, 0);
234+ Gtk.ButtonBox.ButtonBoxChild w26 = ((Gtk.ButtonBox.ButtonBoxChild)(w8[this.OKButton]));
235+ w26.Position = 1;
236+ w26.Expand = false;
237+ w26.Fill = false;
238+ if ((this.Child != null)) {
239+ this.Child.ShowAll();
240+ }
241+ this.DefaultWidth = 408;
242+ this.DefaultHeight = 147;
243+ this.Show();
244+ }
245+ }
246+}
247
248=== modified file 'Flickr/gtk-gui/generated.cs'
249--- Flickr/gtk-gui/generated.cs 2008-12-29 18:23:07 +0000
250+++ Flickr/gtk-gui/generated.cs 2009-04-17 20:57:18 +0000
251@@ -1,7 +1,7 @@
252 // ------------------------------------------------------------------------------
253 // <autogenerated>
254 // This code was generated by a tool.
255-// Mono Runtime Version: 2.0.50727.42
256+//
257 //
258 // Changes to this file may cause incorrect behavior and will be lost if
259 // the code is regenerated.
260
261=== modified file 'Flickr/gtk-gui/gui.stetic'
262--- Flickr/gtk-gui/gui.stetic 2009-01-09 07:25:58 +0000
263+++ Flickr/gtk-gui/gui.stetic 2009-04-24 01:15:22 +0000
264@@ -5,6 +5,7 @@
265 <target-gtk-version>2.12</target-gtk-version>
266 </configuration>
267 <import>
268+ <widget-library name="../../../../../../../usr/local/lib/gnome-do/Do.Interface.Linux.dll" />
269 <widget-library name="../bin/Debug/Flickr.dll" internal="true" />
270 </import>
271 <widget class="Gtk.Bin" id="Flickr.AccountConfig" design-size="401 347">
272@@ -104,7 +105,6 @@
273 <child>
274 <widget class="Gtk.Button" id="auth_btn">
275 <property name="MemberName" />
276- <property name="WidthRequest">174</property>
277 <property name="CanFocus">True</property>
278 <property name="Type">TextAndIcon</property>
279 <property name="Icon">stock:gtk-yes Menu</property>
280@@ -350,4 +350,130 @@
281 </widget>
282 </child>
283 </widget>
284+ <widget class="Gtk.Dialog" id="Flickr.UploadDialog" design-size="408 147">
285+ <property name="MemberName" />
286+ <property name="Title" translatable="yes">Flickr Upload</property>
287+ <property name="Icon">resource:flickr.png</property>
288+ <property name="WindowPosition">CenterOnParent</property>
289+ <property name="Resizable">False</property>
290+ <property name="AllowGrow">False</property>
291+ <property name="SkipTaskbarHint">True</property>
292+ <property name="Buttons">2</property>
293+ <property name="HelpButton">False</property>
294+ <property name="HasSeparator">False</property>
295+ <child internal-child="VBox">
296+ <widget class="Gtk.VBox" id="dialog1_VBox">
297+ <property name="MemberName" />
298+ <property name="BorderWidth">2</property>
299+ <child>
300+ <widget class="Gtk.Alignment" id="alignment1">
301+ <property name="MemberName" />
302+ <property name="LeftPadding">10</property>
303+ <property name="TopPadding">10</property>
304+ <property name="RightPadding">10</property>
305+ <property name="BottomPadding">10</property>
306+ <child>
307+ <widget class="Gtk.HBox" id="hbox1">
308+ <property name="MemberName" />
309+ <property name="Spacing">6</property>
310+ <child>
311+ <widget class="Gtk.Image" id="FlickrImage">
312+ <property name="MemberName" />
313+ </widget>
314+ <packing>
315+ <property name="Position">0</property>
316+ <property name="AutoSize">True</property>
317+ <property name="Expand">False</property>
318+ <property name="Fill">False</property>
319+ </packing>
320+ </child>
321+ <child>
322+ <widget class="Gtk.VBox" id="vbox2">
323+ <property name="MemberName" />
324+ <property name="Spacing">6</property>
325+ <child>
326+ <widget class="Gtk.Label" id="TextLabel">
327+ <property name="MemberName" />
328+ <property name="Justify">Center</property>
329+ <property name="Ellipsize">End</property>
330+ <property name="WidthChars">40</property>
331+ </widget>
332+ <packing>
333+ <property name="Position">0</property>
334+ <property name="AutoSize">True</property>
335+ <property name="Expand">False</property>
336+ <property name="Fill">False</property>
337+ </packing>
338+ </child>
339+ <child>
340+ <widget class="Gtk.ProgressBar" id="uploadProgress">
341+ <property name="MemberName" />
342+ </widget>
343+ <packing>
344+ <property name="Position">1</property>
345+ <property name="AutoSize">True</property>
346+ <property name="Expand">False</property>
347+ <property name="Fill">False</property>
348+ </packing>
349+ </child>
350+ </widget>
351+ <packing>
352+ <property name="Position">1</property>
353+ <property name="AutoSize">False</property>
354+ </packing>
355+ </child>
356+ </widget>
357+ </child>
358+ </widget>
359+ <packing>
360+ <property name="Position">0</property>
361+ <property name="AutoSize">True</property>
362+ <property name="Expand">False</property>
363+ <property name="Fill">False</property>
364+ </packing>
365+ </child>
366+ </widget>
367+ </child>
368+ <child internal-child="ActionArea">
369+ <widget class="Gtk.HButtonBox" id="dialog1_ActionArea">
370+ <property name="MemberName" />
371+ <property name="Spacing">6</property>
372+ <property name="BorderWidth">5</property>
373+ <property name="Size">2</property>
374+ <property name="LayoutStyle">End</property>
375+ <child>
376+ <widget class="Gtk.Button" id="HideButton">
377+ <property name="MemberName" />
378+ <property name="CanDefault">True</property>
379+ <property name="CanFocus">True</property>
380+ <property name="Type">TextAndIcon</property>
381+ <property name="Icon">stock:gtk-leave-fullscreen LargeToolbar</property>
382+ <property name="Label" translatable="yes">_Hide</property>
383+ <property name="UseUnderline">True</property>
384+ <property name="ResponseId">0</property>
385+ </widget>
386+ <packing>
387+ <property name="Expand">False</property>
388+ <property name="Fill">False</property>
389+ </packing>
390+ </child>
391+ <child>
392+ <widget class="Gtk.Button" id="OKButton">
393+ <property name="MemberName" />
394+ <property name="CanFocus">True</property>
395+ <property name="Type">TextAndIcon</property>
396+ <property name="Icon">stock:gtk-ok LargeToolbar</property>
397+ <property name="Label" translatable="yes">_OK</property>
398+ <property name="UseUnderline">True</property>
399+ <property name="ResponseId">0</property>
400+ </widget>
401+ <packing>
402+ <property name="Position">1</property>
403+ <property name="Expand">False</property>
404+ <property name="Fill">False</property>
405+ </packing>
406+ </child>
407+ </widget>
408+ </child>
409+ </widget>
410 </stetic-interface>
411\ No newline at end of file
412
413=== modified file 'Flickr/gtk-gui/objects.xml'
414--- Flickr/gtk-gui/objects.xml 2008-11-16 05:53:37 +0000
415+++ Flickr/gtk-gui/objects.xml 2009-04-23 21:37:32 +0000
416@@ -1,6 +1,2 @@
417 <objects attr-sync="on">
418- <object type="Flickr.UploadConfig" palette-category="Flickr" allow-children="false" base-type="Gtk.Bin">
419- <itemgroups />
420- <signals />
421- </object>
422 </objects>
423\ No newline at end of file
424
425=== modified file 'Flickr/src/UploadAction.cs'
426--- Flickr/src/UploadAction.cs 2008-12-24 03:48:49 +0000
427+++ Flickr/src/UploadAction.cs 2009-04-19 02:03:26 +0000
428@@ -30,17 +30,12 @@
429 using Do.Platform;
430 using Do.Platform.Linux;
431
432-using FlickrNet;
433-
434 namespace Flickr
435 {
436 public class UploadAction : Act, IConfigurable
437- {
438- static object count_lock = new object ();
439- static int upload_num;
440-
441- const string ImageExtensions = ".jpg .jpef .gif .png .tiff";
442-
443+ {
444+ const string ImageExtensions = ".jpg .jpeg .gif .png .tiff";
445+
446 public override string Name {
447 get { return Catalog.GetString ("Upload photo"); }
448 }
449@@ -59,13 +54,13 @@
450
451 public override IEnumerable<Type> SupportedItemTypes {
452 get {
453- return new Type [] { typeof (IFileItem) };
454+ yield return typeof (IFileItem);
455 }
456 }
457
458 public override IEnumerable<Type> SupportedModifierItemTypes {
459 get {
460- return new Type [] { typeof (ITextItem) };
461+ yield return typeof (ITextItem);
462 }
463 }
464
465@@ -82,6 +77,8 @@
466 public override IEnumerable<Item> Perform (IEnumerable<Item> items, IEnumerable<Item> modItems)
467 {
468 string tags;
469+ List<IFileItem> uploads;
470+
471 tags = AccountConfig.Tags + " ";
472
473 if (modItems.Any ()) {
474@@ -90,55 +87,37 @@
475 tags += tag.Text + " ";
476 }
477 }
478-
479+
480 //Build a list of all of the files to upload.
481- List<IFileItem> uploads = new List<IFileItem> ();
482+ uploads = new List<IFileItem> ();
483+
484 foreach (Item item in items) {
485 IFileItem file = item as IFileItem;
486+
487+ if (file == null)
488+ continue;
489+
490 if (Directory.Exists (file.Path)) {
491 DirectoryInfo dinfo = new DirectoryInfo (file.Path);
492- FileInfo [] finfo = dinfo.GetFiles ();
493- foreach (FileInfo f in finfo) {
494+ foreach (FileInfo f in dinfo.GetFiles ()) {
495 if (FileIsPicture (f.FullName))
496 uploads.Add (Services.UniverseFactory.NewFileItem (f.FullName));
497 }
498 } else {
499 uploads.Add (file);
500 }
501- upload_num = 1;
502- foreach (IFileItem photo in uploads) {
503- AsyncUploadToFlickr (photo, tags, uploads.Count);
504- }
505 }
506-
507- return null;
508- }
509
510- public static void AsyncUploadToFlickr (IFileItem photo, string tags, int num)
511- {
512- FlickrNet.Flickr flickr = new FlickrNet.Flickr (AccountConfig.ApiKey,
513- AccountConfig.ApiSecret, AccountConfig.AuthToken);
514-
515- new Thread ((ThreadStart) delegate {
516- try {
517- int thisUpload;
518-
519- flickr.UploadPicture (photo.Path, photo.Name, "", tags,
520- AccountConfig.IsPublic, AccountConfig.FamilyAllowed,
521- AccountConfig.FriendsAllowed);
522-
523- lock (count_lock) {
524- thisUpload = upload_num;
525- upload_num++;
526- }
527-
528- Services.Notifications.Notify ("Flickr",
529- String.Format ("Uploaded {0}. ({1} of {2})", photo.Name,
530- thisUpload, num), photo.Path);
531- } catch (FlickrNet.FlickrException e) {
532- Console.Error.WriteLine (e.Message);
533+ Services.Application.RunOnThread ( () => {
534+ using (UploadPool uploadQueue = new UploadPool (tags)) {
535+ foreach (IFileItem photo in uploads)
536+ uploadQueue.EnqueueUpload (photo);
537+
538+ uploadQueue.BeginUploads ();
539 }
540- }).Start ();
541+ });
542+
543+ yield break;
544 }
545
546 public Gtk.Bin GetConfiguration ()
547
548=== added file 'Flickr/src/UploadDialog.cs'
549--- Flickr/src/UploadDialog.cs 1970-01-01 00:00:00 +0000
550+++ Flickr/src/UploadDialog.cs 2009-04-24 00:44:55 +0000
551@@ -0,0 +1,82 @@
552+using System;
553+using Mono.Unix;
554+
555+using Gtk;
556+using Gdk;
557+using GLib;
558+
559+using Do.Platform;
560+
561+namespace Flickr
562+{
563+
564+
565+ public partial class UploadDialog : Gtk.Dialog
566+ {
567+ readonly string ProgressLabel;
568+ readonly string UploadingLabel;
569+ readonly string ContinuationText;
570+ readonly string FinishedUploadLabel;
571+ readonly string FinishedProgressLabel;
572+
573+ public UploadDialog()
574+ {
575+ Build();
576+
577+ HideButton.Clicked += (sender, args) => Destroy ();
578+ OKButton.Clicked += (sender, args) => Destroy ();
579+ this.Destroyed += OnDestroy;
580+ OKButton.Hide ();
581+
582+ this.CurrentUpload = 0;
583+ this.IsDestroyed = false;
584+ UploadingLabel = Catalog.GetString ("Uploading {0}...");
585+ ProgressLabel = Catalog.GetString ("Uploading {0} of {1}...");
586+ FinishedUploadLabel = Catalog.GetString ("Finished uploading images to Flickr.");
587+ FinishedProgressLabel = Catalog.GetString ("Uploaded {0} images");
588+ ContinuationText = Catalog.GetString ("Your images are still being uploaded.");
589+
590+ using (Pixbuf FlickrPix = Pixbuf.LoadFromResource ("flickr.png"))
591+ FlickrImage.Pixbuf = FlickrPix.ScaleSimple (75, 75, Gdk.InterpType.Bilinear);
592+
593+ TextLabel.Text = Catalog.GetString ("Your images are being uploaded to Flickr.");
594+ uploadProgress.Text = Catalog.GetString (string.Format (ProgressLabel, CurrentUpload, TotalUploads));
595+ }
596+
597+ public int TotalUploads {get; set; }
598+ public int CurrentUpload { get; set; }
599+ private bool IsDestroyed {get; set; }
600+
601+ protected void OnDestroy (object sender, EventArgs args)
602+ {
603+ this.IsDestroyed = true;
604+ if (CurrentUpload < TotalUploads)
605+ ShowDialog (ContinuationText);
606+ }
607+
608+ public void IncrementProgress (string text)
609+ {
610+ CurrentUpload++;
611+
612+ uploadProgress.Text = string.Format (ProgressLabel, CurrentUpload, TotalUploads);
613+ TextLabel.Text = string.Format (UploadingLabel, text);
614+
615+ uploadProgress.Fraction = Math.Min ((double) CurrentUpload / (double) TotalUploads, 1.0f);
616+ }
617+
618+ private void ShowDialog (string text)
619+ {
620+ Services.Notifications.Notify ("Flickr", text, "flickr.png@" + GetType ().Assembly.FullName);
621+ }
622+
623+ public void Finish ()
624+ {
625+ if (this.IsDestroyed)
626+ ShowDialog (string.Format (FinishedUploadLabel, TotalUploads));
627+ HideButton.Visible = false;
628+ OKButton.Visible = true;
629+ uploadProgress.Text = string.Format (FinishedProgressLabel, TotalUploads);
630+ TextLabel.Text = FinishedUploadLabel;
631+ }
632+ }
633+}
634\ No newline at end of file
635
636=== added file 'Flickr/src/UploadPool.cs'
637--- Flickr/src/UploadPool.cs 1970-01-01 00:00:00 +0000
638+++ Flickr/src/UploadPool.cs 2009-04-24 00:46:02 +0000
639@@ -0,0 +1,124 @@
640+// UploadPool.cs
641+//
642+// Copyright (C) 2008 Chris Szikszoy
643+//
644+// This program is free software: you can redistribute it and/or modify
645+// it under the terms of the GNU General Public License as published by
646+// the Free Software Foundation, either version 3 of the License, or
647+// (at your option) any later version.
648+//
649+// This program is distributed in the hope that it will be useful,
650+// but WITHOUT ANY WARRANTY; without even the implied warranty of
651+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
652+// GNU General Public License for more details.
653+//
654+// You should have received a copy of the GNU General Public License
655+// along with this program. If not, see <http://www.gnu.org/licenses/>.
656+//
657+
658+using System;
659+using System.Threading;
660+using System.Diagnostics;
661+using System.Collections.Generic;
662+
663+using Do.Platform;
664+using Do.Universe;
665+
666+using Gtk;
667+
668+using FlickrNet;
669+
670+namespace Flickr
671+{
672+
673+ public class UploadPool : IDisposable
674+ {
675+ object locker;
676+ const int WorkerCount = 4;
677+
678+ Thread[] uploaders;
679+ UploadDialog dialog;
680+ Queue<IFileItem> taskQ;
681+ FlickrNet.Flickr flickr;
682+
683+ public UploadPool (string tags)
684+ {
685+ UploadTags = tags;
686+ locker = new object ();
687+ taskQ = new Queue<IFileItem> ();
688+ uploaders = new Thread [WorkerCount];
689+ flickr = new FlickrNet.Flickr (AccountConfig.ApiKey, AccountConfig.ApiSecret, AccountConfig.AuthToken);
690+ }
691+
692+ public void EnqueueUpload (IFileItem file)
693+ {
694+ lock (locker)
695+ {
696+ taskQ.Enqueue (file);
697+ Monitor.PulseAll (locker);
698+ }
699+ }
700+
701+ public void BeginUploads ()
702+ {
703+ Log<UploadAction>.Debug ("Queue has {0} items", QueueLength);
704+
705+ Services.Application.RunOnMainThread ( () => {
706+ dialog = new UploadDialog ();
707+ dialog.TotalUploads = QueueLength;
708+ dialog.Show ();
709+ });
710+
711+ // Create and start a separate thread for each worker
712+ for (int i = 0; i < WorkerCount; i++)
713+ (uploaders [i] = new Thread (Consume)).Start ();
714+ }
715+
716+ public string UploadTags { get; private set; }
717+
718+ public int QueueLength {
719+ get { return taskQ.Count; }
720+ }
721+
722+ void Consume()
723+ {
724+ IFileItem photo;
725+
726+ do {
727+ lock (locker) {
728+ while (taskQ.Count == 0)
729+ Monitor.Wait (locker);
730+
731+ photo = taskQ.Dequeue();
732+ }
733+
734+ if (photo != null) {
735+ try {
736+ Services.Application.RunOnMainThread ( () => dialog.IncrementProgress (photo.Name));
737+ flickr.UploadPicture (photo.Path, photo.Name, "", UploadTags, AccountConfig.IsPublic, AccountConfig.FamilyAllowed,
738+ AccountConfig.FriendsAllowed);
739+ } catch (FlickrApiException e) {
740+ Log<UploadAction>.Error ("Cannot upload photos, please grant permissions in configuration dialog");
741+ }
742+ }
743+ else
744+ Log<UploadPool>.Debug ("Thread reached the end of queue");
745+
746+ } while (photo != null);
747+ }
748+
749+#region IDisposable
750+ public void Dispose()
751+ {
752+ // Enqueue one null task per worker to make each exit.
753+ foreach (Thread uploader in uploaders)
754+ EnqueueUpload (null);
755+ //wait until the upload threads have finished
756+ foreach (Thread uploader in uploaders)
757+ uploader.Join();
758+
759+ Services.Application.RunOnMainThread ( () => dialog.Finish ());
760+ }
761+#endregion
762+ }
763+}
764\ No newline at end of file

Subscribers

People subscribed via source and target branches