Commit 43d00bc7 authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Port away from KIconLoader

Use icon names instead of pixmaps where possible

Query sizes from QStyle
parent 7ceb76b4
Pipeline #197214 passed with stage
in 7 minutes and 50 seconds
......@@ -376,7 +376,7 @@ QVariant FileModel::data(const QModelIndex &index, int role) const
}
else
{
return Transfer::statusPixmap(status);
return QIcon::fromTheme(Transfer::statusIconName(status));
}
}
} else {
......
......@@ -38,7 +38,7 @@ void Job::setStatus(Status jobStatus)
if (m_status == Aborted) {
m_error.id = -1;
m_error.text.clear();
m_error.pixmap = QPixmap();
m_error.iconName = QString();
m_error.type = AutomaticRetry;
}
m_status = jobStatus;
......@@ -62,12 +62,12 @@ void Job::setPolicy(Policy jobPolicy)
m_scheduler->jobChangedEvent(this, m_policy);
}
void Job::setError(const QString &text, const QPixmap &pixmap, ErrorType type, int errorId)
void Job::setError(const QString &text, const QString &iconName, ErrorType type, int errorId)
{
setStatus(Job::Aborted);
m_error.id = errorId;
m_error.text = text;
m_error.pixmap = pixmap;
m_error.iconName = iconName;
m_error.type = type;
}
......
......@@ -73,7 +73,7 @@ class KGET_EXPORT Job : public QObject
struct Error {
int id;
QString text;
QPixmap pixmap;
QString iconName;
ErrorType type;
};
Job(Scheduler * scheduler, JobQueue * parent);
......@@ -88,7 +88,7 @@ class KGET_EXPORT Job : public QObject
//Job properties
void setStatus(Status jobStatus);
void setPolicy(Policy jobPolicy);
void setError(const QString &text, const QPixmap &pixmap, ErrorType type = AutomaticRetry, int errorId = -1);
void setError(const QString &text, const QString &iconName, ErrorType type = AutomaticRetry, int errorId = -1);
Status status() const {return m_status;}
Status startStatus() const { return m_startStatus;}
......
......@@ -1384,7 +1384,7 @@ void GenericObserver::transfersChangedEvent(QMap<TransferHandler*, Transfer::Cha
} else if (transfer->status() == Job::Aborted && transfer->error().type != Job::AutomaticRetry) {
KNotification * notification = KNotification::event("error", i18n("Error"), i18n("<p>There has been an error in the following transfer:</p><p style=\"font-size: small;\">%1</p>"
"<p>The error message is:</p><p style=\"font-size: small;\">%2</p>", transfer->source().toString(), transfer->error().text),
transfer->error().pixmap, KGet::m_mainWindow, KNotification::CloseOnTimeout);
transfer->error().iconName, KGet::m_mainWindow, KNotification::CloseOnTimeout);
if (transfer->error().type == Job::ManualSolve) {
m_notifications.insert(notification, transfer);
notification->setActions(QStringList() << i18n("Resolve"));
......
......@@ -17,7 +17,6 @@
#include "core/plugin/transferfactory.h"
#include "core/scheduler.h"
#include <KIconLoader>
#include <KLocalizedString>
#include <QDomElement>
......@@ -231,7 +230,7 @@ void Transfer::load(const QDomElement *element)
{
if (!element)
{
setStatus(status(), i18nc("transfer state: stopped", "Stopped"), SmallIcon("process-stop"));
setStatus(status(), i18nc("transfer state: stopped", "Stopped"), "process-stop");
setStartStatus(status());
return;
}
......@@ -250,7 +249,7 @@ void Transfer::load(const QDomElement *element)
setStartStatus(Job::Finished);
setStatus(startStatus());
} else {
setStatus(status(), i18nc("transfer state: stopped", "Stopped"), SmallIcon("process-stop"));
setStatus(status(), i18nc("transfer state: stopped", "Stopped"), "process-stop");
setStartStatus(status());
}
setUploadLimit(e.attribute("UploadLimit").toInt(), Transfer::VisibleSpeedLimit);
......@@ -275,7 +274,7 @@ void Transfer::load(const QDomElement *element)
}
}
void Transfer::setStatus(Job::Status jobStatus, const QString &text, const QPixmap &pix)
void Transfer::setStatus(Job::Status jobStatus, const QString &text, const QString &pix)
{
const bool statusChanged = (status() != jobStatus);
QString statusText = text;
......@@ -285,9 +284,9 @@ void Transfer::setStatus(Job::Status jobStatus, const QString &text, const QPixm
//always prefer pix, if it is set
if (!pix.isNull()) {
m_statusPixmap = pix;
} else if (statusChanged || m_statusPixmap.isNull()) {
m_statusPixmap = SmallIcon(STATUSICONS[jobStatus]);
m_statusIconName = pix;
} else if (statusChanged || m_statusIconName.isNull()) {
m_statusIconName = STATUSICONS[jobStatus];
}
m_statusText = statusText;
......@@ -327,7 +326,7 @@ QString Transfer::statusText(Job::Status status)
return i18nc(STATUSTEXTS[status].context, STATUSTEXTS[status].name);
}
QPixmap Transfer::statusPixmap(Job::Status status)
QString Transfer::statusIconName(Job::Status status)
{
return SmallIcon(STATUSICONS[status]);
return STATUSICONS[status];
}
......@@ -15,7 +15,6 @@
#include "job.h"
#include "kget_export.h"
#include <QPixmap>
#include <QTime>
#include <QUrl>
......@@ -169,10 +168,10 @@ class KGET_EXPORT Transfer : public Job
KIO::filesize_t downloadedSize() const {return m_downloadedSize;}
KIO::filesize_t uploadedSize() const {return m_uploadedSize;}
QString statusText() const {return m_statusText;}
QPixmap statusPixmap() const {return (error().pixmap.isNull() ? m_statusPixmap : error().pixmap);}
QString statusIconName() const {return (error().iconName.isEmpty() ? m_statusIconName : error().iconName);}
static QString statusText(Job::Status status);
static QPixmap statusPixmap(Job::Status status);
static QString statusIconName(Job::Status status);
int percent() const {return m_percent;}
int downloadSpeed() const {return m_downloadSpeed;}
......@@ -319,9 +318,9 @@ class KGET_EXPORT Transfer : public Job
protected:
/**
* Sets the Job status to jobStatus, the status text to text and
* the status pixmap to pix.
* the status icon to iconName.
*/
void setStatus(Job::Status jobStatus, const QString &text = QString(), const QPixmap &pix = QPixmap());
void setStatus(Job::Status jobStatus, const QString &text = QString(), const QString &iconName = QString());
/**
* Sets the capabilities and automatically emits capabilitiesChanged
......@@ -367,7 +366,7 @@ class KGET_EXPORT Transfer : public Job
double m_ratio;
QString m_statusText;
QPixmap m_statusPixmap;
QString m_statusIconName;
QTime m_runningTime;
TransferHandler * m_handler;
......
......@@ -212,9 +212,9 @@ class KGET_EXPORT TransferHandler : public Handler
QString statusText() const {return m_transfer->statusText();}
/**
* @return a pixmap associated with the current transfer status
* @return an icon name associated with the current transfer status
*/
QPixmap statusPixmap() const {return m_transfer->statusPixmap();}
QString statusIconName() const {return m_transfer->statusIconName();}
/**
* @returns the data associated to this Transfer item. This is
......
......@@ -114,7 +114,7 @@ QVariant TransferModelItem::data(int role) const
return m_mimeType;
}
case 1:
return m_transferHandler->statusPixmap();
return QIcon::fromTheme(m_transferHandler->statusIconName());
}
}
if (role == Qt::TextAlignmentRole)
......
......@@ -12,6 +12,9 @@
#include "transfergrouphandler.h"
#include "verifier.h"
#include <QApplication>
#include <QStyle>
DBusTransferWrapper::DBusTransferWrapper(TransferHandler *parent)
: QObject(parent),
m_transfer(parent)
......@@ -141,7 +144,8 @@ QString DBusTransferWrapper::statusText() const
QDBusVariant DBusTransferWrapper::statusPixmap() const
{
return QDBusVariant(QVariant::fromValue(m_transfer->statusPixmap()));
const QPixmap pix = QIcon::fromTheme(m_transfer->statusIconName()).pixmap(qApp->style()->pixelMetric(QStyle::PixelMetric::PM_SmallIconSize));
return QDBusVariant(QVariant::fromValue(pix));
}
void DBusTransferWrapper::slotTransferChanged(TransferHandler *transfer, TransferHandler::ChangesFlags changeFlags)
......
......@@ -415,7 +415,7 @@ void SchedulerTest::testJobErrorType()
auto *job = new TestJob(&scheduler, queue);
job->setPolicy(policy);
job->setError(QString(), QPixmap(), errorType);
job->setError(QString(), QString(), errorType);
queue->appendPub(job);
QCOMPARE(job->status(), finalStatus);
......
......@@ -27,7 +27,6 @@
#include <QSortFilterProxyModel>
#include <KConfigGroup>
#include <KIconLoader>
#include <KLocalizedString>
#include <KMessageBox>
#include <KRun>
......
......@@ -34,7 +34,6 @@
#include "kget_debug.h"
#include <KLocalizedString>
#include <KIconLoader>
#include <KIO/CopyJob>
#include <KMessageBox>
......@@ -137,7 +136,7 @@ void BTTransfer::start()
m_tmpTorrentFile = tmpDirName + m_dest.fileName();
auto *download = new Download(m_source, QUrl::fromLocalFile(m_tmpTorrentFile));
setStatus(Job::Stopped, i18n("Downloading Torrent File...."), SmallIcon("document-save"));
setStatus(Job::Stopped, i18n("Downloading Torrent File...."), "document-save");
setTransferChange(Tc_Status, true);
//m_source = tmpDirName + m_source.fileName();
......@@ -167,7 +166,7 @@ bool BTTransfer::setDirectory(const QUrl &newDirectory)
m_dest = m_dest.adjusted(QUrl::StripTrailingSlash);
m_dest.setPath(m_dest.path() + '/' + (torrent->getStats().torrent_name));
setStatus(Job::Stopped, i18nc("changing the destination of the file", "Changing destination"), SmallIcon("media-playback-pause"));
setStatus(Job::Stopped, i18nc("changing the destination of the file", "Changing destination"), "media-playback-pause");
setTransferChange(Tc_Status, true);
return true;
}
......@@ -181,7 +180,7 @@ void BTTransfer::newDestResult()
disconnect(torrent, &bt::TorrentInterface::aboutToBeStarted, this, &BTTransfer::newDestResult);
m_movingFile = false;
setStatus(Job::Running, i18nc("transfer state: downloading", "Downloading...."), SmallIcon("media-playback-start"));
setStatus(Job::Running, i18nc("transfer state: downloading", "Downloading...."), "media-playback-start");
setTransferChange(Tc_FileName | Tc_Status, true);
}
......@@ -223,7 +222,7 @@ void BTTransfer::load(const QDomElement *element)
if ((m_totalSize == m_downloadedSize) && (m_totalSize != 0))
{
setStatus(Job::Stopped, i18nc("transfer state: finished", "Finished"), SmallIcon("dialog-ok"));
setStatus(Job::Stopped, i18nc("transfer state: finished", "Finished"), "dialog-ok");
}
}
......@@ -285,7 +284,7 @@ void BTTransfer::startTorrent()
if (chunksTotal() == chunksDownloaded()/* && !m_downloadFinished*/) {
slotDownloadFinished(torrent);
} else {
setStatus(Job::Running, i18nc("transfer state: downloading", "Downloading...."), SmallIcon("media-playback-start"));
setStatus(Job::Running, i18nc("transfer state: downloading", "Downloading...."), "media-playback-start");
}
m_totalSize = torrent->getStats().total_bytes_to_download;
setTransferChange(Tc_Status | Tc_TrackersList | Tc_TotalSize, true);
......@@ -302,11 +301,11 @@ void BTTransfer::stopTorrent()
if (m_downloadFinished)
{
setStatus(Job::Stopped, i18nc("transfer state: finished", "Finished"), SmallIcon("dialog-ok"));
setStatus(Job::Stopped, i18nc("transfer state: finished", "Finished"), "dialog-ok");
}
else
{
setStatus(Job::Stopped, i18nc("transfer state: stopped", "Stopped"), SmallIcon("process-stop"));
setStatus(Job::Stopped, i18nc("transfer state: stopped", "Stopped"), "process-stop");
}
setTransferChange(Tc_Status, true);
......@@ -420,12 +419,12 @@ void BTTransfer::btTransferInit(const QUrl &src, const QByteArray &data)
QFile file(m_source.toLocalFile());
if (!file.open(QIODevice::ReadOnly)) {
setError(i18n("Torrent file does not exist"), SmallIcon("dialog-cancel"), Job::NotSolveable);
setError(i18n("Torrent file does not exist"), "dialog-cancel", Job::NotSolveable);
setTransferChange(Tc_Status, true);
return;
}
setStatus(Job::Stopped, i18n("Analyzing torrent...."), SmallIcon("document-preview")); // jpetso says: you should probably use the "process-working" icon here (from the animations category), but that's a multi-frame PNG so it's hard for me to test
setStatus(Job::Stopped, i18n("Analyzing torrent...."), "document-preview"); // jpetso says: you should probably use the "process-working" icon here (from the animations category), but that's a multi-frame PNG so it's hard for me to test
setTransferChange(Tc_Status, true);
bt::InitLog(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/torrentlog.log"), false, false);//initialize the torrent-log
......@@ -437,7 +436,7 @@ void BTTransfer::btTransferInit(const QUrl &src, const QByteArray &data)
i++;
if (i == 10) {
setError(i18n("Cannot initialize port..."), SmallIcon("dialog-cancel"));
setError(i18n("Cannot initialize port..."), "dialog-cancel");
setTransferChange(Tc_Status);
return;
}
......@@ -486,7 +485,7 @@ void BTTransfer::btTransferInit(const QUrl &src, const QByteArray &data)
m_ready = false;
torrent->deleteLater();
torrent = nullptr;
setError(err.toString(), SmallIcon("dialog-cancel"), Job::NotSolveable);
setError(err.toString(), "dialog-cancel", Job::NotSolveable);
setTransferChange(Tc_Status);
return;
}
......@@ -498,7 +497,7 @@ void BTTransfer::slotStoppedByError(const bt::TorrentInterface* &error, const QS
{
Q_UNUSED(error)
stop();
setError(errormsg, SmallIcon("dialog-cancel"), Job::NotSolveable);
setError(errormsg, "dialog-cancel", Job::NotSolveable);
setTransferChange(Tc_Status);
}
......@@ -508,7 +507,7 @@ void BTTransfer::slotDownloadFinished(bt::TorrentInterface* ti)
Q_UNUSED(ti)
m_downloadFinished = true;
//timer.stop();
setStatus(Job::FinishedKeepAlive, i18nc("Transfer status: seeding", "Seeding...."), SmallIcon("media-playback-start"));
setStatus(Job::FinishedKeepAlive, i18nc("Transfer status: seeding", "Seeding...."), "media-playback-start");
setTransferChange(Tc_Status, true);
}
......
......@@ -14,7 +14,6 @@
#include "script.h"
#include <QDebug>
#include <KIconLoader>
#include <KLocalizedString>
#include <KMessageBox>
#include <KUrl>
......@@ -49,7 +48,7 @@ void ContentFetch::deinit()
void ContentFetch::start()
{
qCDebug(KGET_DEBUG) << "ContentFetch::start";
setStatus(Job::Running, i18nc("Transfer state: processing script", "Processing script...."), SmallIcon("media-playback-start"));
setStatus(Job::Running, i18nc("Transfer state: processing script", "Processing script...."), "media-playback-start");
setTransferChange(Tc_Status, true);
m_p_script->setFile(m_scriptFile);
m_p_script->start();
......@@ -66,7 +65,7 @@ void ContentFetch::stop()
// kill -9 the script
m_p_script->terminate();
// delete m_p_script to avoid crash?
setStatus(Job::Stopped, i18nc("transfer state: stopped", "Stopped"), SmallIcon("process-stop"));
setStatus(Job::Stopped, i18nc("transfer state: stopped", "Stopped"), "process-stop");
setTransferChange(Tc_Status, true);
}
......@@ -80,7 +79,7 @@ void ContentFetch::slotAddTransfer(const QString &url, const QString &filename)
void ContentFetch::slotFinish()
{
m_percent = 100;
setStatus(Job::Finished, i18nc("Transfer State: Finished", "Finished"), SmallIcon("dialog-ok"));
setStatus(Job::Finished, i18nc("Transfer State: Finished", "Finished"), "dialog-ok");
setTransferChange(Tc_Status|Tc_Percent, true);
//delete m_p_script;
}
......@@ -89,18 +88,18 @@ void ContentFetch::slotAbort(const QString &error)
{
if (error.isEmpty())
{
setStatus(Job::Aborted, i18nc("Transfer State: Aborted", "Aborted"), SmallIcon("process-stop"));
setStatus(Job::Aborted, i18nc("Transfer State: Aborted", "Aborted"), "process-stop");
}
else
{
setStatus(Job::Aborted, error, SmallIcon("process-stop"));
setStatus(Job::Aborted, error, "process-stop");
}
setTransferChange(Tc_Status, true);
}
void ContentFetch::slotSetTextStatus(const QString& text)
{
setStatus(Job::Running, text, SmallIcon("media-playback-start"));
setStatus(Job::Running, text, "media-playback-start");
setTransferChange(Tc_Status, true);
}
......
......@@ -23,7 +23,6 @@
#include "kget_debug.h"
#include <QDebug>
#include <KIconLoader>
#include <KIO/Scheduler>
#include <KIO/DeleteJob>
#include <KIO/CopyJob>
......@@ -98,7 +97,7 @@ void TransferKio::start()
createJob();
qCDebug(KGET_DEBUG) << "TransferKio::start";
setStatus(Job::Running, i18nc("transfer state: connecting", "Connecting...."), SmallIcon("network-connect")); // should be "network-connecting", but that doesn't exist for KDE 4.0 yet
setStatus(Job::Running, i18nc("transfer state: connecting", "Connecting...."), "network-connect"); // should be "network-connecting", but that doesn't exist for KDE 4.0 yet
setTransferChange(Tc_Status, true);
}
}
......
......@@ -23,7 +23,6 @@
#include "core/signature.h"
#include "kget_debug.h"
#include <KIconLoader>
#include <KIO/DeleteJob>
#include <KIO/RenameDialog>
#include <KLocalizedString>
......
......@@ -26,7 +26,6 @@
#include <algorithm>
#include <KConfigGroup>
#include <KIconLoader>
#include <KIO/DeleteJob>
#include <KIO/RenameDialog>
#include <KLocalizedString>
......@@ -78,7 +77,7 @@ void Metalink::downloadMetalink()
{
m_metalinkJustDownloaded = true;
setStatus(Job::Stopped, i18n("Downloading Metalink File...."), SmallIcon("document-save"));
setStatus(Job::Stopped, i18n("Downloading Metalink File...."), "document-save");
setTransferChange(Tc_Status, true);
// make sure that the DataLocation directory exists (earlier this used to be handled by KStandardDirs)
if (!QFileInfo::exists(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation))) {
......
......@@ -26,7 +26,6 @@
#include "kget_debug.h"
#include <KIconLoader>
#include <KIO/DeleteJob>
#include <KIO/RenameDialog>
#include <KLocalizedString>
......
......@@ -29,7 +29,6 @@
#include <algorithm>
#include <KConfigGroup>
#include <KIconLoader>
#include <KIO/DeleteJob>
#include <KIO/RenameDialog>
#include <KLocalizedString>
......@@ -75,7 +74,7 @@ void MetalinkXml::downloadMetalink()
{
m_metalinkJustDownloaded = true;
setStatus(Job::Running, i18n("Downloading Metalink File...."), SmallIcon("document-save"));
setStatus(Job::Running, i18n("Downloading Metalink File...."), "document-save");
setTransferChange(Tc_Status, true);
// make sure that the DataLocation directory exists (earlier this used to be handled by KStandardDirs)
if (!QFileInfo::exists(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation))) {
......
......@@ -57,8 +57,7 @@ void MmsTransfer::start()
return;
}
setStatus(Job::Running, i18nc("transfer state: running", "Running...."),
QIcon::fromTheme("media-playback-start").pixmap(16));
setStatus(Job::Running, i18nc("transfer state: running", "Running...."), "media-playback-start");
m_mmsdownload = new MmsDownload(m_source.toString(), m_dest.toLocalFile(),
m_fileTemp, m_amountThreads);
connect(m_mmsdownload, SIGNAL(finished()), this, SLOT(slotResult()));
......@@ -92,8 +91,7 @@ void MmsTransfer::stop()
}
}
setStatus(Job::Stopped, i18nc("transfer state: stopped", "Stopped"),
QIcon::fromTheme("process-stop").pixmap(16));
setStatus(Job::Stopped, i18nc("transfer state: stopped", "Stopped"), "process-stop");
m_downloadSpeed = 0;
setTransferChange(Tc_Status | Tc_DownloadSpeed, true);
}
......@@ -124,8 +122,7 @@ void MmsTransfer::slotResult()
* the temporary file where is saved the status of all threads that download the file.
*/
if (m_downloadedSize == m_totalSize && m_totalSize != 0) {
setStatus(Job::Finished, i18nc("Transfer State:Finished","Finished"),
QIcon::fromTheme("dialog-ok").pixmap(16));
setStatus(Job::Finished, i18nc("Transfer State:Finished","Finished"), "dialog-ok");
m_percent = 100;
m_downloadSpeed = 0;
setTransferChange(Tc_Status | Tc_Percent | Tc_DownloadSpeed, true);
......@@ -171,7 +168,7 @@ void MmsTransfer::slotProcessedSizeAndPercent(qulonglong size)
void MmsTransfer::slotBrokenUrl()
{
setError(i18n("Download failed, could not access this URL."), QIcon::fromTheme("dialog-cancel").pixmap(16),
setError(i18n("Download failed, could not access this URL."), "dialog-cancel",
Job::NotSolveable);
setTransferChange(Tc_Status, true);
}
......
......@@ -27,7 +27,6 @@
#include "kget_debug.h"
#include <KIconLoader>
#include <KIO/CopyJob>
#include <KLocalizedString>
#include <KMessageBox>
......
Supports Markdown
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