-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeskFlickrUI.cs
2049 lines (1827 loc) · 77.1 KB
/
DeskFlickrUI.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections;
using System.Threading;
using Gtk;
using Glade;
public class DeskFlickrUI
{
[Glade.Widget]
Window window1;
[Glade.Widget]
Label label1;
[Glade.Widget]
ProgressBar progressbar1;
[Glade.Widget]
ProgressBar progressbar2;
[Glade.Widget]
ImageMenuItem imagemenuitem2;
[Glade.Widget]
CheckMenuItem checkmenuitem3;
[Glade.Widget]
MenuItem menuitem3;
[Glade.Widget]
MenuItem menuitem4;
[Glade.Widget]
ImageMenuItem imagemenuitem5;
[Glade.Widget]
MenuItem menuitem2;
[Glade.Widget]
TreeView treeview1;
[Glade.Widget]
TreeView treeview2;
[Glade.Widget]
TextView textview2;
[Glade.Widget]
VPaned vpaned1;
[Glade.Widget]
HPaned hpaned1;
[Glade.Widget]
Toolbar toolbar1;
[Glade.Widget]
Toolbar toolbar2;
[Glade.Widget]
EventBox eventbox1;
[Glade.Widget]
EventBox eventbox2;
[Glade.Widget]
EventBox eventbox3;
[Glade.Widget]
EventBox eventbox4;
[Glade.Widget]
EventBox eventbox10;
[Glade.Widget]
Label label11;
[Glade.Widget]
Label label12;
[Glade.Widget]
Label label13;
[Glade.Widget]
Image image5;
[Glade.Widget]
Entry entry5;
// Edited photos only check button
[Glade.Widget]
CheckButton checkbutton2;
// Commented photos only check button
[Glade.Widget]
CheckButton checkbutton4;
// Exclude Privacy and License check button
[Glade.Widget]
CheckButton checkbutton3;
// Upload window
[Glade.Widget]
EventBox eventbox6;
Label popuplabel;
// Upload button
[Glade.Widget]
MenuItem menuitem5;
// Download button
[Glade.Widget]
MenuItem menuitem6;
// Photo count
[Glade.Widget]
EventBox eventbox11;
[Glade.Widget]
Label label19;
ToggleToolButton lockbutton;
ToggleToolButton streambutton;
ToggleToolButton conflictbutton;
ToggleToolButton uploadbutton;
ToggleToolButton downloadbutton;
ToolButton syncbutton;
// For toolbar2 on top left
ToolButton connectbutton;
ToolButton uploadfilechooserbutton;
Tooltips tips;
private static string BASE_DIR = System.AppDomain.CurrentDomain.BaseDirectory;
private static string IMAGE_DIR = System.IO.Path.Combine(BASE_DIR, "icons");
public static string ICON_PATH = System.IO.Path.Combine(IMAGE_DIR, "Font-Book.ico");
public static string THUMBNAIL_PATH = System.IO.Path.Combine(IMAGE_DIR, "FontBookThumbnail.png");
public static string SQTHUMBNAIL_PATH = System.IO.Path.Combine(IMAGE_DIR, "FontBookSquareThumbnail.png");
public static string FLICKR_ICON = System.IO.Path.Combine(IMAGE_DIR, "flickr_logo.gif");
private static DeskFlickrUI deskflickr = null;
public static Gdk.Color tabselectedcolor = new Gdk.Color(0x6A, 0x79, 0x7A);
public static Gdk.Color tabcolor = new Gdk.Color(0xCC, 0xCC, 0xB8);
// Needed to store the order of albums and photos shown in
// left and right panes respectively. These two variables used to
// store just the ids. However, an afterthought suggests that if they
// store the complete photo and set objects, it would be more efficient. So,
// changing to that.
private ArrayList _albums;
private ArrayList _photos;
private ArrayList _tags;
private ArrayList _pools; // stores (poolid, pooltitle) entry.
private ArrayList _blogs; // stores (blogid, blogtitle) entry.
// Keep track of photos who are modified both here, and in the server.
private ArrayList _conflictedphotos;
private Gdk.Pixbuf _nophotothumbnail;
private int leftcurselectedindex;
private int selectedtab;
private TargetEntry[] targets;
private ListStore photoStore;
private TreeModelFilter filter;
private Thread _connthread;
private Thread _populatephotosthread;
private Thread _searchwaitthread;
private bool _busysearching;
public class SelectedPhoto {
public Photo photo;
public string path;
public SelectedPhoto(Photo photo, string path) {
this.photo = photo;
this.path = path;
}
}
public class BlogSelectedPhoto : SelectedPhoto {
public BlogEntry blogentry;
public BlogSelectedPhoto(Photo photo, BlogEntry blogentry, string path)
: base (photo, path) {
this.blogentry = blogentry;
}
}
public enum ModeSelected {
NormalMode,
ConflictMode,
UploadMode,
BlogMode,
BlogAndConflictMode
}
public DeskFlickrUI.ModeSelected GetMode() {
DeskFlickrUI.ModeSelected mode = ModeSelected.NormalMode;
if (selectedtab == 3 && conflictbutton.Active) mode = ModeSelected.BlogAndConflictMode;
else if (uploadbutton.Active) mode = ModeSelected.UploadMode;
else if (conflictbutton.Active) mode = ModeSelected.ConflictMode;
else if (selectedtab == 3) mode = ModeSelected.BlogMode;
return mode;
}
public Gdk.Pixbuf GetDFOThumbnail() {
return _nophotothumbnail;
}
private DeskFlickrUI() {
_albums = new ArrayList();
_photos = new ArrayList();
_tags = new ArrayList();
_pools = new ArrayList();
_blogs = new ArrayList();
_conflictedphotos = new ArrayList();
leftcurselectedindex = 0;
selectedtab = 0;
targets = new TargetEntry[] {
new TargetEntry("text/uri-list", 0, 0)
};
}
public void CreateGUI() {
Application.Init();
Glade.XML gxml = new Glade.XML (null, "organizer.glade", "window1", null);
gxml.Autoconnect (this);
// Wao! Loading an image from file, didn't work when it was located
// in object constructor i.e. DeskFlickrUI(). Shifting it to this
// place, magically works!
_nophotothumbnail = new Gdk.Pixbuf(SQTHUMBNAIL_PATH);
tips = new Tooltips();
// Popup upload window, and label box.
eventbox6.ModifyBg(StateType.Normal, tabcolor);
// The value of stream button in this toolbar is being used by
// other initializations. So, this should be positioned _before_ them.
SetHorizontalToolBar();
SetTopLeftToolBar();
// Set Text for the label
label1.Text = "Desktop Flickr Organizer";
label12.Markup = "<span weight='bold'>Search: </span>";
label19.Text = "";
Gdk.Color greycolor = new Gdk.Color(0x7F, 0x7C, 0x7C);
eventbox11.ModifyBg(StateType.Normal, greycolor);
// Set Flames window label size.
label11.Wrap = true;
int height;
int width;
eventbox3.GetSizeRequest(out width, out height);
label11.SetSizeRequest(width, height);
tips.SetTip(eventbox3, "Flames Window", "Flames Window");
tips.Enable();
// Set upload window label.
popuplabel = new Label();
entry5.Changed += new EventHandler(OnFilterEntryChanged);
checkbutton2.Toggled += new EventHandler(OnFilterEntryChanged);
checkbutton3.Toggled += new EventHandler(OnFilterEntryChanged);
checkbutton4.Toggled += new EventHandler(OnFilterEntryChanged);
SetLeftTextView();
SetLeftTreeView();
SetRightTreeView();
// Set the menu bar
SetMenuBar();
SetVerticalBar();
SetFlamesWindow();
SetIsConnected(0);
progressbar2.Text = "Upload Status";
// Set window properties
window1.SetIconFromFile(ICON_PATH);
window1.DeleteEvent += OnWindowDeleteEvent;
RestoreWindow();
window1.ShowAll();
Application.Run();
}
private void RestoreWindow() {
int height = PersistentInformation.GetInstance().WindowHeight;
int width = PersistentInformation.GetInstance().WindowWidth;
if (width != 0 && height != 0) window1.Resize(width, height);
int vpos = PersistentInformation.GetInstance().VerticalPosition;
if (vpos != 0) vpaned1.Position = vpos;
int hpos = PersistentInformation.GetInstance().HorizontalPosition;
if (hpos != 0) hpaned1.Position = hpos;
}
private string GetInfoAlbum(Album a) {
System.Text.StringBuilder info = new System.Text.StringBuilder();
info.AppendFormat(
"<span font_desc='Times Bold 10'>{0}</span>",
Utils.EscapeForPango(a.Title));
info.AppendLine();
info.AppendFormat(
"<span font_desc='Times Bold 10'>{0} pics</span>", a.NumPics);
return info.ToString();
}
public void PopulateAlbums() {
UpdateFlameWindowLabel();
Gtk.ListStore albumStore = (Gtk.ListStore) treeview1.Model;
if (albumStore == null) {
albumStore = new Gtk.ListStore(typeof(Gdk.Pixbuf), typeof(string));
} else {
albumStore.Clear();
}
this._albums.Clear();
// Temporarily store treeiters
ArrayList treeiters = new ArrayList();
foreach (Album a in PersistentInformation.GetInstance().GetAlbums()) {
Photo primaryPhoto = PersistentInformation.GetInstance().
GetPhoto(a.PrimaryPhotoid);
Gdk.Pixbuf thumbnail = _nophotothumbnail;
if (primaryPhoto != null) {
thumbnail = primaryPhoto.Thumbnail;
}
TreeIter curiter = albumStore.AppendValues(thumbnail, GetInfoAlbum(a));
treeiters.Add(curiter);
// Now add the setid to albums.
this._albums.Add(a);
}
treeview1.Model = albumStore;
DoSelection(treeiters);
treeview1.ShowAll();
}
private void DoSelection(ArrayList treeiters) {
if (treeiters.Count > 0) {
// Scenario: There is only a single photo having a particular tag,
// which appears at the end of the tag list. The user removes the
// photo and the tag stops existing. Hence, the number of tag
// entries have fallen below the selected tag index.
if (leftcurselectedindex >= treeiters.Count) {
leftcurselectedindex = treeiters.Count - 1;
}
TreeIter curiter = (TreeIter) treeiters[leftcurselectedindex];
treeview1.Selection.SelectIter(curiter);
}
}
private string GetInfoTag(string tag) {
int numpics = PersistentInformation.GetInstance().GetCountPhotosForTag(tag);
return GetInfoTag(tag, numpics.ToString());
}
private string GetInfoTag(string tag, string numpics) {
System.Text.StringBuilder info = new System.Text.StringBuilder();
info.AppendFormat(
"<span font_desc='Times Bold 10'>{0}</span>", tag);
info.AppendLine();
info.AppendFormat(
"<span font_desc='Times Bold 10'>{0} pics</span>", numpics);
return info.ToString();
}
public void PopulateTags() {
UpdateFlameWindowLabel();
Gtk.ListStore tagStore = (Gtk.ListStore) treeview1.Model;
if (tagStore == null) {
tagStore = new Gtk.ListStore(typeof(Gdk.Pixbuf), typeof(string));
} else {
tagStore.Clear();
}
this._tags.Clear();
ArrayList treeiters = new ArrayList();
foreach (PersistentInformation.Entry entry in
PersistentInformation.GetInstance().GetAllTags()) {
string tag = entry.entry1;
string numpics = entry.entry2;
Photo p = PersistentInformation.GetInstance().GetSinglePhotoForTag(tag);
Gdk.Pixbuf thumbnail = _nophotothumbnail;
if (p != null) {
thumbnail = p.Thumbnail;
}
TreeIter curiter = tagStore.AppendValues(thumbnail, GetInfoTag(tag, numpics));
treeiters.Add(curiter);
// Now add the tag name to _tags.
this._tags.Add(tag);
}
treeview1.Model = tagStore;
DoSelection(treeiters);
treeview1.ShowAll();
}
private string GetInfoPool(PersistentInformation.Entry entry) {
int numpics = PersistentInformation.GetInstance()
.GetPhotoidsForPool(entry.entry1).Count;
return GetInfoPool(entry, numpics);
}
private string GetInfoPool(PersistentInformation.Entry entry, int numpics) {
System.Text.StringBuilder info = new System.Text.StringBuilder();
string pooltitle = entry.entry2;
info.AppendFormat(
"<span font_desc='Times Bold 10'>{0}</span>",
Utils.EscapeForPango(pooltitle));
info.AppendLine();
info.AppendFormat(
"<span font_desc='Times Bold 10'>{0} pics</span>", numpics);
return info.ToString();
}
public void PopulatePools() {
UpdateFlameWindowLabel();
Gtk.ListStore poolStore = (Gtk.ListStore) treeview1.Model;
if (poolStore == null) {
poolStore = new Gtk.ListStore(typeof(Gdk.Pixbuf), typeof(String));
} else {
poolStore.Clear();
}
this._pools.Clear();
ArrayList treeiters = new ArrayList();
foreach (PersistentInformation.Entry entry
in PersistentInformation.GetInstance().GetAllPools()) {
Photo p = PersistentInformation.GetInstance().GetSinglePhotoForPool(entry.entry1);
Gdk.Pixbuf thumbnail = _nophotothumbnail;
if (p != null) thumbnail = p.Thumbnail;
TreeIter curiter = poolStore.AppendValues(thumbnail, GetInfoPool(entry));
treeiters.Add(curiter);
this._pools.Add(entry);
}
treeview1.Model = poolStore;
DoSelection(treeiters);
treeview1.ShowAll();
}
private string GetInfoBlog(PersistentInformation.Entry entry) {
System.Text.StringBuilder info = new System.Text.StringBuilder();
string blogid = entry.entry1;
string blogtitle = entry.entry2;
info.AppendFormat("<span font_desc='Times Bold 10'>{0}</span>", blogtitle);
info.AppendLine();
int numentries =
PersistentInformation.GetInstance().GetEntriesForBlog(blogid).Count;
info.AppendFormat("<span font_desc='Times Bold 10'>{0} entries</span>", numentries);
return info.ToString();
}
private void PopulateBlogs() {
UpdateFlameWindowLabel();
Gtk.ListStore blogStore = (Gtk.ListStore) treeview1.Model;
if (blogStore == null)
blogStore = new Gtk.ListStore(typeof(Gdk.Pixbuf), typeof(String));
else blogStore.Clear();
this._blogs.Clear();
ArrayList treeiters = new ArrayList();
foreach (PersistentInformation.Entry entry
in PersistentInformation.GetInstance().GetAllBlogs()) {
Gdk.Pixbuf thumbnail = DeskFlickrUI.GetInstance().GetDFOThumbnail();
TreeIter curiter = blogStore.AppendValues(thumbnail, GetInfoBlog(entry));
treeiters.Add(curiter);
this._blogs.Add(entry);
}
treeview1.Model = blogStore;
DoSelection(treeiters);
treeview1.ShowAll();
}
public bool IsAlbumTabSelected() {
return selectedtab == 0;
}
public void RefreshLeftTreeView() {
if (selectedtab == 0) PopulateAlbums();
else if (selectedtab == 1) PopulateTags();
else if (selectedtab == 2) PopulatePools();
else if (selectedtab == 3) PopulateBlogs();
}
private void SetLeftTextView() {
TextTag tag = new TextTag("headline");
tag.Font = "Times Bold 12";
tag.WrapMode = WrapMode.Word;
// tag.BackgroundGdk = new Gdk.Color(0x99, 0x66, 0x00);
textview2.Buffer.TagTable.Add(tag);
tag = new TextTag("paragraph");
tag.Font = "Times Italic 10";
tag.WrapMode = WrapMode.Word;
tag.ForegroundGdk = new Gdk.Color(0, 0, 0x99);
textview2.Buffer.TagTable.Add(tag);
}
private void SetLeftTreeView() {
// Set tree view 1
Gtk.CellRendererText titleRenderer = new Gtk.CellRendererText();
titleRenderer.WrapMode = Pango.WrapMode.Word;
titleRenderer.WrapWidth = 200;
treeview1.AppendColumn ("Icon", new Gtk.CellRendererPixbuf(), "pixbuf", 0);
treeview1.AppendColumn ("Title", titleRenderer, "markup", 1);
treeview1.HeadersVisible = false;
treeview1.Model = null;
// Drag and drop mechanism
Gtk.Drag.DestSet(treeview1, Gtk.DestDefaults.All, targets, Gdk.DragAction.Copy);
treeview1.DragDataReceived += OnPhotoDraggedForAddition;
// Can use CursorChanged if need to get an event on every click.
treeview1.Selection.Changed += OnSelectionLeftTree;
treeview1.RowActivated += new RowActivatedHandler(OnDoubleClickLeftView);
// No need to specifically select the album tab, because treeview1's
// selection automatically triggers repopulation of photos.
// AlbumTabSelected(null, null);
}
// Don't really care about the selection data sent. Because, we can
// rather easily just look at the selected photos.
private void OnPhotoDraggedForAddition(object o, DragDataReceivedArgs args) {
TreePath path;
TreeViewDropPosition pos;
// This line determines the destination row.
treeview1.GetDestRowAtPos(args.X, args.Y, out path, out pos);
if (path == null) return;
int destindex = path.Indices[0];
if (selectedtab == 0) { // albums
// TODO: Allow addition to sets.
if (uploadbutton.Active) return; // Doesn't allow addition to sets yet.
string setid = ((Album) _albums[destindex]).SetId;
foreach (TreePath photospath in treeview2.Selection.GetSelectedRows()) {
string photoid = GetPhoto(photospath).Id;
bool exists = PersistentInformation.GetInstance()
.HasAlbumPhoto(photoid, setid);
if (exists) {
TreePath albumselectedpath = treeview1.Selection.GetSelectedRows()[0];
if (!streambutton.Active && !conflictbutton.Active
&& treeview2.Selection.GetSelectedRows().Length == 1
// If dragged dest album is same as the one selected.
&& albumselectedpath.Indices[0] == destindex) {
// Scenario: The user is viewing the set, and decides to
// change the primary photo. He can do so by dragging the photo
// from the respective set, to the set itself. However, make
// sure that only one photo is selected.
// The album selected is the same as the album the photo is
// dragged on.
PersistentInformation.GetInstance().SetPrimaryPhotoForAlbum(setid, photoid);
PersistentInformation.GetInstance().SetAlbumDirtyIfNotNew(setid);
PopulateAlbums();
}
} else { // The photo isn't present in set.
PersistentInformation.GetInstance().AddPhotoToAlbum(photoid, setid);
if (PersistentInformation.GetInstance().GetPhotoIdsForAlbum(setid).Count == 1) {
PersistentInformation.GetInstance().SetPrimaryPhotoForAlbum(setid, photoid);
}
PersistentInformation.GetInstance().SetAlbumDirtyIfNotNew(setid);
UpdateAlbumAtPath(path, (Album) _albums[destindex]);
}
}
}
else if (selectedtab == 1) { // tags
ArrayList selectedphotos = new ArrayList();
foreach (TreePath photospath in treeview2.Selection.GetSelectedRows()) {
Photo photo = GetPhoto(photospath);
string tag = (string) _tags[destindex];
if (uploadbutton.Active) {
photo.AddTag(tag);
PersistentInformation.GetInstance().UpdateInfoForUploadPhoto(photo);
}
else {
// Check if the original version is stored in db. Allow for revert.
if (!PersistentInformation.GetInstance().HasOriginalPhoto(photo.Id)
&& !PersistentInformation.GetInstance().IsPhotoDirty(photo.Id)) {
PersistentInformation.GetInstance().InsertOriginalPhoto(photo);
}
if (!PersistentInformation.GetInstance().HasTag(photo.Id, tag)) {
PersistentInformation.GetInstance().InsertTag(photo.Id, tag);
PersistentInformation.GetInstance().SetPhotoDirty(photo.Id, true);
}
}
photo.AddTag(tag);
TreePath childpath = filter.ConvertPathToChildPath(photospath);
SelectedPhoto selphoto = new SelectedPhoto(photo, childpath.ToString());
selectedphotos.Add(selphoto);
}
// UpdatePhotos will replace the old photos, with the new ones containing
// the tag information.
UpdatePhotos(selectedphotos);
UpdateTagAtPath(path, (string) _tags[destindex]);
}
else if (selectedtab == 2) { // pools
// TODO: Allow addition to pools.
if (uploadbutton.Active) return; // Doesn't allow addition to sets yet.
PersistentInformation.Entry entry = (PersistentInformation.Entry) _pools[destindex];
string groupid = entry.entry1;
foreach (TreePath photospath in treeview2.Selection.GetSelectedRows()) {
Photo photo = GetPhoto(photospath);
if (!PersistentInformation.GetInstance().HasPoolPhoto(photo.Id, groupid)) {
PersistentInformation.GetInstance().InsertPhotoToPool(photo.Id, groupid);
PersistentInformation.GetInstance().MarkPhotoAddedToPool(photo.Id, groupid, true);
}
else if (PersistentInformation.GetInstance()
.IsPhotoDeletedFromPool(photo.Id, groupid)) {
PersistentInformation.GetInstance()
.MarkPhotoDeletedFromPool(photo.Id, groupid, false);
}
}
UpdatePoolAtPath(path, entry);
}
else if (selectedtab == 3) { // blogs
if (uploadbutton.Active) return;
PersistentInformation.Entry entry = (PersistentInformation.Entry) _blogs[destindex];
string blogid = entry.entry1;
ArrayList selectedphotos = new ArrayList();
foreach (TreePath photospath in treeview2.Selection.GetSelectedRows()) {
Photo photo = GetPhoto(photospath);
if (!PersistentInformation.GetInstance().HasBlogPhoto(blogid, photo.Id)) {
BlogEntry blogentry =
new BlogEntry(blogid, photo.Id, photo.Title, photo.Description);
PersistentInformation.GetInstance().InsertEntryToBlog(blogentry);
}
TreePath childpath = filter.ConvertPathToChildPath(photospath);
SelectedPhoto selphoto = new SelectedPhoto(photo, childpath.ToString());
selectedphotos.Add(selphoto);
}
UpdatePhotos(selectedphotos);
UpdateBlogAtPath(path, entry);
}
}
private void UpdateAlbumAtPath(TreePath path, Album a) {
ListStore albumStore = (ListStore) treeview1.Model;
TreeIter iter;
albumStore.GetIter(out iter, path);
albumStore.SetValue(iter, 1, GetInfoAlbum(a));
}
private void UpdateTagAtPath(TreePath path, string tag) {
ListStore tagStore = (ListStore) treeview1.Model;
TreeIter iter;
tagStore.GetIter(out iter, path);
tagStore.SetValue(iter, 1, GetInfoTag(tag));
}
private void UpdatePoolAtPath(TreePath path, PersistentInformation.Entry entry) {
ListStore poolStore = (ListStore) treeview1.Model;
TreeIter iter;
poolStore.GetIter(out iter, path);
ArrayList photoids = PersistentInformation.GetInstance()
.GetPhotoidsForPool(entry.entry1);
poolStore.SetValue(iter, 1, GetInfoPool(entry, photoids.Count));
if (photoids.Count > 0) {
Gdk.Pixbuf thumbnail = _nophotothumbnail;
Photo p = PersistentInformation.GetInstance().GetPhoto((string) photoids[0]);
if (p != null) thumbnail = p.Thumbnail;
poolStore.SetValue(iter, 0, thumbnail);
}
}
private void UpdateBlogAtPath(TreePath path, PersistentInformation.Entry entry) {
ListStore blogStore = (ListStore) treeview1.Model;
TreeIter iter;
blogStore.GetIter(out iter, path);
blogStore.SetValue(iter, 1, GetInfoBlog(entry));
}
private void UpdateLeftTextView(string title, string desc) {
TextBuffer buf = textview2.Buffer;
buf.Clear();
// Set the buffer here.
buf.Text = "\n" + title + "\n\n" + desc;
TextIter start;
TextIter end;
start = buf.GetIterAtLine(1);
end = buf.GetIterAtLine(2);
buf.ApplyTag("headline", start, end);
buf.ApplyTag("paragraph", end, buf.EndIter);
textview2.Buffer = buf;
textview2.ShowAll();
}
// This method is a general purpose method, meant to take of changes
// done to albums, or tags, shown in the left pane.
private void OnSelectionLeftTree(object o, EventArgs args) {
TreePath[] treepaths = ((TreeSelection)o).GetSelectedRows();
if (treepaths.Length > 0) {
leftcurselectedindex = (treepaths[0]).Indices[0];
} else return;
bool ismodebuttonactivated = streambutton.Active || conflictbutton.Active
|| lockbutton.Active || uploadbutton.Active
|| downloadbutton.Active;
ArrayList photos = null;
if (selectedtab == 0) { // albums
// It is obvious that there would be at least one album, because
// otherwise left treeview model wouldn't be formed, and the user
// would have nothing to click upon.
Album album = (Album) _albums[leftcurselectedindex];
UpdateLeftTextView(album.Title, album.Desc);
// Set photos here
if (!ismodebuttonactivated) {
photos = PersistentInformation.GetInstance().GetPhotosForAlbum(album.SetId);
}
}
else if (selectedtab == 1) { // tags
string tag = (string) _tags[leftcurselectedindex];
UpdateLeftTextView(tag, "");
UpdateTagAtPath(treepaths[0], tag);
if (!ismodebuttonactivated) {
photos = PersistentInformation.GetInstance().GetPhotosForTag(tag);
}
} else if (selectedtab == 2) { // pools
PersistentInformation.Entry poolentry = (PersistentInformation.Entry) _pools[leftcurselectedindex];
string groupid = poolentry.entry1;
string grouptitle = poolentry.entry2;
UpdateLeftTextView(grouptitle, "");
if (!ismodebuttonactivated) {
photos = PersistentInformation.GetInstance().GetPhotosForPool(groupid);
}
} else if (selectedtab == 3) { // blogs
PersistentInformation.Entry bentry = (PersistentInformation.Entry) _blogs[leftcurselectedindex];
string blogid = bentry.entry1;
string blogtitle = bentry.entry2;
UpdateLeftTextView(blogtitle, "");
photos = new ArrayList();
if (!ismodebuttonactivated) {
foreach (BlogEntry blogentry in
PersistentInformation.GetInstance().GetEntriesForBlog(blogid)) {
Photo photo = PersistentInformation.GetInstance().GetPhoto(blogentry.Photoid);
photos.Add(photo);
}
}
}
if (!ismodebuttonactivated) {
PopulatePhotosTreeView(photos);
}
}
public void OnDoubleClickLeftView(object o, RowActivatedArgs args) {
if (selectedtab != 0) return; // if not albums, then don't care.
int index = args.Path.Indices[0];
Album album = new Album((Album) _albums[index]);
AlbumEditorUI.FireUp(album);
}
private string GetCol1Data(Photo p) {
System.Text.StringBuilder pangoTitle = new System.Text.StringBuilder();
pangoTitle.AppendFormat(
"<span font_desc='Times Bold 10'>{0}</span>",
Utils.EscapeForPango(p.Title));
if (!uploadbutton.Active // Not an upload photo entry.
&& PersistentInformation.GetInstance().IsPhotoDirty(p.Id)) {
pangoTitle.Append(
"<span font_desc='Times Bold 8' color='red'> [Edited]</span>");
}
if (!uploadbutton.Active
&& PersistentInformation.GetInstance().IsPhotoBlogged(p.Id)) {
pangoTitle.Append(
"<span font_desc='Times Bold 8' color='#026600'> [Blog Post]</span>");
}
if (!uploadbutton.Active
&& PersistentInformation.GetInstance().HasComment(p.Id)) {
// #937504 #A17F01
pangoTitle.Append(
"<span font_desc='Times Bold 8' color='#937504'> [Comments]</span>");
}
pangoTitle.AppendLine();
if (!uploadbutton.Active
&& PersistentInformation.GetInstance().IsDownloadEntryExists(p.Id)) {
string foldername = PersistentInformation.GetInstance().GetFolderNameForPhotoId(p.Id);
foldername = Utils.EscapeForPango(foldername);
pangoTitle.Append(
"<span font_desc='Times Bold 8' color='blue'>Download to: " + foldername + "</span>");
pangoTitle.AppendLine();
}
pangoTitle.AppendFormat(
"<span font_desc='Times Italic 10'>{0}</span>",
Utils.EscapeForPango(p.Description));
return pangoTitle.ToString();
}
private string GetCol2Data(Photo p) {
return String.Format(
"<span font_desc='Times 10'>{0}</span>",
p.TagString);
}
private string GetCol3Data(Photo p) {
return String.Format(
"<span font_desc='Times 10'>{0}</span>", p.PrivacyInfo);
}
private string GetCol4Data(Photo p) {
return String.Format(
"<span font_desc='Times 10'>{0}</span>", p.LicenseInfo);
}
private static string POPULATING_MSG = "Populating...";
private static string STOPPING_SYNC_MSG = "Stopping Sync...";
private System.Collections.Generic.IList<string> messagearray = null;
private void SetLabelPopup(bool isactivated, string message) {
if (messagearray == null) messagearray =
new System.Collections.Generic.List<string>();
if (isactivated) {
if (!messagearray.Contains(message)) {
messagearray.Add(message);
}
} else {
messagearray.Remove(message);
}
if (messagearray.Count > 0) {
string fullmessage = "";
foreach (string s in messagearray) {
fullmessage += s + " ";
}
popuplabel.Markup = "<span font_desc='Times Bold 12'>" + fullmessage
+ "</span>";
if (popuplabel.Parent == null) eventbox6.Add(popuplabel);
eventbox6.HeightRequest = 25;
eventbox6.ShowAll();
} else {
if (popuplabel.Parent != null) eventbox6.Remove(popuplabel);
eventbox6.HeightRequest = 0;
}
}
private void SetActivatePhotosTreeView(bool isactivated) {
if (!isactivated) {
SetLabelPopup(true, POPULATING_MSG);
treeview2.Sensitive = false;
} else {
SetLabelPopup(false, POPULATING_MSG);
treeview2.Sensitive = true;
}
}
// To be run in a thread by PopulatePhotosTreeView method.
private void PopulateStore() {
Gtk.Application.Invoke(delegate{
SetActivatePhotosTreeView(false);
});
// Note that whatever change we do to photoStore, i.e. addition or
// editing of entries, filter is triggered. So, we'll create a store
// first, and then just assign this new store to the global photoStore.
ListStore store = new Gtk.ListStore(
typeof(Gdk.Pixbuf), typeof(string),
typeof(string), typeof(string),
typeof(string));
foreach (Photo p in _photos) {
store.AppendValues(p.Thumbnail, GetCol1Data(p), GetCol2Data(p),
GetCol3Data(p), GetCol4Data(p));
}
Gtk.Application.Invoke(delegate{
photoStore = store;
filter = new TreeModelFilter(photoStore, null);
filter.VisibleFunc = new TreeModelFilterVisibleFunc(FilterPhotos);
treeview2.Model = filter;
SetActivatePhotosTreeView(true);
if (uploadbutton.Active) {
SetUploadWindow(true);
}
uploadfilechooserbutton.Sensitive = true;
treeview2.ShowAll();
});
}
private void UpdatePhotoCountLabel() {
int count = 0;
foreach (Photo p in _photos) {
if (FilterPhoto(p)) count++;
}
label19.Markup = "<span foreground='white' font_desc='Times' weight='bold'> "
+ count + " photos </span>";
}
public void PopulatePhotosTreeView(ArrayList photos) {
if (photos == null) return;
if (_populatephotosthread != null) _populatephotosthread.Abort();
_photos.Clear();
_photos.AddRange(photos);
UpdatePhotoCountLabel();
ThreadStart job = new ThreadStart(PopulateStore);
_populatephotosthread = new Thread(job);
_populatephotosthread.Start();
}
private bool FilterPhotos(TreeModel model, TreeIter iter) {
int index = model.GetPath(iter).Indices[0];
Photo p = (Photo) _photos[index];
return FilterPhoto(p);
}
private bool FilterPhoto(Photo p) {
// Photo has to be dirty if 'Only Edited Photos' is ticked.
if (checkbutton2.Active
&& !uploadbutton.Active
&& !PersistentInformation.GetInstance().IsPhotoDirty(p.Id))
return false;
// Now check for 'Commented Photos Only'
if (checkbutton4.Active
&& !uploadbutton.Active
&& !PersistentInformation.GetInstance().HasComment(p.Id))
return false;
string query = entry5.Text;
if (query == "") return true;
bool flag = false;
System.StringComparison comp = System.StringComparison.OrdinalIgnoreCase;
if (p.Title.IndexOf(query, comp) > -1) flag = true;
else if (p.Description.IndexOf(query, comp) > -1) flag = true;
else if (p.TagString.IndexOf(query, comp) > -1) flag = true;
else if (!checkbutton3.Active
&& p.PrivacyInfo.IndexOf(query, comp) > -1) flag = true;
else if (!checkbutton3.Active
&& p.LicenseInfo.IndexOf(query, comp) > -1) flag = true;
else if (checkbutton4.Active
&& PersistentInformation.GetInstance()
.HasCommentText(p.Id, query)) flag = true;
return flag;
}
// If the user has used search tab, the path
// provided here wouldn't exactly show the absolute position in the
// model, because entries would have been filtered out.
private Photo GetPhoto(TreePath path) {
TreePath childpath = filter.ConvertPathToChildPath(path);
return (Photo) _photos[childpath.Indices[0]];
}
private void OnFilterEntryChanged(object o, EventArgs args) {
if (_searchwaitthread != null && !_busysearching) _searchwaitthread.Abort();
_searchwaitthread = new Thread(new ThreadStart(DoWait));
_searchwaitthread.Start();
}
private void DoWait() {
Thread.Sleep(500);
Thread searchthread = new Thread(new ThreadStart(DoFilterEntries));
searchthread.Start();
}
private void DoFilterEntries() {
if (filter == null) return;
Gtk.Application.Invoke(delegate{
filter.Refilter();
UpdatePhotoCountLabel();
});
}
// This method is used only to refresh the photos in the right pane.
// Its not used to populate photos when a tab selection is made,
// or stream button is pressed. It doesn't populate new different
// set of photos, just is intended to refresh the already existant ones.
public void RefreshPhotosTreeView() {
ArrayList photos = null;
if (streambutton.Active) {
photos = PersistentInformation.GetInstance().GetAllPhotos();
}
else if (conflictbutton.Active) {
photos = new ArrayList();
foreach (Photo src in _conflictedphotos) {
Photo p = PersistentInformation.GetInstance().GetPhoto(src.Id);
if (p == null) continue;
photos.Add(p);
}
}
else if (selectedtab == 0) {
string setid = ((Album) _albums[leftcurselectedindex]).SetId;
photos = PersistentInformation.GetInstance().GetPhotosForAlbum(setid);
}
else if (selectedtab == 1) {
string tag = (string) _tags[leftcurselectedindex];
photos = PersistentInformation.GetInstance().GetPhotosForTag(tag);
}
PopulatePhotosTreeView(photos);
}
public void UpdatePhotos(ArrayList selectedphotos) {
foreach (SelectedPhoto sel in selectedphotos) {
// SelectedPhoto stores childpath.
TreePath childpath = new TreePath(sel.path);
_photos.RemoveAt(childpath.Indices[0]);