Git commit 45d075cbf39704ea5587034b35550a175e1739b5 by Michael Pyne. Committed on 30/09/2017 at 19:02. Pushed by mpyne into branch 'frameworks'. Port WebImageFetch from KDialog. M +30 -27 webimagefetcher.cpp M +3 -11 webimagefetcher.h https://commits.kde.org/juk/45d075cbf39704ea5587034b35550a175e1739b5 diff --git a/webimagefetcher.cpp b/webimagefetcher.cpp index d770450..e80441e 100644 --- a/webimagefetcher.cpp +++ b/webimagefetcher.cpp @@ -1,6 +1,6 @@ /** * Copyright (C) 2004 Nathan Toone - * Copyright (C) 2007 Michael Pyne + * Copyright (C) 2007, 2017 Michael Pyne * Copyright (C) 2012 Martin Sandsmark * * This program is free software; you can redistribute it and/or modify it= under @@ -19,11 +19,9 @@ #include "webimagefetcher.h" = #include -#include #include -#include #include -#include +#include = #include "covermanager.h" #include "filehandle.h" @@ -32,6 +30,9 @@ #include "juk_debug.h" = #include +#include +#include +#include #include #include #include @@ -42,27 +43,21 @@ #include #include = -#include - - class WebImageFetcher::Private { friend class WebImageFetcher; = - Private() : connection(0), dialog(0) - { - } - FileHandle file; QString artist; QString albumName; QPointer connection; - KDialog *dialog; + QDialog *dialog =3D nullptr; QUrl url; }; = WebImageFetcher::WebImageFetcher(QObject *parent) - : QObject(parent), d(new Private) + : QObject(parent) + , d(new Private) { } = @@ -160,21 +155,22 @@ void WebImageFetcher::slotImageFetched(KJob* j) = KIO::StoredTransferJob *job =3D qobject_cast(= j); = - if (d->dialog) return; - d->dialog =3D new KDialog(); - d->dialog->setCaption(i18n("Cover found")); - d->dialog->setButtons(KDialog::Apply | KDialog::Cancel); - d->dialog->button(KDialog::Apply)->setText(i18n("Store")); - QWidget *mainWidget =3D new QWidget(); - d->dialog->setMainWidget(mainWidget); - mainWidget->setLayout(new QVBoxLayout); + if (d->dialog) + return; + + d->dialog =3D new QDialog; + d->dialog->setWindowTitle(i18n("Cover found")); + + auto dlgVLayout =3D new QVBoxLayout(d->dialog); = if(job->error()) { qCCritical(JUK_LOG) << "Unable to grab image\n"; d->dialog->setWindowIcon(DesktopIcon("dialog-error")); + // TODO: What kind of error announcement is this?? return; } = + // TODO: 150x150 seems inconsistent with HiDPI, figure out something b= etter QPixmap iconImage, realImage(150, 150); iconImage.loadFromData(job->data()); realImage.fill(Qt::transparent); @@ -188,18 +184,25 @@ void WebImageFetcher::slotImageFetched(KJob* j) if(iconImage.width() > 150 || iconImage.height() > 150) iconImage =3D iconImage.scaled(150, 150, Qt::KeepAspectRatio, Qt::= SmoothTransformation); = - QLabel *cover =3D new QLabel(); + QLabel *cover =3D new QLabel(d->dialog); cover->setPixmap(iconImage); - mainWidget->layout()->addWidget(cover); - QLabel *infoLabel =3D new QLabel(i18n("Cover fetched from last.fm.")); + dlgVLayout->addWidget(cover); + + QLabel *infoLabel =3D new QLabel(i18n("Cover fetched from last.fm."), d->dialog); infoLabel->setOpenExternalLinks(true); infoLabel->setTextInteractionFlags(Qt::TextBrowserInteraction); - mainWidget->layout()->addItem(new QSpacerItem(0, 0, QSizePolicy::Expan= ding, QSizePolicy::Expanding)); - mainWidget->layout()->addWidget(infoLabel); + dlgVLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSiz= ePolicy::Expanding)); + dlgVLayout->addWidget(infoLabel); + + auto buttonBox =3D new QDialogButtonBox(QDialogButtonBox::Save | QDial= ogButtonBox::Cancel, d->dialog); + dlgVLayout->addWidget(buttonBox); + connect(buttonBox, &QDialogButtonBox::accepted, d->dialog, &QDialog::a= ccept); + connect(buttonBox, &QDialogButtonBox::rejected, d->dialog, &QDialog::r= eject); + + connect(d->dialog, &QDialog::accepted, this, &WebImageFetcher::slotCov= erChosen); = d->dialog->setWindowIcon(realImage); d->dialog->show(); - connect(d->dialog, SIGNAL(applyClicked()), SLOT(slotCoverChosen())); } = = diff --git a/webimagefetcher.h b/webimagefetcher.h index d602289..701f6f0 100644 --- a/webimagefetcher.h +++ b/webimagefetcher.h @@ -16,22 +16,14 @@ * this program. If not, see . */ = -#ifndef WEBIMAGEFETCHER_H -#define WEBIMAGEFETCHER_H +#ifndef JUK_WEBIMAGEFETCHER_H +#define JUK_WEBIMAGEFETCHER_H = #include = -// Predeclare some classes. - - -template -class QList; - class KJob; - class FileHandle; = - class WebImageFetcher : public QObject { Q_OBJECT @@ -46,7 +38,6 @@ public slots: void abortSearch(); void searchCover(); = - signals: void signalCoverChanged(int coverId); = @@ -59,6 +50,7 @@ private: class Private; Private *d; }; + #endif = // vim: set et sw=3D4 tw=3D0 sta: