diff --git a/klipper/clipcommandprocess.cpp b/klipper/clipcommandprocess.cpp --- a/klipper/clipcommandprocess.cpp +++ b/klipper/clipcommandprocess.cpp @@ -40,7 +40,7 @@ map.insert( QLatin1Char('f'), clip ); map.insert( QLatin1Char('F'), clip ); - const QStringList matches = action.regExpMatches(); + const QStringList matches = action.actionCapturedTexts(); // support only %0 and the first 9 matches... const int numMatches = qMin(10, matches.count()); for ( int i = 0; i < numMatches; ++i ) { diff --git a/klipper/configdialog.cpp b/klipper/configdialog.cpp --- a/klipper/configdialog.cpp +++ b/klipper/configdialog.cpp @@ -140,7 +140,7 @@ // clear children if any item->takeChildren(); - item->setText( 0, action->regExp() ); + item->setText( 0, action->actionRegexPattern() ); item->setText( 1, action->description() ); foreach (const ClipCommand& command, action->commands()) { diff --git a/klipper/editactiondialog.cpp b/klipper/editactiondialog.cpp --- a/klipper/editactiondialog.cpp +++ b/klipper/editactiondialog.cpp @@ -321,7 +321,7 @@ return; } - m_ui->leRegExp->setText(m_action->regExp()); + m_ui->leRegExp->setText(m_action->actionRegexPattern()); m_ui->automatic->setChecked(m_action->automatic()); m_ui->leDescription->setText(m_action->description()); @@ -340,7 +340,7 @@ return; } - m_action->setRegExp( m_ui->leRegExp->text() ); + m_action->setActionRegexPattern( m_ui->leRegExp->text() ); m_action->setDescription( m_ui->leDescription->text() ); m_action->setAutomatic( m_ui->automatic->isChecked() ); diff --git a/klipper/klipperpopup.cpp b/klipper/klipperpopup.cpp --- a/klipper/klipperpopup.cpp +++ b/klipper/klipperpopup.cpp @@ -150,8 +150,9 @@ } // We search case insensitive until one uppercased character appears in the search term - Qt::CaseSensitivity caseSens = (filter.toLower() == filter ? Qt::CaseInsensitive : Qt::CaseSensitive); - QRegExp filterexp( filter, caseSens ); + QRegularExpression filterexp( filter, filter.toLower() == filter ? + QRegularExpression::CaseInsensitiveOption + : QRegularExpression::NoPatternOption ); QPalette palette = m_filterWidget->palette(); if ( filterexp.isValid() ) { diff --git a/klipper/popupproxy.h b/klipper/popupproxy.h --- a/klipper/popupproxy.h +++ b/klipper/popupproxy.h @@ -20,7 +20,7 @@ #define POPUPPROXY_H #include -#include +#include #include "history.h" @@ -53,7 +53,7 @@ * @param filter If non-empty, only insert items that match filter as a regex * @return number of items inserted. */ - int buildParent( int index, const QRegExp& filter = QRegExp() ); + int buildParent( int index, const QRegularExpression &filter = QRegularExpression() ); public Q_SLOTS: void slotAboutToShow(); @@ -81,7 +81,7 @@ private: QMenu* m_proxy_for_menu; QByteArray m_spill_uuid; - QRegExp m_filter; + QRegularExpression m_filter; int m_menu_height; int m_menu_width; }; diff --git a/klipper/popupproxy.cpp b/klipper/popupproxy.cpp --- a/klipper/popupproxy.cpp +++ b/klipper/popupproxy.cpp @@ -18,7 +18,6 @@ */ #include "popupproxy.h" -#include #include #include #include @@ -29,7 +28,6 @@ #include "history.h" #include "klipperpopup.h" - PopupProxy::PopupProxy( KlipperPopup* parent, int menu_height, int menu_width ) : QObject( parent ), m_proxy_for_menu( parent ), @@ -64,7 +62,7 @@ } } -int PopupProxy::buildParent( int index, const QRegExp& filter ) { +int PopupProxy::buildParent( int index, const QRegularExpression &filter ) { deleteMoreMenus(); // Start from top of history (again) m_spill_uuid = parent()->history()->empty() ? QByteArray() : parent()->history()->first()->uuid(); @@ -154,7 +152,7 @@ return count; } do { - if ( m_filter.indexIn( item->text() ) != -1) { + if (m_filter.match(item->text()).hasMatch()) { tryInsertItem( item.data(), remainingHeight, index++ ); count++; } diff --git a/klipper/urlgrabber.h b/klipper/urlgrabber.h --- a/klipper/urlgrabber.h +++ b/klipper/urlgrabber.h @@ -20,7 +20,6 @@ #define URLGRABBER_H #include -#include #include #include @@ -145,12 +144,11 @@ ClipAction( KSharedConfigPtr kc, const QString& ); ~ClipAction(); - void setRegExp( const QString& r) { m_myRegExp = QRegExp( r ); } - QString regExp() const { return m_myRegExp.pattern(); } + QString actionRegexPattern() const { return m_regexPattern; } + void setActionRegexPattern(const QString &pattern) { m_regexPattern = pattern; } - bool matches( const QString& string ) const { return ( m_myRegExp.indexIn( string ) != -1 ); } - - QStringList regExpMatches() const { return m_myRegExp.capturedTexts(); } + QStringList actionCapturedTexts() const { return m_regexCapturedTexts; } + void setActionCapturedTexts(const QStringList &captured) { m_regexCapturedTexts = captured; } void setDescription( const QString& d) { m_myDescription = d; } QString description() const { return m_myDescription; } @@ -184,7 +182,8 @@ private: - QRegExp m_myRegExp; + QString m_regexPattern; + QStringList m_regexCapturedTexts; QString m_myDescription; QList m_myCommands; bool m_automatic; diff --git a/klipper/urlgrabber.cpp b/klipper/urlgrabber.cpp --- a/klipper/urlgrabber.cpp +++ b/klipper/urlgrabber.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -162,10 +163,13 @@ matchingMimeActions(clipData); - // now look for matches in custom user actions + QRegularExpression re; foreach (ClipAction* action, m_myActions) { - if ( action->matches( clipData ) && (action->automatic() || !automatically_invoked) ) { + re.setPattern(action->actionRegexPattern()); + const QRegularExpressionMatch match = re.match(clipData); + if (match.hasMatch() && (action->automatic() || !automatically_invoked)) { + action->setActionCapturedTexts(match.capturedTexts()); m_myMatches.append( action ); } } @@ -402,12 +406,12 @@ ClipAction::ClipAction( const QString& regExp, const QString& description, bool automatic ) - : m_myRegExp( regExp ), m_myDescription( description ), m_automatic(automatic) + : m_regexPattern( regExp ), m_myDescription( description ), m_automatic(automatic) { } ClipAction::ClipAction( KSharedConfigPtr kc, const QString& group ) - : m_myRegExp( kc->group(group).readEntry("Regexp") ), + : m_regexPattern( kc->group(group).readEntry("Regexp") ), m_myDescription (kc->group(group).readEntry("Description") ), m_automatic(kc->group(group).readEntry("Automatic", QVariant(true)).toBool() ) { @@ -459,7 +463,7 @@ { KConfigGroup cg(kc, group); cg.writeEntry( "Description", description() ); - cg.writeEntry( "Regexp", regExp() ); + cg.writeEntry( "Regexp", actionRegexPattern() ); cg.writeEntry( "Number of commands", m_myCommands.count() ); cg.writeEntry( "Automatic", automatic() );