windows/databasewindow: localization, remove "hidden" columns

This commit is contained in:
zvon 2020-04-01 13:50:05 +02:00
parent bf5eaa39ea
commit 5e0ba6dbc2
2 changed files with 64 additions and 66 deletions

View File

@ -1,11 +1,16 @@
#pragma comment( linker, "\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"" )
#include "databasewindow.hpp" #include "databasewindow.hpp"
#include "../filesystem.hpp"
#include "../functions.hpp"
#include "gui_functions.hpp" #include "gui_functions.hpp"
#include "progresswindow.hpp" #include "progresswindow.hpp"
#include "searchwindow.hpp" #include "searchwindow.hpp"
#include "../filesystem.hpp"
#include "../functions.hpp"
#include "../resources_windows.h"
#include <commctrl.h> #include <commctrl.h>
#include <fstream>
#include <thread> #include <thread>
#define ID_LISTVIEW 0x0001 #define ID_LISTVIEW 0x0001
@ -18,9 +23,10 @@
#define PATH_COLUMN 1 #define PATH_COLUMN 1
#define LANG_COLUMN 2 #define LANG_COLUMN 2
#define DVD_COLUMN 3 #define DVD_COLUMN 3
#define ID_COLUMN 4
#define LANG_ID_COLUMN 5 #define ID_INDEX 0
#define TVID_COLUMN 6 #define LANG_ID_INDEX 1
#define TVID_INDEX 2
#define database_width( width ) width - 10 #define database_width( width ) width - 10
#define database_height( height ) height - 50 #define database_height( height ) height - 50
@ -34,11 +40,11 @@
DatabaseWindow *DatabaseWindow::dw = nullptr; DatabaseWindow *DatabaseWindow::dw = nullptr;
void toggleDVD( LPNMITEMACTIVATE temp, HWND list_hwnd ) { void toggleDVD( LPNMITEMACTIVATE temp, HWND list_hwnd ) {
auto dvd = getItemText( list_hwnd, temp->iItem, temp->iSubItem ) != L"No"; auto dvd = getItemText( list_hwnd, temp->iItem, temp->iSubItem ) != _( NO );
if ( dvd ) { if ( dvd ) {
setListViewItemText( list_hwnd, temp->iItem, temp->iSubItem, L"No" ); setListViewItemText( list_hwnd, temp->iItem, temp->iSubItem, _( NO ) );
} else { } else {
setListViewItemText( list_hwnd, temp->iItem, temp->iSubItem, L"Yes" ); setListViewItemText( list_hwnd, temp->iItem, temp->iSubItem, _( YES ) );
} }
} }
@ -49,13 +55,14 @@ DatabaseWindow::DatabaseWindow(
: parent( parent_window ), hInst( hInstance ), langs( languages ) { : parent( parent_window ), hInst( hInstance ), langs( languages ) {
// need to set this here for WM_NOTIFY to work // need to set this here for WM_NOTIFY to work
dw = this; dw = this;
window = CreateWindowW( L"DatabaseWindow", L"Progress", window = CreateWindowW( L"DatabaseWindow", _( DATABASE ),
WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT,
CW_USEDEFAULT, window_width, window_height, parent, CW_USEDEFAULT, window_width, window_height, parent,
NULL, hInstance, NULL ); NULL, hInstance, NULL );
ShowWindow( window, SW_SHOW ); ShowWindow( window, SW_SHOW );
auto hFont = ( HFONT )GetStockObject( DEFAULT_GUI_FONT ); auto hFont = ( HFONT )GetStockObject( DEFAULT_GUI_FONT );
EnableWindow( parent, false ); EnableWindow( parent, false );
setIcons( hInstance, window );
INITCOMMONCONTROLSEX icex; // Structure for control initialization. INITCOMMONCONTROLSEX icex; // Structure for control initialization.
icex.dwICC = ICC_LISTVIEW_CLASSES; icex.dwICC = ICC_LISTVIEW_CLASSES;
@ -69,14 +76,10 @@ DatabaseWindow::DatabaseWindow(
list_hwnd = createListView( 5, 5, database_width( client_width ), list_hwnd = createListView( 5, 5, database_width( client_width ),
database_height( client_height ), ID_LISTVIEW, database_height( client_height ), ID_LISTVIEW,
window, hFont ); window, hFont );
addColumnToListView( list_hwnd, L"Show", 90, SHOW_COLUMN ); addColumnToListView( list_hwnd, _( SHOW ), 90, SHOW_COLUMN );
addColumnToListView( list_hwnd, L"Path", 180, PATH_COLUMN ); addColumnToListView( list_hwnd, _( PATH ), 180, PATH_COLUMN );
addColumnToListView( list_hwnd, L"Language", 70, LANG_COLUMN ); addColumnToListView( list_hwnd, _( ID_LANGUAGE ), 70, LANG_COLUMN );
addColumnToListView( list_hwnd, L"DVD", 40, DVD_COLUMN ); addColumnToListView( list_hwnd, _( DVD ), 40, DVD_COLUMN );
// create hidden columns
addColumnToListView( list_hwnd, L"ID", 0, ID_COLUMN );
addColumnToListView( list_hwnd, L"LangID", 0, LANG_ID_COLUMN );
addColumnToListView( list_hwnd, L"TVID", 0, TVID_COLUMN );
int row{ 0 }; int row{ 0 };
@ -86,33 +89,29 @@ DatabaseWindow::DatabaseWindow(
addItemToListView( list_hwnd, row, SHOW_COLUMN, x[L"SHOW"].c_str() ); addItemToListView( list_hwnd, row, SHOW_COLUMN, x[L"SHOW"].c_str() );
addItemToListView( list_hwnd, row, PATH_COLUMN, x[L"PATH"].c_str() ); addItemToListView( list_hwnd, row, PATH_COLUMN, x[L"PATH"].c_str() );
addItemToListView( list_hwnd, row, DVD_COLUMN, addItemToListView( list_hwnd, row, DVD_COLUMN,
x[L"DVD"] == L"1" ? L"Yes" : L"No" ); x[L"DVD"] == L"1" ? _( YES ) : _( NO ) );
addItemToListView( list_hwnd, row, ID_COLUMN, x[L"ID"].c_str() ); int lang_id = 0;
addItemToListView( list_hwnd, row, TVID_COLUMN, x[L"TVID"].c_str() );
// lang_id[0] will be index of the language
wchar_t lang_id[2];
lang_id[1] = '\0';
for ( wchar_t i = 0; i < ( wchar_t )languages.size(); i++ ) { for ( wchar_t i = 0; i < ( wchar_t )languages.size(); i++ ) {
if ( x[L"LANGUAGE"] == languages[i].first ) { if ( x[L"LANGUAGE"] == languages[i].first ) {
addItemToListView( list_hwnd, row, LANG_COLUMN, addItemToListView( list_hwnd, row, LANG_COLUMN,
languages[i].second.c_str() ); languages[i].second.c_str() );
lang_id[0] = i; lang_id = i;
addItemToListView( list_hwnd, row, LANG_ID_COLUMN, lang_id );
} }
} }
show_ids.emplace_back( std::stoi( x[L"ID"].c_str() ), lang_id,
x[L"TVID"] );
row++; row++;
} }
cancel_button = createButton( L"Cancel", cancel_x( client_width ), cancel_button = createButton( _( CANCEL ), cancel_x( client_width ),
cancel_y( client_height ), 80, 25, cancel_y( client_height ), 80, 25,
ID_CANCEL_BUTTON, window, hFont ); ID_CANCEL_BUTTON, window, hFont );
ok_button = ok_button =
createButton( L"OK", ok_x( client_width ), ok_y( client_height ), 80, createButton( _( OK ), ok_x( client_width ), ok_y( client_height ), 80,
25, ID_OK_BUTTON, window, hFont ); 25, ID_OK_BUTTON, window, hFont );
save_button = save_button = createButton( _( SAVE ), save_x( client_width ),
createButton( L"Save", save_x( client_width ), save_y( client_height ), save_y( client_height ), 80, 25, ID_SAVE_BUTTON,
80, 25, ID_SAVE_BUTTON, window, hFont ); window, hFont );
lang_combo = createCombo( 0, 0, 120, 110, ID_LANG_COMBO, window, hFont ); lang_combo = createCombo( 0, 0, 120, 110, ID_LANG_COMBO, window, hFont );
ShowWindow( lang_combo, SW_HIDE ); ShowWindow( lang_combo, SW_HIDE );
@ -151,19 +150,22 @@ LRESULT CALLBACK DatabaseWindow::messageHandler( HWND hwnd, UINT umsg,
ShowWindow( dw->lang_combo, SW_HIDE ); ShowWindow( dw->lang_combo, SW_HIDE );
break; break;
case CBN_SELCHANGE: { case CBN_SELCHANGE: {
wchar_t lang_id[2]; ShowWindow( dw->lang_combo, SW_HIDE );
lang_id[1] = '\0'; int lang_id = getComboCurSel( dw->lang_combo );
lang_id[0] = getComboCurSel( dw->lang_combo );
setListViewItemText( dw->list_hwnd, dw->cur_row, LANG_COLUMN, setListViewItemText( dw->list_hwnd, dw->cur_row, LANG_COLUMN,
dw->langs[lang_id[0]].second.c_str() ); dw->langs[lang_id].second.c_str() );
setListViewItemText( dw->list_hwnd, dw->cur_row, LANG_ID_COLUMN, std::get< LANG_ID_INDEX >( dw->show_ids[dw->cur_row] ) =
lang_id ); lang_id;
} break; } break;
} }
break; break;
} }
break; break;
case WM_SIZE: { case WM_SIZE: {
if ( dw->list_hwnd == nullptr || dw->cancel_button == nullptr ||
dw->ok_button == nullptr || dw->save_button == nullptr )
break;
ShowWindow( dw->lang_combo, SW_HIDE );
auto width = LOWORD( lParam ); auto width = LOWORD( lParam );
auto height = HIWORD( lParam ); auto height = HIWORD( lParam );
SetWindowPos( dw->list_hwnd, HWND_TOP, 5, 5, database_width( width ), SetWindowPos( dw->list_hwnd, HWND_TOP, 5, 5, database_width( width ),
@ -197,9 +199,8 @@ void DatabaseWindow::mainLoop() {
void DatabaseWindow::changed( int index ) { void DatabaseWindow::changed( int index ) {
auto path = getItemText( list_hwnd, index, PATH_COLUMN ); auto path = getItemText( list_hwnd, index, PATH_COLUMN );
if ( !FSLib::isDirectory( path ) ) { if ( !FSLib::isDirectory( path ) ) {
MessageBox( window, MessageBox( window, _( DIR_NOT_EXIST ), _( ERROR ),
( L"Directory '" + path + L"' doesn't exist" ).c_str(), MB_OK | MB_ICONERROR );
L"Error", MB_OK | MB_ICONERROR );
return; return;
} }
changed_rows.push_back( index ); changed_rows.push_back( index );
@ -210,13 +211,12 @@ void DatabaseWindow::save() {
return; return;
std::unordered_set< size_t > row_indexes; std::unordered_set< size_t > row_indexes;
for ( auto &row : changed_rows ) { for ( auto &row : changed_rows ) {
auto index = std::stoi( getItemText( list_hwnd, row, ID_COLUMN ) ); auto index = std::get< ID_INDEX >( show_ids[row] );
auto show = getItemText( list_hwnd, row, SHOW_COLUMN ); auto show = getItemText( list_hwnd, row, SHOW_COLUMN );
auto path = getItemText( list_hwnd, row, PATH_COLUMN ); auto path = getItemText( list_hwnd, row, PATH_COLUMN );
auto lang = auto lang = langs[std::get< LANG_ID_INDEX >( show_ids[row] )].first;
langs[getItemText( list_hwnd, row, LANG_ID_COLUMN )[0]].first; auto show_id = std::get< TVID_INDEX >( show_ids[row] ).c_str();
auto show_id = getItemText( list_hwnd, row, TVID_COLUMN ); bool dvd = getItemText( list_hwnd, row, DVD_COLUMN ) == _( YES );
bool dvd = getItemText( list_hwnd, row, DVD_COLUMN ) == L"Yes";
changeDB( index, path, lang, show_id, dvd ); changeDB( index, path, lang, show_id, dvd );
row_indexes.insert( index ); row_indexes.insert( index );
} }
@ -241,24 +241,20 @@ void DatabaseWindow::listNotify( LPARAM lParam ) {
break; break;
switch ( temp->iSubItem ) { switch ( temp->iSubItem ) {
case SHOW_COLUMN: { case SHOW_COLUMN: {
auto lang_id = auto lang_id = std::get< LANG_ID_INDEX >( show_ids[temp->iItem] );
getItemText( list_hwnd, temp->iItem, LANG_ID_COLUMN );
auto show = getItemText( list_hwnd, temp->iItem, SHOW_COLUMN ); auto show = getItemText( list_hwnd, temp->iItem, SHOW_COLUMN );
SearchWindow sw( hInst, langs, lang_id[0], show.c_str(), window ); SearchWindow sw( hInst, langs, lang_id, show.c_str(), window );
sw.mainLoop(); sw.mainLoop();
// test if user clicke OK // test if user clicke OK
if ( sw.accepted() ) { if ( sw.accepted() ) {
setListViewItemText( list_hwnd, temp->iItem, SHOW_COLUMN, setListViewItemText( list_hwnd, temp->iItem, SHOW_COLUMN,
sw.getShow().c_str() ); sw.getShow().c_str() );
setListViewItemText( list_hwnd, temp->iItem, TVID_COLUMN, std::get< TVID_INDEX >( show_ids[temp->iItem] ) =
sw.getShowID().c_str() ); sw.getShowID();
setListViewItemText( list_hwnd, temp->iItem, LANG_COLUMN, setListViewItemText( list_hwnd, temp->iItem, LANG_COLUMN,
langs[sw.getLangID()].second.c_str() ); langs[sw.getLangID()].second.c_str() );
wchar_t langid[2]; std::get< LANG_ID_INDEX >( show_ids[temp->iItem] ) =
langid[1] = '\0'; sw.getLangID();
langid[0] = sw.getLangID();
setListViewItemText( list_hwnd, temp->iItem, LANG_ID_COLUMN,
langid );
} }
} break; } break;
case PATH_COLUMN: { case PATH_COLUMN: {
@ -272,13 +268,13 @@ void DatabaseWindow::listNotify( LPARAM lParam ) {
cur_row = temp->iItem; cur_row = temp->iItem;
ListView_GetSubItemRect( list_hwnd, temp->iItem, temp->iSubItem, ListView_GetSubItemRect( list_hwnd, temp->iItem, temp->iSubItem,
LVIR_BOUNDS, &item_rect ); LVIR_BOUNDS, &item_rect );
SetWindowPos( lang_combo, HWND_TOP, item_rect.left, item_rect.top, SetWindowPos( lang_combo, HWND_TOP, item_rect.left + 5,
item_rect.right - item_rect.left, window_height, item_rect.top + 5, item_rect.right - item_rect.left,
NULL ); window_height, NULL );
ShowWindow( lang_combo, SW_SHOW ); ShowWindow( lang_combo, SW_SHOW );
SetFocus( lang_combo ); SetFocus( lang_combo );
auto id = getItemText( list_hwnd, temp->iItem, LANG_ID_COLUMN ); auto id = std::get< LANG_ID_INDEX >( show_ids[temp->iItem] );
SendMessage( lang_combo, CB_SETCURSEL, id[0], NULL ); SendMessage( lang_combo, CB_SETCURSEL, id, NULL );
} break; } break;
case DVD_COLUMN: case DVD_COLUMN:
toggleDVD( temp, list_hwnd ); toggleDVD( temp, list_hwnd );

View File

@ -1,6 +1,7 @@
#include <string>
#include <vector>
#include <windows.h> #include <windows.h>
#include <string>
#include <tuple>
#include <vector>
class DatabaseWindow { class DatabaseWindow {
public: public:
@ -25,10 +26,10 @@ private:
HWND window; HWND window;
HWND lang_combo; HWND lang_combo;
HWND list_hwnd; HWND list_hwnd{ nullptr };
HWND cancel_button; HWND cancel_button{ nullptr };
HWND ok_button; HWND ok_button{ nullptr };
HWND save_button; HWND save_button{ nullptr };
HWND parent; HWND parent;
HINSTANCE hInst; HINSTANCE hInst;
int cur_row; int cur_row;
@ -36,5 +37,6 @@ private:
const int window_height{ 370 }; const int window_height{ 370 };
std::vector< int > changed_rows; std::vector< int > changed_rows;
const std::vector< std::pair< std::wstring, std::wstring > > &langs; const std::vector< std::pair< std::wstring, std::wstring > > &langs;
std::vector< std::tuple< int, int, std::wstring > > show_ids;
static DatabaseWindow *dw; static DatabaseWindow *dw;
}; };