/* * Cantata * * Copyright (c) 2011-2012 Craig Drummond * * ---- * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more detailexampleSong. * * You should have received a copy of the GNU General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "filenameschemedialog.h" #include "song.h" #include "localize.h" #include FilenameSchemeDialog::FilenameSchemeDialog(QWidget *parent) : Dialog(parent) { setButtons(Ok|Cancel); setCaption(i18n("Filename Scheme")); setWindowModality(Qt::WindowModal); QWidget *mainWidet = new QWidget(this); setupUi(mainWidet); setMainWidget(mainWidet); connect(pattern, SIGNAL(textChanged(const QString &)), this, SLOT(enableOkButton())); connect(pattern, SIGNAL(textChanged(const QString &)), this, SLOT(updateExample())); connect(help, SIGNAL(leftClickedUrl()), this, SLOT(showHelp())); connect(albumArtist, SIGNAL(clicked()), this, SLOT(insertAlbumArtist())); connect(albumTitle, SIGNAL(clicked()), this, SLOT(insertAlbumTitle())); connect(trackArtist, SIGNAL(clicked()), this, SLOT(insertTrackArtist())); connect(trackTitle, SIGNAL(clicked()), this, SLOT(insertTrackTitle())); connect(trackNo, SIGNAL(clicked()), this, SLOT(insertTrackNumber())); connect(cdNo, SIGNAL(clicked()), this, SLOT(insertCdNumber())); connect(genre, SIGNAL(clicked()), this, SLOT(insertGenre())); connect(year, SIGNAL(clicked()), this, SLOT(insertYear())); exampleSong.albumartist=i18nc("Example album artist", "Various Artists"); exampleSong.artist=i18nc("Example artist", "Wibble"); exampleSong.album=i18nc("Example album", "Now 5001"); exampleSong.title=i18nc("Example song name", "Wobble"); exampleSong.genre=i18nc("Example genre", "Dance"); exampleSong.track=1; exampleSong.disc=2; exampleSong.year=2001; exampleSong.file="wibble.mp3"; } void FilenameSchemeDialog::show(const DeviceOptions &opts) { origOpts=opts; pattern->setText(opts.scheme); example->setText(origOpts.createFilename(exampleSong)); Dialog::show(); enableButtonOk(false); } void FilenameSchemeDialog::slotButtonClicked(int button) { switch (button) { case Ok: emit scheme(pattern->text().trimmed()); break; case Cancel: reject(); break; default: break; } if (Ok==button) { accept(); } Dialog::slotButtonClicked(button); } void FilenameSchemeDialog::showHelp() { QWhatsThis::showText(help->mapToGlobal(help->geometry().topLeft()), i18n("

The following variables will be replaced with their corresponding meaning for each track name.

" "

" "" "" "" "" "" "" "" "" "" "
VariableDescription
%1The artist of the album. For most albums, this will be the same as the Track Artist. " "For compilations, this will often be Various Artists.
%2The name of the album.
%3The artist of each track.
%4The track title.
%5The track number.
%6The album number of a multi-album album. Often compilations consist of several albums.
%7The year of the album's release.
%8The genre of the album.

").arg(DeviceOptions::constAlbumArtist).arg(DeviceOptions::constAlbumTitle) .arg(DeviceOptions::constTrackArtist).arg(DeviceOptions::constTrackTitle) .arg(DeviceOptions::constTrackNumber).arg(DeviceOptions::constCdNumber).arg(DeviceOptions::constYear) .arg(DeviceOptions::constGenre), help); } void FilenameSchemeDialog::enableOkButton() { QString scheme=pattern->text().trimmed(); enableButtonOk(!scheme.isEmpty() && scheme!=origOpts.scheme); } void FilenameSchemeDialog::insertAlbumArtist() { insert(DeviceOptions::constAlbumArtist); } void FilenameSchemeDialog::insertAlbumTitle() { insert(DeviceOptions::constAlbumTitle); } void FilenameSchemeDialog::insertTrackArtist() { insert(DeviceOptions::constTrackArtist); } void FilenameSchemeDialog::insertTrackTitle() { insert(DeviceOptions::constTrackTitle); } void FilenameSchemeDialog::insertTrackNumber() { insert(DeviceOptions::constTrackNumber); } void FilenameSchemeDialog::insertCdNumber() { insert(DeviceOptions::constCdNumber); } void FilenameSchemeDialog::insertGenre() { insert(DeviceOptions::constGenre); } void FilenameSchemeDialog::insertYear() { insert(DeviceOptions::constYear); } void FilenameSchemeDialog::insert(const QString &str) { QString text(pattern->text()); text.insert(pattern->cursorPosition(), str); pattern->setText(text); updateExample(); } void FilenameSchemeDialog::updateExample() { QString saveScheme=origOpts.scheme; origOpts.scheme=pattern->text(); example->setText(origOpts.createFilename(exampleSong)+QLatin1String(".mp3")); origOpts.scheme=saveScheme; }