QgsGrassModule::Description QgsGrassModule::description( QString path ) { QgsDebugMsg( "called." ); // Open QGIS module description path.append( ".qgm" ); QFile qFile( path ); if ( !qFile.exists() ) { return Description( tr( "Not available, description not found (%1)" ).arg( path ) ); } if ( ! qFile.open( QIODevice::ReadOnly ) ) { return Description( tr( "Not available, cannot open description (%1)" ).arg( path ) ); } QDomDocument qDoc( QStringLiteral( "qgisgrassmodule" ) ); QString err; int line, column; if ( !qDoc.setContent( &qFile, &err, &line, &column ) ) { QString errmsg = tr( "Cannot read module file (%1)" ).arg( path ) + tr( "\n%1\nat line %2 column %3" ).arg( err ).arg( line ).arg( column ); QgsDebugMsg( errmsg ); QMessageBox::warning( 0, tr( "Warning" ), errmsg ); qFile.close(); return Description( tr( "Not available, incorrect description (%1)" ).arg( path ) ); } qFile.close(); QDomElement qDocElem = qDoc.documentElement(); QString label = QApplication::translate( "grasslabel", qDocElem.attribute( QStringLiteral( "label" ) ).trimmed().toUtf8() ); bool direct = qDocElem.attribute( QStringLiteral( "direct" ) ) == QLatin1String( "1" ); return Description( label, direct ); }
GpgME::VerificationResult SignaturePrivate::verify(const KUrl &dest, const QByteArray &sig) { GpgME::VerificationResult result; if (!QFile::exists(dest.pathOrUrl()) || sig.isEmpty()) { return result; } GpgME::initializeLibrary(); GpgME::Error error = GpgME::checkEngine(GpgME::OpenPGP); if (error) { kDebug(5001) << "OpenPGP not supported!"; return result; } QScopedPointer<GpgME::Context> context(GpgME::Context::createForProtocol(GpgME::OpenPGP)); if (!context.data()) { kDebug(5001) << "Could not create context."; return result; } boost::shared_ptr<QFile> qFile(new QFile(dest.pathOrUrl())); qFile->open(QIODevice::ReadOnly); QGpgME::QIODeviceDataProvider *file = new QGpgME::QIODeviceDataProvider(qFile); GpgME::Data dFile(file); QGpgME::QByteArrayDataProvider signatureBA(sig); GpgME::Data signature(&signatureBA); return context->verifyDetachedSignature(signature, dFile); }
void MainWindow::on_treeView_clicked(const QModelIndex &index) { QUrl url; //QString qstrQML(CONFIGURATOR_API::getQML(index.internalPointer())); QString qstrFileName("/tmp/"); qstrFileName.append(CONFIGURATOR_API::getFileName(index.internalPointer())); qstrFileName.append(".qml"); qDebug() << qstrFileName; QFile qFile(qstrFileName.toLocal8Bit().data()); qDebug() << "this->getRegenerateQML() =" << this->getRegenerateQML() << " qFile.exists() = " << qFile.exists(); if (this->getRegenerateQML() == true || qFile.exists() == false) { QFile::remove(qstrFileName); if (qFile.open(QIODevice::WriteOnly | QIODevice::Truncate) == 0) { return; } QTextStream out(&qFile); out << CONFIGURATOR_API::getQML(index.internalPointer(), index.row()); } qFile.close(); //url.fromLocalFile(qstrFileName.toLocal8Bit().data()); m_pView->engine()->clearComponentCache(); m_pView->setSource(QUrl::fromLocalFile(qstrFileName.toLocal8Bit().data())); //m_pView->setSource(QUrl::fromLocalFile("/tmp/sasha.xsd.qml")); //m_pView->setSource(url); //m_pView->show(); /*m_pView = new QQuickView(); ApplicationData *pAppData = new ApplicationData(); m_pView->rootContext()->setContextProperty("ApplicationData", pAppData); TableDataModel *pTableDataModel = new TableDataModel[MAX_ARRAY_X]; for (int idx = 0; idx < MAX_ARRAY_X; idx++) { m_pView->rootContext()->setContextProperty(modelNames[idx], &(pTableDataModel[idx])); } m_pView->setSource(url);*/ //QWidget *container = QWidget::createWindowContainer(m_pView); //this->ui->verticalLayout->addWidget(container); }
bool LrcEditor::saveFileAs(const QString &file) { QFile qFile(file); if (!qFile.open(QFile::WriteOnly | QFile::Text)) return false; QTextStream os(&qFile); os.setCodec("UTF-8"); os.setGenerateByteOrderMark(true); os << toPlainText(); qFile.close(); return true; }
void ut_file::testReadOnly() { if (Unittests::isRoot()) { qDebug() << "Running as root, disabling file permissions test!"; return; } QTemporaryFile testFile; testFile.open(); QuillImage image = Unittests::generatePaletteImage(); image.save(testFile.fileName(), "png"); QFile qFile(testFile.fileName()); qFile.setPermissions(QFile::ReadOwner); QuillFile *file = new QuillFile(testFile.fileName(), Strings::png); QVERIFY(!file->supportsEditing()); delete file; }
void BitmapAnnotation::parseShapeAnnotation(QString shape, OMCProxy *omc) { shape = shape.replace("{", ""); shape = shape.replace("}", ""); // parse the shape to get the list of attributes of bitmap. QStringList list = StringHandler::getStrings(shape); // if (list.size() < 16) // { // return; // } // if first item of list is true then the Rectangle should be visible. mVisible = static_cast<QString>(list.at(0)).contains("true"); int index = 0; if (omc->mAnnotationVersion == OMCProxy::ANNOTATION_VERSION3X) { mOrigin.setX(static_cast<QString>(list.at(1)).toFloat()); mOrigin.setY(static_cast<QString>(list.at(2)).toFloat()); mRotation = static_cast<QString>(list.at(3)).toFloat(); index = 3; } // 4,5,6,7 items of the list contains the extent points of rectangle. index = index + 1; qreal x = static_cast<QString>(list.at(index)).toFloat(); index = index + 1; qreal y = static_cast<QString>(list.at(index)).toFloat(); QPointF p1 (x, y); index = index + 1; x = static_cast<QString>(list.at(index)).toFloat(); index = index + 1; y = static_cast<QString>(list.at(index)).toFloat(); QPointF p2 (x, y); mExtent.append(p1); mExtent.append(p2); //8 Item contains filename index = index + 1; QString tempFileName = StringHandler::removeFirstLastQuotes(list.at(index)); QDir dir(tempFileName); if(dir.isAbsolute()) mFileName = tempFileName; else { if(tempFileName.startsWith("/")) mFileName = tempFileName; else { tempFileName.insert(0, QString("/")); mFileName = tempFileName; } } //If not customshape create absolute path. if(!mIsCustomShape) { QString modelPath = mpComponent->mpOMCProxy->getSourceFile(mpComponent->getClassName()); QFileInfo qFile(modelPath); mFileName = qFile.absolutePath() + "/" + tempFileName; } //9 Item contains imagesource if(tempFileName.isEmpty()) { index = index + 1; mImageSource = StringHandler::removeFirstLastQuotes(list.at(index)); } }
QgsGrassModule::QgsGrassModule( QgsGrassTools *tools, QString moduleName, QgisInterface *iface, bool direct, QWidget *parent, Qt::WindowFlags f ) : QWidget( parent, f ) , QgsGrassModuleBase() , mOptions( 0 ) , mSuccess( false ) , mDirect( direct ) { Q_UNUSED( f ); QgsDebugMsg( "called" ); setupUi( this ); // use fixed width font because module's output may be formatted mOutputTextBrowser->setStyleSheet( QStringLiteral( "font-family: Monospace; font-size: 9pt;" ) ); lblModuleName->setText( tr( "Module: %1" ).arg( moduleName ) ); mTools = tools; mIface = iface; mCanvas = mIface->mapCanvas(); //mParent = parent; /* Read module description and create options */ // Open QGIS module description QString mpath = QgsGrass::modulesConfigDirPath() + "/" + moduleName + ".qgm"; QgsDebugMsg( QString( "mpath = %1" ).arg( mpath ) ); QFile qFile( mpath ); if ( !qFile.exists() ) { mErrors.append( tr( "The module file (%1) not found." ).arg( mpath ) ); return; } if ( ! qFile.open( QIODevice::ReadOnly ) ) { mErrors.append( tr( "Cannot open module file (%1)" ).arg( mpath ) ); return; } QDomDocument qDoc( QStringLiteral( "qgisgrassmodule" ) ); QString err; int line, column; if ( !qDoc.setContent( &qFile, &err, &line, &column ) ) { QString errmsg = tr( "Cannot read module file (%1)" ).arg( mpath ) + tr( "\n%1\nat line %2 column %3" ).arg( err ).arg( line ).arg( column ); QgsDebugMsg( errmsg ); mErrors.append( errmsg ); qFile.close(); return; } qFile.close(); QDomElement qDocElem = qDoc.documentElement(); // Read GRASS module description QString xName = qDocElem.attribute( QStringLiteral( "module" ) ); QString xDocName = qDocElem.attribute( QStringLiteral( "manual" ) ); if ( xDocName.isEmpty() ) { xDocName = xName; } // Binary modules on windows has .exe extension // but not all modules have to be binary (can be scripts) // => test if the module is in path and if it is not // add .exe and test again #ifdef Q_OS_WIN mXName = QgsGrass::findModule( xName ); if ( mXName.isNull() ) { QgsDebugMsg( "Module " + xName + " not found" ); mErrors.append( tr( "Module %1 not found" ).arg( xName ) ); return; } #else mXName = xName; #endif QVBoxLayout *layout = new QVBoxLayout( mTabWidget->widget( 0 ) ); layout->setContentsMargins( 0, 0, 0, 0 ); if ( xName == QLatin1String( "r.mapcalc" ) ) { mOptions = new QgsGrassMapcalc( mTools, this, mIface, mTabWidget->widget( 0 ) ); } else { mOptions = new QgsGrassModuleStandardOptions( mTools, this, mIface, mXName, qDocElem, mDirect, mTabWidget->widget( 0 ) ); } layout->addWidget( dynamic_cast<QWidget *>( mOptions ) ); if ( !mOptions->errors().isEmpty() ) { mErrors.append( mOptions->errors() ); } // Hide display if there is no output if ( !mOptions->hasOutput( QgsGrassModuleOption::Vector ) && !mOptions->hasOutput( QgsGrassModuleOption::Raster ) ) { mViewButton->hide(); } mViewButton->setEnabled( false ); // Create manual if available QString gisBase = getenv( "GISBASE" ); QString manPath = gisBase + "/docs/html/" + xDocName + ".html"; QFile manFile( manPath ); if ( manFile.exists() ) { mManualTextBrowser->setOpenExternalLinks( true ); mManualTextBrowser->setSource( QUrl::fromLocalFile( manPath ) ); } else { mManualTextBrowser->clear(); mManualTextBrowser->textCursor().insertImage( QStringLiteral( ":/grass/error.png" ) ); mManualTextBrowser->insertPlainText( tr( "Cannot find man page %1" ).arg( manPath ) ); mManualTextBrowser->insertPlainText( tr( "Please ensure you have the GRASS documentation installed." ) ); } connect( &mProcess, &QProcess::readyReadStandardOutput, this, &QgsGrassModule::readStdout ); connect( &mProcess, &QProcess::readyReadStandardError, this, &QgsGrassModule::readStderr ); connect( &mProcess, static_cast<void ( QProcess::* )( int, QProcess::ExitStatus )>( &QProcess::finished ), this, &QgsGrassModule::finished ); const char *env = "GRASS_MESSAGE_FORMAT=gui"; char *envstr = new char[strlen( env ) + 1]; strcpy( envstr, env ); putenv( envstr ); mOutputTextBrowser->setReadOnly( true ); }
void CComponenetSelectorDialog::writeOutput(int idx) { QFileDialog dialog(this); dialog.setFileMode(QFileDialog::AnyFile); QString qstrFileName; if (m_eOutputMode == QML_OUTPUT) { qstrFileName = dialog.getSaveFileName(this, tr("Save QML File"), "/tmp",tr("QML (*.qml)")); } else if (m_eOutputMode == DOCBOOK_OUTPUT) { qstrFileName = dialog.getSaveFileName(this, tr("Save DocBook File"), "/tmp",tr("XML (*.xml)")); } else if (m_eOutputMode == DOJO_OUTPUT) { qstrFileName = dialog.getSaveFileName(this, tr("Save Dojo File"), "/tmp",tr("Javascript (*.js)")); } const char *pFileName = qstrFileName.toLocal8Bit().data(); qDebug() << pFileName; QFile::remove(qstrFileName); QFile qFile(qstrFileName.toLocal8Bit().data()); if (qFile.open(QIODevice::WriteOnly | QIODevice::Truncate) == 0) { return; } QTextStream out(&qFile); const char *pOutput = NULL; try { if (m_eOutputMode == QML_OUTPUT) { pOutput = CONFIGURATOR_API::getQMLByIndex(idx); out << pOutput; } else if (m_eOutputMode == DOCBOOK_OUTPUT) { pOutput = CONFIGURATOR_API::getDocBookByIndex(idx); out << pOutput; } else if (m_eOutputMode == DOJO_OUTPUT) { pOutput = CONFIGURATOR_API::getDojoByIndex(idx); out << pOutput; } qFile.close(); //this->hide(); if (pOutput != NULL && *pOutput != 0) { QMessageBox::information( this, tr("Success"), tr("Completed with no errors!") ); } else { QMessageBox::warning( this, tr("Failure"), tr("Failed. Nothing generated!") ); } } catch (...) { QMessageBox::warning( this, tr("Exception"), tr("Failed. Exception thrown!") ); } done(0); }