Commit 715d09e5 authored by Milian Wolff's avatar Milian Wolff

Port from KUrl to QUrl.

Based on the initial patch by Dāvis Mosāns, many thanks for that!
There where many things left to do though and the following should
be read by everyone who wants to port a plugin to KUrl:

Add -DQT_NO_URL_CAST_FROM_STRING to your project, otherwise you
are doomed to long debug sessions.

Always be explicit when constructing a QUrl out of a QString.
Think about what the QString represents. Most of the cases we only
care about absolute paths, potentially with a remote host and protocol.
In such a case, the QUrl::fromUserInput is the correct choice. If its
a local file, i.e. comes out of QDir, QFileInfo etc., always use
QUrl::fromLocalFile. Generally, if your plugin only works with local
files, use the latter. *Never* use the QUrl(QString) constructor,
except if you really want to concstruct a relative URL. A common
pitfall is e.g. QUrl(IndexedString(...)). Always prefer
IndexedString::toUrl() instead.

Note that there are, sadly, far too many places in our code base
which abuse QUrl for general "Path" handling. If possible, rewrite
your code to use KDevelop::Path in such a case. It's also much
simpler to port the KUrl to Path directly.

REVIEW: 120123
parent c81eaee8
......@@ -73,7 +73,7 @@ set_package_properties(Grantlee PROPERTIES
URL "http://www.grantlee.org/")
add_definitions(-DTRANSLATION_DOMAIN=\"kdevplatform\")
add_definitions(-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS -DQURL_NO_CAST_FROM_QSTRING)
add_definitions(-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS -DQT_NO_URL_CAST_FROM_STRING)
remove_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0) # comes from KDELibs4Support
add_definitions(-DQT_DEPRECATED_WARNINGS -DQT_DISABLE_DEPRECATED_BEFORE=0x050000)
......
......@@ -78,7 +78,6 @@ Breakpoint::Breakpoint(BreakpointModel *model, const KConfigGroup& config)
m_expression = config.readEntry("expression", QString());
setCondition(config.readEntry("condition", ""));
setIgnoreHits(config.readEntry("ignoreHits", 0));
}
BreakpointModel *Breakpoint::breakpointModel()
......@@ -100,7 +99,7 @@ bool Breakpoint::setData(int index, const QVariant& value)
QRegExp rx("^(.+):([0-9]+)$");
int idx = rx.indexIn(s);
if (m_kind == CodeBreakpoint && idx != -1) {
m_url = QUrl(rx.cap(1));
m_url = QUrl::fromLocalFile(rx.cap(1));
m_line = rx.cap(2).toInt() - 1;
m_expression.clear();
} else {
......@@ -233,6 +232,7 @@ void Breakpoint::setLine(int line) {
}
void Breakpoint::setUrl(const QUrl& url) {
Q_ASSERT(m_kind == CodeBreakpoint);
Q_ASSERT(url.isEmpty() || (!url.isRelative() && !url.fileName().isEmpty()));
m_url = url;
reportChange(LocationColumn);
}
......@@ -242,6 +242,7 @@ QUrl Breakpoint::url() const {
void Breakpoint::setLocation(const QUrl& url, int line)
{
Q_ASSERT(m_kind == CodeBreakpoint);
Q_ASSERT(url.isEmpty() || (!url.isRelative() && !url.fileName().isEmpty()));
m_url = url;
m_line = line;
reportChange(LocationColumn);
......
......@@ -22,7 +22,7 @@
#define KDEVPLATFORM_BREAKPOINT_H
#include <QtCore/QSet>
#include <QtCore/QUrl>
#include <QUrl>
#include "../util/treeitem.h"
class KConfigGroup;
......
......@@ -301,7 +301,7 @@ void BreakpointWidget::slotOpenFile(const QModelIndex& breakpointIdx)
return;
}
ICore::self()->documentController()->openDocument(bp->url().url(QUrl::PreferLocalFile | QUrl::StripTrailingSlash), KTextEditor::Cursor(bp->line(), 0), IDocumentController::DoNotFocus);
ICore::self()->documentController()->openDocument(bp->url(), KTextEditor::Cursor(bp->line(), 0), IDocumentController::DoNotFocus);
}
void BreakpointWidget::slotDisableAllBreakpoints()
......
......@@ -25,7 +25,7 @@
#include <QtCore/QObject>
#include <QtCore/QAbstractItemModel>
#include <QtCore/QUrl>
#include <QUrl>
namespace KDevelop {
......
......@@ -23,7 +23,7 @@
#include "idebugsession.h"
#include <QtCore/QUrl>
#include <QUrl>
#include <QtCore/QAbstractItemModel>
#include <QtCore/QString>
......
......@@ -45,7 +45,7 @@ static QUrl rebaseMatchingUrl(const QUrl& toRebase, const KConfigGroup& config,
const QString searchStr = toRebase.url(matchOpts);
if (searchStr.contains(baseStr)) {
const QUrl rebase = pathCfg.readEntry(rebaseEntry, QUrl());
return rebase.resolved(searchStr.mid(baseStr.length()));
return rebase.resolved(QUrl(searchStr.mid(baseStr.length())));
}
}
//No mapping found
......
......@@ -25,7 +25,7 @@
#include <QWidget>
#include <QtCore/QUrl>
#include <QUrl>
#include <KConfigGroup>
#include <debugger/debuggerexport.h>
......
......@@ -52,11 +52,11 @@ bool Context::hasType( int aType ) const
class FileContextPrivate
{
public:
FileContextPrivate( const KUrl::List &urls )
FileContextPrivate( const QList<QUrl> &urls )
: m_urls( urls )
{}
KUrl::List m_urls;
QList<QUrl> m_urls;
};
FileContext::FileContext( const QList<QUrl> &urls )
......@@ -110,16 +110,16 @@ QList<ProjectBaseItem*> ProjectItemContext::items() const
class OpenWithContextPrivate
{
public:
OpenWithContextPrivate(const KUrl::List& urls, const QMimeType& mimeType)
OpenWithContextPrivate(const QList<QUrl>& urls, const QMimeType& mimeType)
: m_urls( urls )
, m_mimeType( mimeType )
{}
KUrl::List m_urls;
QList<QUrl> m_urls;
QMimeType m_mimeType;
};
OpenWithContext::OpenWithContext(const KUrl::List& urls, const QMimeType& mimeType)
OpenWithContext::OpenWithContext(const QList<QUrl>& urls, const QMimeType& mimeType)
: Context()
, d(new OpenWithContextPrivate(urls, mimeType))
{
......@@ -131,7 +131,7 @@ int OpenWithContext::type() const
return Context::OpenWithContext;
}
KUrl::List OpenWithContext::urls() const
QList<QUrl> OpenWithContext::urls() const
{
return d->m_urls;
}
......
......@@ -35,8 +35,7 @@ Boston, MA 02110-1301, USA.
#include <QStringList>
#include <QMimeType>
#include <KUrl>
#include <QUrl>
template <typename T> class QList;
......@@ -123,7 +122,7 @@ A context for the a list of selected urls.
class KDEVPLATFORMINTERFACES_EXPORT FileContext : public Context
{
public:
/**Builds the file context using a @ref KUrl::List
/**Builds the file context using a @ref QList<QUrl>
@param urls The list of selected url.*/
FileContext( const QList<QUrl> &urls );
......@@ -177,7 +176,7 @@ public:
* @p url The files to open.
* @p mimeType The mime type of said file.
*/
OpenWithContext(const KUrl::List& urls, const QMimeType& mimeType);
OpenWithContext(const QList<QUrl>& urls, const QMimeType& mimeType);
/**
* @return Context::OpenWithContext
......@@ -187,7 +186,7 @@ public:
/**
* @return The files to open.
*/
KUrl::List urls() const;
QList<QUrl> urls() const;
/**
* @return The mimetype of the url to open.
......
......@@ -18,6 +18,9 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include "ibuddydocumentfinder.h"
#include <QtCore/QMap>
namespace KDevelop {
//Our private data is entirely static, so don't need to create an
......
......@@ -22,7 +22,8 @@
#include <QObject>
#include <QVector>
#include <KUrl>
#include <QUrl>
#include "interfacesexport.h"
namespace KDevelop {
......@@ -75,29 +76,29 @@ public:
*
* @return true, if the two documents are buddies.
* For example, a C++ implementation would return true for
* areBuddies(KUrl("...../foo.h"), KUrl("...../foo.cpp")).
* areBuddies(QUrl::fromLocalFile("...../foo.h"), QUrl::fromLocalFile("...../foo.cpp")).
*/
virtual bool areBuddies(const KUrl& url1, const KUrl& url2) = 0;
virtual bool areBuddies(const QUrl& url1, const QUrl& url2) = 0;
/**
* Called to determine the order of two documents in the tabbar.
*
* Example: a C++ implementation that wants to place the tab of the .h
* file left of the .cpp tab must return true for
* buddyOrder(KUrl("...../foo.h"), KUrl("...../foo.cpp"))
* buddyOrder(QUrl::fromLocalFile("...../foo.h"), QUrl::fromLocalFile("...../foo.cpp"))
* and false for
* buddyOrder(KUrl("...../foo.cpp"), KUrl("...../foo.h")).
* buddyOrder(QUrl::fromLocalFile("...../foo.cpp"), QUrl::fromLocalFile("...../foo.h")).
*
* @param url1 @param url2: two documents which are buddies,
* this means areBuddies(url1,url2) returned true.
* @return true, if url1's tab should be placed left of url2's tab.
* false, for the inverse.
*/
virtual bool buddyOrder(const KUrl& url1, const KUrl& url2) = 0;
virtual bool buddyOrder(const QUrl& url1, const QUrl& url2) = 0;
/**
* Returns a list of KUrls of potential buddies of the document
* Returns a list of QUrls of potential buddies of the document
* provided by @p url.
*
* The urls are potential buddies and it is not ensured that the files
......@@ -106,7 +107,7 @@ public:
* @returns list of potential buddy documents or an empty list
* if non are available.
*/
virtual QVector<KUrl> getPotentialBuddies(const KUrl& url) const = 0;
virtual QVector<QUrl> getPotentialBuddies(const QUrl& url) const = 0;
/**
* Registers a IBuddyDocumentFinder object for a mimetype.
......
......@@ -21,7 +21,7 @@
#ifndef KDEVPLATFORM_IDOCUMENT_H
#define KDEVPLATFORM_IDOCUMENT_H
#include <kurl.h>
#include <QUrl>
#include <kmimetype.h>
#include <KTextEditor/Cursor>
#include <KTextEditor/Range>
......@@ -72,7 +72,7 @@ public:
/**
* Returns the URL of this document.
*/
virtual KUrl url() const = 0;
virtual QUrl url() const = 0;
/**
* Returns the mimetype of the document.
......
......@@ -25,7 +25,7 @@ IDocumentController::IDocumentController(QObject *parent)
{
}
KDevelop::IDocument* IDocumentController::openDocument( const KUrl &url,
KDevelop::IDocument* IDocumentController::openDocument( const QUrl &url,
const KTextEditor::Cursor& cursor,
DocumentActivationParams activationParams,
const QString& encoding)
......
......@@ -21,8 +21,8 @@
#include <QtCore/QObject>
#include <QtCore/QList>
#include <QUrl>
#include <kurl.h>
#include <ktexteditor/cursor.h>
#include <ktexteditor/range.h>
......@@ -41,7 +41,7 @@ class ICore;
class KDEVPLATFORMINTERFACES_EXPORT IDocumentFactory {
public:
virtual ~IDocumentFactory() {}
virtual IDocument* create(const KUrl&, ICore* ) = 0;
virtual IDocument* create(const QUrl&, ICore* ) = 0;
};
/**
......@@ -79,7 +79,7 @@ public:
* @param url The Url of the document.
* @return The corresponding document, or null if not found.
*/
Q_SCRIPTABLE virtual KDevelop::IDocument* documentForUrl( const KUrl & url ) const = 0;
Q_SCRIPTABLE virtual KDevelop::IDocument* documentForUrl( const QUrl & url ) const = 0;
/// @return The list of all open documents
Q_SCRIPTABLE virtual QList<KDevelop::IDocument*> openDocuments() const = 0;
......@@ -119,7 +119,7 @@ public Q_SLOTS:
* @param range The location information, if applicable.
* @param activate Indicates whether to fully activate the document.
*/
KDevelop::IDocument* openDocument( const KUrl &url,
KDevelop::IDocument* openDocument( const QUrl &url,
const KTextEditor::Cursor& cursor,
DocumentActivationParams activationParams = 0,
const QString& encoding = "");
......@@ -137,7 +137,7 @@ public Q_SLOTS:
*
* @return The opened document
*/
virtual KDevelop::IDocument* openDocument( const KUrl &url,
virtual KDevelop::IDocument* openDocument( const QUrl &url,
const KTextEditor::Range& range = KTextEditor::Range::invalid(),
DocumentActivationParams activationParams = 0,
const QString& encoding = "",
......@@ -165,7 +165,7 @@ public Q_SLOTS:
* @param url The full Url of the document to open.
* @param prefName The name of the preferred KPart to open that document
*/
virtual KDevelop::IDocument* openDocument( const KUrl &url, const QString& prefname ) = 0;
virtual KDevelop::IDocument* openDocument( const QUrl &url, const QString& prefname ) = 0;
virtual void closeAllDocuments() = 0;
......
......@@ -21,8 +21,6 @@
#include <QtCore/QObject>
#include <kurl.h>
#include "interfacesexport.h"
class QReadWriteLock;
......
......@@ -21,7 +21,9 @@
#define KDEVPLATFORM_ILANGUAGECHECK_H
#include "interfacesexport.h"
#include <KUrl>
#include <QUrl>
#include <QObject>
namespace KDevelop
{
......@@ -33,7 +35,7 @@ class ControlFlowGraph;
class CheckData
{
public:
KUrl url;
QUrl url;
TopDUContext* top;
ControlFlowGraph* flow;
DataAccessRepository* access;
......@@ -43,10 +45,10 @@ class KDEVPLATFORMINTERFACES_EXPORT ILanguageCheck
{
public:
virtual ~ILanguageCheck();
/** Runs the check. This will add problems to the TopDUContext if necessary */
virtual void runCheck(const CheckData& data)=0;
/** @returns the name of the check */
virtual QString name() const=0;
};
......
......@@ -21,11 +21,10 @@
#include <QtCore/QList>
#include <QtCore/QObject>
#include <QUrl>
#include "interfacesexport.h"
class KUrl;
namespace KDevelop {
class ILanguage;
......@@ -52,8 +51,8 @@ public:
* If it is called from a background thread, it can not
* be loaded, and thus zero will be returned.
* */
Q_SCRIPTABLE virtual QList<ILanguage*> languagesForUrl(const KUrl &url) = 0;
Q_SCRIPTABLE virtual QList<ILanguage*> languagesForUrl(const QUrl &url) = 0;
/** @return All languages currently loaded */
Q_SCRIPTABLE virtual QList<ILanguage*> loadedLanguages() const = 0;
......
......@@ -28,7 +28,6 @@ Boston, MA 02110-1301, USA.
#include <QtCore/QList>
#include <kplugininfo.h>
#include <kurl.h>
#include <kservice.h>
#include "iplugin.h"
......
......@@ -29,7 +29,7 @@
#include <QtCore/QObject>
#include <kurl.h>
#include <QUrl>
#include <ksharedconfig.h>
#include "interfacesexport.h"
......@@ -109,26 +109,26 @@ public:
* @return all items with the corresponding @p path
*/
Q_SCRIPTABLE virtual QList<ProjectBaseItem*> itemsForPath( const IndexedString& path ) const = 0;
KDEVPLATFORMINTERFACES_DEPRECATED Q_SCRIPTABLE virtual QList<ProjectBaseItem*> itemsForUrl( const KUrl& url ) const = 0;
KDEVPLATFORMINTERFACES_DEPRECATED Q_SCRIPTABLE virtual QList<ProjectBaseItem*> itemsForUrl( const QUrl &url ) const = 0;
/**
* @return all file items with the corresponding @p file path
*/
Q_SCRIPTABLE virtual QList<ProjectFileItem*> filesForPath( const IndexedString& file ) const = 0;
KDEVPLATFORMINTERFACES_DEPRECATED Q_SCRIPTABLE virtual QList<ProjectFileItem*> filesForUrl( const KUrl& file ) const = 0;
KDEVPLATFORMINTERFACES_DEPRECATED Q_SCRIPTABLE virtual QList<ProjectFileItem*> filesForUrl( const QUrl &file ) const = 0;
/**
* @return all folder items with the corresponding @p folder path
*/
Q_SCRIPTABLE virtual QList<ProjectFolderItem*> foldersForPath( const IndexedString& folder ) const = 0;
KDEVPLATFORMINTERFACES_DEPRECATED Q_SCRIPTABLE virtual QList<ProjectFolderItem*> foldersForUrl( const KUrl& folder ) const = 0;
KDEVPLATFORMINTERFACES_DEPRECATED Q_SCRIPTABLE virtual QList<ProjectFolderItem*> foldersForUrl( const QUrl &folder ) const = 0;
/**
* @return the path to the project file
*/
virtual Path projectFile() const = 0;
/** Get the url of the project file.*/
KDEVPLATFORMINTERFACES_DEPRECATED Q_SCRIPTABLE virtual KUrl projectFileUrl() const = 0;
KDEVPLATFORMINTERFACES_DEPRECATED Q_SCRIPTABLE virtual QUrl projectFileUrl() const = 0;
virtual KSharedConfig::Ptr projectConfiguration() const = 0;
virtual void addToFileSet( ProjectFileItem* item ) = 0;
......@@ -144,7 +144,7 @@ public:
* @brief Get the project folder
* @return The canonical absolute directory of the project.
*/
KDEVPLATFORMINTERFACES_DEPRECATED virtual Q_SCRIPTABLE const KUrl folder() const = 0;
KDEVPLATFORMINTERFACES_DEPRECATED virtual Q_SCRIPTABLE