From cd547a964bbd58fb5b99528d947725cae86bbd67 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Sat, 25 Dec 2021 02:51:02 +0000 Subject: [PATCH] Fix keeping an history of open files --- app/MainWindow.cpp | 50 ++++++++++++++++++-------------- app/MainWindow.h | 8 ++--- app/models/VideostreamResource.h | 1 + 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/app/MainWindow.cpp b/app/MainWindow.cpp index f5eb5f3..7d14e43 100644 --- a/app/MainWindow.cpp +++ b/app/MainWindow.cpp @@ -212,7 +212,7 @@ void MainWindow::loadFile( QString fileName, std::optional stream streamInfoOpt = m_aRecentFileStreamInfo.at( idx ); } - auto streamInfo = streamInfoOpt.has_value() ? *streamInfoOpt : CalypFileInfo{ .m_cFilename = fileName }; + auto streamInfo = streamInfoOpt.has_value() ? *streamInfoOpt : CalypFileInfo{ .m_cFilename = std::move( fileName ) }; auto videoResource = std::make_unique(); @@ -232,19 +232,20 @@ void MainWindow::loadFile( QString fileName, std::optional stream ConfigureFormatDialog formatDialog( this ); if( streamInfo.m_uiWidth == 0 ) { - streamInfo.m_uiWidth = m_cLastWidth; + streamInfo.m_uiWidth = m_lastOpenWidth; } if( streamInfo.m_uiHeight == 0 ) { - streamInfo.m_uiHeight = m_cLastHeight; + streamInfo.m_uiHeight = m_lastOpenHeight; } if( streamInfo.m_uiBitsPelPixel == 0 ) { - streamInfo.m_uiBitsPelPixel = m_cLastBitPerPixel; + streamInfo.m_uiBitsPelPixel = m_lastOpenBitPerPixel; } - if( formatDialog.runConfigureFormatDialog( - QFileInfo( fileName ).fileName(), streamInfo.m_uiWidth, streamInfo.m_uiHeight, streamInfo.m_iPelFormat, - streamInfo.m_uiBitsPelPixel, streamInfo.m_iEndianness, streamInfo.m_uiFrameRate ) != QDialog::Accepted ) + if( formatDialog.runConfigureFormatDialog( QFileInfo( streamInfo.m_cFilename ).fileName(), streamInfo.m_uiWidth, + streamInfo.m_uiHeight, streamInfo.m_iPelFormat, + streamInfo.m_uiBitsPelPixel, streamInfo.m_iEndianness, + streamInfo.m_uiFrameRate ) != QDialog::Accepted ) { return; } @@ -254,6 +255,7 @@ void MainWindow::loadFile( QString fileName, std::optional stream if( opened ) { + const auto openedStreamInfo = videoResource->getStreamInfo(); auto resource_id = m_appResourceHandle->appendResource( std::move( videoResource ) ); auto* videoSubWindow = new VideoStreamSubWindow( m_appResourceHandle.get() ); // createSubWindow(); @@ -267,10 +269,13 @@ void MainWindow::loadFile( QString fileName, std::optional stream updateZoomFactorSBox(); - addStreamInfoToRecentList( std::move( streamInfo ) ); + addStreamInfoToRecentList( std::move( openedStreamInfo ) ); printMessage( "File loaded", CLP_LOG_INFO ); - m_cLastOpenPath = QFileInfo( fileName ).path(); + m_lastOpenPath = QFileInfo( streamInfo.m_cFilename ).path(); + m_lastOpenWidth = streamInfo.m_uiWidth; + m_lastOpenHeight = streamInfo.m_uiHeight; + m_lastOpenBitPerPixel = streamInfo.m_uiBitsPelPixel; } } catch( CalypFailure& e ) @@ -322,11 +327,11 @@ QStringList MainWindow::showFileDialog( bool bRead ) fileNameList.clear(); if( bRead ) { - fileNameList = QFileDialog::getOpenFileNames( this, tr( "Open File" ), m_cLastOpenPath, filter.join( ";;" ) ); + fileNameList = QFileDialog::getOpenFileNames( this, tr( "Open File" ), m_lastOpenPath, filter.join( ";;" ) ); } else { - QString fileName = QFileDialog::getSaveFileName( this, tr( "Save File" ), m_cLastOpenPath, filter.join( ";;" ) ); + QString fileName = QFileDialog::getSaveFileName( this, tr( "Save File" ), m_lastOpenPath, filter.join( ";;" ) ); if( !fileName.isEmpty() ) fileNameList.append( fileName ); } @@ -369,7 +374,7 @@ void MainWindow::saveFrame() if( fileNameList.size() == 1 ) { QString fileName = fileNameList[0]; - m_cLastOpenPath = QFileInfo( fileName ).path(); + m_lastOpenPath = QFileInfo( fileName ).path(); try { saveWindow->save( fileName ); @@ -397,7 +402,7 @@ void MainWindow::saveStream() if( fileNameList.size() == 1 ) { QString fileName = fileNameList[0]; - m_cLastOpenPath = QFileInfo( fileName ).path(); + m_lastOpenPath = QFileInfo( fileName ).path(); try { saveWindow->save( fileName ); @@ -557,7 +562,7 @@ void MainWindow::dropEvent( QDropEvent* event ) if( urlList.size() == 1 ) { QString fileName = urlList.at( 0 ).toLocalFile(); - m_cLastOpenPath = QFileInfo( fileName ).path(); + m_lastOpenPath = QFileInfo( fileName ).path(); loadFile( fileName ); } } @@ -964,6 +969,7 @@ void MainWindow::checkRecentFileActions() else { unsigned long long int fileSize = QFileInfo( m_aRecentFileStreamInfo.at( i ).m_cFilename ).size(); + std::cout << m_aRecentFileStreamInfo.at( i ).m_uiFileSize << std::endl; if( m_aRecentFileStreamInfo.at( i ).m_uiFileSize != fileSize ) { m_aRecentFileStreamInfo.remove( i ); @@ -983,10 +989,10 @@ void MainWindow::readSettings() move( pos ); resize( size ); - m_cLastOpenPath = appSettings.value( "MainWindow/LastOpenPath", QDir::homePath() ).toString(); - m_cLastWidth = appSettings.value( "MainWindow/LastWidth" ).value(); - m_cLastHeight = appSettings.value( "MainWindow/LastHeight" ).value(); - m_cLastBitPerPixel = appSettings.value( "MainWindow/LastBitsPerPixel" ).value(); + m_lastOpenPath = appSettings.value( "MainWindow/LastOpenPath", QDir::homePath() ).toString(); + m_lastOpenWidth = appSettings.value( "MainWindow/LastWidth" ).value(); + m_lastOpenHeight = appSettings.value( "MainWindow/LastHeight" ).value(); + m_lastOpenBitPerPixel = appSettings.value( "MainWindow/LastBitsPerPixel" ).value(); QVariant value = appSettings.value( "MainWindow/RecentFileList" ); m_aRecentFileStreamInfo = value.value(); @@ -1005,10 +1011,10 @@ void MainWindow::writeSettings() appSettings.setValue( "MainWindow/Position", pos() ); appSettings.setValue( "MainWindow/Size", size() ); - appSettings.setValue( "MainWindow/LastOpenPath", m_cLastOpenPath ); - appSettings.setValue( "MainWindow/LastWidth", m_cLastWidth ); - appSettings.setValue( "MainWindow/LastHeight", m_cLastHeight ); - appSettings.setValue( "MainWindow/LastBitsPerPixel", m_cLastBitPerPixel ); + appSettings.setValue( "MainWindow/LastOpenPath", m_lastOpenPath ); + appSettings.setValue( "MainWindow/LastWidth", m_lastOpenWidth ); + appSettings.setValue( "MainWindow/LastHeight", m_lastOpenHeight ); + appSettings.setValue( "MainWindow/LastBitsPerPixel", m_lastOpenBitPerPixel ); QVariant var; var.setValue( m_aRecentFileStreamInfo ); diff --git a/app/MainWindow.h b/app/MainWindow.h index 555a8de..cdbd126 100644 --- a/app/MainWindow.h +++ b/app/MainWindow.h @@ -132,10 +132,10 @@ private: SubWindowAbstract* m_pcCurrentSubWindow; //!< General always set VideoSubWindow* m_pcCurrentVideoSubWindow; - QString m_cLastOpenPath; - unsigned int m_cLastWidth; - unsigned int m_cLastHeight; - unsigned int m_cLastBitPerPixel; + QString m_lastOpenPath; + unsigned int m_lastOpenWidth; + unsigned int m_lastOpenHeight; + unsigned int m_lastOpenBitPerPixel; QStringList showFileDialog( bool bRead ); static VideoStreamSubWindow* findVideoStreamSubWindow( const SubWindowHandle* windowManager, diff --git a/app/models/VideostreamResource.h b/app/models/VideostreamResource.h index 94fb686..b654f05 100644 --- a/app/models/VideostreamResource.h +++ b/app/models/VideostreamResource.h @@ -69,6 +69,7 @@ public: auto loadFile( const QString& cFilename ) -> bool; auto loadFile( const CalypFileInfo& streamInfo, bool optimistic = true ) -> bool; + auto getStreamInfo() const -> CalypFileInfo { return m_sStreamInfo; } auto getResource() -> CalypStream* override { return &m_currStream; }; auto getStream() const -> const CalypStream& { return m_currStream; };