Commit a867577d authored by Nathan Toone's avatar Nathan Toone

Added a dropdown list for the googlefetcherdialog to allow you to choose the...

Added a dropdown list for the googlefetcherdialog to allow you to choose the image size (Very Small, Small, Medium, Large, Very Large).  Also changed the handling of no images (since all images are shown in the box, there is no need for a second popup saying that there is were no images))

svn path=/trunk/kdemultimedia/juk/; revision=362815
parent 1d1ae438
......@@ -44,17 +44,38 @@ GoogleFetcher::GoogleFetcher(const FileHandle &file)
}
void GoogleFetcher::loadImageURLs()
void GoogleFetcher::loadImageURLs(GoogleFetcher::ImageSize size)
{
if(m_loadedQuery == m_searchString)
if(m_loadedQuery == m_searchString && m_loadedSize == size)
return;
m_imageList.clear();
KURL url("http://images.google.com/images");
url.addQueryItem("q", m_searchString);
switch (size) {
case XLarge:
url.addQueryItem("imgsz", "xlarge|xxlarge");
break;
case Large:
url.addQueryItem("imgsz", "large");
break;
case Medium:
url.addQueryItem("imgsz", "medium");
break;
case Small:
url.addQueryItem("imgsz", "small");
break;
case Icon:
url.addQueryItem("imgsz", "icon");
break;
default:
break;
}
m_loadedQuery = m_searchString;
m_loadedSize = size;
DOM::HTMLDocument search;
search.setAsync(false);
......@@ -71,6 +92,7 @@ void GoogleFetcher::loadImageURLs()
if(topLevelNodes.length() <= 5 ||
topLevelNodes.item(4).nodeName().string() != "font")
{
emit newSearch(m_imageList);
return;
}
......@@ -80,7 +102,12 @@ void GoogleFetcher::loadImageURLs()
DOM::Node thisTopNode = topLevelNodes.item(i);
if(thisTopNode.nodeName().string() == "table") {
DOM::NodeList images = thisTopNode.firstChild().firstChild().childNodes();
uint imageIndex = 0;
if(thisTopNode.firstChild().firstChild().firstChild().attributes().getNamedItem("colspan") != NULL)
imageIndex = 1;
DOM::NodeList images = thisTopNode.firstChild().childNodes().item(imageIndex).childNodes();
// For each table node, pull the images out of the first row
......@@ -90,7 +117,7 @@ void GoogleFetcher::loadImageURLs()
.getNamedItem("src").nodeValue().string();
DOM::Node topFont = thisTopNode.firstChild().childNodes()
.item(1).childNodes().item(j).firstChild();
.item(imageIndex + 1).childNodes().item(j).firstChild();
// And pull the size out of the second row
......@@ -103,46 +130,37 @@ void GoogleFetcher::loadImageURLs()
}
}
}
emit newSearch(m_imageList);
}
QPixmap GoogleFetcher::pixmap()
{
m_chosen = false;
m_selectedIndex = 0;
m_loadedSize = All;
displayWaitMessage();
while(!m_chosen) {
if(m_imageList.size() == 0) {
GoogleFetcherDialog *dialog = new GoogleFetcherDialog("google", m_imageList, m_selectedIndex, m_file, 0);
connect (dialog, SIGNAL(sizeChanged(GoogleFetcher::ImageSize)), this, SLOT(loadImageURLs(GoogleFetcher::ImageSize)));
connect (this, SIGNAL(newSearch(GoogleImageList&)), dialog, SLOT(refreshScreen(GoogleImageList&)));
dialog->exec();
m_currentPixmap = ((GoogleFetcherDialog*)dialog)->result();
m_chosen = ((GoogleFetcherDialog*)dialog)->takeIt();
if(((GoogleFetcherDialog*)dialog)->newSearch()) {
bool ok;
m_searchString =
KInputDialog::getText(i18n("Cover Downloader"),
i18n("No covers found. Enter new search terms:"),
m_searchString, &ok);
m_searchString = KInputDialog::getText(i18n("Cover Downloader"),
i18n("Enter new search terms:"),
m_searchString, &ok);
if(ok && !m_searchString.isEmpty())
displayWaitMessage();
else {
m_currentPixmap = QPixmap();
m_chosen = true;
}
else
m_searchString = m_loadedQuery;
}
else {
GoogleFetcherDialog dialog("google", m_imageList, m_selectedIndex, m_file, 0);
dialog.exec();
m_currentPixmap = dialog.result();
m_chosen = dialog.takeIt();
if(dialog.newSearch()) {
bool ok;
m_searchString = KInputDialog::getText(i18n("Cover Downloader"),
i18n("Enter new search terms:"),
m_searchString, &ok);
if(ok && !m_searchString.isEmpty())
displayWaitMessage();
else
m_searchString = m_loadedQuery;
}
if (dialog) {
delete dialog;
dialog=0;
}
}
return m_currentPixmap;
......@@ -155,3 +173,6 @@ void GoogleFetcher::displayWaitMessage()
loadImageURLs();
statusBar->clear();
}
#include "googlefetcher.moc"
......@@ -15,6 +15,8 @@
#ifndef GOOGLEFETCHER_H
#define GOOGLEFETCHER_H
#include <kdialogbase.h>
#include <qpixmap.h>
#include <qstringlist.h>
#include <qregexp.h>
......@@ -38,9 +40,15 @@ private:
QString m_size;
};
class GoogleFetcher
typedef QValueList<GoogleImage> GoogleImageList;
class GoogleFetcher : public QObject
{
Q_OBJECT
public:
enum ImageSize { All, Icon, Small, Medium, Large, XLarge };
GoogleFetcher(const FileHandle &file);
QPixmap pixmap();
......@@ -50,16 +58,23 @@ private:
void saveCover();
void previous();
void next();
void loadImageURLs();
void displayWaitMessage();
void buildBox();
FileHandle m_file;
QString m_searchString;
QString m_loadedQuery;
QValueList<GoogleImage> m_imageList;
ImageSize m_loadedSize;
GoogleImageList m_imageList;
bool m_chosen;
uint m_selectedIndex;
QPixmap m_currentPixmap;
KDialogBase *m_dialog;
signals:
void newSearch(GoogleImageList&);
private slots:
void loadImageURLs(GoogleFetcher::ImageSize size = All);
};
#endif
......@@ -16,15 +16,18 @@
#include <klocale.h>
#include <kdebug.h>
#include <kmessagebox.h>
#include <kcombobox.h>
#include <qhbox.h>
#include <qimage.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include "googlefetcherdialog.h"
#include "tag.h"
GoogleFetcherDialog::GoogleFetcherDialog(const QString &name,
const QValueList<GoogleImage> &imageList,
const GoogleImageList &imageList,
uint selectedIndex,
const FileHandle &file,
QWidget *parent) :
......@@ -46,7 +49,22 @@ GoogleFetcherDialog::GoogleFetcherDialog(const QString &name,
m_iconWidget->setFixedSize(500,550);
m_iconWidget->arrangeItemsInGrid();
m_iconWidget->setItemsMovable(FALSE);
QHBox *imgSize = new QHBox(actionButton(User1)->parentWidget());
QLabel *label = new QLabel(imgSize);
label->setText(i18n("Image Size: "));
KComboBox *combo = new KComboBox(imgSize);
combo->insertItem(i18n("All Sizes"));
combo->insertItem(i18n("Very Small"));
combo->insertItem(i18n("Small"));
combo->insertItem(i18n("Medium"));
combo->insertItem(i18n("Large"));
combo->insertItem(i18n("Very Large"));
combo->setCurrentItem(0);
connect(combo, SIGNAL(activated(int)), this, SLOT(imgSizeChanged(int)));
imgSize->adjustSize();
setMainWidget(mainBox);
setButtonText(User1, i18n("New Search"));
}
......@@ -70,10 +88,21 @@ void GoogleFetcherDialog::setLayout()
adjustSize();
}
void GoogleFetcherDialog::setImageList(const GoogleImageList &imageList)
{
m_imageList=imageList;
}
////////////////////////////////////////////////////////////////////////////////
// public slots
////////////////////////////////////////////////////////////////////////////////
void GoogleFetcherDialog::refreshScreen(GoogleImageList &imageList)
{
setImageList(imageList);
setLayout();
}
int GoogleFetcherDialog::exec()
{
setLayout();
......@@ -117,6 +146,30 @@ void GoogleFetcherDialog::slotUser1()
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);
}
QPixmap GoogleFetcherDialog::fetchedImage(uint index) const
{
......
......@@ -33,7 +33,7 @@ class GoogleFetcherDialog : public KDialogBase
public:
GoogleFetcherDialog(const QString &name,
const QValueList<GoogleImage> &urlList,
const GoogleImageList &urlList,
uint selectedIndex,
const FileHandle &file,
QWidget *parent = 0);
......@@ -43,23 +43,29 @@ public:
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);
public slots:
int exec();
void refreshScreen(GoogleImageList &list);
signals:
int sizeChanged(GoogleFetcher::ImageSize);
protected slots:
void slotOk();
void slotCancel();
void slotUser1();
void imgSizeChanged(int index);
private:
void setLayout();
QPixmap fetchedImage(uint index) const;
QPixmap pixmapFromURL(const KURL &url) const;
QPixmap m_pixmap;
QValueList<GoogleImage> m_imageList;
GoogleImageList m_imageList;
KIconView *m_iconWidget;
bool m_takeIt;
bool m_newSearch;
......
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