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
|
# File 'lib/grumblr/ui.rb', line 47
def initialize
super false, 4
@statusbar = Gtk::Statusbar.new
@notebook = Gtk::Notebook.new
@notebook.set_homogeneous true
@notebook.set_tab_pos Gtk::POS_LEFT
@text_title = Gtk::Entry.new
@format = Gtk::CheckButton.new '_markdown'
@format.set_active $cfg.get(:format_markdown)
@format.signal_connect(:toggled) do |widget|
$cfg.set :format_markdown, widget.active?
end
label = Gtk::Label.new 'Body'
box = Gtk::HBox.new false, 8
box.pack_start label, false
box.pack_start @format, false
page = Gtk::VBox.new false, 4
page.set_border_width 8
page.pack_with_label 'Title (optional)', @text_title
page.pack_start box, false
page.pack_start multiline_entry(:text_body), true
@notebook.add_page_with_tab page, 'Text'
@link_url = Gtk::Entry.new
@link_name = Gtk::Entry.new
link_description = multiline_entry :link_description
page = Gtk::VBox.new false, 4
page.set_border_width 8
page.pack_with_label 'URL', @link_url
page.pack_with_label 'Name (optional)', @link_name
page.pack_with_label'Description (optional)', link_description, true
@notebook.add_page_with_tab page, 'Link'
@chat_title = Gtk::Entry.new
chat_conversation = multiline_entry :chat_conversation
page = Gtk::VBox.new false, 4
page.set_border_width 8
page.pack_with_label 'Title (optional)', @chat_title
page.pack_with_label 'Conversation', chat_conversation, true
@notebook.add_page_with_tab page, 'Chat'
@quote_source = Gtk::Entry.new
quote_quote = multiline_entry :quote_quote
page = Gtk::VBox.new false, 4
page.set_border_width 8
page.pack_with_label 'Quote', quote_quote, true
page.pack_with_label 'Source (optional)', @quote_source
@notebook.add_page_with_tab page, 'Quote'
filter = Gtk::FileFilter.new
filter.set_name "Images"
filter.add_mime_type "image/*"
@photo_source = Gtk::Entry.new
@photo_click_through_url = Gtk::Entry.new
photo_data = file_chooser_button :photo_data, filter
photo_caption = multiline_entry :photo_caption
page = Gtk::VBox.new false, 4
page.set_border_width 8
page.pack_with_label 'File', photo_data
page.pack_with_label 'Source', @photo_source
page.pack_with_label 'Caption', photo_caption, true
page.pack_with_label 'Link (optional)', @photo_click_through_url
@notebook.add_page_with_tab page, 'Photo'
if $api.user.can_upload_audio == '1'
filter = Gtk::FileFilter.new
filter.set_name "Audio"
filter.add_mime_type "audio/*"
audio_data = file_chooser_button :audio_data, filter
audio_caption = multiline_entry :audio_caption
page = Gtk::VBox.new false, 4
page.set_border_width 8
page.pack_with_label 'File', audio_data
page.pack_with_label 'Caption (optional)', audio_caption, true
@notebook.add_page_with_tab page, 'Audio'
end
@video_embed = Gtk::Entry.new
video_caption = multiline_entry :video_caption
page = Gtk::VBox.new false, 4
page.set_border_width 8
if $api.user.can_upload_video == '1'
filter = Gtk::FileFilter.new
filter.set_name "Video"
filter.add_mime_type "video/*"
video_data = file_chooser_button :video_data, filter
@video_title = Gtk::Entry.new
page.pack_with_label 'File', video_data
page.pack_with_label 'Title (optional)', @video_title
end
page.pack_with_label 'Embed code / YouTube link', @video_embed
page.pack_with_label 'Caption (optional)', video_caption, true
@notebook.add_page_with_tab page, 'Video'
toolbar = Gtk::Toolbar.new
toolbar.icon_size = Gtk::IconSize::MENU
icon = Gtk::Image.new Gtk::Stock::HOME, Gtk::IconSize::MENU
item = Gtk::ToolButton.new icon, 'Tumblelog'
item.signal_connect(:clicked) do
Thread.new { system('xdg-open "%s"' % $app.blog.url) }
end
toolbar.insert 0, item
icon = Gtk::Image.new Gtk::Stock::PREFERENCES, Gtk::IconSize::MENU
item = Gtk::ToolButton.new icon, 'Dashboard'
item.signal_connect(:clicked) do
Thread.new { system('xdg-open "http://www.tumblr.com/tumblelog/%s"' % $app.blog.name) }
end
toolbar.insert 1, item
combo = Gtk::ComboBox.new
active_blog = $cfg.get(:active_blog) || nil
active_blog_idx = nil
$api.blogs.each_with_index do |blog, idx|
combo.append_text blog.title
active_blog_idx = idx if blog.name.eql?(active_blog)
active_blog_idx = idx if active_blog_idx.nil? and blog.is_primary == "yes"
end
combo.signal_connect(:changed) do |widget|
$app.blog = $api.blogs[widget.active]
$cfg.set :active_blog, $app.blog.name
@statusbar.push 0, $app.blog.title
end
combo.set_active(active_blog_idx)
item = Gtk::ToolItem.new
item.set_expand true
item.add combo
toolbar.insert 2, item
icon = Gtk::Image.new Gtk::Stock::QUIT, Gtk::IconSize::MENU
item = Gtk::ToolButton.new icon, 'Quit'
item.set_homogeneous false
item.signal_connect(:clicked) do
$app.quit
end
toolbar.insert 3, item
clear_button = Gtk::Button.new 'Clear'
clear_button.set_focus_on_click false
clear_button.signal_connect(:clicked) do |widget|
page = @notebook.get_nth_page @notebook.page
message_type = @notebook. page
reset_form message_type.downcase
end
@private_button = Gtk::ToggleButton.new 'Private'
@private_button.signal_connect(:toggled) do |widget|
$cfg.set :private, widget.active?
end
@private_button.set_active $cfg.get(:private)
submit_button = Gtk::Button.new 'Send'
submit_button.signal_connect(:released) do |widget|
post
end
button_box = Gtk::HBox.new false, 4
button_box.pack_start clear_button, false
button_box.pack_start @private_button, false
button_box.pack_start submit_button
pack_start toolbar, false
pack_start @notebook
pack_start button_box, false
pack_start @statusbar, false
show_all
end
|