-
Notifications
You must be signed in to change notification settings - Fork 0
/
PhotoEditorUI.cs
902 lines (791 loc) · 31.1 KB
/
PhotoEditorUI.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
using System;
using System.Collections;
using Gtk;
using Glade;
public class PhotoEditorUI
{
[Glade.Widget]
Window window2;
[Glade.Widget]
Notebook notebook1;
[Glade.Widget]
Table table1;
[Glade.Widget]
Label label2;
[Glade.Widget]
Label label3;
[Glade.Widget]
Label label4;
[Glade.Widget]
Label label5;
[Glade.Widget]
Label label6;
[Glade.Widget]
Label label7;
[Glade.Widget]
Entry entry1;
[Glade.Widget]
TextView textview5;
[Glade.Widget]
ComboBox combobox1;
[Glade.Widget]
ComboBox combobox2;
[Glade.Widget]
IconView iconview1;
[Glade.Widget]
TextView textview3;
[Glade.Widget]
TextView textview4;
[Glade.Widget]
Button button3;
[Glade.Widget]
Button button4;
[Glade.Widget]
CheckButton checkbutton1;
[Glade.Widget]
Button button5;
[Glade.Widget]
EventBox eventbox5;
[Glade.Widget]
Label label14;
// Save and Close
[Glade.Widget]
Button button6;
[Glade.Widget]
Image image3;
// Search tag
[Glade.Widget]
Label label15;
[Glade.Widget]
Entry entry2;
// Revert button
[Glade.Widget]
Button button9;
[Glade.Widget]
Label label17;
[Glade.Widget]
Label label18;
[Glade.Widget]
Entry entry4;
[Glade.Widget]
TextView textview7;
// Comments Tab
[Glade.Widget]
Toolbar toolbar3;
[Glade.Widget]
TreeView treeview3;
private ArrayList _tags;
private ArrayList _selectedphotos;
private System.Collections.Generic.IDictionary<string, Photo> _originalphotos;
private int _curphotoindex;
private string _currenturl;
private TreeModelFilter _filter;
private ArrayList _comments;
// I haven't been able to figure out a way so that only the user
// selection of combobox elements, would trigger the OnPrivacyChanged
// and OnLicenseChanged methods. So, I'll go with a hack, by passing
// in a boolean variable, which can tell these methods, when to not
// heed to the changes done to the box.
private bool _ignorechangedevent;
private bool _isconflictmode;
private bool _isuploadmode;
private bool _isblogmode;
private Tooltips tips;
private ToolButton _addcommentbutton;
private ToolButton _editcommentbutton;
private ToolButton _deletecommentbutton;
private PhotoEditorUI(ArrayList selectedphotos, DeskFlickrUI.ModeSelected mode)
{
Glade.XML gxml = new Glade.XML (null, "organizer.glade", "window2", null);
gxml.Autoconnect (this);
_isconflictmode = (mode == DeskFlickrUI.ModeSelected.ConflictMode);
_isuploadmode = (mode == DeskFlickrUI.ModeSelected.UploadMode);
_isblogmode = (mode == DeskFlickrUI.ModeSelected.BlogMode);
if (mode == DeskFlickrUI.ModeSelected.BlogAndConflictMode) {
_isconflictmode = true;
_isblogmode = true;
}
_tags = new ArrayList();
_comments = new ArrayList();
window2.Title = "Edit information for " + selectedphotos.Count + " photos";
window2.SetIconFromFile(DeskFlickrUI.ICON_PATH);
notebook1.SetTabLabelText(notebook1.CurrentPageWidget, "Information");
notebook1.NextPage();
notebook1.SetTabLabelText(notebook1.CurrentPageWidget, "Tags");
notebook1.NextPage();
notebook1.SetTabLabelText(notebook1.CurrentPageWidget, "Comments");
tips = new Tooltips();
SetCommentsToolBar();
tips.Enable();
SetCommentsTree();
if (_isconflictmode) {
notebook1.NextPage();
notebook1.SetTabLabelText(notebook1.CurrentPageWidget, "Information at Server");
} else {
notebook1.RemovePage(3);
}
if (_isblogmode) {
notebook1.NextPage();
notebook1.SetTabLabelText(notebook1.CurrentPageWidget, "Blog Entry");
notebook1.Page = 3; // Default page is blog entry if editor is in Blog mode.
} else {
if (_isconflictmode) notebook1.RemovePage(4);
else notebook1.RemovePage(3);
notebook1.Page = 0; // Default page is photo editing.
}
table1.SetColSpacing(0, 50);
// Set Labels
label6.Text = "Edit";
label5.Text = "Title:";
label4.Text = "Description:";
label3.Text = "Visibility:";
label2.Text = "License:";
if (_isuploadmode) label2.Sensitive = false;
// Labels for blog tab.
label17.Text = "Title: ";
label18.Text = "Description: ";
// Search box
label15.Markup = "<span weight='bold'>Search: </span>";
entry2.Changed += new EventHandler(OnFilterEntryChanged);
// Revert button
button9.Label = "Revert Photo(s)";
button9.Clicked += new EventHandler(OnRevertButtonClicked);
// entry1.ModifyFont(Pango.FontDescription.FromString("FreeSerif 10"));
SetPrivacyComboBox();
SetLicenseComboBox();
SetTagTreeView();
// Make previous and next buttons insensitive. They'll become sensitive
// only when the user ticks the 'Per Photo' checkbutton.
button3.Sensitive = false;
button4.Sensitive = false;
checkbutton1.Toggled += new EventHandler(OnPerPageCheckToggled);
button3.Clicked += new EventHandler(OnPrevButtonClick);
button4.Clicked += new EventHandler(OnNextButtonClick);
button5.Clicked += new EventHandler(OnSaveButtonClick);
button6.Clicked += new EventHandler(OnCancelButtonClick);
entry1.Changed += new EventHandler(OnTitleChanged);
textview5.Buffer.Changed += new EventHandler(OnDescChanged);
combobox1.Changed += new EventHandler(OnPrivacyChanged);
combobox2.Changed += new EventHandler(OnLicenseChanged);
entry4.Changed += new EventHandler(OnBlogTitleChanged);
textview7.Buffer.Changed += new EventHandler(OnBlogDescChanged);
textview3.Buffer.Changed += new EventHandler(OnTagsChanged);
TextTag texttag = new TextTag("conflict");
texttag.Font = "Times Italic 10";
texttag.WrapMode = WrapMode.Word;
texttag.ForegroundGdk = new Gdk.Color(0x99, 0, 0);
textview4.Buffer.TagTable.Add(texttag);
// Showing photos should be the last step.
this._selectedphotos = selectedphotos;
if (selectedphotos.Count == 1) {
checkbutton1.Sensitive = false;
ShowInformationForCurrentPhoto();
} else {
EmbedCommonInformation();
}
// Save a copy of the original photos, so that only those photos
// which have been edited, would have their dirty bit set. Advantage:
// this would reduce the number of dirty photos, and hence there'll
// be lesser photos to update when sycing with server.
_originalphotos = new System.Collections.Generic.Dictionary<string, Photo>();
foreach (DeskFlickrUI.SelectedPhoto sel in _selectedphotos) {
Photo p = sel.photo;
_originalphotos.Add(p.Id, new Photo(p));
}
eventbox5.ButtonPressEvent += OnLinkPressed;
eventbox5.EnterNotifyEvent += MouseOnLink;
eventbox5.LeaveNotifyEvent += MouseLeftLink;
window2.ShowAll();
}
public static void FireUp(ArrayList selectedphotos, DeskFlickrUI.ModeSelected mode) {
new PhotoEditorUI(selectedphotos, mode);
}
private void SetCommentsToolBar() {
toolbar3.ToolbarStyle = ToolbarStyle.Icons;
_addcommentbutton = new ToolButton(Stock.Add);
_addcommentbutton.Sensitive = true;
_addcommentbutton.SetTooltip(tips, "Add Comment", "Add Comment");
_addcommentbutton.Clicked += new EventHandler(OnAddCommentButtonClicked);
toolbar3.Insert(_addcommentbutton, -1);
_editcommentbutton = new ToolButton(Stock.Edit);
_editcommentbutton.Sensitive = true;
_editcommentbutton.SetTooltip(tips, "Edit Comment", "Edit Comment");
_editcommentbutton.Clicked += new EventHandler(OnEditCommentButtonClicked);
toolbar3.Insert(_editcommentbutton, -1);
_deletecommentbutton = new ToolButton(Stock.Delete);
_deletecommentbutton.Sensitive = true;
_deletecommentbutton.SetTooltip(tips, "Delete Comment", "Delete Comment");
_deletecommentbutton.Clicked += new EventHandler(OnDeleteCommentButtonClicked);
toolbar3.Insert(_deletecommentbutton, -1);
}
private void SetActivateComments(bool issensitive) {
_addcommentbutton.Sensitive = issensitive;
_editcommentbutton.Sensitive = issensitive;
_deletecommentbutton.Sensitive = issensitive;
if (!issensitive) {
treeview3.Model = null;
}
}
private bool RunInputTextDialog(string title, string button1,
string originalcomment, out string comment) {
Dialog d = new Dialog();
d.SetIconFromFile(DeskFlickrUI.ICON_PATH);
d.Title = title;
d.AddButton(button1, Gtk.ResponseType.Ok);
d.AddButton(Stock.Cancel, Gtk.ResponseType.Cancel);
ScrolledWindow swin = new ScrolledWindow();
swin.HscrollbarPolicy = Gtk.PolicyType.Never;
swin.VscrollbarPolicy = Gtk.PolicyType.Automatic;
swin.ShadowType = Gtk.ShadowType.EtchedIn;
TextView tv = new TextView();
tv.WrapMode = Gtk.WrapMode.WordChar;
tv.BorderWidth = 2;
tv.Buffer.Text = originalcomment;
swin.Add(tv);
d.VBox.Add(swin);
d.WidthRequest = 400;
d.HeightRequest = 200;
d.ShowAll();
Gtk.ResponseType response = (Gtk.ResponseType) d.Run();
comment = tv.Buffer.Text;
d.Destroy();
if (response == Gtk.ResponseType.Cancel) return false;
else if (comment.Trim() == "") return false;
else return true;
}
private void OnAddCommentButtonClicked(object o, EventArgs args) {
string comment;
if (!RunInputTextDialog("Add New Comment", Stock.Add, "", out comment)) return;
Photo p = ((DeskFlickrUI.SelectedPhoto) _selectedphotos[_curphotoindex]).photo;
PersistentInformation.GetInstance().InsertNewComment(p.Id, comment);
PopulateComments(p.Id);
}
private void OnEditCommentButtonClicked(object o, EventArgs args) {
if (treeview3.Selection.GetSelectedRows().Length == 0) return;
Photo p = ((DeskFlickrUI.SelectedPhoto) _selectedphotos[_curphotoindex]).photo;
TreePath path = treeview3.Selection.GetSelectedRows()[0];
Comment comment = (Comment) _comments[path.Indices[0]];
string originalcomment = comment.CommentHtml;
string commenthtml;
if (!RunInputTextDialog(
"Edit Comment", Stock.Ok, originalcomment, out commenthtml)) return;
PersistentInformation.GetInstance().UpdateComment(
p.Id, comment.CommentId, commenthtml, true);
PopulateComments(p.Id);
}
private void OnDeleteCommentButtonClicked(object o, EventArgs args) {
if (treeview3.Selection.GetSelectedRows().Length == 0) return;
MessageDialog md = new MessageDialog(
window2, DialogFlags.DestroyWithParent, MessageType.Question,
ButtonsType.YesNo,
"Are you sure you want to delete the comment?");
ResponseType response = ResponseType.No;
response = (ResponseType) md.Run();
md.Destroy();
if (response == ResponseType.No) return;
Photo p = ((DeskFlickrUI.SelectedPhoto) _selectedphotos[_curphotoindex]).photo;
TreePath path = treeview3.Selection.GetSelectedRows()[0];
string commentid = ((Comment) _comments[path.Indices[0]]).CommentId;
if (commentid.IndexOf("new:") > -1) { // new comment.
PersistentInformation.GetInstance().DeleteComment(p.Id, commentid);
} else {
PersistentInformation.GetInstance().MarkCommentForDeletion(p.Id, commentid);
}
PopulateComments(p.Id);
}
private void SetCommentsTree() {
Gtk.CellRendererText textcell = new Gtk.CellRendererText();
textcell.WrapMode = Pango.WrapMode.WordChar;
textcell.WrapWidth = 450;
treeview3.AppendColumn("Comments", textcell, "markup", 0);
treeview3.HeadersVisible = false;
treeview3.RulesHint = true;
treeview3.RowActivated += new RowActivatedHandler(OnEditCommentButtonClicked);
}
private int GetIndexOfPrivacyBox(Photo p) {
if (p.IsPublic == 1) return 1;
else if ((p.IsFriend == 1) && (p.IsFamily == 1)) return 2;
else if (p.IsFriend == 1) return 3;
else if (p.IsFamily == 1) return 4;
else return 5;
}
private void SetPhotoPrivacyFromBox(ref Photo p, int index) {
if (index == 1) {
p.IsPublic = 1; p.IsFriend = 0; p.IsFamily = 0;
} else if (index == 2) {
p.IsPublic = 0; p.IsFriend = 1; p.IsFamily = 1;
} else if (index == 3) {
p.IsPublic = 0; p.IsFriend = 1; p.IsFamily = 0;
} else if (index == 4) {
p.IsPublic = 0; p.IsFriend = 0; p.IsFamily = 1;
} else {
p.IsPublic = 0; p.IsFriend = 0; p.IsFamily = 0;
}
}
private void SetPrivacyComboBox() {
// Set Combo boxes - Privacy Level
combobox1.Clear();
CellRendererText cell = new CellRendererText();
combobox1.PackStart(cell, false);
combobox1.AddAttribute(cell, "text", 0);
ListStore store1 = new ListStore(typeof(string));
store1.AppendValues("");
store1.AppendValues(GetPangoFormattedText("Public"));
store1.AppendValues(GetPangoFormattedText("Only Friends and Family"));
store1.AppendValues(GetPangoFormattedText("Only Friends"));
store1.AppendValues(GetPangoFormattedText("Only Family"));
store1.AppendValues(GetPangoFormattedText("Private"));
combobox1.Model = store1;
}
private int GetIndexOfLicenseBox(Photo p) {
return p.License + 1;
}
private Photo SetPhotoLicenseFromBox(ref Photo p, int index) {
p.License = index - 1;
return p;
}
private void SetLicenseComboBox() {
if (_isuploadmode) combobox2.Sensitive = false;
// Set Combo boxes - License
combobox2.Clear();
CellRendererText cell2 = new CellRendererText();
combobox2.PackStart(cell2, false);
combobox2.AddAttribute(cell2, "text", 0);
ListStore store2 = new ListStore(typeof(string));
store2.AppendValues("");
store2.AppendValues(GetPangoFormattedText("All Rights Reserved"));
store2.AppendValues(GetPangoFormattedText("Attribution-NonCommercial-ShareAlike License"));
store2.AppendValues(GetPangoFormattedText("Attribution-NonCommercial License"));
store2.AppendValues(GetPangoFormattedText("Attribution-NonCommercial-NoDerivs License"));
store2.AppendValues(GetPangoFormattedText("Attribution License"));
store2.AppendValues(GetPangoFormattedText("Attribution-ShareAlike License"));
store2.AppendValues(GetPangoFormattedText("Attribution-NoDerivs License"));
combobox2.Model = store2;
}
private void OnFilterEntryChanged(object o, EventArgs args) {
_filter.Refilter();
}
private void SetTagTreeView() {
ListStore tagstore = new ListStore(typeof(string));
_tags.Clear();
foreach(PersistentInformation.Entry entry in
PersistentInformation.GetInstance().GetAllTags()) {
string tag = entry.entry1;
string numpics = entry.entry2;
_tags.Add(tag);
tagstore.AppendValues(tag + "(" + numpics + ")");
}
_filter = new TreeModelFilter(tagstore, null);
_filter.VisibleFunc = new TreeModelFilterVisibleFunc(FilterTags);
iconview1.Model = _filter;
iconview1.TextColumn = 0;
iconview1.ItemActivated += new ItemActivatedHandler(OnTagClicked);
}
private bool FilterTags(TreeModel model, TreeIter iter) {
int index = model.GetPath(iter).Indices[0];
string tag = (string) _tags[index];
string query = entry2.Text;
System.StringComparison comp = System.StringComparison.OrdinalIgnoreCase;
return (tag.IndexOf(query, comp) > -1);
}
private string GetPangoFormattedText(string text) {
//return String.Format("<span font_desc='FreeSerif 10'>{0}</span>", text);
return text;
}
private void SetPhotoLink(string photoid) {
string userid = PersistentInformation.GetInstance().UserId;
if (_isuploadmode || photoid.Equals("") || userid.Equals("")) {
_currenturl = "";
label14.Text = "";
return;
}
_currenturl = String.Format(
"http://www.flickr.com/photos/{0}/{1}", userid, photoid);
label14.Markup = "<span foreground='#666666' style='italic'>View in browser</span>";
}
private void OnLinkPressed(object sender, EventArgs args) {
if (_currenturl.Equals("")) return;
System.Diagnostics.Process.Start(_currenturl);
}
private void MouseOnLink(object sender, EnterNotifyEventArgs args) {
if (_currenturl.Equals("")) return;
label14.Markup =
"<span foreground='#666666' underline='low' style='italic'>View in browser</span>";
}
private void MouseLeftLink(object sender, LeaveNotifyEventArgs args) {
if (_currenturl.Equals("")) return;
label14.Markup = "<span foreground='#666666' style='italic'>View in browser</span>";
}
private bool IsPhotoEdited(Photo p) {
if (!PersistentInformation.GetInstance().HasOriginalPhoto(p.Id)) return false;
Photo originalphoto = PersistentInformation.GetInstance().GetOriginalPhoto(p.Id);
return !originalphoto.isEqual(p);
}
private void EmbedCommonInformation() {
// Work upon the selected photos here.
Photo firstphoto = ((DeskFlickrUI.SelectedPhoto) _selectedphotos[0]).photo;
string commonTitle = firstphoto.Title;
string commonDesc = firstphoto.Description;
int commonPrivacy = GetIndexOfPrivacyBox(firstphoto);
int commonLicense = GetIndexOfLicenseBox(firstphoto);
ArrayList tagschosen = firstphoto.Tags;
bool isanyphotodirty = false;
foreach (DeskFlickrUI.SelectedPhoto sel in _selectedphotos) {
Photo p = sel.photo;
if (!commonTitle.Equals(p.Title)) commonTitle = "";
if (!commonDesc.Equals(p.Description)) commonDesc = "";
if (commonPrivacy != GetIndexOfPrivacyBox(p)) commonPrivacy = 0;
if (commonLicense != GetIndexOfLicenseBox(p)) commonLicense = 0;
tagschosen = Utils.GetIntersection(tagschosen, p.Tags);
if (!_isuploadmode && IsPhotoEdited(p)) isanyphotodirty = true;
}
entry1.Text = commonTitle;
textview5.Buffer.Text = commonDesc;
_ignorechangedevent = true;
{
combobox1.Active = commonPrivacy;
combobox2.Active = commonLicense;
textview3.Buffer.Text = Utils.GetDelimitedString(tagschosen, " ");
}
_ignorechangedevent = false;
if (_isblogmode) {
BlogEntry firstblogentry = ((DeskFlickrUI.BlogSelectedPhoto) _selectedphotos[0]).blogentry;
string commonblogtitle = firstblogentry.Title;
string commonblogdesc = firstblogentry.Desc;
foreach (DeskFlickrUI.BlogSelectedPhoto bsel in _selectedphotos) {
if (!commonblogtitle.Equals(bsel.blogentry.Title)) commonblogtitle = "";
if (!commonblogdesc.Equals(bsel.blogentry.Desc)) commonblogdesc = "";
}
entry4.Text = commonblogtitle;
textview7.Buffer.Text = commonblogdesc;
}
image3.Sensitive = false;
image3.Pixbuf = null;
button3.Sensitive = false;
button4.Sensitive = false;
label7.Text = "";
label7.Sensitive = false;
SetPhotoLink("");
button9.Sensitive = isanyphotodirty;
SetActivateComments(false);
}
private void ApplyConflictTagToLine(int startline, int endline) {
TextBuffer buf = textview4.Buffer;
TextIter start = buf.GetIterAtLine(startline);
TextIter end = buf.GetIterAtLine(endline);
buf.ApplyTag("conflict", start, end);
textview4.Buffer = buf;
}
private void HighlightDifferences(Photo serverphoto, Photo photo) {
if (!serverphoto.Title.Equals(photo.Title))
ApplyConflictTagToLine(0, 1);
if (!serverphoto.Description.Equals(photo.Description))
ApplyConflictTagToLine(1, 2);
if (!serverphoto.PrivacyInfo.Equals(photo.PrivacyInfo))
ApplyConflictTagToLine(2, 3);
if (!serverphoto.LicenseInfo.Equals(photo.LicenseInfo))
ApplyConflictTagToLine(3, 4);
if (!serverphoto.TagString.Equals(photo.TagString))
ApplyConflictTagToLine(4, 5);
}
private void ActivateRevertButton() {
if (!_isuploadmode) button9.Sensitive = true;
}
private void SetTitleTopRight(string title) {
if (title.Length > 30) {
title = title.Substring(0, 30) + "...";
}
label7.Markup = "<span weight='bold'>" + Utils.EscapeForPango(title)
+ "</span>";
}
private void PopulateComments(string photoid) {
_comments.Clear();
ListStore store = new Gtk.ListStore(typeof(string));
foreach (Comment comment in
PersistentInformation.GetInstance().GetCommentsForPhoto(photoid)) {
string username = comment.UserName;
string safecomment = Utils.EscapeForPango(comment.CommentHtml);
string text = String.Format(
"<span weight='bold'>{0}:</span> {1}",
username, safecomment);
store.AppendValues(text);
_comments.Add(comment);
}
treeview3.Model = store;
treeview3.ShowAll();
}
private void ShowInformationForCurrentPhoto() {
DeskFlickrUI.SelectedPhoto sel =
(DeskFlickrUI.SelectedPhoto) _selectedphotos[_curphotoindex];
Photo p = sel.photo;
entry1.Text = p.Title;
textview5.Buffer.Text = p.Description;
_ignorechangedevent = true;
{
combobox1.Active = GetIndexOfPrivacyBox(p);
combobox2.Active = GetIndexOfLicenseBox(p);
textview3.Buffer.Text = Utils.GetDelimitedString(p.Tags, " ");
}
_ignorechangedevent = false;
if (_isconflictmode) {
Photo serverphoto = DeskFlickrUI.GetInstance().GetServerPhoto(p.Id);
string text = String.Format(
"Title:\t\t{0}\n"
+ "Description:\t{1}\n"
+ "Visibility:\t\t{2}\n"
+ "License:\t\t{3}\n"
+ "Tags:\t\t{4}\n",
serverphoto.Title, serverphoto.Description,
serverphoto.PrivacyInfo, serverphoto.LicenseInfo,
serverphoto.TagString);
textview4.Buffer.Text = text;
HighlightDifferences(serverphoto, p);
}
if (_isblogmode) {
BlogEntry blogentry = ((DeskFlickrUI.BlogSelectedPhoto) sel).blogentry;
entry4.Text = blogentry.Title;
textview7.Buffer.Text = blogentry.Desc;
}
image3.Sensitive = true;
image3.Pixbuf = p.SmallImage;
label7.Sensitive = true;
SetTitleTopRight(p.Title);
SetPhotoLink(p.Id);
button9.Sensitive = !_isuploadmode && IsPhotoEdited(p);
PopulateComments(p.Id);
SetActivateComments(!_isuploadmode);
}
private void OnTagClicked(object o, ItemActivatedArgs args) {
TreePath childpath = _filter.ConvertPathToChildPath(args.Path);
string tag = (string) _tags[childpath.Indices[0]];
ArrayList tagschosen;
if (checkbutton1.Active || !checkbutton1.Sensitive) {
Photo p = ((DeskFlickrUI.SelectedPhoto) _selectedphotos[_curphotoindex]).photo;
p.AddTag(tag);
tagschosen = p.Tags;
} else {
foreach (DeskFlickrUI.SelectedPhoto sel in _selectedphotos) {
Photo p = sel.photo;
p.AddTag(tag);
}
tagschosen = ((DeskFlickrUI.SelectedPhoto) _selectedphotos[0]).photo.Tags;
foreach (DeskFlickrUI.SelectedPhoto sel in _selectedphotos) {
Photo p = sel.photo;
tagschosen = Utils.GetIntersection(tagschosen, p.Tags);
}
}
ActivateRevertButton();
_ignorechangedevent = true;
textview3.Buffer.Text = Utils.GetDelimitedString(tagschosen, " ");
_ignorechangedevent = false;
}
private void OnTagsChanged(object o, EventArgs args) {
ArrayList parsedtags = Utils.ParseTagsFromString(textview3.Buffer.Text);
if (parsedtags == null || _ignorechangedevent) {
return;
}
if (checkbutton1.Active || !checkbutton1.Sensitive) {
Photo p = ((DeskFlickrUI.SelectedPhoto) _selectedphotos[_curphotoindex]).photo;
p.Tags = parsedtags;
} else {
foreach (DeskFlickrUI.SelectedPhoto sel in _selectedphotos) {
Photo p = sel.photo;
p.Tags = parsedtags;
}
}
ActivateRevertButton();
}
private void OnTitleChanged(object o, EventArgs args) {
// if the entry is not being changed by the user, then
// don't do the updates.
if (!entry1.IsFocus) return;
if (checkbutton1.Active || !checkbutton1.Sensitive) {
// Per photo
Photo p = ((DeskFlickrUI.SelectedPhoto) _selectedphotos[_curphotoindex]).photo;
p.Title = entry1.Text;
} else {
// Group of photos
foreach (DeskFlickrUI.SelectedPhoto sel in _selectedphotos) {
Photo p = sel.photo;
p.Title = entry1.Text;
}
}
SetTitleTopRight(entry1.Text);
ActivateRevertButton();
}
private void OnDescChanged(object o, EventArgs args) {
if (!textview5.IsFocus) return;
if (checkbutton1.Active || !checkbutton1.Sensitive) {
// Per photo
Photo p = ((DeskFlickrUI.SelectedPhoto) _selectedphotos[_curphotoindex]).photo;
p.Description = textview5.Buffer.Text;
} else {
// Group of photos
foreach (DeskFlickrUI.SelectedPhoto sel in _selectedphotos) {
Photo p = sel.photo;
p.Description = textview5.Buffer.Text;
}
}
ActivateRevertButton();
}
private void OnPrivacyChanged(object o, EventArgs args) {
if (_ignorechangedevent) return;
if (checkbutton1.Active || !checkbutton1.Sensitive) {
Photo p = ((DeskFlickrUI.SelectedPhoto) _selectedphotos[_curphotoindex]).photo;
SetPhotoPrivacyFromBox(ref p, combobox1.Active);
} else {
for (int i=0; i < _selectedphotos.Count; i++) {
Photo p = ((DeskFlickrUI.SelectedPhoto) _selectedphotos[i]).photo;
SetPhotoPrivacyFromBox(ref p, combobox1.Active);
}
}
ActivateRevertButton();
}
private void OnLicenseChanged(object o, EventArgs args) {
if (_ignorechangedevent) return;
if (checkbutton1.Active || !checkbutton1.Sensitive) {
Photo p = ((DeskFlickrUI.SelectedPhoto) _selectedphotos[_curphotoindex]).photo;
SetPhotoLicenseFromBox(ref p, combobox2.Active);
} else {
for (int i=0; i < _selectedphotos.Count; i++) {
Photo p = ((DeskFlickrUI.SelectedPhoto) _selectedphotos[i]).photo;
SetPhotoLicenseFromBox(ref p, combobox2.Active);
}
}
ActivateRevertButton();
}
private void OnBlogTitleChanged(object o, EventArgs args) {
if (!entry4.IsFocus) return;
if (checkbutton1.Active || !checkbutton1.Sensitive) {
// Per photo
BlogEntry blogentry =
((DeskFlickrUI.BlogSelectedPhoto) _selectedphotos[_curphotoindex]).blogentry;
blogentry.Title = entry4.Text;
} else {
// Group of photos
foreach (DeskFlickrUI.BlogSelectedPhoto bsel in _selectedphotos) {
BlogEntry blogentry = bsel.blogentry;
blogentry.Title = entry4.Text;
}
}
}
private void OnBlogDescChanged(object o, EventArgs args) {
if (!textview7.IsFocus) return;
if (checkbutton1.Active || !checkbutton1.Sensitive) {
// Per photo
BlogEntry blogentry =
((DeskFlickrUI.BlogSelectedPhoto) _selectedphotos[_curphotoindex]).blogentry;
blogentry.Desc = textview7.Buffer.Text;
} else {
// Group of photos
foreach (DeskFlickrUI.BlogSelectedPhoto bsel in _selectedphotos) {
BlogEntry blogentry = bsel.blogentry;
blogentry.Desc = textview7.Buffer.Text;
}
}
}
private void OnRevertButtonClicked(object sender, EventArgs args) {
if (checkbutton1.Active || !checkbutton1.Sensitive) {
Photo p = ((DeskFlickrUI.SelectedPhoto) _selectedphotos[_curphotoindex]).photo;
Photo originalp = PersistentInformation.GetInstance().GetOriginalPhoto(p.Id);
if (originalp != null) p.CopyContent(originalp);
ShowInformationForCurrentPhoto();
}
else {
for (int i=0; i < _selectedphotos.Count; i++) {
Photo p = ((DeskFlickrUI.SelectedPhoto) _selectedphotos[i]).photo;
Photo originalp = PersistentInformation.GetInstance().GetOriginalPhoto(p.Id);
if (originalp != null) p.CopyContent(originalp);
}
EmbedCommonInformation();
}
button9.Sensitive = false;
}
private void OnPerPageCheckToggled(object o, EventArgs args) {
if (checkbutton1.Active) {
_curphotoindex = 0;
button3.Sensitive = false; // Previous button
button4.Sensitive = true; // Next button
ShowInformationForCurrentPhoto();
} else {
EmbedCommonInformation();
}
}
private void OnNextButtonClick(object o, EventArgs args) {
_curphotoindex += 1;
if (_curphotoindex == _selectedphotos.Count -1) {
button4.Sensitive = false;
}
if (_curphotoindex == 1) {
button3.Sensitive = true;
}
ShowInformationForCurrentPhoto();
}
private void OnPrevButtonClick(object o, EventArgs args) {
_curphotoindex -= 1;
if (_curphotoindex == 0) {
button3.Sensitive = false;
}
if (_curphotoindex == _selectedphotos.Count - 2) {
button4.Sensitive = true;
}
ShowInformationForCurrentPhoto();
}
private void OnCancelButtonClick(object o, EventArgs args) {
window2.Destroy();
}
private void OnSaveButtonClick(object o, EventArgs args) {
foreach (DeskFlickrUI.SelectedPhoto sel in _selectedphotos) {
Photo p = sel.photo;
if (_isuploadmode) {
PersistentInformation.GetInstance().UpdateInfoForUploadPhoto(p);
}
else {
if (_isconflictmode) {
Photo serverphoto = DeskFlickrUI.GetInstance().GetServerPhoto(p.Id);
p.LastUpdate = serverphoto.LastUpdate;
DeskFlickrUI.GetInstance().RemoveServerPhoto(p.Id);
}
if (_isblogmode) {
BlogEntry blogentry = ((DeskFlickrUI.BlogSelectedPhoto) sel).blogentry;
PersistentInformation.GetInstance().UpdateEntryToBlog(blogentry);
}
// This original photo is the photo sent to the editor initially.
// Note that this photo is different from the photos stored in
// originalphoto table, which are the ones originally retrieved from
// the server.
Photo originalp = _originalphotos[p.Id];
bool ischanged = false;
if (!p.isMetaDataEqual(originalp)) {
ischanged = true;
PersistentInformation.GetInstance().UpdateMetaInfoPhoto(p);
}
if (!p.isTagsEqual(originalp)) {
ischanged = true;
p.SortTags();
PersistentInformation.GetInstance().UpdateTagsForPhoto(p);
}
// Get the originally retrieved photo from server.
Photo originalcleanphoto = PersistentInformation.GetInstance().GetOriginalPhoto(p.Id);
if (originalcleanphoto == null || p.isEqual(originalcleanphoto)) {
PersistentInformation.GetInstance().SetPhotoDirty(p.Id, false);
}
else if (ischanged) {
PersistentInformation.GetInstance().SetPhotoDirty(p.Id, true);
} else {
Console.Error.WriteLine(
"Inconsistent State: Photo seems to be different than stored"
+ " in server, but the metadata and tags are unchanged.");
Console.Out.WriteLine("=== Local photo ===");
Console.Out.WriteLine(p.PrettyPrint());
Console.Out.WriteLine("=== Server Photo ===");
Console.Out.WriteLine(originalcleanphoto.PrettyPrint());
}
}
}
window2.Destroy();
DeskFlickrUI.GetInstance().UpdateToolBarButtons();
if (_isconflictmode) DeskFlickrUI.GetInstance().OnConflictButtonClicked(null, null);
else DeskFlickrUI.GetInstance().UpdatePhotos(_selectedphotos);
}
}