Commit 1e30c84a authored by Ahmad Samir's avatar Ahmad Samir

[KMenuEdit] Port QRegExp to QRegularExpression

Test Plan:
- Start kmenuedit, create a new sub-menu somewhere, name it t-1
- Creat a new submenu in the same location and name it t-1 again
  the submenu is created but named t-2 automatically

- Copy an existing item to the same location from where you copied it,
  note the "-number" suffix that's added
- Drag and drop a .desktop file twice on the same location, note the
  suffix that's added

- The createDesktopFile() part, in tree.cpp, strips the name to a base
  that's then fed to KService::newServicePath(), e.g. "foo-1.desktop" to
  "foo"

Reviewers: #plasma, davidedmundson, mlaurent, apol

Reviewed By: apol

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D28519
parent a9e0ef29
......@@ -21,7 +21,7 @@
#include <QDir>
#include <QFile>
#include <QTextStream>
#include <QRegExp>
#include <QRegularExpression>
#include <QFileInfo>
#include <QStandardPaths>
......@@ -454,8 +454,9 @@ QString MenuFile::uniqueMenuName(const QString &menuName, const QString &newMenu
result.chop(1);
}
QRegExp r(QStringLiteral("(.*)(?=-\\d+)"));
result = (r.indexIn(result) > -1) ? r.cap(1) : result;
static const QRegularExpression re(QStringLiteral("(.*)(?=-\\d+)"));
const QRegularExpressionMatch match = re.match(result);
result = match.hasMatch() ? match.captured(1) : result;
int trunc = result.length(); // Position of trailing '/'
......
......@@ -19,7 +19,7 @@
#include "menuinfo.h"
#include <QRegExp>
#include <QRegularExpressionMatch>
#include <KDesktopFile>
......@@ -106,11 +106,17 @@ void MenuFolderInfo::take(MenuEntryInfo *entry)
entries.removeAll(entry);
}
QString uniqueCaption(const QString &caption)
{
static const QRegularExpression re(QStringLiteral("(.*)(?=-\\d+)"));
const QRegularExpressionMatch match = re.match(caption);
return match.hasMatch() ? match.captured(1) : caption;
}
// Return a unique sub-menu caption inspired by @p caption
QString MenuFolderInfo::uniqueMenuCaption(const QString &caption)
{
QRegExp r(QStringLiteral("(.*)(?=-\\d+)"));
QString cap = (r.indexIn(caption) > -1) ? r.cap(1) : caption;
QString cap = uniqueCaption(caption);
QString result = caption;
......@@ -134,8 +140,7 @@ QString MenuFolderInfo::uniqueMenuCaption(const QString &caption)
// Return a unique item caption inspired by @p caption
QString MenuFolderInfo::uniqueItemCaption(const QString &caption, const QString &exclude)
{
QRegExp r(QStringLiteral("(.*)(?=-\\d+)"));
QString cap = (r.indexIn(caption) > -1) ? r.cap(1) : caption;
QString cap = uniqueCaption(caption);
QString result = caption;
......
......@@ -36,7 +36,7 @@
#include <QInputDialog>
#include <QMenu>
#include <QPainter>
#include <QRegExp>
#include <QRegularExpressionMatch>
#include <QUrl>
#include <KActionCollection>
......@@ -727,8 +727,9 @@ static QString createDesktopFile(const QString &file, QString *menuId, QStringLi
QString base = file.mid(file.lastIndexOf(QLatin1Char('/'))+1);
base = base.left(base.lastIndexOf(QLatin1Char('.')));
QRegExp r(QStringLiteral("(.*)(?=-\\d+)"));
base = (r.indexIn(base) > -1) ? r.cap(1) : base;
const QRegularExpression re(QStringLiteral("(.*)(?=-\\d+)"));
const QRegularExpressionMatch match = re.match(base);
base = match.hasMatch() ? match.captured(1) : base;
QString result = KService::newServicePath(true, base, menuId, excludeList);
excludeList->append(*menuId);
......
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