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 bc9ca5f3 authored by Michael Pyne's avatar Michael Pyne

* Remove crap dealing with eligible playlist items (to have covers). All playlist items

  have been able to have a cover since KDE 3.5 or so.
* --kde3support by removing K3IconView in the web image fetcher.

svn path=/trunk/KDE/kdemultimedia/juk/; revision=679479
parent a98619d6
......@@ -22,19 +22,17 @@
#include <kio/job.h>
#include <klocale.h>
#include <kdebug.h>
#include <k3iconview.h>
#include <kmessagebox.h>
#include <krun.h>
#include <kcombobox.h>
#include <kiconloader.h>
#include <kurllabel.h>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QImage>
#include <QLabel>
#include <QPushButton>
#include <QPainter>
#include <QIcon>
#include <QEventLoop>
#include <QListView>
#include <QPixmap>
GoogleFetcherDialog::GoogleFetcherDialog(const GoogleImageList &imageList,
......@@ -51,23 +49,24 @@ GoogleFetcherDialog::GoogleFetcherDialog(const GoogleImageList &imageList,
setDefaultButton(NoDefault);
showButtonSeparator(true);
#ifdef __GNUC__
#warning KDE4 How to port this?
#endif
//disableResize();
QWidget *mainBox = new QWidget(this);
QBoxLayout *mainLayout = new QVBoxLayout(mainBox);
mainLayout->setMargin(0); // No extra padding needed.
mainLayout->setSpacing(spacingHint());
m_iconWidget = new QListView(mainBox);
m_iconWidget->setGridSize(QSize(100, 120));
m_iconWidget->setViewMode(QListView::IconMode);
m_iconWidget->setResizeMode(QListView::Adjust);
m_iconWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
m_iconWidget->setVerticalScrollMode(QListView::ScrollPerItem);
m_iconWidget->setMovement(QListView::Static);
m_iconWidget->setSelectionMode(QListView::SingleSelection);
m_iconWidget->setIconSize(QSize(80, 80));
m_iconWidget = new K3IconView(mainBox);
m_iconWidget->setResizeMode(Q3IconView::Adjust);
m_iconWidget->setSpacing(10);
m_iconWidget->setFixedSize(500,550);
m_iconWidget->arrangeItemsInGrid();
m_iconWidget->setItemsMovable(false);
mainLayout->addWidget(m_iconWidget);
connect(m_iconWidget, SIGNAL(executed(Q3IconViewItem *)),
this, SLOT(slotOk()));
connect(m_iconWidget, SIGNAL(activated(const QModelIndex &)),
this, SLOT(slotActivated(const QModelIndex &)));
// Before changing the code below be sure to check the attribution terms
// of the Yahoo Image Search API.
......@@ -77,7 +76,7 @@ GoogleFetcherDialog::GoogleFetcherDialog(const GoogleImageList &imageList,
logoLabel->setPixmap(UserIcon("yahoo_credit"));
logoLabel->setMargin(15); // Allow large margin per attribution terms.
logoLabel->setUseTips(true); // Show URL in tooltip.
connect(logoLabel, SIGNAL(leftClickedURL(const QString &)),
connect(logoLabel, SIGNAL(leftClickedUrl(const QString &)),
SLOT(showCreditURL(const QString &)));
QBoxLayout *creditLayout = new QHBoxLayout;
......@@ -93,6 +92,8 @@ GoogleFetcherDialog::GoogleFetcherDialog(const GoogleImageList &imageList,
connect(this, SIGNAL(user1Clicked()), SIGNAL(newSearchRequested()));
connect(this, SIGNAL(okClicked()), SLOT(slotOk()));
connect(this, SIGNAL(cancelClicked()), SLOT(slotCancel()));
setInitialSize(QSize(500, 480));
}
GoogleFetcherDialog::~GoogleFetcherDialog()
......@@ -113,9 +114,16 @@ void GoogleFetcherDialog::setLayout()
.arg(m_file.tag()->album())
.arg(m_imageList.size()));
m_iconWidget->clear();
for(int i = 0; i < m_imageList.size(); i++)
new CoverIconViewItem(m_iconWidget, m_imageList[i]);
QStandardItemModel *model = new QStandardItemModel(m_iconWidget);
QAbstractItemModel *oldModel = m_iconWidget->model();
foreach(GoogleImage image, m_imageList) {
CoverIconViewItem *item = new CoverIconViewItem(m_iconWidget, image);
model->appendRow(item);
}
m_iconWidget->setModel(model);
delete oldModel;
adjustSize();
}
......@@ -148,16 +156,19 @@ int GoogleFetcherDialog::exec()
void GoogleFetcherDialog::slotOk()
{
int selectedIndex = m_iconWidget->index(m_iconWidget->currentItem());
m_pixmap = pixmapFromURL(m_imageList[selectedIndex].imageURL());
slotActivated(m_iconWidget->currentIndex());
}
void GoogleFetcherDialog::slotActivated(const QModelIndex &index)
{
m_pixmap = pixmapFromURL(m_imageList[index.row()].imageURL());
if(m_pixmap.isNull()) {
KMessageBox::sorry(this,
i18n("The cover you have selected is unavailable. Please select another."),
i18n("Cover Unavailable"));
QPixmap blankPix(80,80);
blankPix.fill();
m_iconWidget->currentItem()->setPixmap(blankPix, true, true);
QTimer::singleShot(0, this, SLOT(selectedItemIsBad()));
return;
}
......@@ -165,6 +176,18 @@ void GoogleFetcherDialog::slotOk()
emit coverSelected();
}
void GoogleFetcherDialog::selectedItemIsBad()
{
QModelIndex index = m_iconWidget->currentIndex();
QStandardItemModel *model = static_cast<QStandardItemModel *>(m_iconWidget->model());
QStandardItem *item = model->itemFromIndex(index);
if(!item)
return;
item->setIcon(DesktopIcon("dialog-error"));
}
void GoogleFetcherDialog::slotCancel()
{
m_pixmap = QPixmap();
......@@ -185,6 +208,7 @@ QPixmap GoogleFetcherDialog::pixmapFromURL(const KUrl &url) const
KIO::NetAccess::removeTempFile(file);
return pixmap;
}
KIO::NetAccess::removeTempFile(file);
return QPixmap();
}
......@@ -193,21 +217,17 @@ QPixmap GoogleFetcherDialog::pixmapFromURL(const KUrl &url) const
// CoverIconViewItem
////////////////////////////////////////////////////////////////////////////////
CoverIconViewItem::CoverIconViewItem(Q3IconView *parent, const GoogleImage &image) :
QObject(parent), K3IconViewItem(parent, parent->lastItem(), image.size()), m_job(0)
CoverIconViewItem::CoverIconViewItem(QWidget *parent, const GoogleImage &image) :
QObject(parent), QStandardItem(image.size()), m_job(0)
{
// Set up the iconViewItem
QPixmap mainMap(80,80);
mainMap.fill();
setPixmap(mainMap, true, true);
setIcon(DesktopIcon("system-search"));
// Start downloading the image.
m_job = KIO::get(image.thumbURL(), false, false);
connect(m_job, SIGNAL(result(KIO::Job *)), this, SLOT(imageResult(KIO::Job *)));
connect(m_job, SIGNAL(data(KIO::Job *, const QByteArray &)),
this, SLOT(imageData(KIO::Job *, const QByteArray &)));
m_job = KIO::storedGet(image.thumbURL());
connect(m_job, SIGNAL(result(KJob *)), this, SLOT(imageResult(KJob *)));
}
CoverIconViewItem::~CoverIconViewItem()
......@@ -223,20 +243,54 @@ CoverIconViewItem::~CoverIconViewItem()
}
}
void CoverIconViewItem::imageData(KIO::Job *, const QByteArray &data)
void CoverIconViewItem::imageResult(KJob *job)
{
int currentSize = m_buffer.size();
m_buffer.resize(currentSize + data.size());
memcpy(&(m_buffer.data()[currentSize]), data.data(), data.size());
}
if(job != m_job) {
kError() << "Wrong slot called.\n";
setIcon(DesktopIcon("dialog-error"));
return;
}
void CoverIconViewItem::imageResult(KIO::Job *job)
{
if(job->error())
if(job->error()) {
kError() << "Unable to grab image\n";
setIcon(DesktopIcon("dialog-error"));
return;
}
// Create thumbnail to show on icon. At least by Qt 4.3 the standard
// item delegate is still retarded when it comes to drawing uneven sized
// items in a grid, as shorter items (in height) have the corresponding
// text shoved up below meaning the text doesn't line up. So, force every
// icon to be the exact same size manually...
QPixmap iconImage, realImage(80, 80);
iconImage.loadFromData(m_job->data());
realImage.fill(Qt::transparent);
if(iconImage.isNull()) {
kError() << "Thumbnail image is not of a supported format\n";
setIcon(DesktopIcon("dialog-error"));
return;
}
// Scale down if necesssary
if(iconImage.width() > 80 || iconImage.height() > 80)
iconImage = iconImage.scaled(80, 80, Qt::KeepAspectRatio, Qt::SmoothTransformation);
QPainter p;
QRect targetRect(QPoint(0, 0), iconImage.size());
p.begin(&realImage);
// Center thumbnail in 80x80 pixmap
targetRect.setWidth(iconImage.width());
targetRect.moveLeft((realImage.width() - iconImage.width()) / 2);
targetRect.setHeight(iconImage.height());
targetRect.moveTop((realImage.height() - iconImage.height()) / 2);
p.drawPixmap(targetRect, iconImage, iconImage.rect());
p.end();
QPixmap iconImage(m_buffer);
setPixmap(iconImage.scaled(80, 80, Qt::KeepAspectRatio, Qt::SmoothTransformation));
setIcon(realImage);
}
#include "googlefetcherdialog.moc"
......
......@@ -18,16 +18,19 @@
#define GOOGLEFETCHERDIALOG_H
#include <kdialog.h>
#include <k3iconview.h>
#include "googlefetcher.h"
#include "filehandle.h"
#include <QPixmap>
#include <QStandardItem>
#include <QByteArray>
#include <QPointer>
class KUrl;
class QListView;
class GoogleFetcherDialog : public KDialog
{
Q_OBJECT
......@@ -54,9 +57,11 @@ public slots:
void refreshScreen(GoogleImageList &list);
protected slots:
void slotActivated(const QModelIndex &);
void slotOk();
void slotCancel();
void showCreditURL(const QString &url);
void selectedItemIsBad();
private:
QPixmap fetchedImage(int index) const;
......@@ -64,7 +69,7 @@ private:
QPixmap m_pixmap;
GoogleImageList m_imageList;
K3IconView *m_iconWidget;
QListView *m_iconWidget;
bool m_takeIt;
bool m_newSearch;
FileHandle m_file;
......@@ -72,25 +77,26 @@ private:
namespace KIO
{
class TransferJob;
class StoredTransferJob;
class Job;
}
class CoverIconViewItem : public QObject, public K3IconViewItem
class KJob;
class CoverIconViewItem : public QObject, public QStandardItem
{
Q_OBJECT
public:
CoverIconViewItem(Q3IconView *parent, const GoogleImage &image);
CoverIconViewItem(QWidget *parent, const GoogleImage &image);
~CoverIconViewItem();
private slots:
void imageData(KIO::Job *job, const QByteArray &data);
void imageResult(KIO::Job *job);
void imageResult(KJob *job);
private:
QByteArray m_buffer;
QPointer<KIO::TransferJob> m_job;
QPointer<KIO::StoredTransferJob> m_job;
};
#endif
......
......@@ -821,16 +821,6 @@ void Playlist::slotShowCoverManager()
managerDialog->show();
}
unsigned int Playlist::eligibleCoverItems(const PlaylistItemList &items)
{
// This used to count the number of tracks with an artist and album, that
// is not strictly required anymore. This may prove useful in the future
// so I'm leaving it in for now, right now we just mark every item as
// eligible.
return items.count();
}
void Playlist::slotAddCover(bool retrieveLocal)
{
PlaylistItemList items = selectedItems();
......@@ -838,18 +828,6 @@ void Playlist::slotAddCover(bool retrieveLocal)
if(items.isEmpty())
return;
if(eligibleCoverItems(items) == 0) {
// No items in the list can be assigned a cover, inform the user and
// bail.
// KDE 4.0 Fix this string.
KMessageBox::sorry(this, i18n("None of the items you have selected can "
"be assigned a cover. A track must have both the Artist "
"and Album tags set to be assigned a cover."));
return;
}
QPixmap newCover;
if(retrieveLocal) {
......
......@@ -551,13 +551,6 @@ private:
void refreshAlbum(const QString &artist, const QString &album);
/**
* Returns the number of PlaylistItems in @p items that can be assigned a
* cover. Used to avoid wasting the users' time setting the cover for 20
* items when none are eligible.
*/
unsigned int eligibleCoverItems(const PlaylistItemList &items);
void updatePlaying() const;
/**
......
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