gloudapp 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in gloudapp.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,42 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gloudapp (1.0)
5
+ cloudapp_api
6
+ gtk2
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ atk (1.0.0)
12
+ glib2 (>= 1.0.0)
13
+ cairo (1.10.0)
14
+ pkg-config
15
+ cloudapp_api (0.3.1)
16
+ httparty (>= 0.6.0)
17
+ httparty (>= 0.6.0)
18
+ mime-types
19
+ gdk_pixbuf2 (1.0.0)
20
+ glib2 (>= 1.0.0)
21
+ glib2 (1.0.0)
22
+ pkg-config
23
+ gtk2 (1.0.0)
24
+ atk (>= 1.0.0)
25
+ gdk_pixbuf2 (>= 1.0.0)
26
+ pango (>= 1.0.0)
27
+ httparty (0.8.0)
28
+ multi_json
29
+ multi_xml
30
+ mime-types (1.16)
31
+ multi_json (1.0.3)
32
+ multi_xml (0.4.0)
33
+ pango (1.0.0)
34
+ cairo (>= 1.10.0)
35
+ glib2 (>= 1.0.0)
36
+ pkg-config (1.1.2)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ gloudapp!
data/LICENSE ADDED
@@ -0,0 +1,187 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ GloudApp
2
+ ========
3
+
4
+ GloudApp is a [CloudApp](http://getcloudapp.com/) client for Linux and
5
+ [GNOME2](http://www.gnome.org/) based on GTK using the
6
+ [Ruby-GNOME2](http://ruby-gnome2.sourceforge.jp/) bindings.
7
+
8
+ It hat equivalent features as the official OSX client allowing you
9
+ to take and upload screenshots with only a single click and other
10
+ files through a file chooser dialog.
11
+
12
+ Install
13
+ -------
14
+
15
+ Header files needed to build native gem extensions for gtk2 gem and dependencies
16
+ (distribution specific package names; here: Ubuntu 11.04):
17
+
18
+ - libgdk-pixbuf2.0-dev
19
+ - libglib2.0-dev
20
+ - libatk1.0-dev
21
+ - libgtk2.0-dev
22
+ - libpango1.0-dev
23
+
24
+ Then install the gloudapp gem:
25
+
26
+ sudo gem install gloudapp
27
+
28
+ (If you use [rvm](http://beginrescueend.com/) you should omit the 'sudo'.)
29
+
30
+ Usage
31
+ -----
32
+
33
+ You could launch gloudapp (or place it in auto-start) via:
34
+
35
+ gloudapp
36
+
37
+ Then you will be prompted to provide your credentials (or not if you're already
38
+ using [cloudapp-cli](https://github.com/cmur2/cloudapp-cli) on the same machine).
39
+ A successful login gives you a new small but fine icon right in your notification bar
40
+ which is sensitive for left clicking (take screenshot and upload) and right clicking
41
+ (offering a popup menu with all other commands). After an upload the new URL will
42
+ appear immediately be copied into the clipboard for easily pasting it somewhere.
43
+ Have fun!
44
+
45
+ Thanks
46
+ ------
47
+
48
+ To [Jan Graichen](https://github.com/jgraichen) for all kinds of help especially his nice art work!
49
+
50
+ License
51
+ -------
52
+
53
+ GloudApp is licensed under the Apache License, Version 2.0. See LICENSE for more information.
54
+
55
+ Links
56
+ -----
57
+
58
+ - [no screenshots from Ruby :(](http://tips.webdesign10.com/how-to-take-a-screenshot-on-ubuntu-linux)
59
+ - [Ruby-GNOME2](http://ruby-gnome2.sourceforge.jp/)
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/gloudapp ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require 'gloudapp'
5
+
6
+ GloudApp::App.new.run!
data/gloudapp.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ require "gloudapp/info"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "gloudapp"
8
+ s.version = GloudApp::Info::VERSION
9
+ s.authors = GloudApp::Info::AUTHORS.map { |author| author[0] }
10
+ s.email = GloudApp::Info::AUTHORS.map { |author| author[1] }
11
+ s.homepage = GloudApp::Info::HOMEPAGE
12
+ s.summary = GloudApp::Info::SUMMARY
13
+ #s.description = %q{CloudApp client for GNOME/GTK}
14
+
15
+ s.rubyforge_project = "gloudapp"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ # specify any dependencies here; for example:
23
+ # s.add_development_dependency "rspec"
24
+ s.add_runtime_dependency "cloudapp_api"
25
+ s.add_runtime_dependency "gtk2"
26
+ s.add_runtime_dependency "json"
27
+ end
Binary file
@@ -0,0 +1,16 @@
1
+ module GloudApp
2
+ module Info
3
+ VERSION = "1.1.1"
4
+ AUTHORS = [
5
+ ["Christian Nicolai", "chrnicolai@gmail.com"],
6
+ ["Jan Graichen", "jan.graichen@altimos.de"]
7
+ ]
8
+ ARTISTS = [
9
+ ["Jan Graichen", "jan.graichen@altimos.de"]
10
+ ]
11
+ HOMEPAGE = "https://github.com/cmur2/gloudapp"
12
+ SUMMARY = "CloudApp client for GNOME/GTK"
13
+ COPYRIGHT = "Copyright 2011 GloudApp Team"
14
+ LICENSE = "Apache License, Version 2.0"
15
+ end
16
+ end
@@ -0,0 +1,31 @@
1
+
2
+ # patches for cloudapp_api
3
+ module CloudApp
4
+ class Account
5
+ attr_reader :subscription_expires_at
6
+ end
7
+
8
+ class Drop
9
+ def slug
10
+ url.split(/\//).last
11
+ end
12
+
13
+ def self.find(id)
14
+ res = get "http://#{$domain}/#{id}"
15
+ res.ok? ? Drop.new(res) : bad_response(res)
16
+ end
17
+
18
+ attr_reader :source
19
+ end
20
+
21
+ class Multipart
22
+ def payload
23
+ {
24
+ :headers => {
25
+ "User-Agent" => "Ruby.CloudApp.API",
26
+ "Content-Type" => "multipart/form-data; boundary=#{boundary}"},
27
+ :body => @body
28
+ }
29
+ end
30
+ end
31
+ end
data/lib/gloudapp.rb ADDED
@@ -0,0 +1,386 @@
1
+
2
+ require 'gtk2'
3
+ require 'cloudapp_api'
4
+
5
+ require 'gloudapp/info'
6
+ require 'gloudapp/patches'
7
+
8
+ module GloudApp
9
+ SCRN_TIME_FMT = '%d%m%y-%H%M%S'
10
+ TMP_DIR = "/tmp"
11
+
12
+ class App
13
+ def initialize
14
+ @client = CloudApp::Client.new
15
+
16
+ @credentials = load_credentials
17
+ @client.authenticate(@credentials[:username], @credentials[:password])
18
+
19
+ if not credentials_valid?
20
+ @credentials = request_credentials
21
+ @client.authenticate(@credentials[:username], @credentials[:password])
22
+ end
23
+
24
+ if not credentials_valid?
25
+ ErrorDialog.run!("Error", "Authentication failed!")
26
+ end
27
+
28
+ create_tray
29
+ end
30
+
31
+ def run!
32
+ @tray.run!
33
+ Gtk.main
34
+ end
35
+
36
+ def credentials_valid?
37
+ # check whether auth was successful
38
+ @acc = CloudApp::Account.find
39
+ $domain = @acc.domain.nil? ? 'cl.ly' : @acc.domain
40
+ return true
41
+ rescue
42
+ return false
43
+ end
44
+
45
+ def load_credentials
46
+ if ARGV.length == 2
47
+ # assume that's username and password in ARGV
48
+ return {:username => ARGV[0], :password => ARGV[1]}
49
+ end
50
+
51
+ @config_file = File.join(ENV['HOME'], '.cloudapp-cli')
52
+ if File.exists?(@config_file)
53
+ creds = YAML.load_file(@config_file)
54
+ return creds unless creds[:username].nil? or creds[:password].nil?
55
+ end
56
+
57
+ request_credentails
58
+ end
59
+
60
+ def request_credentials
61
+ login_dlg = LoginDialog.new
62
+ case login_dlg.run
63
+ when Gtk::Dialog::RESPONSE_ACCEPT
64
+ creds = {:username => login_dlg.login.text, :password => login_dlg.password.text}
65
+ login_dlg.destroy
66
+ return creds
67
+ when Gtk::Dialog::RESPONSE_REJECT
68
+ login_dlg.destroy
69
+ return nil
70
+ end
71
+ end
72
+
73
+ def create_tray
74
+ @tray = Tray.new :default => Proc.new { take_screenshot }
75
+
76
+ @tray.add_action "Copy last drop url",
77
+ :show => Proc.new { |item| check_last_drop(item) },
78
+ :action => Proc.new { copy_last_drop_url },
79
+ :no_icon_change => true
80
+
81
+ @tray.add_separator
82
+
83
+ # take and upload screenshot
84
+ @tray.add_action("Take screenshot") { take_screenshot }
85
+
86
+ # upload file from path in clipboard
87
+ @tray.add_action "Upload from clipboard",
88
+ :show => Proc.new { |item| check_clipboard(item) },
89
+ :action => Proc.new { upload_from_clipboard }
90
+
91
+ # upload file via file chooser
92
+ @tray.add_action("Upload file") { upload_via_chooser }
93
+
94
+ # show about dialog
95
+ @tray.add_action("About", :no_icon_change => true) { GloudApp::AboutDialog.run! }
96
+
97
+ @tray.add_separator
98
+
99
+ # quit app
100
+ @tray.add_action("Quit", :no_icon_change => true) { Gtk.main_quit }
101
+ end
102
+
103
+ def check_clipboard(item)
104
+ with_clipboard_text do |text|
105
+ if !text.nil? and File.file?(text)
106
+ item.set_sensitive(true)
107
+ item.label = "Upload: #{text}"
108
+ else
109
+ item.set_sensitive(false)
110
+ item.label = "Upload from clipboard"
111
+ end
112
+ end
113
+ end
114
+
115
+ def upload_from_clipboard
116
+ # current cliboard context might not be the same as shown
117
+ # on popup menu creation...
118
+ with_clipboard_text do |text|
119
+ if !text.nil?
120
+ puts "Uploading file from clipboard..."
121
+ upload_file(text)
122
+ end
123
+ end
124
+ end
125
+
126
+ def check_last_drop(item)
127
+ if @last_drop.nil?
128
+ item.set_sensitive(false)
129
+ item.label = "Copy last drop url"
130
+ else
131
+ item.set_sensitive(true)
132
+ item.label = "Copy #{@last_drop.url}"
133
+ end
134
+ end
135
+
136
+ def copy_last_drop_url
137
+ self.clipboard_text = @last_drop.url unless @last_drop.nil?
138
+ end
139
+
140
+ def with_clipboard_text
141
+ Gtk::Clipboard.get(Gdk::Selection::CLIPBOARD).request_text do |clipboard, text|
142
+ yield text
143
+ end
144
+ end
145
+
146
+ def clipboard_text=(text)
147
+ Gtk::Clipboard.get(Gdk::Selection::CLIPBOARD).text = text
148
+ end
149
+
150
+ def upload_via_chooser
151
+ file_dlg = Gtk::FileChooserDialog.new(
152
+ "Upload File",
153
+ nil,
154
+ Gtk::FileChooser::ACTION_OPEN,
155
+ nil,
156
+ [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL],
157
+ ["Upload", Gtk::Dialog::RESPONSE_ACCEPT])
158
+
159
+ if file_dlg.run == Gtk::Dialog::RESPONSE_ACCEPT
160
+ file = GLib.filename_to_utf8(file_dlg.filename)
161
+ file_dlg.destroy
162
+
163
+ # timeout to close file chooser before blocking gtk thread
164
+ Gtk.timeout_add 50 do
165
+ if upload_file(file)
166
+ @tray.icon = Icon.finish
167
+ end
168
+ false
169
+ end
170
+ false
171
+ else
172
+ file_dlg.destroy
173
+ @tray.icon = Icon.normal
174
+ false
175
+ end
176
+ end
177
+
178
+ def upload_file(file)
179
+ if File.file?(file)
180
+ puts "Uploading #{file}"
181
+ drop = @client.upload(file)
182
+ puts "URL (in clipboard, too): #{drop.url}"
183
+ # copy URL to clipboard
184
+ self.clipboard_text = drop.url
185
+ @last_drop = drop
186
+ drop.url
187
+ else
188
+ error "Error uploading file #{file}. Does not exists or is not a file."
189
+ end
190
+ end
191
+
192
+ def take_screenshot
193
+ file = File.join(TMP_DIR, "Screenshot #{Time.now.strftime(SCRN_TIME_FMT)}.png")
194
+ puts "Taking screenshot..."
195
+ # TODO: find rubish way to take screen shots
196
+ # make screenshot via image magick:
197
+ system("import -window root \"#{file}\"")
198
+ if File.file?(file)
199
+ upload_file(file)
200
+ else
201
+ error "Error taking screenshot - did you install imagemagick?"
202
+ end
203
+ end
204
+
205
+ def error(message)
206
+ options = {:message => message} unless message.is_a?(Hash)
207
+ options = {:title => 'Error'}.merge(options)
208
+
209
+ @tray.icon = Icon.error
210
+ @tray.message = options[:message]
211
+ ErrorDialog.run!(options[:title], options[:message])
212
+ false
213
+ end
214
+ end
215
+
216
+ class Icon
217
+ def self.icon(icon) File.join(File.dirname(__FILE__), 'gloudapp', 'icons', icon + '.png') end
218
+ def self.normal_path; self.icon 'gloudapp' end
219
+ def self.finish_path; self.icon 'gloudapp_finish' end
220
+ def self.working_path; self.icon 'gloudapp_working' end
221
+ def self.error_path; self.icon 'gloudapp_error' end
222
+ def self.normal; Gdk::Pixbuf.new(normal_path) end
223
+ def self.finish; Gdk::Pixbuf.new(finish_path) end
224
+ def self.working; Gdk::Pixbuf.new(working_path) end
225
+ def self.error; Gdk::Pixbuf.new(error_path) end
226
+ end
227
+
228
+ class Tray
229
+ def initialize(options = {}, &default)
230
+ @options = {:tooltip => 'GloudApp', :icon => GloudApp::Icon.normal_path}.merge(options)
231
+ @options[:default] = default unless @options[:default].is_a?(Proc)
232
+ end
233
+
234
+ def add_action(title, options = {}, &proc)
235
+ @actions ||= []
236
+ options = {} unless options.is_a?(Hash)
237
+ options[:action] = proc unless options[:action].is_a?(Proc)
238
+ options[:title] = title unless options[:title].is_a?(String)
239
+ @actions << options
240
+ end
241
+
242
+ def add_separator()
243
+ @actions ||= []
244
+ @actions << {:separator => true}
245
+ end
246
+
247
+ def run!
248
+ @si = Gtk::StatusIcon.new
249
+ @si.pixbuf = Gdk::Pixbuf.new(@options[:icon])
250
+ @si.tooltip = @options[:tooltip]
251
+ @si.signal_connect('activate') do
252
+ run_action @options[:default]
253
+ end
254
+
255
+ create_menu
256
+ @si.signal_connect('popup-menu') do |tray, button, time|
257
+ if not @working
258
+ @actions.each do |action|
259
+ if action[:show].is_a?(Proc)
260
+ action[:show].call(action[:item])
261
+ end
262
+ end
263
+ self.icon = Icon.normal
264
+ self.message = nil
265
+ @menu.popup(nil, nil, button, time)
266
+ end
267
+ end
268
+ end
269
+
270
+ def icon=(icon)
271
+ @si.pixbuf = icon.is_a?(Gdk::Pixbuf) ? icon : Gdk::Pixbuf.new(icon)
272
+ end
273
+
274
+ def message=(message)
275
+ @si.tooltip = message.nil? ? @options[:tooltip] : message.to_s
276
+ end
277
+
278
+ private
279
+ def run_action(proc, no_icon_change = false)
280
+ if proc.is_a?(Proc)
281
+ self.icon = Icon.working unless no_icon_change
282
+
283
+ # timeout action to get at least on repaint event after
284
+ # changing icon to working image
285
+ Gtk.timeout_add 50 do
286
+ if proc.call
287
+ self.icon = Icon.finish unless no_icon_change
288
+ end
289
+ false
290
+ end
291
+ end
292
+ end
293
+
294
+ def create_menu
295
+ @menu = Gtk::Menu.new
296
+ @actions.each do |action|
297
+ if action[:separator]
298
+ @menu.append Gtk::SeparatorMenuItem.new
299
+ next
300
+ end
301
+
302
+ item = Gtk::MenuItem.new(action[:title].to_s)
303
+ action[:item] = item
304
+ item.signal_connect('activate') do
305
+ run_action action[:action], !!action[:no_icon_change]
306
+ end
307
+ @menu.append item
308
+ end
309
+ @menu.show_all
310
+ end
311
+ end
312
+
313
+ class ErrorDialog < Gtk::MessageDialog
314
+ def initialize(title, message)
315
+ super(nil,
316
+ Gtk::Dialog::MODAL,
317
+ Gtk::MessageDialog::ERROR,
318
+ Gtk::MessageDialog::BUTTONS_CLOSE,
319
+ message)
320
+ self.icon = GloudApp::Icon.normal
321
+ self.title = title
322
+ end
323
+
324
+ def self.run!(title, message)
325
+ instance = self.new(title, message)
326
+ instance.run
327
+ instance.destroy
328
+ end
329
+ end
330
+
331
+ class AboutDialog < Gtk::AboutDialog
332
+ def initialize
333
+ super
334
+ self.icon = GloudApp::Icon.normal
335
+ self.name = "GloudApp"
336
+ self.program_name = "GloudApp"
337
+ self.version = GloudApp::Info::VERSION
338
+ self.copyright = GloudApp::Info::COPYRIGHT
339
+ self.license = GloudApp::Info::LICENSE
340
+ self.artists = GloudApp::Info::ARTISTS.map { |author| "#{author[0]} <#{author[1]}>" }
341
+ self.authors = GloudApp::Info::AUTHORS.map { |author| "#{author[0]} <#{author[1]}>" }
342
+ self.website = GloudApp::Info::HOMEPAGE
343
+ self.logo = GloudApp::Icon.normal
344
+ end
345
+
346
+ def self.run!
347
+ instance = self.new
348
+ instance.run
349
+ instance.destroy
350
+ end
351
+ end
352
+
353
+ class LoginDialog < Gtk::Dialog
354
+ attr_reader :login, :password
355
+
356
+ def initialize
357
+ super("Authentication",
358
+ nil,
359
+ Gtk::Dialog::MODAL,
360
+ ["Login", Gtk::Dialog::RESPONSE_ACCEPT],
361
+ [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_REJECT])
362
+ self.icon = GloudApp::Icon.normal
363
+ self.has_separator = false
364
+
365
+ @login = Gtk::Entry.new
366
+ @password = Gtk::Entry.new.set_visibility(false)
367
+ image = Gtk::Image.new(Gtk::Stock::DIALOG_AUTHENTICATION, Gtk::IconSize::DIALOG)
368
+
369
+ table = Gtk::Table.new(2, 3).set_border_width(5)
370
+ table.attach(image, 0, 1, 0, 2, nil, nil, 10, 10)
371
+ table.attach_defaults(Gtk::Label.new("Username:").set_xalign(1).set_xpad(5), 1, 2, 0, 1)
372
+ table.attach_defaults(@login, 2, 3, 0, 1)
373
+ table.attach_defaults(Gtk::Label.new("Password:").set_xalign(1).set_xpad(5), 1, 2, 1, 2)
374
+ table.attach_defaults(@password, 2, 3, 1, 2)
375
+
376
+ self.vbox.add(table)
377
+ self.show_all
378
+ # close dialog on return or enter
379
+ self.signal_connect("key_release_event") do |obj, ev|
380
+ if ev.keyval == Gdk::Keyval::GDK_Return or ev.keyval == Gdk::Keyval::GDK_KP_Enter
381
+ obj.response(Gtk::Dialog::RESPONSE_ACCEPT)
382
+ end
383
+ end
384
+ end
385
+ end
386
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gloudapp
3
+ version: !ruby/object:Gem::Version
4
+ hash: 17
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 1
9
+ - 1
10
+ version: 1.1.1
11
+ platform: ruby
12
+ authors:
13
+ - Christian Nicolai
14
+ - Jan Graichen
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-09-16 00:00:00 Z
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: cloudapp_api
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: gtk2
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: json
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :runtime
62
+ version_requirements: *id003
63
+ description:
64
+ email:
65
+ - chrnicolai@gmail.com
66
+ - jan.graichen@altimos.de
67
+ executables:
68
+ - gloudapp
69
+ extensions: []
70
+
71
+ extra_rdoc_files: []
72
+
73
+ files:
74
+ - Gemfile
75
+ - Gemfile.lock
76
+ - LICENSE
77
+ - README.md
78
+ - Rakefile
79
+ - bin/gloudapp
80
+ - gloudapp.gemspec
81
+ - lib/gloudapp.rb
82
+ - lib/gloudapp/icons/gloudapp.png
83
+ - lib/gloudapp/icons/gloudapp_error.png
84
+ - lib/gloudapp/icons/gloudapp_finish.png
85
+ - lib/gloudapp/icons/gloudapp_working.png
86
+ - lib/gloudapp/info.rb
87
+ - lib/gloudapp/patches.rb
88
+ homepage: https://github.com/cmur2/gloudapp
89
+ licenses: []
90
+
91
+ post_install_message:
92
+ rdoc_options: []
93
+
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ hash: 3
102
+ segments:
103
+ - 0
104
+ version: "0"
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ hash: 3
111
+ segments:
112
+ - 0
113
+ version: "0"
114
+ requirements: []
115
+
116
+ rubyforge_project: gloudapp
117
+ rubygems_version: 1.8.6
118
+ signing_key:
119
+ specification_version: 3
120
+ summary: CloudApp client for GNOME/GTK
121
+ test_files: []
122
+