本文整理汇总了C++中QFileInfo::exists方法的典型用法代码示例。如果您正苦于以下问题:C++ QFileInfo::exists方法的具体用法?C++ QFileInfo::exists怎么用?C++ QFileInfo::exists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QFileInfo
的用法示例。
在下文中一共展示了QFileInfo::exists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: start
void DataInput::start()
{
QNetworkRequest nr;
QString url;
//qDebug() << "DataInput:start:"<<type<<":"<<input->arg1();
if( type == "ifttt" ) {
// url = "http://api.thingm.com/blink1/eventsall/" + iftttKey;
url = "http://feed.thingm.com/blink1/eventsall/" + iftttKey;
//url = "http://localhost:3232/blink1/eventsall/" + iftttKey;
nr.setUrl(QUrl(url));
reply = networkManager->get(nr);
connect(reply, SIGNAL(finished()), this, SLOT(onFinished()));
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onError()));
}
else if( type == "url" ) {
url = input->arg1();
//qDebug() << "datainput:start url: "<<url;
if(!url.startsWith("http://") && !url.startsWith("https://"))
url="http://"+url;
QUrl correctUrl(url);
if(correctUrl.isValid()) {
nr.setUrl(QUrl(url));
reply = networkManager->get(nr);
connect(reply, SIGNAL(finished()), this, SLOT(onFinished()));
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onError()));
}
else {
input->setArg2("Bad URL");
input->setDate(-1); // FIXME: don't like -1 here
emit toDelete(this);
}
}
else if( type == "file" ) {
QFileInfo fileInfo;
fileInfo.setFile(input->arg1());
if( !fileInfo.exists() ) {
qDebug() << "datainput:start: no file";
input->setArg2("Not Found");
input->setDate(-1);
}
else {
int lastModTime = fileInfo.lastModified().toTime_t(); // why was cast to uint?
if( lastModTime > input->date()) {
qDebug() << "datainput:start: file newer";
QFile f(input->arg1());
if(!f.open(QIODevice::ReadOnly | QIODevice::Text)) {
input->setArg2("Couldn't Open");
input->setDate(-1); // FIXME: why -1? what does it mean?
emit toDelete(this);
return;
}
input->setDate( lastModTime); //fileInfo.lastModified().toTime_t());
QString txt = "";
QTextStream in(&f);
txt.append(in.readAll());
bool good = parsePatternOrColor( txt, type, lastModTime );
if( !good ) {
input->setArg2("Bad Parse");
}
} // last modified
else {
//input->setArg2("Old File"); // FIXME: should do something to indicate older file
//input->setDate(-1);
}
}
emit toDelete(this);
}
else if( type == "script" ) {
//QString path = QStandardPaths::locate(QStandardPaths::DocumentsLocation, input->arg1());
QFileInfo fileInfo;
fileInfo.setFile( input->arg1() );
if( !fileInfo.exists() ) {
input->setArg2("Not Found");
input->setDate(-1);
emit toDelete(this);
}
else if( !fileInfo.isExecutable() ) {
input->setArg2("Not Executable");
input->setDate(-1);
emit toDelete(this);
}
else {
// FIXME: should check new value compare to lastVal
// (and FIXME: need to refactor to properly use lastVal for all monitor types)
//if(fileInfo.lastModified().toTime_t() != (uint)input->date()){
// no, don't do lastModTime check on exec file, jeez
input->setDate(fileInfo.lastModified().toTime_t());
process = new QProcess;
connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(onProcessOutput()));
connect(process, SIGNAL(readyReadStandardError()), this, SLOT(onError()));
connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(onError()));
connect(process, SIGNAL(finished(int)), this, SLOT(onProcessFinished()));
// start process running
process->start( fileInfo.canonicalFilePath() );
}
}
示例2: loadSession
void loadSession(DocEngine* docEngine, TopEditorContainer* editorContainer, QString sessionPath)
{
QFile file(sessionPath);
file.open(QIODevice::ReadOnly);
if (!file.isOpen())
return;
SessionReader reader(file);
bool success = false;
const auto& views = reader.readData(&success);
if (!success || views.empty()) {
return;
}
int viewCounter = 0;
for (const auto& view : views) {
// Each new view must be created if it does not yet exist.
EditorTabWidget* tabW = editorContainer->tabWidget(viewCounter);
int activeIndex = 0;
if (!tabW)
tabW = editorContainer->addTabWidget();
viewCounter++;
for (const TabData& tab : view.tabs) {
const QFileInfo fileInfo(tab.filePath);
const bool fileExists = fileInfo.exists();
const bool cacheFileExists = QFileInfo(tab.cacheFilePath).exists();
const QUrl fileUrl = QUrl::fromLocalFile(tab.filePath);
const QUrl cacheFileUrl = QUrl::fromLocalFile(tab.cacheFilePath);
// This is the file to load the document from
const QUrl& loadUrl = cacheFileExists ? cacheFileUrl : fileUrl;
const bool success = docEngine->loadDocumentSilent(loadUrl, tabW);
if (!success)
continue;
int idx = tabW->findOpenEditorByUrl(loadUrl);
if (idx == -1)
continue;
// DocEngine sets the editor's fileName to loadUrl since this is where the file
// was loaded from. Since loadUrl could point to a cached file we reset it here.
Editor* editor = tabW->editor(idx);
if (cacheFileExists) {
editor->markDirty();
editor->setLanguageFromFileName();
// Since we loaded from cache we want to unmonitor the cache file.
docEngine->unmonitorDocument(editor);
}
if (fileExists) {
editor->setFileName(fileUrl);
docEngine->monitorDocument(editor);
} else {
editor->setFileName(QUrl());
tabW->setTabText(idx, docEngine->getNewDocumentName());
}
// If we're loading an existing file from cache we want to inform the user whether
// the file has changed since Nqq was last closed. For this we can compare the
// file's last modification date.
if (fileExists && cacheFileExists && tab.lastModified != 0) {
auto lastModified = fileInfo.lastModified().toMSecsSinceEpoch();
if (lastModified > tab.lastModified) {
editor->setFileOnDiskChanged(true);
}
}
// If the orig. file does not exist but *should* exist, we inform the user of its removal.
if (!fileExists && !fileUrl.isEmpty()) {
editor->setFileOnDiskChanged(true);
emit docEngine->fileOnDiskChanged(tabW, idx, true);
}
if(tab.active) activeIndex = idx;
if(!tab.language.isEmpty()) editor->setLanguage(tab.language);
editor->setScrollPosition(tab.scrollX, tab.scrollY);
editor->clearFocus();
} // end for
tabW->clearFocus();
// In case a new tabwidget was created but no tabs were actually added to it,
// we'll attempt to re-use the widget for the next view.
if (tabW->count() == 0)
//.........这里部分代码省略.........
示例3: procesFile
void dibSHP::procesFile(Document_Interface *doc)
{
int num_ent, st;
double min_bound[4], max_bound[4];
currDoc = doc;
QFileInfo fi = QFileInfo(fileedit->text());
if (fi.suffix() != "shp") {
QMessageBox::critical ( this, "Shapefile", QString(tr("The file %1 not have extension .shp")).arg(fileedit->text()) );
return;
}
if (!fi.exists() ) {
QMessageBox::critical ( this, "Shapefile", QString(tr("The file %1 not exist")).arg(fileedit->text()) );
return;
}
QString file = fi.canonicalFilePath ();
SHPHandle sh = SHPOpen( file.toLocal8Bit(), "rb" );
SHPGetInfo( sh, &num_ent, &st, min_bound, max_bound );
DBFHandle dh = DBFOpen( file.toLocal8Bit(), "rb" );
if (radiolay1->isChecked()) {
layerF = -1;
attdata.layer = currDoc->getCurrentLayer();
} else {
layerF = DBFGetFieldIndex( dh, (layerdata->currentText()).toLatin1().data() );
layerT = DBFGetFieldInfo( dh, layerF, NULL, NULL, NULL );
}
if (radiocol1->isChecked())
colorF = -1;
else {
colorF = DBFGetFieldIndex( dh, (colordata->currentText()).toLatin1().data() );
colorT = DBFGetFieldInfo( dh, colorF, NULL, NULL, NULL );
}
if (radioltype1->isChecked())
ltypeF = -1;
else {
ltypeF = DBFGetFieldIndex( dh, (ltypedata->currentText()).toLatin1().data() );
ltypeT = DBFGetFieldInfo( dh, ltypeF, NULL, NULL, NULL );
}
if (radiolwidth1->isChecked())
lwidthF = -1;
else {
lwidthF = DBFGetFieldIndex( dh, (lwidthdata->currentText()).toLatin1().data() );
lwidthT = DBFGetFieldInfo( dh, lwidthF, NULL, NULL, NULL );
}
if (radiopoint1->isChecked())
pointF = -1;
else {
pointF = DBFGetFieldIndex( dh, (pointdata->currentText()).toLatin1().data() );
pointT = DBFGetFieldInfo( dh, pointF, NULL, NULL, NULL );
}
currlayer =currDoc->getCurrentLayer();
for( int i = 0; i < num_ent; i++ ) {
sobject= NULL;
sobject = SHPReadObject( sh, i );
if (sobject) {
switch (sobject->nSHPType) {
case SHPT_NULL:
break;
case SHPT_POINT:
case SHPT_POINTM: //2d point with measure
case SHPT_POINTZ: //3d point
readPoint(dh, i);
break;
case SHPT_MULTIPOINT:
case SHPT_MULTIPOINTM:
case SHPT_MULTIPOINTZ:
break;
case SHPT_ARC:
case SHPT_ARCM:
case SHPT_ARCZ:
readPolyline(dh, i);
break;
case SHPT_POLYGON:
case SHPT_POLYGONM:
case SHPT_POLYGONZ:
readPolylineC(dh, i);
case SHPT_MULTIPATCH:
readMultiPolyline(dh, i);
default:
break;
}
SHPDestroyObject(sobject);
}
}
SHPClose( sh );
DBFClose( dh );
currDoc->setLayer(currlayer);
}
示例4: init
bool QgsServer::init()
{
if ( sInitialized )
{
return false;
}
QCoreApplication::setOrganizationName( QgsApplication::QGIS_ORGANIZATION_NAME );
QCoreApplication::setOrganizationDomain( QgsApplication::QGIS_ORGANIZATION_DOMAIN );
QCoreApplication::setApplicationName( QgsApplication::QGIS_APPLICATION_NAME );
QgsApplication::init();
#if defined(SERVER_SKIP_ECW)
QgsMessageLog::logMessage( "Skipping GDAL ECW drivers in server.", "Server", Qgis::Info );
QgsApplication::skipGdalDriver( "ECW" );
QgsApplication::skipGdalDriver( "JP2ECW" );
#endif
// reload settings to take into account QCoreApplication and QgsApplication
// configuration
sSettings.load();
// init and configure logger
QgsServerLogger::instance();
QgsServerLogger::instance()->setLogLevel( sSettings.logLevel() );
if ( ! sSettings.logFile().isEmpty() )
{
QgsServerLogger::instance()->setLogFile( sSettings.logFile() );
}
else if ( sSettings.logStderr() )
{
QgsServerLogger::instance()->setLogStderr();
}
// log settings currently used
sSettings.logSummary();
setupNetworkAccessManager();
QDomImplementation::setInvalidDataPolicy( QDomImplementation::DropInvalidChars );
// Instantiate the plugin directory so that providers are loaded
QgsProviderRegistry::instance( QgsApplication::pluginPath() );
QgsMessageLog::logMessage( "Prefix PATH: " + QgsApplication::prefixPath(), QStringLiteral( "Server" ), Qgis::Info );
QgsMessageLog::logMessage( "Plugin PATH: " + QgsApplication::pluginPath(), QStringLiteral( "Server" ), Qgis::Info );
QgsMessageLog::logMessage( "PkgData PATH: " + QgsApplication::pkgDataPath(), QStringLiteral( "Server" ), Qgis::Info );
QgsMessageLog::logMessage( "User DB PATH: " + QgsApplication::qgisUserDatabaseFilePath(), QStringLiteral( "Server" ), Qgis::Info );
QgsMessageLog::logMessage( "Auth DB PATH: " + QgsApplication::qgisAuthDatabaseFilePath(), QStringLiteral( "Server" ), Qgis::Info );
QgsMessageLog::logMessage( "SVG PATHS: " + QgsApplication::svgPaths().join( QDir::separator() ), QStringLiteral( "Server" ), Qgis::Info );
QgsApplication::createDatabase(); //init qgis.db (e.g. necessary for user crs)
// Initialize the authentication system
// creates or uses qgis-auth.db in ~/.qgis3/ or directory defined by QGIS_AUTH_DB_DIR_PATH env variable
// set the master password as first line of file defined by QGIS_AUTH_PASSWORD_FILE env variable
// (QGIS_AUTH_PASSWORD_FILE variable removed from environment after accessing)
QgsApplication::authManager()->init( QgsApplication::pluginPath(), QgsApplication::qgisAuthDatabaseFilePath() );
QString defaultConfigFilePath;
QFileInfo projectFileInfo = defaultProjectFile(); //try to find a .qgs/.qgz file in the server directory
if ( projectFileInfo.exists() )
{
defaultConfigFilePath = projectFileInfo.absoluteFilePath();
QgsMessageLog::logMessage( "Using default project file: " + defaultConfigFilePath, QStringLiteral( "Server" ), Qgis::Info );
}
else
{
QFileInfo adminSLDFileInfo = defaultAdminSLD();
if ( adminSLDFileInfo.exists() )
{
defaultConfigFilePath = adminSLDFileInfo.absoluteFilePath();
}
}
// Store the config file path
sConfigFilePath = new QString( defaultConfigFilePath );
//create cache for capabilities XML
sCapabilitiesCache = new QgsCapabilitiesCache();
#ifdef ENABLE_MS_TESTS
QgsFontUtils::loadStandardTestFonts( QStringList() << QStringLiteral( "Roman" ) << QStringLiteral( "Bold" ) );
#endif
sServiceRegistry = new QgsServiceRegistry();
sServerInterface = new QgsServerInterfaceImpl( sCapabilitiesCache, sServiceRegistry, &sSettings );
// Load service module
QString modulePath = QgsApplication::libexecPath() + "server";
qDebug() << "Initializing server modules from " << modulePath << endl;
sServiceRegistry->init( modulePath, sServerInterface );
sInitialized = true;
QgsMessageLog::logMessage( QStringLiteral( "Server initialized" ), QStringLiteral( "Server" ), Qgis::Info );
return true;
}
示例5: QTextDocument
StrainPipeData::StrainPipeData(const QFileInfo &directory)
: QTextDocument(), directory(directory), base_dir(directory.absoluteFilePath())
{
if (directory.exists()) init();
}
示例6: matchesFilters
bool QFileSystemIteratorPrivate::matchesFilters(const QAbstractFileEngineIterator *it) const
{
const bool filterPermissions = ((filters & QDir::PermissionMask)
&& (filters & QDir::PermissionMask) != QDir::PermissionMask);
const bool skipDirs = !(filters & (QDir::Dirs | QDir::AllDirs));
const bool skipFiles = !(filters & QDir::Files);
const bool skipSymlinks = (filters & QDir::NoSymLinks);
const bool doReadable = !filterPermissions || (filters & QDir::Readable);
const bool doWritable = !filterPermissions || (filters & QDir::Writable);
const bool doExecutable = !filterPermissions || (filters & QDir::Executable);
const bool includeHidden = (filters & QDir::Hidden);
const bool includeSystem = (filters & QDir::System);
#ifndef QT_NO_REGEXP
// Prepare name filters
QList<QRegExp> regexps;
bool hasNameFilters = !nameFilters.isEmpty() && !(nameFilters.contains(QLatin1String("*")));
if (hasNameFilters) {
for (int i = 0; i < nameFilters.size(); ++i) {
regexps << QRegExp(nameFilters.at(i),
(filters & QDir::CaseSensitive) ? Qt::CaseSensitive : Qt::CaseInsensitive,
QRegExp::Wildcard);
}
}
#endif
QString fileName = it->currentFileName();
if (fileName.isEmpty()) {
// invalid entry
return false;
}
QFileInfo fi = it->currentFileInfo();
QString filePath = it->currentFilePath();
#ifndef QT_NO_REGEXP
// Pass all entries through name filters, except dirs if the AllDirs
// filter is passed.
if (hasNameFilters && !((filters & QDir::AllDirs) && fi.isDir())) {
bool matched = false;
for (int i = 0; i < regexps.size(); ++i) {
if (regexps.at(i).exactMatch(fileName)) {
matched = true;
break;
}
}
if (!matched)
return false;
}
#endif
bool dotOrDotDot = (fileName == QLatin1String(".") || fileName == QLatin1String(".."));
if ((filters & QDir::NoDotAndDotDot) && dotOrDotDot)
return false;
bool isHidden = !dotOrDotDot && fi.isHidden();
if (!includeHidden && isHidden)
return false;
bool isSystem = (!fi.isFile() && !fi.isDir() && !fi.isSymLink())
|| (!fi.exists() && fi.isSymLink());
if (!includeSystem && isSystem)
return false;
bool alwaysShow = (filters & QDir::TypeMask) == 0
&& ((isHidden && includeHidden)
|| (includeSystem && isSystem));
// Skip files and directories
if ((filters & QDir::AllDirs) == 0 && skipDirs && fi.isDir()) {
if (!alwaysShow)
return false;
}
if ((skipFiles && (fi.isFile() || !fi.exists()))
|| (skipSymlinks && fi.isSymLink())) {
if (!alwaysShow)
return false;
}
if (filterPermissions
&& ((doReadable && !fi.isReadable())
|| (doWritable && !fi.isWritable())
|| (doExecutable && !fi.isExecutable()))) {
return false;
}
if (!includeSystem && !dotOrDotDot && ((fi.exists() && !fi.isFile() && !fi.isDir() && !fi.isSymLink())
|| (!fi.exists() && fi.isSymLink()))) {
return false;
}
return true;
}
示例7: SaveBaseData
//.........这里部分代码省略.........
// get from combobox selected file extension
extension = itksys::SystemTools::GetFilenameLastExtension( selected_suffix.toLocal8Bit().constData());
extension = extension.substr(0, extension.size()-1);
qfileName += QString::fromStdString(extension);
}
MITK_INFO<<"extension: " << extension;
// check if extension is valid
if (!writer->IsExtensionValid(extension))
{
QString message;
message.append("File extension not suitable for writing point set data. Choose one extension of this list: ");
message.append(writer->GetPossibleFileExtensionsAsString().c_str());
QMessageBox::critical(NULL,"ERROR",message);
return;
}
if (qfileName.isEmpty() == false )
{
writer->SetInput( pointset );
writer->SetFileName( qfileName.toLocal8Bit().constData() );
writer->Update();
fileNameUsed = writer->GetFileName();
writingSuccessful = true;
} else {
return;
}
}
if(!writingSuccessful)
{
mitk::Surface::Pointer surface = dynamic_cast<mitk::Surface*>(data);
if(surface.IsNotNull())
{
fileNameUsed = CommonFunctionality::SaveSurface(surface, aFileName);
if(!(fileNameUsed.length()>0)){
return;
} else {
writingSuccessful = true;
}
}
if(!writingSuccessful)
{
// now try the file writers provided by the CoreObjectFactory
mitk::CoreObjectFactory::FileWriterList fileWriters = mitk::CoreObjectFactory::GetInstance()->GetFileWriters();
bool writerFound = false;
for (mitk::CoreObjectFactory::FileWriterList::iterator it = fileWriters.begin() ; it != fileWriters.end() ; ++it)
{
if ( (*it)->CanWriteBaseDataType(data) ) {
writerFound = true;
SaveToFileWriter(*it, data, NULL, aFileName);
fileNameUsed = (*it)->GetFileName();
// correct writer has been found->break
if(!(fileNameUsed.length()>0)){
return;
} else {
writingSuccessful = true;
break;
}
}
}
if(!writerFound)
{
// no appropriate writer has been found
QMessageBox::critical(NULL,"ERROR","Could not find file writer for this data type");
return;
}
}
}
}
} else {
QMessageBox::critical(NULL,"ERROR","Cannot write data (invalid/empty)");
return;
}
} catch(itk::ExceptionObject e)
{
QMessageBox::critical( NULL, "SaveDialog", e.GetDescription(),QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton);
}
//writing is assumed to have been successful
//check if file exists, file size >0 and last modified after this function was called
try{
QFileInfo* fileInfo = new QFileInfo(QString(fileNameUsed.c_str()));
if(!fileInfo->exists())
{
QMessageBox::warning(NULL,"WARNING","File was not created or was split into multiple files");
} else if(fileInfo->size()==0) {
QMessageBox::warning(NULL,"WARNING","File is empty");
} else if(fileInfo->lastModified()<initialTime) {
QMessageBox::warning(NULL,"WARNING","Save not successful. File was not updated (only old version available)");
}
delete fileInfo;
} catch(...) {
QMessageBox::critical(NULL,"ERROR","Save not successful. Possibly no writing permission.");
}
}
示例8: maxTime
FileErrorDialog::FileErrorDialog(QWidget *parent, QFileInfo fileInfo, std::string errorString, const ErrorType &errorType) :
QDialog(parent),
ui(new Ui::fileErrorDialog)
{
Qt::WindowFlags flags = windowFlags();
#ifdef Q_OS_LINUX
flags=flags & ~Qt::X11BypassWindowManagerHint;
#endif
flags=flags | Qt::WindowStaysOnTopHint;
setWindowFlags(flags);
ui->setupUi(this);
action=FileError_Cancel;
ui->label_error->setText(QString::fromStdString(errorString));
if(fileInfo.exists())
{
ui->label_content_file_name->setText(QString::fromStdString(TransferThread::resolvedName(fileInfo)));
if(ui->label_content_file_name->text().isEmpty())
{
ui->label_content_file_name->setText(fileInfo.absoluteFilePath());
ui->label_folder->setVisible(false);
ui->label_content_folder->setVisible(false);
}
else
{
QString folder=fileInfo.absolutePath();
if(folder.size()>80)
folder=folder.mid(0,38)+"..."+folder.mid(folder.size()-38);
ui->label_content_folder->setText(fileInfo.absolutePath());
}
ui->label_content_size->setText(QString::number(fileInfo.size()));
QDateTime maxTime(QDate(ULTRACOPIER_PLUGIN_MINIMALYEAR,1,1));
if(maxTime<fileInfo.lastModified())
{
ui->label_modified->setVisible(true);
ui->label_content_modified->setVisible(true);
ui->label_content_modified->setText(fileInfo.lastModified().toString());
}
else
{
ui->label_modified->setVisible(false);
ui->label_content_modified->setVisible(false);
}
if(fileInfo.isDir())
{
this->setWindowTitle(tr("Error on folder"));
ui->label_size->hide();
ui->label_content_size->hide();
ui->label_file_name->setText(tr("Folder name"));
}
ui->label_file_destination->setVisible(fileInfo.isSymLink());
ui->label_content_file_destination->setVisible(fileInfo.isSymLink());
if(fileInfo.isSymLink())
ui->label_content_file_destination->setText(fileInfo.symLinkTarget());
}
else
{
ui->label_content_file_name->setText(QString::fromStdString(TransferThread::resolvedName(fileInfo)));
if(ui->label_content_file_name->text().isEmpty())
{
ui->label_content_file_name->setText(fileInfo.absoluteFilePath());
ui->label_folder->setVisible(false);
ui->label_content_folder->setVisible(false);
}
else
ui->label_content_folder->setText(fileInfo.absolutePath());
ui->label_file_destination->hide();
ui->label_content_file_destination->hide();
ui->label_size->hide();
ui->label_content_size->hide();
ui->label_modified->hide();
ui->label_content_modified->hide();
}
if(errorType==ErrorType_Folder || errorType==ErrorType_FolderWithRety)
ui->PutToBottom->hide();
if(errorType==ErrorType_Folder)
ui->Retry->hide();
ui->Rights->hide();
#ifdef ULTRACOPIER_PLUGIN_RIGHTS
if(isInAdmin)
ui->Rights->hide();
#ifdef Q_OS_WIN32
if(errorType!=ErrorType_Rights)
ui->Rights->hide();
#else
ui->Rights->hide();
#endif
#else
ui->Rights->hide();
#endif
}
示例9: launch
void IanniXApp::launch(int &argc, char **argv) {
//Display splash
Application::splash = new UiSplashScreen(QPixmap(":/general/res_splash.png"));
//Start
setHelp();
QDir pathApplicationDir = QDir(QCoreApplication::applicationDirPath()).absolutePath();
#ifdef Q_OS_MAC
pathApplicationDir.cdUp();
pathApplicationDir.cdUp();
pathApplicationDir.cdUp();
#endif
#ifdef QT4
Application::pathDocuments = QFileInfo(QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation) + "/IanniX");
#else
Application::pathDocuments = QFileInfo(QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation).first() + "/IanniX");
#endif
Application::pathApplication = QFileInfo(pathApplicationDir.absolutePath());
Application::pathCurrent = QFileInfo(QDir::currentPath());
if((Application::pathApplication.absoluteFilePath().endsWith("/IanniX-build-64")) || (Application::pathApplication.absoluteFilePath().endsWith("/IanniX-build-32")))
Application::pathApplication = QFileInfo(Application::pathApplication.absoluteFilePath().remove("-build-64").remove("-build-32"));
if(Application::pathApplication.absoluteFilePath().endsWith("/IanniX-build/release"))
Application::pathApplication = QFileInfo(Application::pathApplication.absoluteFilePath().remove("-build/release"));
if(Application::pathApplication.absoluteFilePath().endsWith("/IanniX-build"))
Application::pathApplication = QFileInfo(Application::pathApplication.absoluteFilePath().remove("-build"));
qDebug("Pathes");
qDebug("\tDocuments : %s", qPrintable(Application::pathDocuments .absoluteFilePath()));
qDebug("\tApplication: %s", qPrintable(Application::pathApplication.absoluteFilePath()));
qDebug("\tCurrent : %s", qPrintable(Application::pathCurrent .absoluteFilePath()));
qDebug("Arguments");
for(quint16 i = 0 ; i < argc ; i++) {
qDebug("\t%2d=\t%s", i, argv[i]);
}
/*
if(Application::pathCurrent.absoluteFilePath().startsWith("/Users/Guillaume/Documents/buzzinglight/Projets/Coduys/IanniX/IanniX"))
generateHelp();
*/
QFileInfo file;
for(quint16 i = 0 ; i < argc ; i++) {
file = QFileInfo(argv[i]);
if((file.exists()) && (file.suffix().toLower().contains("iannix"))) {
project = file;
break;
}
file = QFileInfo(Application::pathCurrent.absoluteFilePath() + "/" + argv[i]);
if((file.exists()) && (file.suffix().toLower().contains("iannix"))) {
project = file;
break;
}
file = QFileInfo(Application::pathDocuments.absoluteFilePath() + "/" + argv[i]);
if((file.exists()) && (file.suffix().toLower().contains("iannix"))) {
project = file;
break;
}
}
//Add font
if(QFontDatabase::addApplicationFont(Application::pathApplication.absoluteFilePath() + "/Tools/Museo.ttf"))
qDebug("Loading IanniX font failed : %s", qPrintable(Application::pathApplication.absoluteFilePath() + "/Tools/Museo.ttf"));
//List of fonts
if(false) {
qDebug("[FONTS]");
QFontDatabase fontDb;
QStringList fontList = fontDb.families();
foreach(const QString &font, fontList) {
qDebug("\tFamille : %s", qPrintable(font));
if(true) {
qDebug("\t\tFont : %s", qPrintable(font));
QStringList styleList = fontDb.styles(font);
foreach(const QString &style, styleList) {
int weight = fontDb.weight(font, style);
qDebug("\t\t\t > Style / Graisse %s %d", qPrintable(style), weight);
}
示例10: loadSpawnPoints
void SpawnMonitor::loadSpawnPoints()
{
QString fileName;
fileName = m_zoneName + ".sp";
QFileInfo fileInfo =
m_dataLocMgr->findExistingFile("spawnpoints", fileName, false);
if (!fileInfo.exists())
{
seqWarn("Can't find spawn point file %s",
(const char*)fileInfo.absFilePath());
return;
}
fileName = fileInfo.absFilePath();
QFile spFile(fileName);
if (!spFile.open(IO_ReadOnly))
{
seqWarn( "Can't open spawn point file %s", (const char*)fileName );
return;
}
QTextStream input( &spFile );
int16_t x, y, z;
unsigned long diffTime;
uint32_t count;
QString name;
while (!input.atEnd())
{
input >> x;
input >> y;
input >> z;
input >> diffTime;
input >> count;
name = input.readLine();
name = name.stripWhiteSpace();
EQPoint loc(x, y, z);
SpawnPoint* p = new SpawnPoint( 0, loc, name, diffTime, count );
if (p)
{
QString key = p->key();
if (!m_points.find(key))
{
m_points.insert(key, p);
emit newSpawnPoint(p);
}
else
{
seqWarn("Warning: spawn point key already in use!");
delete p;
}
}
}
seqInfo("Loaded spawn points: %s", (const char*)fileName);
m_modified = false;
}
示例11: testFile
/*!
\fn int FileLoader::TestFile()
\author Franz Schmid
\date
\brief Tests if the file "FileName" exists and determines the type of the file.
\retval int -1 if the file doesn't exist or any other error has occurred, 0 for the old Format, 1 for the new Format, 2 for EPS and PS files, 3 for SVG files and 4 for PDF files
*/
int FileLoader::testFile()
{
QFileInfo fi = QFileInfo(m_fileName);
int ret = -1;
if (!fi.exists())
ret = -1;
QString ext = fi.completeSuffix().toLower();
bool found = false;
QList<FileFormat> fileFormats(LoadSavePlugin::supportedFormats());
QList<FileFormat>::const_iterator it(fileFormats.constBegin());
QList<FileFormat>::const_iterator itEnd(fileFormats.constEnd());
for ( ; it != itEnd ; ++it )
{
for (int a = 0; a < it->fileExtensions.count(); a++)
{
QString exts = it->fileExtensions[a].toLower();
if (ext == exts)
{
if (it->plug != 0)
{
if (it->plug->fileSupported(0, m_fileName))
{
ret = it->formatId;
found = true;
break;
}
}
}
}
if (found)
break;
}
if (!found)
{
// now try for the last suffix
ext = fi.suffix().toLower();
it = fileFormats.constBegin();
itEnd = fileFormats.constEnd();
for ( ; it != itEnd ; ++it )
{
bool found = false;
for (int a = 0; a < it->fileExtensions.count(); a++)
{
QString exts = it->fileExtensions[a].toLower();
if (ext == exts)
{
if (it->plug != 0)
{
if (it->plug->fileSupported(0, m_fileName))
{
ret = it->formatId;
found = true;
break;
}
}
}
}
if (found)
break;
}
}
m_fileType = ret;
return ret;
}
示例12: init
/**
* Server initialization
*/
bool QgsServer::init( int & argc, char ** argv )
{
if ( mInitialised )
{
return FALSE;
}
#ifndef _MSC_VER
qInstallMsgHandler( dummyMessageHandler );
#endif
QString optionsPath = getenv( "QGIS_OPTIONS_PATH" );
if ( !optionsPath.isEmpty() )
{
QgsDebugMsg( "Options PATH: " + optionsPath );
QSettings::setDefaultFormat( QSettings::IniFormat );
QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, optionsPath );
}
mQgsApplication = new QgsApplication( argc, argv, getenv( "DISPLAY" ) );
QCoreApplication::setOrganizationName( QgsApplication::QGIS_ORGANIZATION_NAME );
QCoreApplication::setOrganizationDomain( QgsApplication::QGIS_ORGANIZATION_DOMAIN );
QCoreApplication::setApplicationName( QgsApplication::QGIS_APPLICATION_NAME );
//Default prefix path may be altered by environment variable
QgsApplication::init();
#if !defined(Q_OS_WIN)
// init QGIS's paths - true means that all path will be inited from prefix
QgsApplication::setPrefixPath( CMAKE_INSTALL_PREFIX, TRUE );
#endif
#if defined(SERVER_SKIP_ECW)
QgsDebugMsg( "Skipping GDAL ECW drivers in server." );
QgsApplication::skipGdalDriver( "ECW" );
QgsApplication::skipGdalDriver( "JP2ECW" );
#endif
setupNetworkAccessManager();
QDomImplementation::setInvalidDataPolicy( QDomImplementation::DropInvalidChars );
// Instantiate the plugin directory so that providers are loaded
QgsProviderRegistry::instance( QgsApplication::pluginPath() );
QgsDebugMsg( "Prefix PATH: " + QgsApplication::prefixPath() );
QgsDebugMsg( "Plugin PATH: " + QgsApplication::pluginPath() );
QgsDebugMsg( "PkgData PATH: " + QgsApplication::pkgDataPath() );
QgsDebugMsg( "User DB PATH: " + QgsApplication::qgisUserDbFilePath() );
QgsDebugMsg( "SVG PATHS: " + QgsApplication::svgPaths().join( ":" ) );
QgsApplication::createDB(); //init qgis.db (e.g. necessary for user crs)
QString defaultConfigFilePath;
QFileInfo projectFileInfo = defaultProjectFile(); //try to find a .qgs file in the server directory
if ( projectFileInfo.exists() )
{
defaultConfigFilePath = projectFileInfo.absoluteFilePath();
QgsDebugMsg( "Using default project file: " + defaultConfigFilePath );
}
else
{
QFileInfo adminSLDFileInfo = defaultAdminSLD();
if ( adminSLDFileInfo.exists() )
{
defaultConfigFilePath = adminSLDFileInfo.absoluteFilePath();
}
}
//create cache for capabilities XML
mCapabilitiesCache = new QgsCapabilitiesCache();
mMapRenderer = new QgsMapRenderer;
mMapRenderer->setLabelingEngine( new QgsPalLabeling() );
#ifdef ENABLE_MS_TESTS
QgsFontUtils::loadStandardTestFonts( QStringList() << "Roman" << "Bold" );
#endif
#ifdef HAVE_SERVER_PYTHON_PLUGINS
mServerInterface = new QgsServerInterfaceImpl( mCapabilitiesCache );
if ( mInitPython )
{
// Init plugins
if ( ! QgsServerPlugins::initPlugins( mServerInterface ) )
{
QgsMessageLog::logMessage( "No server python plugins are available", "Server", QgsMessageLog::INFO );
}
else
{
QgsMessageLog::logMessage( "Server python plugins loaded", "Server", QgsMessageLog::INFO );
}
}
#endif
QgsServerLogger::instance();
QgsEditorWidgetRegistry::initEditors();
mInitialised = TRUE;
QgsMessageLog::logMessage( "Server intialised", "Server", QgsMessageLog::INFO );
return TRUE;
//.........这里部分代码省略.........
示例13: validateInputs
bool DownloadRepoDialog::validateInputs()
{
if (has_manual_merge_mode_ && manual_merge_mode_) {
return validateInputsManualMergeMode();
}
setDirectoryText(mDirectory->text().trimmed());
if (mDirectory->text().isEmpty()) {
QMessageBox::warning(this, getBrand(),
tr("Please choose the folder to sync."),
QMessageBox::Ok);
return false;
}
sync_with_existing_ = false;
alternative_path_ = QString();
QString path = QDir(mDirectory->text()).absoluteFilePath(repo_.name);
QFileInfo fileinfo = QFileInfo(path);
if (fileinfo.exists()) {
sync_with_existing_ = true;
// exist and but not a directory ?
if (!fileinfo.isDir()) {
QMessageBox::warning(this, getBrand(),
tr("Conflicting with existing file \"%1\", please choose a different folder.").arg(path),
QMessageBox::Ok);
return false;
}
// exist and but conflicting?
QString repo_name;
if (isPathConflictWithExistingRepo(path, &repo_name)) {
QMessageBox::warning(this, getBrand(),
tr("Conflicting with existing library \"%1\", please choose a different folder.").arg(repo_name),
QMessageBox::Ok);
return false;
}
int ret = QMessageBox::question(
this, getBrand(), tr("The folder \"%1\" already exists. Are you sure to sync with it (contents will be merged)?")
.arg(path) + QString("<br/><br/><small>%1</small>").arg(tr("Click No to sync with a new folder instead")),
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::Yes);
if (ret & QMessageBox::Cancel)
return false;
if (ret & QMessageBox::No) {
QString new_path = getAlternativePath(mDirectory->text(), repo_.name);
if (new_path.isEmpty()) {
QMessageBox::warning(this, getBrand(),
tr("Unable to find an alternative folder name").arg(path),
QMessageBox::Ok);
return false;
}
alternative_path_ = new_path;
}
}
if (repo_.encrypted) {
mPassword->setText(mPassword->text().trimmed());
if (mPassword->text().isEmpty()) {
QMessageBox::warning(this, getBrand(),
tr("Please enter the password"),
QMessageBox::Ok);
return false;
}
}
return true;
}
示例14: parseLogToFile
bool ProjectFileParser::parseLogToFile(const QDomElement &element, LogSettings *pLogSettings)
{
bool bRet = true;
// Check attribute
QString enabled = element.attribute(ProjectFileDefinitions::cEnabledAttribute, ProjectFileDefinitions::cTrueValue);
if (!enabled.toLower().compare(ProjectFileDefinitions::cTrueValue))
{
pLogSettings->bLogToFile = true;
}
else
{
pLogSettings->bLogToFile = false;
}
// Check nodes
QDomElement child = element.firstChildElement();
while (!child.isNull())
{
if (child.tagName() == ProjectFileDefinitions::cFilenameTag)
{
QFileInfo fileInfo = QFileInfo(child.text());
bool bValid = true;
/* check file path points to existing file */
if (!fileInfo.isFile())
{
/* Check if file path points to something else that already exists */
if (fileInfo.exists())
{
/* path exist, but it is not a file */
bValid = false;
_msgBox.setText(tr("Log file path (%1) already exists, but it is not a file. Log file is set to default.").arg(fileInfo.filePath()));
_msgBox.exec();
}
else
{
/* file path does not exist yet */
/* Does parent directory exist? */
if (!fileInfo.dir().exists())
{
bValid = false;
_msgBox.setText(tr("Log file path (parent directory) does not exists (%1). Log file is set to default.").arg(fileInfo.filePath()));
_msgBox.exec();
}
}
}
if (bValid)
{
pLogSettings->bLogToFileFile = true;
pLogSettings->logFile = fileInfo.filePath();
}
else
{
pLogSettings->bLogToFileFile = false;
}
}
else
{
// unkown tag: ignore
}
child = child.nextSiblingElement();
}
return bRet;
}
示例15: getLang
QStringList ScribusQApp::getLang(QString lang)
{
QStringList langs;
// read the locales
if (!lang.isEmpty())
langs.append(lang);
//add in user preferences lang, only overridden by lang command line option
QString Pff = QDir::toNativeSeparators(ScPaths::getApplicationDataDir());
QFileInfo Pffi = QFileInfo(Pff);
if (Pffi.exists())
{
QString PrefsPfad;
if (Pffi.isDir())
PrefsPfad = Pff;
else
PrefsPfad = QDir::homePath();
QString prefsXMLFile=QDir::toNativeSeparators(PrefsPfad + "/prefs150.xml");
QFileInfo infoPrefsFile(prefsXMLFile);
if (infoPrefsFile.exists())
{
PrefsFile* prefsFile = new PrefsFile(prefsXMLFile);
if (prefsFile)
{
PrefsContext* userprefsContext = prefsFile->getContext("user_preferences");
if (userprefsContext)
{
QString prefslang = userprefsContext->get("gui_language","");
if (!prefslang.isEmpty())
langs.append(prefslang);
}
}
delete prefsFile;
}
}
if (!(lang = ::getenv("LANG")).isEmpty())
{
if (lang=="C")
lang="en";
langs.append(lang);
}
if (!(lang = ::getenv("LC_MESSAGES")).isEmpty())
{
if (lang=="C")
lang="en";
langs.append(lang);
}
if (!(lang = ::getenv("LC_ALL")).isEmpty())
{
if (lang=="C")
lang="en";
langs.append(lang);
}
#if defined(_WIN32)
wchar_t out[256];
QString language, sublanguage;
LCID lcIdo = GetUserDefaultLCID();
WORD sortId = SORTIDFROMLCID(lcIdo);
LANGID langId = GetUserDefaultUILanguage();
LCID lcIdn = MAKELCID(langId, sortId);
if ( GetLocaleInfoW(lcIdn, LOCALE_SISO639LANGNAME , out, 255) )
{
language = QString::fromUtf16( (ushort*)out );
if ( GetLocaleInfoW(lcIdn, LOCALE_SISO3166CTRYNAME, out, 255) )
{
sublanguage = QString::fromUtf16( (ushort*)out ).toLower();
lang = language;
if ( sublanguage != language && !sublanguage.isEmpty() )
lang += "_" + sublanguage.toUpper();
langs.append(lang);
}
}
#endif
langs.append(QString(QLocale::system().name()));
// remove duplicate entries...
QStringList::Iterator it = langs.end();
while (it != langs.begin())
{
--it;
if (langs.count(*it) > 1)
it = langs.erase(it);
}
return langs;
}