1212
1313#include " logger.h"
1414#include " qmlutils.h"
15+ #include " common/tabviewmodel.h"
1516#include " models/connectionconf.h"
1617#include " models/configmanager.h"
1718#include " models/connectionsmanager.h"
2021#include " modules/value-editor/valueviewmodel.h"
2122#include " modules/value-editor/viewmodel.h"
2223#include " modules/value-editor/sortfilterproxymodel.h"
23- #include " modules/console/consoleviewmodel.h"
24+ #include " modules/console/consolemodel.h"
25+ #include " modules/server-stats/serverstatsmodel.h"
2426#include " modules/bulk-operations/bulkoperationsmanager.h"
2527
2628
@@ -47,16 +49,22 @@ Application::Application(int &argc, char **argv)
4749 initAppAnalytics ();
4850 initRedisClient ();
4951 initUpdater ();
52+ installTranslator ();
5053}
5154
5255void Application::initModels ()
5356{
5457 initConnectionsManager ();
5558
56- m_consoleModel = QSharedPointer<Console::ViewModel >(new Console::ViewModel ( ));
59+ m_consoleModel = QSharedPointer<TabViewModel >(new TabViewModel (getTabModelFactory< Console::Model>() ));
5760
5861 connect (m_connections.data (), &ConnectionsManager::openConsole,
59- m_consoleModel.data (), &Console::ViewModel::openConsole);
62+ m_consoleModel.data (), &TabViewModel::openTab);
63+
64+ m_serverStatsModel = QSharedPointer<TabViewModel>(new TabViewModel (getTabModelFactory<ServerStats::Model>()));
65+
66+ connect (m_connections.data (), &ConnectionsManager::openServerStats,
67+ m_serverStatsModel.data (), &TabViewModel::openTab);
6068}
6169
6270void Application::initAppInfo ()
@@ -70,8 +78,16 @@ void Application::initAppInfo()
7078void Application::initAppFonts ()
7179{
7280 QSettings settings;
73- QString appFont = settings.value (" app/appFont" , " Open Sans" ).toString ();
74- int appFontSize = settings.value (" app/appFontSize" , 11 ).toInt ();
81+ #ifdef Q_OS_MAC
82+ QString defaultFontName (" Helvetica Neue" );
83+ int defaultFontSize = 12 ;
84+ #else
85+ QString defaultFontName (" Open Sans" );
86+ int defaultFontSize = 11 ;
87+ #endif
88+
89+ QString appFont = settings.value (" app/appFont" , defaultFontName).toString ();
90+ int appFontSize = settings.value (" app/appFontSize" , defaultFontSize).toInt ();
7591
7692 if (appFont == " Open Sans" ) {
7793 int result = QFontDatabase::addApplicationFont (" ://fonts/OpenSans.ttc" );
@@ -109,6 +125,7 @@ void Application::registerQmlRootObjects()
109125 m_engine.rootContext ()->setContextProperty (" viewModel" , m_keyValues.data ()); // TODO: Remove legacy name usage in qml
110126 m_engine.rootContext ()->setContextProperty (" valuesModel" , m_keyValues.data ());
111127 m_engine.rootContext ()->setContextProperty (" consoleModel" , m_consoleModel.data ());
128+ m_engine.rootContext ()->setContextProperty (" serverStatsModel" , m_serverStatsModel.data ());
112129 m_engine.rootContext ()->setContextProperty (" appLogger" , m_logger);
113130 m_engine.rootContext ()->setContextProperty (" bulkOperations" , m_bulkOperations.data ());
114131}
@@ -151,10 +168,9 @@ void Application::initConnectionsManager()
151168
152169 if (config.isNull ()) {
153170 QMessageBox::critical (nullptr ,
154- " Settings directory is not writable" ,
155- QString (" Program can't save connections file to settings dir."
156- " Please change permissions or restart this program "
157- " with administrative privileges" )
171+ QObject::tr (" Settings directory is not writable" ),
172+ QString (QObject::tr (" RDM can't save connections file to settings directory. "
173+ " Please change file permissions or restart RDM as administrator." ))
158174 );
159175
160176 throw std::runtime_error (" invalid connections config" );
@@ -188,8 +204,29 @@ void Application::initUpdater()
188204 connect (m_updater.data (), SIGNAL (updateUrlRetrived (QString &)), this , SLOT (OnNewUpdateAvailable (QString &)));
189205}
190206
207+ void Application::installTranslator ()
208+ {
209+ QString locale = QLocale::system ().uiLanguages ().first ().replace ( " -" , " _" );
210+
211+ qDebug () << QLocale::system ().uiLanguages ();
212+
213+ if (locale.isEmpty () || locale == " C" )
214+ locale = " en_US" ;
215+
216+ qDebug () << " Detected locale:" << locale;
217+
218+ QTranslator* translator = new QTranslator ((QObject *)this );
219+ if (translator->load ( QString ( " :/translations/rdm_" ) + locale ))
220+ {
221+ qDebug () << " Load translations file for locale:" << locale;
222+ QCoreApplication::installTranslator ( translator );
223+ } else {
224+ delete translator;
225+ }
226+ }
227+
191228void Application::OnNewUpdateAvailable (QString &url)
192229{
193230 QMessageBox::information (nullptr , " New update available" ,
194- QString (" Please download new version of Redis Desktop Manager: %1" ).arg (url));
231+ QString (QObject::tr ( " Please download new version of Redis Desktop Manager: %1" ) ).arg (url));
195232}
0 commit comments