Skip to content

Commit

Permalink
Add preferences dialog and app language option
Browse files Browse the repository at this point in the history
  • Loading branch information
ragnar-lodbrok committed Feb 12, 2023
1 parent c5f70e6 commit 09b7c82
Show file tree
Hide file tree
Showing 35 changed files with 1,322 additions and 455 deletions.
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ set(HEADER_FILES
app/actions.h
app/app.h
app/log.h
app/language.h
db/collation_fetcher.h
db/common.h
db/connection.h
Expand Down Expand Up @@ -128,6 +129,7 @@ set(HEADER_FILES
settings/settings_icons.h
settings/settings_text.h
settings/data_editors.h
settings/general.h
settings/queries_storage.h
settings/query_data_export_storage.h
settings/table_filters_storage.h
Expand Down Expand Up @@ -234,6 +236,8 @@ set(HEADER_FILES
ui/models/user_privileges_model.h
ui/models/variables_table_model.h
ui/models/session_objects_tree_model.h
ui/preferences/general_tab.h
ui/preferences/preferences_dialog.h
ui/presenters/central_right_host_widget_model.h
ui/presenters/central_right_widget_model.h
ui/presenters/central_right_data_filter_form.h
Expand All @@ -245,6 +249,7 @@ set(HEADER_FILES
ui/presenters/editable_data_context_menu_presenter.h
ui/presenters/export_database_form.h
ui/presenters/export_query_presenter.h
ui/presenters/preferences_presenter.h
ui/presenters/routine_form.h
ui/presenters/select_db_object_form.h
ui/presenters/table_info_form.h
Expand Down Expand Up @@ -360,6 +365,7 @@ set(SOURCE_FILES
settings/settings_icons.cpp
settings/settings_text.cpp
settings/data_editors.cpp
settings/general.cpp
settings/queries_storage.cpp
settings/query_data_export_storage.cpp
settings/table_filters_storage.cpp
Expand Down Expand Up @@ -461,6 +467,8 @@ set(SOURCE_FILES
ui/models/user_privileges_model.cpp
ui/models/variables_table_model.cpp
ui/models/session_objects_tree_model.cpp
ui/preferences/general_tab.cpp
ui/preferences/preferences_dialog.cpp
ui/presenters/central_right_host_widget_model.cpp
ui/presenters/central_right_widget_model.cpp
ui/presenters/central_right_data_filter_form.cpp
Expand All @@ -472,6 +480,7 @@ set(SOURCE_FILES
ui/presenters/editable_data_context_menu_presenter.cpp
ui/presenters/export_database_form.cpp
ui/presenters/export_query_presenter.cpp
ui/presenters/preferences_presenter.cpp
ui/presenters/routine_form.cpp
ui/presenters/select_db_object_form.cpp
ui/presenters/table_info_form.cpp
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,23 @@ Mac OS:

This project is licensed under the GPL 2.0 License

## Translations

If you want to translate MeowSQL to your language, open corresponding `resources/translations/meowsql_*.ts` file.

Use either Qt Linguist or in any text editor remove (` type="unfinished"`) from translation section:

`<translation type="unfinished">ADD TRANSLATION HERE</translation>`

Then create merge request (see also resources/translations/README.txt).

## Acknowledgments
* HeidiSQL developers - now on [github](https://github.com/HeidiSQL/HeidiSQL)
* [peek](https://github.com/phw/peek) was used for GIF recording
* [linuxdeployqt](https://github.com/probonopd/linuxdeployqt) was used for AppImage creation

## Donation
* One time (any amount + message): https://www.donationalerts.com/r/ragnar_lodbro
* Recurring: https://boosty.to/ragnar_lodbro
* Recurring: https://patreon.com/ragnar_lodbrok

5 changes: 5 additions & 0 deletions app/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ void Actions::createActions(App * app)
tr("Export database as SQL"), this);
_exportDatabase->setStatusTip(tr("Dump database objects to an SQL file"));

// -------------------------------------------------------------------------

_preferences = new QAction(QIcon(":/icons/wrench_orange.png"),
tr("Preferences"), this);

}

} // namespace meow
3 changes: 3 additions & 0 deletions app/actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class Actions : public QObject

QAction * exportDatabase() const { return _exportDatabase; }

QAction * preferences() const { return _preferences; }

private:

void createActions(App * app);
Expand All @@ -65,6 +67,7 @@ class Actions : public QObject
QAction * _logClear;

QAction * _exportDatabase;
QAction * _preferences;
};

} // namespace meow
Expand Down
6 changes: 5 additions & 1 deletion app/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ App::App()
, _dbConnectionParamsManager()
, _dbConnectionsManager(db::ConnectionsManager::create())
, _settingsCore()
, _actions(this) // after settings
{
g_app = this;
_dbConnectionParamsManager.load();
_dbConnectionsManager->init();
}

App::~App()
{
delete _actions;
}

db::ConnectionParamsManager * App::dbConnectionParamsManager()
{
return &_dbConnectionParamsManager;
Expand Down
10 changes: 8 additions & 2 deletions app/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@ class App
{
public:
App();
~App();
db::ConnectionParamsManager * dbConnectionParamsManager();
db::ConnectionsManager * dbConnectionsManager();

meow::settings::Core * settings() { return &_settingsCore; }

Actions * actions() { return &_actions; }
Actions * actions() {
if (!_actions) {
_actions = new Actions(this);
}
return _actions;
}

Log * log() { return &_log; }

Expand All @@ -34,7 +40,7 @@ class App

meow::settings::Core _settingsCore;

Actions _actions;
Actions * _actions = nullptr;
};

App * app();
Expand Down
48 changes: 48 additions & 0 deletions app/language.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#ifndef MEOW_APP_LANGUAGE_H
#define MEOW_APP_LANGUAGE_H

#include <QString>
#include <QVector>
#include <QObject>

namespace meow {

using LanguageCode = QString;

struct Language
{
LanguageCode code;
QString name;
QString nameTranslated;
};

static inline LanguageCode defaultLanguage()
{
return "en";
}

static inline QVector<Language> allLanguages()
{
static QVector<Language> langs = {
{"bg", "Bulgarian", QObject::tr("Bulgarian")},
{"zh", "Chinese", QObject::tr("Chinese")},
{"cs", "Czech", QObject::tr("Czech")},
{"en", "English", QObject::tr("English")},
{"fr", "French", QObject::tr("French")},
{"de", "German", QObject::tr("German")},
{"hu", "Hungarian", QObject::tr("Hungarian")},
{"it", "Italian", QObject::tr("Italian")},
{"ko", "Korean", QObject::tr("Korean")},
{"pt", "Portuguese", QObject::tr("Portuguese")},
{"ro", "Romanian", QObject::tr("Romanian")},
{"ru", "Russian", QObject::tr("Russian")},
{"es", "Spanish", QObject::tr("Spanish")},
{"sv", "Swedish", QObject::tr("Swedish")},
};

return langs;
}

} // namespace meow

#endif // MEOW_APP_LANGUAGE_H
2 changes: 1 addition & 1 deletion icons.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<file>resources/icons/delimiter.png</file>
<file>resources/icons/execute_selection.png</file>
<file alias="execute_line.png">resources/icons/execute_line.png</file>
<file>resources/icons/wrench_orange.png</file>
<file alias="wrench_orange.png">resources/icons/wrench_orange.png</file>
<file alias="wordwrap.png">resources/icons/wordwrap.png</file>
<file>resources/icons/view_highlight.png</file>
<file>resources/icons/view_edit.png</file>
Expand Down
12 changes: 6 additions & 6 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ int main(int argc, char *argv[])
);
#endif

// test translations TODO
//QTranslator translator;
//translator.load(":translations/meowsql_fr.qm");
//a.installTranslator(&translator);
// test translations

meow::App app;

QString language = app.settings()->generalSettings()->language();
QTranslator translator;
if (translator.load(QString(":translations/meowsql_%1.qm").arg(language))) {
a.installTranslator(&translator);
}

meow::ui::main_window::Window w;
w.show();

Expand Down
Loading

0 comments on commit 09b7c82

Please sign in to comment.