diff --git a/Source/GUI/Qt/DatabaseUi.cpp b/Source/GUI/Qt/DatabaseUi.cpp index 528c8d77..f5520291 100644 --- a/Source/GUI/Qt/DatabaseUi.cpp +++ b/Source/GUI/Qt/DatabaseUi.cpp @@ -230,4 +230,12 @@ void DatabaseUi::get_sql_query_for_update_ui_table_v14(std::string& q) q = create.str(); } +//--------------------------------------------------------------------------- +void DatabaseUi::get_sql_query_for_update_ui_settings_table_v15(std::string& q) +{ + std::stringstream create; + create << "ALTER TABLE UI_SETTINGS"; // Table name + create << " ADD DISPLAYCAPTIONS_OPTION TEXT DEFAULT NULL;"; + q = create.str(); +} } diff --git a/Source/GUI/Qt/DatabaseUi.h b/Source/GUI/Qt/DatabaseUi.h index cd3bee25..21354de6 100644 --- a/Source/GUI/Qt/DatabaseUi.h +++ b/Source/GUI/Qt/DatabaseUi.h @@ -105,6 +105,9 @@ class DatabaseUi : public Database virtual int ui_settings_save_last_save_display_path(const std::string&, int user_id = -1) = 0; virtual int ui_settings_get_last_save_display_path(std::string&, int user_id = -1) = 0; + virtual int ui_settings_save_displaycaptions_option(const std::string&, int user_id = -1) = 0; + virtual int ui_settings_get_displaycaptions_option(std::string&, int user_id = -1) = 0; + virtual int ui_settings_save_mco_token(const std::string&, int user_id = -1) = 0; virtual int ui_settings_get_mco_token(std::string&, int user_id = -1) = 0; @@ -127,6 +130,7 @@ class DatabaseUi : public Database void get_sql_query_for_update_ui_table_v12(std::string& q); void get_sql_query_for_update_ui_settings_table_v13(std::string& q); void get_sql_query_for_update_ui_table_v14(std::string& q); + void get_sql_query_for_update_ui_settings_table_v15(std::string& q); private: DatabaseUi (const DatabaseUi&); diff --git a/Source/GUI/Qt/NoDatabaseUi.cpp b/Source/GUI/Qt/NoDatabaseUi.cpp index 8898fd57..90442c24 100644 --- a/Source/GUI/Qt/NoDatabaseUi.cpp +++ b/Source/GUI/Qt/NoDatabaseUi.cpp @@ -354,6 +354,18 @@ int NoDatabaseUi::ui_settings_get_last_save_display_path(std::string&, int) return 0; } +//--------------------------------------------------------------------------- +int NoDatabaseUi::ui_settings_save_displaycaptions_option(const std::string&, int) +{ + return 0; +} + +//--------------------------------------------------------------------------- +int NoDatabaseUi::ui_settings_get_displaycaptions_option(std::string&, int) +{ + return 0; +} + //--------------------------------------------------------------------------- int NoDatabaseUi::ui_settings_save_mco_token(const std::string&, int) { diff --git a/Source/GUI/Qt/NoDatabaseUi.h b/Source/GUI/Qt/NoDatabaseUi.h index 1fd27e92..1d255e49 100644 --- a/Source/GUI/Qt/NoDatabaseUi.h +++ b/Source/GUI/Qt/NoDatabaseUi.h @@ -88,6 +88,9 @@ class NoDatabaseUi : public DatabaseUi virtual int ui_settings_save_last_save_display_path(const std::string&, int user_id = -1); virtual int ui_settings_get_last_save_display_path(std::string&, int user_id = -1); + virtual int ui_settings_save_displaycaptions_option(const std::string&, int user_id = -1); + virtual int ui_settings_get_displaycaptions_option(std::string&, int user_id = -1); + virtual int ui_settings_save_mco_token(const std::string&, int user_id=-1); virtual int ui_settings_get_mco_token(std::string&, int user_id = -1); diff --git a/Source/GUI/Qt/SQLLiteUi.cpp b/Source/GUI/Qt/SQLLiteUi.cpp index fe5c4c63..4bbd2324 100644 --- a/Source/GUI/Qt/SQLLiteUi.cpp +++ b/Source/GUI/Qt/SQLLiteUi.cpp @@ -28,7 +28,7 @@ namespace MediaConch { // SQLLiteUi //*************************************************************************** -int SQLLiteUi::ui_current_version = 15; +int SQLLiteUi::ui_current_version = 16; //*************************************************************************** // Constructor/Destructor @@ -115,6 +115,7 @@ int SQLLiteUi::ui_update_table() UPDATE_UI_TABLE_FOR_VERSION(12); // UPDATE_UI_TABLE_FOR_VERSION(13); nothing to do UPDATE_UI_TABLE_FOR_VERSION(14); + // UPDATE_UI_TABLE_FOR_VERSION(15); nothing to do #undef UPDATE_UI_TABLE_FOR_VERSION @@ -911,6 +912,7 @@ int SQLLiteUi::ui_settings_update_table() // UPDATE_UI_SETTINGS_TABLE_FOR_VERSION(12); nothing to do UPDATE_UI_SETTINGS_TABLE_FOR_VERSION(13); // UPDATE_UI_SETTINGS_TABLE_FOR_VERSION(14); nothing to do + UPDATE_UI_SETTINGS_TABLE_FOR_VERSION(15); #undef UPDATE_UI_SETTINGS_TABLE_FOR_VERSION return 0; @@ -2120,6 +2122,63 @@ int SQLLiteUi::ui_settings_get_last_save_display_path(std::string& save_path, in return 0; } +//--------------------------------------------------------------------------- +int SQLLiteUi::ui_settings_save_displaycaptions_option(const std::string& option, int user_id) +{ + if (ui_settings_check_user_id(user_id)) + return -1; + + std::stringstream create; + + reports.clear(); + create << "UPDATE UI_SETTINGS "; + create << "SET DISPLAYCAPTIONS_OPTION = ? "; + create << "WHERE USER_ID = ?;"; + + query = create.str(); + + const char* end = NULL; + int ret = sqlite3_prepare_v2(db, query.c_str(), query.length() + 1, &stmt, &end); + if (ret != SQLITE_OK || !stmt || (end && *end)) + return -1; + + ret = sqlite3_bind_blob(stmt, 1, option.c_str(), option.length(), SQLITE_STATIC); + if (ret != SQLITE_OK) + return -1; + + ret = sqlite3_bind_int(stmt, 2, user_id); + if (ret != SQLITE_OK) + return -1; + + return execute(); +} + +//--------------------------------------------------------------------------- +int SQLLiteUi::ui_settings_get_displaycaptions_option(std::string& option, int user_id) +{ + if (ui_settings_check_user_id(user_id)) + return -1; + + reports.clear(); + query = "SELECT DISPLAYCAPTIONS_OPTION FROM UI_SETTINGS WHERE USER_ID = ?;"; + + const char* end = NULL; + int ret = sqlite3_prepare_v2(db, query.c_str(), query.length() + 1, &stmt, &end); + if (ret != SQLITE_OK || !stmt || (end && *end)) + return -1; + + ret = sqlite3_bind_int(stmt, 1, user_id); + if (ret != SQLITE_OK) + return -1; + + if (execute() || reports.size() != 1) + return -1; + + if (reports[0].find("DISPLAYCAPTIONS_OPTION") != reports[0].end()) + option = reports[0]["DISPLAYCAPTIONS_OPTION"]; + return 0; +} + //--------------------------------------------------------------------------- int SQLLiteUi::ui_settings_save_mco_token(const std::string& token, int user_id) { diff --git a/Source/GUI/Qt/SQLLiteUi.h b/Source/GUI/Qt/SQLLiteUi.h index a87c03d7..9245cf17 100644 --- a/Source/GUI/Qt/SQLLiteUi.h +++ b/Source/GUI/Qt/SQLLiteUi.h @@ -98,6 +98,9 @@ class SQLLiteUi : public DatabaseUi, public SQLLite virtual int ui_settings_save_last_save_display_path(const std::string&, int user_id = -1); virtual int ui_settings_get_last_save_display_path(std::string&, int user_id = -1); + virtual int ui_settings_save_displaycaptions_option(const std::string&, int user_id = -1); + virtual int ui_settings_get_displaycaptions_option(std::string&, int user_id = -1); + virtual int ui_settings_save_mco_token(const std::string&, int user_id=-1); virtual int ui_settings_get_mco_token(std::string&, int user_id = -1); diff --git a/Source/GUI/Qt/WebCommonPage.cpp b/Source/GUI/Qt/WebCommonPage.cpp index dfdebde1..3d183246 100644 --- a/Source/GUI/Qt/WebCommonPage.cpp +++ b/Source/GUI/Qt/WebCommonPage.cpp @@ -448,16 +448,22 @@ namespace MediaConch return ret; } - void WebCommonPage::on_save_settings_selected(const QString& policy, - const QString& display, - const QString& verbosity, - const QString& parsespeed, - const QString& save_report_path, const QString& load_files_path, - const QString& save_policy_path, const QString& load_policy_path, - const QString& save_display_path, const QString& load_display_path) + void WebCommonPage::on_save_settings_selected(const QJsonObject& values) { UiSettings& settings = mainwindow->get_settings(); + const QString policy = values.value("policy").toString(); + const QString display = values.value("display").toString(); + const QString verbosity = values.value("verbosity").toString(); + const QString parsespeed = values.value("parsespeed").toString(); + const QString displaycaptions = values.value("displaycaptions").toString(); + const QString save_report_path = values.value("save_report_path").toString(); + const QString load_files_path = values.value("load_files_path").toString(); + const QString save_policy_path = values.value("save_policy_path").toString(); + const QString load_policy_path = values.value("load_policy_path").toString(); + const QString save_display_path = values.value("save_display_path").toString(); + const QString load_display_path = values.value("load_display_path").toString(); + //policy if (policy == "-2") settings.change_default_policy("last"); @@ -488,6 +494,10 @@ namespace MediaConch else settings.change_default_parsespeed(parsespeed.toStdString()); + //displaycaptions + if (!displaycaptions.isEmpty()) + settings.change_displaycaptions_option(displaycaptions.toStdString()); + //Save report path std::string r_s_path; if (save_report_path == "last") diff --git a/Source/GUI/Qt/WebCommonPage.h b/Source/GUI/Qt/WebCommonPage.h index b5a3dc98..cb17559f 100644 --- a/Source/GUI/Qt/WebCommonPage.h +++ b/Source/GUI/Qt/WebCommonPage.h @@ -78,10 +78,7 @@ public Q_SLOTS: const QString& verbosity, bool fixer, const QStringList&); QString on_file_from_db_selected(); QString status_reports_multi(const QStringList& ids, const QStringList& policy_ids); - void on_save_settings_selected(const QString& policy, const QString& display, const QString& verbosity, const QString& parsespeed, - const QString& save_report, const QString& load_files, - const QString& save_policy, const QString& load_policy, - const QString& save_display, const QString& load_display); + void on_save_settings_selected(const QJsonObject& values); void menu_link_checker(const QString& name); void on_input_changed(const QString& inputName); diff --git a/Source/GUI/Qt/mainwindow.cpp b/Source/GUI/Qt/mainwindow.cpp index 0a922707..0f61674d 100644 --- a/Source/GUI/Qt/mainwindow.cpp +++ b/Source/GUI/Qt/mainwindow.cpp @@ -267,6 +267,14 @@ int MainWindow::add_file_to_list(const QString& file, const QString& path, std::vector opt_vec; for (int i = 0; i < options.size(); ++i) opt_vec.push_back(options[i].toUtf8().data()); + + std::string displaycaptions_option = uisettings.get_displaycaptions_option(); + if (!displaycaptions_option.empty()) + { + opt_vec.push_back("file_displaycaptions"); + opt_vec.push_back(displaycaptions_option); + }; + if (workerfiles.add_file_to_list(filename, filepath, policy.toInt(), display_i, verbosity_i, fixer, force, create_policy, opt_vec, err) < 0) return -1; return 0; @@ -291,6 +299,13 @@ int MainWindow::add_attachment_to_list(const QString& file, int policy, int disp for (int i = 0; i < options.size(); ++i) opt_vec.push_back(options[i].toUtf8().data()); + std::string displaycaptions_option = uisettings.get_displaycaptions_option(); + if (!displaycaptions_option.empty()) + { + opt_vec.push_back("file_displaycaptions"); + opt_vec.push_back(displaycaptions_option); + }; + std::string filename = std::string(file.toUtf8().data(), file.toUtf8().length()); if (workerfiles.add_attachment_to_list(filename, policy, display, verbosity, opt_vec, err) < 0) return -1; @@ -331,7 +346,19 @@ int MainWindow::analyze_force_file_to_list(long id, std::string& err) if (db) db->ui_reset_file_for_reload(fr); - if (workerfiles.add_file_to_list(fr->filename, fr->filepath, fr->policy, fr->display, fr->verbosity, false, true, false, fr->options, err) < 0) + std::vector options = fr->options; + std::vector::iterator it = std::find(options.begin(), options.end(), "file_displaycaptions"); + if (it != options.end() && it + 1 != options.end()) + options.erase(it, it + 2); + + std::string displaycaptions_option = uisettings.get_displaycaptions_option(); + if (!displaycaptions_option.empty()) + { + options.push_back("file_displaycaptions"); + options.push_back(displaycaptions_option); + }; + + if (workerfiles.add_file_to_list(fr->filename, fr->filepath, fr->policy, fr->display, fr->verbosity, false, true, false, options, err) < 0) return -1; return 0; diff --git a/Source/GUI/Qt/settingswindow.cpp b/Source/GUI/Qt/settingswindow.cpp index 47600abd..3464133e 100644 --- a/Source/GUI/Qt/settingswindow.cpp +++ b/Source/GUI/Qt/settingswindow.cpp @@ -99,6 +99,10 @@ void SettingsWindow::fill_settings_html(QString& html) QString parsespeed; create_parsespeed_options(parsespeed); add_parsespeed_to_html_selection(parsespeed, html, "settings_parsespeed_selector"); + + QString displaycaptions; + create_displaycaptions_options(displaycaptions); + add_displaycaptions_to_html_selection(displaycaptions, html, "settings_displaycaptions_selector"); } //--------------------------------------------------------------------------- @@ -269,6 +273,45 @@ void SettingsWindow::create_parsespeed_options(QString& parsespeed) parsespeed += QString("value=\"1\">Full (1)"); } +//--------------------------------------------------------------------------- +void SettingsWindow::add_displaycaptions_to_html_selection(QString& displaycaptions, QString& html, const QString& selector) +{ + QRegExp reg("class=\"displaycaptionsList form-control\">"); + int pos = html.indexOf(selector); + + reg.setMinimal(true); + + if (pos == -1) + return; + + if ((pos = reg.indexIn(html, pos)) != -1) + { + pos += reg.matchedLength(); + html.insert(pos, displaycaptions); + } +} + +//--------------------------------------------------------------------------- +void SettingsWindow::create_displaycaptions_options(QString& displaycaptions) +{ + std::string selected_displaycaptions_option = main_window->get_settings().get_displaycaptions_option(); + + displaycaptions += QString(""); + + displaycaptions += QString(""); + + displaycaptions += QString(""); +} + //--------------------------------------------------------------------------- void SettingsWindow::add_policy_to_html_selection(QString& policies, QString& html, const QString& selector) { diff --git a/Source/GUI/Qt/settingswindow.h b/Source/GUI/Qt/settingswindow.h index 5c7dfa70..863a34cf 100644 --- a/Source/GUI/Qt/settingswindow.h +++ b/Source/GUI/Qt/settingswindow.h @@ -35,7 +35,8 @@ class SettingsWindow : public CommonWebWindow void create_verbosity_options(QString& verbosity); void add_parsespeed_to_html_selection(QString& parsespeed, QString& html, const QString& selector); void create_parsespeed_options(QString& parsespeed); - + void add_displaycaptions_to_html_selection(QString& displaycaptions, QString& html, const QString& selector); + void create_displaycaptions_options(QString& displaycaptions); void create_html_base(QString& base, const QString& settings); void change_qt_scripts_in_template(QString& html); void set_webmachine_script_in_template(QString& html); diff --git a/Source/GUI/Qt/uisettings.cpp b/Source/GUI/Qt/uisettings.cpp index 5873fc61..216cc60c 100644 --- a/Source/GUI/Qt/uisettings.cpp +++ b/Source/GUI/Qt/uisettings.cpp @@ -78,6 +78,8 @@ int UiSettings::init() return -1; if (database->ui_settings_get_last_load_display_path(last_load_display_path)) return -1; + if (database->ui_settings_get_displaycaptions_option(displaycaptions_option)) + return -1; if (database->ui_settings_get_mco_token(mco_token)) return -1; @@ -399,6 +401,24 @@ void UiSettings::change_last_save_display_path(const std::string& path) last_save_display_path = path; } +//--------------------------------------------------------------------------- +std::string UiSettings::get_displaycaptions_option() const +{ + return displaycaptions_option; +} + +//--------------------------------------------------------------------------- +void UiSettings::change_displaycaptions_option(const std::string& option) +{ + if (!database || displaycaptions_option == option) + return; + + if (database->ui_settings_save_displaycaptions_option(option) < 0) + return; + + displaycaptions_option = option; +} + //--------------------------------------------------------------------------- std::string UiSettings::get_last_load_files_path() const { diff --git a/Source/GUI/Qt/uisettings.h b/Source/GUI/Qt/uisettings.h index 69b2a614..d5194659 100644 --- a/Source/GUI/Qt/uisettings.h +++ b/Source/GUI/Qt/uisettings.h @@ -71,6 +71,10 @@ class UiSettings std::string get_last_save_display_path() const; void change_last_save_display_path(const std::string& path); + // Options + std::string get_displaycaptions_option() const; + void change_displaycaptions_option(const std::string& option); + // MCO Token std::string get_mco_token() const; void change_mco_token(const std::string& token); @@ -100,6 +104,9 @@ class UiSettings std::string last_save_policy_path; std::string last_save_display_path; + //Options + std::string displaycaptions_option; + //MCO Token std::string mco_token; diff --git a/Source/Resource/html/js/settings.js b/Source/Resource/html/js/settings.js index 5dd35ad8..efc2e8f1 100644 --- a/Source/Resource/html/js/settings.js +++ b/Source/Resource/html/js/settings.js @@ -2,16 +2,22 @@ $(document).ready(function() { // Settings form $('#settings form').on('submit', function (e) { e.preventDefault(); - webpage.on_save_settings_selected($('#settings_policy').val(), - $('#settings_display_selector').val(), - $('#settings_verbosity_selector').val(), - $('#settings_parsespeed_selector').val(), - $('input[name=settings_save_report_path]:checked').val(), - $('input[name=settings_load_files_path]:checked').val(), - $('input[name=settings_save_policy_path]:checked').val(), - $('input[name=settings_load_policy_path]:checked').val(), - $('input[name=settings_save_display_path]:checked').val(), - $('input[name=settings_load_display_path]:checked').val()); + + var values = { + "policy": $('#settings_policy').val(), + "display": $('#settings_display_selector').val(), + "verbosity": $('#settings_verbosity_selector').val(), + "parsespeed": $('#settings_parsespeed_selector').val(), + "displaycaptions": $('#settings_displaycaptions_selector').val(), + "save_report_path": $('input[name=settings_save_report_path]:checked').val(), + "load_files_path": $('input[name=settings_load_files_path]:checked').val(), + "save_policy_path": $('input[name=settings_save_policy_path]:checked').val(), + "load_policy_path": $('input[name=settings_load_policy_path]:checked').val(), + "save_display_path": $('input[name=settings_save_display_path]:checked').val(), + "load_display_path": $('input[name=settings_load_display_path]:checked').val(), + }; + + webpage.on_save_settings_selected(values); }); }); diff --git a/Source/Resource/html/settings.html b/Source/Resource/html/settings.html index 41e80b61..b7030bbb 100644 --- a/Source/Resource/html/settings.html +++ b/Source/Resource/html/settings.html @@ -1,8 +1,6 @@

Settings

-
-
@@ -160,6 +158,16 @@

Settings

+

Advanced

+ +
+ +
+ +
+
+