/
Window.boo
174 lines (144 loc) · 5 KB
/
Window.boo
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
/* This file is a part of Flickroff
*
* Copyright (C) 2008:
*
* Authors:
* Michael Dominic K. <mdk@mdk.am>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
namespace Flickroff
import System
import Gtk
class Window (Gtk.Window):
_table as Table
_progressBar as ProgressBar
_directoryCaption as Label
_directoryChooser as DirectoryChooserButton
_syncButton as Button
_abortButton as Button
_buttonBox as HBox
_photoCountLabel as Label
_thumbnailArea as ThumbnailArea
def constructor ():
super ("Flickroff")
BorderWidth = 12
DeleteEvent += OnDeleteEvent
mainHBox = HBox (false, 12)
rightVBox = VBox (false, 6)
leftVBox = VBox (false, 6)
vbox = VBox (false, 6)
_thumbnailArea = ThumbnailArea ()
leftVBox.PackStart (_thumbnailArea, false, false, 0)
syncTimeCaption = Label ("Last synchronization:")
syncTimeLabel = Label ("Never")
_directoryCaption = Label ("Photos location:")
_directoryChooser = DirectoryChooserButton ()
photoCountCaption = Label ("Photo count:")
_photoCountLabel = Label ("123")
syncTimeCaption.Xalign = 1.0
syncTimeLabel.Xalign = 0.0
_directoryCaption.Xalign = 1.0
photoCountCaption.Xalign = 1.0
_photoCountLabel.Xalign = 0.0
_progressBar = SyncProgressBar ()
_table = Table (2, 3, false)
_table.ColumnSpacing = 6
_table.RowSpacing = 6
_table.Attach (syncTimeCaption, 0, 1, 0, 1)
_table.Attach (syncTimeLabel, 1, 2, 0, 1)
_table.Attach (photoCountCaption, 0, 1, 1, 2)
_table.Attach (_photoCountLabel, 1, 2, 1, 2)
_table.Attach (_directoryCaption, 0, 1, 2, 3)
_table.Attach (_directoryChooser, 1, 2, 2, 3)
_syncButton = Button ("Synchronize")
_syncButton.Clicked += OnSynchronizeClicked
_abortButton = Button ("Abort")
_abortButton.Clicked += OnAbortClicked
_buttonBox = HBox (false, 6)
_buttonBox.PackStart (_progressBar, true, true, 0)
_buttonBox.PackEnd (_syncButton, false, false, 0)
rightVBox.Add (_table)
mainHBox.PackStart (leftVBox, false, false, 0)
mainHBox.PackEnd (rightVBox, true, true, 0)
vbox.PackStart (mainHBox, false, false, 6)
vbox.PackEnd (_buttonBox, false, false, 0)
vbox.Spacing = 12
vbox.ShowAll ()
_progressBar.HideAll ()
UpdatePhotoCount ()
Add (vbox)
SyncEngine.Error += OnSyncError
SyncEngine.Finished += OnSyncFinished
private def UpdatePhotoCount ():
_photoCountLabel.Text = Database.GetPhotoCount ().ToString ()
private def OnDeleteEvent ():
Application.Quit ()
private def OnSynchronizeClicked ():
ShowProgressBar ()
_directoryChooser.Sensitive = false
copyPhotos = false
resetDb = false
if Config.PhotosDirectory != Config.PreviousPhotosDirectory and Database.GetPhotoCount () > 0:
moveQuestionDialog = CopyQuestionDialog (self)
response = moveQuestionDialog.Run ()
moveQuestionDialog.Destroy ()
if response == ResponseType.Yes:
copyPhotos = true
else:
resetDb = true
if not FlickrStore.HasToken:
authorizeDialog = AuthorizeDialog (self)
response = authorizeDialog.Run ()
authorizeDialog.Destroy ()
return if response != ResponseType.Ok
# FIXME Temporary
FlickrStore.GetTokenForFrob (authorizeDialog.Frob)
SyncEngine.StartSync (copyPhotos, resetDb)
private def OnAbortClicked ():
_abortButton.Sensitive = false;
SyncEngine.Abort ()
private def ShowProgressBar ():
_progressBar.Show ()
width = _syncButton.Requisition.Width
_buttonBox.Remove (_syncButton)
_buttonBox.PackEnd (_abortButton, false, false, 0)
_abortButton.WidthRequest = width
_abortButton.Show ()
private def HideProgressBar ():
_progressBar.Hide ()
_buttonBox.Remove (_abortButton)
_buttonBox.PackEnd (_syncButton, false, false, 0)
_syncButton.Show ()
private def OnSyncFinished ():
try:
Gdk.Threads.Enter ()
_syncButton.Sensitive = true;
_abortButton.Sensitive = true;
_directoryChooser.Sensitive = true;
HideProgressBar ();
_thumbnailArea.ResetToLogo ()
ensure:
Gdk.Threads.Leave ()
private def OnSyncError (o, e as Exception):
print e
try:
Gdk.Threads.Enter ()
dialog = SyncErrorDialog (self, e)
dialog.ShowAll ()
dialog.Run ()
dialog.Destroy ()
ensure:
Gdk.Threads.Leave ()