diff --git a/src/calibre/gui2/dialogs/config/add_save.py b/src/calibre/gui2/dialogs/config/add_save.py
index 54d948044b..3c1e30ff01 100644
--- a/src/calibre/gui2/dialogs/config/add_save.py
+++ b/src/calibre/gui2/dialogs/config/add_save.py
@@ -11,9 +11,7 @@ import textwrap
from PyQt4.Qt import QTabWidget
from calibre.gui2.dialogs.config.add_save_ui import Ui_TabWidget
-from calibre.library.save_to_disk import config, FORMAT_ARG_DESCS, \
- preprocess_template
-from calibre.gui2 import error_dialog
+from calibre.library.save_to_disk import config
from calibre.utils.config import prefs
from calibre.gui2.widgets import FilenamePattern
@@ -22,8 +20,8 @@ class AddSave(QTabWidget, Ui_TabWidget):
def __init__(self, parent=None):
QTabWidget.__init__(self, parent)
self.setupUi(self)
- while self.count() > 2:
- self.removeTab(2)
+ while self.count() > 3:
+ self.removeTab(3)
c = config()
opts = c.parse()
for x in ('asciiize', 'update_metadata', 'save_cover', 'write_opf',
@@ -41,36 +39,17 @@ class AddSave(QTabWidget, Ui_TabWidget):
g.setToolTip(help)
g.setWhatsThis(help)
- help = '\n'.join(textwrap.wrap(c.get_option('template').help, 75))
- self.opt_template.initialize('save_to_disk_template_history',
- opts.template, help)
-
- variables = sorted(FORMAT_ARG_DESCS.keys())
- rows = []
- for var in variables:
- rows.append(u'%s | %s |
'%
- (var, FORMAT_ARG_DESCS[var]))
- table = u''%(u'\n'.join(rows))
- self.template_variables.setText(table)
self.opt_read_metadata_from_filename.setChecked(not prefs['read_file_metadata'])
self.filename_pattern = FilenamePattern(self)
self.metadata_box.layout().insertWidget(0, self.filename_pattern)
self.opt_swap_author_names.setChecked(prefs['swap_author_names'])
+ help = '\n'.join(textwrap.wrap(c.get_option('template').help, 75))
+ self.save_template.initialize('save_to_disk', opts.template, help)
+ self.send_template.initialize('send_to_device', opts.send_template, help)
def validate(self):
- tmpl = preprocess_template(self.opt_template.text())
- fa = {}
- for x in FORMAT_ARG_DESCS.keys():
- fa[x]=''
- try:
- tmpl.format(**fa)
- except Exception, err:
- error_dialog(self, _('Invalid template'),
- ''+_('The template %s is invalid:')%tmpl + \
- '
'+str(err), show=True)
- return False
- return True
+ return self.save_template.validate() and self.send_template.validate()
def save_settings(self):
if not self.validate():
@@ -79,12 +58,13 @@ class AddSave(QTabWidget, Ui_TabWidget):
for x in ('asciiize', 'update_metadata', 'save_cover', 'write_opf',
'replace_whitespace', 'to_lowercase'):
c.set(x, getattr(self, 'opt_'+x).isChecked())
- for x in ('formats', 'template', 'timefmt'):
+ for x in ('formats', 'timefmt'):
val = unicode(getattr(self, 'opt_'+x).text()).strip()
if x == 'formats' and not val:
val = 'all'
c.set(x, val)
- self.opt_template.save_history('save_to_disk_template_history')
+ self.save_template.save_settings(c, 'template')
+ self.send_template.save_settings(c, 'send_template')
prefs['read_file_metadata'] = not bool(self.opt_read_metadata_from_filename.isChecked())
pattern = self.filename_pattern.commit()
prefs['filename_pattern'] = pattern
diff --git a/src/calibre/gui2/dialogs/config/add_save.ui b/src/calibre/gui2/dialogs/config/add_save.ui
index 806f77dade..fbf9ceaf2a 100644
--- a/src/calibre/gui2/dialogs/config/add_save.ui
+++ b/src/calibre/gui2/dialogs/config/add_save.ui
@@ -141,38 +141,6 @@
-
- -
-
-
- Save &template
-
-
-
-
-
-
- By adjusting the template below, you can control what folders the files are saved in and what filenames they are given. You can use the / character to indicate sub-folders. Available metadata variables are described below. If a particular book does not have some metadata, the variable will be replaced by the empty string.
-
-
- true
-
-
-
- -
-
-
- Available variables:
-
-
-
- -
-
-
- -
-
-
-
-
-
-
@@ -187,14 +155,38 @@
+ -
+
+
+
+
+
+
+ Sending to &device
+
+
+ -
+
+
+ Here you can control how calibre will save your books when you click the Send to Device button. This setting can be overriden for individual devices by customizing the device interface plugins in Preferences->Plugins
+
+
+ true
+
+
+
+ -
+
+
- HistoryBox
- QComboBox
- calibre/gui2/dialogs/config/history.h
+ SaveTemplate
+ QWidget
+ calibre/gui2/dialogs/config/save_template.h
+ 1
diff --git a/src/calibre/gui2/dialogs/config/save_template.py b/src/calibre/gui2/dialogs/config/save_template.py
new file mode 100644
index 0000000000..8fe36c430f
--- /dev/null
+++ b/src/calibre/gui2/dialogs/config/save_template.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python
+# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
+from __future__ import with_statement
+
+__license__ = 'GPL v3'
+__copyright__ = '2009, Kovid Goyal '
+__docformat__ = 'restructuredtext en'
+
+from PyQt4.Qt import QWidget
+
+from calibre.gui2 import error_dialog
+from calibre.gui2.dialogs.config.save_template_ui import Ui_Form
+from calibre.library.save_to_disk import FORMAT_ARG_DESCS, \
+ preprocess_template
+
+class SaveTemplate(QWidget, Ui_Form):
+
+ def __init__(self, *args):
+ QWidget.__init__(self, *args)
+ Ui_Form.__init__(self)
+ self.setupUi(self)
+
+ def initialize(self, name, default, help):
+ variables = sorted(FORMAT_ARG_DESCS.keys())
+ rows = []
+ for var in variables:
+ rows.append(u'%s | %s |
'%
+ (var, FORMAT_ARG_DESCS[var]))
+ table = u''%(u'\n'.join(rows))
+ self.template_variables.setText(table)
+
+ self.opt_template.initialize(name+'_template_history',
+ default, help)
+ self.option_name = name
+
+ def validate(self):
+ tmpl = preprocess_template(self.opt_template.text())
+ fa = {}
+ for x in FORMAT_ARG_DESCS.keys():
+ fa[x]=''
+ try:
+ tmpl.format(**fa)
+ except Exception, err:
+ error_dialog(self, _('Invalid template'),
+ ''+_('The template %s is invalid:')%tmpl + \
+ '
'+str(err), show=True)
+ return False
+ return True
+
+ def save_settings(self, config, name):
+ val = unicode(self.opt_template.text())
+ config.set(name, val)
+ self.opt_template.save_history(self.option_name+'_template_history')
+
+
+
+
+
diff --git a/src/calibre/gui2/dialogs/config/save_template.ui b/src/calibre/gui2/dialogs/config/save_template.ui
new file mode 100644
index 0000000000..02506891bb
--- /dev/null
+++ b/src/calibre/gui2/dialogs/config/save_template.ui
@@ -0,0 +1,60 @@
+
+
+ Form
+
+
+
+ 0
+ 0
+ 400
+ 300
+
+
+
+ Form
+
+
+ -
+
+
+ Save &template
+
+
+
-
+
+
+ By adjusting the template below, you can control what folders the files are saved in and what filenames they are given. You can use the / character to indicate sub-folders. Available metadata variables are described below. If a particular book does not have some metadata, the variable will be replaced by the empty string.
+
+
+ true
+
+
+
+ -
+
+
+ Available variables:
+
+
+
+ -
+
+
+ -
+
+
+
+
+
+
+
+
+
+ HistoryBox
+ QComboBox
+ calibre/gui2/dialogs/config/history.h
+
+
+
+
+
diff --git a/src/calibre/gui2/library.py b/src/calibre/gui2/library.py
index 55d6d94967..6463d11daa 100644
--- a/src/calibre/gui2/library.py
+++ b/src/calibre/gui2/library.py
@@ -399,6 +399,8 @@ class BooksModel(QAbstractTableModel):
data[_('Author(s)')] = au
return data
+ def metadata_for(self, ids):
+ return [self.db.get_metadata(id, index_is_id=True) for id in ids]
def get_metadata(self, rows, rows_are_ids=False, full_metadata=False):
metadata, _full_metadata = [], []
diff --git a/src/calibre/library/save_to_disk.py b/src/calibre/library/save_to_disk.py
index e169222bb5..537d7db7c1 100644
--- a/src/calibre/library/save_to_disk.py
+++ b/src/calibre/library/save_to_disk.py
@@ -18,6 +18,8 @@ from calibre.constants import preferred_encoding, filesystem_encoding
from calibre import strftime
DEFAULT_TEMPLATE = '{author_sort}/{title}/{title} - {authors}'
+DEFAULT_SEND_TEMPLATE = '{author_sort}/{title} - {authors}'
+
FORMAT_ARG_DESCS = dict(
title=_('The title'),
authors=_('The authors'),
@@ -62,6 +64,13 @@ def config(defaults=None):
'Default is "%s" which will save books into a per-author '
'subdirectory with filenames containing title and author. '
'Available controls are: {%s}')%(DEFAULT_TEMPLATE, ', '.join(FORMAT_ARGS)))
+ x('send_template', default=DEFAULT_SEND_TEMPLATE,
+ help=_('The template to control the filename and directory structure of files '
+ 'sent to the device. '
+ 'Default is "%s" which will save books into a per-author '
+ 'directory with filenames containing title and author. '
+ 'Available controls are: {%s}')%(DEFAULT_SEND_TEMPLATE, ', '.join(FORMAT_ARGS)))
+
x('asciiize', default=True,
help=_('Normally, calibre will convert all non English characters into English equivalents '
'for the file names. '