windows/databasewindow: localization, remove "hidden" columns
This commit is contained in:
parent
bf5eaa39ea
commit
5e0ba6dbc2
@ -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 "../filesystem.hpp"
|
||||
#include "../functions.hpp"
|
||||
#include "gui_functions.hpp"
|
||||
#include "progresswindow.hpp"
|
||||
#include "searchwindow.hpp"
|
||||
#include "../filesystem.hpp"
|
||||
#include "../functions.hpp"
|
||||
#include "../resources_windows.h"
|
||||
|
||||
#include <commctrl.h>
|
||||
#include <fstream>
|
||||
#include <thread>
|
||||
|
||||
#define ID_LISTVIEW 0x0001
|
||||
@ -18,9 +23,10 @@
|
||||
#define PATH_COLUMN 1
|
||||
#define LANG_COLUMN 2
|
||||
#define DVD_COLUMN 3
|
||||
#define ID_COLUMN 4
|
||||
#define LANG_ID_COLUMN 5
|
||||
#define TVID_COLUMN 6
|
||||
|
||||
#define ID_INDEX 0
|
||||
#define LANG_ID_INDEX 1
|
||||
#define TVID_INDEX 2
|
||||
|
||||
#define database_width( width ) width - 10
|
||||
#define database_height( height ) height - 50
|
||||
@ -34,11 +40,11 @@
|
||||
DatabaseWindow *DatabaseWindow::dw = nullptr;
|
||||
|
||||
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 ) {
|
||||
setListViewItemText( list_hwnd, temp->iItem, temp->iSubItem, L"No" );
|
||||
setListViewItemText( list_hwnd, temp->iItem, temp->iSubItem, _( NO ) );
|
||||
} 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 ) {
|
||||
// need to set this here for WM_NOTIFY to work
|
||||
dw = this;
|
||||
window = CreateWindowW( L"DatabaseWindow", L"Progress",
|
||||
window = CreateWindowW( L"DatabaseWindow", _( DATABASE ),
|
||||
WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT,
|
||||
CW_USEDEFAULT, window_width, window_height, parent,
|
||||
NULL, hInstance, NULL );
|
||||
ShowWindow( window, SW_SHOW );
|
||||
auto hFont = ( HFONT )GetStockObject( DEFAULT_GUI_FONT );
|
||||
EnableWindow( parent, false );
|
||||
setIcons( hInstance, window );
|
||||
|
||||
INITCOMMONCONTROLSEX icex; // Structure for control initialization.
|
||||
icex.dwICC = ICC_LISTVIEW_CLASSES;
|
||||
@ -69,14 +76,10 @@ DatabaseWindow::DatabaseWindow(
|
||||
list_hwnd = createListView( 5, 5, database_width( client_width ),
|
||||
database_height( client_height ), ID_LISTVIEW,
|
||||
window, hFont );
|
||||
addColumnToListView( list_hwnd, L"Show", 90, SHOW_COLUMN );
|
||||
addColumnToListView( list_hwnd, L"Path", 180, PATH_COLUMN );
|
||||
addColumnToListView( list_hwnd, L"Language", 70, LANG_COLUMN );
|
||||
addColumnToListView( list_hwnd, L"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 );
|
||||
addColumnToListView( list_hwnd, _( SHOW ), 90, SHOW_COLUMN );
|
||||
addColumnToListView( list_hwnd, _( PATH ), 180, PATH_COLUMN );
|
||||
addColumnToListView( list_hwnd, _( ID_LANGUAGE ), 70, LANG_COLUMN );
|
||||
addColumnToListView( list_hwnd, _( DVD ), 40, DVD_COLUMN );
|
||||
|
||||
int row{ 0 };
|
||||
|
||||
@ -86,33 +89,29 @@ DatabaseWindow::DatabaseWindow(
|
||||
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, DVD_COLUMN,
|
||||
x[L"DVD"] == L"1" ? L"Yes" : L"No" );
|
||||
addItemToListView( list_hwnd, row, ID_COLUMN, x[L"ID"].c_str() );
|
||||
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';
|
||||
x[L"DVD"] == L"1" ? _( YES ) : _( NO ) );
|
||||
int lang_id = 0;
|
||||
for ( wchar_t i = 0; i < ( wchar_t )languages.size(); i++ ) {
|
||||
if ( x[L"LANGUAGE"] == languages[i].first ) {
|
||||
addItemToListView( list_hwnd, row, LANG_COLUMN,
|
||||
languages[i].second.c_str() );
|
||||
lang_id[0] = i;
|
||||
addItemToListView( list_hwnd, row, LANG_ID_COLUMN, lang_id );
|
||||
lang_id = i;
|
||||
}
|
||||
}
|
||||
show_ids.emplace_back( std::stoi( x[L"ID"].c_str() ), lang_id,
|
||||
x[L"TVID"] );
|
||||
row++;
|
||||
}
|
||||
|
||||
cancel_button = createButton( L"Cancel", cancel_x( client_width ),
|
||||
cancel_button = createButton( _( CANCEL ), cancel_x( client_width ),
|
||||
cancel_y( client_height ), 80, 25,
|
||||
ID_CANCEL_BUTTON, window, hFont );
|
||||
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 );
|
||||
save_button =
|
||||
createButton( L"Save", save_x( client_width ), save_y( client_height ),
|
||||
80, 25, ID_SAVE_BUTTON, window, hFont );
|
||||
save_button = createButton( _( SAVE ), save_x( client_width ),
|
||||
save_y( client_height ), 80, 25, ID_SAVE_BUTTON,
|
||||
window, hFont );
|
||||
|
||||
lang_combo = createCombo( 0, 0, 120, 110, ID_LANG_COMBO, window, hFont );
|
||||
ShowWindow( lang_combo, SW_HIDE );
|
||||
@ -151,19 +150,22 @@ LRESULT CALLBACK DatabaseWindow::messageHandler( HWND hwnd, UINT umsg,
|
||||
ShowWindow( dw->lang_combo, SW_HIDE );
|
||||
break;
|
||||
case CBN_SELCHANGE: {
|
||||
wchar_t lang_id[2];
|
||||
lang_id[1] = '\0';
|
||||
lang_id[0] = getComboCurSel( dw->lang_combo );
|
||||
ShowWindow( dw->lang_combo, SW_HIDE );
|
||||
int lang_id = getComboCurSel( dw->lang_combo );
|
||||
setListViewItemText( dw->list_hwnd, dw->cur_row, LANG_COLUMN,
|
||||
dw->langs[lang_id[0]].second.c_str() );
|
||||
setListViewItemText( dw->list_hwnd, dw->cur_row, LANG_ID_COLUMN,
|
||||
lang_id );
|
||||
dw->langs[lang_id].second.c_str() );
|
||||
std::get< LANG_ID_INDEX >( dw->show_ids[dw->cur_row] ) =
|
||||
lang_id;
|
||||
} break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
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 height = HIWORD( lParam );
|
||||
SetWindowPos( dw->list_hwnd, HWND_TOP, 5, 5, database_width( width ),
|
||||
@ -197,9 +199,8 @@ void DatabaseWindow::mainLoop() {
|
||||
void DatabaseWindow::changed( int index ) {
|
||||
auto path = getItemText( list_hwnd, index, PATH_COLUMN );
|
||||
if ( !FSLib::isDirectory( path ) ) {
|
||||
MessageBox( window,
|
||||
( L"Directory '" + path + L"' doesn't exist" ).c_str(),
|
||||
L"Error", MB_OK | MB_ICONERROR );
|
||||
MessageBox( window, _( DIR_NOT_EXIST ), _( ERROR ),
|
||||
MB_OK | MB_ICONERROR );
|
||||
return;
|
||||
}
|
||||
changed_rows.push_back( index );
|
||||
@ -210,13 +211,12 @@ void DatabaseWindow::save() {
|
||||
return;
|
||||
std::unordered_set< size_t > row_indexes;
|
||||
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 path = getItemText( list_hwnd, row, PATH_COLUMN );
|
||||
auto lang =
|
||||
langs[getItemText( list_hwnd, row, LANG_ID_COLUMN )[0]].first;
|
||||
auto show_id = getItemText( list_hwnd, row, TVID_COLUMN );
|
||||
bool dvd = getItemText( list_hwnd, row, DVD_COLUMN ) == L"Yes";
|
||||
auto lang = langs[std::get< LANG_ID_INDEX >( show_ids[row] )].first;
|
||||
auto show_id = std::get< TVID_INDEX >( show_ids[row] ).c_str();
|
||||
bool dvd = getItemText( list_hwnd, row, DVD_COLUMN ) == _( YES );
|
||||
changeDB( index, path, lang, show_id, dvd );
|
||||
row_indexes.insert( index );
|
||||
}
|
||||
@ -241,24 +241,20 @@ void DatabaseWindow::listNotify( LPARAM lParam ) {
|
||||
break;
|
||||
switch ( temp->iSubItem ) {
|
||||
case SHOW_COLUMN: {
|
||||
auto lang_id =
|
||||
getItemText( list_hwnd, temp->iItem, LANG_ID_COLUMN );
|
||||
auto lang_id = std::get< LANG_ID_INDEX >( show_ids[temp->iItem] );
|
||||
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();
|
||||
// test if user clicke OK
|
||||
if ( sw.accepted() ) {
|
||||
setListViewItemText( list_hwnd, temp->iItem, SHOW_COLUMN,
|
||||
sw.getShow().c_str() );
|
||||
setListViewItemText( list_hwnd, temp->iItem, TVID_COLUMN,
|
||||
sw.getShowID().c_str() );
|
||||
std::get< TVID_INDEX >( show_ids[temp->iItem] ) =
|
||||
sw.getShowID();
|
||||
setListViewItemText( list_hwnd, temp->iItem, LANG_COLUMN,
|
||||
langs[sw.getLangID()].second.c_str() );
|
||||
wchar_t langid[2];
|
||||
langid[1] = '\0';
|
||||
langid[0] = sw.getLangID();
|
||||
setListViewItemText( list_hwnd, temp->iItem, LANG_ID_COLUMN,
|
||||
langid );
|
||||
std::get< LANG_ID_INDEX >( show_ids[temp->iItem] ) =
|
||||
sw.getLangID();
|
||||
}
|
||||
} break;
|
||||
case PATH_COLUMN: {
|
||||
@ -272,13 +268,13 @@ void DatabaseWindow::listNotify( LPARAM lParam ) {
|
||||
cur_row = temp->iItem;
|
||||
ListView_GetSubItemRect( list_hwnd, temp->iItem, temp->iSubItem,
|
||||
LVIR_BOUNDS, &item_rect );
|
||||
SetWindowPos( lang_combo, HWND_TOP, item_rect.left, item_rect.top,
|
||||
item_rect.right - item_rect.left, window_height,
|
||||
NULL );
|
||||
SetWindowPos( lang_combo, HWND_TOP, item_rect.left + 5,
|
||||
item_rect.top + 5, item_rect.right - item_rect.left,
|
||||
window_height, NULL );
|
||||
ShowWindow( lang_combo, SW_SHOW );
|
||||
SetFocus( lang_combo );
|
||||
auto id = getItemText( list_hwnd, temp->iItem, LANG_ID_COLUMN );
|
||||
SendMessage( lang_combo, CB_SETCURSEL, id[0], NULL );
|
||||
auto id = std::get< LANG_ID_INDEX >( show_ids[temp->iItem] );
|
||||
SendMessage( lang_combo, CB_SETCURSEL, id, NULL );
|
||||
} break;
|
||||
case DVD_COLUMN:
|
||||
toggleDVD( temp, list_hwnd );
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <windows.h>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
class DatabaseWindow {
|
||||
public:
|
||||
@ -25,10 +26,10 @@ private:
|
||||
|
||||
HWND window;
|
||||
HWND lang_combo;
|
||||
HWND list_hwnd;
|
||||
HWND cancel_button;
|
||||
HWND ok_button;
|
||||
HWND save_button;
|
||||
HWND list_hwnd{ nullptr };
|
||||
HWND cancel_button{ nullptr };
|
||||
HWND ok_button{ nullptr };
|
||||
HWND save_button{ nullptr };
|
||||
HWND parent;
|
||||
HINSTANCE hInst;
|
||||
int cur_row;
|
||||
@ -36,5 +37,6 @@ private:
|
||||
const int window_height{ 370 };
|
||||
std::vector< int > changed_rows;
|
||||
const std::vector< std::pair< std::wstring, std::wstring > > &langs;
|
||||
std::vector< std::tuple< int, int, std::wstring > > show_ids;
|
||||
static DatabaseWindow *dw;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user