diff --git a/calibre-plugin/config.py b/calibre-plugin/config.py
index 6180f465..3a72a1b5 100644
--- a/calibre-plugin/config.py
+++ b/calibre-plugin/config.py
@@ -153,7 +153,7 @@ class RejectURLList:
self.sync_lock = threading.RLock()
self.listcache = None
- def _read_list_from_text(self,text):
+ def _read_list_from_text(self,text,addreasontext=None):
cache = {}
for line in text.splitlines():
if ',' in line:
@@ -162,6 +162,10 @@ class RejectURLList:
(rejurl,note) = (line,'')
rejurl = getNormalStoryURL(rejurl)
if rejurl:
+ if addreasontext and note:
+ note = note +" - "+addreasontext
+ elif addreasontext:
+ note = addreasontext
cache[rejurl] = note
return cache
@@ -200,8 +204,8 @@ class RejectURLList:
del listcache[url]
self._save_list(listcache)
- def add_text(self,rejecttext):
- self.add(self._read_list_from_text(rejecttext).items())
+ def add_text(self,rejecttext,addreasontext):
+ self.add(self._read_list_from_text(rejecttext,addreasontext).items())
def add(self,rejectlist,clear=False):
# rejectlist=list of (url,note) tuples.
@@ -524,7 +528,8 @@ class BasicTab(QWidget):
rejectlist,
rejectreasons=rejecturllist.get_reject_reasons(),
header="Edit Reject URLs List",
- show_delete=False)
+ show_delete=False,
+ show_all_reasons=False)
d.exec_()
if d.result() != d.Accepted:
@@ -552,11 +557,13 @@ class BasicTab(QWidget):
"http://example.com?story.php?sid=5,Reason why I rejected it",
icon=self.windowIcon(),
title="Add Reject URLs",
- label="Add Reject URLs. Use: http://...,note",
- tooltip="One URL per line, everything after , will be put in the note.")
+ label="Add Reject URLs. Use: http://...,note
Invalid story URLs will be ignored.",
+ tooltip="One URL per line, everything after , will be put in the note.",
+ rejectreasons=rejecturllist.get_reject_reasons(),
+ reasonslabel='Add this reason to all URLs added:')
d.exec_()
if d.result() == d.Accepted:
- rejecturllist.add_text(d.get_plain_text())
+ rejecturllist.add_text(d.get_plain_text(),d.get_reason_text())
class PersonalIniTab(QWidget):
diff --git a/calibre-plugin/dialogs.py b/calibre-plugin/dialogs.py
index 4ee16fe2..35a6c02a 100644
--- a/calibre-plugin/dialogs.py
+++ b/calibre-plugin/dialogs.py
@@ -45,6 +45,19 @@ collision_order=[SKIP,
OVERWRITEALWAYS,
CALIBREONLY,]
+# This is a more than slightly kludgey way to get
+# EditWithComplete to *not* alpha-order the reasons, but leave
+# them in the order entered. If
+# calibre.gui2.complete2.CompleteModel.set_items ever changes,
+# this function will need to also.
+def complete_model_set_items_kludge(self, items):
+ items = [unicode(x.strip()) for x in items]
+ items = [x for x in items if x]
+ items = tuple(items)
+ self.all_items = self.current_items = items
+ self.current_prefix = ''
+ self.reset()
+
class NotGoingToDownload(Exception):
def __init__(self,error,icon='dialog_error.png'):
self.error=error
@@ -779,19 +792,6 @@ class RejectListTableWidget(QTableWidget):
note_cell = EditWithComplete(self)
- # This is a more than slightly kludgey way to get
- # EditWithComplete to *not* alpha-order the reasons, but leave
- # them in the order entered. If
- # calibre.gui2.complete2.CompleteModel.set_items ever changes,
- # this function will need to also.
- def complete_model_set_items_kludge(self, items):
- items = [unicode(x.strip()) for x in items]
- items = [x for x in items if x]
- items = tuple(items)
- self.all_items = self.current_items = items
- self.current_prefix = ''
- self.reset()
-
note_cell.lineEdit().mcompleter.model().set_items = \
partial(complete_model_set_items_kludge,
note_cell.lineEdit().mcompleter.model())
@@ -895,6 +895,7 @@ class RejectListDialog(SizePersistedDialog):
header="List of Books to Reject",
icon='rotate-right.png',
show_delete=True,
+ show_all_reasons=True,
save_size_name='ffdl:reject list dialog'):
SizePersistedDialog.__init__(self, gui, save_size_name)
self.gui = gui
@@ -935,6 +936,26 @@ class RejectListDialog(SizePersistedDialog):
spacerItem1 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
button_layout.addItem(spacerItem1)
+ if show_all_reasons:
+ self.reason_edit = EditWithComplete(self)
+ self.reason_edit.lineEdit().mcompleter.model().set_items = \
+ partial(complete_model_set_items_kludge,
+ self.reason_edit.lineEdit().mcompleter.model())
+
+ items = ['']+rejectreasons
+ self.reason_edit.update_items_cache(items)
+ self.reason_edit.show_initial_value('')
+ self.reason_edit.set_separator(None)
+ self.reason_edit.setToolTip("This will be added to whatever note you've set for each URL above.")
+
+ horz = QHBoxLayout()
+ label = QLabel("Add this reason to all URLs added:")
+ label.setToolTip("This will be added to whatever note you've set for each URL above.")
+ horz.addWidget(label)
+ horz.addWidget(self.reason_edit)
+ horz.insertStretch(-1)
+ layout.addLayout(horz)
+
options_layout = QHBoxLayout()
if show_delete:
@@ -960,13 +981,18 @@ class RejectListDialog(SizePersistedDialog):
def get_reject_list(self):
return self.rejects_table.get_reject_list()
+ def get_reason_text(self):
+ return unicode(self.reason_edit.currentText()).strip()
+
def get_deletebooks(self):
return self.deletebooks.isChecked()
class EditTextDialog(QDialog):
def __init__(self, parent, text,
- icon=None, title=None, label=None, tooltip=None):
+ icon=None, title=None, label=None, tooltip=None,
+ rejectreasons=[],reasonslabel=None
+ ):
QDialog.__init__(self, parent)
self.resize(600, 500)
self.l = QVBoxLayout()
@@ -987,6 +1013,29 @@ class EditTextDialog(QDialog):
self.label.setToolTip(tooltip)
self.textedit.setToolTip(tooltip)
+ if rejectreasons or reasonslabel:
+ self.reason_edit = EditWithComplete(self)
+
+ self.reason_edit.lineEdit().mcompleter.model().set_items = \
+ partial(complete_model_set_items_kludge,
+ self.reason_edit.lineEdit().mcompleter.model())
+
+ items = ['']+rejectreasons
+ self.reason_edit.update_items_cache(items)
+ self.reason_edit.show_initial_value('')
+ self.reason_edit.set_separator(None)
+ self.reason_edit.setToolTip(reasonslabel)
+
+ if reasonslabel:
+ horz = QHBoxLayout()
+ label = QLabel(reasonslabel)
+ label.setToolTip(reasonslabel)
+ horz.addWidget(label)
+ horz.addWidget(self.reason_edit)
+ self.l.addLayout(horz)
+ else:
+ self.l.addWidget(self.reason_edit)
+
button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
button_box.accepted.connect(self.accept)
button_box.rejected.connect(self.reject)
@@ -994,3 +1043,7 @@ class EditTextDialog(QDialog):
def get_plain_text(self):
return unicode(self.textedit.toPlainText())
+
+ def get_reason_text(self):
+ return unicode(self.reason_edit.currentText()).strip()
+
diff --git a/calibre-plugin/ffdl_plugin.py b/calibre-plugin/ffdl_plugin.py
index 07009ba0..b99aab43 100644
--- a/calibre-plugin/ffdl_plugin.py
+++ b/calibre-plugin/ffdl_plugin.py
@@ -404,8 +404,13 @@ class FanFictionDownLoaderPlugin(InterfaceAction):
bookids=[]
rejectlist=[]
+ addreasontext=d.get_reason_text()
for (bookid,url,note) in d.get_reject_list():
bookids.append(bookid)
+ if addreasontext and note:
+ note = note +" - "+addreasontext
+ elif addreasontext:
+ note = addreasontext
rejectlist.append((url,note))
print("Adding (%s) to Reject List: %s"%(url,note))