windows/mainwindow: localization

This commit is contained in:
zvon 2020-04-01 13:53:34 +02:00
parent e2199bbb83
commit c12020529b

View File

@ -1,13 +1,17 @@
#pragma comment( linker, "\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"" )
#include "mainwindow.hpp" #include "mainwindow.hpp"
#include "../filesystem.hpp"
#include "../functions.hpp"
#include "../tv_rename.hpp"
#include "databasewindow.hpp" #include "databasewindow.hpp"
#include "gui_functions.hpp" #include "gui_functions.hpp"
#include "patternwindow.hpp" #include "patternwindow.hpp"
#include "progresswindow.hpp" #include "progresswindow.hpp"
#include "searchwindow.hpp" #include "searchwindow.hpp"
#include "seasonwindow.hpp" #include "seasonwindow.hpp"
#include "../filesystem.hpp"
#include "../functions.hpp"
#include "../resources_windows.h"
#include "../tv_rename.hpp"
#include <fstream> #include <fstream>
#include <thread> #include <thread>
@ -51,18 +55,34 @@ MainWindow::MainWindow( HINSTANCE hInstance, int nCmdShow )
window_height, NULL, NULL, hInst, NULL ); window_height, NULL, NULL, hInst, NULL );
ShowWindow( window, nCmdShow ); ShowWindow( window, nCmdShow );
hFont = ( HFONT )GetStockObject( DEFAULT_GUI_FONT ); hFont = ( HFONT )GetStockObject( DEFAULT_GUI_FONT );
setIcons( hInstance, window );
authenticate( API_KEY ); authenticate( API_KEY );
languages = getLangs(); languages = getLangs();
createLabel( L"Show:", 5, 5, 30, 15, ID_SHOW_STATIC, window, hFont ); std::wstring label = _( SHOW );
createLabel( L"Language:", 170, 5, 55, 15, ID_LANGUAGE_STATIC, window, label += L":";
createLabel( label.c_str(), 5, 5, 30, 15, ID_SHOW_STATIC, window, hFont );
label = _( ID_LANGUAGE );
label += L":";
createLabel( label.c_str(), 170, 5, 55, 15, ID_LANGUAGE_STATIC, window,
hFont ); hFont );
createLabel( L"Directory:", 5, 45, 65, 15, ID_DIR_STATIC, window, hFont );
createLabel( L"Pattern:", 5, 85, 55, 15, ID_PATTERN_STATIC, window, hFont ); label = _( DIRECTORY );
possible_label = createLabel( L"Possible shows:", 5, 190, 100, 15, label += L":";
createLabel( label.c_str(), 5, 45, 65, 15, ID_DIR_STATIC, window, hFont );
label = _( PATTERN );
label += L":";
createLabel( label.c_str(), 5, 85, 55, 15, ID_PATTERN_STATIC, window,
hFont );
label = _( POSSIBLE_SHOWS );
label += L":";
possible_label = createLabel( label.c_str(), 5, 190, 100, 15,
ID_POSSIBLE_STATIC, window, hFont ); ID_POSSIBLE_STATIC, window, hFont );
show_input = createEditBox( 5, 20, 160, 25, ID_SHOW_EDIT, window, hFont ); show_input = createEditBox( 5, 20, 160, 20, ID_SHOW_EDIT, window, hFont );
language_input = language_input =
createCombo( 170, 20, 160, 250, ID_LANGUAGE_COMBO, window, hFont ); createCombo( 170, 20, 160, 250, ID_LANGUAGE_COMBO, window, hFont );
for ( auto &x : languages ) { for ( auto &x : languages ) {
@ -70,26 +90,26 @@ MainWindow::MainWindow( HINSTANCE hInstance, int nCmdShow )
} }
SendMessage( language_input, CB_SETCURSEL, langPos( L"en" ), NULL ); SendMessage( language_input, CB_SETCURSEL, langPos( L"en" ), NULL );
dir_input = createEditBox( 5, 60, 160, 25, ID_DIR_EDIT, window, hFont ); dir_input = createEditBox( 5, 60, 160, 20, ID_DIR_EDIT, window, hFont );
createButton( L"Choose directory", 170, 60, 120, 25, ID_DIR_BUTTON, window, createButton( _( CHOOSE_DIR ), 170, 60, 80, 25, ID_DIR_BUTTON, window,
hFont ); hFont );
pattern_input = pattern_input =
createEditBox( 5, 100, 160, 25, ID_PATTERN_EDIT, window, hFont ); createEditBox( 5, 100, 160, 20, ID_PATTERN_EDIT, window, hFont );
createButton( L"Pattern help", 170, 100, 100, 25, ID_PATTERN_BUTTON, window, createButton( _( PATTERN_HELP ), 170, 100, 80, 25, ID_PATTERN_BUTTON,
window, hFont );
createButton( _( PROCESS ), 5, 140, 80, 25, ID_PROCESS_BUTTON, window,
hFont ); hFont );
createButton( L"Process", 5, 140, 80, 25, ID_PROCESS_BUTTON, window, trust_input = createCheckbox( _( DONT_RENAME_CONFIRM ), 90, 146, 180, 12,
hFont ); ID_RENAME_CHECKBOX, window, hFont );
trust_input = createCheckbox( L"Don't ask for rename confirmation", 90, 146, dvd_input = createCheckbox( _( USE_DVD ), 5, 170, 180, 12,
180, 12, ID_RENAME_CHECKBOX, window, hFont );
dvd_input = createCheckbox( L"Use DVD ordering", 5, 170, 180, 12,
ID_DVD_CHECKBOX, window, hFont ); ID_DVD_CHECKBOX, window, hFont );
possible_input = createCombo( 5, 205, 160, window_height - 220, possible_input = createCombo( 5, 205, 160, window_height - 220,
ID_SHOW_COMBO, window, hFont ); ID_SHOW_COMBO, window, hFont );
rename_button = createButton( L"Rename", 5, 230, 80, 25, ID_RENAME_BUTTON, rename_button = createButton( _( RENAME ), 5, 230, 80, 25, ID_RENAME_BUTTON,
window, hFont ); window, hFont );
db_add_button = createButton( L"Add to database", 90, 230, 100, 25, db_add_button = createButton( _( ADD_TO_DB ), 90, 230, 80, 25,
ID_DB_ADD_BUTTON, window, hFont ); ID_DB_ADD_BUTTON, window, hFont );
createButton( L"Quit", window_width - 100, window_height - 88, 80, 25, createButton( _( QUIT ), window_width - 100, window_height - 88, 80, 25,
ID_QUIT_BUTTON, window, hFont ); ID_QUIT_BUTTON, window, hFont );
// MENUS // MENUS
@ -97,23 +117,21 @@ MainWindow::MainWindow( HINSTANCE hInstance, int nCmdShow )
HMENU hMenuFile = CreateMenu(); HMENU hMenuFile = CreateMenu();
HMENU hMenuDatabase = CreateMenu(); HMENU hMenuDatabase = CreateMenu();
AppendMenuW( hMenuFile, MF_STRING, MENU_FILE_EXIT, L"&Exit" ); AppendMenuW( hMenuFile, MF_STRING, MENU_FILE_EXIT, _( EXIT ) );
AppendMenuW( hMenuDatabase, MF_STRING, MENU_DAT_UPDATE, AppendMenuW( hMenuDatabase, MF_STRING, MENU_DAT_UPDATE, _( UPDATE_DB ) );
L"&Update database" ); AppendMenuW( hMenuDatabase, MF_STRING, MENU_DAT_REFRESH, _( REFRESH_DB ) );
AppendMenuW( hMenuDatabase, MF_STRING, MENU_DAT_REFRESH, AppendMenuW( hMenuDatabase, MF_STRING, MENU_DAT_CLEAN, _( CLEAN_DB ) );
L"&Refresh database" ); AppendMenuW( hMenuDatabase, MF_STRING, MENU_DAT_MANAGE, _( MANAGE_DB ) );
AppendMenuW( hMenuDatabase, MF_STRING, MENU_DAT_CLEAN, L"&Clean database" );
AppendMenuW( hMenuDatabase, MF_STRING, MENU_DAT_MANAGE,
L"&Manage database" );
AppendMenuW( hMenuDatabase, MF_STRING, MENU_DAT_PATTERN, AppendMenuW( hMenuDatabase, MF_STRING, MENU_DAT_PATTERN,
L"Change &pattern" ); _( CHANGE_DB_PATTERN ) );
AppendMenuW( hMenuBar, MF_POPUP, ( UINT_PTR )hMenuFile, L"&File" ); AppendMenuW( hMenuBar, MF_POPUP, ( UINT_PTR )hMenuFile, _( ID_FILE ) );
AppendMenuW( hMenuBar, MF_POPUP, ( UINT_PTR )hMenuDatabase, L"&Database" ); AppendMenuW( hMenuBar, MF_POPUP, ( UINT_PTR )hMenuDatabase, _( DATABASE_MENU ) );
SetMenu( window, hMenuBar ); SetMenu( window, hMenuBar );
INITCOMMONCONTROLSEX icex; // Structure for control initialization. INITCOMMONCONTROLSEX icex; // Structure for control initialization.
icex.dwICC = ICC_LISTVIEW_CLASSES; icex.dwICC = ICC_LISTVIEW_CLASSES;
icex.dwSize = sizeof( icex );
InitCommonControlsEx( &icex ); InitCommonControlsEx( &icex );
auto appdata = userHome() + L"\\tv_rename"; auto appdata = userHome() + L"\\tv_rename";
@ -216,23 +234,16 @@ void MainWindow::process() {
wchar_t show[256]; wchar_t show[256];
SendMessage( show_input, WM_GETTEXT, ( WPARAM )255, ( LPARAM )show ); SendMessage( show_input, WM_GETTEXT, ( WPARAM )255, ( LPARAM )show );
if ( wcslen( show ) == 0 ) { if ( wcslen( show ) == 0 ) {
MessageBox( window, L"Show field is empty", L"Error", MessageBox( window, _( SHOW_FIELD_EMPTY ), _( ERROR ), MB_OK | MB_ICONERROR );
MB_OK | MB_ICONERROR );
return; return;
} }
auto index = SendMessage( language_input, CB_GETCURSEL, NULL, NULL ); auto index = SendMessage( language_input, CB_GETCURSEL, NULL, NULL );
if ( index == CB_ERR ) {
MessageBox( window, L"No show selected", L"Error",
MB_OK | MB_ICONERROR );
return;
}
auto lang_code = languages[index].first; auto lang_code = languages[index].first;
possible_shows = searchShow( show, lang_code ); possible_shows = searchShow( show, lang_code );
if ( possible_shows.size() == 0 ) { if ( possible_shows.size() == 0 ) {
MessageBox( window, L"No results found for given show name", L"Error", MessageBox( window, _( NO_RESULTS ), _( ERROR ), MB_OK | MB_ICONERROR );
MB_OK | MB_ICONERROR );
return; return;
} }
@ -254,12 +265,11 @@ void MainWindow::rename() {
SendMessage( dir_input, WM_GETTEXT, ( WPARAM )MAX_PATH - 1, SendMessage( dir_input, WM_GETTEXT, ( WPARAM )MAX_PATH - 1,
( LPARAM )path ); ( LPARAM )path );
if ( wcslen( path ) == 0 ) { if ( wcslen( path ) == 0 ) {
MessageBox( window, L"Directory field is empty", L"Error", MessageBox( window, _( DIR_EMPTY ), _( ERROR ), MB_OK | MB_ICONERROR );
MB_OK | MB_ICONERROR );
return; return;
} }
if ( !FSLib::isDirectory( path ) ) { if ( !FSLib::isDirectory( path ) ) {
MessageBox( window, L"Directory doesn't exist", L"Error", MessageBox( window, _( DIR_NOT_EXIST ), _( ERROR ),
MB_OK | MB_ICONERROR ); MB_OK | MB_ICONERROR );
return; return;
} }
@ -277,20 +287,10 @@ void MainWindow::rename() {
sw.mainLoop(); sw.mainLoop();
auto index = SendMessage( possible_input, CB_GETCURSEL, NULL, NULL ); auto index = SendMessage( possible_input, CB_GETCURSEL, NULL, NULL );
if ( index == CB_ERR ) {
MessageBox( window, L"No show selected", L"Error",
MB_OK | MB_ICONERROR );
return;
}
auto show = possible_shows[index].first; auto show = possible_shows[index].first;
auto show_id = possible_shows[index].second; auto show_id = possible_shows[index].second;
index = SendMessage( language_input, CB_GETCURSEL, NULL, NULL ); index = SendMessage( language_input, CB_GETCURSEL, NULL, NULL );
if ( index == CB_ERR ) {
MessageBox( window, L"No show selected", L"Error",
MB_OK | MB_ICONERROR );
return;
}
auto lang = languages[index].first; auto lang = languages[index].first;
bool dvd = SendMessage( dvd_input, BM_GETCHECK, NULL, NULL ) == BST_CHECKED; bool dvd = SendMessage( dvd_input, BM_GETCHECK, NULL, NULL ) == BST_CHECKED;
@ -327,7 +327,7 @@ void MainWindow::rename() {
std::get< 3 >( file ) + L"\n"; std::get< 3 >( file ) + L"\n";
} }
auto res = MessageBox( window, message_text.c_str(), L"Is this OK?", auto res = MessageBox( window, message_text.c_str(), _( CONFIRMATION ),
MB_OKCANCEL ); MB_OKCANCEL );
if ( res == IDOK ) if ( res == IDOK )
renameFiles( renamed_files ); renameFiles( renamed_files );
@ -339,32 +339,21 @@ void MainWindow::dbAdd() {
SendMessage( dir_input, WM_GETTEXT, ( WPARAM )MAX_PATH - 1, SendMessage( dir_input, WM_GETTEXT, ( WPARAM )MAX_PATH - 1,
( LPARAM )path ); ( LPARAM )path );
if ( wcslen( path ) == 0 ) { if ( wcslen( path ) == 0 ) {
MessageBox( window, L"Directory field is empty", L"Error", MessageBox( window, _( DIR_EMPTY ), _( ERROR ), MB_OK | MB_ICONERROR );
MB_OK | MB_ICONERROR );
return; return;
} }
if ( !FSLib::isDirectory( path ) ) { if ( !FSLib::isDirectory( path ) ) {
MessageBox( window, L"Directory doesn't exist", L"Error", MessageBox( window, _( DIR_NOT_EXIST ), _( ERROR ),
MB_OK | MB_ICONERROR ); MB_OK | MB_ICONERROR );
return; return;
} }
auto index = SendMessage( possible_input, CB_GETCURSEL, NULL, NULL ); auto index = SendMessage( possible_input, CB_GETCURSEL, NULL, NULL );
if ( index == CB_ERR ) {
MessageBox( window, L"No show selected", L"Error",
MB_OK | MB_ICONERROR );
return;
}
auto show = possible_shows[index].first; auto show = possible_shows[index].first;
auto show_id = possible_shows[index].second; auto show_id = possible_shows[index].second;
index = SendMessage( language_input, CB_GETCURSEL, NULL, NULL ); index = SendMessage( language_input, CB_GETCURSEL, NULL, NULL );
if ( index == CB_ERR ) {
MessageBox( window, L"No language selected", L"Error",
MB_OK | MB_ICONERROR );
return;
}
auto lang = languages[index].first; auto lang = languages[index].first;
bool dvd = SendMessage( dvd_input, BM_GETCHECK, NULL, NULL ) == BST_CHECKED; bool dvd = SendMessage( dvd_input, BM_GETCHECK, NULL, NULL ) == BST_CHECKED;
@ -412,20 +401,28 @@ void MainWindow::dbPattern() {
} }
void MainWindow::patternHelp() { void MainWindow::patternHelp() {
MessageBoxW( std::wstring text = L"%filename - ";
NULL, text += _( PATTERN_FILENAME );
L"%filename - original filename (without type extension)\n\n" text += L"\n\n%show - ";
"%show - show name from thetvdb\n\n" text += _( PATTERN_SHOW );
"%epname - episode name from thetvdb\n\n" text += L"\n\n%epname - ";
"%season - season number\n\n" text += _( PATTERN_EPNAME );
"%episode - episode number\n\n" text += L"\n\n%season - ";
"Both season number and episode number can be padded with zeros, just " text += _( PATTERN_SEASON );
"add width of padding" text += L"\n\n%episode - ";
" right after %, like this: %2season.\n\n" text += _( PATTERN_EPISODE );
"Default pattern is \"%filename - %epname\", you might want to change " text += L"\n\n";
"this to" text += _( PATTERN_LEADING_ZERO );
" \"S%2seasonE%2episode - %epname\" or \"%show - S%2seasonE%2episode - " text += L"\n\n";
"%epname\"", text += L" %2season, %2episode - ";
L"Test", MB_OK ); text += _( PATTERN_LEADING_NUM );
text += L"\n";
text += _( PATTERN_DEFAULT );
text += L" \"%filename - %epname\"";
text += _( PATTERN_CHANGE );
text += L" \"S%2seasonE%2episode - %epname\" ";
text += _( OR );
text += L" \"%show - S%2seasonE%2episode - %epname\"";
MessageBoxW( NULL, text.c_str(), _( PATTERN_HELP ), MB_OK );
return; return;
} }