Commit 815a2ed7 authored by Frerich Raabe's avatar Frerich Raabe

- I like a few milliseconds better than a few seconds for updating an MP3 tag

  after guessing the information, so do it.
- Moved the tag guessing logic into PlaylistItem (somebody moved the button
  out of the tag editor but left the code as it is)
- Make it possible to select a bunch of items and guess the tags for them all

svn path=/trunk/kdemultimedia/juk/; revision=217307
parent 7d3f2e42
......@@ -425,6 +425,13 @@ void Playlist::clear()
clearItems(selectedItems());
}
void Playlist::slotGuessTagInfo()
{
PlaylistItemList items = selectedItems();
for(PlaylistItem *item = items.first(); item != 0; item = items.next())
item->guessTagInfo();
}
////////////////////////////////////////////////////////////////////////////////
// protected members
////////////////////////////////////////////////////////////////////////////////
......
......@@ -146,6 +146,8 @@ public slots:
virtual void clear();
virtual void selectAll() { KListView::selectAll(true); }
void slotGuessTagInfo();
protected:
/**
* Remove \a items from the playlist and disk. This will ignore items that
......
......@@ -17,6 +17,7 @@
#include <kdebug.h>
#include "tagguesser.h"
#include "playlistitem.h"
#include "playlist.h"
#include "collectionlist.h"
......@@ -36,7 +37,12 @@ void PlaylistItem::setFile(const QString &file)
slotRefresh();
}
Tag *PlaylistItem::tag() const
Tag *PlaylistItem::tag()
{
return m_data->tag();
}
const Tag *PlaylistItem::tag() const
{
return m_data->tag();
}
......@@ -69,6 +75,24 @@ bool PlaylistItem::isWritable() const
return m_data->fileInfo()->isWritable();
}
void PlaylistItem::guessTagInfo()
{
TagGuesser guesser(tag()->absFilePath());
if(!guesser.title().isNull())
tag()->setTrack(guesser.title());
if(!guesser.artist().isNull())
tag()->setArtist(guesser.artist());
if(!guesser.album().isNull())
tag()->setAlbum(guesser.album());
if(!guesser.track().isNull())
tag()->setTrackNumber(guesser.track().toInt());
if(!guesser.comment().isNull())
tag()->setComment(guesser.comment());
slotRefresh();
}
////////////////////////////////////////////////////////////////////////////////
// PlaylistItem public slots
////////////////////////////////////////////////////////////////////////////////
......@@ -285,7 +309,12 @@ void PlaylistItem::Data::deleteUser()
delete this;
}
Tag *PlaylistItem::Data::tag() const
Tag *PlaylistItem::Data::tag()
{
return m_dataTag;
}
const Tag *PlaylistItem::Data::tag() const
{
return m_dataTag;
}
......
......@@ -65,7 +65,8 @@ public:
static int lastColumn() { return FileNameColumn; }
void setFile(const QString &file);
Tag *tag() const;
Tag *tag();
const Tag *tag() const;
// These are just forwarding methods to PlaylistItem::Data, a QFileInfo
......@@ -78,6 +79,8 @@ public:
bool isWritable() const;
void setPlaying(bool playing = true) { m_playing = playing; }
void guessTagInfo();
public slots:
/**
* This just refreshes from the in memory data. This may seem pointless at
......@@ -152,7 +155,8 @@ public:
void refresh();
Tag *tag() const;
Tag *tag();
const Tag *tag() const;
void setFile(const QString &file);
bool isFile() const { return m_fileInfo.isFile(); }
......
......@@ -336,6 +336,13 @@ void PlaylistSplitter::slotAddToPlaylist(const QStringList &files, Playlist *lis
m_editor->slotUpdateCollection();
}
void PlaylistSplitter::slotGuessTagInfo()
{
visiblePlaylist()->slotGuessTagInfo();
if(m_editor)
m_editor->slotRefresh();
}
////////////////////////////////////////////////////////////////////////////////
// private members
////////////////////////////////////////////////////////////////////////////////
......
......@@ -171,7 +171,7 @@ public slots:
// Tagger slots
void slotSaveTag() { m_editor->save(); }
void slotGuessTagInfo() { m_editor->slotGuessTagInfo(); }
void slotGuessTagInfo();
// Playlist slots
......
......@@ -33,7 +33,6 @@
#include "tageditor.h"
#include "tag.h"
#include "tagguesser.h"
#include "collectionlist.h"
#include "genrelistlist.h"
......@@ -240,28 +239,6 @@ void TagEditor::slotUpdateCollection()
}
}
void TagEditor::slotGuessTagInfo()
{
PlaylistItem *item = m_items.getFirst();
if(!item)
return;
Tag *tag = item->tag();
Q_ASSERT(tag);
TagGuesser guesser(tag->absFilePath());
if(!guesser.title().isNull())
m_trackNameBox->setText(guesser.title());
if(!guesser.artist().isNull())
m_artistNameBox->setEditText(guesser.artist());
if(!guesser.album().isNull())
m_albumNameBox->setEditText(guesser.album());
if(!guesser.track().isNull())
m_trackSpin->setValue(guesser.track().toInt());
if(!guesser.comment().isNull())
m_commentBox->setText(guesser.comment());
}
////////////////////////////////////////////////////////////////////////////////
// private members
////////////////////////////////////////////////////////////////////////////////
......
......@@ -48,7 +48,6 @@ public slots:
void slotRefresh();
void slotClear();
void slotUpdateCollection();
void slotGuessTagInfo();
private:
void setupLayout();
......
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