PyObject* Application::sExport(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/) { PyObject* object; const char* filename; if (!PyArg_ParseTuple(args, "Os",&object,&filename)) return NULL; PY_TRY { App::Document* doc = 0; Py::Sequence list(object); for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { PyObject* item = (*it).ptr(); if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) { App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr(); doc = obj->getDocument(); break; } } // get the view that belongs to the found document if (doc) { QString fileName = QString::fromUtf8(filename); QFileInfo fi; fi.setFile(fileName); QString ext = fi.completeSuffix().toLower(); if (ext == QLatin1String("iv") || ext == QLatin1String("wrl") || ext == QLatin1String("vrml") || ext == QLatin1String("wrz") || ext == QLatin1String("svg") || ext == QLatin1String("idtf")) { Gui::Document* gui_doc = Application::Instance->getDocument(doc); std::list<MDIView*> view3d = gui_doc->getMDIViewsOfType(View3DInventor::getClassTypeId()); if (view3d.empty()) { PyErr_SetString(PyExc_Exception, "Cannot export to SVG because document doesn't have a 3d view"); return 0; } else { QString cmd = QString::fromLatin1( "Gui.getDocument(\"%1\").mdiViewsOfType('Gui::View3DInventor')[0].dump(\"%2\")" ).arg(QLatin1String(doc->getName())).arg(fi.absoluteFilePath()); Base::Interpreter().runString(cmd.toUtf8()); } } else if (ext == QLatin1String("pdf")) { Gui::Document* gui_doc = Application::Instance->getDocument(doc); if (gui_doc) { Gui::MDIView* view = gui_doc->getActiveView(); if (view) { View3DInventor* view3d = qobject_cast<View3DInventor*>(view); if (view3d) view3d->viewAll(); QPrinter printer(QPrinter::ScreenResolution); printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFileName(fileName); view->print(&printer); } } } } } PY_CATCH; Py_Return; }
void ScanFileOrFolder::listFolder(QFileInfo source,QFileInfo destination) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("source: %1 (%2), destination: %3 (%4)").arg(source.absoluteFilePath()).arg(source.isSymLink()).arg(destination.absoluteFilePath()).arg(destination.isSymLink())); if(stopIt) return; destination=resolvDestination(destination); if(stopIt) return; if(fileErrorAction==FileError_Skip) return; //if is same if(source.absoluteFilePath()==destination.absoluteFilePath()) { emit folderAlreadyExists(source,destination,true); waitOneAction.acquire(); QString destinationSuffixPath; switch(folderExistsAction) { case FolderExists_Merge: break; case FolderExists_Skip: return; break; case FolderExists_Rename: ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"destination before rename: "+destination.absoluteFilePath()); if(newName.isEmpty()) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"pattern: "+folder_isolation.pattern()); //resolv the new name destinationSuffixPath=destination.baseName(); int num=1; do { if(num==1) { if(firstRenamingRule.isEmpty()) destinationSuffixPath=tr("%1 - copy").arg(destination.baseName()); else { destinationSuffixPath=firstRenamingRule; destinationSuffixPath.replace(QStringLiteral("%name%"),destination.baseName()); } } else { if(otherRenamingRule.isEmpty()) destinationSuffixPath=tr("%1 - copy (%2)").arg(destination.baseName()).arg(num); else { destinationSuffixPath=otherRenamingRule; destinationSuffixPath.replace(QStringLiteral("%name%"),destination.baseName()); destinationSuffixPath.replace(QStringLiteral("%number%"),QString::number(num)); } } num++; if(destination.completeSuffix().isEmpty()) destination.setFile(destination.absolutePath()+text_slash+destinationSuffixPath); else destination.setFile(destination.absolutePath()+text_slash+destinationSuffixPath+text_dot+destination.completeSuffix()); } while(destination.exists()); } else { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"use new name: "+newName); destinationSuffixPath = newName; } destination.setFile(destination.absolutePath()+text_slash+destinationSuffixPath); ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"destination after rename: "+destination.absoluteFilePath()); break; default: return; break; } } //check if destination exists if(checkDestinationExists) { if(destination.exists()) { emit folderAlreadyExists(source,destination,false); waitOneAction.acquire(); QString destinationSuffixPath; switch(folderExistsAction) { case FolderExists_Merge: break; case FolderExists_Skip: return; break; case FolderExists_Rename: ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"destination before rename: "+destination.absoluteFilePath()); if(newName.isEmpty()) { //resolv the new name QFileInfo destinationInfo; int num=1; do { if(num==1) { if(firstRenamingRule.isEmpty()) destinationSuffixPath=tr("%1 - copy").arg(destination.baseName()); else { destinationSuffixPath=firstRenamingRule; destinationSuffixPath.replace(QStringLiteral("%name%"),destination.baseName()); } } else { if(otherRenamingRule.isEmpty()) destinationSuffixPath=tr("%1 - copy (%2)").arg(destination.baseName()).arg(num); else { destinationSuffixPath=otherRenamingRule; destinationSuffixPath.replace(QStringLiteral("%name%"),destination.baseName()); destinationSuffixPath.replace(QStringLiteral("%number%"),QString::number(num)); } } destinationInfo.setFile(destinationInfo.absolutePath()+text_slash+destinationSuffixPath); num++; } while(destinationInfo.exists()); } else { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"use new name: "+newName); destinationSuffixPath = newName; } if(destination.completeSuffix().isEmpty()) destination.setFile(destination.absolutePath()+text_slash+destinationSuffixPath); else destination.setFile(destination.absolutePath()+text_slash+destinationSuffixPath+QStringLiteral(".")+destination.completeSuffix()); ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"destination after rename: "+destination.absoluteFilePath()); break; default: return; break; } } } //do source check //check of source is readable do { fileErrorAction=FileError_NotSet; if(!source.isReadable() || !source.isExecutable() || !source.exists() || !source.isDir()) { if(!source.isDir()) emit errorOnFolder(source,tr("This is not a folder")); else if(!source.exists()) emit errorOnFolder(source,tr("The folder does exists")); else emit errorOnFolder(source,tr("The folder is not readable")); waitOneAction.acquire(); ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"actionNum: "+QString::number(fileErrorAction)); } } while(fileErrorAction==FileError_Retry); do { QDir tempDir(source.absoluteFilePath()); fileErrorAction=FileError_NotSet; if(!tempDir.isReadable() || !tempDir.exists()) { emit errorOnFolder(source,tr("Problem with name encoding")); waitOneAction.acquire(); ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"actionNum: "+QString::number(fileErrorAction)); } } while(fileErrorAction==FileError_Retry); if(stopIt) return; /// \todo check here if the folder is not readable or not exists QFileInfoList entryList=QDir(source.absoluteFilePath()).entryInfoList(QDir::AllEntries|QDir::NoDotAndDotDot|QDir::Hidden|QDir::System,QDir::DirsFirst|QDir::Name|QDir::IgnoreCase);//possible wait time here if(stopIt) return; int sizeEntryList=entryList.size(); emit newFolderListing(source.absoluteFilePath()); if(mode!=Ultracopier::Move) emit addToMkPath(source,destination,sizeEntryList); for (int index=0;index<sizeEntryList;++index) { QFileInfo fileInfo=entryList.at(index); if(stopIt) return; if(haveFilters) { if(reloadTheNewFilters) { QMutexLocker lock(&filtersMutex); QCoreApplication::processEvents(QEventLoop::AllEvents); reloadTheNewFilters=false; this->include=this->include_send; this->exclude=this->exclude_send; } QString fileName=fileInfo.fileName(); if(fileInfo.isDir() && !fileInfo.isSymLink()) { bool excluded=false,included=(include.size()==0); int filters_index=0; while(filters_index<exclude.size()) { if(exclude.at(filters_index).apply_on==ApplyOn_folder || exclude.at(filters_index).apply_on==ApplyOn_fileAndFolder) { if(fileName.contains(exclude.at(filters_index).regex)) { excluded=true; break; } } filters_index++; } if(excluded) {} else { filters_index=0; while(filters_index<include.size()) { if(include.at(filters_index).apply_on==ApplyOn_folder || include.at(filters_index).apply_on==ApplyOn_fileAndFolder) { if(fileName.contains(include.at(filters_index).regex)) { included=true; break; } } filters_index++; } if(!included) {} else listFolder(fileInfo,destination.absoluteFilePath()+text_slash+fileInfo.fileName()); } } else { bool excluded=false,included=(include.size()==0); int filters_index=0; while(filters_index<exclude.size()) { if(exclude.at(filters_index).apply_on==ApplyOn_file || exclude.at(filters_index).apply_on==ApplyOn_fileAndFolder) { if(fileName.contains(exclude.at(filters_index).regex)) { excluded=true; break; } } filters_index++; } if(excluded) {} else { filters_index=0; while(filters_index<include.size()) { if(include.at(filters_index).apply_on==ApplyOn_file || include.at(filters_index).apply_on==ApplyOn_fileAndFolder) { if(fileName.contains(include.at(filters_index).regex)) { included=true; break; } } filters_index++; } if(!included) {} else emit fileTransfer(fileInfo,destination.absoluteFilePath()+text_slash+fileInfo.fileName(),mode); } } } else { if(fileInfo.isDir() && !fileInfo.isSymLink())//possible wait time here //listFolder(source,destination,suffixPath+fileInfo.fileName()+QDir::separator()); listFolder(fileInfo,destination.absoluteFilePath()+text_slash+fileInfo.fileName());//put unix separator because it's transformed into that's under windows too else emit fileTransfer(fileInfo,destination.absoluteFilePath()+text_slash+fileInfo.fileName(),mode); } } if(mode==Ultracopier::Move) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"source: "+source.absoluteFilePath()+", sizeEntryList: "+QString::number(sizeEntryList)); emit addToMovePath(source,destination,sizeEntryList); } }
void MegaUploader::upload(QFileInfo info, MegaNode *parent) { QApplication::processEvents(); MegaNodeList *children = megaApi->getChildren(parent); QByteArray utf8name = info.fileName().toUtf8(); QString currentPath = QDir::toNativeSeparators(info.absoluteFilePath()); MegaNode *dupplicate = NULL; for (int i = 0; i < children->size(); i++) { MegaNode *child = children->get(i); if (!strcmp(utf8name.constData(), child->getName()) && ((info.isDir() && (child->getType() == MegaNode::TYPE_FOLDER)) || (info.isFile() && (child->getType() == MegaNode::TYPE_FILE) && (info.size() == child->getSize())))) { dupplicate = child->copy(); break; } } delete children; if (dupplicate) { if (dupplicate->getType() == MegaNode::TYPE_FILE) { emit dupplicateUpload(info.absoluteFilePath(), info.fileName(), dupplicate->getHandle()); } if (dupplicate->getType() == MegaNode::TYPE_FOLDER) { QDir dir(info.absoluteFilePath()); QFileInfoList entries = dir.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot); for (int i = 0; i < entries.size(); i++) { upload(entries[i], dupplicate); } } delete dupplicate; return; } string localPath = megaApi->getLocalPath(parent); if (localPath.size() && megaApi->isSyncable(info.fileName().toUtf8().constData())) { #ifdef WIN32 QString destPath = QDir::toNativeSeparators(QString::fromWCharArray((const wchar_t *)localPath.data()) + QDir::separator() + info.fileName()); if (destPath.startsWith(QString::fromAscii("\\\\?\\"))) { destPath = destPath.mid(4); } #else QString destPath = QDir::toNativeSeparators(QString::fromUtf8(localPath.data()) + QDir::separator() + info.fileName()); #endif megaApi->moveToLocalDebris(destPath.toUtf8().constData()); QtConcurrent::run(Utilities::copyRecursively, currentPath, destPath); } else if (info.isFile()) { megaApi->startUpload(currentPath.toUtf8().constData(), parent); } else if (info.isDir()) { folders.enqueue(info); megaApi->createFolder(info.fileName().toUtf8().constData(), parent, delegateListener); } }
QFileInfo ScanFileOrFolder::resolvDestination(const QFileInfo &destination) { QFileInfo newDestination=destination; while(newDestination.isSymLink()) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("resolv destination to: %1").arg(newDestination.symLinkTarget())); if(QFileInfo(newDestination.symLinkTarget()).isAbsolute()) newDestination.setFile(newDestination.symLinkTarget()); else newDestination.setFile(newDestination.absolutePath()+text_slash+newDestination.symLinkTarget()); } do { fileErrorAction=FileError_NotSet; if(isBlackListed(destination)) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,QStringLiteral("isBlackListed: %1").arg(destination.absoluteFilePath())); emit errorOnFolder(destination,tr("Blacklisted folder"),ErrorType_Folder); waitOneAction.acquire(); ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"actionNum: "+QString::number(fileErrorAction)); } } while(fileErrorAction==FileError_Retry || fileErrorAction==FileError_PutToEndOfTheList); return newDestination; }
qint64 RCCFileInfo::writeDataBlob(RCCResourceLibrary &lib, qint64 offset, QString *errorMessage) { const bool text = (lib.m_format == RCCResourceLibrary::C_Code || lib.m_format == RCCResourceLibrary::Go_Code); //capture the offset m_dataOffset = offset; //find the data to be written QFile file(m_fileInfo.absoluteFilePath()); if (!file.open(QFile::ReadOnly)) { *errorMessage = msgOpenReadFailed(m_fileInfo.absoluteFilePath(), file.errorString()); return 0; } QByteArray data = file.readAll(); #ifndef QT_NO_COMPRESS // Check if compression is useful for this file if (m_compressLevel != 0 && data.size() != 0) { QByteArray compressed = qCompress(reinterpret_cast<uchar *>(data.data()), data.size(), m_compressLevel); int compressRatio = int(100.0 * (data.size() - compressed.size()) / data.size()); if (compressRatio >= m_compressThreshold) { data = compressed; m_flags |= Compressed; } } #endif // QT_NO_COMPRESS // some info if (text) { lib.writeString(" // "); lib.writeByteArray(m_fileInfo.absoluteFilePath().toLocal8Bit()); lib.writeString("\n "); } // write the length lib.writeNumber4(data.size()); if (text) lib.writeString("\n "); offset += 4; // write the payload const char *p = data.constData(); if (text) { for (int i = data.size(), j = 0; --i >= 0; --j) { lib.writeHex(*p++); if (j == 0) { lib.writeString("\n "); j = 16; } } } else { for (int i = data.size(); --i >= 0; ) lib.writeChar(*p++); } offset += data.size(); // done if (text) lib.writeString("\n "); return offset; }
// ------------------------------------------------------- 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; }
QString MaidFacade::getCapturedFileName(const QFileInfo& saveFile) { //if (!viewport) // return saveFile.fileName(); qDebug() << "saving captured image..."; //DkImageLoader* loader = viewport->getImageLoader(); QString selectedFilter; QString saveName; saveName = saveFile.fileName(); int filterIdx = -1; // do not use the nomacs saveFilters here, the file format is already set QStringList sF; sF.append("Nikon (*.nef)"); sF.append("JPEG (*.jpg *.jpeg)"); //qDebug() << sF; QRegExp exp = QRegExp("*." + saveFile.suffix() + "*", Qt::CaseInsensitive); exp.setPatternSyntax(QRegExp::Wildcard); //qDebug() << "exp: " << exp; for (int idx = 0; idx < sF.size(); idx++) { if (exp.exactMatch(sF.at(idx))) { selectedFilter = sF.at(idx); filterIdx = idx; break; } } if (filterIdx == -1) saveName.remove("." + saveFile.suffix()); QString fileName; //int answer = QDialog::Rejected; //if (!selectedFilter.isEmpty() && viewport()->getImageLoader()->isEdited()) { // fileName = loader->getCurrentImage()->file().absoluteFilePath(); // DkMessageBox* msg = new DkMessageBox(QMessageBox::Question, tr("Overwrite File"), // tr("Do you want to overwrite:\n%1?").arg(fileName), // (QMessageBox::Yes | QMessageBox::No), this); // msg->setObjectName("overwriteDialog"); // //msg->show(); // answer = msg->exec(); //} //if (answer == QDialog::Rejected || answer == QMessageBox::No) { // note: basename removes the whole file name from the first dot... if (firstFilename.isEmpty() || !autoSaveNaming) { QString savePath = (!selectedFilter.isEmpty()) ? saveFile.absoluteFilePath() : QFileInfo(saveFile.absoluteDir(), saveName).absoluteFilePath(); // TODO: set the main window here... fileName = QFileDialog::getSaveFileName(dialogParent, tr("Save File %1").arg(saveName), savePath, selectedFilter, &selectedFilter); } return fileName; }