Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Port static methods of Transaction & Daemon from QString to QStringView #56

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,22 +298,22 @@ uint Daemon::versionMicro()
return global()->d_ptr->versionMicro;
}

QString Daemon::packageName(const QString &packageID)
QStringView Daemon::packageName(QStringView packageID)
{
return Transaction::packageName(packageID);
}

QString Daemon::packageVersion(const QString &packageID)
QStringView Daemon::packageVersion(QStringView packageID)
{
return Transaction::packageVersion(packageID);
}

QString Daemon::packageArch(const QString &packageID)
QStringView Daemon::packageArch(QStringView packageID)
{
return Transaction::packageArch(packageID);
}

QString Daemon::packageData(const QString &packageID)
QStringView Daemon::packageData(QStringView packageID)
{
return Transaction::packageData(packageID);
}
Expand Down
14 changes: 7 additions & 7 deletions src/daemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Offline;
* This class holds all the functions enabling the user to interact with the PackageKit daemon.
*
* Most methods are static so that you can just call Daemon::backendName() to get the name of the backend.
*
*
* This class is a singleton, its constructor is private. Call Daemon::global() to get
* an instance of the Daemon object, you only need Daemon::global() when connecting to the signals
* of this class.
Expand Down Expand Up @@ -268,23 +268,23 @@ class PACKAGEKITQT_LIBRARY Daemon : public QObject
/**
* Returns the package name from the \p packageID
*/
Q_INVOKABLE static QString packageName(const QString &packageID);
Q_INVOKABLE static QStringView packageName(QStringView packageID);

/**
* Returns the package version from the \p packageID
*/
Q_INVOKABLE static QString packageVersion(const QString &packageID);
Q_INVOKABLE static QStringView packageVersion(QStringView packageID);

/**
* Returns the package arch from the \p packageID
*/
Q_INVOKABLE static QString packageArch(const QString &packageID);
Q_INVOKABLE static QStringView packageArch(QStringView packageID);

/**
* Returns the package data from the \p packageID
*/
Q_INVOKABLE static QString packageData(const QString &packageID);
Q_INVOKABLE static QStringView packageData(QStringView packageID);

static QString enumToString(const QMetaObject &metaObject, int value, const char *enumName);

/**
Expand All @@ -297,7 +297,7 @@ class PACKAGEKITQT_LIBRARY Daemon : public QObject
}

static int enumFromString(const QMetaObject &metaObject, const QString &str, const char *enumName);

template<class T> static int enumFromString(const QString &str, const char *enumName)
{
return enumFromString(T::staticMetaObject, str, enumName);
Expand Down
22 changes: 11 additions & 11 deletions src/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,16 @@ QDBusPendingReply<> Transaction::cancel()
return QDBusPendingReply<>();
}

QString Transaction::packageName(const QString &packageID)
QStringView Transaction::packageName(QStringView packageID)
{
QString ret;
QStringView ret;
ret = packageID.left(packageID.indexOf(QLatin1Char(';')));
return ret;
}

QString Transaction::packageVersion(const QString &packageID)
QStringView Transaction::packageVersion(QStringView packageID)
{
QString ret;
QStringView ret;
int start = packageID.indexOf(QLatin1Char(';'));
if (start == -1) {
return ret;
Expand All @@ -215,9 +215,9 @@ QString Transaction::packageVersion(const QString &packageID)
return ret;
}

QString Transaction::packageArch(const QString &packageID)
QStringView Transaction::packageArch(QStringView packageID)
{
QString ret;
QStringView ret;
int start = packageID.indexOf(QLatin1Char(';'));
if (start == -1) {
return ret;
Expand All @@ -235,9 +235,9 @@ QString Transaction::packageArch(const QString &packageID)
return ret;
}

QString Transaction::packageData(const QString &packageID)
QStringView Transaction::packageData(QStringView packageID)
{
QString ret;
QStringView ret;
int start = packageID.indexOf(QLatin1Char(';'));
if (start == -1) {
return ret;
Expand Down Expand Up @@ -289,7 +289,7 @@ qulonglong Transaction::downloadSizeRemaining() const
{
Q_D(const Transaction);
return d->downloadSizeRemaining;
}
}

Transaction::Role Transaction::role() const
{
Expand Down Expand Up @@ -372,9 +372,9 @@ Transaction::InternalError Transaction::parseError(const QString &errorName)
if (error.startsWith(QLatin1String("org.freedesktop.packagekit."))) {
return Transaction::InternalErrorFailedAuth;
}

error.remove(QLatin1String("org.freedesktop.PackageKit.Transaction."));

if (error.startsWith(QLatin1String("PermissionDenied")) ||
error.startsWith(QLatin1String("RefusedByPolicy"))) {
return Transaction::InternalErrorFailedAuth;
Expand Down
10 changes: 5 additions & 5 deletions src/transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ class PACKAGEKITQT_LIBRARY Transaction : public QObject
* \return speed bits per second, or 0 if not known.
*/
uint speed() const;

/**
* Returns the number of bytes remaining to download
* \return bytes to download, or 0 if nothing is left to download.
Expand Down Expand Up @@ -666,22 +666,22 @@ class PACKAGEKITQT_LIBRARY Transaction : public QObject
/**
* Returns the package name from the \p packageID
*/
static QString packageName(const QString &packageID);
static QStringView packageName(QStringView packageID);

/**
* Returns the package version from the \p packageID
*/
static QString packageVersion(const QString &packageID);
static QStringView packageVersion(QStringView packageID);

/**
* Returns the package arch from the \p packageID
*/
static QString packageArch(const QString &packageID);
static QStringView packageArch(QStringView packageID);

/**
* Returns the package data from the \p packageID
*/
static QString packageData(const QString &packageID);
static QStringView packageData(QStringView packageID);

Q_SIGNALS:
void allowCancelChanged();
Expand Down