From 6bad6948033823b82ea37fb889188e4904a6508c Mon Sep 17 00:00:00 2001
From: Kovid Goyal <kovid@kovidgoyal.net>
Date: Sat, 20 Jul 2019 14:59:54 +0530
Subject: [PATCH 04/71] Preferences->Ignored devices: Add a button to reset the
list of devices that calibre is allowed to manage
---
.../gui2/preferences/ignored_devices.py | 31 ++++++++++++++-----
1 file changed, 24 insertions(+), 7 deletions(-)
diff --git a/src/calibre/gui2/preferences/ignored_devices.py b/src/calibre/gui2/preferences/ignored_devices.py
index 8cfb943cf3..cef9ac0dc2 100644
--- a/src/calibre/gui2/preferences/ignored_devices.py
+++ b/src/calibre/gui2/preferences/ignored_devices.py
@@ -1,15 +1,16 @@
#!/usr/bin/env python2
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai
+# License: GPLv3 Copyright: 2012, Kovid Goyal <kovid at kovidgoyal.net>
from __future__ import absolute_import, division, print_function, unicode_literals
-__license__ = 'GPL v3'
-__copyright__ = '2012, Kovid Goyal <kovid at kovidgoyal.net>'
-__docformat__ = 'restructuredtext en'
+import textwrap
-from PyQt5.Qt import (QLabel, QVBoxLayout, QListWidget, QListWidgetItem, Qt,
- QIcon)
+from PyQt5.Qt import (
+ QIcon, QLabel, QListWidget, QListWidgetItem, QPushButton, Qt, QVBoxLayout
+)
from calibre.customize.ui import enable_plugin
+from calibre.gui2 import gprefs
from calibre.gui2.preferences import ConfigWidgetBase, test_widget
from polyglot.builtins import iteritems, range
@@ -22,6 +23,7 @@ class ConfigWidget(ConfigWidgetBase):
self.gui = gui
self.l = l = QVBoxLayout()
self.setLayout(l)
+ self.confirms_reset = False
self.la = la = QLabel(_(
'The list of devices that you have asked calibre to ignore. '
@@ -46,11 +48,24 @@ class ConfigWidget(ConfigWidgetBase):
f.itemChanged.connect(self.changed_signal)
f.itemDoubleClicked.connect(self.toggle_item)
+ self.reset_confirmations_button = b = QPushButton(_('Reset allowed devices'))
+ b.setToolTip(textwrap.fill(_(
+ 'This will erase the list of devices that calibre knows about'
+ ' causing it to ask you for permission to manage them again,'
+ ' the next time they connect')))
+ b.clicked.connect(self.reset_confirmations)
+ l.addWidget(b)
+
+ def reset_confirmations(self):
+ self.confirms_reset = True
+ self.changed_signal.emit()
+
def toggle_item(self, item):
item.setCheckState(Qt.Checked if item.checkState() == Qt.Unchecked else
Qt.Unchecked)
def initialize(self):
+ self.confirms_reset = False
self.devices.blockSignals(True)
self.devices.clear()
for dev in self.gui.device_manager.devices:
@@ -94,11 +109,13 @@ class ConfigWidget(ConfigWidgetBase):
dev = e.data(Qt.UserRole)
if e.checkState() == Qt.Unchecked:
enable_plugin(dev)
+ if self.confirms_reset:
+ gprefs['ask_to_manage_device'] = []
return True # Restart required
if __name__ == '__main__':
- from PyQt5.Qt import QApplication
- app = QApplication([])
+ from calibre.gui2 import Application
+ app = Application([])
test_widget('Sharing', 'Ignored Devices')