mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Mkae filename pattern used to guess metadata configurable
This commit is contained in:
parent
dd3de8a127
commit
baef59dce7
@ -55,12 +55,21 @@ def set_metadata(stream, mi, stream_type='lrf'):
|
|||||||
elif stream_type == 'rtf':
|
elif stream_type == 'rtf':
|
||||||
set_rtf_metadata(stream, mi)
|
set_rtf_metadata(stream, mi)
|
||||||
|
|
||||||
_filename_pat = re.compile(r'(?P<title>.+) - (?P<author>[^_]+)')
|
_filename_pat = re.compile(ur'(?P<title>.+) - (?P<author>[^_]+)')
|
||||||
|
|
||||||
def metadata_from_filename(name):
|
def get_filename_pat():
|
||||||
|
return _filename_pat.pattern
|
||||||
|
|
||||||
|
def set_filename_pat(pat):
|
||||||
|
global _filename_pat
|
||||||
|
_filename_pat = re.compile(pat)
|
||||||
|
|
||||||
|
def metadata_from_filename(name, pat=None):
|
||||||
name = os.path.splitext(name)[0]
|
name = os.path.splitext(name)[0]
|
||||||
mi = MetaInformation(None, None)
|
mi = MetaInformation(None, None)
|
||||||
match = _filename_pat.search(name)
|
if pat is None:
|
||||||
|
pat = _filename_pat
|
||||||
|
match = pat.search(name)
|
||||||
if match:
|
if match:
|
||||||
try:
|
try:
|
||||||
mi.title = match.group('title')
|
mi.title = match.group('title')
|
||||||
@ -79,6 +88,15 @@ def metadata_from_filename(name):
|
|||||||
mi.authors = authors
|
mi.authors = authors
|
||||||
except IndexError:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
|
try:
|
||||||
|
mi.series = match.group('series')
|
||||||
|
except IndexError:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
si = match.group('series_index')
|
||||||
|
mi.series_index = int(si)
|
||||||
|
except IndexError, ValueError:
|
||||||
|
pass
|
||||||
if not mi.title:
|
if not mi.title:
|
||||||
mi.title = name
|
mi.title = name
|
||||||
return mi
|
return mi
|
||||||
|
@ -14,12 +14,13 @@
|
|||||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from PyQt4.QtGui import QDialog, QMessageBox, QListWidgetItem
|
from PyQt4.QtGui import QDialog, QMessageBox, QListWidgetItem, QVBoxLayout
|
||||||
from PyQt4.QtCore import QSettings, QVariant, SIGNAL, QStringList, QTimer, Qt
|
from PyQt4.QtCore import QSettings, QVariant, SIGNAL, QStringList, QTimer, Qt
|
||||||
|
|
||||||
from libprs500 import islinux
|
from libprs500 import islinux
|
||||||
from libprs500.gui2.dialogs.config_ui import Ui_Dialog
|
from libprs500.gui2.dialogs.config_ui import Ui_Dialog
|
||||||
from libprs500.gui2 import qstring_to_unicode, choose_dir, error_dialog
|
from libprs500.gui2 import qstring_to_unicode, choose_dir, error_dialog
|
||||||
|
from libprs500.gui2.widgets import FilenamePattern
|
||||||
|
|
||||||
class ConfigDialog(QDialog, Ui_Dialog):
|
class ConfigDialog(QDialog, Ui_Dialog):
|
||||||
|
|
||||||
@ -61,6 +62,11 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
|||||||
item.setCheckState(Qt.Unchecked)
|
item.setCheckState(Qt.Unchecked)
|
||||||
else:
|
else:
|
||||||
item.setCheckState(Qt.Checked)
|
item.setCheckState(Qt.Checked)
|
||||||
|
|
||||||
|
self.mbl = QVBoxLayout()
|
||||||
|
self.metadata_box.setLayout(self.mbl)
|
||||||
|
self.filename_pattern = FilenamePattern(None)
|
||||||
|
self.mbl.addChildWidget(self.filename_pattern)
|
||||||
|
|
||||||
|
|
||||||
def compact(self, toggled):
|
def compact(self, toggled):
|
||||||
@ -88,7 +94,10 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
|||||||
settings.setValue('network timeout', QVariant(self.timeout.value()))
|
settings.setValue('network timeout', QVariant(self.timeout.value()))
|
||||||
path = qstring_to_unicode(self.location.text())
|
path = qstring_to_unicode(self.location.text())
|
||||||
self.final_columns = [self.columns.item(i).checkState() == Qt.Checked for i in range(self.columns.count())]
|
self.final_columns = [self.columns.item(i).checkState() == Qt.Checked for i in range(self.columns.count())]
|
||||||
|
|
||||||
|
pattern = self.filename_pattern.commit()
|
||||||
|
settings.setValue('filename pattern', QVariant(pattern))
|
||||||
|
|
||||||
if not path or not os.path.exists(path) or not os.path.isdir(path):
|
if not path or not os.path.exists(path) or not os.path.isdir(path):
|
||||||
d = error_dialog(self, _('Invalid database location'), _('Invalid database location ')+path+_('<br>Must be a directory.'))
|
d = error_dialog(self, _('Invalid database location'), _('Invalid database location ')+path+_('<br>Must be a directory.'))
|
||||||
d.exec_()
|
d.exec_()
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>451</width>
|
<width>667</width>
|
||||||
<height>507</height>
|
<height>630</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle" >
|
<property name="windowTitle" >
|
||||||
@ -15,275 +15,360 @@
|
|||||||
<property name="windowIcon" >
|
<property name="windowIcon" >
|
||||||
<iconset resource="../images.qrc" >:/images/config.svg</iconset>
|
<iconset resource="../images.qrc" >:/images/config.svg</iconset>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" >
|
<layout class="QGridLayout" >
|
||||||
<item>
|
<item row="0" column="0" >
|
||||||
<widget class="QStackedWidget" name="stackedWidget" >
|
<layout class="QHBoxLayout" >
|
||||||
<widget class="QWidget" name="page" >
|
<item>
|
||||||
<layout class="QGridLayout" >
|
<widget class="QListWidget" name="listWidget" >
|
||||||
<item row="0" column="0" >
|
<property name="sizePolicy" >
|
||||||
<layout class="QVBoxLayout" >
|
<sizepolicy vsizetype="Expanding" hsizetype="Minimum" >
|
||||||
<item>
|
<horstretch>0</horstretch>
|
||||||
<widget class="QLabel" name="label" >
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize" >
|
||||||
|
<size>
|
||||||
|
<width>100</width>
|
||||||
|
<height>16777215</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="font" >
|
||||||
|
<font>
|
||||||
|
<weight>75</weight>
|
||||||
|
<bold>true</bold>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="iconSize" >
|
||||||
|
<size>
|
||||||
|
<width>32</width>
|
||||||
|
<height>32</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="movement" >
|
||||||
|
<enum>QListView::Static</enum>
|
||||||
|
</property>
|
||||||
|
<property name="flow" >
|
||||||
|
<enum>QListView::TopToBottom</enum>
|
||||||
|
</property>
|
||||||
|
<property name="isWrapping" stdset="0" >
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="gridSize" >
|
||||||
|
<size>
|
||||||
|
<width>80</width>
|
||||||
|
<height>80</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="viewMode" >
|
||||||
|
<enum>QListView::IconMode</enum>
|
||||||
|
</property>
|
||||||
|
<property name="uniformItemSizes" >
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="currentRow" >
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<property name="text" >
|
||||||
|
<string>Basic</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon" >
|
||||||
|
<iconset resource="../images.qrc" >:/images/metadata.svg</iconset>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text" >
|
||||||
|
<string>Advanced</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon" >
|
||||||
|
<iconset resource="../images.qrc" >:/images/view.svg</iconset>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QStackedWidget" name="stackedWidget" >
|
||||||
|
<property name="currentIndex" >
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="page" >
|
||||||
|
<layout class="QGridLayout" >
|
||||||
|
<item row="0" column="0" >
|
||||||
|
<layout class="QVBoxLayout" >
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>&Location of books database (library1.db)</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy" >
|
||||||
|
<cstring>location</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" >
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="location" />
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="browse_button" >
|
||||||
|
<property name="toolTip" >
|
||||||
|
<string>Browse for the new database location</string>
|
||||||
|
</property>
|
||||||
|
<property name="text" >
|
||||||
|
<string>...</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon" >
|
||||||
|
<iconset resource="../images.qrc" >:/images/mimetypes/dir.svg</iconset>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0" >
|
||||||
|
<widget class="QCheckBox" name="roman_numerals" >
|
||||||
<property name="text" >
|
<property name="text" >
|
||||||
<string>&Location of books database (library1.db)</string>
|
<string>Use &Roman numerals for series number</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="buddy" >
|
<property name="checked" >
|
||||||
<cstring>location</cstring>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item row="2" column="0" >
|
||||||
<layout class="QHBoxLayout" >
|
<layout class="QHBoxLayout" >
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="location" />
|
<widget class="QLabel" name="label_2" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>Default network &timeout:</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy" >
|
||||||
|
<cstring>timeout</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QToolButton" name="browse_button" >
|
<widget class="QSpinBox" name="timeout" >
|
||||||
<property name="toolTip" >
|
<property name="toolTip" >
|
||||||
<string>Browse for the new database location</string>
|
<string>Set the default timeout for network fetches (i.e. anytime libprs500 foes out to the internet to get information)</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="text" >
|
<property name="suffix" >
|
||||||
<string>...</string>
|
<string> seconds</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon" >
|
<property name="minimum" >
|
||||||
<iconset resource="../images.qrc" >:/images/mimetypes/dir.svg</iconset>
|
<number>2</number>
|
||||||
|
</property>
|
||||||
|
<property name="maximum" >
|
||||||
|
<number>120</number>
|
||||||
|
</property>
|
||||||
|
<property name="value" >
|
||||||
|
<number>5</number>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
<item row="3" column="0" >
|
||||||
</item>
|
<layout class="QHBoxLayout" >
|
||||||
<item row="1" column="0" >
|
<item>
|
||||||
<widget class="QCheckBox" name="roman_numerals" >
|
<widget class="QLabel" name="label_3" >
|
||||||
<property name="text" >
|
<property name="text" >
|
||||||
<string>Use &Roman numerals for series number</string>
|
<string>&Priority for conversion jobs:</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="checked" >
|
<property name="buddy" >
|
||||||
<bool>true</bool>
|
<cstring>priority</cstring>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0" >
|
<item>
|
||||||
<layout class="QHBoxLayout" >
|
<widget class="QComboBox" name="priority" />
|
||||||
<item>
|
</item>
|
||||||
<widget class="QLabel" name="label_2" >
|
</layout>
|
||||||
<property name="text" >
|
|
||||||
<string>Default network &timeout:</string>
|
|
||||||
</property>
|
|
||||||
<property name="buddy" >
|
|
||||||
<cstring>timeout</cstring>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item row="6" column="0" >
|
||||||
<widget class="QSpinBox" name="timeout" >
|
<widget class="QGroupBox" name="dirs_box" >
|
||||||
<property name="toolTip" >
|
<property name="title" >
|
||||||
<string>Set the default timeout for network fetches (i.e. anytime libprs500 foes out to the internet to get information)</string>
|
<string>Frequently used directories</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="suffix" >
|
<layout class="QGridLayout" >
|
||||||
<string> seconds</string>
|
<item row="0" column="0" >
|
||||||
</property>
|
<layout class="QHBoxLayout" >
|
||||||
<property name="minimum" >
|
|
||||||
<number>2</number>
|
|
||||||
</property>
|
|
||||||
<property name="maximum" >
|
|
||||||
<number>120</number>
|
|
||||||
</property>
|
|
||||||
<property name="value" >
|
|
||||||
<number>5</number>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="0" >
|
|
||||||
<layout class="QHBoxLayout" >
|
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="label_3" >
|
|
||||||
<property name="text" >
|
|
||||||
<string>&Priority for conversion jobs:</string>
|
|
||||||
</property>
|
|
||||||
<property name="buddy" >
|
|
||||||
<cstring>priority</cstring>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QComboBox" name="priority" />
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="0" >
|
|
||||||
<layout class="QHBoxLayout" >
|
|
||||||
<item>
|
|
||||||
<spacer>
|
|
||||||
<property name="orientation" >
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" >
|
|
||||||
<size>
|
|
||||||
<width>40</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QToolButton" name="compact_button" >
|
|
||||||
<property name="toolTip" >
|
|
||||||
<string>Free unused diskspace from the database</string>
|
|
||||||
</property>
|
|
||||||
<property name="text" >
|
|
||||||
<string>&Compact database</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<spacer>
|
|
||||||
<property name="orientation" >
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" >
|
|
||||||
<size>
|
|
||||||
<width>40</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item row="6" column="0" >
|
|
||||||
<widget class="QGroupBox" name="dirs_box" >
|
|
||||||
<property name="title" >
|
|
||||||
<string>Frequently used directories</string>
|
|
||||||
</property>
|
|
||||||
<layout class="QGridLayout" >
|
|
||||||
<item row="0" column="0" >
|
|
||||||
<layout class="QHBoxLayout" >
|
|
||||||
<item>
|
|
||||||
<widget class="QListWidget" name="directory_list" >
|
|
||||||
<property name="alternatingRowColors" >
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="iconSize" >
|
|
||||||
<size>
|
|
||||||
<width>22</width>
|
|
||||||
<height>22</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<layout class="QVBoxLayout" >
|
|
||||||
<item>
|
<item>
|
||||||
<spacer>
|
<widget class="QListWidget" name="directory_list" >
|
||||||
<property name="orientation" >
|
<property name="alternatingRowColors" >
|
||||||
<enum>Qt::Vertical</enum>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" >
|
<property name="iconSize" >
|
||||||
<size>
|
<size>
|
||||||
<width>20</width>
|
<width>22</width>
|
||||||
<height>40</height>
|
<height>22</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QToolButton" name="add_button" >
|
|
||||||
<property name="toolTip" >
|
|
||||||
<string>Add a directory to the frequently used directories list</string>
|
|
||||||
</property>
|
|
||||||
<property name="text" >
|
|
||||||
<string>...</string>
|
|
||||||
</property>
|
|
||||||
<property name="icon" >
|
|
||||||
<iconset resource="../images.qrc" >:/images/plus.svg</iconset>
|
|
||||||
</property>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer>
|
<layout class="QVBoxLayout" >
|
||||||
<property name="orientation" >
|
<item>
|
||||||
<enum>Qt::Vertical</enum>
|
<spacer>
|
||||||
</property>
|
<property name="orientation" >
|
||||||
<property name="sizeHint" >
|
<enum>Qt::Vertical</enum>
|
||||||
<size>
|
</property>
|
||||||
<width>20</width>
|
<property name="sizeHint" >
|
||||||
<height>40</height>
|
<size>
|
||||||
</size>
|
<width>20</width>
|
||||||
</property>
|
<height>40</height>
|
||||||
</spacer>
|
</size>
|
||||||
</item>
|
</property>
|
||||||
<item>
|
</spacer>
|
||||||
<widget class="QToolButton" name="remove_button" >
|
</item>
|
||||||
<property name="toolTip" >
|
<item>
|
||||||
<string>Remove a directory from the frequently used directories list</string>
|
<widget class="QToolButton" name="add_button" >
|
||||||
</property>
|
<property name="toolTip" >
|
||||||
<property name="text" >
|
<string>Add a directory to the frequently used directories list</string>
|
||||||
<string>...</string>
|
</property>
|
||||||
</property>
|
<property name="text" >
|
||||||
<property name="icon" >
|
<string>...</string>
|
||||||
<iconset resource="../images.qrc" >:/images/list_remove.svg</iconset>
|
</property>
|
||||||
</property>
|
<property name="icon" >
|
||||||
</widget>
|
<iconset resource="../images.qrc" >:/images/plus.svg</iconset>
|
||||||
</item>
|
</property>
|
||||||
<item>
|
</widget>
|
||||||
<spacer>
|
</item>
|
||||||
<property name="orientation" >
|
<item>
|
||||||
<enum>Qt::Vertical</enum>
|
<spacer>
|
||||||
</property>
|
<property name="orientation" >
|
||||||
<property name="sizeHint" >
|
<enum>Qt::Vertical</enum>
|
||||||
<size>
|
</property>
|
||||||
<width>20</width>
|
<property name="sizeHint" >
|
||||||
<height>40</height>
|
<size>
|
||||||
</size>
|
<width>20</width>
|
||||||
</property>
|
<height>40</height>
|
||||||
</spacer>
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="remove_button" >
|
||||||
|
<property name="toolTip" >
|
||||||
|
<string>Remove a directory from the frequently used directories list</string>
|
||||||
|
</property>
|
||||||
|
<property name="text" >
|
||||||
|
<string>...</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon" >
|
||||||
|
<iconset resource="../images.qrc" >:/images/list_remove.svg</iconset>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer>
|
||||||
|
<property name="orientation" >
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" >
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</widget>
|
||||||
</layout>
|
</item>
|
||||||
</widget>
|
<item row="7" column="0" >
|
||||||
</item>
|
<spacer>
|
||||||
<item row="7" column="0" >
|
<property name="orientation" >
|
||||||
<spacer>
|
<enum>Qt::Vertical</enum>
|
||||||
<property name="orientation" >
|
</property>
|
||||||
<enum>Qt::Vertical</enum>
|
<property name="sizeHint" >
|
||||||
</property>
|
<size>
|
||||||
<property name="sizeHint" >
|
<width>392</width>
|
||||||
<size>
|
<height>16</height>
|
||||||
<width>392</width>
|
</size>
|
||||||
<height>16</height>
|
</property>
|
||||||
</size>
|
</spacer>
|
||||||
</property>
|
</item>
|
||||||
</spacer>
|
<item row="5" column="0" >
|
||||||
</item>
|
<widget class="QGroupBox" name="groupBox" >
|
||||||
<item row="5" column="0" >
|
<property name="title" >
|
||||||
<widget class="QGroupBox" name="groupBox" >
|
<string>Select visible &columns in library view</string>
|
||||||
<property name="title" >
|
</property>
|
||||||
<string>Select visible &columns in library view</string>
|
<layout class="QGridLayout" >
|
||||||
</property>
|
<item row="0" column="0" >
|
||||||
<layout class="QGridLayout" >
|
<widget class="QListWidget" name="columns" >
|
||||||
<item row="0" column="0" >
|
<property name="selectionMode" >
|
||||||
<widget class="QListWidget" name="columns" >
|
<enum>QAbstractItemView::NoSelection</enum>
|
||||||
<property name="selectionMode" >
|
</property>
|
||||||
<enum>QAbstractItemView::NoSelection</enum>
|
</widget>
|
||||||
</property>
|
</item>
|
||||||
</widget>
|
</layout>
|
||||||
</item>
|
</widget>
|
||||||
</layout>
|
</item>
|
||||||
</widget>
|
</layout>
|
||||||
</item>
|
</widget>
|
||||||
</layout>
|
<widget class="QWidget" name="page_2" >
|
||||||
</widget>
|
<layout class="QVBoxLayout" >
|
||||||
<widget class="QWidget" name="page_2" />
|
<item>
|
||||||
</widget>
|
<layout class="QHBoxLayout" >
|
||||||
|
<item>
|
||||||
|
<spacer>
|
||||||
|
<property name="orientation" >
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" >
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="compact_button" >
|
||||||
|
<property name="toolTip" >
|
||||||
|
<string>Free unused diskspace from the database</string>
|
||||||
|
</property>
|
||||||
|
<property name="text" >
|
||||||
|
<string>&Compact database</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer>
|
||||||
|
<property name="orientation" >
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" >
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="metadata_box" >
|
||||||
|
<property name="title" >
|
||||||
|
<string>&Metadata from file name</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item row="1" column="0" >
|
||||||
<widget class="QDialogButtonBox" name="buttonBox" >
|
<widget class="QDialogButtonBox" name="buttonBox" >
|
||||||
<property name="orientation" >
|
<property name="orientation" >
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
@ -306,8 +391,8 @@
|
|||||||
<slot>accept()</slot>
|
<slot>accept()</slot>
|
||||||
<hints>
|
<hints>
|
||||||
<hint type="sourcelabel" >
|
<hint type="sourcelabel" >
|
||||||
<x>227</x>
|
<x>231</x>
|
||||||
<y>279</y>
|
<y>502</y>
|
||||||
</hint>
|
</hint>
|
||||||
<hint type="destinationlabel" >
|
<hint type="destinationlabel" >
|
||||||
<x>157</x>
|
<x>157</x>
|
||||||
@ -322,8 +407,8 @@
|
|||||||
<slot>reject()</slot>
|
<slot>reject()</slot>
|
||||||
<hints>
|
<hints>
|
||||||
<hint type="sourcelabel" >
|
<hint type="sourcelabel" >
|
||||||
<x>295</x>
|
<x>299</x>
|
||||||
<y>285</y>
|
<y>502</y>
|
||||||
</hint>
|
</hint>
|
||||||
<hint type="destinationlabel" >
|
<hint type="destinationlabel" >
|
||||||
<x>286</x>
|
<x>286</x>
|
||||||
@ -331,5 +416,21 @@
|
|||||||
</hint>
|
</hint>
|
||||||
</hints>
|
</hints>
|
||||||
</connection>
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>listWidget</sender>
|
||||||
|
<signal>currentRowChanged(int)</signal>
|
||||||
|
<receiver>stackedWidget</receiver>
|
||||||
|
<slot>setCurrentIndex(int)</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel" >
|
||||||
|
<x>176</x>
|
||||||
|
<y>184</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel" >
|
||||||
|
<x>294</x>
|
||||||
|
<y>9</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
</connections>
|
</connections>
|
||||||
</ui>
|
</ui>
|
||||||
|
182
src/libprs500/gui2/filename_pattern.ui
Normal file
182
src/libprs500/gui2/filename_pattern.ui
Normal file
@ -0,0 +1,182 @@
|
|||||||
|
<ui version="4.0" >
|
||||||
|
<class>Form</class>
|
||||||
|
<widget class="QWidget" name="Form" >
|
||||||
|
<property name="geometry" >
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>498</width>
|
||||||
|
<height>452</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle" >
|
||||||
|
<string>Form</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" >
|
||||||
|
<item>
|
||||||
|
<spacer>
|
||||||
|
<property name="orientation" >
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" >
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>15</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label" >
|
||||||
|
<property name="text" >
|
||||||
|
<string><p>Set a regular expression pattern to use when trying to guess ebook metadata from filenames. <p>A <a href="http://docs.python.org/lib/re-syntax.html">reference</a> on the syntax of regular expressions is available.<p>Use the <b>Test</b> functionality below to test you regular expression on a few sample filenames.</string>
|
||||||
|
</property>
|
||||||
|
<property name="textFormat" >
|
||||||
|
<enum>Qt::RichText</enum>
|
||||||
|
</property>
|
||||||
|
<property name="wordWrap" >
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="openExternalLinks" >
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="groupBox" >
|
||||||
|
<property name="title" >
|
||||||
|
<string>Regular &expression</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" >
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="re" />
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="groupBox_2" >
|
||||||
|
<property name="title" >
|
||||||
|
<string>&Test</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" >
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" >
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" >
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_2" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>File &name:</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy" >
|
||||||
|
<cstring>filename</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="filename" />
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="test_button" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>Test</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QGridLayout" >
|
||||||
|
<item row="0" column="0" >
|
||||||
|
<widget class="QLabel" name="label_3" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>Title:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1" >
|
||||||
|
<widget class="QLineEdit" name="title" >
|
||||||
|
<property name="toolTip" >
|
||||||
|
<string>Regular expression group name (?P<title>)</string>
|
||||||
|
</property>
|
||||||
|
<property name="text" >
|
||||||
|
<string>No match</string>
|
||||||
|
</property>
|
||||||
|
<property name="readOnly" >
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0" >
|
||||||
|
<widget class="QLabel" name="label_4" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>Authors:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1" >
|
||||||
|
<widget class="QLineEdit" name="authors" >
|
||||||
|
<property name="toolTip" >
|
||||||
|
<string>Regular expression group name (?P<authors>)</string>
|
||||||
|
</property>
|
||||||
|
<property name="text" >
|
||||||
|
<string>No match</string>
|
||||||
|
</property>
|
||||||
|
<property name="readOnly" >
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0" >
|
||||||
|
<widget class="QLabel" name="label_5" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>Series:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1" >
|
||||||
|
<widget class="QLineEdit" name="series" >
|
||||||
|
<property name="toolTip" >
|
||||||
|
<string>Regular expression group name (?P<series>)</string>
|
||||||
|
</property>
|
||||||
|
<property name="text" >
|
||||||
|
<string>No match</string>
|
||||||
|
</property>
|
||||||
|
<property name="readOnly" >
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="0" >
|
||||||
|
<widget class="QLabel" name="label_6" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>Series index:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="1" >
|
||||||
|
<widget class="QLineEdit" name="series_index" >
|
||||||
|
<property name="toolTip" >
|
||||||
|
<string>Regular expression group name (?P<series_index>)</string>
|
||||||
|
</property>
|
||||||
|
<property name="text" >
|
||||||
|
<string>No match</string>
|
||||||
|
</property>
|
||||||
|
<property name="readOnly" >
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
@ -22,7 +22,7 @@ from PyQt4.QtSvg import QSvgRenderer
|
|||||||
|
|
||||||
from libprs500 import __version__, __appname__, islinux, sanitize_file_name
|
from libprs500 import __version__, __appname__, islinux, sanitize_file_name
|
||||||
from libprs500.ptempfile import PersistentTemporaryFile
|
from libprs500.ptempfile import PersistentTemporaryFile
|
||||||
from libprs500.ebooks.metadata.meta import get_metadata
|
from libprs500.ebooks.metadata.meta import get_metadata, get_filename_pat, set_filename_pat
|
||||||
from libprs500.devices.errors import FreeSpaceError
|
from libprs500.devices.errors import FreeSpaceError
|
||||||
from libprs500.devices.interface import Device
|
from libprs500.devices.interface import Device
|
||||||
from libprs500.gui2 import APP_UID, warning_dialog, choose_files, error_dialog, \
|
from libprs500.gui2 import APP_UID, warning_dialog, choose_files, error_dialog, \
|
||||||
@ -806,6 +806,7 @@ class Main(MainWindow, Ui_MainWindow):
|
|||||||
self.database_path = qstring_to_unicode(settings.value("database path",
|
self.database_path = qstring_to_unicode(settings.value("database path",
|
||||||
QVariant(QString.fromUtf8(dbpath))).toString())
|
QVariant(QString.fromUtf8(dbpath))).toString())
|
||||||
set_sidebar_directories(None)
|
set_sidebar_directories(None)
|
||||||
|
set_filename_pat(qstring_to_unicode(settings.value('filename pattern', QVariant(get_filename_pat())).toString()))
|
||||||
|
|
||||||
def write_settings(self):
|
def write_settings(self):
|
||||||
settings = QSettings()
|
settings = QSettings()
|
||||||
|
@ -12,19 +12,71 @@
|
|||||||
## You should have received a copy of the GNU General Public License along
|
## You should have received a copy of the GNU General Public License along
|
||||||
## with this program; if not, write to the Free Software Foundation, Inc.,
|
## with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Miscellanous widgets used in the GUI
|
Miscellaneous widgets used in the GUI
|
||||||
'''
|
'''
|
||||||
|
import re
|
||||||
from PyQt4.QtGui import QListView, QIcon, QFont, QLabel, QListWidget, \
|
from PyQt4.QtGui import QListView, QIcon, QFont, QLabel, QListWidget, \
|
||||||
QListWidgetItem, QTextCharFormat, QApplication, \
|
QListWidgetItem, QTextCharFormat, QApplication, \
|
||||||
QSyntaxHighlighter, QCursor, QColor
|
QSyntaxHighlighter, QCursor, QColor, QWidget
|
||||||
from PyQt4.QtCore import QAbstractListModel, QVariant, Qt, QSize, SIGNAL, \
|
from PyQt4.QtCore import QAbstractListModel, QVariant, Qt, QSize, SIGNAL, \
|
||||||
QObject, QRegExp, QSettings
|
QObject, QRegExp, QSettings
|
||||||
|
|
||||||
from libprs500.gui2.jobs import DetailView
|
from libprs500.gui2.jobs import DetailView
|
||||||
from libprs500.gui2 import human_readable, NONE, TableView
|
from libprs500.gui2 import human_readable, NONE, TableView, qstring_to_unicode, error_dialog
|
||||||
|
from libprs500.gui2.filename_pattern_ui import Ui_Form
|
||||||
from libprs500 import fit_image, get_font_families
|
from libprs500 import fit_image, get_font_families
|
||||||
|
from libprs500.ebooks.metadata.meta import get_filename_pat, metadata_from_filename, \
|
||||||
|
set_filename_pat
|
||||||
|
|
||||||
|
class FilenamePattern(QWidget, Ui_Form):
|
||||||
|
|
||||||
|
def __init__(self, parent):
|
||||||
|
QWidget.__init__(self, parent)
|
||||||
|
self.setupUi(self)
|
||||||
|
|
||||||
|
self.connect(self.test_button, SIGNAL('clicked()'), self.do_test)
|
||||||
|
self.connect(self.re, SIGNAL('returnPressed()'), self.do_test)
|
||||||
|
self.re.setText(get_filename_pat())
|
||||||
|
|
||||||
|
def do_test(self):
|
||||||
|
try:
|
||||||
|
pat = self.pattern()
|
||||||
|
except Exception, err:
|
||||||
|
error_dialog(self, _('Invalid regular expression'),
|
||||||
|
_('Invalid regular expression: %s')%err).exec_()
|
||||||
|
return
|
||||||
|
mi = metadata_from_filename(qstring_to_unicode(self.filename.text()), pat)
|
||||||
|
if mi.title:
|
||||||
|
self.title.setText(mi.title)
|
||||||
|
else:
|
||||||
|
self.title.setText(_('No match'))
|
||||||
|
if mi.authors:
|
||||||
|
self.authors.setText(', '.join(mi.authors))
|
||||||
|
else:
|
||||||
|
self.authors.setText(_('No match'))
|
||||||
|
|
||||||
|
if mi.series:
|
||||||
|
self.series.setText(mi.series)
|
||||||
|
else:
|
||||||
|
self.series.setText(_('No match'))
|
||||||
|
|
||||||
|
if mi.series_index is not None:
|
||||||
|
self.series_index.setText(str(mi.series_index))
|
||||||
|
else:
|
||||||
|
self.series_index.setText(_('No match'))
|
||||||
|
|
||||||
|
def pattern(self):
|
||||||
|
pat = qstring_to_unicode(self.re.text())
|
||||||
|
return re.compile(pat)
|
||||||
|
|
||||||
|
def commit(self):
|
||||||
|
pat = self.pattern()
|
||||||
|
set_filename_pat(pat)
|
||||||
|
return pat.pattern
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ImageView(QLabel):
|
class ImageView(QLabel):
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user