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

Port bugfix for bug 116181 (Internet cover search doesn't work) to KDE 4. You

can't see the thumbnails at this point but double-clicking still sets the cover
like it should.

I still need to rename the files on Friday but I'm closing the bug now.

svn path=/trunk/KDE/kdemultimedia/juk/; revision=678286
parent 7bd0b670
This diff is collapsed.
/***************************************************************************
copyright : (C) 2004 Nathan Toone
email : nathan@toonetown.com
copyright : (C) 2007 Michael Pyne
email : michael.pyne@kdemail.net
***************************************************************************/
/***************************************************************************
......@@ -25,16 +27,19 @@ class QPixmap;
template<class T>
class QList;
namespace DOM {
class HTMLDocument;
}
class KJob;
class FileHandle;
class GoogleFetcherDialog;
class GoogleImage
{
public:
explicit GoogleImage(QString thumbURL = QString(), QString size = QString());
GoogleImage();
GoogleImage(const QString &imageURL,
const QString &thumbURL,
int width, int height);
QString imageURL() const { return m_imageURL; }
QString thumbURL() const { return m_thumbURL; }
......@@ -53,23 +58,28 @@ class GoogleFetcher : public QObject
Q_OBJECT
public:
enum ImageSize { All, Icon, Small, Medium, Large, XLarge };
GoogleFetcher(QObject *parent);
~GoogleFetcher();
void setFile(const FileHandle &file);
void chooseCover();
GoogleFetcher(const FileHandle &file);
QPixmap pixmap();
public slots:
void abortSearch();
signals:
void signalNewSearch(GoogleImageList &images);
void signalCoverChanged(int coverId);
private:
void displayWaitMessage();
bool requestNewSearchTerms(bool noResults = false);
// Returns true if there are results in the search, otherwise returns false.
bool hasImageResults(DOM::HTMLDocument &search);
void requestNewSearchTerms(bool noResults = false);
private slots:
void slotLoadImageURLs(GoogleFetcher::ImageSize size = All);
void slotLoadImageURLs();
void slotWebRequestFinished(KJob *job);
void slotCoverChosen();
void slotNewSearch();
private:
class Private;
......
/***************************************************************************
copyright : (C) 2004 Nathan Toone
email : nathan@toonetown.com
copyright : (C) 2007 Michael Pyne
email : michael.pyne@kdemail.net
***************************************************************************/
/***************************************************************************
......@@ -22,29 +24,29 @@
#include <kdebug.h>
#include <k3iconview.h>
#include <kmessagebox.h>
#include <krun.h>
#include <kcombobox.h>
#include <khbox.h>
#include <kiconloader.h>
#include <kurllabel.h>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QImage>
#include <QLabel>
#include <QPushButton>
#include <QEventLoop>
#include <QPixmap>
GoogleFetcherDialog::GoogleFetcherDialog(const QString &name,
const GoogleImageList &imageList,
GoogleFetcherDialog::GoogleFetcherDialog(const GoogleImageList &imageList,
const FileHandle &file,
QWidget *parent) :
KDialog(parent),
m_pixmap(QPixmap()),
m_imageList(imageList),
m_takeIt(false),
m_newSearch(false),
m_file(file)
{
setObjectName(name.toAscii());
setObjectName("internet_image_fetcher");
setModal(true);
// setCaption(QString());
setButtons(Ok | Cancel | User1);
setDefaultButton(NoDefault);
showButtonSeparator(true);
......@@ -54,45 +56,54 @@ GoogleFetcherDialog::GoogleFetcherDialog(const QString &name,
#endif
//disableResize();
KHBox *mainBox = new KHBox(this);
QWidget *mainBox = new QWidget(this);
QBoxLayout *mainLayout = new QVBoxLayout(mainBox);
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()));
#ifdef __GNUC__
#warning This is probably wrong.
#endif
// Before changing the code below be sure to check the attribution terms
// of the Yahoo Image Search API.
// http://developer.yahoo.com/attribution/
KUrlLabel *logoLabel = new KUrlLabel(mainBox);
logoLabel->setUrl("http://developer.yahoo.com/about/");
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 &)),
SLOT(showCreditURL(const QString &)));
QBoxLayout *creditLayout = new QHBoxLayout;
mainLayout->addLayout(creditLayout);
creditLayout->addStretch(); // Left spacer
creditLayout->addWidget(logoLabel);
creditLayout->addStretch(); // Right spacer
KHBox *imgSize = new KHBox(parent /*actionButton(User1)->parentWidget()*/);
QLabel *label = new QLabel(imgSize);
label->setText(i18n("Image size:"));
KComboBox *combo = new KComboBox(imgSize);
combo->addItem(i18n("All Sizes"));
combo->addItem(i18n("Very Small"));
combo->addItem(i18n("Small"));
combo->addItem(i18n("Medium"));
combo->addItem(i18n("Large"));
combo->addItem(i18n("Very Large"));
combo->setCurrentIndex(0);
connect(combo, SIGNAL(activated(int)), this, SLOT(imgSizeChanged(int)));
imgSize->adjustSize();
setMainWidget(mainBox);
setButtonText(User1, i18n("New Search"));
connect(this,SIGNAL(user1Clicked()),this,SLOT(slotUser1()));
connect(this,SIGNAL(okClicked()),this,SLOT(slotOk()));
connect(this,SIGNAL(cancelClicked()),this,SLOT(slotCancel()));
connect(this, SIGNAL(user1Clicked()), SIGNAL(newSearchRequested()));
connect(this, SIGNAL(okClicked()), SLOT(slotOk()));
connect(this, SIGNAL(cancelClicked()), SLOT(slotCancel()));
}
GoogleFetcherDialog::~GoogleFetcherDialog()
{
}
void GoogleFetcherDialog::showCreditURL(const QString &url)
{
// Don't use static member since I'm sure that someday knowing my luck
// Yahoo will change their mimetype they serve.
(void) new KRun(KUrl(url), topLevelWidget());
}
void GoogleFetcherDialog::setLayout()
......@@ -111,7 +122,12 @@ void GoogleFetcherDialog::setLayout()
void GoogleFetcherDialog::setImageList(const GoogleImageList &imageList)
{
m_imageList=imageList;
m_imageList = imageList;
}
void GoogleFetcherDialog::setFile(const FileHandle &file)
{
m_file = file;
}
////////////////////////////////////////////////////////////////////////////////
......@@ -145,50 +161,14 @@ void GoogleFetcherDialog::slotOk()
return;
}
m_takeIt = true;
m_newSearch = false;
hide();
accept();
emit coverSelected();
}
void GoogleFetcherDialog::slotCancel()
{
m_takeIt = true;
m_newSearch = false;
m_pixmap = QPixmap();
hide();
}
void GoogleFetcherDialog::slotUser1()
{
m_takeIt = false;
m_newSearch = true;
m_pixmap = QPixmap();
hide();
}
void GoogleFetcherDialog::imgSizeChanged(int index)
{
GoogleFetcher::ImageSize imageSize = GoogleFetcher::All;
switch (index) {
case 1:
imageSize = GoogleFetcher::Icon;
break;
case 2:
imageSize = GoogleFetcher::Small;
break;
case 3:
imageSize = GoogleFetcher::Medium;
break;
case 4:
imageSize=GoogleFetcher::Large;
break;
case 5:
imageSize=GoogleFetcher::XLarge;
break;
default:
break;
}
emit sizeChanged(imageSize);
reject();
}
QPixmap GoogleFetcherDialog::fetchedImage(int index) const
......
/***************************************************************************
copyright : (C) 2004 Nathan Toone
email : nathan@toonetown.com
copyright : (C) 2007 Michael Pyne
email : michael.pyne@kdemail.net
***************************************************************************/
/***************************************************************************
......@@ -31,32 +33,30 @@ class GoogleFetcherDialog : public KDialog
Q_OBJECT
public:
GoogleFetcherDialog(const QString &name,
const GoogleImageList &urlList,
GoogleFetcherDialog(const GoogleImageList &urlList,
const FileHandle &file,
QWidget *parent = 0);
virtual ~GoogleFetcherDialog();
QPixmap result() const { return m_pixmap; }
bool takeIt() const { return m_takeIt; }
bool newSearch() const { return m_newSearch; }
void setLayout();
void setImageList(const GoogleImageList &urlList);
void setFile(const FileHandle &file);
signals:
void coverSelected();
void newSearchRequested();
public slots:
int exec();
void refreshScreen(GoogleImageList &list);
signals:
void sizeChanged(GoogleFetcher::ImageSize);
protected slots:
void slotOk();
void slotCancel();
void slotUser1();
void imgSizeChanged(int index);
void showCreditURL(const QString &url);
private:
QPixmap fetchedImage(int index) const;
......
install( FILES playing.png splash.png DESTINATION ${DATA_INSTALL_DIR}/juk/pics )
install( FILES playing.png splash.png yahoo_credit.png DESTINATION ${DATA_INSTALL_DIR}/juk/pics )
......@@ -321,6 +321,7 @@ Playlist::Playlist(PlaylistCollection *collection, const QString &name,
const QString &iconName) :
K3ListView(collection->playlistStack()),
m_collection(collection),
m_fetcher(new GoogleFetcher(this)),
m_selectedCount(0),
m_allowDuplicates(false),
m_applySharedSettings(true),
......@@ -343,6 +344,7 @@ Playlist::Playlist(PlaylistCollection *collection, const PlaylistItemList &items
const QString &name, const QString &iconName) :
K3ListView(collection->playlistStack()),
m_collection(collection),
m_fetcher(new GoogleFetcher(this)),
m_selectedCount(0),
m_allowDuplicates(false),
m_applySharedSettings(true),
......@@ -366,6 +368,7 @@ Playlist::Playlist(PlaylistCollection *collection, const QFileInfo &playlistFile
const QString &iconName) :
K3ListView(collection->playlistStack()),
m_collection(collection),
m_fetcher(new GoogleFetcher(this)),
m_selectedCount(0),
m_allowDuplicates(false),
m_applySharedSettings(true),
......@@ -388,6 +391,7 @@ Playlist::Playlist(PlaylistCollection *collection, const QFileInfo &playlistFile
Playlist::Playlist(PlaylistCollection *collection, bool delaySetup) :
K3ListView(collection->playlistStack()),
m_collection(collection),
m_fetcher(new GoogleFetcher(this)),
m_selectedCount(0),
m_allowDuplicates(false),
m_applySharedSettings(true),
......@@ -854,8 +858,9 @@ void Playlist::slotAddCover(bool retrieveLocal)
newCover = QPixmap(file.directory() + '/' + file.fileName());
}
else {
PlaylistItemList::Iterator it=items.begin();
newCover = GoogleFetcher((*it)->file()).pixmap();
m_fetcher->setFile((*items.begin())->file());
m_fetcher->chooseCover();
return;
}
if(newCover.isNull())
......@@ -868,6 +873,13 @@ void Playlist::slotAddCover(bool retrieveLocal)
refreshAlbums(items, newId);
}
// Called when image fetcher has added a new cover.
void Playlist::slotCoverChanged(int coverId)
{
kDebug(65432) << "Refreshing information for newly changed covers.\n";
refreshAlbums(selectedItems(), coverId);
}
void Playlist::slotGuessTagInfo(TagGuesser::Type type)
{
KApplication::setOverrideCursor(Qt::waitCursor);
......@@ -1437,6 +1449,9 @@ void Playlist::refreshAlbum(const QString &artist, const QString &album)
void Playlist::hideColumn(int c, bool updateSearch)
{
foreach (QAction *action, m_headerMenu->actions()) {
if(!action)
continue;
if (action->data().toInt() == c) {
action->setChecked(false);
break;
......@@ -1475,6 +1490,9 @@ void Playlist::hideColumn(int c, bool updateSearch)
void Playlist::showColumn(int c, bool updateSearch)
{
foreach (QAction *action, m_headerMenu->actions()) {
if(!action)
continue;
if (action->data().toInt() == c) {
action->setChecked(true);
break;
......@@ -1550,11 +1568,6 @@ void Playlist::slotInitialize()
// setup header RMB menu
//////////////////////////////////////////////////
m_columnVisibleAction = new KActionMenu(i18n("&Show Columns"), this);
ActionCollection::actions()->addAction("showColumns", m_columnVisibleAction);
m_headerMenu = m_columnVisibleAction->menu();
#ifdef __GNUC__
#warning should be fixed...
#endif
......@@ -1674,8 +1687,22 @@ void Playlist::setup()
setItemMargin(3);
connect(header(), SIGNAL(indexChange(int, int, int)), this, SLOT(slotColumnOrderChanged(int, int, int)));
connect(m_fetcher, SIGNAL(signalCoverChanged(int)), this, SLOT(slotCoverChanged(int)));
// Prevent list of selected items from changing while internet search is in
// progress.
connect(this, SIGNAL(selectionChanged()), m_fetcher, SLOT(abortSearch()));
setSorting(1);
// This apparently must be created very early in initialization for other
// Playlist code requiring m_headerMenu.
m_columnVisibleAction = new KActionMenu(i18n("&Show Columns"), this);
ActionCollection::actions()->addAction("showColumns", m_columnVisibleAction);
m_headerMenu = m_columnVisibleAction->menu();
// TODO: Determine if other stuff in setup must happen before slotInitialize().
QTimer::singleShot(0, this, SLOT(slotInitialize()));
}
......
......@@ -39,6 +39,7 @@ class QFileInfo;
class QMimeData;
class QDrag;
class GoogleFetcher;
class PlaylistItem;
class PlaylistCollection;
class PlaylistToolTip;
......@@ -601,6 +602,12 @@ private slots:
*/
void slotRenameTag();
/**
* The image fetcher will update the cover asynchronously, this internal
* slot is called when it happens.
*/
void slotCoverChanged(int coverId);
/**
* Moves the column \a from to the position \a to. This matches the signature
* for the signal QHeader::indexChange().
......@@ -641,6 +648,8 @@ private:
StringHash m_members;
GoogleFetcher *m_fetcher;
int m_currentColumn;
int m_processed;
int m_rmbEditID;
......
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