QLibrary* RazorPluginInfo::loadLibrary(const QString& libDir) const { QString baseName, path; QFileInfo fi = QFileInfo(fileName()); path = fi.canonicalPath(); baseName = value("X-Razor-Library", fi.completeBaseName()).toString(); QString soPath = QString("%1/lib%2.so").arg(libDir, baseName); QLibrary* library = new QLibrary(soPath); if (!library->load()) { qWarning() << QString("Can't load plugin lib \"%1\"").arg(soPath) << library->errorString(); delete library; return 0; } QString locale = QLocale::system().name(); QTranslator* translator = new QTranslator(library); translator->load(QString("%1/%2/%2_%3.qm").arg(path, baseName, locale)); qApp->installTranslator(translator); return library; }
void DownloadItemViewModel::showInFolder() { if (m_state != Done) return; QFileInfo info = QFileInfo(m_resultFileName); #if defined(Q_OS_WIN) QString url = info.canonicalFilePath(); url.replace("/", "\\"); url = "/select, \"" + url + "\""; ShellExecute(NULL, L"open", L"explorer.exe", (WCHAR*)url.utf16(), NULL, 5); #else QString url = info.canonicalPath(); QDesktopServices::openUrl(QUrl("file:///"+url)); #endif }
void PlaylistModel::openFilesAndDirs0(QVector<ImageFile*> &openfiles, const QStringList &paths, int level) { if (paths.empty()) return; for (auto iter = paths.cbegin(); iter != paths.cend(); ++iter) { const QFileInfo info(*iter); if (info.isFile()) { if (ImageFile::isReadableImageFile(*iter)) { ImageFile *imgfile = new ImageFile(*iter); openfiles.append(imgfile); } else { QVector<ImageFile*> imgfiles = ImageFile::openArchive(*iter); openfiles.append(imgfiles); imgfiles.clear(); } } else if (level > 0) { QStringList newlist; const QFileInfoList entrylist = QDir(*iter).entryInfoList(); const int clen = info.canonicalPath().length(); for (auto iter2 = entrylist.cbegin(); iter2 != entrylist.cend(); ++iter2) { if (clen < iter2->canonicalPath().length()) { newlist << iter2->filePath(); } } openFilesAndDirs0(openfiles, newlist, level-1); } } }
// ------------------------------------------------------- QString SpiceFile::getSubcircuitFile() { // construct full filename QString FileName = Props.getFirst()->Value; if (FileName.isEmpty()) { return misc::properAbsFileName(FileName); } QFileInfo FileInfo(FileName); if (FileInfo.exists()) { // the file must be an absolute path to a schematic file return FileInfo.absoluteFilePath(); } else { // get the complete base name (everything except the last '.' // and whatever follows QString baseName = FileInfo.completeBaseName(); // if only a file name is supplied, first check if it is in the // same directory as the schematic file it is a part of if (FileInfo.fileName () == FileName) { // the file has no path information, just the file name if (containingSchematic) { // check if a file of the same name is in the same directory // as the schematic file, if we have a pointer to it, in // which case we use this one QFileInfo schematicFileInfo = containingSchematic->getFileInfo (); for (int i = 0; i < QucsSettings.spiceExtensions.count (); i++) { QString extension = QucsSettings.spiceExtensions[i]; extension.remove(0, 1); // take leading '*' out, issue with exits() QFileInfo localFileInfo (schematicFileInfo.canonicalPath () + "/" + baseName + extension); if (localFileInfo.exists ()) { // return the subcircuit saved in the same directory // as the schematic file return localFileInfo.absoluteFilePath(); } else { /// \todo improve GUI/CLI error/warning qCritical() << "Spice file not found:" << localFileInfo.absFilePath(); } } } } // look up the hash table for the schematic file as // it does not seem to be an absolute path, this will also // search the home directory which is always hashed QMutex mutex; mutex.lock(); QString hashsearchresult = ""; // if GUI is running and has something in the hash if ( (QucsMain != 0) && !QucsMain->spiceNameHash.isEmpty() ) hashsearchresult = QucsMain->spiceNameHash.value(baseName); mutex.unlock(); if (hashsearchresult.isEmpty()) { // the schematic was not found in the hash table, return // what would always have been returned in this case return misc::properAbsFileName(FileName); } else { // we found an entry in the hash table, check it actually still exists FileInfo.setFile(hashsearchresult); if (FileInfo.exists()) { // it does exist so return the absolute file path return FileInfo.absoluteFilePath(); } else { // the schematic file does not actually exist, return // what would always have been returned in this case return misc::properAbsFileName(FileName); } } } }
// ------------------------------------------------------- QString Subcircuit::getSubcircuitFile() { // construct full filename QString FileName = Props.getFirst()->Value; if (FileName.isEmpty()) { return properAbsFileName(FileName); } QFileInfo FileInfo(FileName); if (FileInfo.exists()) { // the file must be an absolute path to a schematic file return FileInfo.absoluteFilePath(); } else { // get the complete base name (everything except the last '.' // and whatever follows QString baseName = FileInfo.completeBaseName(); // if only a file name is supplied, first check if it is in the // same directory as the schematic file it is a part of if (FileInfo.fileName () == FileName) { // the file has no path information, just the file name if (containingSchematic) { // check if a file of the same name is in the same directory // as the schematic file, if we have a pointer to it, in // which case we use this one QFileInfo schematicFileInfo = containingSchematic->getFileInfo (); QFileInfo localFIleInfo (schematicFileInfo.canonicalPath () + "/" + baseName + ".sch"); if (localFIleInfo.exists ()) { // return the subcircuit saved in the same directory // as the schematic file return localFIleInfo.absoluteFilePath(); } } } // look up the hash table for the schematic file as // it does not seem to be an absolute path, this will also // search the home directory which is always hashed QMutex mutex; mutex.lock(); QString hashsearchresult = QucsMain->schNameHash.value(baseName); mutex.unlock(); if (hashsearchresult.isEmpty()) { // the schematic was not found in the hash table, return // what would always have been returned in this case return properAbsFileName(FileName); } else { // we found an entry in the hash table, check it actually still exists FileInfo.setFile(hashsearchresult); if (FileInfo.exists()) { // it does exist so return the absolute file path return FileInfo.absoluteFilePath(); } else { // the schematic file does not actually exist, return // what would always have been returned in this case return properAbsFileName(FileName); } } } }
bool processXmlFile(const QString &xmlFile) { QFile file(xmlFile); if (!file.open(QIODevice::ReadOnly)) return false; const QLatin1String tag_app("app"); const QLatin1String attrib_mainQmlFile("mainqmlfile"); const QLatin1String attrib_projectPath("projectpath"); const QLatin1String attrib_projectName("projectname"); const QLatin1String attrib_screenOrientation("screenorientation"); const QLatin1String value_screenOrientationLockLandscape("LockLandscape"); const QLatin1String value_screenOrientationLockPortrait("LockPortrait"); const QLatin1String attrib_networkAccess("networkaccess"); static const QString qtDir = QLibraryInfo::location(QLibraryInfo::PrefixPath) + QLatin1Char('/'); QXmlStreamReader reader(&file); while (!reader.atEnd()) { const QXmlStreamReader::TokenType token = reader.readNext(); switch (token) { case QXmlStreamReader::StartElement: if (reader.name() == tag_app) { QtQuickApp app; QFileInfo projectPath; if (!reader.attributes().hasAttribute(attrib_projectPath)) { qDebug() << "Project without path found"; continue; } projectPath = qtDir + reader.attributes().value(attrib_projectPath).toString(); app.setProjectPath(projectPath.absoluteFilePath()); if (reader.attributes().hasAttribute(attrib_mainQmlFile)) { const QFileInfo qmlFileOrigin( qtDir + reader.attributes().value(attrib_mainQmlFile).toString()); if (!qmlFileOrigin.exists()) { qDebug() << "Cannot find" << QDir::toNativeSeparators(qmlFileOrigin.absoluteFilePath()); continue; } const QFileInfo qmlTargetPath(QString(projectPath.absoluteFilePath() + QLatin1Char('/') + qmlFileOrigin.baseName() + QLatin1String("/qml"))); #ifdef Q_OS_WIN const QString sourcePath = QDir::toNativeSeparators(qmlFileOrigin.canonicalPath() + QLatin1String("/*")); const QString targetPath = QDir::toNativeSeparators(qmlTargetPath.absoluteFilePath() + QLatin1Char('/')); QProcess xcopy; QStringList parameters; parameters << QLatin1String("/E") << sourcePath << targetPath; xcopy.start(QLatin1String("xcopy.exe"), parameters); if (!xcopy.waitForStarted() || !xcopy.waitForFinished()) { qDebug() << "Could not copy" << QDir::toNativeSeparators(sourcePath); continue; } #else // Q_OS_WIN // Implement me! #endif // Q_OS_WIN app.setMainQmlFile(qmlTargetPath.absoluteFilePath() + QLatin1Char('/') + qmlFileOrigin.fileName()); } app.setProjectName(reader.attributes().hasAttribute(attrib_projectName) ? reader.attributes().value(attrib_projectName).toString() : QFileInfo(app.mainQmlFile()).baseName()); if (reader.attributes().hasAttribute(attrib_screenOrientation)) { const QStringRef orientation = reader.attributes().value(attrib_screenOrientation); app.setOrientation(orientation == value_screenOrientationLockLandscape ? AbstractMobileApp::ScreenOrientationLockLandscape : orientation == value_screenOrientationLockPortrait ? AbstractMobileApp::ScreenOrientationLockPortrait : AbstractMobileApp::ScreenOrientationAuto); } if (reader.attributes().hasAttribute(attrib_networkAccess)) app.setNetworkEnabled( reader.attributes().value(attrib_networkAccess).toString() == QLatin1String("true")); if (!app.generateFiles(0)) qDebug() << "Unable to generate the files for" << app.projectName(); } break; default: break; } } return true; }
void FileBrowser::on_parentDir_clicked() { QFileInfo info = model->fileInfo( ui->treeFiles->rootIndex() ); setPath(info.canonicalPath()); }