Changeset View
Changeset View
Standalone View
Standalone View
klipper/urlgrabber.cpp
Show First 20 Lines • Show All 139 Lines • ▼ Show 20 Line(s) | 103 | { | |||
---|---|---|---|---|---|
140 | // might take a long time, and i want this function to be quick! | 140 | // might take a long time, and i want this function to be quick! | ||
141 | if ( ( clipData.startsWith( QLatin1String("http://") ) || clipData.startsWith( QLatin1String("https://") ) ) | 141 | if ( ( clipData.startsWith( QLatin1String("http://") ) || clipData.startsWith( QLatin1String("https://") ) ) | ||
142 | && mimetype.name() != QLatin1String("text/html") ) | 142 | && mimetype.name() != QLatin1String("text/html") ) | ||
143 | { | 143 | { | ||
144 | mimetype = db.mimeTypeForName(QStringLiteral("text/html")); | 144 | mimetype = db.mimeTypeForName(QStringLiteral("text/html")); | ||
145 | } | 145 | } | ||
146 | 146 | | |||
147 | if ( !mimetype.isDefault() ) { | 147 | if ( !mimetype.isDefault() ) { | ||
148 | KService::List lst = KMimeTypeTrader::self()->query( mimetype.name(), QStringLiteral("Application") ); | 148 | const KService::List lst = KMimeTypeTrader::self()->query( mimetype.name(), QStringLiteral("Application") ); | ||
149 | if ( !lst.isEmpty() ) { | 149 | if ( !lst.isEmpty() ) { | ||
150 | ClipAction* action = new ClipAction( QString(), mimetype.comment() ); | 150 | ClipAction* action = new ClipAction( QString(), mimetype.comment() ); | ||
151 | foreach( const KService::Ptr &service, lst ) { | 151 | for ( const KService::Ptr &service : lst ) { | ||
152 | action->addCommand( ClipCommand( QString(), service->name(), true, service->icon(), | 152 | action->addCommand( ClipCommand( QString(), service->name(), true, service->icon(), | ||
153 | ClipCommand::IGNORE, service->storageId() ) ); | 153 | ClipCommand::IGNORE, service->storageId() ) ); | ||
154 | } | 154 | } | ||
155 | m_myMatches.append( action ); | 155 | m_myMatches.append( action ); | ||
156 | } | 156 | } | ||
157 | } | 157 | } | ||
158 | } | 158 | } | ||
159 | 159 | | |||
160 | const ActionList& URLGrabber::matchingActions( const QString& clipData, bool automatically_invoked ) | 160 | const ActionList& URLGrabber::matchingActions( const QString& clipData, bool automatically_invoked ) | ||
161 | { | 161 | { | ||
162 | m_myMatches.clear(); | 162 | m_myMatches.clear(); | ||
163 | 163 | | |||
164 | matchingMimeActions(clipData); | 164 | matchingMimeActions(clipData); | ||
165 | 165 | | |||
166 | 166 | | |||
167 | // now look for matches in custom user actions | 167 | // now look for matches in custom user actions | ||
168 | foreach (ClipAction* action, m_myActions) { | 168 | for (ClipAction* action : qAsConst(m_myActions)) { | ||
169 | if ( action->matches( clipData ) && (action->automatic() || !automatically_invoked) ) { | 169 | if ( action->matches( clipData ) && (action->automatic() || !automatically_invoked) ) { | ||
170 | m_myMatches.append( action ); | 170 | m_myMatches.append( action ); | ||
171 | } | 171 | } | ||
172 | } | 172 | } | ||
173 | 173 | | |||
174 | return m_myMatches; | 174 | return m_myMatches; | ||
175 | } | 175 | } | ||
176 | 176 | | |||
Show All 10 Lines | 186 | { | |||
187 | if (!item) { | 187 | if (!item) { | ||
188 | qWarning("Attempt to invoke URLGrabber without an item"); | 188 | qWarning("Attempt to invoke URLGrabber without an item"); | ||
189 | return; | 189 | return; | ||
190 | } | 190 | } | ||
191 | QString text(item->text()); | 191 | QString text(item->text()); | ||
192 | if (m_stripWhiteSpace) { | 192 | if (m_stripWhiteSpace) { | ||
193 | text = text.trimmed(); | 193 | text = text.trimmed(); | ||
194 | } | 194 | } | ||
195 | ActionList matchingActionsList = matchingActions( text, automatically_invoked ); | 195 | const ActionList matchingActionsList = matchingActions( text, automatically_invoked ); | ||
196 | 196 | | |||
197 | if (!matchingActionsList.isEmpty()) { | 197 | if (!matchingActionsList.isEmpty()) { | ||
198 | // don't react on blacklisted (e.g. konqi's/netscape's urls) unless the user explicitly asked for it | 198 | // don't react on blacklisted (e.g. konqi's/netscape's urls) unless the user explicitly asked for it | ||
199 | if ( automatically_invoked && isAvoidedWindow() ) { | 199 | if ( automatically_invoked && isAvoidedWindow() ) { | ||
200 | return; | 200 | return; | ||
201 | } | 201 | } | ||
202 | 202 | | |||
203 | m_myCommandMapper.clear(); | 203 | m_myCommandMapper.clear(); | ||
204 | 204 | | |||
205 | m_myPopupKillTimer->stop(); | 205 | m_myPopupKillTimer->stop(); | ||
206 | 206 | | |||
207 | m_myMenu = new QMenu; | 207 | m_myMenu = new QMenu; | ||
208 | 208 | | |||
209 | connect(m_myMenu, &QMenu::triggered, this, &URLGrabber::slotItemSelected); | 209 | connect(m_myMenu, &QMenu::triggered, this, &URLGrabber::slotItemSelected); | ||
210 | 210 | | |||
211 | foreach (ClipAction* clipAct, matchingActionsList) { | 211 | for (ClipAction* clipAct : matchingActionsList) { | ||
212 | m_myMenu->addSection(QIcon::fromTheme( QStringLiteral("klipper") ), | 212 | m_myMenu->addSection(QIcon::fromTheme( QStringLiteral("klipper") ), | ||
213 | i18n("%1 - Actions For: %2", clipAct->description(), KStringHandler::csqueeze(text, 45))); | 213 | i18n("%1 - Actions For: %2", clipAct->description(), KStringHandler::csqueeze(text, 45))); | ||
214 | QList<ClipCommand> cmdList = clipAct->commands(); | 214 | QList<ClipCommand> cmdList = clipAct->commands(); | ||
215 | int listSize = cmdList.count(); | 215 | int listSize = cmdList.count(); | ||
216 | for (int i=0; i<listSize;++i) { | 216 | for (int i=0; i<listSize;++i) { | ||
217 | ClipCommand command = cmdList.at(i); | 217 | ClipCommand command = cmdList.at(i); | ||
218 | 218 | | |||
219 | QString item = command.description; | 219 | QString item = command.description; | ||
▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Line(s) | |||||
328 | 328 | | |||
329 | void URLGrabber::saveSettings() const | 329 | void URLGrabber::saveSettings() const | ||
330 | { | 330 | { | ||
331 | KConfigGroup cg(KSharedConfig::openConfig(), "General"); | 331 | KConfigGroup cg(KSharedConfig::openConfig(), "General"); | ||
332 | cg.writeEntry( "Number of Actions", m_myActions.count() ); | 332 | cg.writeEntry( "Number of Actions", m_myActions.count() ); | ||
333 | 333 | | |||
334 | int i = 0; | 334 | int i = 0; | ||
335 | QString group; | 335 | QString group; | ||
336 | foreach (ClipAction* action, m_myActions) { | 336 | for (ClipAction* action : qAsConst(m_myActions)) { | ||
337 | group = QStringLiteral("Action_%1").arg( i ); | 337 | group = QStringLiteral("Action_%1").arg( i ); | ||
338 | action->save( KSharedConfig::openConfig(), group ); | 338 | action->save( KSharedConfig::openConfig(), group ); | ||
339 | ++i; | 339 | ++i; | ||
340 | } | 340 | } | ||
341 | 341 | | |||
342 | KlipperSettings::setNoActionsForWM_CLASS(m_myAvoidWindows); | 342 | KlipperSettings::setNoActionsForWM_CLASS(m_myAvoidWindows); | ||
343 | } | 343 | } | ||
344 | 344 | | |||
▲ Show 20 Lines • Show All 120 Lines • ▼ Show 20 Line(s) | 464 | { | |||
465 | KConfigGroup cg(kc, group); | 465 | KConfigGroup cg(kc, group); | ||
466 | cg.writeEntry( "Description", description() ); | 466 | cg.writeEntry( "Description", description() ); | ||
467 | cg.writeEntry( "Regexp", regExp() ); | 467 | cg.writeEntry( "Regexp", regExp() ); | ||
468 | cg.writeEntry( "Number of commands", m_myCommands.count() ); | 468 | cg.writeEntry( "Number of commands", m_myCommands.count() ); | ||
469 | cg.writeEntry( "Automatic", automatic() ); | 469 | cg.writeEntry( "Automatic", automatic() ); | ||
470 | 470 | | |||
471 | int i=0; | 471 | int i=0; | ||
472 | // now iterate over all commands of this action | 472 | // now iterate over all commands of this action | ||
473 | foreach (const ClipCommand& cmd, m_myCommands) { | 473 | for (const ClipCommand& cmd : qAsConst(m_myCommands)) { | ||
474 | QString _group = group + QStringLiteral("/Command_%1"); | 474 | QString _group = group + QStringLiteral("/Command_%1"); | ||
475 | KConfigGroup cg(kc, _group.arg(i)); | 475 | KConfigGroup cg(kc, _group.arg(i)); | ||
476 | 476 | | |||
477 | cg.writePathEntry( "Commandline", cmd.command ); | 477 | cg.writePathEntry( "Commandline", cmd.command ); | ||
478 | cg.writeEntry( "Description", cmd.description ); | 478 | cg.writeEntry( "Description", cmd.description ); | ||
479 | cg.writeEntry( "Enabled", cmd.isEnabled ); | 479 | cg.writeEntry( "Enabled", cmd.isEnabled ); | ||
480 | cg.writeEntry( "Icon", cmd.icon ); | 480 | cg.writeEntry( "Icon", cmd.icon ); | ||
481 | cg.writeEntry( "Output", static_cast<int>(cmd.output) ); | 481 | cg.writeEntry( "Output", static_cast<int>(cmd.output) ); | ||
482 | 482 | | |||
483 | ++i; | 483 | ++i; | ||
484 | } | 484 | } | ||
485 | } | 485 | } | ||
486 | 486 | | |||
487 | 487 | |