Skip to content

Commit f70b590

Browse files
committed
Implement messageBox function for script API in qimageuploader
1 parent 3387f2c commit f70b590

24 files changed

+291
-129
lines changed

Dist/create_build.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def write_json_header(jsonfile, json_builds_file_name, source_dir, version_heade
151151
json_builds_data = {
152152

153153
}
154-
last_commit_hash = json_builds_data.get("last_commit_hash");
154+
last_commit_hash = json_builds_data.get("last_commit_hash")
155155

156156
json_builds_data["last_commit_hash"] = version_header_defines['IU_COMMIT_HASH']
157157

@@ -438,14 +438,15 @@ def modify_update_file(component_name, filepath, version_header_defines, json_da
438438
shutil.copyfile("../Source/versioninfo.h.dist", VERSION_HEADER_FILE)
439439

440440
version_file_abs_path = os.path.abspath(VERSION_HEADER_FILE)
441-
version_header_defines = generate_version_header(VERSION_HEADER_FILE, True)
441+
generate_version_header(VERSION_HEADER_FILE, True)
442442
repo_dir_abs = os.path.abspath(repo_dir)
443443
shutil.copyfile(VERSION_HEADER_FILE, repo_dir + "/Source/" + VERSION_HEADER_FILE)
444-
app_ver = version_header_defines["IU_APP_VER"]
445-
build_number = version_header_defines["IU_BUILD_NUMBER"]
444+
446445
dist_directory = os.path.dirname(os.path.realpath(__file__))
447446
#with cwd(repo_dir):
448-
generate_version_header(repo_dir_abs + "/Source/" + VERSION_HEADER_FILE, False)
447+
version_header_defines = generate_version_header(repo_dir_abs + "/Source/" + VERSION_HEADER_FILE, False)
448+
app_ver = version_header_defines["IU_APP_VER"]
449+
build_number = version_header_defines["IU_BUILD_NUMBER"]
449450

450451
proc = subprocess.run("wsl -e /bin/bash generate_mo.sh", cwd=repo_dir_abs + "/Lang/")
451452
if proc.returncode !=0:

Source/CLI/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ add_executable(CLI
99
ConsoleScriptDialogProvider.cpp
1010
ConsoleScriptDialogProvider.h
1111
../Core/Settings/CliSettings.cpp
12+
ConsoleScriptFunctionsImpl.cpp
1213
${RESOURCE_LIST}
1314
)
1415

Source/CLI/ConsoleScriptDialogProvider.cpp

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#include "ConsoleScriptDialogProvider.h"
22

3+
#include <iostream>
4+
#include <map>
5+
36
#include "Core/Network/NetworkClient.h"
47
#include "Core/Utils/DesktopUtils.h"
58
#include "Core/Utils/CoreUtils.h"
69
#include "Core/Utils/ConsoleUtils.h"
7-
#include <iostream>
10+
#include "Core/Utils/StringUtils.h"
811

912
std::string ConsoleScriptDialogProvider::askUserCaptcha(NetworkClient* nm, const std::string& url) {
1013
std::lock_guard<std::mutex> guard(ConsoleUtils::instance()->getOutputMutex());
@@ -27,3 +30,39 @@ std::string ConsoleScriptDialogProvider::inputDialog(const std::string& text, co
2730
std::cin >> result;
2831
return result;
2932
}
33+
34+
std::string ConsoleScriptDialogProvider::messageBox(const std::string& message, const std::string& title, const std::string& buttons, const std::string& type) {
35+
std::cerr << "----------";
36+
#ifdef _WIN32
37+
std::wcerr << IuCoreUtils::Utf8ToWstring(title);
38+
#else
39+
std::cerr << IuCoreUtils::Utf8ToSystemLocale(title);
40+
#endif
41+
std::cerr << "----------" << std::endl;
42+
#ifdef _WIN32
43+
std::wcerr << IuCoreUtils::Utf8ToWstring(message) << std::endl;;
44+
#else
45+
std::cerr << IuCoreUtils::Utf8ToSystemLocale(message) << std::endl;;
46+
#endif
47+
if (buttons.empty() || buttons == "OK") {
48+
getc(stdin);
49+
return "OK";
50+
}
51+
else {
52+
std::vector<std::string> tokens;
53+
std::map<char, std::string> buttonsMap;
54+
IuStringUtils::Split(buttons, "_", tokens, 10);
55+
for (int i = 0; i < tokens.size(); i++) {
56+
if (i != 0) {
57+
std::cerr << "/";
58+
}
59+
buttonsMap[tokens[i][0]] = tokens[i];
60+
std::cerr << "(" << tokens[i][0] << ")" << IuStringUtils::toLower(tokens[i]).c_str() + 1;
61+
}
62+
std::cerr << ": ";
63+
char res;
64+
std::cin >> res;
65+
res = toupper(res);
66+
return buttonsMap[res];
67+
}
68+
}

Source/CLI/ConsoleScriptDialogProvider.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
class ConsoleScriptDialogProvider : public IDialogProvider {
77
public:
8-
virtual std::string askUserCaptcha(NetworkClient *nm, const std::string& url) override;
9-
virtual std::string inputDialog(const std::string& text, const std::string& defaultValue) override;
8+
std::string askUserCaptcha(NetworkClient *nm, const std::string& url) override;
9+
std::string inputDialog(const std::string& text, const std::string& defaultValue) override;
10+
std::string ConsoleScriptDialogProvider::messageBox(const std::string& message, const std::string& title, const std::string& buttons, const std::string& type) override;
1011
};
11-
#endif
12+
#endif
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
#include "Core/Scripting/API/ScriptFunctionsImpl.h"
3+
4+
#include "Core/Utils/StringUtils.h"
5+
6+
namespace ScriptAPI::Impl {
7+
8+
std::string GetAppLanguageImpl() {
9+
return "en";
10+
}
11+
12+
std::string GetAppLocaleImpl() {
13+
return "en_US";
14+
}
15+
16+
}

Source/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
3737
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})
3838

3939
if (MSVC)
40-
add_definitions("/MP")
40+
# add_definitions("/MP")
4141
add_compile_options(/wd4091) # disable warning C4091: 'typedef ': ignored on left of '*' when no variable is declared
4242
endif()
4343

@@ -411,4 +411,4 @@ if(IU_BUILD_QIMAGEUPLOADER)
411411
add_subdirectory(qimageuploader)
412412
endif()
413413
#enable_testing()
414-
add_subdirectory(Tests)
414+
add_subdirectory(Tests)

Source/Core/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ if (IU_ENABLE_WEBVIEW2)
288288
target_link_libraries(iucore PUBLIC WebView2LoaderStatic.lib version.lib)
289289
endif()
290290

291-
if(MSVC)
292-
target_compile_options(iucore PRIVATE "/MP")
293-
endif()
291+
#if(MSVC)
292+
# target_compile_options(iucore PRIVATE "/MP")
293+
#endif()
294294

295295
set_target_properties(iucore PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib/)

Source/Core/Scripting/API/Functions.cpp

Lines changed: 5 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include "Core/i18n/Translator.h"
5454
#include "Core/Settings/BasicSettings.h"
5555
#include "Core/Utils/SystemUtils.h"
56+
#include "ScriptFunctionsImpl.h"
5657

5758
using namespace Sqrat;
5859

@@ -85,7 +86,7 @@ Sqrat::Table GetAppVersion() {
8586
return res;
8687
}
8788

88-
const std::string GetCurrentScriptFileName()
89+
std::string GetCurrentScriptFileName()
8990
{
9091
return GetScriptName(GetCurrentThreadVM());
9192
}
@@ -183,7 +184,6 @@ std::string InputDialog(const std::string& text, const std::string& defaultValue
183184
return ServiceLocator::instance()->dialogProvider()->inputDialog(text, defaultValue);
184185
}
185186

186-
187187
std::string GetFileMimeType(const std::string& filename)
188188
{
189189
return IuCoreUtils::GetFileMimeType(filename);
@@ -265,94 +265,8 @@ void DebugMessage(const std::string& msg, bool isResponseBody) {
265265
ServiceLocator::instance()->uploadErrorHandler()->DebugMessage(msg,isResponseBody);
266266
}
267267

268-
std::string MessageBox( const std::string& message, const std::string &title,const std::string& buttons , const std::string& type) {
269-
#if defined(_WIN32) && !defined(IU_CLI)
270-
UINT uButtons = MB_OK;
271-
if ( buttons == "ABORT_RETRY_IGNORE") {
272-
uButtons = MB_ABORTRETRYIGNORE;
273-
} else if ( buttons == "CANCEL_TRY_CONTINUE") {
274-
uButtons = MB_CANCELTRYCONTINUE;
275-
} else if ( buttons == "OK_CANCEL") {
276-
uButtons = MB_OKCANCEL;
277-
} else if ( buttons == "RETRY_CANCEL") {
278-
uButtons = MB_RETRYCANCEL;
279-
} else if ( buttons == "YES_NO") {
280-
uButtons = MB_YESNO;
281-
}else if ( buttons == "YES_NO_CANCEL") {
282-
uButtons = MB_YESNOCANCEL;
283-
}
284-
UINT icon = 0;
285-
if ( type == "EXCLAMATION") {
286-
icon = MB_ICONEXCLAMATION;
287-
} else if ( type == "WARNING") {
288-
icon = MB_ICONWARNING;
289-
} else if ( type == "INFORMATION") {
290-
icon = MB_ICONINFORMATION;
291-
} else if ( type == "QUESTION") {
292-
icon = MB_ICONQUESTION;
293-
} else if ( type == "ERROR") {
294-
icon = MB_ICONERROR;
295-
}
296-
int res = ::MessageBox(GetActiveWindow(), IuCoreUtils::Utf8ToWstring(message).c_str(), IuCoreUtils::Utf8ToWstring(title).c_str(), uButtons |icon );
297-
if ( res == IDABORT ) {
298-
return "ABORT";
299-
} else if ( res == IDCANCEL ) {
300-
return "CANCEL";
301-
} else if ( res == IDCONTINUE ) {
302-
return "CONTINUE";
303-
} else if ( res == IDIGNORE ) {
304-
return "IGNORE";
305-
} else if ( res == IDNO ) {
306-
return "NO";
307-
} else if ( res == IDOK ) {
308-
return "OK";
309-
} else if ( res == IDYES ) {
310-
return "YES";
311-
}
312-
else if ( res == IDRETRY ) {
313-
return "TRY";
314-
} else if ( res == IDTRYAGAIN ) {
315-
return "TRY";
316-
}
317-
return "";
318-
319-
#else
320-
std::cerr<<"----------";
321-
#ifdef _WIN32
322-
std::wcerr<<IuCoreUtils::Utf8ToWstring(title);
323-
#else
324-
std::cerr<<IuCoreUtils::Utf8ToSystemLocale(title);
325-
#endif
326-
std::cerr<<"----------"<<std::endl;
327-
#ifdef _WIN32
328-
std::wcerr<<IuCoreUtils::Utf8ToWstring(message)<<std::endl;;
329-
#else
330-
std::cerr<<IuCoreUtils::Utf8ToSystemLocale(message)<<std::endl;;
331-
#endif
332-
if ( buttons.empty() || buttons == "OK") {
333-
getc(stdin);
334-
return "OK";
335-
} else {
336-
337-
338-
std::vector<std::string> tokens;
339-
std::map<char,std::string> buttonsMap;
340-
IuStringUtils::Split(buttons,"_", tokens,10);
341-
for(int i = 0; i< tokens.size(); i++ ) {
342-
if ( i !=0 ) {
343-
std::cerr<< "/";
344-
}
345-
buttonsMap[tokens[i][0]] = tokens[i];
346-
std::cerr<< "("<<tokens[i][0]<<")"<<IuStringUtils::toLower(tokens[i]).c_str()+1;
347-
}
348-
std::cerr<<": ";
349-
char res;
350-
std::cin >> res;
351-
res = toupper(res);
352-
return buttonsMap[res];
353-
}
354-
355-
#endif
268+
std::string MessageBox(const std::string& message, const std::string& title, const std::string& buttons, const std::string& type) {
269+
return ServiceLocator::instance()->dialogProvider()->messageBox(message, title, buttons, type);
356270
}
357271

358272
void parseJSONObj(const Json::Value& root, Sqrat::Array& obj);
@@ -504,15 +418,7 @@ int64_t ScriptGetFileSize(const std::string& filename) {
504418
}
505419

506420
std::string GetAppLanguage() {
507-
#ifndef IU_CLI
508-
ITranslator* translator = ServiceLocator::instance()->translator();
509-
if ( !translator ) {
510-
LOG(ERROR) << "No translator set";
511-
} else {
512-
return translator->getCurrentLanguage();
513-
}
514-
#endif
515-
return "en";
421+
return Impl::GetAppLanguageImpl();
516422
}
517423

518424
std::string GetAppLocale() {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#pragma once
2+
3+
#include <string>
4+
5+
namespace ScriptAPI::Impl{
6+
std::string GetAppLanguageImpl();
7+
std::string GetAppLocaleImpl();
8+
}

Source/Core/Scripting/DialogProvider.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ class IDialogProvider {
1313
virtual ~IDialogProvider() = default;
1414
virtual std::string askUserCaptcha(NetworkClient *nm, const std::string& url) = 0;
1515
virtual std::string inputDialog(const std::string& text, const std::string& defaultValue) = 0;
16+
virtual std::string messageBox(const std::string& message, const std::string& title, const std::string& buttons, const std::string& type) = 0;
17+
1618
std::mutex& getMutex() { return dialogMutex_; }
1719
protected:
1820
std::mutex dialogMutex_;
1921
};
2022

21-
#endif
23+
#endif

Source/Func/WtlScriptDialogProvider.cpp

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,56 @@ std::string WtlScriptDialogProvider::inputDialog(const std::string& text, const
3030
return W2U(dlg.getValue());
3131
}
3232
return {};
33-
}
33+
}
34+
35+
std::string WtlScriptDialogProvider::messageBox(const std::string& message, const std::string& title, const std::string& buttons, const std::string& type) {
36+
UINT uButtons = MB_OK;
37+
if (buttons == "ABORT_RETRY_IGNORE") {
38+
uButtons = MB_ABORTRETRYIGNORE;
39+
} else if (buttons == "CANCEL_TRY_CONTINUE") {
40+
uButtons = MB_CANCELTRYCONTINUE;
41+
} else if (buttons == "OK_CANCEL") {
42+
uButtons = MB_OKCANCEL;
43+
} else if (buttons == "RETRY_CANCEL") {
44+
uButtons = MB_RETRYCANCEL;
45+
} else if (buttons == "YES_NO") {
46+
uButtons = MB_YESNO;
47+
} else if (buttons == "YES_NO_CANCEL") {
48+
uButtons = MB_YESNOCANCEL;
49+
}
50+
UINT icon = 0;
51+
if (type == "EXCLAMATION") {
52+
icon = MB_ICONEXCLAMATION;
53+
} else if (type == "WARNING") {
54+
icon = MB_ICONWARNING;
55+
} else if (type == "INFORMATION") {
56+
icon = MB_ICONINFORMATION;
57+
} else if (type == "QUESTION") {
58+
icon = MB_ICONQUESTION;
59+
} else if (type == "ERROR") {
60+
icon = MB_ICONERROR;
61+
}
62+
IProgramWindow* window = ServiceLocator::instance()->programWindow();
63+
64+
int res = ::MessageBox(window ? window->getHandle() : ::GetActiveWindow(), IuCoreUtils::Utf8ToWstring(message).c_str(), IuCoreUtils::Utf8ToWstring(title).c_str(), uButtons | icon);
65+
if (res == IDABORT) {
66+
return "ABORT";
67+
} else if (res == IDCANCEL) {
68+
return "CANCEL";
69+
} else if (res == IDCONTINUE) {
70+
return "CONTINUE";
71+
} else if (res == IDIGNORE) {
72+
return "IGNORE";
73+
} else if (res == IDNO) {
74+
return "NO";
75+
} else if (res == IDOK) {
76+
return "OK";
77+
} else if (res == IDYES) {
78+
return "YES";
79+
} else if (res == IDRETRY) {
80+
return "TRY";
81+
} else if (res == IDTRYAGAIN) {
82+
return "TRY";
83+
}
84+
return {};
85+
}

Source/Func/WtlScriptDialogProvider.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ class WtlScriptDialogProvider : public IDialogProvider {
77
public:
88
std::string askUserCaptcha(NetworkClient *nm, const std::string& url) override;
99
std::string inputDialog(const std::string& text, const std::string& defaultValue) override;
10+
std::string messageBox(const std::string& message, const std::string& title, const std::string& buttons, const std::string& type) override;
11+
1012
};
11-
#endif
13+
#endif

0 commit comments

Comments
 (0)