Commit aa3fc5d1 authored by Michael Pyne's avatar Michael Pyne

Port away from KUrl.

This removes KUrl from most (but not all) files and throws in minor
other assorted cleanups that I didn't want to split off into a separate
commit.
parent 6dcc3f85
......@@ -49,7 +49,7 @@ endif(TUNEPIMP_FOUND)
########### next target ###############
include_directories( ${TAGLIB_INCLUDES} )
add_definitions(-DQT_STL)
add_definitions(-DQT_STL -DQT_NO_URL_CAST_FROM_STRING)
# Look for Ogg Opus support in taglib (not released yet)
cmake_push_check_state()
......
......@@ -28,9 +28,9 @@
#include <QByteArray>
#include <QMap>
#include <QTemporaryFile>
#include <QUrl>
#include <kdemacros.h>
#include <kurl.h>
#include <kstandarddirs.h>
#include <kglobal.h>
#include <kio/job.h>
......@@ -405,30 +405,21 @@ QPixmap CoverManager::coverFromData(const CoverData &coverData, Size size)
coverKey CoverManager::addCover(const QPixmap &large, const QString &artist, const QString &album)
{
qCDebug(JUK_LOG) << "Adding new pixmap to cover database.";
if(large.isNull()) {
qCDebug(JUK_LOG) << "The pixmap you're trying to add is NULL!";
return NoMatch;
}
QTemporaryFile tempFile;
if(!tempFile.open()) {
qCCritical(JUK_LOG) << "Unable to open file for pixmap cover, unable to add cover to DB";
return NoMatch;
}
// Now that file is open, file name will be available, which is where we want
// to save the pixmap as a .png.
if(!large.save(tempFile.fileName(), "PNG")) {
if(!tempFile.open() || !large.save(tempFile.fileName(), "PNG")) {
qCCritical(JUK_LOG) << "Unable to save pixmap to " << tempFile.fileName();
return NoMatch;
}
return addCover(KUrl::fromPath(tempFile.fileName()), artist, album);
return addCover(QUrl::fromLocalFile(tempFile.fileName()), artist, album);
}
coverKey CoverManager::addCover(const KUrl &path, const QString &artist, const QString &album)
coverKey CoverManager::addCover(const QUrl &path, const QString &artist, const QString &album)
{
coverKey id = data()->nextId();
CoverData coverData;
......@@ -459,8 +450,8 @@ coverKey CoverManager::addCover(const KUrl &path, const QString &artist, const Q
// it assumes we merely want the file on the hard disk somewhere.
KIO::FileCopyJob *job = KIO::file_copy(
path, KUrl::fromPath(coverData.path),
-1 /* perms */,KIO::HideProgressInfo | KIO::Overwrite
path, QUrl::fromLocalFile(coverData.path),
-1 /* perms */, KIO::HideProgressInfo | KIO::Overwrite
);
QObject::connect(job, SIGNAL(result(KJob*)),
data()->coverProxy(), SLOT(handleResult(KJob*)));
......
......@@ -29,13 +29,12 @@ class CoverManagerPrivate;
class CoverProxy;
class QPixmap;
class QTimer;
class QUrl;
class KJob;
template<class T>
class QList;
class KUrl;
/**
* This class saves the covers when its saveCovers() slot is called to avoid
* making CoverManager a QObject and avoid moving the actual implementation
......@@ -58,14 +57,10 @@ private:
};
/**
* This class holds the data on a cover. This includes the path to the cover
* representation on-disk, and the artist and album associated with the cover.
* This class holds the data on a cover.
* Don't assume that the artist or album information is filled out, it is
* there to allow the CoverManager to try to automatically assign covers to
* new tracks.
*
* @author Michael Pyne <mpyne@kde.org>
* @see CoverManager
*/
class CoverData
{
......@@ -92,7 +87,7 @@ typedef QList<coverKey> CoverList;
* contains the cover ID used for this cover, and also supports an image/png
* mimetype for dragging to other applications.
*
* As of this writing the mimetype is application/x-juk-coverid
* The mimetype is "application/x-juk-coverid"
*
* @author Michael Pyne <mpyne@kde.org>
*/
......@@ -192,7 +187,7 @@ public:
* @param artist The artist of the new cover.
* @param album The album of the new cover.
*/
static coverKey addCover(const KUrl &path, const QString &artist = "", const QString &album = "");
static coverKey addCover(const QUrl &path, const QString &artist = "", const QString &album = "");
/**
* Function to determine if @p id matches any covers in the database.
......
......@@ -16,11 +16,11 @@
#include "exampleoptions.h"
#include <QUrl>
#include <QHideEvent>
#include <QShowEvent>
#include <QVBoxLayout>
#include <kurlrequester.h>
#include <klocale.h>
ExampleOptions::ExampleOptions(QWidget *parent) :
......@@ -28,7 +28,7 @@ ExampleOptions::ExampleOptions(QWidget *parent) :
{
setupUi(this);
setObjectName( QLatin1String("example options widget" ));
setObjectName(QLatin1String("example options widget"));
}
void ExampleOptions::exampleSelectionChanged()
......@@ -52,7 +52,7 @@ void ExampleOptions::exampleFileChanged()
ExampleOptionsDialog::ExampleOptionsDialog(QWidget *parent) :
QDialog(parent)
{
setObjectName( QLatin1String("example options dialog" ));
setObjectName(QLatin1String("example options dialog"));
setWindowTitle(i18n("JuK"));
QVBoxLayout *l = new QVBoxLayout(this);
......@@ -64,13 +64,13 @@ ExampleOptionsDialog::ExampleOptionsDialog(QWidget *parent) :
connect(m_options, SIGNAL(fileChanged()), SLOT(fileModeSelected()));
connect(m_options, SIGNAL(dataChanged()), SIGNAL(dataChanged()));
connect(m_options->m_exampleFile, SIGNAL(urlSelected(KUrl)),
this, SLOT(fileChanged(KUrl)));
connect(m_options->m_exampleFile, &KUrlRequester::urlSelected,
this, &ExampleOptionsDialog::urlChanged);
connect(m_options->m_exampleFile, SIGNAL(returnPressed(QString)),
this, SIGNAL(fileChanged(QString)));
}
void ExampleOptionsDialog::fileChanged(const KUrl &url)
void ExampleOptionsDialog::urlChanged(const QUrl &url)
{
emit fileChanged(url.path());
}
......@@ -87,7 +87,7 @@ void ExampleOptionsDialog::showEvent(QShowEvent *)
void ExampleOptionsDialog::fileModeSelected()
{
emit fileChanged(m_options->m_exampleFile->url());
emit urlChanged(m_options->m_exampleFile->url());
}
// vim: set et sw=4 tw=0 sta:
......@@ -14,16 +14,14 @@
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef EXAMPLEOPTIONS_H
#define EXAMPLEOPTIONS_H
#ifndef JUK_EXAMPLEOPTIONS_H
#define JUK_EXAMPLEOPTIONS_H
#include <KUrl>
class QUrl;
#include <qdialog.h>
#include <QHideEvent>
#include <QShowEvent>
#include <QDialog>
#include <QWidget>
#include "ui_exampleoptionsbase.h"
class ExampleOptions : public QWidget, public Ui::ExampleOptionsBase
......@@ -33,17 +31,15 @@ public:
ExampleOptions(QWidget *parent);
protected slots:
virtual void exampleSelectionChanged();
virtual void exampleDataChanged();
virtual void exampleFileChanged();
void exampleSelectionChanged();
void exampleDataChanged();
void exampleFileChanged();
signals:
void dataChanged();
void fileChanged();
};
// We're not using KDialog(Base) because this dialog won't have any push
// buttons to close it. It's just a little floating dialog.
class ExampleOptionsDialog : public QDialog
{
Q_OBJECT
......@@ -52,13 +48,14 @@ public:
const ExampleOptions *widget() const { return m_options; }
protected:
protected:
virtual void hideEvent(QHideEvent *);
virtual void showEvent(QShowEvent *);
protected slots:
void fileModeSelected();
void fileChanged(const KUrl &);
void urlChanged(const QUrl &);
signals:
void fileChanged(const QString &);
void dataChanged();
......@@ -69,6 +66,6 @@ private:
ExampleOptions *m_options;
};
#endif /* EXAMPLEOPTIONS_H */
#endif /* JUK_EXAMPLEOPTIONS_H */
// vim: set et sw=4 tw=0 sta:
......@@ -25,10 +25,10 @@
#if HAVE_TUNEPIMP > 0
#include <kprotocolmanager.h>
#include <kurl.h>
#include <kio/job.h>
#include <QCoreApplication>
#include <QUrl>
#include <QtAlgorithms>
#include <QMutex>
#include <QRegExp>
......@@ -164,7 +164,7 @@ protected:
// Check what hosts are allowed to proceed without being proxied,
// or if using reversed proxy, what hosts must be proxied.
foreach(const QString &host, noProxies) {
const QString normalizedHost(KUrl::fromAce(KUrl::toAce(host)));
const QString normalizedHost(QUrl().setHost(host).host(QUrl::EncodeUnicode));
if(normalizedHost == tunepimpHost ||
tunepimpHost.endsWith('.' + normalizedHost))
......@@ -188,11 +188,11 @@ protected:
useProxy = !useProxy;
if(useProxy) {
KUrl proxy = KProtocolManager::proxyFor("http");
QUrl proxy = QUrl::fromUserInput(KProtocolManager::proxyFor("http"));
QString proxyHost = proxy.host();
qCDebug(JUK_LOG) << "Using proxy server " << proxyHost << " for www.musicbrainz.org.\n";
tp_SetProxy(m_pimp, proxyHost.toAscii(), short(proxy.port()));
tp_SetProxy(m_pimp, proxyHost.toUtf8(), short(proxy.port()));
}
}
#else
......
......@@ -267,18 +267,18 @@ QStringList MediaFiles::mimeTypes()
return savedMimeTypes;
}
QStringList MediaFiles::convertURLsToLocal(const KUrl::List &urlList, QWidget *w)
QStringList MediaFiles::convertURLsToLocal(const QList<QUrl> &urlList, QWidget *w)
{
QStringList result;
KUrl localUrl;
QUrl localUrl;
foreach(const KUrl &url, urlList) {
for(const auto &url : urlList) {
localUrl = KIO::NetAccess::mostLocalUrl(url, w);
if(!localUrl.isLocalFile())
qCDebug(JUK_LOG) << localUrl << " is not a local file, skipping.\n";
else
if(localUrl.isLocalFile())
result.append(localUrl.path());
else
qCDebug(JUK_LOG) << localUrl << " is not a local file, skipping.";
}
return result;
......
......@@ -17,6 +17,8 @@
#ifndef JUK_MEDIAFILES_H
#define JUK_MEDIAFILES_H
#include <QList>
class QWidget;
class QString;
class QStringList;
......@@ -25,7 +27,6 @@ namespace TagLib {
class File;
}
#include <kurl.h>
#include <taglib_config.h>
/**
......@@ -121,7 +122,7 @@ namespace MediaFiles
* @param w KIO may need the widget to handle user interaction.
* @return list of all local files in urlList, converted to absolute paths.
*/
QStringList convertURLsToLocal(const KUrl::List &urlList, QWidget *w = 0);
QStringList convertURLsToLocal(const QList<QUrl> &urlList, QWidget *w = nullptr);
}
#endif
......
......@@ -32,8 +32,8 @@
#include <QDBusMessage>
#include <QVariant>
#include <QFile>
#include <QUrl>
#include <KUrl>
#include <KStandardDirs>
static QByteArray idFromPlaylistItem(const PlaylistItem *item)
......@@ -128,7 +128,7 @@ void MediaPlayer2Player::SetPosition(const QDBusObjectPath& TrackId, qlonglong P
void MediaPlayer2Player::OpenUri(QString Uri) const
{
KUrl url(Uri);
QUrl url = QUrl::fromUserInput(Uri);
// JuK does not yet support KIO
if (url.isLocalFile()) {
......@@ -205,8 +205,8 @@ QVariantMap MediaPlayer2Player::Metadata() const
metaData["xesam:genre"] = QStringList(playingFile.tag()->genre());
metaData["mpris:length"] = qint64(playingFile.tag()->seconds() * 1000000);
metaData["xesam:url"] = QString::fromLatin1(
KUrl::fromLocalFile(playingFile.absFilePath()).toEncoded());
metaData["xesam:url"] = QString::fromUtf8(
QUrl::fromLocalFile(playingFile.absFilePath()).toEncoded());
if(playingFile.coverInfo()->hasCover()) {
QString fallbackFileName = KStandardDirs::locateLocal("tmp",
......@@ -217,8 +217,8 @@ QVariantMap MediaPlayer2Player::Metadata() const
path = playingFile.coverInfo()->localPathToCover(fallbackFileName);
}
metaData["mpris:artUrl"] = QString::fromLatin1(QUrl::fromLocalFile(
path).toEncoded());
metaData["mpris:artUrl"] = QString::fromUtf8(
QUrl::fromLocalFile(path).toEncoded());
}
return metaData;
......
......@@ -23,7 +23,6 @@
#include <kactioncollection.h>
#include <kselectaction.h>
#include <ktoggleaction.h>
#include <kurl.h>
#include <Phonon/AudioOutput>
#include <Phonon/MediaObject>
......@@ -31,6 +30,7 @@
#include <QPixmap>
#include <QTimer>
#include <QUrl>
#include <math.h>
......@@ -225,7 +225,7 @@ void PlayerManager::play(const FileHandle &file)
// The "currently playing" media object.
Phonon::MediaObject *mediaObject = m_media[m_curOutputPath];
if(file.isNull()) {
if(paused())
mediaObject->play();
......@@ -239,7 +239,7 @@ void PlayerManager::play(const FileHandle &file)
if(!m_file.isNull())
{
mediaObject->setCurrentSource(KUrl::fromPath(m_file.absFilePath()));
mediaObject->setCurrentSource(QUrl::fromLocalFile(m_file.absFilePath()));
mediaObject->play();
emit signalItemChanged(m_file);
......@@ -247,7 +247,7 @@ void PlayerManager::play(const FileHandle &file)
}
}
else {
mediaObject->setCurrentSource(KUrl::fromPath(file.absFilePath()));
mediaObject->setCurrentSource(QUrl::fromLocalFile(file.absFilePath()));
mediaObject->play();
if(m_file != file)
......
......@@ -963,7 +963,8 @@ void Playlist::removeFromDisk(const PlaylistItemList &items)
action("forward")->trigger();
QString removePath = item->file().absFilePath();
if((!shouldDelete && KIO::NetAccess::synchronousRun(KIO::trash(removePath), this)) ||
QUrl removeUrl = QUrl::fromLocalFile(removePath);
if((!shouldDelete && KIO::NetAccess::synchronousRun(KIO::trash(removeUrl), this)) ||
(shouldDelete && QFile::remove(removePath)))
{
delete item->collectionItem();
......@@ -1018,39 +1019,9 @@ bool Playlist::acceptDrag(QDropEvent *e) const
void Playlist::decode(const QMimeData *s, PlaylistItem *item)
{
if(!KUrl::List::canDecode(s))
return;
const KUrl::List urls = KUrl::List::fromMimeData(s);
if(urls.isEmpty())
return;
// handle dropped images
if(!MediaFiles::isMediaFile(urls.front().path())) {
QString file;
if(urls.front().isLocalFile())
file = urls.front().path();
else
KIO::NetAccess::download(urls.front(), file, 0);
KMimeType::Ptr mimeType = KMimeType::findByPath(file);
if(item && mimeType->name().startsWith(QLatin1String("image/"))) {
item->file().coverInfo()->setCover(QImage(file));
refreshAlbum(item->file().tag()->artist(),
item->file().tag()->album());
}
KIO::NetAccess::removeTempFile(file);
}
QStringList fileList = MediaFiles::convertURLsToLocal(urls, this);
addFiles(fileList, item);
Q_UNUSED(s);
Q_UNUSED(item);
// TODO Re-add drag-drop
}
bool Playlist::eventFilter(QObject *watched, QEvent *e)
......
......@@ -892,8 +892,8 @@ void PlaylistCollection::readConfig()
m_excludedFolderList = canonicalizeFolderPaths(
config.readEntry("ExcludeDirectoryList", QStringList()));
foreach(const QString &folder, m_folderList) {
m_dirLister.openUrl(folder, KDirLister::Keep);
for(const auto &folder : m_folderList) {
m_dirLister.openUrl(QUrl::fromUserInput(folder), KDirLister::Keep);
}
}
......
......@@ -22,9 +22,7 @@
#include <KXmlGuiWindow>
#include <KLocale>
#include <KInputDialog>
#include <KUrl>
#include <KIO/Job>
#include <QPushButton>
#include <KDialog>
#include "covermanager.h"
......@@ -37,9 +35,12 @@
#include <QDomDocument>
#include <QDomElement>
#include <QPointer>
#include <QPushButton>
#include <QLayout>
#include <QLabel>
#include <QPainter>
#include <QUrl>
#include <QUrlQuery>
#include <kiconloader.h>
......@@ -57,7 +58,7 @@ class WebImageFetcher::Private
QString albumName;
QPointer<KIO::StoredTransferJob> connection;
KDialog *dialog;
KUrl url;
QUrl url;
};
WebImageFetcher::WebImageFetcher(QObject *parent)
......@@ -87,14 +88,16 @@ void WebImageFetcher::searchCover()
QStatusBar *statusBar = JuK::JuKInstance()->statusBar();
statusBar->showMessage(i18n("Searching for cover. Please Wait..."));
QUrlQuery urlQuery;
urlQuery.addQueryItem("method", "album.getInfo");
urlQuery.addQueryItem("api_key", "3e6ecbd7284883089e8f2b5b53b0aecd");
urlQuery.addQueryItem("artist", d->artist);
urlQuery.addQueryItem("album", d->albumName);
KUrl url("http://ws.audioscrobbler.com/2.0/");
url.addQueryItem("method", "album.getInfo");
url.addQueryItem("api_key", "3e6ecbd7284883089e8f2b5b53b0aecd");
url.addQueryItem("artist", d->artist);
url.addQueryItem("album", d->albumName);
QUrl url("http://ws.audioscrobbler.com/2.0/");
url.setQuery(urlQuery);
qCDebug(JUK_LOG) << "Using request " << url.encodedPathAndQuery();
qCDebug(JUK_LOG) << "Using request " << url.toDisplayString();
d->connection = KIO::storedGet(url, KIO::Reload /* reload always */, KIO::HideProgressInfo);
connect(d->connection, SIGNAL(result(KJob*)), SLOT(slotWebRequestFinished(KJob*)));
......@@ -104,8 +107,6 @@ void WebImageFetcher::searchCover()
void WebImageFetcher::slotWebRequestFinished(KJob *job)
{
qCDebug(JUK_LOG) << "Results received.\n";
if (job != d->connection)
return;
......@@ -115,7 +116,6 @@ void WebImageFetcher::slotWebRequestFinished(KJob *job)
return;
}
qCDebug(JUK_LOG) << "Checking for data!!\n";
if (d->connection->data().isEmpty()) {
qCCritical(JUK_LOG) << "last.fm returned an empty result!\n";
return;
......@@ -131,7 +131,7 @@ void WebImageFetcher::slotWebRequestFinished(KJob *job)
return;
}
QDomNode n = results.documentElement();
if (n.isNull()) {
......@@ -140,14 +140,15 @@ void WebImageFetcher::slotWebRequestFinished(KJob *job)
}
n = n.firstChildElement("album");
d->url = n.lastChildElement("image").text(); //FIXME: We assume they have a sane sorting (smallest -> largest)
//FIXME: We assume they have a sane sorting (smallest -> largest)
d->url = QUrl::fromEncoded(n.lastChildElement("image").text().toLatin1());
//TODO: size attribute can have the values mega, extralarge, large, medium and small
qCDebug(JUK_LOG) << "Got cover:" << d->url;
QStatusBar *statusBar = JuK::JuKInstance()->statusBar();
statusBar->showMessage(i18n("Downloading cover. Please Wait..."));
KIO::StoredTransferJob *newJob = KIO::storedGet(d->url, KIO::Reload /* reload always */, KIO::HideProgressInfo);
connect(newJob, SIGNAL(result(KJob*)), SLOT(slotImageFetched(KJob*)));
}
......@@ -158,7 +159,7 @@ void WebImageFetcher::slotImageFetched(KJob* j)
statusBar->clearMessage();
KIO::StoredTransferJob *job = qobject_cast<KIO::StoredTransferJob*>(j);
if (d->dialog) return;
d->dialog = new KDialog();
d->dialog->setCaption(i18n("Cover found"));
......@@ -167,7 +168,7 @@ void WebImageFetcher::slotImageFetched(KJob* j)
QWidget *mainWidget = new QWidget();
d->dialog->setMainWidget(mainWidget);
mainWidget->setLayout(new QVBoxLayout);
if(job->error()) {
qCCritical(JUK_LOG) << "Unable to grab image\n";
d->dialog->setWindowIcon(DesktopIcon("dialog-error"));
......@@ -195,7 +196,7 @@ void WebImageFetcher::slotImageFetched(KJob* j)
infoLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
mainWidget->layout()->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding));
mainWidget->layout()->addWidget(infoLabel);
d->dialog->setWindowIcon(realImage);
d->dialog->show();
connect(d->dialog, SIGNAL(applyClicked()), SLOT(slotCoverChosen()));
......
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