Class: Ruber::ChoosePluginsWidget

Inherits:
Qt::Widget
  • Object
show all
Defined in:
lib/ruber/main_window/choose_plugins_dlg.rb

Overview

Widget which implements most of the functionality of the ChoosePluginsDlg class.

It contains a list of plugins in the current search path, where the user can choose the plugins to load (using checkboxes), and a list of directories where the user can choose where to look for plugins.

In the plugin list, chosen plugins are shown with a selected mark, while plugins which will be loaded to satisfy the dependencies of chosen plugins will be shown with a partial mark.

Whenever the user changes the chosen plugins, the dependencies are re-computed. If there’s a problem, the user is warned with a message box.

Instance Method Summary collapse

Constructor Details

#initialize(parent = nil) ⇒ ChoosePluginsWidget

Creates a new ChoosePluginsWidget.

The list of directories where to look for plugins is read from the configuration file. The chosen plugins are read from the configuration file, but excluding all those which aren’t currently loaded (the reason to do so is that a chosen plugin might have failed to load and thus it should not appear in the chosen list). Also, any plugin which is included in the chosen list but whose PDF can’t be found is excluded.

Dependencies are then computed, and dependencies of the chosen plugins are marked as such. If a dependency problem occurs, the user is warned and all plugins are deselected.



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
# File 'lib/ruber/main_window/choose_plugins_dlg.rb', line 123

def initialize parent = nil
  super
  @ui = Ui::ChoosePluginsWidget.new
  @ui.setupUi self
  
  dirs = Ruber[:app].plugin_dirs
  
  @chosen_plugins = Ruber[:config][:general, :plugins].map(&:to_sym)
  loaded = Ruber[:components].plugins.map(&:plugin_name)
  @chosen_plugins.delete_if{|i| !loaded.include? i}
  
  read_plugins dirs
  res = find_deps(:sorry) do |e| 
    "There were problems making dependencies. #{create_failure_message e}\nAll plugins will be deselected"
  end
  if res
    @chosen_plugins.clear
    @needed_plugins = []
  end
  m = Qt::StandardItemModel.new @ui.plugins
  @ui.plugins.model = m
  
  connect m, SIGNAL('itemChanged(QStandardItem*)'), self, SLOT('plugin_toggled(QStandardItem*)')
  
  def m.flags idx
    Qt::ItemIsSelectable|Qt::ItemIsEnabled| Qt::ItemIsUserCheckable
  end
  
  @url = KDE::UrlRequester.new self
  @ui.directories.custom_editor = @url.custom_editor
  @url.mode = KDE::File::Directory | KDE::File::LocalOnly
  connect @ui.directories, SIGNAL(:changed), self, SLOT(:slot_directories_changed)      
  @ui.directories.items = dirs
  
  fill_plugin_list
end

Instance Method Details

#apply_defaultsObject

Sets both the chosen plugins and the plugin directories to their default values (see Appplication::DEFAULT_PLUGIN_PATHS and Application::DEFAULT_PLUGINS). If a dependency problem occurs, the user is warned and all plugins are deselected



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/ruber/main_window/choose_plugins_dlg.rb', line 187

def apply_defaults
  dirs = Ruber[:config].default :general, :plugin_dirs
  @chosen_plugins = Ruber[:config].default( :general, :plugins).split(',').map{|i| i.to_sym}
  read_plugins dirs
  res = find_deps(:sorry) do |e| 
    "There were problems making dependencies. #{create_failure_message e}\nAll plugins will be deselected"
  end
  if res
    @chosen_plugins.clear
    @needed_plugins = []
  end
  @ui.directories.clear
  @ui.directories.items = dirs
  
  fill_plugin_list
end

#deps_satisfied?Boolean

Returns false if there’s a dependency problem among the chosen plugins and true otherwise.

Returns:

  • (Boolean)


208
209
210
211
212
213
214
215
# File 'lib/ruber/main_window/choose_plugins_dlg.rb', line 208

def deps_satisfied?
  begin 
    find_deps
    true
  rescue ComponentManager::UnresolvedDep, ComponentManager::CircularDep
    false
  end
end

#pluginsObject

Returns a hash containing both the chosen plugins and their dependencies. The keys are the plugin names, while the values are the directories of the plugins.



221
222
223
224
225
# File 'lib/ruber/main_window/choose_plugins_dlg.rb', line 221

def plugins
  @ui.plugins.model.enum_for(:each_row).map do |name, _, dir|
    [name.data.to_string.to_sym, dir.text] if name.checked?
  end.compact.to_h
end

#sizeHintObject

:nodoc:



161
162
163
# File 'lib/ruber/main_window/choose_plugins_dlg.rb', line 161

def sizeHint #:nodoc:
  Qt::Size.new 600, 550
end

#write_settingsObject

Writes the settings to the configuration file. The directories listed in the

directory widget are stored in the <i>general/plugin_dirs</i> entry, while
the chosen plugins are stored in the <i>general/plugins</i> entry. Plugins
which haven't been chosen but are dependencies of the chosen ones aren't stored.


171
172
173
174
175
176
177
178
179
180
# File 'lib/ruber/main_window/choose_plugins_dlg.rb', line 171

def write_settings
  dirs = @ui.directories.items
  Ruber[:app].plugin_dirs = dirs
  plugins = []
  @ui.plugins.model.each_row do |r|
    plugins << r[0].data.to_string if  r[0].fully_checked?
  end
  Ruber[:config][:general, :plugins] = plugins
  Ruber[:config].write
end