Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 114c230a authored by Michael Pyne's avatar Michael Pyne

More --qt3support:

* Remove support for the cover system used in KDE 3.3.
* Cover dragging uses "pure" Qt4 now.  Unfortunately the cover manager is
  still Qt 3 so drag-and-drop from there is temporarily disabled.
* Add a coverId() function that ensures the m_coverId for a CoverInfo is
  properly set before use.


svn path=/trunk/KDE/kdemultimedia/juk/; revision=832069
parent 96c26c7f
......@@ -38,10 +38,13 @@ CoverIconViewItem *CoverIconView::currentItem() const
Q3DragObject *CoverIconView::dragObject()
{
#if 0
// Temporarily disabled pending conversion of the cover manager icon view
// to Qt 4 ish stuff.
CoverIconViewItem *item = currentItem();
if(item)
return new CoverDrag(item->id(), this);
#endif
return 0;
}
......
......@@ -31,6 +31,7 @@
#include <QFile>
#include <QFileInfo>
#include <QDesktopWidget>
#include <QImage>
#include <taglib/mpegfile.h>
#include <taglib/tstring.h>
......@@ -72,13 +73,12 @@ CoverInfo::CoverInfo(const FileHandle &file) :
m_hasCover(false),
m_hasAttachedCover(false),
m_haveCheckedForCover(false),
m_coverKey(CoverManager::NoMatch),
m_needsConverting(false)
m_coverKey(CoverManager::NoMatch)
{
}
bool CoverInfo::hasCover()
bool CoverInfo::hasCover() const
{
if(m_haveCheckedForCover)
return m_hasCover || m_hasAttachedCover;
......@@ -97,14 +97,6 @@ bool CoverInfo::hasCover()
if(m_coverKey != CoverManager::NoMatch)
m_hasCover = CoverManager::hasCover(m_coverKey);
// We *still* don't have it? Check the old-style covers then.
if(!m_hasCover) {
m_hasCover = QFile(coverLocation(FullSize)).exists();
if(m_hasCover)
m_needsConverting = true;
}
// Check if it's embedded in the file itself.
QByteArray filePath = QFile::encodeName(m_file.absFilePath());
......@@ -139,8 +131,6 @@ void CoverInfo::clearCover()
// Re-search for cover since we may still have a different type of cover.
m_haveCheckedForCover = false;
m_needsConverting = false;
// We don't need to call removeCover because the CoverManager will
// automatically unlink the cover if we were the last track to use it.
CoverManager::setIdForTrack(m_file.absFilePath(), CoverManager::NoMatch);
......@@ -153,7 +143,6 @@ void CoverInfo::setCover(const QImage &image)
return;
m_haveCheckedForCover = true;
m_needsConverting = false;
m_hasCover = true;
QPixmap cover = QPixmap::fromImage(image);
......@@ -170,7 +159,6 @@ void CoverInfo::setCoverId(coverKey id)
{
m_coverKey = id;
m_haveCheckedForCover = true;
m_needsConverting = false;
m_hasCover = id != CoverManager::NoMatch;
// Inform CoverManager of the change.
......@@ -203,21 +191,23 @@ void CoverInfo::applyCoverToWholeAlbum(bool overwriteExistingCovers) const
for(; it != results.constEnd(); ++it) {
// Don't worry about files that somehow already have a tag,
// unless the coversion is forced.
if(!overwriteExistingCovers && !(*it)->file().coverInfo()->m_needsConverting)
// unless the conversion is forced.
if(!overwriteExistingCovers && (*it)->file().coverInfo()->coverId() != CoverManager::NoMatch)
continue;
kDebug(65432) << "Setting cover for: " << *it;
(*it)->file().coverInfo()->setCoverId(m_coverKey);
}
}
QPixmap CoverInfo::pixmap(CoverSize size) const
coverKey CoverInfo::coverId() const
{
if(m_needsConverting)
convertOldStyleCover();
hasCover(); // Force check for cover.
return m_coverKey;
}
if(m_hasCover && m_coverKey != CoverManager::NoMatch) {
QPixmap CoverInfo::pixmap(CoverSize size) const
{
if(hasCover() && m_coverKey != CoverManager::NoMatch) {
return CoverManager::coverFromId(m_coverKey,
size == Thumbnail
? CoverManager::Thumbnail
......@@ -340,65 +330,4 @@ QImage CoverInfo::scaleCoverToThumbnail(const QImage &image) const
return image.scaled(80, 80, Qt::KeepAspectRatio, Qt::SmoothTransformation);
}
/**
* DEPRECATED
*/
QString CoverInfo::coverLocation(CoverSize size) const
{
QString fileName(QFile::encodeName(m_file.tag()->artist() + " - " + m_file.tag()->album()));
QRegExp maskedFileNameChars("[ /?:\"]");
fileName.replace(maskedFileNameChars, "_");
fileName.append(".png");
QString dataDir = KGlobal::dirs()->saveLocation("appdata");
QString subDir;
switch (size) {
case FullSize:
subDir = "large/";
break;
default:
break;
}
QString fileLocation = dataDir + "covers/" + subDir + fileName.toLower();
return fileLocation;
}
bool CoverInfo::convertOldStyleCover() const
{
// Ah, old-style cover. Let's transfer it to the new system.
kDebug() << "Found old style cover for " << m_file.absFilePath();
QString artist = m_file.tag()->artist();
QString album = m_file.tag()->album();
QString oldLocation = coverLocation(FullSize);
m_coverKey = CoverManager::addCover(oldLocation, artist, album);
m_needsConverting = false;
if(m_coverKey != CoverManager::NoMatch) {
CoverManager::setIdForTrack(m_file.absFilePath(), m_coverKey);
// Now let's also set the ID for the tracks matching the track and
// artist at this point so that the conversion is complete, otherwise
// we can't tell apart the "No cover on purpose" and "Has no cover yet"
// possibilities.
applyCoverToWholeAlbum();
// If we convert we need to remove the old cover otherwise we'll find
// it later if the user un-sets the new cover.
if(!QFile::remove(oldLocation))
kError(65432) << "Unable to remove converted cover at " << oldLocation << endl;
return true;
}
else {
kDebug() << "We were unable to replace the old style cover.\n";
return false;
}
}
// vim: set et sw=4 tw=0 sta:
......@@ -34,7 +34,7 @@ public:
CoverInfo(const FileHandle &file);
bool hasCover();
bool hasCover() const;
void clearCover();
void setCover(const QImage &image = QImage());
......@@ -53,22 +53,21 @@ public:
*/
void applyCoverToWholeAlbum(bool overwriteExistingCovers = false) const;
coverKey coverId() const { return m_coverKey; }
coverKey coverId() const;
QPixmap pixmap(CoverSize size) const;
void popup() const;
private:
QString coverLocation(CoverSize size) const;
bool convertOldStyleCover() const;
QImage scaleCoverToThumbnail(const QImage &image) const;
FileHandle m_file;
bool m_hasCover;
bool m_hasAttachedCover;
bool m_haveCheckedForCover;
// Mutable to allow this info to be cached.
mutable bool m_hasCover;
mutable bool m_hasAttachedCover;
mutable bool m_haveCheckedForCover;
mutable coverKey m_coverKey;
mutable bool m_needsConverting;
};
#endif
......
......@@ -23,8 +23,8 @@
#include <QDataStream>
#include <QHash>
#include <Q3Cache>
#include <QMimeSource>
#include <QBuffer>
#include <QByteArray>
#include <kdebug.h>
#include <ktemporaryfile.h>
......@@ -237,7 +237,8 @@ QString CoverManagerPrivate::coverLocation() const
}
// XXX: This could probably use some improvement, I don't like the linear
// search for ID idea.
// search for ID idea. Linear search is used instead of covers.size() since we want to
// re-use old IDs if possible.
coverKey CoverManagerPrivate::nextId() const
{
// Start from 1...
......@@ -252,66 +253,31 @@ coverKey CoverManagerPrivate::nextId() const
//
// Implementation of CoverDrag
//
CoverDrag::CoverDrag(coverKey id, QWidget *src) : Q3DragObject(src, "coverDrag"),
m_id(id)
CoverDrag::CoverDrag(coverKey id) :
QMimeData()
{
QPixmap cover = CoverManager::coverFromId(id);
if(!cover.isNull())
setPixmap(cover);
setImageData(cover.toImage());
setData(dragMimetype, QByteArray::number(qulonglong(id), 10));
}
const char *CoverDrag::format(int i) const
bool CoverDrag::isCover(const QMimeData *data)
{
if(i == 0)
return dragMimetype;
if(i == 1)
return "image/png";
return 0;
}
QByteArray CoverDrag::encodedData(const char *mimetype) const
{
if(qstrcmp(dragMimetype, mimetype) == 0) {
QByteArray data;
QDataStream ds(&data, QIODevice::WriteOnly);
ds << quint32(m_id);
return data;
}
else if(qstrcmp(dragMimetype, "image/png") == 0) {
QPixmap large = CoverManager::coverFromId(m_id, CoverManager::FullSize);
QImage img = large.toImage();
QByteArray data;
QBuffer buffer(&data);
buffer.open(IO_WriteOnly);
img.save(&buffer, "PNG"); // Write in PNG format.
return data;
}
return QByteArray();
}
bool CoverDrag::canDecode(const QMimeSource *e)
{
return e->provides(dragMimetype);
return data->hasImage() || data->hasFormat(dragMimetype);
}
bool CoverDrag::decode(const QMimeSource *e, coverKey &id)
coverKey CoverDrag::idFromData(const QMimeData *data)
{
if(!canDecode(e))
return false;
bool ok = false;
QByteArray data = e->encodedData(dragMimetype);
QDataStream ds(&data, QIODevice::ReadOnly);
quint32 i;
if(!data->hasFormat(dragMimetype))
return CoverManager::NoMatch;
ds >> i;
id = (coverKey) i;
coverKey id = data->data(dragMimetype).toULong(&ok);
if(!ok)
return CoverManager::NoMatch;
return true;
return id;
}
const char *CoverDrag::mimetype()
......
/***************************************************************************
begin : Sun May 15 2005
copyright : (C) 2005 by Michael Pyne
copyright : (C) 2005, 2008 by Michael Pyne
email : michael.pyne@kdemail.net
***************************************************************************/
......@@ -13,12 +13,12 @@
* *
***************************************************************************/
#ifndef COVERMANAGER_H
#define COVERMANAGER_H
#ifndef JUK_COVERMANAGER_H
#define JUK_COVERMANAGER_H
#include <ksharedptr.h>
#include <Q3DragObject>
#include <QMimeData>
#include <QString>
class CoverManagerPrivate;
......@@ -74,28 +74,20 @@ typedef QList<coverKey> CoverList;
*
* @author Michael Pyne <michael.pyne@kdemail.net>
*/
class CoverDrag : public Q3DragObject
class CoverDrag : public QMimeData
{
public:
CoverDrag(coverKey id, QWidget *src);
virtual const char *format(int i) const;
virtual QByteArray encodedData(const char *mimetype) const;
Q_OBJECT
void setId(coverKey id) { m_id = id; }
/**
* Returns true if CoverDrag can decode the given mime source. Note that
* true is returned only if \p e contains a cover id, even though
* CoverDrag can convert it to an image.
*/
static bool canDecode(const QMimeSource *e);
static bool decode(const QMimeSource *e, coverKey &id);
public:
CoverDrag(coverKey id);
static const char* mimetype();
private:
coverKey m_id;
static bool isCover(const QMimeData *data);
// CoverDrag stores QByteArray data for the cover id, this can convert it
// back.
static coverKey idFromData(const QMimeData *data);
};
/**
......@@ -267,6 +259,6 @@ public:
static QPixmap createThumbnail(const QPixmap &base);
};
#endif /* COVERMANAGER_H */
#endif /* JUK_COVERMANAGER_H */
// vim: set et sw=4 tw=0 sta:
......@@ -19,13 +19,13 @@
#include <klocale.h>
#include <kdebug.h>
#include <krandom.h>
#include <k3urldrag.h>
#include <kglobalsettings.h>
#include <kio/netaccess.h>
#include <QImage>
#include <QLayout>
#include <QEvent>
#include <Q3DragObject>
#include <QDrag>
#include <QTimer>
#include <QPoint>
#include <QFrame>
......@@ -34,6 +34,8 @@
#include <QVBoxLayout>
#include <QDragEnterEvent>
#include <QMouseEvent>
#include <QUrl>
#include <QList>
#include <QTextDocument>
#include "playlistcollection.h"
......@@ -167,40 +169,48 @@ void CoverItem::mouseMoveEvent(QMouseEvent *e)
return;
QPoint diff = m_dragStart - e->globalPos();
if(qAbs(diff.x()) > 1 || qAbs(diff.y()) > 1) {
if(diff.manhattanLength() > KGlobalSettings::dndEventDelay()) {
// Start a drag.
m_dragging = true;
CoverDrag *drag = new CoverDrag(m_file.coverInfo()->coverId(), this);
drag->drag();
QDrag *drag = new QDrag(this);
CoverDrag *data = new CoverDrag(m_file.coverInfo()->coverId());
drag->setMimeData(data);
drag->exec(Qt::CopyAction);
}
}
void CoverItem::dragEnterEvent(QDragEnterEvent *e)
{
e->setAccepted(Q3ImageDrag::canDecode(e) || K3URLDrag::canDecode(e) || CoverDrag::canDecode(e));
e->setAccepted(CoverDrag::isCover(e->mimeData()) || e->mimeData()->hasUrls());
}
void CoverItem::dropEvent(QDropEvent *e)
{
QImage image;
KUrl::List urls;
QList<QUrl> urls;
coverKey key;
if(e->source() == this)
return;
if(Q3ImageDrag::decode(e, image)) {
m_file.coverInfo()->setCover(image);
key = CoverDrag::idFromData(e->mimeData());
if(key != CoverManager::NoMatch) {
m_file.coverInfo()->setCoverId(key);
update(m_file);
}
else if(CoverDrag::decode(e, key)) {
m_file.coverInfo()->setCoverId(key);
else if(e->mimeData()->hasImage()) {
m_file.coverInfo()->setCover(qvariant_cast<QImage>(e->mimeData()->imageData()));
update(m_file);
}
else if(K3URLDrag::decode(e, urls)) {
else {
urls = e->mimeData()->urls();
if(urls.isEmpty())
return;
QString fileName;
if(KIO::NetAccess::download(urls.front(), fileName, this)) {
......
......@@ -1019,7 +1019,7 @@ void Playlist::contentsDragEnterEvent(QDragEnterEvent *e)
{
K3ListView::contentsDragEnterEvent(e);
if(CoverDrag::canDecode(e)) {
if(CoverDrag::isCover(e->mimeData())) {
setDropHighlighter(true);
setDropVisualizer(false);
......@@ -1042,7 +1042,7 @@ void Playlist::contentsDragEnterEvent(QDragEnterEvent *e)
bool Playlist::acceptDrag(QDropEvent *e) const
{
return CoverDrag::canDecode(e) || K3URLDrag::canDecode(e);
return CoverDrag::isCover(e->mimeData()) || K3URLDrag::canDecode(e);
}
void Playlist::decode(const QMimeData *s, PlaylistItem *item)
......@@ -1155,9 +1155,8 @@ void Playlist::contentsDropEvent(QDropEvent *e)
// First see if we're dropping a cover, if so we can get it out of the
// way early.
if(item && CoverDrag::canDecode(e)) {
coverKey id;
CoverDrag::decode(e, id);
if(item && CoverDrag::isCover(e->mimeData())) {
coverKey id = CoverDrag::idFromData(e->mimeData());
// If the item we dropped on is selected, apply cover to all selected
// items, otherwise just apply to the dropped item.
......
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