File indexing completed on 2024-04-28 04:50:21
0001 /* 0002 SPDX-FileCopyrightText: 1998-2008 Sebastian Trueg <trueg@k3b.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "k3bcddbpatternwidget.h" 0008 0009 #include <KConfigGroup> 0010 #include <KComboBox> 0011 #include <KLineEdit> 0012 #include <KLocalizedString> 0013 #include <KUrlLabel> 0014 0015 #include <QDebug> 0016 #include <QRegExp> 0017 #include <QValidator> 0018 #include <QCheckBox> 0019 #include <QLayout> 0020 #include <QGridLayout> 0021 #include <QWhatsThis> 0022 0023 0024 K3b::CddbPatternWidget::CddbPatternWidget( QWidget* parent ) 0025 : QWidget( parent ) 0026 { 0027 setupUi( this ); 0028 0029 // fix the layout 0030 ((QGridLayout*)layout())->setRowStretch( 4, 1 ); 0031 0032 // setup validators 0033 // there can never be one of the following characters in both dir and filename: 0034 // * ? " 0035 // additional the filename can never contain a slash / 0036 // and the dir should never start with a slash since it should always be a relative path 0037 0038 static const QRegularExpression rx( "[^/][^?\\*\\\"]*" ); 0039 auto dirValidator = new QRegularExpressionValidator( rx, this ); 0040 m_comboFilenamePattern->setValidator( dirValidator ); 0041 m_comboPlaylistPattern->setValidator( dirValidator ); 0042 m_editBlankReplace->setValidator( dirValidator ); 0043 0044 // default pattern 0045 m_comboFilenamePattern->addItem( i18nc("Please do NOT modify/translate the quotes, they are part of the pattern!", "%A - %T/%n - !a='%A'{%a - }%t") ); 0046 m_comboFilenamePattern->addItem( i18n( "%{albumartist} - %{albumtitle}/%{number} - %{artist} - %{title}" ) ); 0047 m_comboFilenamePattern->addItem( i18n( "%{genre}/%{albumartist} - %{albumtitle}/Track%{number}" ) ); 0048 m_comboFilenamePattern->addItem( i18n( "music/ripped-tracks/%a - %t" ) ); 0049 0050 m_comboPlaylistPattern->addItem( i18n( "%{albumartist} - %{albumtitle}" ) ); 0051 m_comboPlaylistPattern->addItem( i18n( "Playlist" ) ); 0052 m_comboPlaylistPattern->addItem( i18n( "playlists/%{albumartist}/%{albumtitle}" ) ); 0053 0054 connect( m_comboFilenamePattern, SIGNAL(editTextChanged(QString)), 0055 this, SIGNAL(changed()) ); 0056 connect( m_comboPlaylistPattern, SIGNAL(editTextChanged(QString)), 0057 this, SIGNAL(changed()) ); 0058 connect( m_editBlankReplace, SIGNAL(textChanged(QString)), 0059 this, SIGNAL(changed()) ); 0060 connect( m_checkBlankReplace, SIGNAL(toggled(bool)), 0061 this, SIGNAL(changed()) ); 0062 connect( m_specialStringsLabel, SIGNAL(leftClickedUrl()), 0063 this, SLOT(slotSeeSpecialStrings()) ); 0064 connect( m_conditionalInclusionLabel, SIGNAL(leftClickedUrl()), 0065 this, SLOT(slotSeeConditionalInclusion()) ); 0066 } 0067 0068 0069 K3b::CddbPatternWidget::~CddbPatternWidget() 0070 { 0071 } 0072 0073 0074 QString K3b::CddbPatternWidget::filenamePattern() const 0075 { 0076 return m_comboFilenamePattern->currentText(); 0077 } 0078 0079 0080 QString K3b::CddbPatternWidget::playlistPattern() const 0081 { 0082 return m_comboPlaylistPattern->currentText(); 0083 } 0084 0085 0086 QString K3b::CddbPatternWidget::blankReplaceString() const 0087 { 0088 return m_editBlankReplace->text(); 0089 } 0090 0091 0092 bool K3b::CddbPatternWidget::replaceBlanks() const 0093 { 0094 return m_checkBlankReplace->isChecked(); 0095 } 0096 0097 0098 void K3b::CddbPatternWidget::loadConfig( const KConfigGroup& c ) 0099 { 0100 m_comboPlaylistPattern->setEditText( c.readEntry( "playlist pattern", m_comboPlaylistPattern->itemText(0) ) ); 0101 m_comboFilenamePattern->setEditText( c.readEntry( "filename pattern", m_comboFilenamePattern->itemText(0) ) ); 0102 m_checkBlankReplace->setChecked( c.readEntry( "replace blanks", false ) ); 0103 m_editBlankReplace->setText( c.readEntry( "blank replace string", "_" ) ); 0104 } 0105 0106 0107 void K3b::CddbPatternWidget::saveConfig( KConfigGroup c ) 0108 { 0109 c.writeEntry( "playlist pattern", m_comboPlaylistPattern->currentText() ); 0110 c.writeEntry( "filename pattern", m_comboFilenamePattern->currentText() ); 0111 c.writeEntry( "replace blanks", m_checkBlankReplace->isChecked() ); 0112 c.writeEntry( "blank replace string", m_editBlankReplace->text() ); 0113 } 0114 0115 0116 void K3b::CddbPatternWidget::slotSeeSpecialStrings() 0117 { 0118 QWhatsThis::showText( m_specialStringsLabel->mapToGlobal( m_specialStringsLabel->geometry().topLeft() ), 0119 i18n( "<p><b>Pattern special strings:</b>" 0120 "<p>The following strings will be replaced with their respective meaning in every " 0121 "track name.<br>" 0122 "<em>Hint:</em> %A differs from %a only on soundtracks or compilations." 0123 "<p><table border=\"0\">" 0124 "<tr><td></td><td><em>Meaning</em></td><td><em>Alternatives</em></td></tr>" 0125 "<tr><td>%a</td><td>artist of the track</td><td>%{a} or %{artist}</td></tr>" 0126 "<tr><td>%t</td><td>title of the track</td><td>%{t} or %{title}</td></tr>" 0127 "<tr><td>%n</td><td>track number</td><td>%{n} or %{number}</td></tr>" 0128 "<tr><td>%y</td><td>year of the CD</td><td>%{y} or %{year}</td></tr>" 0129 "<tr><td>%c</td><td>extended track information</td><td>%{c} or %{comment}</td></tr>" 0130 "<tr><td>%g</td><td>genre of the CD</td><td>%{g} or %{genre}</td></tr>" 0131 "<tr><td>%A</td><td>album artist</td><td>%{A} or %{albumartist}</td></tr>" 0132 "<tr><td>%T</td><td>album title</td><td>%{T} or %{albumtitle}</td></tr>" 0133 "<tr><td>%C</td><td>extended CD information</td><td>%{C} or %{albumcomment}</td></tr>" 0134 "<tr><td>%d</td><td>current date</td><td>%{d} or %{date}</td></tr>" 0135 "<tr><td>%e</td><td>file extension (if left out, it is added automatically)</td><td>%{e} or %{ext}</td></tr>" 0136 "</table>"), 0137 m_specialStringsLabel ); 0138 } 0139 0140 void K3b::CddbPatternWidget::slotSeeConditionalInclusion() 0141 { 0142 // xgettext: no-c-format 0143 QWhatsThis::showText( m_conditionalInclusionLabel->mapToGlobal( m_conditionalInclusionLabel->geometry().topLeft() ), 0144 i18nc( "Please do NOT modify/translate the quotes, they are part of the pattern!", 0145 "<p><b>Conditional inclusion:</b>" 0146 "<p>These patterns make it possible to selectively include texts, " 0147 "depending on the value of CDDB entries. You can choose only to " 0148 "include or exclude texts if one of the entries is empty, " 0149 "or if it has a specific value. Examples:" 0150 "<ul>" 0151 "<li>@T{TEXT} includes TEXT if the album title is specified" 0152 "<li>!T{TEXT} includes TEXT if the album title is not specified" 0153 "<li>@C=\'Soundtrack\'{TEXT} includes TEXT if the CD's extended " 0154 "information is named Soundtrack" 0155 "<li>!C=\'Soundtrack\'{TEXT} includes TEXT if the CD's extended " 0156 "information is anything else but Soundtrack" 0157 "<li>It is also possible to include special strings in texts and conditions, " 0158 "e.g. !a='%A'{%a} only includes the title's artist information " 0159 "if it does not differ from the album artist." 0160 "</ul>" 0161 "<p>Conditional includes make use of the same characters as the special " 0162 "strings, which means that the X in @X{...} can be one character out of " 0163 "[atnycgATCd]." ), 0164 m_conditionalInclusionLabel ); 0165 } 0166 0167 #include "moc_k3bcddbpatternwidget.cpp"