From e7716954cb681c531132a342b4b486a28179f792 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Fri, 20 Jan 2023 20:23:35 +0100 Subject: Minor, UX enhancements --- Examples/WhisperDesktop/AppState.cpp | 13 +++++++++++++ Examples/WhisperDesktop/AppState.h | 2 ++ Examples/WhisperDesktop/TranscribeDlg.cpp | 26 ++++++++++++++++++++++++-- Examples/WhisperDesktop/TranscribeDlg.h | 12 ++++++++---- 4 files changed, 47 insertions(+), 6 deletions(-) (limited to 'Examples') diff --git a/Examples/WhisperDesktop/AppState.cpp b/Examples/WhisperDesktop/AppState.cpp index 651e8ae..b478546 100644 --- a/Examples/WhisperDesktop/AppState.cpp +++ b/Examples/WhisperDesktop/AppState.cpp @@ -203,4 +203,17 @@ void AppState::gpuFlagsStore( uint32_t flags ) registryKey.DeleteValue( regValGpuFlags ); else dwordStore( regValGpuFlags, flags ); +} + +bool AppState::boolLoad( LPCTSTR name ) +{ + return dwordLoad( name, 0 ) != 0; +} + +void AppState::boolStore( LPCTSTR name, bool val ) +{ + if( val ) + dwordStore( name, 1 ); + else + registryKey.DeleteValue( name ); } \ No newline at end of file diff --git a/Examples/WhisperDesktop/AppState.h b/Examples/WhisperDesktop/AppState.h index 9824b42..76688d8 100644 --- a/Examples/WhisperDesktop/AppState.h +++ b/Examples/WhisperDesktop/AppState.h @@ -37,6 +37,8 @@ public: void stringStore( LPCTSTR name, LPCTSTR value ); uint32_t dwordLoad( LPCTSTR name, uint32_t fallback ); void dwordStore( LPCTSTR name, uint32_t value ); + bool boolLoad( LPCTSTR name ); + void boolStore( LPCTSTR name, bool val ); bool automaticallyLoadModel = true; diff --git a/Examples/WhisperDesktop/TranscribeDlg.cpp b/Examples/WhisperDesktop/TranscribeDlg.cpp index bfdb6f1..0e05827 100644 --- a/Examples/WhisperDesktop/TranscribeDlg.cpp +++ b/Examples/WhisperDesktop/TranscribeDlg.cpp @@ -22,6 +22,7 @@ constexpr int progressMaxInteger = 1024 * 8; static const LPCTSTR regValInput = L"sourceMedia"; static const LPCTSTR regValOutFormat = L"resultFormat"; static const LPCTSTR regValOutPath = L"resultPath"; +static const LPCTSTR regValUseInputFolder = L"useInputFolder"; LRESULT TranscribeDlg::OnInitDialog( UINT nMessage, WPARAM wParam, LPARAM lParam, BOOL& bHandled ) { @@ -61,8 +62,10 @@ LRESULT TranscribeDlg::OnInitDialog( UINT nMessage, WPARAM wParam, LPARAM lParam sourceMediaPath.SetWindowText( appState.stringLoad( regValInput ) ); transcribeOutFormat.SetCurSel( (int)appState.dwordLoad( regValOutFormat, 0 ) ); transcribeOutputPath.SetWindowText( appState.stringLoad( regValOutPath ) ); + if( appState.boolLoad( regValUseInputFolder ) ) + useInputFolder.SetCheck( BST_CHECKED ); BOOL unused; - OnOutFormatChange( 0, 0, nullptr, unused ); + onOutFormatChange( 0, 0, nullptr, unused ); appState.lastScreenSave( SCREEN_TRANSCRIBE ); appState.setupIcon( this ); @@ -118,7 +121,8 @@ enum struct TranscribeDlg::eOutputFormat : uint8_t WebVTT = 3 }; -LRESULT TranscribeDlg::OnOutFormatChange( UINT, INT, HWND, BOOL& bHandled ) +// CBN_SELCHANGE notification for IDC_OUTPUT_FORMAT combobox +LRESULT TranscribeDlg::onOutFormatChange( UINT, INT, HWND, BOOL& bHandled ) { BOOL enabled = transcribeOutFormat.GetCurSel() != 0; useInputFolder.EnableWindow( enabled ); @@ -134,6 +138,17 @@ LRESULT TranscribeDlg::OnOutFormatChange( UINT, INT, HWND, BOOL& bHandled ) return 0; } +// EN_CHANGE notification for IDC_PATH_MEDIA edit box +LRESULT TranscribeDlg::onInputChange( UINT, INT, HWND, BOOL& ) +{ + if( !useInputFolder.IsWindowEnabled() ) + return 0; + if( !isChecked( useInputFolder ) ) + return 0; + setOutputPath(); + return 0; +} + void TranscribeDlg::onBrowseMedia() { LPCTSTR title = L"Input audio file to transcribe"; @@ -255,12 +270,19 @@ void TranscribeDlg::onTranscribe() transcribeError( L"Please select an output text file" ); return; } + if( PathFileExists( transcribeArgs.pathOutput ) ) + { + const int resp = MessageBox( L"The output file is already there.\nOverwrite the file?", L"Confirm Overwrite", MB_ICONQUESTION | MB_YESNO ); + if( resp != IDYES ) + return; + } appState.stringStore( regValOutPath, transcribeArgs.pathOutput ); } else cbConsole.ensureChecked(); appState.dwordStore( regValOutFormat, (uint32_t)(int)transcribeArgs.format ); + appState.boolStore( regValUseInputFolder, isChecked( useInputFolder ) ); languageSelector.saveSelection( appState ); cbTranslate.saveSelection( appState ); appState.stringStore( regValInput, transcribeArgs.pathMedia ); diff --git a/Examples/WhisperDesktop/TranscribeDlg.h b/Examples/WhisperDesktop/TranscribeDlg.h index 9a90510..800d8eb 100644 --- a/Examples/WhisperDesktop/TranscribeDlg.h +++ b/Examples/WhisperDesktop/TranscribeDlg.h @@ -32,8 +32,9 @@ public: ON_BUTTON_CLICK( IDC_BROWSE_MEDIA, onBrowseMedia ) ON_BUTTON_CLICK( IDC_BROWSE_RESULT, onBrowseOutput ) ON_BUTTON_CLICK( IDC_TRANSCRIBE, onTranscribe ) - ON_BUTTON_CLICK( IDC_CAPTURE, onCapture ); - COMMAND_HANDLER( IDC_OUTPUT_FORMAT, CBN_SELCHANGE, OnOutFormatChange ) + ON_BUTTON_CLICK( IDC_CAPTURE, onCapture ) + COMMAND_HANDLER( IDC_OUTPUT_FORMAT, CBN_SELCHANGE, onOutFormatChange ) + COMMAND_HANDLER( IDC_PATH_MEDIA, EN_CHANGE, onInputChange ) MESSAGE_HANDLER( WM_CALLBACK_STATUS, onCallbackStatus ) MSG_WM_CLOSE( onWmClose ) END_MSG_MAP() @@ -79,7 +80,8 @@ private: CProgressBarCtrl progressBar; void populateOutputFormats(); - LRESULT OnOutFormatChange( UINT, INT, HWND, BOOL& bHandled ); + LRESULT onOutFormatChange( UINT, INT, HWND, BOOL& bHandled ); + LRESULT onInputChange( UINT, INT, HWND, BOOL& ); void onInputFolderCheck(); void onBrowseMedia(); void onBrowseOutput(); @@ -125,6 +127,8 @@ private: HRESULT progressCallback( double p ) noexcept; void onWmClose(); - void setOutputPath(); + // Populate output path based on the provided input media path void setOutputPath( const CString& input ); + // Populate output path based on the input media path in the edit box + void setOutputPath(); }; \ No newline at end of file -- cgit v1.2.3