XDCC-Fetch 1.386

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/COPYING +23 -0
  2. data/XDCC-Fetch.rbw +54 -0
  3. data/doc/ark.png +0 -0
  4. data/doc/connect_established.png +0 -0
  5. data/doc/index.html +300 -0
  6. data/doc/mega_ark.png +0 -0
  7. data/doc/package.png +0 -0
  8. data/doc/package_unknown.png +0 -0
  9. data/doc/shot1.png +0 -0
  10. data/doc/shot1_mini.png +0 -0
  11. data/doc/shot2.png +0 -0
  12. data/doc/shot2_mini.png +0 -0
  13. data/doc/xdccfetch.css +155 -0
  14. data/icons/ark.png +0 -0
  15. data/icons/ark_big.png +0 -0
  16. data/icons/camera_test.png +0 -0
  17. data/icons/cancel.png +0 -0
  18. data/icons/connect_creating.png +0 -0
  19. data/icons/connect_established.png +0 -0
  20. data/icons/connect_failed.png +0 -0
  21. data/icons/connect_no.png +0 -0
  22. data/icons/edit_add.png +0 -0
  23. data/icons/edit_remove.png +0 -0
  24. data/icons/exit.png +0 -0
  25. data/icons/fileclose.png +0 -0
  26. data/icons/folder_inbox.png +0 -0
  27. data/icons/idea.png +0 -0
  28. data/icons/mega_ark.png +0 -0
  29. data/icons/messagebox_critical.png +0 -0
  30. data/icons/messagebox_info.png +0 -0
  31. data/icons/messagebox_warning.png +0 -0
  32. data/icons/messagebox_warning_small.png +0 -0
  33. data/icons/package.png +0 -0
  34. data/icons/package_favourite.png +0 -0
  35. data/icons/package_unknown.png +0 -0
  36. data/src/Console/Console_Parser.rb +71 -0
  37. data/src/Console/XDCC_Pack_Match_Template.rb +29 -0
  38. data/src/Console/xdcc-fetch.rb +123 -0
  39. data/src/GUI/About_Dialog.rb +50 -0
  40. data/src/GUI/Application_Builder.rb +280 -0
  41. data/src/GUI/Context_Menu.rb +81 -0
  42. data/src/GUI/Custom_Tabs.rb +60 -0
  43. data/src/GUI/Dialog_Box.rb +116 -0
  44. data/src/GUI/Download_Finished_Box.rb +41 -0
  45. data/src/GUI/Empty_Text_Field_Handler.rb +86 -0
  46. data/src/GUI/Gui_Logic.rb +629 -0
  47. data/src/GUI/Icon_Loader.rb +58 -0
  48. data/src/GUI/Main_Window.rb +227 -0
  49. data/src/GUI/Packet_Item.rb +171 -0
  50. data/src/GUI/Packet_List.rb +145 -0
  51. data/src/GUI/Speed_Widget.rb +101 -0
  52. data/src/GUI/Talk_Back.rb +118 -0
  53. data/src/GUI/Toggle_Button.rb +56 -0
  54. data/src/Network/CTCP_Handler.rb +61 -0
  55. data/src/Network/DCC_File.rb +323 -0
  56. data/src/Network/DCC_Parser.rb +71 -0
  57. data/src/Network/IPAddr_Ext.rb +76 -0
  58. data/src/Network/IRC_Message.rb +161 -0
  59. data/src/Network/IRC_Server.rb +273 -0
  60. data/src/Network/IRC_Server_Respond_Map.rb +223 -0
  61. data/src/Network/IRC_User.rb +58 -0
  62. data/src/Network/TCP_Connection.rb +168 -0
  63. data/src/Network/XDCC_Announcement.rb +120 -0
  64. data/src/Network/XDCC_Announcement_Storage.rb +167 -0
  65. data/src/Network/XDCC_Download_Handler.rb +412 -0
  66. data/src/Network/XDCC_Pack.rb +58 -0
  67. data/src/Network/XDCC_Parser.rb +253 -0
  68. data/src/Translations/README +61 -0
  69. data/src/Translations/check_translations +83 -0
  70. data/src/Translations/de.rb +140 -0
  71. data/src/Translations/en.rb +145 -0
  72. data/src/Utilities/Configuration.rb +91 -0
  73. data/src/Utilities/Events.rb +87 -0
  74. data/src/Utilities/Globals.rb +138 -0
  75. data/src/Utilities/PrettyException.rb +1091 -0
  76. data/src/Utilities/Recursive_Open_Struct.rb +159 -0
  77. data/src/Utilities/Timer.rb +71 -0
  78. metadata +135 -0
@@ -0,0 +1,145 @@
1
+ # Copyright (c) 2004, 2005 Martin Ankerl
2
+ # All rights reserved.
3
+ #
4
+ # Redistribution and use in source and binary forms, with or without modification,
5
+ # are permitted provided that the following conditions are met:
6
+ #
7
+ # * Redistributions of source code must retain the above copyright notice, this list
8
+ # of conditions and the following disclaimer.
9
+ # * Redistributions in binary form must reproduce the above copyright notice, this list
10
+ # of conditions and the following disclaimer in the documentation and/or other materials
11
+ # provided with the distribution.
12
+ # * Neither the name of Martin Ankerl nor the names of its contributors may be used to
13
+ # endorse or promote products derived from this software without specific prior written
14
+ # permission.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
17
+ # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18
+ # AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
19
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21
+ # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22
+ # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
23
+ # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
+
25
+ require 'set'
26
+ require 'src/GUI/Packet_Item'
27
+
28
+ # Packet_List is a more convenient wrapper for FXIconList. This class has to be used
29
+ # in combination with Packet_Item.
30
+ class Packet_List < FXIconList
31
+ include Responder
32
+
33
+ # Create a new Packet_List. All parameters are passed to the parental constructor FXIconList.
34
+ def initialize(variables, *args)
35
+ @variables = variables
36
+ @sort_mutex = Mutex.new
37
+ @sort_thread = nil
38
+ if FOXVERSION=="1.0"
39
+ def getItem(num)
40
+ retrieveItem(num)
41
+ end
42
+ end
43
+
44
+ @header_item_index = 0
45
+ @reversed = false
46
+ @conversions = Array.new
47
+ @items = Set.new
48
+ super(*args)
49
+
50
+ header.connect(SEL_COMMAND) do |sender, sel, item_number|
51
+ on_cmd_header(item_number)
52
+ end
53
+ end
54
+
55
+ # Called whenever a header is clicked
56
+ def on_cmd_header(header_item_index)
57
+ @variables.gui_mutex.synchronize do
58
+ header.setArrowDir(@header_item_index, MAYBE)
59
+ if @header_item_index == header_item_index
60
+ @reversed = !@reversed
61
+ else
62
+ @reversed = false
63
+ end
64
+ @header_item_index = header_item_index
65
+ header.setArrowDir(@header_item_index, @reversed)
66
+ sortItems
67
+ end
68
+
69
+ return 0
70
+ end
71
+
72
+ def sortItems
73
+ @items.each do |item|
74
+ item.update_sort_key
75
+ end
76
+ super
77
+ end
78
+
79
+ # Check if the search order is reversed (happens when clicking on the same header twice)
80
+ def reversed?
81
+ @reversed
82
+ end
83
+
84
+ # Get index of the header that should be used for sorting
85
+ def sort_index
86
+ @header_item_index
87
+ end
88
+
89
+ # Add a new header. The block that you need to specify is used to convert a string of this
90
+ # column into something that can be used for sorting. The yielded parameter item_colum_text
91
+ # is the text of one item of this column.
92
+ def add_header(text, width, &conversion) # :yields: item_column_text
93
+ appendHeader(text, nil, width)
94
+ header.setArrowDir(0, false) if @conversions.empty?
95
+ @conversions.push conversion
96
+ end
97
+
98
+ # Create a new Packet_Item. After the icon, you can specify the text for each of the columns.
99
+ # Here is an example:
100
+ # list.create_item(my_icon, "Martin", "Ankerl", "2005")
101
+ def create_item(icon, *args)
102
+ Packet_Item.new(self, icon, *args)
103
+ end
104
+
105
+ # Add a new Packet_Item to this list.Called from within Packet_Item during Packet_Item#parent=
106
+ def add_item(item)
107
+ @items.add item
108
+ appendItem(item.fox_item)
109
+ item
110
+ end
111
+
112
+ # Remove the given Packet_Item from the list. This is slow, because
113
+ # the item has to be searched with a linear search. To remove all items
114
+ # use #clear.
115
+ def remove_item(item)
116
+ i = 0
117
+ @items.delete item
118
+ fox_item = item.fox_item
119
+ i += 1 while i < numItems && fox_item != getItem(i)
120
+ removeItem(i) if i < numItems
121
+ item
122
+ end
123
+
124
+ # Removes all items from the list.
125
+ def clear
126
+ @items.each { |item| item.clear }
127
+ @items.clear
128
+ # todo: mutex!?
129
+ clearItems
130
+ end
131
+
132
+ # use in combination with Packet_Item#show
133
+ def dirty_clear
134
+ clearItems
135
+ @items.clear
136
+ end
137
+
138
+ # Get the sort for a given header index. The sort function has been supplied
139
+ # when calling #new. This is used from Packet_Item.
140
+ def sort_function(header_item_index)
141
+ @conversions[header_item_index]
142
+ end
143
+ end
144
+
145
+
@@ -0,0 +1,101 @@
1
+ # Copyright (c) 2004, 2005 Martin Ankerl
2
+ # All rights reserved.
3
+ #
4
+ # Redistribution and use in source and binary forms, with or without modification,
5
+ # are permitted provided that the following conditions are met:
6
+ #
7
+ # * Redistributions of source code must retain the above copyright notice, this list
8
+ # of conditions and the following disclaimer.
9
+ # * Redistributions in binary form must reproduce the above copyright notice, this list
10
+ # of conditions and the following disclaimer in the documentation and/or other materials
11
+ # provided with the distribution.
12
+ # * Neither the name of Martin Ankerl nor the names of its contributors may be used to
13
+ # endorse or promote products derived from this software without specific prior written
14
+ # permission.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
17
+ # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18
+ # AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
19
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21
+ # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22
+ # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
23
+ # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
+
25
+ # Speed_Widget is a widget to display the download speed. The widget shows the average
26
+ # average download speed.
27
+ class Speed_Widget
28
+
29
+ # Create a new widget in parent with given width. The specified block is used to convert an
30
+ # integer value into a string that is used to display the current average speed. The widget
31
+ # updates itself every 0.5 second.
32
+ def initialize(parent, width, init_text, &proc) # :yields: current_speed
33
+ @updateMutex = Mutex.new
34
+ @val_to_str = proc
35
+ @max = 10000
36
+ @slowness = 0.95
37
+ FXHorizontalFrame.new(parent, FRAME_SUNKEN|LAYOUT_FILL_Y, 0,0,0,0, 1,1,1,1,1,1) do |frame|
38
+ @progress = FXProgressBar.new(frame, nil, 0, LAYOUT_FILL_Y|LAYOUT_FIX_WIDTH) do |progress|
39
+ progress.width = width
40
+ progress.total = @max
41
+ end
42
+ @label = FXLabel.new(frame, init_text, nil, JUSTIFY_CENTER_Y|JUSTIFY_RIGHT|LAYOUT_FIX_WIDTH) do |label|
43
+ label.width = 60
44
+ end
45
+ end
46
+ @highest_val = 0
47
+ @value = 0.0
48
+ @values = Hash.new
49
+
50
+ @updater = Thread.new do
51
+ loop do
52
+ update
53
+ sleep(0.1)
54
+ end
55
+ end
56
+ end
57
+
58
+ # Specify how slow adapting is, a value from 0 to 1.
59
+ # 0.0: instantaneously
60
+ # 0.5: medium
61
+ # 0.9: extremely slow
62
+ def slowness=(slowness)
63
+ @slowness = slowness
64
+ end
65
+
66
+ # The widget uses multiple sources for the average speed. All values specified here are summed
67
+ # up.
68
+ def []=(key, val)
69
+ @values[key] = val
70
+ end
71
+
72
+ # Remove a source.
73
+ def delete(key)
74
+ @values.delete(key)
75
+ end
76
+
77
+ private
78
+
79
+ # update is called every 0.1 second.
80
+ def update
81
+ @updateMutex.synchronize do
82
+ # sum up values
83
+ new_value = 0
84
+ @values.each_value do |val|
85
+ new_value += val
86
+ end
87
+ # update top value
88
+ @highest_val = new_value if (new_value > @highest_val)
89
+ return if @highest_val == 0
90
+ # exponentally adapt to new value
91
+ last_value = @value
92
+ @value = @value*@slowness + new_value*(1-@slowness)
93
+ # nothing to do if value has not changed
94
+ return if @value == last_value
95
+ # calc + set progress bar size
96
+ @progress.progress = (1.0 * @max / @highest_val * @value).to_i
97
+ # set text
98
+ @label.text = @val_to_str.call(new_value)
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,118 @@
1
+ # Copyright (c) 2004, 2005 Martin Ankerl
2
+ # All rights reserved.
3
+ #
4
+ # Redistribution and use in source and binary forms, with or without modification,
5
+ # are permitted provided that the following conditions are met:
6
+ #
7
+ # * Redistributions of source code must retain the above copyright notice, this list
8
+ # of conditions and the following disclaimer.
9
+ # * Redistributions in binary form must reproduce the above copyright notice, this list
10
+ # of conditions and the following disclaimer in the documentation and/or other materials
11
+ # provided with the distribution.
12
+ # * Neither the name of Martin Ankerl nor the names of its contributors may be used to
13
+ # endorse or promote products derived from this software without specific prior written
14
+ # permission.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
17
+ # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18
+ # AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
19
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21
+ # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22
+ # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
23
+ # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
+
25
+ require 'fox'
26
+
27
+ include Fox
28
+
29
+ require 'src/Utilities/Globals'
30
+
31
+
32
+ # Unfortunately Talk_Back only works for email server that allow non-secure connections,
33
+ # and therefore is useless. Let's wait until smtp supports everything requird.
34
+ class Talk_Back < FXDialogBox
35
+ def Talk_Back.run(err)
36
+ $main_window.hide if $main_window
37
+ app = FXApp.instance || FXApp.new($cfg.talkback.name, $cfg.talkback.name)
38
+ app.create
39
+ main = $main_window || FXMainWindow.new(FXApp.instance, $cfg.talkback.name)
40
+ main.hide
41
+ puts err.backtrace
42
+ tb = Talk_Back.new(app, err)
43
+ tb.execute
44
+ app.run
45
+ end
46
+
47
+ def initialize(app, err)
48
+ super(app, $cfg.talkback.name, DECOR_ALL, 0, 0, 400, 400)
49
+ @err = err
50
+ @time = Time.now
51
+ build_controls
52
+ end
53
+
54
+ def create
55
+ super
56
+ if dialog == MBOX_CLICKED_OK
57
+ show(PLACEMENT_SCREEN)
58
+ else
59
+ exit
60
+ end
61
+ end
62
+
63
+ def build_controls
64
+ FXVerticalFrame.new(self, LAYOUT_FILL_X|LAYOUT_FILL_Y) do |main|
65
+ FXLabel.new(main, "1. Specify your email, if you want an response:", nil, LABEL_NORMAL)
66
+ @addr = FXTextField.new(main, 1, nil, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|FRAME_SUNKEN) do |addr|
67
+ addr.text = "anonymous@unknown.com"
68
+ end
69
+ FXLabel.new(main, "2. If possible, describe how you got this crash:", nil, LABEL_NORMAL)
70
+ FXHorizontalFrame.new(main, LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_SUNKEN, 0,0,0,0, 0,0,0,0,0,0) do |textframe|
71
+ @user_desc = FXText.new(textframe, nil, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_Y) do |user_desc|
72
+ user_desc.text = "1. Steps to reproduce\n\n\n\n"
73
+ user_desc.text += "2. Steps to reproduce\n\n\n\n"
74
+ user_desc.text += "3. Steps to reproduce\n\n\n\n"
75
+ end
76
+ end
77
+
78
+ FXLabel.new(main, "When you click 'Send', an email is sent to\nxdcctest@gmail.com that contains your specified\ninformation and a stack trace. No other private\ninformation is sent.", nil, JUSTIFY_LEFT|ICON_BEFORE_TEXT)
79
+
80
+ FXHorizontalSeparator.new(main)
81
+
82
+ FXHorizontalFrame.new(main, LAYOUT_FILL_X) do |buttonframe|
83
+ @send_btn = FXButton.new(buttonframe, $cfg.text.submit, nil, nil, 0, BUTTON_NORMAL|LAYOUT_CENTER_X)
84
+ @send_btn.connect(SEL_COMMAND) { on_cmd_send }
85
+ @cancel_btn = FXButton.new(buttonframe, $cfg.text.cancel , nil, nil, 0, BUTTON_NORMAL|LAYOUT_CENTER_X)
86
+ @cancel_btn.connect(SEL_COMMAND) { exit }
87
+ end
88
+ end
89
+
90
+ end
91
+
92
+ def dialog
93
+ FXMessageBox.error(self, MBOX_OK_CANCEL, $cfg.talkback.name, $cfg.text.talkback.preamble)
94
+ end
95
+
96
+ def on_cmd_send
97
+ subject = "[BUG] #{$cfg.app.version}, Revision #{$cfg.app.revision}, #{@time}"
98
+ text = @user_desc.text
99
+ text += "\n\n-------------------\n\n"
100
+ text += `ruby --version` + "\n"
101
+ text += "FXRuby #{Fox.fxrubyversion}"
102
+ text += "\n\n-------------------\n\n"
103
+ text += "Version: #{$cfg.app.version}\n"
104
+ text += "Revision: #{$cfg.app.revision}\n\n"
105
+ text += @err.message + "\n" + @err.backtrace.join("\n")
106
+
107
+ msg = ["Subject: " + subject + "\n", "\n", text+"\n"]
108
+ recipients = [ "martin.ankerl@fh-hagenberg.at" ] #"xdcctest@gmail.com" ]
109
+
110
+ puts text
111
+
112
+ Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
113
+ Net::SMTP.start("mailse.fh-hagenberg.at") do |smtp|
114
+ smtp.sendmail(msg, @addr.text.strip, recipients)
115
+ end
116
+ exit
117
+ end
118
+ end
@@ -0,0 +1,56 @@
1
+ # Copyright (c) 2004, 2005 Christoph Heindl and Martin Ankerl
2
+ # All rights reserved.
3
+ #
4
+ # Redistribution and use in source and binary forms, with or without modification,
5
+ # are permitted provided that the following conditions are met:
6
+ #
7
+ # * Redistributions of source code must retain the above copyright notice, this list
8
+ # of conditions and the following disclaimer.
9
+ # * Redistributions in binary form must reproduce the above copyright notice, this list
10
+ # of conditions and the following disclaimer in the documentation and/or other materials
11
+ # provided with the distribution.
12
+ # * Neither the name of Christoph Heindl and Martin Ankerl nor the names of its contributors
13
+ # may be used to endorse or promote products derived from this software without specific
14
+ # prior written permission.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
17
+ # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18
+ # AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
19
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21
+ # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22
+ # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
23
+ # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
+
25
+ # A button that uses the state (down, up) to display if it is enabled or not.
26
+ # the specified proc is executed
27
+ class Toggle_Button
28
+
29
+ # Creates a new toggle button. The specified block is called with the new toggle status whenever the button is clicked.
30
+ def initialize(parent, icon, text, toggled, &proc) # :yields: new_toggle_status
31
+ @btn = FXButton.new(parent, text, icon, nil, 0, FRAME_RAISED)
32
+ @toggled = toggled
33
+ @proc = proc
34
+ @btn.connect(SEL_COMMAND) do |sender, sel, data|
35
+ @toggled = !@toggled
36
+ on_toggle(@toggled)
37
+ @proc.call(@toggled) if @proc
38
+ end
39
+ on_toggle(@toggled)
40
+ end
41
+
42
+ # Check if the button is toggled (status down)
43
+ def toggled?
44
+ @toggled
45
+ end
46
+
47
+ private
48
+
49
+ def on_toggle(status)
50
+ if status
51
+ @btn.state = STATE_DOWN
52
+ else
53
+ @btn.state = STATE_UP
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,61 @@
1
+ # Copyright (c) 2005, Christoph Heindl
2
+ # All rights reserved.
3
+ #
4
+ # Redistribution and use in source and binary forms, with or without modification,
5
+ # are permitted provided that the following conditions are met:
6
+ #
7
+ # * Redistributions of source code must retain the above copyright notice, this list
8
+ # of conditions and the following disclaimer.
9
+ # * Redistributions in binary form must reproduce the above copyright notice, this list
10
+ # of conditions and the following disclaimer in the documentation and/or other materials
11
+ # provided with the distribution.
12
+ # * Neither the name of Christoph Heindl nor the names of its contributors may be used to
13
+ # endorse or promote products derived from this software without specific prior written
14
+ # permission.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
17
+ # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18
+ # AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
19
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21
+ # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22
+ # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
23
+ # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
+
25
+ # Parses extended ctcp queries and response appropriately if allowed to.
26
+ # Queries by the user itself (commands) are not supported (why should they?)
27
+ # as of now.
28
+ class CTCP_Handler
29
+
30
+ def initialize(irc_server)
31
+ @irc_server = irc_server
32
+ @irc_server.connect_to_events(IRC_Server::ON_USER_MESSAGE, self)
33
+ end
34
+
35
+ def shutdown
36
+ @irc_server.disconnect_from_events(IRC_Server::ON_USER_MESSAGE, self)
37
+ end
38
+
39
+ def on_event(irc_server, eventtype, eventargs)
40
+ irc_user, message, targets, irc_msg = eventargs
41
+ if (@irc_server.me.has_name?(targets[0]))
42
+ if irc_msg.ctcp_command?
43
+ return unless $cfg.network.ctcp.enable_replies
44
+ case (irc_msg.parameters[-1])
45
+ when "VERSION"
46
+ irc_user.notice("\001VERSION #{$cfg.app.name}:#{$cfg.app.revision}:#{RUBY_PLATFORM}\001")
47
+ when "SOURCE"
48
+ irc_user.notice("\001SOURCE #{$cfg.app.url}::\001")
49
+ irc_user.notice("\001SOURCE\001")
50
+ when "PING"
51
+ # Just sent back received string
52
+ irc_user.notice(message)
53
+ when "TIME"
54
+ irc_user.notice("\001#{Time.now}\001")
55
+ when "USERINFO"
56
+ irc_user.notice("\001USERINFO :no way\001")
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end