Commit 7fde3f93 authored by Scott Wheeler's avatar Scott Wheeler

General cleaning. Remove variables from the class that are only used in one

method, fix style and content (i.e. comparing an object to NULL is just a bad,
bad idea) and remember:  the stack is our friend.  Only new things if you need
to.  :-)

CCMAIL:Nathan Toone <nathan@toonetown.com>

svn path=/trunk/kdemultimedia/juk/; revision=363064
parent 5f33ee90
......@@ -44,7 +44,7 @@ GoogleFetcher::GoogleFetcher(const FileHandle &file)
}
void GoogleFetcher::loadImageURLs(GoogleFetcher::ImageSize size)
void GoogleFetcher::slotLoadImageURLs(GoogleFetcher::ImageSize size)
{
if(m_loadedQuery == m_searchString && m_loadedSize == size)
return;
......@@ -92,7 +92,7 @@ void GoogleFetcher::loadImageURLs(GoogleFetcher::ImageSize size)
if(topLevelNodes.length() <= 5 ||
topLevelNodes.item(4).nodeName().string() != "font")
{
emit newSearch(m_imageList);
emit signalNewSearch(m_imageList);
return;
}
......@@ -104,8 +104,11 @@ void GoogleFetcher::loadImageURLs(GoogleFetcher::ImageSize size)
if(thisTopNode.nodeName().string() == "table") {
uint imageIndex = 0;
if(thisTopNode.firstChild().firstChild().firstChild().attributes().getNamedItem("colspan") != NULL)
if(!thisTopNode.firstChild().firstChild().firstChild()
.attributes().getNamedItem("colspan").isNull())
{
imageIndex = 1;
}
DOM::NodeList images = thisTopNode.firstChild().childNodes().item(imageIndex).childNodes();
......@@ -130,25 +133,30 @@ void GoogleFetcher::loadImageURLs(GoogleFetcher::ImageSize size)
}
}
}
emit newSearch(m_imageList);
emit signalNewSearch(m_imageList);
}
QPixmap GoogleFetcher::pixmap()
{
m_chosen = false;
m_selectedIndex = 0;
bool chosen = false;
const int selectedIndex = 0;
m_loadedSize = All;
displayWaitMessage();
while(!m_chosen) {
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()) {
QPixmap pixmap;
while(!chosen) {
GoogleFetcherDialog dialog("google", m_imageList, selectedIndex, m_file, 0);
connect(&dialog, SIGNAL(sizeChanged(GoogleFetcher::ImageSize)),
this, SLOT(slotLoadImageURLs(GoogleFetcher::ImageSize)));
connect(this, SIGNAL(signalNewSearch(GoogleImageList &)),
&dialog, SLOT(refreshScreen(GoogleImageList &)));
dialog.exec();
pixmap = dialog.result();
chosen = dialog.takeIt();
if(dialog.newSearch()) {
bool ok;
m_searchString = KInputDialog::getText(i18n("Cover Downloader"),
i18n("Enter new search terms:"),
......@@ -158,19 +166,15 @@ QPixmap GoogleFetcher::pixmap()
else
m_searchString = m_loadedQuery;
}
if (dialog) {
delete dialog;
dialog=0;
}
}
return m_currentPixmap;
return pixmap;
}
void GoogleFetcher::displayWaitMessage()
{
KStatusBar *statusBar = static_cast<KMainWindow *>(kapp->mainWidget())->statusBar();
statusBar->message(i18n("Searching for Images. Please Wait..."));
loadImageURLs();
slotLoadImageURLs();
statusBar->clear();
}
......
......@@ -44,7 +44,7 @@ typedef QValueList<GoogleImage> GoogleImageList;
class GoogleFetcher : public QObject
{
Q_OBJECT
Q_OBJECT
public:
enum ImageSize { All, Icon, Small, Medium, Large, XLarge };
......@@ -61,20 +61,17 @@ private:
void displayWaitMessage();
void buildBox();
private slots:
void slotLoadImageURLs(GoogleFetcher::ImageSize size = All);
signals:
void signalNewSearch(GoogleImageList &images);
FileHandle m_file;
QString m_searchString;
QString m_loadedQuery;
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
......@@ -28,7 +28,7 @@
GoogleFetcherDialog::GoogleFetcherDialog(const QString &name,
const GoogleImageList &imageList,
uint selectedIndex,
uint /* selectedIndex */,
const FileHandle &file,
QWidget *parent) :
KDialogBase(parent, name.latin1(), true, QString::null,
......@@ -37,7 +37,6 @@ GoogleFetcherDialog::GoogleFetcherDialog(const QString &name,
m_imageList(imageList),
m_takeIt(false),
m_newSearch(false),
m_index(selectedIndex),
m_file(file)
{
QHBox *mainBox = new QHBox(this);
......@@ -111,12 +110,12 @@ int GoogleFetcherDialog::exec()
void GoogleFetcherDialog::slotOk()
{
uint selectedIndex=m_iconWidget->index(m_iconWidget->currentItem());
uint selectedIndex = m_iconWidget->index(m_iconWidget->currentItem());
m_pixmap = pixmapFromURL(m_imageList[selectedIndex].imageURL());
if(m_pixmap.isNull()) {
KMessageBox::sorry(this,
i18n("The cover you have selected is unavailable. Please select another."),
i18n("The cover you have selected is unavailable. Please select another."),
i18n("Cover Unavailable"));
QPixmap blankPix;
blankPix.resize(80, 80);
......@@ -148,16 +147,16 @@ void GoogleFetcherDialog::slotUser1()
void GoogleFetcherDialog::imgSizeChanged(int index)
{
GoogleFetcher::ImageSize imageSize=GoogleFetcher::All;
GoogleFetcher::ImageSize imageSize = GoogleFetcher::All;
switch (index) {
case 1:
imageSize=GoogleFetcher::Icon;
imageSize = GoogleFetcher::Icon;
break;
case 2:
imageSize=GoogleFetcher::Small;
imageSize = GoogleFetcher::Small;
break;
case 3:
imageSize=GoogleFetcher::Medium;
imageSize = GoogleFetcher::Medium;
break;
case 4:
imageSize=GoogleFetcher::Large;
......
......@@ -69,7 +69,6 @@ private:
KIconView *m_iconWidget;
bool m_takeIt;
bool m_newSearch;
uint m_index;
FileHandle m_file;
};
......
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