mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Fix #7834 (Preselect right formats for "Send to device")
This commit is contained in:
commit
e86ead4e11
@ -166,6 +166,8 @@ class RegexEdit(QWidget, Ui_Edit):
|
|||||||
|
|
||||||
def builder(self):
|
def builder(self):
|
||||||
bld = RegexBuilder(self.db, self.book_id, self.edit.text(), self)
|
bld = RegexBuilder(self.db, self.book_id, self.edit.text(), self)
|
||||||
|
if bld.cancelled:
|
||||||
|
return
|
||||||
if bld.exec_() == bld.Accepted:
|
if bld.exec_() == bld.Accepted:
|
||||||
self.edit.setText(bld.regex.text())
|
self.edit.setText(bld.regex.text())
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ from calibre.customize.ui import available_input_formats, available_output_forma
|
|||||||
device_plugins
|
device_plugins
|
||||||
from calibre.devices.interface import DevicePlugin
|
from calibre.devices.interface import DevicePlugin
|
||||||
from calibre.devices.errors import UserFeedback, OpenFeedback
|
from calibre.devices.errors import UserFeedback, OpenFeedback
|
||||||
from calibre.gui2.dialogs.choose_format import ChooseFormatDialog
|
from calibre.gui2.dialogs.choose_format_device import ChooseFormatDeviceDialog
|
||||||
from calibre.utils.ipc.job import BaseJob
|
from calibre.utils.ipc.job import BaseJob
|
||||||
from calibre.devices.scanner import DeviceScanner
|
from calibre.devices.scanner import DeviceScanner
|
||||||
from calibre.gui2 import config, error_dialog, Dispatcher, dynamic, \
|
from calibre.gui2 import config, error_dialog, Dispatcher, dynamic, \
|
||||||
@ -826,8 +826,24 @@ class DeviceMixin(object): # {{{
|
|||||||
|
|
||||||
fmt = None
|
fmt = None
|
||||||
if specific:
|
if specific:
|
||||||
d = ChooseFormatDialog(self, _('Choose format to send to device'),
|
formats = []
|
||||||
self.device_manager.device.settings().format_map)
|
aval_out_formats = available_output_formats()
|
||||||
|
format_count = {}
|
||||||
|
for row in rows:
|
||||||
|
fmts = self.library_view.model().db.formats(row.row())
|
||||||
|
if fmts:
|
||||||
|
for f in fmts.split(','):
|
||||||
|
f = f.lower()
|
||||||
|
if format_count.has_key(f):
|
||||||
|
format_count[f] += 1
|
||||||
|
else:
|
||||||
|
format_count[f] = 1
|
||||||
|
for f in self.device_manager.device.settings().format_map:
|
||||||
|
if f in format_count.keys():
|
||||||
|
formats.append((f, _('%i of %i Books' % (format_count[f], len(rows))), True if f in aval_out_formats else False))
|
||||||
|
elif f in aval_out_formats:
|
||||||
|
formats.append((f, _('0 of %i Books' % len(rows)), True))
|
||||||
|
d = ChooseFormatDeviceDialog(self, _('Choose format to send to device'), formats)
|
||||||
if d.exec_() != QDialog.Accepted:
|
if d.exec_() != QDialog.Accepted:
|
||||||
return
|
return
|
||||||
if d.format():
|
if d.format():
|
||||||
|
53
src/calibre/gui2/dialogs/choose_format_device.py
Normal file
53
src/calibre/gui2/dialogs/choose_format_device.py
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
__license__ = 'GPL v3'
|
||||||
|
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
|
||||||
|
|
||||||
|
from PyQt4.Qt import QDialog, QTreeWidgetItem, QIcon, SIGNAL
|
||||||
|
|
||||||
|
from calibre.gui2 import file_icon_provider
|
||||||
|
from calibre.gui2.dialogs.choose_format_device_ui import Ui_ChooseFormatDeviceDialog
|
||||||
|
|
||||||
|
class ChooseFormatDeviceDialog(QDialog, Ui_ChooseFormatDeviceDialog):
|
||||||
|
|
||||||
|
def __init__(self, window, msg, formats):
|
||||||
|
'''
|
||||||
|
formats is a list of tuples: [(format, exists, convertible)].
|
||||||
|
format: Lower case format identifier. E.G. mobi
|
||||||
|
exists: String representing the number of books that
|
||||||
|
exist in the format.
|
||||||
|
convertible: True if the format is a convertible format.
|
||||||
|
formats should be ordered in the device's preferred format ordering.
|
||||||
|
'''
|
||||||
|
QDialog.__init__(self, window)
|
||||||
|
Ui_ChooseFormatDeviceDialog.__init__(self)
|
||||||
|
self.setupUi(self)
|
||||||
|
self.connect(self.formats, SIGNAL('activated(QModelIndex)'),
|
||||||
|
self.activated_slot)
|
||||||
|
|
||||||
|
self.msg.setText(msg)
|
||||||
|
for i, (format, exists, convertible) in enumerate(formats):
|
||||||
|
t_item = QTreeWidgetItem()
|
||||||
|
t_item.setIcon(0, file_icon_provider().icon_from_ext(format.lower()))
|
||||||
|
t_item.setText(0, format.upper())
|
||||||
|
t_item.setText(1, exists)
|
||||||
|
if convertible:
|
||||||
|
t_item.setIcon(2, QIcon(I('ok.png')))
|
||||||
|
self.formats.addTopLevelItem(t_item)
|
||||||
|
if i == 0:
|
||||||
|
self.formats.setCurrentItem(t_item)
|
||||||
|
t_item.setSelected(True)
|
||||||
|
self.formats.resizeColumnToContents(2)
|
||||||
|
self.formats.resizeColumnToContents(1)
|
||||||
|
self.formats.resizeColumnToContents(0)
|
||||||
|
self.formats.header().resizeSection(0, self.formats.header().sectionSize(0) * 2)
|
||||||
|
self._format = None
|
||||||
|
|
||||||
|
def activated_slot(self, *args):
|
||||||
|
self.accept()
|
||||||
|
|
||||||
|
def format(self):
|
||||||
|
return self._format
|
||||||
|
|
||||||
|
def accept(self):
|
||||||
|
self._format = unicode(self.formats.currentItem().text(0))
|
||||||
|
return QDialog.accept(self)
|
||||||
|
|
111
src/calibre/gui2/dialogs/choose_format_device.ui
Normal file
111
src/calibre/gui2/dialogs/choose_format_device.ui
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>ChooseFormatDeviceDialog</class>
|
||||||
|
<widget class="QDialog" name="ChooseFormatDeviceDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>507</width>
|
||||||
|
<height>377</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Choose Format</string>
|
||||||
|
</property>
|
||||||
|
<property name="windowIcon">
|
||||||
|
<iconset resource="../../../../resources/images.qrc">
|
||||||
|
<normaloff>:/images/mimetypes/unknown.png</normaloff>:/images/mimetypes/unknown.png</iconset>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="msg">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QTreeWidget" name="formats">
|
||||||
|
<property name="alternatingRowColors">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="iconSize">
|
||||||
|
<size>
|
||||||
|
<width>64</width>
|
||||||
|
<height>64</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="allColumnsShowFocus">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>Format</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>Existing</string>
|
||||||
|
</property>
|
||||||
|
<property name="textAlignment">
|
||||||
|
<set>AlignLeft|AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>Convertible</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources>
|
||||||
|
<include location="../../../../resources/images.qrc"/>
|
||||||
|
</resources>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>ChooseFormatDeviceDialog</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>248</x>
|
||||||
|
<y>254</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>157</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>ChooseFormatDeviceDialog</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>316</x>
|
||||||
|
<y>260</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>286</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
Loading…
x
Reference in New Issue
Block a user