kwave  18.07.70
Kwave::K3BExportPlugin Class Reference

#include <K3BExportPlugin.h>

Inheritance diagram for Kwave::K3BExportPlugin:
Inheritance graph
Collaboration diagram for Kwave::K3BExportPlugin:
Collaboration graph

Classes

struct  BlockInfo
 

Public Types

enum  export_location_t { EXPORT_TO_SAME_DIR = 0, EXPORT_TO_SUB_DIR = 1 }
 
enum  overwrite_policy_t { OVERWRITE_EXISTING_FILES = 0, USE_NEW_FILE_NAMES = 1 }
 

Public Member Functions

 K3BExportPlugin (QObject *parent, const QVariantList &args)
 
virtual ~K3BExportPlugin () Q_DECL_OVERRIDE
 
virtual void load (QStringList &params) Q_DECL_OVERRIDE
 
virtual QStringList * setup (QStringList &params) Q_DECL_OVERRIDE
 
virtual int start (QStringList &params) Q_DECL_OVERRIDE
 
- Public Member Functions inherited from Kwave::Plugin
 Plugin (QObject *parent, const QVariantList &args)
 
virtual ~Plugin () Q_DECL_OVERRIDE
 
virtual QString name () const
 
virtual QString description () const
 
virtual QString progressText ()
 
virtual bool canClose () const
 
bool isRunning () const
 
bool shouldStop () const
 
virtual void unload ()
 
virtual int stop ()
 
virtual void run (QStringList params)
 
Kwave::PluginManagermanager () const
 
Kwave::SignalManagersignalManager ()
 
QWidget * parentWidget () const
 
QString signalName ()
 
virtual sample_index_t signalLength ()
 
virtual double signalRate ()
 
virtual const QList< unsigned int > selectedTracks ()
 
virtual sample_index_t selection (QList< unsigned int > *tracks=Q_NULLPTR, sample_index_t *left=Q_NULLPTR, sample_index_t *right=Q_NULLPTR, bool expand_if_empty=false)
 
virtual void selectRange (sample_index_t offset, sample_index_t length)
 
virtual void migrateToActiveContext ()
 
- Public Member Functions inherited from Kwave::Runnable
virtual ~Runnable ()
 

Static Public Member Functions

static QStringList knownPatterns ()
 

Protected Member Functions

int interpreteParameters (QStringList &params)
 
void scanBlocksToSave (const QString &base, sample_index_t selection_left, sample_index_t selection_right)
 
QString createFileName (const QString &pattern, unsigned int index)
 
bool detectBlockMetaData (const QString &text, const QString &pattern, BlockInfo &block)
 
void saveGeneralDocumentData (QDomElement *part)
 
void saveDocumentData (QDomElement *docElem)
 
int saveBlocks (bool selection_only, const QString &out_dir, const QString &out_pattern)
 
int saveK3BFile (const QString &k3b_filename)
 
- Protected Member Functions inherited from Kwave::Plugin
int execute (QStringList &params)
 
void emitCommand (const QString &command)
 
void use ()
 
void setPluginManager (Kwave::PluginManager *new_plugin_manager)
 
virtual void run_wrapper (const QVariant &params) Q_DECL_OVERRIDE
 

Private Attributes

QUrl m_url
 
QString m_pattern
 
bool m_selection_only
 
export_location_t m_export_location
 
overwrite_policy_t m_overwrite_policy
 
QVector< BlockInfom_block_info
 

Additional Inherited Members

- Public Slots inherited from Kwave::Plugin
virtual void setProgressDialogEnabled (bool enable)
 
virtual void updateProgress (qreal progress)
 
virtual void cancel ()
 
virtual void close ()
 
void release ()
 
- Signals inherited from Kwave::Plugin
void sigRunning (Kwave::Plugin *plugin)
 
void sigDone (Kwave::Plugin *plugin)
 
void sigClosed (Kwave::Plugin *p)
 
void sigCommand (const QString &command)
 
void setProgressText (const QString &text)
 

Detailed Description

Definition at line 36 of file K3BExportPlugin.h.

Member Enumeration Documentation

◆ export_location_t

◆ overwrite_policy_t

Constructor & Destructor Documentation

◆ K3BExportPlugin()

Kwave::K3BExportPlugin::K3BExportPlugin ( QObject *  parent,
const QVariantList &  args 
)

Constructor

Parameters
parentreference to our plugin manager
argsargument list [unused]

Definition at line 73 of file K3BExportPlugin.cpp.

◆ ~K3BExportPlugin()

Kwave::K3BExportPlugin::~K3BExportPlugin ( )
virtual

Destructor

Definition at line 86 of file K3BExportPlugin.cpp.

87 {
88 }

Member Function Documentation

◆ createFileName()

QString Kwave::K3BExportPlugin::createFileName ( const QString &  pattern,
unsigned int  index 
)
protected

create a filename (with extension) out of a given name pattern and index

Parameters
patternthe pattern for creating the filename
indexthe index of the current file
Returns
the name of the file

Definition at line 196 of file K3BExportPlugin.cpp.

References _, Kwave::Plugin::name(), OUTFILE_DIGITS, OUTFILE_PATTERN, and OUTFILE_SUFFIX.

Referenced by saveBlocks(), and start().

198 {
199  QString name = pattern;
200  QString num = _("%1").arg(index, OUTFILE_DIGITS, 10, QLatin1Char('0'));
201  name.replace(OUTFILE_PATTERN, num);
202  name += OUTFILE_SUFFIX;
203  return name;
204 }
#define OUTFILE_DIGITS
virtual QString name() const
Definition: Plugin.cpp:196
#define OUTFILE_SUFFIX
#define _(m)
Definition: memcpy.c:66
#define OUTFILE_PATTERN
Here is the call graph for this function:
Here is the caller graph for this function:

◆ detectBlockMetaData()

bool Kwave::K3BExportPlugin::detectBlockMetaData ( const QString &  text,
const QString &  pattern,
BlockInfo block 
)
protected

detects the meta data of a block from splitting the description text of a label

Parameters
textthe description of a label
patterna pattern describing the format of the text
blocka BlockInfo structure that receives artist and title
Returns
true if the pattern did match, false otherwise

Definition at line 207 of file K3BExportPlugin.cpp.

References _, Kwave::Parser::escape(), knownPatterns(), Kwave::K3BExportPlugin::BlockInfo::m_artist, and Kwave::K3BExportPlugin::BlockInfo::m_title.

Referenced by scanBlocksToSave().

212 {
213  if (!pattern.length()) {
214  // auto detect -> try all known patterns
215  foreach (const QString &p, knownPatterns())
216  if (detectBlockMetaData(text, p, block))
217  return true;
218  return false;
219  }
220 
221  // list of placeholders and pointers to the resulting strings
222  QMap <QString, QString *> map_patterns;
223  map_patterns.insert(_("[%artist]"), &block.m_artist);
224  map_patterns.insert(_("[%title]"), &block.m_title);
225 
226  // try to find the placeholders within the pattern
227  // NOTE: we use a map because it will automatically be sorted (by pos)
228  QString pattern_esc = Kwave::Parser::escape(pattern);
229  QMap <int, QString *> map_result;
230  foreach (const QString &placeholder, map_patterns.keys()) {
231  QString placeholder_esc;
232  placeholder_esc = Kwave::Parser::escape(placeholder);
233  if (pattern_esc.contains(placeholder_esc)) {
234  const QString rx_string = _("(.+)");
235  int pos = pattern.indexOf(placeholder);
236  pattern_esc.replace(placeholder_esc, rx_string);
237  map_result.insert(pos, map_patterns[placeholder]);
238  }
239  }
240  if (map_result.isEmpty())
241  return false; // no placeholders found in the patterns
242 
243  // relax the pattern: turn single whitespace to one or more whitespaces
244  pattern_esc.replace(QRegExp(_("(\\\\\\s)+")), _("\\s+"));
245 
246  // try to match the pattern on the given text
247  QRegExp rx(pattern_esc, Qt::CaseInsensitive);
248  if (!rx.exactMatch(text.trimmed()))
249  return false; // does not match :-(
250 
251  // we found a match
252  // -> now map the results into the corresponding result strings
253  for (int index = 0; index < map_result.count(); ++index) {
254  QString value = rx.cap(index + 1).trimmed();
255  if (value.length()) {
256  QString *result = map_result[map_result.keys()[index]];
257  if (result) *result = value;
258  }
259  }
260 
261  return true;
262 }
static QStringList knownPatterns()
#define _(m)
Definition: memcpy.c:66
static QString escape(const QString &text)
Definition: Parser.cpp:277
bool detectBlockMetaData(const QString &text, const QString &pattern, BlockInfo &block)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ interpreteParameters()

int Kwave::K3BExportPlugin::interpreteParameters ( QStringList &  params)
protected

reads values from the parameter list

Definition at line 91 of file K3BExportPlugin.cpp.

References EXPORT_TO_SAME_DIR, EXPORT_TO_SUB_DIR, m_export_location, m_overwrite_policy, m_pattern, m_selection_only, m_url, OVERWRITE_EXISTING_FILES, Kwave::Parser::unescape(), and USE_NEW_FILE_NAMES.

Referenced by setup(), and start().

92 {
93  bool ok;
94  QString param;
95 
96  // evaluate the parameter list
97  if (params.count() != 5)
98  return -EINVAL;
99 
100  // the selected URL
101  m_url = QUrl::fromUserInput(Kwave::Parser::unescape(params[0]));
102  if (!m_url.isValid()) return -EINVAL;
103 
104  // label pattern
105  m_pattern = Kwave::Parser::unescape(params[1]);
106 
107  // selection only
108  param = params[2];
109  int v = param.toInt(&ok);
110  Q_ASSERT(ok);
111  if (!ok) return -EINVAL;
112  m_selection_only = (v != 0);
113 
114  // export location
115  param = params[3];
116  int where = param.toInt(&ok);
117  Q_ASSERT(ok);
118  if (!ok) return -EINVAL;
119  if ((where != EXPORT_TO_SAME_DIR) &&
120  (where != EXPORT_TO_SUB_DIR)) return -EINVAL;
121  m_export_location = static_cast<export_location_t>(where);
122 
123  // overwrite policy
124  param = params[4];
125  int overwrite = param.toInt(&ok);
126  Q_ASSERT(ok);
127  if (!ok) return -EINVAL;
128  if ((overwrite != OVERWRITE_EXISTING_FILES) &&
129  (overwrite != USE_NEW_FILE_NAMES)) return -EINVAL;
130  m_overwrite_policy = static_cast<overwrite_policy_t>(overwrite);
131 
132  return 0;
133 }
overwrite_policy_t m_overwrite_policy
export_location_t m_export_location
static QString unescape(const QString &text)
Definition: Parser.cpp:314
Here is the call graph for this function:
Here is the caller graph for this function:

◆ knownPatterns()

QStringList Kwave::K3BExportPlugin::knownPatterns ( )
static

returns a list of all known detection patterns

Definition at line 777 of file K3BExportPlugin.cpp.

References _.

Referenced by detectBlockMetaData(), and Kwave::K3BExportWidget::K3BExportWidget().

778 {
779  // list of all known detection patterns
780  QStringList patterns;
781  patterns << _("[%title] ([%artist])");
782  patterns << _("[%title], [%artist]");
783  patterns << _("[%artist]: [%title]");
784  patterns << _("[%artist] - [%title]");
785  return patterns;
786 }
#define _(m)
Definition: memcpy.c:66
Here is the caller graph for this function:

◆ load()

void Kwave::K3BExportPlugin::load ( QStringList &  params)
virtual
See also
Kwave::Plugin::load()

Reimplemented from Kwave::Plugin.

Definition at line 265 of file K3BExportPlugin.cpp.

References _, and Kwave::Plugin::emitCommand().

266 {
267  Q_UNUSED(params);
268 
269  QString menu_path = _("File/Save/%1").arg(_(I18N_NOOP2(
270  "menu: /File/Save/Export to K3b Project...",
271  "Export to K3b Project..."
272  )));
273  emitCommand(_("menu(plugin:setup(export_k3b),%1%2)").arg(
274  menu_path).arg(_("/#group(@SIGNAL)")));
275  emitCommand(_("menu(plugin:setup(export_k3b),%1%2)").arg(
276  menu_path).arg(_("/#icon(application-x-k3b)")));
277 }
void emitCommand(const QString &command)
Definition: Plugin.cpp:510
#define _(m)
Definition: memcpy.c:66
Here is the call graph for this function:

◆ saveBlocks()

int Kwave::K3BExportPlugin::saveBlocks ( bool  selection_only,
const QString &  out_dir,
const QString &  out_pattern 
)
protected

save the blocks through the saveblocks plugin

Parameters
selection_onlyif true, save only the selection
out_diroutput directory for saving the blocks
out_patternthe pattern for creating the block filenames
Returns
zero if succeeded, or error code if failed

Definition at line 686 of file K3BExportPlugin.cpp.

References _, createFileName(), Kwave::CodecManager::encoder(), Kwave::Parser::escape(), Kwave::Parser::escapeForFileName(), Kwave::PluginManager::executePlugin(), m_overwrite_policy, m_url, Kwave::Plugin::manager(), Kwave::SignalManager::metaData(), Kwave::CodecManager::mimeTypeOf(), Kwave::FileInfo::properties(), Kwave::MetaDataList::replace(), Kwave::FileInfo::set(), Kwave::FileInfo::setBits(), Kwave::Plugin::signalManager(), Kwave::Encoder::unsupportedProperties(), and USE_NEW_FILE_NAMES.

Referenced by start().

689 {
690  QString first_filename = Kwave::Parser::escapeForFileName(
691  QUrl::fromLocalFile(createFileName(out_pattern, 1)).toString());
692 
693  // remember the original file info remove all unsupported/ properties,
694  // to avoid that the saveblocks plugin complains...
695  const Kwave::FileInfo orig_file_info(signalManager().metaData());
696  Kwave::FileInfo file_info(orig_file_info);
697  QList<Kwave::FileProperty> unsupported_properties;
698  {
699  QString mimetype = Kwave::CodecManager::mimeTypeOf(m_url);
700  Kwave::Encoder *encoder = Kwave::CodecManager::encoder(mimetype);
701  if (encoder) {
702  unsupported_properties = encoder->unsupportedProperties(
703  file_info.properties().keys());
704  delete encoder;
705  }
706  if (!unsupported_properties.isEmpty()) {
707  foreach (const Kwave::FileProperty &p, unsupported_properties) {
708  file_info.set(p, QVariant());
709  }
710  }
711  }
712 
713  // make sure that the file uses 16 bits/sample only
714  file_info.setBits(16);
715 
717 
718  // call the saveblocks plugin and let it do the main work of exporting
719  // the *.wav files with all the tracks...
720 
721  QStringList params;
722  params << out_dir + QDir::separator() + first_filename;
723  params << Kwave::Parser::escape(out_pattern);
724  params << ((m_overwrite_policy == USE_NEW_FILE_NAMES) ? _("0") : _("1"));
725  params << (selection_only ? _("1") : _("0"));
726  int result = manager().executePlugin(_("saveblocks"), &params);
727 
728  // restore the original file info
729  signalManager().metaData().replace(Kwave::MetaDataList(orig_file_info));
730 
731  return result;
732 }
overwrite_policy_t m_overwrite_policy
Kwave::MetaDataList & metaData()
Kwave::SignalManager & signalManager()
Definition: Plugin.cpp:444
QString createFileName(const QString &pattern, unsigned int index)
static QString mimeTypeOf(const QUrl &url)
Kwave::PluginManager & manager() const
Definition: Plugin.cpp:437
int executePlugin(const QString &name, QStringList *params)
static QString escapeForFileName(const QString &text)
Definition: Parser.cpp:295
virtual QList< Kwave::FileProperty > unsupportedProperties(const QList< Kwave::FileProperty > &properties_to_check)
Definition: Encoder.cpp:27
virtual void replace(const MetaDataList &list)
static Kwave::Encoder * encoder(const QString &mimetype_name)
#define _(m)
Definition: memcpy.c:66
static QString escape(const QString &text)
Definition: Parser.cpp:277
FileProperty
Definition: FileInfo.h:45
Here is the call graph for this function:
Here is the caller graph for this function:

◆ saveDocumentData()

void Kwave::K3BExportPlugin::saveDocumentData ( QDomElement *  docElem)
protected

save the K3b project document data

Definition at line 410 of file K3BExportPlugin.cpp.

References _, Kwave::FileInfo::get(), GET_INF, Kwave::INF_AUTHOR, Kwave::INF_CD, Kwave::INF_COMMENTS, Kwave::INF_COPYRIGHTED, Kwave::INF_ISRC, Kwave::INF_NAME, Kwave::INF_ORGANIZATION, Kwave::INF_PERFORMER, Kwave::INF_TECHNICAN, Kwave::K3BExportPlugin::BlockInfo::m_artist, m_block_info, Kwave::K3BExportPlugin::BlockInfo::m_filename, Kwave::K3BExportPlugin::BlockInfo::m_title, saveGeneralDocumentData(), and Kwave::Plugin::signalManager().

Referenced by saveK3BFile().

411 {
412  #define GET_INF(inf) doc.createTextNode(info.get(inf).toString())
413 
414  const Kwave::FileInfo info(signalManager().metaData());
415 
416  QDomDocument doc = docElem->ownerDocument();
417  saveGeneralDocumentData(docElem);
418 
419  // add normalize
420  QDomElement normalizeElem = doc.createElement(_("normalize"));
421  normalizeElem.appendChild(doc.createTextNode(_("no")));
422  docElem->appendChild(normalizeElem);
423 
424  // add hide track
425  QDomElement hideFirstTrackElem = doc.createElement(_("hide_first_track"));
426  hideFirstTrackElem.appendChild(doc.createTextNode(_("no")));
427  docElem->appendChild(hideFirstTrackElem);
428 
429  // save the audio cd ripping settings
430  // paranoia mode, read retries, and ignore read errors
431  // ------------------------------------------------------------
432  QDomElement ripMain = doc.createElement(_("audio_ripping"));
433  docElem->appendChild(ripMain);
434 
435  QDomElement ripElem = doc.createElement(_("paranoia_mode"));
436  ripElem.appendChild(doc.createTextNode(_("0")));
437  ripMain.appendChild(ripElem);
438 
439  ripElem = doc.createElement(_("read_retries"));
440  ripElem.appendChild(doc.createTextNode(_("0")));
441  ripMain.appendChild(ripElem);
442 
443  ripElem = doc.createElement(_("ignore_read_errors"));
444  ripElem.appendChild(doc.createTextNode(_("no")));
445  ripMain.appendChild(ripElem);
446  // ------------------------------------------------------------
447 
448  // save disc cd-text
449  // -------------------------------------------------------------
450  QDomElement cdTextMain = doc.createElement(_("cd-text"));
451  cdTextMain.setAttribute(_("activated"), _("yes"));
452 
453  QDomElement cdTextElem = doc.createElement(_("title"));
454  cdTextElem.appendChild(GET_INF(INF_NAME));
455  cdTextMain.appendChild(cdTextElem);
456 
457  cdTextElem = doc.createElement(_("artist"));
458  cdTextElem.appendChild(GET_INF(INF_AUTHOR));
459  cdTextMain.appendChild(cdTextElem);
460 
461  cdTextElem = doc.createElement(_("arranger"));
462  cdTextElem.appendChild(GET_INF(INF_TECHNICAN));
463  cdTextMain.appendChild(cdTextElem);
464 
465  cdTextElem = doc.createElement(_("songwriter"));
466  cdTextElem.appendChild(GET_INF(INF_PERFORMER));
467  cdTextMain.appendChild(cdTextElem);
468 
469  cdTextElem = doc.createElement(_("composer"));
470  cdTextElem.appendChild(GET_INF(INF_ORGANIZATION));
471  cdTextMain.appendChild(cdTextElem);
472 
473  cdTextElem = doc.createElement(_("disc_id"));
474  cdTextElem.appendChild(GET_INF(INF_CD));
475  cdTextMain.appendChild(cdTextElem);
476 
477  cdTextElem = doc.createElement(_("upc_ean"));
478  cdTextElem.appendChild(GET_INF(INF_ISRC));
479  cdTextMain.appendChild(cdTextElem);
480 
481  cdTextElem = doc.createElement(_("message"));
482  cdTextElem.appendChild(GET_INF(INF_COMMENTS));
483  cdTextMain.appendChild(cdTextElem);
484 
485  docElem->appendChild( cdTextMain );
486  // -------------------------------------------------------------
487 
488  // save the tracks
489  // -------------------------------------------------------------
490  QDomElement contentsElem = doc.createElement(_("contents"));
491 
492  unsigned int index = 1;
493  foreach (const Kwave::K3BExportPlugin::BlockInfo &block, m_block_info) {
494  QString title = block.m_title;
495  QString artist = block.m_artist;
496  QString songwriter = QString();
497  QString url = block.m_filename;
498 
499  QDomElement trackElem = doc.createElement(_("track"));
500 
501  // add sources
502  QDomElement sourcesParent = doc.createElement(_("sources"));
503  QDomElement sourceElem = doc.createElement(_("file"));
504  sourceElem.setAttribute(_("url"), url);
505  sourceElem.setAttribute(_("start_offset"), _("00:00:00"));
506  sourceElem.setAttribute(_("end_offset"), _("00:00:00"));
507  sourcesParent.appendChild(sourceElem);
508  trackElem.appendChild(sourcesParent);
509 
510  // index 0
511  QDomElement index0Elem = doc.createElement(_("index0"));
512  index0Elem.appendChild(doc.createTextNode(QString::number(index)));
513  trackElem.appendChild(index0Elem);
514 
515  // add cd-text
516  cdTextMain = doc.createElement(_("cd-text"));
517  cdTextElem = doc.createElement(_("title"));
518  cdTextElem.appendChild(doc.createTextNode(title));
519  cdTextMain.appendChild(cdTextElem);
520 
521  cdTextElem = doc.createElement(_("artist"));
522  cdTextElem.appendChild(doc.createTextNode(artist));
523  cdTextMain.appendChild(cdTextElem);
524 
525  cdTextElem = doc.createElement(_("arranger"));
526  cdTextElem.appendChild(GET_INF(INF_TECHNICAN));
527  cdTextMain.appendChild(cdTextElem);
528 
529  cdTextElem = doc.createElement(_("songwriter"));
530  cdTextElem.appendChild(doc.createTextNode(songwriter));
531  cdTextMain.appendChild(cdTextElem );
532 
533  cdTextElem = doc.createElement(_("composer"));
534  cdTextElem.appendChild(GET_INF(INF_ORGANIZATION));
535  cdTextMain.appendChild(cdTextElem);
536 
537  cdTextElem = doc.createElement(_("isrc"));
538  cdTextElem.appendChild(GET_INF(INF_ISRC));
539  cdTextMain.appendChild(cdTextElem);
540 
541  cdTextElem = doc.createElement(_("message"));
542  cdTextElem.appendChild(GET_INF(INF_COMMENTS));
543  cdTextMain.appendChild(cdTextElem);
544 
545  trackElem.appendChild(cdTextMain);
546 
547  // add copy protection
548  QDomElement copyElem = doc.createElement(_("copy_protection"));
549  copyElem.appendChild(doc.createTextNode(
550  info.get(INF_COPYRIGHTED).toInt() ? _("yes") : _("no")
551  ));
552  trackElem.appendChild(copyElem);
553 
554  // add pre emphasis
555  copyElem = doc.createElement(_("pre_emphasis"));
556  copyElem.appendChild(doc.createTextNode(_("no")));
557  trackElem.appendChild(copyElem);
558 
559  contentsElem.appendChild(trackElem);
560  index++;
561  }
562  // -------------------------------------------------------------
563 
564  docElem->appendChild(contentsElem);
565 }
#define GET_INF(inf)
Kwave::SignalManager & signalManager()
Definition: Plugin.cpp:444
void saveGeneralDocumentData(QDomElement *part)
#define _(m)
Definition: memcpy.c:66
QVector< BlockInfo > m_block_info
Here is the call graph for this function:
Here is the caller graph for this function:

◆ saveGeneralDocumentData()

void Kwave::K3BExportPlugin::saveGeneralDocumentData ( QDomElement *  part)
protected

save the "general" section

Definition at line 374 of file K3BExportPlugin.cpp.

References _.

Referenced by saveDocumentData().

375 {
376  QDomDocument doc = part->ownerDocument();
377  QDomElement mainElem = doc.createElement(_("general"));
378 
379  QDomElement propElem = doc.createElement(_("writing_mode"));
380  propElem.appendChild(doc.createTextNode(_("auto")));
381  mainElem.appendChild(propElem);
382 
383  propElem = doc.createElement(_("dummy"));
384  propElem.setAttribute(_("activated"), _("no"));
385  mainElem.appendChild(propElem);
386 
387  propElem = doc.createElement(_("on_the_fly"));
388  propElem.setAttribute(_("activated"), _("true"));
389  mainElem.appendChild(propElem);
390 
391  propElem = doc.createElement(_("only_create_images"));
392  propElem.setAttribute(_("activated"), _("no"));
393  mainElem.appendChild(propElem);
394 
395  propElem = doc.createElement(_("remove_images"));
396  propElem.setAttribute(_("activated"), _("no"));
397  mainElem.appendChild(propElem);
398 
399  part->appendChild( mainElem );
400 }
#define _(m)
Definition: memcpy.c:66
Here is the caller graph for this function:

◆ saveK3BFile()

int Kwave::K3BExportPlugin::saveK3BFile ( const QString &  k3b_filename)
protected

save the *.k3b file

Parameters
k3b_filenamepath to the *.k3b file
Returns
zero if succeeded, or error code if failed

Definition at line 735 of file K3BExportPlugin.cpp.

References _, K3B_PROJECT_MIME_TYPE, and saveDocumentData().

Referenced by start().

736 {
737  // create the K3B file
738  KZip zip(k3b_filename);
739 
740  bool ok = zip.open(QIODevice::WriteOnly);
741  if (!ok) return -EIO;
742 
743  // write the mime type
744  QByteArray app_type(K3B_PROJECT_MIME_TYPE);
745  zip.setCompression(KZip::NoCompression);
746  zip.setExtraField(KZip::NoExtraField);
747  zip.writeFile(_("mimetype"), app_type);
748 
749  // export file global data
750  QByteArray xml;
751  QBuffer out(&xml);
752  out.open(QIODevice::WriteOnly);
753 
754  // save the data in the document
755  QDomDocument xmlDoc(_("k3b_audio_project"));
756 
757  xmlDoc.appendChild(xmlDoc.createProcessingInstruction(
758  _("xml"), _("version=\"1.0\" encoding=\"UTF-8\"")
759  ));
760  QDomElement docElem = xmlDoc.createElement(_("k3b_audio_project"));
761  xmlDoc.appendChild(docElem);
762  saveDocumentData(&docElem);
763  QTextStream xmlStream(&out);
764  xmlDoc.save(xmlStream, 0);
765 
766  out.close();
767 
768  zip.setCompression(KZip::NoCompression);
769  zip.setExtraField(KZip::NoExtraField);
770  zip.writeFile(_("maindata.xml"), xml.data());
771  zip.close();
772 
773  return 0;
774 }
void saveDocumentData(QDomElement *docElem)
#define _(m)
Definition: memcpy.c:66
#define K3B_PROJECT_MIME_TYPE
Here is the call graph for this function:
Here is the caller graph for this function:

◆ scanBlocksToSave()

void Kwave::K3BExportPlugin::scanBlocksToSave ( const QString &  base,
sample_index_t  selection_left,
sample_index_t  selection_right 
)
protected

determines the blocks which should be saved, including start position, length and title.

Parameters
basethe base name, without indices, extension etc...
selection_leftindex of the first sample
selection_rightindex of the last sample

Definition at line 136 of file K3BExportPlugin.cpp.

References detectBlockMetaData(), Kwave::FileInfo::get(), Kwave::INF_AUTHOR, Kwave::INF_NAME, Kwave::MetaData::isNull(), Kwave::K3BExportPlugin::BlockInfo::m_artist, m_block_info, Kwave::K3BExportPlugin::BlockInfo::m_filename, Kwave::K3BExportPlugin::BlockInfo::m_index, Kwave::K3BExportPlugin::BlockInfo::m_length, m_pattern, Kwave::K3BExportPlugin::BlockInfo::m_start, Kwave::K3BExportPlugin::BlockInfo::m_title, Kwave::Label::name(), Kwave::Label::pos(), Kwave::Plugin::signalLength(), and Kwave::Plugin::signalManager().

Referenced by start().

139 {
140  sample_index_t block_start;
141  sample_index_t block_end = 0;
142 
143  Kwave::LabelList labels(signalManager().metaData());
144  Kwave::LabelListIterator it(labels);
145  Kwave::Label label = (it.hasNext()) ? it.next() : Kwave::Label();
146 
147  // get the title of the whole file, in case that a block does not have
148  // an own title
149  FileInfo info(signalManager().metaData());
150  QString file_title = info.get(INF_NAME).toString();
151  QString file_artist = info.get(INF_AUTHOR).toString();
152 
153  // fallback: if there is no INF_NAME either, fall back to the file
154  // name as last resort
155  if (!file_title.length()) file_title = base;
156 
157  m_block_info.clear();
158  QString prev_title = file_title;
159  for (unsigned int index = 1; ; ++index) {
160  block_start = block_end;
161  block_end = (label.isNull()) ? signalLength() : label.pos();
162 
163  QString block_title = (!label.isNull() && label.name().length()) ?
164  label.name() : prev_title;
165 
166  if ((block_end > selection_left) && (block_start <= selection_right)) {
167  BlockInfo block;
168 
169  // init and set reasonable defaults
170  block.m_index = index;
171  block.m_filename = QString();
172  block.m_start = block_start;
173  block.m_length = block_end - block_start;
174  block.m_title = prev_title;
175  block.m_artist = file_artist;
176 
177  // detect title and artist
178  detectBlockMetaData(prev_title, m_pattern, block);
179  m_block_info.append(block);
180 
181  prev_title = block_title;
182 
183 // qDebug("#%d [%llu...%llu]", index, block_start, block_end);
184 // qDebug(" title = '%s'", DBG(block.m_title));
185 // qDebug(" artist = '%s'", DBG(block.m_artist));
186  } else {
187  prev_title = block_title;
188  }
189 
190  if (label.isNull()) break;
191  label = (it.hasNext()) ? it.next() : Kwave::Label();
192  }
193 }
Kwave::SignalManager & signalManager()
Definition: Plugin.cpp:444
virtual sample_index_t pos() const
Definition: Label.cpp:56
quint64 sample_index_t
Definition: Sample.h:28
QListIterator< Kwave::Label > LabelListIterator
Definition: LabelList.h:76
virtual bool isNull() const
Definition: MetaData.cpp:69
virtual QString name() const
Definition: Label.cpp:74
virtual sample_index_t signalLength()
Definition: Plugin.cpp:462
bool detectBlockMetaData(const QString &text, const QString &pattern, BlockInfo &block)
QVector< BlockInfo > m_block_info
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup()

QStringList * Kwave::K3BExportPlugin::setup ( QStringList &  params)
virtual

Normally this method is used to set up all necessary parameters for executing the plugin. This plugin uses it for performing actions in the context of the GUI thread.

Parameters
paramssome parameters
Returns
string list with parameters or null pointer

Reimplemented from Kwave::Plugin.

Definition at line 280 of file K3BExportPlugin.cpp.

References _, Kwave::Plugin::description(), Kwave::Plugin::emitCommand(), Kwave::Parser::escape(), interpreteParameters(), K3B_FILE_SUFFIX, m_export_location, m_overwrite_policy, m_pattern, m_selection_only, Kwave::Plugin::name(), Kwave::Plugin::parentWidget(), Kwave::Plugin::selection(), Kwave::Plugin::signalLength(), and Kwave::Plugin::signalName().

281 {
282  // try to interpret the previous parameters
283  interpreteParameters(params);
284 
285  sample_index_t selection_left = 0;
286  sample_index_t selection_right = 0;
287  selection(Q_NULLPTR, &selection_left, &selection_right, false);
288 
289  // enable the "selection only" checkbox only if there is something
290  // selected but not everything
291  bool selected_something = (selection_left != selection_right);
292  bool selected_all = ((selection_left == 0) &&
293  (selection_right + 1 >= signalLength()));
294  bool enable_selection_only = selected_something && !selected_all;
295 
296  // show a "File / Save As..." dialog for the *.k3b file
297  QPointer<Kwave::K3BExportDialog> dialog =
298  new(std::nothrow) Kwave::K3BExportDialog(
299  _("kfiledialog:///kwave_export_k3b"),
300  K3B_FILE_SUFFIX + _("|") + i18nc(
301  "file type filter when exporting to K3b",
302  "K3b project file (*.k3b)"
303  ),
304  parentWidget(),
305  QUrl::fromUserInput(signalName()),
306  _("*.k3b"),
307  m_pattern,
309  enable_selection_only,
312  );
313  if (!dialog) return Q_NULLPTR;
314 
315  dialog->setWindowTitle(description());
316  if (dialog->exec() != QDialog::Accepted) {
317  delete dialog;
318  return Q_NULLPTR;
319  }
320 
321  QStringList *list = new(std::nothrow) QStringList();
322  Q_ASSERT(list);
323  if (!list) {
324  delete dialog;
325  return Q_NULLPTR;
326  }
327 
328  // user has pressed "OK"
329  QUrl url = dialog->selectedUrl();
330  if (url.isEmpty()) {
331  delete dialog;
332  delete list;
333  return Q_NULLPTR;
334  }
335 
336  QString name = url.path();
337  QFileInfo path(name);
338 
339  // add the correct extension if necessary
340  if (path.suffix() != K3B_FILE_SUFFIX.mid(2))
341  url.setPath(name + K3B_FILE_SUFFIX.mid(1));
342 
343  name = Kwave::Parser::escape(url.toString());
344  QString pattern = Kwave::Parser::escape(dialog->pattern());
345  int export_location = static_cast<int>(dialog->exportLocation());
346  int overwrite_policy = static_cast<int>(dialog->overwritePolicy());
347  bool selection_only = (enable_selection_only) ?
348  dialog->selectionOnly() : m_selection_only;
349 
350  *list << name; // url
351  *list << pattern; // pattern
352  *list << QString::number(selection_only); // selection only
353  *list << QString::number(export_location); // export location
354  *list << QString::number(overwrite_policy); // overwrite policy
355 
356  emitCommand(_("plugin:execute(export_k3b,") +
357  name + _(",") + pattern + _(",") +
358  QString::number(selection_only) + _(",") +
359  QString::number(export_location) + _(",") +
360  QString::number(overwrite_policy) + _(")")
361  );
362 
363  if (dialog) delete dialog;
364  return list;
365 }
void emitCommand(const QString &command)
Definition: Plugin.cpp:510
overwrite_policy_t m_overwrite_policy
#define K3B_FILE_SUFFIX
QWidget * parentWidget() const
Definition: Plugin.cpp:450
export_location_t m_export_location
virtual QString name() const
Definition: Plugin.cpp:196
quint64 sample_index_t
Definition: Sample.h:28
int interpreteParameters(QStringList &params)
virtual sample_index_t signalLength()
Definition: Plugin.cpp:462
QString signalName()
Definition: Plugin.cpp:456
#define _(m)
Definition: memcpy.c:66
static QString escape(const QString &text)
Definition: Parser.cpp:277
virtual QString description() const
Definition: Plugin.cpp:202
virtual sample_index_t selection(QList< unsigned int > *tracks=Q_NULLPTR, sample_index_t *left=Q_NULLPTR, sample_index_t *right=Q_NULLPTR, bool expand_if_empty=false)
Definition: Plugin.cpp:480
Here is the call graph for this function:

◆ start()

int Kwave::K3BExportPlugin::start ( QStringList &  params)
virtual

Saves the K3b project file, using the settings made in "setup()"

See also
Kwave::Plugin::start()

Reimplemented from Kwave::Plugin.

Definition at line 568 of file K3BExportPlugin.cpp.

References _, createFileName(), DBG, EXPORT_TO_SUB_DIR, interpreteParameters(), m_block_info, m_export_location, m_overwrite_policy, m_selection_only, m_url, Kwave::Plugin::name(), OUTFILE_PATTERN, OUTFILE_SUFFIX, Kwave::Plugin::parentWidget(), Kwave::MessageBox::questionYesNo(), saveBlocks(), saveK3BFile(), scanBlocksToSave(), Kwave::Plugin::selection(), Kwave::Plugin::signalLength(), Kwave::MessageBox::sorry(), and USE_NEW_FILE_NAMES.

569 {
570  qDebug("K3BExportPlugin::start()");
571 
572  // interpret the parameters
573  int result = interpreteParameters(params);
574  if (result) return result;
575 
576  // check the output file
577  if (!m_url.isLocalFile())
578  return -EINVAL; // sorry, KZip supports only local files
579 
580  // determine output directory and file name pattern
581  QString k3b_filename = m_url.path();
582  QFileInfo fi(k3b_filename);
583  QString base = fi.completeBaseName();
584  QString out_dir;
585  QString out_pattern;
587  // export to a subdir with the name "<filename>.dir"
588  out_dir = fi.absolutePath() + QDir::separator() + base + _(".dir");
589  out_pattern = _("track-") + OUTFILE_PATTERN;
590  } else {
591  // use the same directory as the *.k3b file
592  out_dir = fi.absolutePath();
593  out_pattern = base + _("-track-") + OUTFILE_PATTERN;
594  }
595  qDebug("out_dir = '%s'", DBG(out_dir));
596  qDebug("out_pattern = '%s'", DBG(out_pattern));
597 
598  // determine the selection settings
599  sample_index_t selection_left = 0;
600  sample_index_t selection_right = 0;
601  QList<unsigned int> tracks;
602  selection(&tracks, &selection_left, &selection_right, false);
603 
604  // check: only mono or stereo files are supported
605  if ((tracks.count() != 1) && (tracks.count() != 2)) {
606  qWarning("sorry, K3b can not handle %u tracks", tracks.count());
608  "Only mono and stereo files can be used for an audio CD. "
609  "You can either deselect some channels or export the file "
610  "in a different file format that supports mono and stereo "
611  "only (for example FLAC) and then try again."
612  ));
613  return -EINVAL;
614  }
615 
616  bool selected_something = (selection_left != selection_right);
617  bool selected_all = ( (selection_left == 0) &&
618  ((selection_right + 1) >= signalLength()) );
619  bool enable_selection_only = selected_something && !selected_all;
620  bool selection_only = enable_selection_only && m_selection_only;
621  if (!selection_only) {
622  selection_left = 0;
623  selection_right = signalLength() - 1;
624  }
625 
626  // create a list of blocks to save, but not yet the output file names
627  scanBlocksToSave(base, selection_left, selection_right);
628  unsigned int count = m_block_info.count();
629  if (!count)
630  return -EINVAL;
631 
632  // find the start index of the file numbering
633  unsigned int first = 1;
635  // use new files, find out the highest existing index
636  QString pat = out_pattern;
637  pat.replace(OUTFILE_PATTERN, _("*"));
638  pat += OUTFILE_SUFFIX;
639 
640  QDir dir(out_dir, pat);
641  QStringList files;
642  files = dir.entryList();
643 
644  for (unsigned int i = first; i < (first + count); ++i) {
645  QString name = createFileName(out_pattern, i);
646  QRegExp rx(_("^(") + name + _(")$"), Qt::CaseInsensitive);
647  QStringList matches = files.filter(rx);
648  if (matches.count() > 0) first = i + 1;
649  }
650  qDebug("found first usable index -> %d", first);
651  } else {
652  // overwrite mode, always start at 1
653  }
654 
655  // create the complete file names
656  for (unsigned int i = 0; i < count; ++i) {
657  m_block_info[i].m_filename = out_dir + QDir::separator() +
658  createFileName(out_pattern, first + i);
659  }
660 
661  result = saveBlocks(selection_only, out_dir, out_pattern);
662  if (result != 0)
663  return result; // aborted or failed -> do not create a k3b file
664 
665  result = saveK3BFile(k3b_filename);
666  if (result != 0)
667  return result; // aborted or failed -> do not ask about starting k3b
668 
670  "A K3b project file has been created and audio files have "
671  "been exported.\n"
672  "Should I start K3b and open the audio CD project now?"
673  )) == KMessageBox::Yes) {
674  // call k3b and pass the project file name (must be full path)
675  QStringList args;
676  args << k3b_filename;
677  if (!QProcess::startDetached(_("k3b"), args)) {
678  return -EIO;
679  }
680  }
681 
682  return result;
683 }
int saveK3BFile(const QString &k3b_filename)
overwrite_policy_t m_overwrite_policy
QWidget * parentWidget() const
Definition: Plugin.cpp:450
export_location_t m_export_location
static int sorry(QWidget *widget, QString message, QString caption=QString())
Definition: MessageBox.cpp:85
virtual QString name() const
Definition: Plugin.cpp:196
static int questionYesNo(QWidget *widget, QString message, QString caption=QString(), const QString buttonYes=QString(), const QString buttonNo=QString(), const QString &dontAskAgainName=QString())
Definition: MessageBox.cpp:63
quint64 sample_index_t
Definition: Sample.h:28
QString createFileName(const QString &pattern, unsigned int index)
int interpreteParameters(QStringList &params)
virtual sample_index_t signalLength()
Definition: Plugin.cpp:462
#define OUTFILE_SUFFIX
#define _(m)
Definition: memcpy.c:66
#define DBG(qs)
Definition: String.h:55
void scanBlocksToSave(const QString &base, sample_index_t selection_left, sample_index_t selection_right)
#define OUTFILE_PATTERN
QVector< BlockInfo > m_block_info
virtual sample_index_t selection(QList< unsigned int > *tracks=Q_NULLPTR, sample_index_t *left=Q_NULLPTR, sample_index_t *right=Q_NULLPTR, bool expand_if_empty=false)
Definition: Plugin.cpp:480
int saveBlocks(bool selection_only, const QString &out_dir, const QString &out_pattern)
Here is the call graph for this function:

Member Data Documentation

◆ m_block_info

QVector<BlockInfo> Kwave::K3BExportPlugin::m_block_info
private

list of all blocks to save

Definition at line 171 of file K3BExportPlugin.h.

Referenced by saveDocumentData(), scanBlocksToSave(), and start().

◆ m_export_location

export_location_t Kwave::K3BExportPlugin::m_export_location
private

where to export the files of the tracks, subdir, same dir, ...

Definition at line 165 of file K3BExportPlugin.h.

Referenced by interpreteParameters(), setup(), and start().

◆ m_overwrite_policy

overwrite_policy_t Kwave::K3BExportPlugin::m_overwrite_policy
private

overwrite existing files or create a new file name

Definition at line 168 of file K3BExportPlugin.h.

Referenced by interpreteParameters(), saveBlocks(), setup(), and start().

◆ m_pattern

QString Kwave::K3BExportPlugin::m_pattern
private

pattern for detecting title and artist

Definition at line 159 of file K3BExportPlugin.h.

Referenced by interpreteParameters(), scanBlocksToSave(), and setup().

◆ m_selection_only

bool Kwave::K3BExportPlugin::m_selection_only
private

if true, export only the selected range

Definition at line 162 of file K3BExportPlugin.h.

Referenced by interpreteParameters(), setup(), and start().

◆ m_url

QUrl Kwave::K3BExportPlugin::m_url
private

the URL of the project file

Definition at line 156 of file K3BExportPlugin.h.

Referenced by interpreteParameters(), saveBlocks(), and start().


The documentation for this class was generated from the following files: