diff --git a/klipper/clipcommandprocess.cpp b/klipper/clipcommandprocess.cpp index 493132058..4789d766f 100644 --- a/klipper/clipcommandprocess.cpp +++ b/klipper/clipcommandprocess.cpp @@ -40,7 +40,7 @@ ClipCommandProcess::ClipCommandProcess(const ClipAction& action, const ClipComma 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 index b123675b8..336c4238b 100644 --- a/klipper/configdialog.cpp +++ b/klipper/configdialog.cpp @@ -140,7 +140,7 @@ void ActionsWidget::updateActionItem( QTreeWidgetItem* item, ClipAction* action // 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 index 66cefcf81..739c84010 100644 --- a/klipper/editactiondialog.cpp +++ b/klipper/editactiondialog.cpp @@ -321,7 +321,7 @@ void EditActionDialog::updateWidgets(int commandIdxToSelect) 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 @@ void EditActionDialog::saveAction() 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 index 162a3a32a..d580083c6 100644 --- a/klipper/klipperpopup.cpp +++ b/klipper/klipperpopup.cpp @@ -150,8 +150,9 @@ void KlipperPopup::rebuild( const QString& filter ) { } // 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.cpp b/klipper/popupproxy.cpp index 23fe530e6..53b65f3b8 100644 --- 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 @@ void PopupProxy::deleteMoreMenus() { } } -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 @@ int PopupProxy::insertFromSpill( int index ) { 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/popupproxy.h b/klipper/popupproxy.h index f33f62c11..9eaa9db95 100644 --- 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 @@ public: * @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: 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/urlgrabber.cpp b/klipper/urlgrabber.cpp index 2e479a4a4..070201ac2 100644 --- a/klipper/urlgrabber.cpp +++ b/klipper/urlgrabber.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -162,10 +163,13 @@ const ActionList& URLGrabber::matchingActions( const QString& clipData, bool aut 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 @@ ClipCommand::ClipCommand(const QString&_command, const QString& _description, 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 @@ void ClipAction::save( KSharedConfigPtr kc, const QString& group ) const { 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() ); diff --git a/klipper/urlgrabber.h b/klipper/urlgrabber.h index f8a358e6f..ad384c4b6 100644 --- a/klipper/urlgrabber.h +++ b/klipper/urlgrabber.h @@ -20,7 +20,6 @@ #define URLGRABBER_H #include -#include #include #include @@ -145,12 +144,11 @@ public: 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 @@ public: private: - QRegExp m_myRegExp; + QString m_regexPattern; + QStringList m_regexCapturedTexts; QString m_myDescription; QList m_myCommands; bool m_automatic;