Skip to content

Commit

Permalink
GUI: Add captions display options
Browse files Browse the repository at this point in the history
Signed-off-by: Maxime Gervais <[email protected]>
  • Loading branch information
g-maxime committed Jun 28, 2024
1 parent f7c5044 commit 74c1a2c
Show file tree
Hide file tree
Showing 15 changed files with 234 additions and 26 deletions.
8 changes: 8 additions & 0 deletions Source/GUI/Qt/DatabaseUi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
4 changes: 4 additions & 0 deletions Source/GUI/Qt/DatabaseUi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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&);
Expand Down
12 changes: 12 additions & 0 deletions Source/GUI/Qt/NoDatabaseUi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
3 changes: 3 additions & 0 deletions Source/GUI/Qt/NoDatabaseUi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
61 changes: 60 additions & 1 deletion Source/GUI/Qt/SQLLiteUi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace MediaConch {
// SQLLiteUi
//***************************************************************************

int SQLLiteUi::ui_current_version = 15;
int SQLLiteUi::ui_current_version = 16;

//***************************************************************************
// Constructor/Destructor
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down
3 changes: 3 additions & 0 deletions Source/GUI/Qt/SQLLiteUi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
24 changes: 17 additions & 7 deletions Source/GUI/Qt/WebCommonPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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")
Expand Down
5 changes: 1 addition & 4 deletions Source/GUI/Qt/WebCommonPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
29 changes: 28 additions & 1 deletion Source/GUI/Qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,14 @@ int MainWindow::add_file_to_list(const QString& file, const QString& path,
std::vector<std::string> 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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<std::string> options = fr->options;
std::vector<std::string>::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;
Expand Down
43 changes: 43 additions & 0 deletions Source/GUI/Qt/settingswindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -269,6 +273,45 @@ void SettingsWindow::create_parsespeed_options(QString& parsespeed)
parsespeed += QString("value=\"1\">Full (1)</option>");
}

//---------------------------------------------------------------------------
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("<option ");
if ("Content" == selected_displaycaptions_option)
displaycaptions += QString("selected=\"selected\" ");
displaycaptions += QString("value=\"Content\">When content is detected</option>");

displaycaptions += QString("<option ");
if ("" == selected_displaycaptions_option || "Command" == selected_displaycaptions_option)
displaycaptions += QString("selected=\"selected\" ");
displaycaptions += QString("value=\"Command\">When content or a command is detected</option>");

displaycaptions += QString("<option ");
if ("Stream" == selected_displaycaptions_option)
displaycaptions += QString("selected=\"selected\" ");
displaycaptions += QString("value=\"Stream\">Even when no content or command is detected</option>");
}

//---------------------------------------------------------------------------
void SettingsWindow::add_policy_to_html_selection(QString& policies, QString& html, const QString& selector)
{
Expand Down
3 changes: 2 additions & 1 deletion Source/GUI/Qt/settingswindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
20 changes: 20 additions & 0 deletions Source/GUI/Qt/uisettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand Down
7 changes: 7 additions & 0 deletions Source/GUI/Qt/uisettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down
Loading

0 comments on commit 74c1a2c

Please sign in to comment.