コード例 #1
0
ファイル: texteditor.cpp プロジェクト: chegestar/TextEditor
// QML listView: file name was selected for reading
void TextEditor::fileOpenRequested(QString fileName)
{
    bool fileIsReadable = false;

    //qDebug() << "DBG> open"<<fileName<<"from currentFolder:"<<currentFolder;

    QUrl url(newFolder+"/"+fileName);
    QString localFile = url.toLocalFile();
    QFile file(localFile);
    fileIsReadable = file.open(QIODevice::ReadOnly | QIODevice::Text);
    if (fileIsReadable)
    {
        QTextStream stream( &file );
        currentContent = stream.readAll();
        file.close();
        // update current folder and file name
        currentFolder = newFolder;
        currentFile = fileName;
        // update the recent files list
        recentFiles->readRecentFiles();
        recentFiles->addFile(currentFolder+"|"+currentFile);
        // pass the content to the TextArea component
        emit openCompleted(currentContent,currentFolder,currentFile);
    } else {
        // remove the entry from the recent files list (if it exists there)
        // do not touch the current folder and file names
        recentFiles->removeFile(newFolder+"|"+fileName);
        emit openFailed(fileName,file.errorString());
    }
}
コード例 #2
0
ファイル: PhVideoDecoder.cpp プロジェクト: xela13/Joker
void PhVideoDecoder::open(QString fileName)
{
	close();
	PHDEBUG << fileName;

	_currentFrame = PHFRAMEMIN;

	if(avformat_open_input(&_formatContext, fileName.toStdString().c_str(), NULL, NULL) < 0) {
		emit openFailed();
		close();
		return;
	}

	PHDEBUG << "Retrieve stream information";
	if (avformat_find_stream_info(_formatContext, NULL) < 0) {
		emit openFailed();
		close();
		return; // Couldn't find stream information
	}

	// Disable dump for specs
	if(PhDebug::logMask() & 1)
		av_dump_format(_formatContext, 0, fileName.toStdString().c_str(), 0);

	// Find video stream :
	for(int i = 0; i < (int)_formatContext->nb_streams; i++) {
		AVMediaType streamType = _formatContext->streams[i]->codec->codec_type;
		PHDEBUG << i << ":" << streamType;
		switch(streamType) {
		case AVMEDIA_TYPE_VIDEO:
			// Some containers are advertised with several video streams.
			// For example, one is the main stream and the other one is just a cover picture (single frame).
			// Here we choose the one that has the largest number of frames.
			if (!_videoStream || _videoStream->nb_frames < _formatContext->streams[i]->nb_frames) {
				_videoStream = _formatContext->streams[i];
			}
			PHDEBUG << "\t=> video";
			break;
		case AVMEDIA_TYPE_AUDIO:
			if(_useAudio && (_audioStream == NULL))
				_audioStream = _formatContext->streams[i];
			PHDEBUG << "\t=> audio";
			break;
		default:
			PHDEBUG << "\t=> unknown";
			break;
		}
	}

	if(_videoStream == NULL) {
		emit openFailed();
		close();
		return;
	}

	// Looking for timecode type
	_tcType = PhTimeCode::computeTimeCodeType(this->framePerSecond());

	PHDEBUG << "size : " << _videoStream->codec->width << "x" << _videoStream->codec->height;
	AVCodec * videoCodec = avcodec_find_decoder(_videoStream->codec->codec_id);
	if(videoCodec == NULL) {
		PHDEBUG << "Unable to find the codec:" << _videoStream->codec->codec_id;
		emit openFailed();
		close();
		return;
	}

	if (avcodec_open2(_videoStream->codec, videoCodec, NULL) < 0) {
		PHDEBUG << "Unable to open the codec:" << _videoStream->codec;
		emit openFailed();
		close();
		return;
	}

	_videoFrame = av_frame_alloc();

	if(_audioStream) {
		AVCodec* audioCodec = avcodec_find_decoder(_audioStream->codec->codec_id);
		if(audioCodec) {
			if(avcodec_open2(_audioStream->codec, audioCodec, NULL) < 0) {
				PHDEBUG << "Unable to open audio codec.";
				_audioStream = NULL;
			}
			else {
				_audioFrame = av_frame_alloc();
				PHDEBUG << "Audio OK.";
			}
		}
		else {
			PHDEBUG << "Unable to find codec for audio.";
			_audioStream = NULL;
		}
	}

	_fileName = fileName;

	emit opened(_tcType, frameIn(), frameLength(), width(), height(), codecName());
}
コード例 #3
0
ファイル: texteditor.cpp プロジェクト: chegestar/TextEditor
TextEditor::TextEditor(QObject *qml, RecentFiles *recentfiles, QObject *parent) :
    QObject(parent)
{

    currentFolder = "file:///home/user";
    newFolder = currentFolder;
    //currentFolder = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
    //qDebug() << currentFolder;
    currentFile = tr(UNTITLED);
    currentContent = "";
    recentFiles = recentfiles;

    // connect QML signals to TextEditor slots
    connect(qml, SIGNAL(menuOpenClicked(QString)),
             this, SLOT(menuOpenClicked(QString)));
    connect(qml, SIGNAL(toolSaveClicked(QString)),
             this, SLOT(toolSaveClicked(QString)));
    connect(qml, SIGNAL(toolRecentClicked()),
             this, SLOT(toolRecentClicked()));
    connect(qml, SIGNAL(menuSaveAsClicked()),
             this, SLOT(menuSaveAsClicked()));
    connect(qml, SIGNAL(saveAsRequested(QString,QString)),
             this, SLOT(saveAsRequested(QString,QString)));
    connect(qml, SIGNAL(newFolderChanged(QString)),
             this, SLOT(newFolderChanged(QString)));
    connect(qml, SIGNAL(fileOpenRequested(QString)),
             this, SLOT(fileOpenRequested(QString)));
    connect(qml, SIGNAL(saveAsConfirmed(QString)),
             this, SLOT(saveAsConfirmed(QString)));
    connect(qml, SIGNAL(newOrOpenConfirmed(QString)),
             this, SLOT(newOrOpenConfirmed(QString)));
    connect(qml, SIGNAL(openRecentConfirmed()),
             this, SLOT(openRecentConfirmed()));
    connect(qml, SIGNAL(menuQuitClicked(QString)),
             this, SLOT(menuQuitClicked(QString)));
    connect(qml, SIGNAL(saveBeforeClosed(QString)),
             this, SLOT(saveBeforeClosed(QString)));
    connect(qml, SIGNAL(menuNewClicked(QString)),
             this, SLOT(menuNewClicked(QString)));
    connect(qml, SIGNAL(recentFileClicked(QString,QString,QString)),
             this, SLOT(recentFileClicked(QString,QString,QString)));

    // connect TextEditor signals to QML signals
    connect(this, SIGNAL(browseRequested(QString,bool)),
               qml, SLOT(browseRequested(QString,bool)));
    connect(this, SIGNAL(recentRequested()),
               qml, SLOT(recentRequested()));
    connect(this, SIGNAL(openCompleted(QString,QString,QString)),
               qml, SLOT(openCompleted(QString,QString,QString)));
    connect(this, SIGNAL(openFailed(QString,QString)),
               qml, SLOT(openFailed(QString,QString)));
    connect(this, SIGNAL(saveCompleted()),
               qml, SLOT(saveCompleted()));
    connect(this, SIGNAL(saveFailed(QString,QString)),
               qml, SLOT(saveFailed(QString,QString)));
    connect(this, SIGNAL(saveAsCompleted(QString,QString)),
               qml, SLOT(saveAsCompleted(QString,QString)));
    connect(this, SIGNAL(saveAsToBeConfirmed(QString)),
               qml, SLOT(saveAsToBeConfirmed(QString)));
    connect(this, SIGNAL(newOrOpenToBeConfirmed(QString,QString)),
               qml, SLOT(newOrOpenToBeConfirmed(QString,QString)));
    connect(this, SIGNAL(openRecentToBeConfirmed(QString)),
               qml, SLOT(openRecentToBeConfirmed(QString)));
    connect(this, SIGNAL(appCloseToBeConfirmed(QString)),
               qml, SLOT(appCloseToBeConfirmed(QString)));
    connect(this, SIGNAL(appToBeClosed()),
               qml, SLOT(appToBeClosed()));
    connect(this, SIGNAL(editorCleared(QString,QString)),
               qml, SLOT(editorCleared(QString,QString)));
}