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