2007-02-13 00:22:05 +00:00
|
|
|
module Msf
|
|
|
|
module Ui
|
|
|
|
module Gtk2
|
|
|
|
|
|
|
|
##
|
|
|
|
# This class describe all search stuff into the module treeview
|
|
|
|
##
|
|
|
|
class ModuleSearch
|
|
|
|
include Msf::Ui::Gtk2::MyControls
|
|
|
|
|
2007-02-13 14:38:15 +00:00
|
|
|
RUNNING, CLEAR = *(0..2).to_a
|
|
|
|
|
2007-02-15 22:09:24 +00:00
|
|
|
@@state = nil
|
2007-02-13 14:38:15 +00:00
|
|
|
|
2007-02-13 00:22:05 +00:00
|
|
|
#
|
|
|
|
# Initialize all stuff to perform a search
|
|
|
|
#
|
2007-02-13 09:14:02 +00:00
|
|
|
def initialize(search_entry, search_button, search_cancel_button)
|
2007-02-13 00:22:05 +00:00
|
|
|
@search_entry = search_entry
|
|
|
|
@search_button = search_button
|
2007-02-13 09:14:02 +00:00
|
|
|
@cancel_button = search_cancel_button
|
2007-02-13 00:22:05 +00:00
|
|
|
|
2007-02-15 22:09:24 +00:00
|
|
|
# Active completion
|
|
|
|
completion()
|
|
|
|
|
|
|
|
# Init state
|
|
|
|
@@state = CLEAR
|
|
|
|
|
2007-02-13 16:12:26 +00:00
|
|
|
# Signals
|
|
|
|
@search_entry.signal_connect('activate') do
|
|
|
|
@search_button.activate
|
|
|
|
end
|
|
|
|
|
2007-02-13 00:22:05 +00:00
|
|
|
@search_button.signal_connect('clicked') do
|
|
|
|
search(@search_entry.text)
|
|
|
|
end
|
2007-02-13 09:14:02 +00:00
|
|
|
|
|
|
|
@cancel_button.signal_connect('clicked') do
|
|
|
|
cancel()
|
|
|
|
end
|
2007-02-13 00:22:05 +00:00
|
|
|
end
|
|
|
|
|
2007-02-13 14:38:15 +00:00
|
|
|
|
2007-02-13 00:22:05 +00:00
|
|
|
#
|
2007-02-13 08:48:39 +00:00
|
|
|
# Perform a search throught the module treeview,
|
|
|
|
# and return the array result to MyModuleTree::remove
|
|
|
|
#
|
2007-02-13 00:22:05 +00:00
|
|
|
def search(text)
|
2007-02-15 22:09:24 +00:00
|
|
|
# If current state set to RUUNING, call cancel method
|
|
|
|
cancel if @@state == RUNNING
|
|
|
|
|
|
|
|
# Set current state to RUNNING
|
|
|
|
@@state = RUNNING
|
|
|
|
|
|
|
|
# Perform the search
|
2007-02-13 08:48:39 +00:00
|
|
|
found = []
|
2007-02-13 00:22:05 +00:00
|
|
|
filter = Regexp.new(text, Regexp::IGNORECASE)
|
|
|
|
$gtk2driver.module_model.each do |model, path, iter|
|
2007-02-13 08:48:39 +00:00
|
|
|
if (not iter[0][filter])
|
|
|
|
found.push(iter)
|
2007-02-13 00:22:05 +00:00
|
|
|
end
|
|
|
|
end
|
2007-02-13 08:48:39 +00:00
|
|
|
|
2007-02-13 14:38:15 +00:00
|
|
|
# Colorize the Gtk::Entry
|
|
|
|
state(RUNNING)
|
|
|
|
|
2007-02-13 08:48:39 +00:00
|
|
|
# pass the found array to the MyModuleTree and remove all not matched iter
|
2007-02-13 15:26:38 +00:00
|
|
|
# and finish by expanding the treeview
|
2007-02-13 08:48:39 +00:00
|
|
|
$gtk2driver.module_tree.remove(found)
|
2007-02-13 15:26:38 +00:00
|
|
|
$gtk2driver.module_tree.expand
|
2007-02-13 00:22:05 +00:00
|
|
|
end
|
2007-02-13 09:14:02 +00:00
|
|
|
|
2007-02-13 14:38:15 +00:00
|
|
|
|
2007-02-13 09:14:02 +00:00
|
|
|
#
|
|
|
|
# Clean the Gtk::Entry and refresh the modules treeview
|
|
|
|
#
|
|
|
|
def cancel
|
2007-02-13 14:38:15 +00:00
|
|
|
# clear the Gtk::Entry
|
2007-02-13 09:14:02 +00:00
|
|
|
@search_entry.set_text("")
|
2007-02-13 14:38:15 +00:00
|
|
|
|
|
|
|
# Colorize the Gtk::Entry
|
|
|
|
state(CLEAR)
|
|
|
|
|
|
|
|
# Refresh the modules treeview
|
2007-02-13 09:14:02 +00:00
|
|
|
$gtk2driver.module_tree.refresh
|
2007-02-15 22:09:24 +00:00
|
|
|
|
|
|
|
# Register the current state
|
|
|
|
@@state = CLEAR
|
2007-02-13 09:14:02 +00:00
|
|
|
end
|
2007-02-13 14:38:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Colorize the Gtk::Entry by state parameter
|
|
|
|
#
|
|
|
|
def state(state)
|
|
|
|
if (state == RUNNING)
|
|
|
|
@search_entry.modify_base(Gtk::STATE_NORMAL, Gdk::Color.parse('gray'))
|
|
|
|
elsif (state == CLEAR)
|
|
|
|
@search_entry.modify_base(Gtk::STATE_NORMAL, Gdk::Color.parse('white'))
|
|
|
|
end
|
|
|
|
end
|
2007-02-15 22:09:24 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Display completion for @search_entry
|
|
|
|
#
|
|
|
|
def completion
|
|
|
|
# set completion
|
|
|
|
completion = Gtk::EntryCompletion.new
|
|
|
|
@search_entry.completion = completion
|
|
|
|
|
|
|
|
# Describe the model completion
|
|
|
|
model = Gtk::ListStore.new(String)
|
|
|
|
$gtk2driver.module_completion.each do |v|
|
|
|
|
iter = model.append
|
|
|
|
iter[0] = v
|
|
|
|
end
|
|
|
|
|
|
|
|
# Attach the model completion to the completion object
|
|
|
|
completion.model = model
|
|
|
|
completion.text_column = 0
|
|
|
|
end
|
2007-02-13 00:22:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|