Commit 5fd9d353 authored by Scott Wheeler's avatar Scott Wheeler

Things are working for saving tags except for the genre frames.

svn path=/trunk/kdemultimedia/juk/; revision=142744
parent c4195357
......@@ -85,7 +85,9 @@ void FileList::setup()
addColumn(i18n("Genre"));
addColumn(i18n("Year"));
addColumn(i18n("File Name"));
setAllColumnsShowFocus(true);
setSelectionMode(QListView::Extended);
setShowSortIndicator(true);
setItemMargin(3);
......
......@@ -29,13 +29,7 @@ FileListItem::FileListItem(QFileInfo *file, KListView *parent) : KListViewItem(p
fileInfo = file;
tag = new Tag(fileInfo->filePath());
setText(0, tag->getTrack());
setText(1, tag->getArtist());
setText(2, tag->getAlbum());
setText(3, tag->getTrackNumberString());
setText(4, tag->getGenre());
setText(5, tag->getYearString());
setText(6, fileInfo->filePath());
refresh();
}
FileListItem::~FileListItem()
......@@ -68,6 +62,32 @@ MPEGHeader *FileListItem::getHeader()
return(header);
}
void FileListItem::setFile(QString fileName)
{
if(fileInfo)
fileInfo->setFile(fileName);
if(header) {
delete(header);
(void) getHeader();
}
if(tag) {
delete(tag);
(void) getTag();
}
}
void FileListItem::refresh()
{
setText(0, tag->getTrack());
setText(1, tag->getArtist());
setText(2, tag->getAlbum());
setText(3, tag->getTrackNumberString());
setText(4, tag->getGenre());
setText(5, tag->getYearString());
setText(6, fileInfo->filePath());
}
////////////////////////////////////////////////////////////////////////////////
// private methods
////////////////////////////////////////////////////////////////////////////////
......
......@@ -32,6 +32,9 @@ public:
QFileInfo *getFileInfo();
Tag *getTag();
MPEGHeader *getHeader();
void setFile(QString fileName);
void refresh();
protected:
......
......@@ -130,6 +130,12 @@ void JuK::openDirectory()
tagger->add(KFileDialog::getExistingDirectory());
}
void JuK::saveFile()
{
if(tagger && tagger->isVisible())
tagger->save();
}
void JuK::quit()
{
kapp->quit();
......
......@@ -65,6 +65,7 @@ private slots:
// file menu
void openFile();
void openDirectory();
void saveFile();
void quit();
// function menu
......
......@@ -61,7 +61,7 @@ Tag::Tag(QString file)
if(trackName.length() <= 0) {
trackName = fileName;
while((trackName.right(4)).lower() == ".mp3") {
trackName = trackName.left(trackName.length()-4);
trackName = trackName.left(trackName.length() - 4);
}
trackName = trackName.right(trackName.length() - trackName.findRev(QDir::separator(), -1) -1);
}
......@@ -82,6 +82,18 @@ Tag::Tag(QString file)
Tag::~Tag()
{
save();
}
bool Tag::exists()
{
QFile id3_file(fileName);
return(id3_file.exists());
}
void Tag::save()
{
if(changed) {
if(artistName.length()>0) {
......@@ -127,18 +139,11 @@ Tag::~Tag()
ID3_AddComment(&tag, comment.latin1(), REPLACE);
}
tag.Update();
}
tag.Update();
changed = false;
}
}
bool Tag::exists()
{
QFile id3_file(fileName);
return(id3_file.exists());
}
////////////////////////////////////////////////
// functions to gather information
////////////////////////////////////////////////
......
......@@ -29,6 +29,7 @@ public:
~Tag();
bool exists();
void save();
// functions that gather information
......
......@@ -15,6 +15,7 @@
* *
***************************************************************************/
#include <kmessagebox.h>
#include <klocale.h>
#include <kdebug.h>
......@@ -24,6 +25,7 @@
#include <qhbox.h>
#include <qlayout.h>
#include <qlabel.h>
#include <qdir.h>
#include "taggerwidget.h"
#include "genrelistlist.h"
......@@ -34,6 +36,7 @@
TaggerWidget::TaggerWidget(QWidget *parent) : QWidget(parent)
{
changed = false;
setupLayout();
readConfig();
}
......@@ -58,6 +61,68 @@ FileListItem *TaggerWidget::getSelectedItem()
return(0);
}
////////////////////////////////////////////////////////////////////////////////
// public slots
////////////////////////////////////////////////////////////////////////////////
void TaggerWidget::save()
{
kdDebug() << "TaggerWidget::save()" << endl;
QPtrList<QListViewItem> items = taggerList->selectedItems();
if(items.count() > 0) {
FileListItem *item = dynamic_cast<FileListItem *>(items.first());
if(item && changed) {
QFileInfo newFile(item->getFileInfo()->dirPath() + QDir::separator() + fileNameBox->text());
QFileInfo directory(item->getFileInfo()->dirPath());
// if (the new file is writable or the new file doesn't exist and it's directory is writable)
// and the old file is writable...
if((newFile.isWritable() || (!newFile.exists() && directory.isWritable())) && item->getFileInfo()->isWritable()) {
// if the file name in the box doesn't match the current file name
if(item->getFileInfo()->fileName()!=newFile.fileName()) {
// rename the file if it doesn't exist or we say it's ok
if(!newFile.exists() ||
KMessageBox::warningYesNo(this, i18n("This file already exists.\nDo you want to replace it?"),
i18n("File Exists")) == KMessageBox::Yes)
{
QDir currentDir;
currentDir.rename(item->getFileInfo()->filePath(), newFile.filePath());
item->setFile(newFile.filePath());
}
}
item->getTag()->setArtist(artistNameBox->currentText());
item->getTag()->setTrack(trackNameBox->text());
item->getTag()->setAlbum(albumNameBox->currentText());
// item->getTag()->setGenre(genreBox->currentText());
// item->getTag()->setGenre(genreBox->currentItem() - 1);
item->getTag()->setTrackNumber(trackSpin->value());
item->getTag()->setYear(yearSpin->value());
item->getTag()->setComment(commentBox->text());
item->getTag()->save();
item->refresh();
changed = false;
}
else {
KMessageBox::sorry(this, i18n("Could not save to specified file."));
}
changed = false;
}
}
}
void TaggerWidget::setChanged()
{
changed = true;
}
////////////////////////////////////////////////////////////////////////////////
// private members
////////////////////////////////////////////////////////////////////////////////
......@@ -90,7 +155,7 @@ void TaggerWidget::setupLayout()
taggerList = new FileList(split, "taggerList");
// this connection is a little ugly -- it does a cast
connect(taggerList, SIGNAL(selectionChanged(QListViewItem *)), this, SLOT(updateBoxes(FileListItem *)));
connect(taggerList, SIGNAL(selectionChanged()), this, SLOT(updateBoxes()));
//////////////////////////////////////////////////////////////////////////////
// now set up a bottom widget of the splitter and make it stay small at
......@@ -181,6 +246,15 @@ void TaggerWidget::setupLayout()
commentBox = new KEdit(bottem, "commentBox");
rightColumnLayout->addWidget(commentBox);
}
connect(artistNameBox, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
connect(trackNameBox, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
connect(albumNameBox, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
connect(genreBox, SIGNAL(activated(const QString&)), this, SLOT(setChanged()));
connect(fileNameBox, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
connect(yearSpin, SIGNAL(valueChanged(int)), this, SLOT(setChanged()));
connect(trackSpin, SIGNAL(valueChanged(int)), this, SLOT(setChanged()));
connect(commentBox, SIGNAL(textChanged()), this, SLOT(setChanged()));
}
void TaggerWidget::readConfig()
......@@ -199,31 +273,42 @@ void TaggerWidget::readConfig()
// private slots
////////////////////////////////////////////////////////////////////////////////
void TaggerWidget::updateBoxes(FileListItem *item)
void TaggerWidget::updateBoxes() // this needs to be updated to properly work with multiple selections
{
// kdDebug() << "updateBoxes(): " << item->getFileInfo()->filePath() << endl;
Tag *tag = item->getTag();
QFileInfo *fileInfo = item->getFileInfo();
MPEGHeader *header = item->getHeader();
artistNameBox->setEditText(tag->getArtist());
trackNameBox->setText(tag->getTrack());
albumNameBox->setEditText(tag->getAlbum());
QPtrList<QListViewItem> items = taggerList->selectedItems();
if(genreList && genreList->findIndex(tag->getGenre()) >= 0)
genreBox->setCurrentItem(genreList->findIndex(tag->getGenre()) + 1);
else
genreBox->setCurrentItem(0);
if(items.count() > 0) {
fileNameBox->setText(fileInfo->fileName());
trackSpin->setValue(tag->getTrackNumber());
yearSpin->setValue(tag->getYear());
FileListItem *item = dynamic_cast<FileListItem *>(items.first());
if(header->getResult()) {
lengthBox->setText(header->getLengthChar());
bitrateBox->setText(QString::number(header->getBitrate()));
if(item) {
Tag *tag = item->getTag();
QFileInfo *fileInfo = item->getFileInfo();
MPEGHeader *header = item->getHeader();
artistNameBox->setEditText(tag->getArtist());
trackNameBox->setText(tag->getTrack());
albumNameBox->setEditText(tag->getAlbum());
if(genreList && genreList->findIndex(tag->getGenre()) >= 0)
genreBox->setCurrentItem(genreList->findIndex(tag->getGenre()) + 1);
else
genreBox->setCurrentItem(0);
fileNameBox->setText(fileInfo->fileName());
trackSpin->setValue(tag->getTrackNumber());
yearSpin->setValue(tag->getYear());
if(header->getResult()) {
lengthBox->setText(header->getLengthChar());
bitrateBox->setText(QString::number(header->getBitrate()));
}
commentBox->setText(tag->getComment());
changed = false;
}
}
commentBox->setText(tag->getComment());
}
......@@ -40,6 +40,10 @@ public:
FileListItem *getSelectedItem();
public slots:
void save();
void setChanged();
private:
void setupLayout();
void readConfig();
......@@ -58,10 +62,12 @@ private:
KLineEdit *bitrateBox;
KEdit *commentBox;
// internally useful things
GenreList *genreList;
bool changed;
private slots:
void updateBoxes(FileListItem *item);
void updateBoxes();
};
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment