Commit 006135be authored by Urs Fleisch's avatar Urs Fleisch
Browse files

FormatListEdit to edit sets of format strings.

parent 5ff1e11b
......@@ -30,8 +30,6 @@
#include <QTextEdit>
#include <QString>
#include <QLineEdit>
#include <QComboBox>
#include <QToolTip>
#include <QMessageBox>
#include <QRegExp>
#include <QUrl>
......@@ -43,6 +41,7 @@
#include "externalprocess.h"
#include "configtable.h"
#include "configtablemodel.h"
#include "formatlistedit.h"
#include "qtcompatmac.h"
/**
......@@ -105,19 +104,19 @@ BrowseCoverArtDialog::BrowseCoverArtDialog(QWidget* parent) :
QGroupBox* srcbox = new QGroupBox(i18n("&Source"), this);
if (srcbox) {
m_sourceComboBox = new QComboBox(srcbox);
m_sourceComboBox->setEditable(true);
m_urlLineEdit = new QLineEdit(srcbox);
m_urlLineEdit->setToolTip(getToolTip());
m_formatListEdit = new FormatListEdit(
QStringList() << i18n("Source:")
<< i18n("URL:"),
QStringList() << QString()
<< getToolTip(),
srcbox);
QVBoxLayout* vbox = new QVBoxLayout;
vbox->setMargin(2);
vbox->addWidget(m_sourceComboBox);
vbox->addWidget(m_urlLineEdit);
vbox->addWidget(m_formatListEdit);
srcbox->setLayout(vbox);
vlayout->addWidget(srcbox);
connect(m_sourceComboBox, SIGNAL(activated(int)), this,
SLOT(setSourceLineEdit(int)));
connect(m_urlLineEdit, SIGNAL(returnPressed()),
connect(m_formatListEdit, SIGNAL(formatChanged()),
this, SLOT(showPreview()));
}
......@@ -178,21 +177,6 @@ BrowseCoverArtDialog::~BrowseCoverArtDialog()
delete m_process;
}
/**
* Set the format lineedits to the format selected in the combo box.
*
* @param index current index of the combo box
*/
void BrowseCoverArtDialog::setSourceLineEdit(int index)
{
if (index < static_cast<int>(m_urls.size())) {
m_urlLineEdit->setText(m_urls[index]);
} else {
m_urlLineEdit->clear();
}
showPreview();
}
/**
* Show browse command as preview.
*/
......@@ -200,7 +184,7 @@ void BrowseCoverArtDialog::showPreview()
{
m_frames.setArtist(m_artistLineEdit->text());
m_frames.setAlbum(m_albumLineEdit->text());
FrameFormatReplacer fmt(m_frames, m_urlLineEdit->text());
FrameFormatReplacer fmt(m_frames, m_formatListEdit->getCurrentFormat(1));
fmt.replaceEscapedChars();
fmt.replacePercentCodes(FormatReplacer::FSF_SupportUrlEncode);
m_url = fmt.getString();
......@@ -237,11 +221,10 @@ void BrowseCoverArtDialog::setFrames(const FrameCollection& frames)
*/
void BrowseCoverArtDialog::setSourceFromConfig()
{
m_urls = ConfigStore::s_genCfg.m_pictureSourceUrls;
m_sourceComboBox->clear();
m_sourceComboBox->addItems(ConfigStore::s_genCfg.m_pictureSourceNames);
m_sourceComboBox->setCurrentIndex(ConfigStore::s_genCfg.m_pictureSourceIdx);
setSourceLineEdit(ConfigStore::s_genCfg.m_pictureSourceIdx);
m_formatListEdit->setFormats(
QList<QStringList>() << ConfigStore::s_genCfg.m_pictureSourceNames
<< ConfigStore::s_genCfg.m_pictureSourceUrls,
ConfigStore::s_genCfg.m_pictureSourceIdx);
}
/**
......@@ -264,19 +247,10 @@ void BrowseCoverArtDialog::readConfig()
*/
void BrowseCoverArtDialog::saveConfig()
{
ConfigStore::s_genCfg.m_pictureSourceIdx = m_sourceComboBox->currentIndex();
if (ConfigStore::s_genCfg.m_pictureSourceIdx <
static_cast<int>(ConfigStore::s_genCfg.m_pictureSourceNames.size())) {
ConfigStore::s_genCfg.m_pictureSourceNames[ConfigStore::s_genCfg.m_pictureSourceIdx] =
m_sourceComboBox->currentText();
ConfigStore::s_genCfg.m_pictureSourceUrls[ConfigStore::s_genCfg.m_pictureSourceIdx] =
m_urlLineEdit->text();
} else {
ConfigStore::s_genCfg.m_pictureSourceIdx =
ConfigStore::s_genCfg.m_pictureSourceNames.size();
ConfigStore::s_genCfg.m_pictureSourceNames.append(m_sourceComboBox->currentText());
ConfigStore::s_genCfg.m_pictureSourceUrls.append(m_urlLineEdit->text());
}
QList<QStringList> formats = m_formatListEdit->getFormats(
&ConfigStore::s_genCfg.m_pictureSourceIdx);
ConfigStore::s_genCfg.m_pictureSourceNames = formats.at(0);
ConfigStore::s_genCfg.m_pictureSourceUrls = formats.at(1);
ConfigStore::s_genCfg.m_matchPictureUrlMap = m_matchUrlTableModel->getMap();
ConfigStore::s_genCfg.m_browseCoverArtWindowWidth = size().width();
ConfigStore::s_genCfg.m_browseCoverArtWindowHeight = size().height();
......
......@@ -28,15 +28,14 @@
#define BROWSECOVERARTDIALOG_H
#include <QDialog>
#include <QStringList>
#include "frame.h"
class QTextEdit;
class QLineEdit;
class QComboBox;
class ExternalProcess;
class ConfigTable;
class ConfigTableModel;
class FormatListEdit;
/**
* Browse cover art dialog.
......@@ -75,13 +74,6 @@ public slots:
*/
virtual void accept();
/**
* Set the source lineedits to the source selected in the combo box.
*
* @param index current index of the combo box
*/
void setSourceLineEdit(int index);
private slots:
/**
* Show browse command as preview.
......@@ -110,16 +102,12 @@ private:
QLineEdit* m_artistLineEdit;
/** Combobox with album */
QLineEdit* m_albumLineEdit;
/** Combobox with sources */
QComboBox* m_sourceComboBox;
/** LineEdit for URL */
QLineEdit* m_urlLineEdit;
/** format editor */
FormatListEdit* m_formatListEdit;
/** Table to extract picture URL */
ConfigTable* m_matchUrlTable;
/** Table model to extract picture URL */
ConfigTableModel* m_matchUrlTableModel;
/** URLs */
QStringList m_urls;
/** Formatted URL */
QString m_url;
......
......@@ -40,15 +40,12 @@
#include <QString>
#include <QTextEdit>
#include <QTableView>
#include <QLineEdit>
#include <QComboBox>
#include <QDir>
#include <QApplication>
#include <QClipboard>
#include <QUrl>
#include <QToolTip>
#include <QMessageBox>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include "taggedfile.h"
......@@ -57,6 +54,7 @@
#include "contexthelp.h"
#include "textexporter.h"
#include "texttablemodel.h"
#include "formatlistedit.h"
#include "qtcompatmac.h"
/**
......@@ -88,31 +86,20 @@ ExportDialog::ExportDialog(QWidget* parent, TextExporter* textExporter) :
m_table->hide();
vlayout->addWidget(m_table);
QGroupBox* fmtbox = new QGroupBox(i18n("&Format"), this);
if (fmtbox) {
m_formatComboBox = new QComboBox(fmtbox);
m_formatComboBox->setEditable(true);
m_headerLineEdit = new QLineEdit(fmtbox);
m_trackLineEdit = new QLineEdit(fmtbox);
m_trailerLineEdit = new QLineEdit(fmtbox);
QString formatToolTip = ImportTrackData::getFormatToolTip();
m_headerLineEdit->setToolTip(formatToolTip);
m_trackLineEdit->setToolTip(formatToolTip);
m_trailerLineEdit->setToolTip(formatToolTip);
QVBoxLayout* vbox = new QVBoxLayout;
vbox->setMargin(2);
vbox->addWidget(m_formatComboBox);
vbox->addWidget(m_headerLineEdit);
vbox->addWidget(m_trackLineEdit);
vbox->addWidget(m_trailerLineEdit);
fmtbox->setLayout(vbox);
vlayout->addWidget(fmtbox);
connect(m_formatComboBox, SIGNAL(activated(int)), this,
SLOT(setFormatLineEdit(int)));
connect(m_headerLineEdit, SIGNAL(returnPressed()), this, SLOT(showPreview()));
connect(m_trackLineEdit, SIGNAL(returnPressed()), this, SLOT(showPreview()));
connect(m_trailerLineEdit, SIGNAL(returnPressed()), this, SLOT(showPreview()));
}
QString formatToolTip = ImportTrackData::getFormatToolTip();
m_formatListEdit = new FormatListEdit(
QStringList() << i18n("Format:")
<< i18n("Header:")
<< i18n("Tracks:")
<< i18n("Footer"),
QStringList() << QString()
<< formatToolTip
<< formatToolTip
<< formatToolTip,
this);
connect(m_formatListEdit, SIGNAL(formatChanged()),
this, SLOT(showPreview()));
vlayout->addWidget(m_formatListEdit);
QHBoxLayout* butlayout = new QHBoxLayout;
if (butlayout) {
......@@ -220,35 +207,17 @@ void ExportDialog::slotToClipboard()
m_textExporter->getText(), QClipboard::Clipboard);
}
/**
* Set the format lineedits to the format selected in the combo box.
*
* @param index current index of the combo box
*/
void ExportDialog::setFormatLineEdit(int index)
{
if (index < static_cast<int>(m_formatHeaders.size())) {
m_headerLineEdit->setText(m_formatHeaders[index]);
m_trackLineEdit->setText(m_formatTracks[index]);
m_trailerLineEdit->setText(m_formatTrailers[index]);
} else {
m_headerLineEdit->clear();
m_trackLineEdit->clear();
m_trailerLineEdit->clear();
}
showPreview();
}
/**
* Show exported text as preview in editor.
*/
void ExportDialog::showPreview()
{
m_textExporter->updateText(m_headerLineEdit->text(),
m_trackLineEdit->text(),
m_trailerLineEdit->text());
m_textExporter->updateText(m_formatListEdit->getCurrentFormat(1),
m_formatListEdit->getCurrentFormat(2),
m_formatListEdit->getCurrentFormat(3));
QString text(m_textExporter->getText());
if (m_textTableModel->setText(text, !m_headerLineEdit->text().isEmpty())) {
if (m_textTableModel->setText(
text, !m_formatListEdit->getCurrentFormat(1).isEmpty())) {
m_table->resizeColumnsToContents();
m_table->show();
m_edit->hide();
......@@ -264,13 +233,12 @@ void ExportDialog::showPreview()
*/
void ExportDialog::setFormatFromConfig()
{
m_formatHeaders = ConfigStore::s_genCfg.m_exportFormatHeaders;
m_formatTracks = ConfigStore::s_genCfg.m_exportFormatTracks;
m_formatTrailers = ConfigStore::s_genCfg.m_exportFormatTrailers;
m_formatComboBox->clear();
m_formatComboBox->addItems(ConfigStore::s_genCfg.m_exportFormatNames);
m_formatComboBox->setCurrentIndex(ConfigStore::s_genCfg.m_exportFormatIdx);
setFormatLineEdit(ConfigStore::s_genCfg.m_exportFormatIdx);
m_formatListEdit->setFormats(
QList<QStringList>() << ConfigStore::s_genCfg.m_exportFormatNames
<< ConfigStore::s_genCfg.m_exportFormatHeaders
<< ConfigStore::s_genCfg.m_exportFormatTracks
<< ConfigStore::s_genCfg.m_exportFormatTrailers,
ConfigStore::s_genCfg.m_exportFormatIdx);
}
/**
......@@ -297,19 +265,12 @@ void ExportDialog::saveConfig()
{
ConfigStore::s_genCfg.m_exportSrcV1 = TrackData::tagVersionCast(
m_srcComboBox->itemData(m_srcComboBox->currentIndex()).toInt());
ConfigStore::s_genCfg.m_exportFormatIdx = m_formatComboBox->currentIndex();
if (ConfigStore::s_genCfg.m_exportFormatIdx < static_cast<int>(ConfigStore::s_genCfg.m_exportFormatNames.size())) {
ConfigStore::s_genCfg.m_exportFormatNames[ConfigStore::s_genCfg.m_exportFormatIdx] = m_formatComboBox->currentText();
ConfigStore::s_genCfg.m_exportFormatHeaders[ConfigStore::s_genCfg.m_exportFormatIdx] = m_headerLineEdit->text();
ConfigStore::s_genCfg.m_exportFormatTracks[ConfigStore::s_genCfg.m_exportFormatIdx] = m_trackLineEdit->text();
ConfigStore::s_genCfg.m_exportFormatTrailers[ConfigStore::s_genCfg.m_exportFormatIdx] = m_trailerLineEdit->text();
} else {
ConfigStore::s_genCfg.m_exportFormatIdx = ConfigStore::s_genCfg.m_exportFormatNames.size();
ConfigStore::s_genCfg.m_exportFormatNames.append(m_formatComboBox->currentText());
ConfigStore::s_genCfg.m_exportFormatHeaders.append(m_headerLineEdit->text());
ConfigStore::s_genCfg.m_exportFormatTracks.append(m_trackLineEdit->text());
ConfigStore::s_genCfg.m_exportFormatTrailers.append(m_trailerLineEdit->text());
}
QList<QStringList> formats = m_formatListEdit->getFormats(
&ConfigStore::s_genCfg.m_exportFormatIdx);
ConfigStore::s_genCfg.m_exportFormatNames = formats.at(0);
ConfigStore::s_genCfg.m_exportFormatHeaders = formats.at(1);
ConfigStore::s_genCfg.m_exportFormatTracks = formats.at(2);
ConfigStore::s_genCfg.m_exportFormatTrailers = formats.at(3);
ConfigStore::s_genCfg.m_exportWindowWidth = size().width();
ConfigStore::s_genCfg.m_exportWindowHeight = size().height();
......
......@@ -33,11 +33,11 @@
class QTextEdit;
class QTableView;
class QLineEdit;
class QPushButton;
class QComboBox;
class TextExporter;
class TextTableModel;
class FormatListEdit;
/**
* Export dialog.
......@@ -71,13 +71,6 @@ public slots:
void showPreview();
private slots:
/**
* Set the format lineedits to the format selected in the combo box.
*
* @param index current index of the combo box
*/
void setFormatLineEdit(int index);
/**
* Export to a file.
*/
......@@ -114,26 +107,14 @@ private:
QTextEdit* m_edit;
/** Table view */
QTableView* m_table;
/** cobobox with formats */
QComboBox* m_formatComboBox;
/** LineEdit for header */
QLineEdit* m_headerLineEdit;
/** LineEdit for track */
QLineEdit* m_trackLineEdit;
/** LineEdit for trailer */
QLineEdit* m_trailerLineEdit;
/** Format editor */
FormatListEdit* m_formatListEdit;
/** To File button */
QPushButton* m_fileButton;
/** To Clipboard button */
QPushButton* m_clipButton;
/** combobox with export sources */
QComboBox* m_srcComboBox;
/** header formats */
QStringList m_formatHeaders;
/** track formats */
QStringList m_formatTracks;
/** trailer formats */
QStringList m_formatTrailers;
/** text exporter */
TextExporter* m_textExporter;
......
......@@ -30,14 +30,11 @@
#include <QLabel>
#include <QSpinBox>
#include <QString>
#include <QLineEdit>
#include <QComboBox>
#include <QToolTip>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include "configstore.h"
#include "contexthelp.h"
#include "formatlistedit.h"
#include "qtcompatmac.h"
/**
......@@ -64,21 +61,13 @@ FilterDialog::FilterDialog(QWidget* parent) : QDialog(parent)
vlayout->addWidget(m_edit);
}
QGroupBox* fltbox = new QGroupBox(i18n("&Filter"), this);
if (fltbox) {
m_nameComboBox = new QComboBox(fltbox);
m_nameComboBox->setEditable(true);
m_filterLineEdit = new QLineEdit(fltbox);
m_filterLineEdit->setToolTip(FileFilter::getFormatToolTip());
QVBoxLayout* vbox = new QVBoxLayout;
vbox->setMargin(2);
vbox->addWidget(m_nameComboBox);
vbox->addWidget(m_filterLineEdit);
fltbox->setLayout(vbox);
vlayout->addWidget(fltbox);
connect(m_nameComboBox, SIGNAL(activated(int)), this,
SLOT(setFilterLineEdit(int)));
}
m_formatListEdit = new FormatListEdit(
QStringList() << i18n("&Filter:")
<< i18n("&Expression:"),
QStringList() << QString()
<< FileFilter::getFormatToolTip(),
this);
vlayout->addWidget(m_formatListEdit);
QHBoxLayout* hlayout = new QHBoxLayout;
if (hlayout) {
......@@ -128,38 +117,22 @@ FilterDialog::~FilterDialog()
void FilterDialog::applyFilter()
{
m_edit->clear();
m_fileFilter.setFilterExpression(m_filterLineEdit->text());
m_fileFilter.setFilterExpression(m_formatListEdit->getCurrentFormat(1));
m_fileFilter.initParser();
m_applyButton->setEnabled(false);
emit apply(m_fileFilter);
m_applyButton->setEnabled(true);
}
/**
* Set the filter lineedit to the format selected in the combo box.
*
* @param index current index of the combo box
*/
void FilterDialog::setFilterLineEdit(int index)
{
if (index < static_cast<int>(m_filterNames.size())) {
m_filterLineEdit->setText(m_filterExpressions[index]);
} else {
m_filterLineEdit->clear();
}
}
/**
* Set the filter combo box and line edit from the configuration.
*/
void FilterDialog::setFiltersFromConfig()
{
m_filterNames = ConfigStore::s_filterCfg.m_filterNames;
m_filterExpressions = ConfigStore::s_filterCfg.m_filterExpressions;
m_nameComboBox->clear();
m_nameComboBox->addItems(ConfigStore::s_filterCfg.m_filterNames);
m_nameComboBox->setCurrentIndex(ConfigStore::s_filterCfg.m_filterIdx);
setFilterLineEdit(ConfigStore::s_filterCfg.m_filterIdx);
m_formatListEdit->setFormats(
QList<QStringList>() << ConfigStore::s_filterCfg.m_filterNames
<< ConfigStore::s_filterCfg.m_filterExpressions,
ConfigStore::s_filterCfg.m_filterIdx);
}
/**
......@@ -185,19 +158,10 @@ void FilterDialog::readConfig()
*/
void FilterDialog::saveConfig()
{
ConfigStore::s_filterCfg.m_filterIdx = m_nameComboBox->currentIndex();
if (ConfigStore::s_filterCfg.m_filterIdx <
static_cast<int>(ConfigStore::s_filterCfg.m_filterNames.size())) {
ConfigStore::s_filterCfg.m_filterNames[ConfigStore::s_filterCfg.m_filterIdx] =
m_nameComboBox->currentText();
ConfigStore::s_filterCfg.m_filterExpressions[ConfigStore::s_filterCfg.m_filterIdx] =
m_filterLineEdit->text();
} else {
ConfigStore::s_filterCfg.m_filterIdx =
ConfigStore::s_filterCfg.m_filterNames.size();
ConfigStore::s_filterCfg.m_filterNames.append(m_nameComboBox->currentText());
ConfigStore::s_filterCfg.m_filterExpressions.append(m_filterLineEdit->text());
}
QList<QStringList> formats = m_formatListEdit->getFormats(
&ConfigStore::s_filterCfg.m_filterIdx);
ConfigStore::s_filterCfg.m_filterNames = formats.at(0);
ConfigStore::s_filterCfg.m_filterExpressions = formats.at(1);
ConfigStore::s_filterCfg.m_windowWidth = size().width();
ConfigStore::s_filterCfg.m_windowHeight = size().height();
......
......@@ -28,13 +28,11 @@
#define FILTERDIALOG_H
#include <QDialog>
#include <QStringList>
#include <QTextEdit>
#include "filefilter.h"
class QLineEdit;
class QComboBox;
class QPushButton;
class FormatListEdit;
/**
* Filter dialog.
......@@ -74,13 +72,6 @@ signals:
void apply(FileFilter&);
public slots:
/**
* Set the filter lineedit to the filter selected in the combo box.
*
* @param index current index of the combo box
*/
void setFilterLineEdit(int index);
/**
* Show information about filter event.
*
......@@ -114,16 +105,10 @@ private:
/** Text editor */
QTextEdit* m_edit;
/** cobobox with filter names */
QComboBox* m_nameComboBox;
/** LineEdit for filter expression */
QLineEdit* m_filterLineEdit;
/** format editor */
FormatListEdit* m_formatListEdit;
/** Apply button */
QPushButton* m_applyButton;
/** filter names */
QStringList m_filterNames;
/** filter expressions */
QStringList m_filterExpressions;
/** file filter used */
FileFilter m_fileFilter;
};
......
......@@ -26,15 +26,13 @@
#include "tagimportdialog.h"
#include <QHBoxLayout>
#include <QFormLayout>
#include <QComboBox>
#include <QLineEdit>
#include <QPushButton>
#include "textimporter.h"
#include "importparser.h"
#include "trackdatamodel.h"
#include "configstore.h"
#include "contexthelp.h"
#include "formatlistedit.h"
#include "qtcompatmac.h"
/**
......@@ -55,19 +53,15 @@ TagImportDialog::TagImportDialog(QWidget* parent,
vboxLayout->setSpacing(6);
vboxLayout->setMargin(6);
m_formatComboBox = new QComboBox(this);
m_formatComboBox->setEditable(true);
m_sourceLineEdit = new QLineEdit(this);
m_extractionLineEdit = new QLineEdit(this);
m_sourceLineEdit->setToolTip(TrackDataFormatReplacer::getToolTip());
m_extractionLineEdit->setToolTip(ImportParser::getFormatToolTip());
connect(m_formatComboBox, SIGNAL(activated(int)),
this, SLOT(setFormatLineEdit(int)));
QFormLayout* formatLayout = new QFormLayout;
formatLayout->addRow(i18n("Format:"), m_formatComboBox);
formatLayout->addRow(i18n("Source:"), m_sourceLineEdit);
formatLayout->addRow(i18n("Extraction:"), m_extractionLineEdit);
vboxLayout->addLayout(formatLayout);
m_formatListEdit = new FormatListEdit(
QStringList() << i18n("Format:")
<< i18n("Source:")
<< i18n("Extraction:"),
QStringList() << QString()
<< TrackDataFormatReplacer::getToolTip()
<< ImportParser::getFormatToolTip(),
this);
vboxLayout->addWidget(m_formatListEdit);
QHBoxLayout* buttonLayout = new QHBoxLayout;
QPushButton* helpButton = new QPushButton(i18n("&Help"), this);
......@@ -111,8 +105,8 @@ void TagImportDialog::clear()
void TagImportDialog::apply()
{
ImportTrackDataVector trackDataVector(m_trackDataModel->getTrackData());
TextImporter::importFromTags(m_sourceLineEdit->text(),
m_extractionLineEdit->text(),
TextImporter::importFromTags(m_formatListEdit->getCurrentFormat(1),
m_formatListEdit->getCurrentFormat(2),
trackDataVector);
m_trackDataModel->setTrackData(trackDataVector);
emit trackDataUpdated();
......@@ -123,28 +117,11 @@ void TagImportDialog::apply()
*/
void TagImportDialog::setFormatFromConfig()
{
m_formatSources = ConfigStore::s_genCfg.m_importTagsSources;
m_formatExtractions = ConfigStore::s_genCfg.m_importTagsExtractions;
m_formatComboBox->clear();
m_formatComboBox->addItems(ConfigStore::s_genCfg.m_importTagsNames);
m_formatComboBox->setCurrentIndex(ConfigStore::s_genCfg.m_importTagsIdx);
setFormatLineEdit(ConfigStore::s_genCfg.m_importTagsIdx);
}
/**
* Set the format lineedits to the format selected in the combo box.