[kde-doc-english] [kwave] /: saveblocks: added pattern to include the title of the current block
Thomas Eschenbacher
Thomas.Eschenbacher at gmx.de
Wed Oct 28 19:12:56 UTC 2015
Git commit 480833bd05f094ef22eea9df287f45b2e4b3f32d by Thomas Eschenbacher.
Committed on 28/10/2015 at 18:51.
Pushed by eschenbacher into branch 'master'.
saveblocks: added pattern to include the title of the current block
M +2 -1 CHANGES
M +13 -0 doc/en/index.docbook
M +69 -17 plugins/saveblocks/SaveBlocksPlugin.cpp
M +15 -4 plugins/saveblocks/SaveBlocksPlugin.h
M +8 -0 plugins/saveblocks/SaveBlocksWidget.cpp
http://commits.kde.org/kwave/480833bd05f094ef22eea9df287f45b2e4b3f32d
diff --git a/CHANGES b/CHANGES
index faaa5e5..a3af7e2 100644
--- a/CHANGES
+++ b/CHANGES
@@ -15,7 +15,8 @@
of patterns were ignored
* saveblocks: allow path separators in filename patterns to make it possible
to create subdirectories
- * saveblocks: added pattern to include file info (file meta data)
+ * saveblocks: added patterns to include file info (file meta data) or the
+ title of the current block
0.9.0 [2015-05-25]
diff --git a/doc/en/index.docbook b/doc/en/index.docbook
index 07e1746..27f8a55 100644
--- a/doc/en/index.docbook
+++ b/doc/en/index.docbook
@@ -6995,6 +6995,19 @@
for a list of all available keywords.
</entry>
</row>
+ <row>
+ <entry>&no-i18n-tag;<command>[%title]</command></entry>
+ <entry>
+ Will be replaced with the title the block, which is taken
+ from the descriptive text of the label at the
+ <emphasis>start</emphasis> of the block.
+ If that text is empty it will fall back to the title
+ of the file (see file information item
+ "<link linkend="INF_NAME">Name</link>").
+ If this also does not exist, it will fall back to the
+ base file name as described above.
+ </entry>
+ </row>
</tbody>
</tgroup>
</informaltable>
diff --git a/plugins/saveblocks/SaveBlocksPlugin.cpp b/plugins/saveblocks/SaveBlocksPlugin.cpp
index 2d0453c..77ce529 100644
--- a/plugins/saveblocks/SaveBlocksPlugin.cpp
+++ b/plugins/saveblocks/SaveBlocksPlugin.cpp
@@ -28,6 +28,7 @@
#include <KLocalizedString>
#include "libkwave/CodecManager.h"
+#include "libkwave/FileInfo.h"
#include "libkwave/Label.h"
#include "libkwave/LabelList.h"
#include "libkwave/MessageBox.h"
@@ -46,7 +47,7 @@ KWAVE_PLUGIN(Kwave::SaveBlocksPlugin, "saveblocks", "2.4",
Kwave::SaveBlocksPlugin::SaveBlocksPlugin(Kwave::PluginManager &plugin_manager)
:Kwave::Plugin(plugin_manager),
m_url(), m_pattern(), m_numbering_mode(CONTINUE),
- m_selection_only(true)
+ m_selection_only(true), m_block_info()
{
}
@@ -73,6 +74,10 @@ QStringList *Kwave::SaveBlocksPlugin::setup(QStringList &previous_params)
(selection_right + 1 >= signalLength()));
bool enable_selection_only = selected_something && !selected_all;
+ QString filename = m_url.path();
+ QString base = findBase(filename, m_pattern);
+ scanBlocksToSave(base, m_selection_only && enable_selection_only);
+
QPointer<Kwave::SaveBlocksDialog> dialog =
new(std::nothrow) Kwave::SaveBlocksDialog(
_("kfiledialog:///kwave_save_blocks"),
@@ -212,7 +217,8 @@ int Kwave::SaveBlocksPlugin::start(QStringList ¶ms)
}
// get the index range
- unsigned int count = blocksToSave(selection_only);
+ scanBlocksToSave(base, selection_only);
+ unsigned int count = m_block_info.count();
unsigned int first = firstIndex(path, base, ext, m_pattern,
m_numbering_mode, count);
@@ -396,13 +402,14 @@ int Kwave::SaveBlocksPlugin::interpreteParameters(QStringList ¶ms)
}
//***************************************************************************
-unsigned int Kwave::SaveBlocksPlugin::blocksToSave(bool selection_only)
+void Kwave::SaveBlocksPlugin::scanBlocksToSave(const QString &base,
+ bool selection_only)
{
- unsigned int count = 0;
sample_index_t selection_left, selection_right;
sample_index_t block_start;
sample_index_t block_end = 0;
+ QString block_title;
Kwave::LabelList labels(signalManager().metaData());
Kwave::LabelListIterator it(labels);
Kwave::Label label = (it.hasNext()) ? it.next() : Kwave::Label();
@@ -410,19 +417,39 @@ unsigned int Kwave::SaveBlocksPlugin::blocksToSave(bool selection_only)
if (selection_only) {
selection(0, &selection_left, &selection_right, true);
} else {
- selection_left = 0;
+ selection_left = 0;
selection_right = signalLength() - 1;
}
+
+ // get the title of the whole file, in case that a block does not have
+ // an own title
+ FileInfo info(signalManager().metaData());
+ QString file_title = info.get(INF_NAME).toString();
+
+ // fallback: if there is no INF_NAME either, fall back to the file
+ // name as last resort
+ if (!file_title.length()) file_title = base;
+
+ m_block_info.clear();
+ QString prev_title;
for (;;) {
block_start = block_end;
block_end = (label.isNull()) ? signalLength() : label.pos();
- if ((selection_left < block_end) && (selection_right > block_start))
- count++;
+ block_title = prev_title;
+ prev_title = (label.isNull()) ? file_title : label.name();
+
+ if ((block_end > selection_left) && (block_start <= selection_right)) {
+ BlockInfo block;
+ block.m_start = block_start;
+ block.m_length = block_end - block_start;
+ block.m_title = block_title;
+ if (!block.m_title.length()) block.m_title = file_title;
+ m_block_info.append(block);
+ }
+
if (label.isNull()) break;
label = (it.hasNext()) ? it.next() : Kwave::Label();
}
-
- return count;
}
//***************************************************************************
@@ -482,7 +509,7 @@ QString Kwave::SaveBlocksPlugin::createFileName(const QString &base,
// support for file info
QRegExp rx_fileinfo(
- _("\\\\\\[%(\\d*)fileinfo\\\\\\{([A-Z,a-z]+)\\\\\\}\\\\\\]"),
+ _("\\\\\\[%(\\d*)fileinfo\\\\\\{([\\w\\s]+)\\\\\\}\\\\\\]"),
Qt::CaseInsensitive
);
Kwave::FileInfo info(signalManager().metaData());
@@ -524,6 +551,17 @@ QString Kwave::SaveBlocksPlugin::createFileName(const QString &base,
p.replace(rx, value);
}
+ // format the "title" parameter
+ QRegExp rx_title(_("\\\\\\[%title\\\\\\]"), Qt::CaseInsensitive);
+ if (rx_title.indexIn(p) >= 0) {
+ QString title;
+ int idx = (index - 1) - (total - count);
+ if ((idx >= 0) && (idx < m_block_info.count()))
+ title = m_block_info[idx].m_title;
+ if (title.length())
+ p.replace(rx_title, QRegExp::escape(title));
+ }
+
if (ext.length()) p += _(".") + ext;
// sanitize the filename/path, make sure that there are no spaces
@@ -578,20 +616,28 @@ QString Kwave::SaveBlocksPlugin::findBase(const QString &filename,
// \[%[0-9]?count\] -> \d+
// \[%[0-9]?total\] -> \d+
// \[%filename\] -> base
+ // \[%fileinfo\] -> .
+ // \[%title\] -> .
QRegExp rx_nr(_("\\\\\\[%\\d*nr\\\\\\]"), Qt::CaseInsensitive);
QRegExp rx_count(_("\\\\\\[%\\d*count\\\\\\]"), Qt::CaseInsensitive);
QRegExp rx_total(_("\\\\\\[%\\d*total\\\\\\]"), Qt::CaseInsensitive);
QRegExp rx_filename(_("\\\\\\[%filename\\\\\\]"), Qt::CaseInsensitive);
+ QRegExp rx_fileinfo(_("\\\\\\[%fileinfo\\\\\\]"), Qt::CaseInsensitive);
+ QRegExp rx_title(_("\\\\\\[%title\\\\\\]"), Qt::CaseInsensitive);
QString p = QRegExp::escape(pattern);
- int idx_nr = rx_nr.indexIn(p);
- int idx_count = rx_count.indexIn(p);
- int idx_total = rx_total.indexIn(p);
+ int idx_nr = rx_nr.indexIn(p);
+ int idx_count = rx_count.indexIn(p);
+ int idx_total = rx_total.indexIn(p);
int idx_filename = rx_filename.indexIn(p);
- p.replace(rx_nr, _("(\\d+)"));
- p.replace(rx_count, _("(\\d+)"));
- p.replace(rx_total, _("(\\d+)"));
+ int idx_fileinfo = rx_fileinfo.indexIn(p);
+ int idx_title = rx_fileinfo.indexIn(p);
+ p.replace(rx_nr, _("(\\d+)"));
+ p.replace(rx_count, _("(\\d+)"));
+ p.replace(rx_total, _("(\\d+)"));
p.replace(rx_filename, _("(.+)"));
+ p.replace(rx_fileinfo, _("(.+)"));
+ p.replace(rx_title, _("(.+)"));
int max = 0;
for (int i = 0; i < pattern.length(); i++) {
@@ -599,10 +645,15 @@ QString Kwave::SaveBlocksPlugin::findBase(const QString &filename,
if (idx_count == max) max++;
if (idx_total == max) max++;
if (idx_filename == max) max++;
+ if (idx_fileinfo == max) max++;
+ if (idx_title == max) max++;
+
if (idx_nr > max) idx_nr--;
if (idx_count > max) idx_count--;
if (idx_total > max) idx_total--;
if (idx_filename > max) idx_filename--;
+ if (idx_fileinfo > max) idx_fileinfo--;
+ if (idx_title > max) idx_title--;
}
if (ext.length()) p += _(".") + ext;
@@ -627,7 +678,8 @@ QString Kwave::SaveBlocksPlugin::firstFileName(const QString &filename,
// now we have a new name, base and extension
// -> find out the numbering, min/max etc...
- unsigned int count = blocksToSave(selection_only);
+ scanBlocksToSave(base, selection_only);
+ unsigned int count = m_block_info.count();
unsigned int first = firstIndex(path, base, ext, pattern, mode, count);
unsigned int total = first + count - 1;
diff --git a/plugins/saveblocks/SaveBlocksPlugin.h b/plugins/saveblocks/SaveBlocksPlugin.h
index a7fc25d..399b717 100644
--- a/plugins/saveblocks/SaveBlocksPlugin.h
+++ b/plugins/saveblocks/SaveBlocksPlugin.h
@@ -70,12 +70,12 @@ namespace Kwave
int interpreteParameters(QStringList ¶ms);
/**
- * Returns the number of blocks to save, depending on whether
- * we save everything or only the selection
+ * determines the blocks which should be saved, including
+ * start position, length and title.
+ * @param base the base name, without indices, extension etc...
* @param selection_only if true, save only selected blocks
- * @return number of blocks, [0...N]
*/
- unsigned int blocksToSave(bool selection_only);
+ void scanBlocksToSave(const QString &base, bool selection_only);
/**
* create a filename (without extension) out of a given base name,
@@ -154,6 +154,14 @@ namespace Kwave
private:
+ typedef struct {
+ sample_index_t m_start; /**< start of the block [samples] */
+ sample_index_t m_length; /**< length of the block [samples] */
+ QString m_title; /**< title of the block */
+ } BlockInfo;
+
+ private:
+
/**
* internal helper to create a string that contains a HTML
* formated list of file names or directories
@@ -178,6 +186,9 @@ namespace Kwave
/** if true, only save stuff within the selection */
bool m_selection_only;
+ /** list of all blocks to save */
+ QList<BlockInfo> m_block_info;
+
};
}
diff --git a/plugins/saveblocks/SaveBlocksWidget.cpp b/plugins/saveblocks/SaveBlocksWidget.cpp
index 12ae783..d5c6197 100644
--- a/plugins/saveblocks/SaveBlocksWidget.cpp
+++ b/plugins/saveblocks/SaveBlocksWidget.cpp
@@ -22,6 +22,7 @@
#include <KComboBox>
+#include "libkwave/FileInfo.h"
#include "libkwave/String.h"
#include "SaveBlocksWidget.h"
@@ -36,8 +37,15 @@ Kwave::SaveBlocksWidget::SaveBlocksWidget(QWidget *parent,
{
setupUi(this);
+ Kwave::FileInfo info;
+
// the file name pattern combo box
+ cbPattern->addItem(_("[%2nr]-[%title]"));
cbPattern->addItem(_("[%filename] part [%nr] of [%total]"));
+ cbPattern->addItem(
+ _("[%fileinfo{") +
+ info.name(Kwave::INF_NAME) +
+ _("}] (part [%nr] of [%total])"));
cbPattern->addItem(_("[%filename] - [%04nr]"));
cbPattern->addItem(_("[%2nr] [%filename]"));
cbPattern->addItem(_("[%2nr]-[%filename]"));
More information about the kde-doc-english
mailing list