From 8f076a462454ee3b9e39becdfd332eeaef8b1e54 Mon Sep 17 00:00:00 2001
From: Kovid Goyal
Date: Fri, 17 Aug 2012 09:05:02 +0530
Subject: [PATCH] Nicer error message when the user has set the default send to
device action incorrectly
---
src/calibre/devices/errors.py | 6 ++++++
src/calibre/devices/usbms/device.py | 15 ++++++++++++---
src/calibre/gui2/device.py | 5 ++++-
3 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/src/calibre/devices/errors.py b/src/calibre/devices/errors.py
index 9b8c7b9d42..d906bb86c8 100644
--- a/src/calibre/devices/errors.py
+++ b/src/calibre/devices/errors.py
@@ -104,3 +104,9 @@ class ControlError(ProtocolError):
if self.desc:
return self.desc
return "Unknown control error occurred"
+
+class WrongDestinationError(PathError):
+ ''' The user chose the wrong destination to send books to, for example by
+ trying to send books to a non existant storage card.'''
+ pass
+
diff --git a/src/calibre/devices/usbms/device.py b/src/calibre/devices/usbms/device.py
index 759aa80bbb..600916128d 100644
--- a/src/calibre/devices/usbms/device.py
+++ b/src/calibre/devices/usbms/device.py
@@ -15,7 +15,8 @@ import os, subprocess, time, re, sys, glob
from itertools import repeat
from calibre.devices.interface import DevicePlugin
-from calibre.devices.errors import DeviceError, FreeSpaceError
+from calibre.devices.errors import (DeviceError, FreeSpaceError,
+ WrongDestinationError)
from calibre.devices.usbms.deviceconfig import DeviceConfig
from calibre.constants import iswindows, islinux, isosx, isfreebsd, plugins
from calibre.utils.filenames import ascii_filename as sanitize, shorten_components_to
@@ -976,9 +977,17 @@ class Device(DeviceConfig, DevicePlugin):
def _sanity_check(self, on_card, files):
if on_card == 'carda' and not self._card_a_prefix:
- raise ValueError(_('The reader has no storage card in this slot.'))
+ raise WrongDestinationError(_(
+ 'The reader has no storage card %s. You may have changed '
+ 'the default send to device action. Right click on the send '
+ 'to device button and reset the default action to be '
+ '"Send to main memory".')%'A')
elif on_card == 'cardb' and not self._card_b_prefix:
- raise ValueError(_('The reader has no storage card in this slot.'))
+ raise WrongDestinationError(_(
+ 'The reader has no storage card %s. You may have changed '
+ 'the default send to device action. Right click on the send '
+ 'to device button and reset the default action to be '
+ '"Send to main memory".')%'B')
elif on_card and on_card not in ('carda', 'cardb'):
raise DeviceError(_('Selected slot: %s is not supported.') % on_card)
diff --git a/src/calibre/gui2/device.py b/src/calibre/gui2/device.py
index 4ecf18f836..a029e0be8f 100644
--- a/src/calibre/gui2/device.py
+++ b/src/calibre/gui2/device.py
@@ -23,7 +23,7 @@ from calibre.gui2 import (config, error_dialog, Dispatcher, dynamic,
from calibre.ebooks.metadata import authors_to_string
from calibre import preferred_encoding, prints, force_unicode, as_unicode
from calibre.utils.filenames import ascii_filename
-from calibre.devices.errors import FreeSpaceError
+from calibre.devices.errors import FreeSpaceError, WrongDestinationError
from calibre.devices.apple.driver import ITUNES_ASYNC
from calibre.devices.folder_device.driver import FOLDER_DEVICE
from calibre.devices.bambook.driver import BAMBOOK, BAMBOOKWifi
@@ -1450,6 +1450,9 @@ class DeviceMixin(object): # {{{
'is no more free space available ')+where+
'
\n'%(titles,))
d.exec_()
+ elif isinstance(job.exception, WrongDestinationError):
+ error_dialog(self, _('Incorrect destination'),
+ unicode(job.exception), show=True)
else:
self.device_job_exception(job)
return