Blame 0004-Preferences-Ignored-devices-Add-a-button-to-reset-th.patch

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