diff --git a/src/calibre/devices/nook/driver.py b/src/calibre/devices/nook/driver.py index 987b90c748..ca05885645 100644 --- a/src/calibre/devices/nook/driver.py +++ b/src/calibre/devices/nook/driver.py @@ -91,3 +91,19 @@ class NOOK_COLOR(NOOK): EBOOK_DIR_MAIN = 'My Files/Books' + ''' + def create_upload_path(self, path, mdata, fname, create_dirs=True): + filepath = NOOK.create_upload_path(self, path, mdata, fname, + create_dirs=create_dirs) + edm = self.EBOOK_DIR_MAIN.replace('/', os.sep) + npath = os.path.join(edm, _('News')) + os.sep + if npath in filepath: + filepath = filepath.replace(npath, os.sep.join('My Files', + 'Magazines')+os.sep) + filedir = os.path.dirname(filepath) + if create_dirs and not os.path.exists(filedir): + os.makedirs(filedir) + + return filepath + ''' + diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index df6ac45e5b..e699551150 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -269,10 +269,14 @@ def question_dialog(parent, title, msg, det_msg='', show_copy_button=True, return d.exec_() == yes_button -def info_dialog(parent, title, msg, det_msg='', show=False): +def info_dialog(parent, title, msg, det_msg='', show=False, + show_copy_button=True): d = MessageBox(QMessageBox.Information, title, msg, QMessageBox.Ok, parent, det_msg) d.setIconPixmap(QPixmap(I('dialog_information.png'))) + if not show_copy_button: + d.cb.setVisible(False) + if show: return d.exec_() return d diff --git a/src/calibre/gui2/preferences/plugins.py b/src/calibre/gui2/preferences/plugins.py index 2fe2b3bf01..c53c634ab4 100644 --- a/src/calibre/gui2/preferences/plugins.py +++ b/src/calibre/gui2/preferences/plugins.py @@ -15,7 +15,8 @@ from calibre.gui2.preferences.plugins_ui import Ui_Form from calibre.customize.ui import initialized_plugins, is_disabled, enable_plugin, \ disable_plugin, plugin_customization, add_plugin, \ remove_plugin -from calibre.gui2 import NONE, error_dialog, info_dialog, choose_files +from calibre.gui2 import NONE, error_dialog, info_dialog, choose_files, \ + question_dialog class PluginModel(QAbstractItemModel): # {{{ @@ -76,6 +77,16 @@ class PluginModel(QAbstractItemModel): # {{{ return self.index(j, 0, parent) return QModelIndex() + def plugin_to_index_by_properties(self, plugin): + for i, category in enumerate(self.categories): + parent = self.index(i, 0, QModelIndex()) + for j, p in enumerate(self._data[category]): + if plugin.name == p.name and plugin.type == p.type and \ + plugin.author == p.author and plugin.version == p.version: + return self.index(j, 0, parent) + return QModelIndex() + + def refresh_plugin(self, plugin, rescan=False): if rescan: self.populate() @@ -132,7 +143,6 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): self.toggle_plugin_button.clicked.connect(self.toggle_plugin) self.customize_plugin_button.clicked.connect(self.customize_plugin) self.remove_plugin_button.clicked.connect(self.remove_plugin) - self.button_plugin_browse.clicked.connect(self.find_plugin) self.button_plugin_add.clicked.connect(self.add_plugin) def toggle_plugin(self, *args): @@ -149,23 +159,39 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): self.modify_plugin(op='remove') def add_plugin(self): - path = unicode(self.plugin_path.text()) - if path and os.access(path, os.R_OK) and path.lower().endswith('.zip'): - add_plugin(path) + path = choose_files(self, 'add a plugin dialog', _('Add plugin'), + filters=[(_('Plugins'), ['zip'])], all_files=False, + select_only_single_file=True) + if not path: + return + path = path[0] + if path and os.access(path, os.R_OK) and path.lower().endswith('.zip'): + if not question_dialog(self, _('Are you sure?'), '
' + \
+ _('Installing plugins is a security risk. '
+ 'Plugins can contain a virus/malware. '
+ 'Only install it if you got it from a trusted source.'
+ ' Are you sure you want to proceed?'),
+ show_copy_button=False):
+ return
+ plugin = add_plugin(path)
self._plugin_model.populate()
self._plugin_model.reset()
self.changed_signal.emit()
- self.plugin_path.setText('')
+ info_dialog(self, _('Success'),
+ _('Plugin {0} successfully installed under '
+ ' {1} plugins. You may have to restart calibre '
+ 'for the plugin to take effect.').format(plugin.name, plugin.type),
+ show=True, show_copy_button=False)
+ idx = self._plugin_model.plugin_to_index_by_properties(plugin)
+ if idx.isValid():
+ self.plugin_view.scrollTo(idx,
+ self.plugin_view.PositionAtCenter)
+ self.plugin_view.scrollTo(idx,
+ self.plugin_view.PositionAtCenter)
else:
error_dialog(self, _('No valid plugin path'),
_('%s is not a valid plugin path')%path).exec_()
- def find_plugin(self):
- path = choose_files(self, 'choose plugin dialog', _('Choose plugin'),
- filters=[('Plugins', ['zip'])], all_files=False,
- select_only_single_file=True)
- if path:
- self.plugin_path.setText(path[0])
def modify_plugin(self, op=''):
index = self.plugin_view.currentIndex()
@@ -191,10 +217,13 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
if plugin.do_user_config():
self._plugin_model.refresh_plugin(plugin)
elif op == 'remove':
+ msg = _('Plugin {0} successfully removed').format(plugin.name)
if remove_plugin(plugin):
self._plugin_model.populate()
self._plugin_model.reset()
self.changed_signal.emit()
+ info_dialog(self, _('Success'), msg, show=True,
+ show_copy_button=False)
else:
error_dialog(self, _('Cannot remove builtin plugin'),
plugin.name + _(' cannot be removed. It is a '
diff --git a/src/calibre/gui2/preferences/plugins.ui b/src/calibre/gui2/preferences/plugins.ui
index 8979867bbc..18f0786a66 100644
--- a/src/calibre/gui2/preferences/plugins.ui
+++ b/src/calibre/gui2/preferences/plugins.ui
@@ -72,64 +72,10 @@