示例#1
0
bool ejson::internal::Document::load(const std::string& _file) {
	// Start loading the XML : 
	EJSON_VERBOSE("open file (xml) \"" << _file << "\"");
	clear();
	etk::FSNode tmpFile(_file);
	if (false == tmpFile.exist()) {
		EJSON_ERROR("File Does not exist : " << _file);
		return false;
	}
	int64_t fileSize = tmpFile.fileSize();
	if (0 == fileSize) {
		EJSON_ERROR("This file is empty : " << _file);
		return false;
	}
	if (false == tmpFile.fileOpenRead()) {
		EJSON_ERROR("Can not open (r) the file : " << _file);
		return false;
	}
	// allocate data
	std::vector<char> fileBuffer;
	fileBuffer.resize(fileSize+5, 0);
	// load data from the file :
	tmpFile.fileRead(&fileBuffer[0], 1, fileSize);
	// close the file:
	tmpFile.fileClose();
	
	std::string tmpDataUnicode(&fileBuffer[0]);
	// parse the data :
	bool ret = parse(tmpDataUnicode);
	//Display();
	return ret;
}
示例#2
0
bool HelpViewer::launchedWithExternalApp(const QUrl &url)
{
    bool isPdf = url.path().endsWith(QLatin1String(".pdf"));
    if (url.scheme() == QLatin1String("http")
        || url.scheme() == QLatin1String("ftp")
        || url.scheme() == QLatin1String("mailto") || isPdf) {
        bool launched = false;
        if (isPdf && url.scheme() == QLatin1String("qthelp")) {
            const QString& path = url.path();
            const int lastDash = path.lastIndexOf(QChar('/'));
            QString fileName = QDir::tempPath() + QDir::separator();
            if (lastDash < 0)
                fileName += path;
            else
                fileName += path.mid(lastDash + 1, path.length());

            QFile tmpFile(QDir::cleanPath(fileName));
            if (tmpFile.open(QIODevice::ReadWrite)) {
                tmpFile.write(helpEngine->fileData(url));
                tmpFile.close();
            }
            launched = QDesktopServices::openUrl(QUrl(tmpFile.fileName()));
        } else {
            launched = QDesktopServices::openUrl(url);
        }

        if (!launched) {
            QMessageBox::information(this, tr("Help"),
                tr("Unable to launch external application.\n"), tr("OK"));
        }
        return true;
    }
    return false;
}
示例#3
0
////////////////////////////////////////////////////////////
/// Function definitions
////////////////////////////////////////////////////////////
void Logger::setFileLocation(const std::string& path)
{
    /////////////////////////////////////////
    // The following is a hack.
    // It's necessary because gcc won't support
    //      move semantics for streams until
    //      version 5
    /////////////////////////////////////////

    // Attempt to open new log file
    std::ofstream tmpFile(path);

    // Bail if file open failed
    if(!tmpFile)
    {
        logMessage("Logger couldn't set file location to ", path);
        return;
    }
    tmpFile.close();

    // On success, check if a log file is already open and close it
    if(file)
    {
        file.close();
    }

    // Set new log file
    file.open(path);
}
static bool removeDirectory(QString dirName)
{
    QDir dir(dirName);
    QString tmpdir ="";
    if(!dir.exists()){
        return false;
    }

    QFileInfoList fileInfoList = dir.entryInfoList();
    foreach(QFileInfo fileInfo, fileInfoList)
    {
        if(fileInfo.fileName()=="."|| fileInfo.fileName()=="..")
            continue;

        if(fileInfo.isDir()){
            tmpdir = dirName +("/")+ fileInfo.fileName();
            removeDirectory(tmpdir);
            dir.rmdir(fileInfo.fileName());/**< 移除子目录 */
        }
        else if(fileInfo.isFile()){
            QFile tmpFile(fileInfo.fileName());
            dir.remove(tmpFile.fileName());/**< 删除临时文件 */
        }
        else{
            ;
        }
    }

    dir.cdUp();            /**< 返回上级目录,因为只有返回上级目录,才可以删除这个目录 */
    if(dir.exists(dirName)){
        if(!dir.rmdir(dirName))
            return false;
    }
    return true;
}
示例#5
0
static BaseEngine *psgz2pdf(const WCHAR *fileName)
{
    ScopedMem<WCHAR> tmpFile(path::GetTempPath(L"PsE"));
    ScopedFile tmpFileScope(tmpFile);
    if (!tmpFile)
        return NULL;

    gzFile inFile = gzopen_w(fileName, "rb");
    if (!inFile)
        return NULL;
    FILE *outFile = NULL;
    errno_t err = _wfopen_s(&outFile, tmpFile, L"wb");
    if (err != 0 || !outFile) {
        gzclose(inFile);
        return NULL;
    }

    char buffer[12*1024];
    for (;;) {
        int len = gzread(inFile, buffer, sizeof(buffer));
        if (len <= 0)
            break;
        fwrite(buffer, 1, len, outFile);
    }
    fclose(outFile);
    gzclose(inFile);

    return ps2pdf(tmpFile);
}
GdbCoreEngine::~GdbCoreEngine()
{
    if (false && !m_tempCoreName.isEmpty()) {
        QFile tmpFile(m_tempCoreName);
        tmpFile.remove();
    }
}
示例#7
0
void PluginBase::writeTempFile( XMP_IORef srcFileRef, XMP_IORef tmpFileRef, XMP_StringPtr xmpStr )
{
	IOAdapter srcFile( srcFileRef );
	IOAdapter tmpFile( tmpFileRef );
	std::string buffer( xmpStr );

	this->writeTempFile( srcFile, tmpFile, buffer );
}
bool SubversionBackend::AppendText(const QString path, const QString text) {
    QString repoPath(path);
    QString fileName = QFileInfo(path).baseName();
    repoPath.replace(QRegExp("\\/[^\\/]+$"), "");
    QTemporaryFile tmpFile("changelogger");
    QString tmpPath;

    if (!tmpFile.open()) {
        return false;
    }
    tmpPath = tmpFile.fileName();
    tmpFile.remove();
    QDir(QDir::tempPath()).mkdir(tmpPath);
    tmpPath.prepend(QDir::separator());
    tmpPath.prepend(QDir::tempPath());

    if (QProcess::execute("svn", QStringList() << "co" << "--depth" << "files" << repoPath << tmpPath) != 0) {
        qDebug() << "Fehler beim auschecken nach: " << tmpPath;
        SubversionBackend::RecursiveRemove(tmpPath);
        return false;
    }

    qDebug() << "Checkout liegt in: " << tmpPath;
    qDebug() << "Filename ist: " << fileName;

    QString localChangeLogPath = tmpPath + QDir::separator() + fileName;
    QFile file(localChangeLogPath);
    if (!file.open(QFile::ReadOnly)) {
        qDebug() << localChangeLogPath + " kann nicht zum lesen geöffnet werden!";
        SubversionBackend::RecursiveRemove(tmpPath);
        return false;
    }
    QString oldContent = QString::fromUtf8(file.readAll());
    file.close();

    if (!file.open(QFile::WriteOnly | QFile::Truncate)) {
        qDebug() << localChangeLogPath + " kann nicht zum schreiben geöffnet werden!";
        SubversionBackend::RecursiveRemove(tmpPath);
        return false;
    }
    file.write(text.trimmed().toUtf8());
    file.write("\n\n");
    file.write(oldContent.trimmed().toUtf8());
    file.write("\n");
    file.close();

    qDebug() << localChangeLogPath + " geschrieben!";

    if (QProcess::execute("svn", QStringList() << "ci" << localChangeLogPath << "-m" << "Update via ChangeLogger") != 0) {
        qDebug() << "Fehler beim Check-In: " + tmpPath;
        return false;
    }

    SubversionBackend::RecursiveRemove(tmpPath);

    return true;
}
示例#9
0
void TwitterAdapter::getHisJson(string type, string hisID, Json::Value& theJson){
	cleanTmpFile();

	char cmd[500];
	sprintf(cmd, "php ./fetch_TWdata.php %s %s %s %s %s", accessToken.c_str(), accessTokenSecret.c_str(),type.c_str(), hisID.c_str(), tmpFileName);
	system(cmd);
	ifstream tmpFile(tmpFileName);
	tmpFile>> theJson;
}
示例#10
0
void TestQgsOpenClUtils::testProgramSource()
{
  QgsOpenClUtils::setSourcePath( QDir::tempPath() );
  QTemporaryFile tmpFile( QDir::tempPath() + "/XXXXXX.cl" );
  tmpFile.open( );
  tmpFile.write( QByteArray::fromStdString( source( ) ) );
  tmpFile.flush();
  QString baseName = tmpFile.fileName().replace( ".cl", "" ).replace( QDir::tempPath(), "" );
  QVERIFY( ! QgsOpenClUtils::sourceFromBaseName( baseName ).isEmpty() );
}
示例#11
0
文件: photos.cpp 项目: AchillesL/ARM
//???
void Photos::deleteImage()
{
    if( 0 == imageList.size())
    {
        QMessageBox::critical(this,tr("Warn"),
                              tr("No picture"),QMessageBox::Ok);
        return;
    }
    QMessageBox::StandardButton select = QMessageBox::question(NULL,"Warning",
                 tr("Delete is?"),QMessageBox::Yes | QMessageBox::No, QMessageBox::No);

    if(QMessageBox::Yes == select)
    {

        imageList.takeAt(position);
        QDir dir(dirPath);
        QFileInfoList fileList;
        QFileInfo curFile;
        QStringList filters;

        filters << "*.jpg" << "*.JPG";

        //??их?
        fileList = dir.entryInfoList(filters, QDir::Dirs|QDir::Files
                                   | QDir::Readable | QDir::Writable
                                   | QDir::Hidden | QDir::NoDotAndDotDot
                                   , QDir::Name);

        if(fileList.size()>0)
        {

            curFile = fileList[position];
            QFile tmpFile(curFile.filePath());
            tmpFile.remove();
            fileList.removeAt(position);

        }

        if(0 == imageList.size())
        {

            QMessageBox::critical(this,tr("Warn"),
                                  tr("No more"),QMessageBox::Ok);
            return;
        }

        //???? ???■?????ш????????
        imagePath = imageList.at(position);
        setPixmap(imagePath);

    }
}
示例#12
0
void FacebookAdapter::getNextJson(string url, Json::Value& theJson){//move up to static and resued by twitter?
	ofstream output(tmpFileName, ios_base::out | ios_base::trunc);
	output << url;
	output.close();

	//php
	char cmd[500];
	sprintf(cmd, "php ./myWget.php %s %s", tmpFileName, tmpFileName);
	system(cmd);

	ifstream tmpFile(tmpFileName);
	tmpFile >> theJson;
}
示例#13
0
void welcomeWizard::slotCheckDisabled()
{
  QString username = QString::fromLocal8Bit(getenv("LOGNAME"));

  QString filename = "/home/" + username + "/.config/hide-welcome";
  QFile tmpFile(filename);

  if ( checkDisableWelcome->isChecked() )
    system("touch " + filename.toLatin1() );
  else
    tmpFile.remove();
   
}
示例#14
0
static BaseEngine *ps2pdf(const WCHAR *fileName)
{
    // TODO: read from gswin32c's stdout instead of using a TEMP file
    ScopedMem<WCHAR> shortPath(path::ShortPath(fileName));
    ScopedMem<WCHAR> tmpFile(path::GetTempPath(L"PsE"));
    ScopedFile tmpFileScope(tmpFile);
    ScopedMem<WCHAR> gswin32c(GetGhostscriptPath());
    if (!shortPath || !tmpFile || !gswin32c)
        return NULL;

    // try to help Ghostscript determine the intended page size
    ScopedMem<WCHAR> psSetup;
    RectI page = ExtractDSCPageSize(fileName);
    if (!page.IsEmpty())
        psSetup.Set(str::Format(L" << /PageSize [%i %i] >> setpagedevice", page.dx, page.dy));

    ScopedMem<WCHAR> cmdLine(str::Format(
        L"\"%s\" -q -dSAFER -dNOPAUSE -dBATCH -dEPSCrop -sOutputFile=\"%s\" -sDEVICE=pdfwrite -c \".setpdfwrite%s\" -f \"%s\"",
        gswin32c, tmpFile, psSetup ? psSetup : L"", shortPath));
    fprintf(stderr, "- %s:%d: using '%ls' for creating '%%TEMP%%\\%ls'\n", path::GetBaseName(__FILE__), __LINE__, gswin32c.Get(), path::GetBaseName(tmpFile));

    // TODO: the PS-to-PDF conversion can hang the UI for several seconds
    HANDLE process = LaunchProcess(cmdLine, NULL, CREATE_NO_WINDOW);
    if (!process)
        return NULL;

    DWORD timeout = 10000;
#ifdef DEBUG
    // allow to disable the timeout for debugging purposes
    if (GetEnvironmentVariable(L"SUMATRAPDF_NO_GHOSTSCRIPT_TIMEOUT", NULL, 0))
        timeout = INFINITE;
#endif
    DWORD exitCode = EXIT_FAILURE;
    WaitForSingleObject(process, timeout);
    GetExitCodeProcess(process, &exitCode);
    TerminateProcess(process, 1);
    CloseHandle(process);
    if (exitCode != EXIT_SUCCESS)
        return NULL;

    size_t len;
    ScopedMem<char> pdfData(file::ReadAll(tmpFile, &len));
    if (!pdfData)
        return NULL;

    ScopedComPtr<IStream> stream(CreateStreamFromData(pdfData, len));
    if (!stream)
        return NULL;

    return PdfEngine::CreateFromStream(stream);
}
示例#15
0
void testLocalFile(const QString &filename)
{
    QFile tmpFile(filename); // Yeah, I know, security risk blah blah. This is a test prog!

    if(tmpFile.open(IO_ReadWrite))
    {
        QCString fname = QFile::encodeName(tmpFile.name());
        filter(fname, fname, KURIFilterData::LOCAL_FILE);
        tmpFile.close();
        tmpFile.remove();
    }
    else
        kdDebug() << "Couldn't create " << tmpFile.name() << ", skipping test" << endl;
}
GdbCoreEngine::~GdbCoreEngine()
{
    if (m_coreUnpackProcess) {
        m_coreUnpackProcess->blockSignals(true);
        m_coreUnpackProcess->terminate();
        m_coreUnpackProcess->deleteLater();
        m_coreUnpackProcess = 0;
        if (m_tempCoreFile.isOpen())
            m_tempCoreFile.close();
    }
    if (!m_tempCoreName.isEmpty()) {
        QFile tmpFile(m_tempCoreName);
        tmpFile.remove();
    }
}
示例#17
0
bool TmpDirChecker::checkWritePermissions(const QString &dirPath) {
    QDir dir(dirPath);
    if (!dir.exists()) {
        return false;
    }

    QFile tmpFile(getNewFilePath(dir.absolutePath(), "checkWritePermissions"));
    if (!tmpFile.open(QIODevice::WriteOnly)) {
        return false;
    }

    tmpFile.close();
    tmpFile.remove();
    return true;
}
示例#18
0
// Sven Wiegand <*****@*****.**> -- eps output filter (from KSnapshot)
KDE_EXPORT void kimgio_eps_write(QImageIO *imageio)
{
    QPrinter psOut(QPrinter::PrinterResolution);
    QPainter p;

    // making some definitions (papersize, output to file, filename):
    psOut.setCreator("KDE " KDE_VERSION_STRING);
    psOut.setOutputToFile(true);

    // Extension must be .eps so that Qt generates EPS file
    KTempFile tmpFile(QString::null, ".eps");
    tmpFile.setAutoDelete(true);
    if(tmpFile.status() != 0)
        return;
    tmpFile.close(); // Close the file, we just want the filename

    psOut.setOutputFileName(tmpFile.name());
    psOut.setFullPage(true);

    // painting the pixmap to the "printer" which is a file
    p.begin(&psOut);
    // Qt uses the clip rect for the bounding box
    p.setClipRect(0, 0, imageio->image().width(), imageio->image().height(), QPainter::CoordPainter);
    p.drawImage(QPoint(0, 0), imageio->image());
    p.end();

    // Copy file to imageio struct
    QFile inFile(tmpFile.name());
    inFile.open(IO_ReadOnly);

    QTextStream in(&inFile);
    in.setEncoding(QTextStream::Latin1);
    QTextStream out(imageio->ioDevice());
    out.setEncoding(QTextStream::Latin1);

    QString szInLine = in.readLine();
    out << szInLine << '\n';

    while(!in.atEnd())
    {
        szInLine = in.readLine();
        out << szInLine << '\n';
    }

    inFile.close();

    imageio->setStatus(0);
}
示例#19
0
// Sven Wiegand <*****@*****.**> -- eps output filter (from KSnapshot)
bool EPSHandler::write(const QImage &image)
{
    QPrinter psOut(QPrinter::PrinterResolution);
    QPainter p;

    // making some definitions (papersize, output to file, filename):
    psOut.setCreator( "KDE " KDE_VERSION_STRING  );
    if ( psOut.outputFileName().isEmpty() )
      psOut.setOutputFileName( "untitled_printer_document" );

    // Extension must be .eps so that Qt generates EPS file
    QTemporaryFile tmpFile("XXXXXXXX.eps");
    if ( !tmpFile.open() )
        return false;

    psOut.setOutputFileName(tmpFile.fileName());
    psOut.setOutputFormat(QPrinter::PostScriptFormat);
    psOut.setFullPage(true);
    psOut.setPaperSize(image.size(), QPrinter::DevicePixel);

    // painting the pixmap to the "printer" which is a file
    p.begin( &psOut );
    p.drawImage( QPoint( 0, 0 ), image );
    p.end();

    // Copy file to imageio struct
    QFile inFile(tmpFile.fileName());
    inFile.open( QIODevice::ReadOnly );

    QTextStream in( &inFile );
    in.setCodec( "ISO-8859-1" );
    QTextStream out( device() );
    out.setCodec( "ISO-8859-1" );

    QString szInLine = in.readLine();
    out << szInLine << '\n';

    while( !in.atEnd() ){
        szInLine = in.readLine();
        out << szInLine << '\n';
    }

    inFile.close();

    return true;
}
示例#20
0
bool HelpPage::acceptNavigationRequest(QWebFrame *,
    const QNetworkRequest &request, QWebPage::NavigationType type)
{
    const QUrl &url = request.url();
    const bool closeNewTab = closeNewTabIfNeeded;
    closeNewTabIfNeeded = false;

    if (isLocalUrl(url)) {
        const QString& path = url.path();
        if (path.endsWith(QLatin1String(".pdf"))) {
            const int lastDash = path.lastIndexOf(QChar('/'));
            QString fileName = QDir::tempPath() + QDir::separator();
            if (lastDash < 0)
                fileName += path;
            else
                fileName += path.mid(lastDash + 1, path.length());

            QFile tmpFile(QDir::cleanPath(fileName));
            if (tmpFile.open(QIODevice::ReadWrite)) {
                tmpFile.write(helpEngine->fileData(url));
                tmpFile.close();
            }
            QDesktopServices::openUrl(QUrl(tmpFile.fileName()));

            if (closeNewTab)
                QMetaObject::invokeMethod(CentralWidget::instance(), "closeTab");
            return false;
        }

        if (type == QWebPage::NavigationTypeLinkClicked
            && (m_keyboardModifiers & Qt::ControlModifier
            || m_pressedButtons == Qt::MidButton)) {
                HelpViewer* viewer = centralWidget->newEmptyTab();
                if (viewer)
                    CentralWidget::instance()->setSource(url);
                m_pressedButtons = Qt::NoButton;
                m_keyboardModifiers = Qt::NoModifier;
                return false;
        }
        return true;
    }

    QDesktopServices::openUrl(url);
    return false;
}
示例#21
0
bool ejson::internal::Document::store(const std::string& _file) {
	std::string createData;
	if (false == generate(createData)) {
		EJSON_ERROR("Error while creating the XML : " << _file);
		return false;
	}
	etk::FSNode tmpFile(_file);
	if (false == tmpFile.fileOpenWrite()) {
		EJSON_ERROR("Can not open (w) the file : " << _file);
		return false;
	}
	if (tmpFile.fileWrite((char*)createData.c_str(), sizeof(char), createData.size()) != (int32_t)createData.size()) {
		EJSON_ERROR("Error while writing output XML file : " << _file);
		tmpFile.fileClose();
		return false;
	}
	tmpFile.fileClose();
	return true;
}
示例#22
0
static PdfEngine *ps2pdf(const WCHAR *fileName)
{
    // TODO: read from gswin32c's stdout instead of using a TEMP file
    ScopedMem<WCHAR> shortPath(path::ShortPath(fileName));
    ScopedMem<WCHAR> tmpFile(path::GetTempPath(L"PsE"));
    ScopedFile tmpFileScope(tmpFile);
    ScopedMem<WCHAR> gswin32c(GetGhostscriptPath());
    if (!shortPath || !tmpFile || !gswin32c)
        return NULL;
    ScopedMem<WCHAR> cmdLine(str::Format(L"\"%s\" -q -dSAFER -dNOPAUSE -dBATCH -dEPSCrop -sOutputFile=\"%s\" -sDEVICE=pdfwrite -c .setpdfwrite -f \"%s\"", gswin32c, tmpFile, shortPath));

    if (GetEnvironmentVariable(L"MULOG", NULL, 0)) {
        wprintf(L"ps2pdf: using Ghostscript from '%s'\n", gswin32c.Get());
        wprintf(L"ps2pdf: for creating '%s'\n", tmpFile.Get());
    }

    // TODO: the PS-to-PDF conversion can hang the UI for several seconds
    HANDLE process = LaunchProcess(cmdLine, NULL, CREATE_NO_WINDOW);
    if (!process)
        return NULL;

    DWORD exitCode = EXIT_FAILURE;
    WaitForSingleObject(process, 10000);
    GetExitCodeProcess(process, &exitCode);
    TerminateProcess(process, 1);
    CloseHandle(process);
    if (exitCode != EXIT_SUCCESS)
        return NULL;

    size_t len;
    ScopedMem<char> pdfData(file::ReadAll(tmpFile, &len));
    if (!pdfData)
        return NULL;

    ScopedComPtr<IStream> stream(CreateStreamFromData(pdfData, len));
    if (!stream)
        return NULL;

    if (GetEnvironmentVariable(L"MULOG", NULL, 0))
        printf("ps2pdf: PDF conversion successful\n");

    return PdfEngine::CreateFromStream(stream);
}
示例#23
0
int CompileWork::ResponseStaticPage(string &respMsg)
{
	char bf;
	string tmp = "";
	respMsg = "";
	string path = requestHttp->GetPath();
	if(path.empty() || path == "/")
	{
		path = "index.html";
	}

	int dotpos = path.rfind(".");
	if(dotpos >= 0)
	{
		string suffix = string(path,dotpos+1);
		if(suffix == "css")
			responseHttp->SetMsgHead("Content-Type","text/css");
		else if(suffix == "js")
			responseHttp->SetMsgHead("Content-Type","application/x-javascript; charset=utf-8");
	}
	string compileworkdir = Config::GetInstance()->GetValue("COMPILEWOKRDIR");
	if(compileworkdir.empty())
		compileworkdir = COMPILEWOKRDIR;
	string dir = compileworkdir + path;
	fstream tmpFile(dir.c_str(),ios::in | ios::_Nocreate);
	if(tmpFile.is_open())
	{
		while(tmpFile.get(bf))
		{
			respMsg += bf;
		}
		tmpFile.close();
	}
	else
	{
		ResponseNotFound(respMsg);
	}

	responseHttp->SetMsgBody(respMsg);
	respMsg = responseHttp->ResponseContent();

	return RT_OK;
}
示例#24
0
void MainWindow::arduinoExec(const QString &action) {
    QStringList arguments;

    // Check if temp path exists
    QDir dir(settings->tmpDirName());
    if (dir.exists() == false) {
        dir.mkdir(settings->tmpDirName());
    }

    // Check if tmp file exists
    QFile tmpFile(settings->tmpFileName());
    if (tmpFile.exists()) {
        tmpFile.remove();
    }
    tmpFile.open(QIODevice::WriteOnly);

    // Read code
    QWebFrame *mainFrame = ui->webView->page()->mainFrame();
    QVariant codeVariant = mainFrame->evaluateJavaScript(
                "Blockly.Arduino.workspaceToCode();");
    QString codeString = codeVariant.toString();

    // Write code to tmp file
    tmpFile.write(codeString.toLocal8Bit());
    tmpFile.close();

    // Verify code
    arguments << action;
    // Board parameter
    if (ui->boardBox->count() > 0) {
        arguments << "--board" << ui->boardBox->currentText();
    }
    // Port parameter
    if (ui->serialPortBox->count() > 0) {
        arguments << "--port" << ui->serialPortBox->currentText();
    }
    arguments << settings->tmpFileName();
    process->start(settings->arduinoIdePath(), arguments);

    // Show messages
    ui->messagesWidget->show();
}
void ImageOpenThread::run()
{
    if (FUrl.scheme()=="file")
    {
        int dot=FUrl.path().lastIndexOf('.');
        if (dot>0)
        {
            QString ext=FUrl.path().mid(dot+1);
            if (!ext.isEmpty())
            {
                QStringList validExtensions;
                validExtensions << "png" << "gif" << "jpg" << "jpeg" << "ico" << "bmp" << "tif" << "tiff" << "svg";
                if (validExtensions.contains(ext, Qt::CaseInsensitive))
                {
                    QDesktopServices::openUrl(FUrl.path());
                    return;
                }
            }
        }

		QDir temp = QDir::temp();
        if (temp.isReadable())
        {
            QString fileName=FUrl.toLocalFile();
            QImageReader reader(fileName);
            if (reader.canRead())
            {
                QString type(reader.format());
                QString tmpFileName(fileName);
                tmpFileName.append('.').append(type);
                QFile tmpFile(temp.filePath(tmpFileName));
                if (!tmpFile.exists() || tmpFile.size()!=reader.device()->size())    // Exists already
                    QFile::copy(fileName, tmpFileName);
                QDesktopServices::openUrl(QUrl::fromLocalFile(tmpFile.fileName()));
            }
            else
                LOG_WARNING("Reader can't' read!");
        }
    }
    else
        QDesktopServices::openUrl(FUrl);
}
示例#26
0
void appl::TextPluginCtags::jumpTo(const std::string& _name) {
	if (m_ctagFile == nullptr) {
		APPL_WARNING("No ctags file open");
		return;
	}
	tagEntry entry;
	APPL_INFO("try to find the tag : " << _name);
	if (tagsFind (m_ctagFile, &entry, _name.c_str(), 0) != TagSuccess) {
		APPL_INFO("no tag find ...");
		return;
	}
	tagEntry entrySave = entry;
	int32_t numberOfTags = 0;
	
	// For all tags : Save in an internal Structure :
	std::string tmpFile(m_tagFolderBase + "/" + entry.file);
	etk::FSNode myfile(tmpFile);
	int32_t lineID = entry.address.lineNumber;
	printTag(&entry);
	
	if (tagsFindNext (m_ctagFile, &entry) == TagSuccess) {
		APPL_INFO("Multiple file destination ...");
		ememory::SharedPtr<appl::TagFileSelection> tmpWidget = appl::TagFileSelection::create();
		if (tmpWidget == nullptr) {
			APPL_ERROR("Can not allocate widget  == > display might be in error");
		} else {
			tmpWidget->addCtagsNewItem(myfile.getFileSystemName(), lineID);
			do {
				tmpFile = m_tagFolderBase + "/" + entry.file;
				myfile = tmpFile;
				lineID = entry.address.lineNumber;
				printTag(&entry);
				tmpWidget->addCtagsNewItem(myfile.getFileSystemName(), lineID);
			} while (tagsFindNext (m_ctagFile, &entry) == TagSuccess);
			ewol::getContext().getWindows()->popUpWidgetPush(tmpWidget);
			tmpWidget->signalSelect.connect(sharedFromThis(), &appl::TextPluginCtags::onCallbackOpenCtagsSelectReturn);
		}
	} else {
		jumpFile(myfile.getName(), lineID - 1);
	}
}
示例#27
0
int main() {
/*        const char *macs[4] = {
                "00-21-29-96-31-e7",
                "00-25-9c-57-de-a2",
                "00-21-91-51-58-6d",
                "00-17-9a-02-4e-05"
        };
*/

	std::string file("../pics/IMG_0024.JPG.log");
	std::string imageName("IMG_0024.JPG");
	LogFileResult result = parseLogFile(file, imageName);

	std::cout << "result found " << result.image_found << " at " << result.image_time << std::endl;
	std::cout << result.aps.size() << " aps." << std::endl;

	for (int i = 0; i < result.aps.size(); i++) {
		AccessPoint point = result.aps[i];
		std::cout << "ap " << point.mac_address << " with signal " << point.signal << " at "  << point.time << std::endl;
	}

        GeoLocateResult gresult = geolocate_locate(result.aps);
	std::cout << "lat " << gresult.lat << " lon " << gresult.lon << " accuracy " <<  gresult.accuracy << " succeeded " << gresult.success << std::endl;

	

	std::string imgFile("photo.jpg");
	dumpAllExif(imgFile);
ExifGPS gps = readGPS(imgFile);

	std::cout << "gps lat " << gps.lat << " gps lon " << gps.lon << std::endl;


	std::string tmpFile("test.jpg");
	writeGPS(tmpFile, gps);

	dumpAllExif(tmpFile);

	return 0;
}
示例#28
0
int CompileWork::ResponseNotFound(string &respMsg)
{
	char bf;
	string compileworkdir = Config::GetInstance()->GetValue("COMPILEWOKRDIR");
	if(compileworkdir.empty())
		compileworkdir = COMPILEWOKRDIR;
	string dir = compileworkdir + "404.html";
	responseHttp->SetStatus("404 Not Found");
	respMsg = "404 not Found";
	fstream tmpFile(dir.c_str(),ios::in | ios::_Nocreate);
	if(tmpFile.is_open())
	{
		respMsg = "";
		while(tmpFile.get(bf))
		{
			respMsg += bf;
		}
	}
	tmpFile.close();

	return RT_OK;
}
示例#29
0
QUrl ExportManager::tempSave(const QString &mimetype)
{
    // if we already have a temp file saved, use that
    if (mTempFile.isValid()) {
        if (QFile(mTempFile.toLocalFile()).exists()) {
            return mTempFile;
        }
    }

    QTemporaryFile tmpFile(QDir::tempPath() + QDir::separator() + "Spectacle.XXXXXX." + mimetype);
    tmpFile.setAutoRemove(false);
    tmpFile.setPermissions(QFile::ReadUser | QFile::WriteUser);

    if (tmpFile.open()) {
        if(!writeImage(&tmpFile, mimetype.toLatin1())) {
            emit errorMessage(i18n("Cannot save screenshot. Error while writing temporary local file."));
            return QUrl();
        }
        mTempFile = QUrl::fromLocalFile(tmpFile.fileName());
        return mTempFile;
    }

    return QUrl();
}
示例#30
0
bool HelpPage::acceptNavigationRequest(QWebFrame *,
    const QNetworkRequest &request, QWebPage::NavigationType)
{
    const QUrl &url = request.url();
    if (isLocalUrl(url)) {
        if (url.path().endsWith(QLatin1String("pdf"))) {
            QString fileName = url.toString();
            fileName = QDir::tempPath() + QDir::separator() + fileName.right
                (fileName.length() - fileName.lastIndexOf(QChar('/')));

            QFile tmpFile(QDir::cleanPath(fileName));
            if (tmpFile.open(QIODevice::ReadWrite)) {
                tmpFile.write(helpEngine->fileData(url));
                tmpFile.close();
            }
            QDesktopServices::openUrl(QUrl(tmpFile.fileName()));
            return false;
        }
        return true;
    }

    QDesktopServices::openUrl(url);
    return false;
}