mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Make the selection of db fields to add to the CSV/xML catalog in the GUI more intuitive
This commit is contained in:
parent
223e115f42
commit
dea55f5f09
@ -9,7 +9,7 @@ __docformat__ = 'restructuredtext en'
|
||||
|
||||
from calibre.gui2 import gprefs
|
||||
from calibre.gui2.catalog.catalog_csv_xml_ui import Ui_Form
|
||||
from PyQt4.Qt import QWidget
|
||||
from PyQt4.Qt import QWidget, QListWidgetItem
|
||||
|
||||
class PluginWidget(QWidget, Ui_Form):
|
||||
|
||||
@ -20,23 +20,32 @@ class PluginWidget(QWidget, Ui_Form):
|
||||
def __init__(self, parent=None):
|
||||
QWidget.__init__(self, parent)
|
||||
self.setupUi(self)
|
||||
from calibre.library.catalog import FIELDS
|
||||
self.all_fields = []
|
||||
for x in FIELDS:
|
||||
if x != 'all':
|
||||
self.all_fields.append(x)
|
||||
QListWidgetItem(x, self.db_fields)
|
||||
|
||||
def initialize(self, name):
|
||||
self.name = name
|
||||
fields = gprefs.get(name+'_db_fields', self.all_fields)
|
||||
# Restore the activated fields from last use
|
||||
for x in range(self.db_fields.count()):
|
||||
pref = '%s_db_fields_%s' % (self.name, self.db_fields.item(x).text())
|
||||
activated = gprefs[pref] if pref in gprefs else False
|
||||
self.db_fields.item(x).setSelected(activated)
|
||||
item = self.db_fields.item(x)
|
||||
item.setSelected(unicode(item.text()) in fields)
|
||||
|
||||
def options(self):
|
||||
# Save the currently activated fields
|
||||
fields = []
|
||||
for x in range(self.db_fields.count()):
|
||||
pref = '%s_db_fields_%s' % (self.name, self.db_fields.item(x).text())
|
||||
gprefs[pref] = self.db_fields.item(x).isSelected()
|
||||
item = self.db_fields.item(x)
|
||||
if item.isSelected():
|
||||
fields.append(unicode(item.text()))
|
||||
gprefs.set(self.name+'_db_fields', fields)
|
||||
|
||||
# Return a dictionary with current options for this widget
|
||||
if len(self.db_fields.selectedItems()):
|
||||
return {'fields':[str(item.text()) for item in self.db_fields.selectedItems()]}
|
||||
return {'fields':[unicode(item.text()) for item in self.db_fields.selectedItems()]}
|
||||
else:
|
||||
return {'fields':['all']}
|
||||
|
@ -34,91 +34,6 @@
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::MultiSelection</enum>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>author_sort</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>authors</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>comments</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>cover</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>formats</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>id</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>isbn</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>pubdate</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>publisher</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>rating</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>series_index</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>series</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>size</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>tags</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>timestamp</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>title</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>uuid</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="geometry">
|
||||
|
@ -17,6 +17,7 @@ from calibre.customize.ui import catalog_plugins
|
||||
|
||||
class Catalog(QDialog, Ui_Dialog):
|
||||
''' Catalog Dialog builder'''
|
||||
widgets = []
|
||||
|
||||
def __init__(self, parent, dbspec, ids):
|
||||
import re, cStringIO
|
||||
|
@ -2,6 +2,11 @@ import os
|
||||
|
||||
from calibre.customize import CatalogPlugin
|
||||
|
||||
FIELDS = ['all', 'author_sort', 'authors', 'comments',
|
||||
'cover', 'formats', 'id', 'isbn', 'pubdate', 'publisher', 'rating',
|
||||
'series_index', 'series', 'size', 'tags', 'timestamp', 'title',
|
||||
'uuid']
|
||||
|
||||
class CSV_XML(CatalogPlugin):
|
||||
'CSV/XML catalog generator'
|
||||
|
||||
@ -22,11 +27,9 @@ class CSV_XML(CatalogPlugin):
|
||||
dest = 'fields',
|
||||
help = _('The fields to output when cataloging books in the '
|
||||
'database. Should be a comma-separated list of fields.\n'
|
||||
'Available fields: all, author_sort, authors, comments, '
|
||||
'cover, formats, id, isbn, pubdate, publisher, rating, '
|
||||
'series_index, series, size, tags, timestamp, title, uuid.\n'
|
||||
"Default: '%default'\n"
|
||||
"Applies to: CSV, XML output formats")),
|
||||
'Available fields: %s.\n'
|
||||
"Default: '%%default'\n"
|
||||
"Applies to: CSV, XML output formats")%', '.join(FIELDS)),
|
||||
|
||||
Option('--sort-by',
|
||||
default = 'id',
|
||||
|
Loading…
x
Reference in New Issue
Block a user