| 218 | } |
| 219 | |
| 220 | void ExternalScriptJob::start() |
| 221 | { |
| 222 | qCDebug(PLUGIN_EXTERNALSCRIPT) << "launching?" << m_proc; |
| 223 | |
| 224 | if (m_proc) { |
| 225 | if (m_showOutput) { |
| 226 | startOutput(); |
| 227 | } |
| 228 | appendLine(i18n("Running external script: %1", m_proc->program().join(QLatin1Char(' ')))); |
| 229 | m_proc->start(); |
| 230 | |
| 231 | if (m_inputMode != ExternalScriptItem::InputNone) { |
| 232 | QString inputText; |
| 233 | |
| 234 | switch (m_inputMode) { |
| 235 | case ExternalScriptItem::InputNone: |
| 236 | // do nothing; |
| 237 | break; |
| 238 | case ExternalScriptItem::InputSelectionOrNone: |
| 239 | if (m_selectionRange.isValid()) { |
| 240 | inputText = m_document->text(m_selectionRange); |
| 241 | } // else nothing |
| 242 | break; |
| 243 | case ExternalScriptItem::InputSelectionOrDocument: |
| 244 | if (m_selectionRange.isValid()) { |
| 245 | inputText = m_document->text(m_selectionRange); |
| 246 | } else { |
| 247 | inputText = m_document->text(); |
| 248 | } |
| 249 | break; |
| 250 | case ExternalScriptItem::InputDocument: |
| 251 | inputText = m_document->text(); |
| 252 | break; |
| 253 | } |
| 254 | |
| 255 | ///TODO: what to do with the encoding here? |
| 256 | /// maybe ask Christoph for what kate returns... |
| 257 | m_proc->write(inputText.toUtf8()); |
| 258 | |
| 259 | m_proc->closeWriteChannel(); |
| 260 | } |
| 261 | } else { |
| 262 | qCDebug(PLUGIN_EXTERNALSCRIPT) << "No process, something went wrong when creating the job"; |
| 263 | // No process means we've returned early on from the constructor, some bad error happened |
| 264 | emitResult(); |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | bool ExternalScriptJob::doKill() |
| 269 | { |