From fd1b7996221cd42a9c52b1be74b8bbefb26fd46f Mon Sep 17 00:00:00 2001 From: John Schember Date: Fri, 5 Jun 2009 18:49:31 -0400 Subject: [PATCH 1/4] Hide eject button when leaving location_view. --- src/calibre/gui2/widgets.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/calibre/gui2/widgets.py b/src/calibre/gui2/widgets.py index d6b9d7d8ed..08422a285b 100644 --- a/src/calibre/gui2/widgets.py +++ b/src/calibre/gui2/widgets.py @@ -257,6 +257,9 @@ class LocationView(QListView): if 0 <= row and row <= 3: self.model().location_changed(row) + def leaveEvent(self, event): + self.eject_button.hide() + def show_eject(self, location): self.eject_button.hide() From cec9bf66ba3e25129e819ec8acbe994fb47ccc4c Mon Sep 17 00:00:00 2001 From: John Schember Date: Fri, 5 Jun 2009 19:24:03 -0400 Subject: [PATCH 2/4] Windows device ejection. --- src/calibre/devices/usbms/device.py | 33 +++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/calibre/devices/usbms/device.py b/src/calibre/devices/usbms/device.py index f0c54d7051..59c9849ca2 100644 --- a/src/calibre/devices/usbms/device.py +++ b/src/calibre/devices/usbms/device.py @@ -7,7 +7,14 @@ intended to be subclassed with the relevant parts implemented for a particular device. This class handles device detection. ''' -import os, subprocess, time, re, sys, glob +import glob +import os +import re +import struct +import subprocess +import sys +import time + from itertools import repeat from calibre.devices.interface import DevicePlugin @@ -492,7 +499,29 @@ class Device(DeviceConfig, DevicePlugin): self.open_osx() def eject_windows(self): - pass + win32file = __import__('win32file', globals(), locals(), [], -1) + win32con = __import__('win32con', globals(), locals(), [], -1) + win32shell = __import__('win32com.shell.shell', globals(), locals(), [], -1) + win32shellcon = __import__('win32com.shell.shellcon', globals(), locals(), [], -1) + + FSCTL_LOCK_VOLUME = 0x0090018 + FSCTL_DISMOUNT_VOLUME = 0x00090020 + IOCTL_STORAGE_MEDIA_REMOVAL = 0x002D4804 + IOCTL_STORAGE_EJECT_MEDIA = 0x002D4808 + + for x in ('_main_prefix', '_card_a_prefix', '_card_b_prefix'): + x = getattr(self, x, None) + if x is not None: + vol = win32file.CreateFile(x, win32con.GENERIC_READ | win32con.GENERIC_WRITE, win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE, None, win32con.OPEN_EXISTING, 0, None) + try: + win32file.DeviceIoControl(vol, FSCTL_LOCK_VOLUME, '', 0, None) + win32file.DeviceIoControl(vol, FSCTL_DISMOUNT_VOLUME, '', 0, None) + win32file.DeviceIoControl(vol, IOCTL_STORAGE_MEDIA_REMOVAL, struct.pack('B', 0), 0, None) + win32file.DeviceIoControl(vol, IOCTL_STORAGE_EJECT_MEDIA, '', 0, None) + time.sleep(2) + win32shell.SHChangeNotify(win32shellcon.SHCNE_DRIVEREMOVED, win32shellcon.SHCNF_PATH, x) + finally: + win32file.CloseHandle(vol) def eject_osx(self): for x in ('_main_prefix', '_card_a_prefix', '_card_b_prefix'): From ff42c7b8baa95c656eca9f7c296457a3ccdc7a42 Mon Sep 17 00:00:00 2001 From: John Schember Date: Fri, 5 Jun 2009 20:44:46 -0400 Subject: [PATCH 3/4] Fix opts variable in txt output. --- src/calibre/ebooks/txt/output.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/ebooks/txt/output.py b/src/calibre/ebooks/txt/output.py index ffb4d6fee5..6cb854df10 100644 --- a/src/calibre/ebooks/txt/output.py +++ b/src/calibre/ebooks/txt/output.py @@ -46,7 +46,7 @@ class TXTOutput(OutputFormatPlugin): out_stream.seek(0) out_stream.truncate() - out_stream.write(txt.encode(self.opts.output_encoding, 'replace')) + out_stream.write(txt.encode(opts.output_encoding, 'replace')) if close: out_stream.close() From cef6b55971b712607bfd7c58b26c4863c18c505c Mon Sep 17 00:00:00 2001 From: John Schember Date: Fri, 5 Jun 2009 20:46:59 -0400 Subject: [PATCH 4/4] Fix opts variable in pml output. --- src/calibre/ebooks/pml/output.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/ebooks/pml/output.py b/src/calibre/ebooks/pml/output.py index deace8df79..851a89db56 100644 --- a/src/calibre/ebooks/pml/output.py +++ b/src/calibre/ebooks/pml/output.py @@ -40,7 +40,7 @@ class PMLOutput(OutputFormatPlugin): pmlmlizer = PMLMLizer(ignore_tables=opts.linearize_tables) content = pmlmlizer.extract_content(oeb_book, opts) with open(os.path.join(tdir, 'index.pml'), 'wb') as out: - out.write(content.encode(self.opts.output_encoding, 'replace')) + out.write(content.encode(opts.output_encoding, 'replace')) self.write_images(oeb_book.manifest, tdir)