MCPcopy Create free account
hub / github.com/KDE/kdevelop / copyFileAndExpandMacros

Method copyFileAndExpandMacros

plugins/appwizard/appwizardplugin.cpp:476–520  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

474}
475
476bool 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}
521KDevelop::ContextMenuExtension AppWizardPlugin::contextMenuExtension(KDevelop::Context* context, QWidget* parent)
522{
523 Q_UNUSED(parent);

Callers

nothing calls this directly

Calls 6

execMethod · 0.80
atEndMethod · 0.80
readLineMethod · 0.80
openMethod · 0.45
handleMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected