| 474 | } |
| 475 | |
| 476 | bool AppWizardPlugin::copyFileAndExpandMacros(const QString &source, const QString &dest) |
| 477 | { |
| 478 | qCDebug(PLUGIN_APPWIZARD) << "copy:" << source << "to" << dest; |
| 479 | QMimeDatabase db; |
| 480 | QMimeType mime = db.mimeTypeForFile(source); |
| 481 | if( !mime.inherits(QStringLiteral("text/plain")) ) |
| 482 | { |
| 483 | KIO::CopyJob* job = KIO::copy( QUrl::fromUserInput(source), QUrl::fromUserInput(dest), KIO::HideProgressInfo ); |
| 484 | if( !job->exec() ) |
| 485 | { |
| 486 | return false; |
| 487 | } |
| 488 | return true; |
| 489 | } else |
| 490 | { |
| 491 | QFile inputFile(source); |
| 492 | QFile outputFile(dest); |
| 493 | |
| 494 | |
| 495 | if (inputFile.open(QFile::ReadOnly) && outputFile.open(QFile::WriteOnly)) |
| 496 | { |
| 497 | QTextStream input(&inputFile); |
| 498 | QTextStream output(&outputFile); |
| 499 | while(!input.atEnd()) |
| 500 | { |
| 501 | QString line = input.readLine(); |
| 502 | output << KMacroExpander::expandMacros(line, m_variables) << "\n"; |
| 503 | } |
| 504 | #ifndef Q_OS_WIN |
| 505 | // Preserve file mode... |
| 506 | QT_STATBUF statBuf; |
| 507 | QT_FSTAT(inputFile.handle(), &statBuf); |
| 508 | // Unix only, won't work in Windows, maybe KIO::chmod could be used |
| 509 | ::fchmod(outputFile.handle(), statBuf.st_mode); |
| 510 | #endif |
| 511 | return true; |
| 512 | } |
| 513 | else |
| 514 | { |
| 515 | inputFile.close(); |
| 516 | outputFile.close(); |
| 517 | return false; |
| 518 | } |
| 519 | } |
| 520 | } |
| 521 | KDevelop::ContextMenuExtension AppWizardPlugin::contextMenuExtension(KDevelop::Context* context, QWidget* parent) |
| 522 | { |
| 523 | Q_UNUSED(parent); |