Skip to content

Commit

Permalink
0.9.0-alpha2
Browse files Browse the repository at this point in the history
* Implement server info tab
* Add basic translations support
* Update translations and messages
* Update qredisclient
* Fix links in WelcomeTab
* Use Helvetica Neue 12px as default font on OSX
  • Loading branch information
uglide authored Oct 21, 2016
1 parent 3b901e1 commit 2bed502
Show file tree
Hide file tree
Showing 57 changed files with 3,560 additions and 399 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ script:
- ./../bin/tests/tests -platform minimal -txt
- ./../bin/tests/qml_tests -platform minimal -txt
- cd ./../src
- qmake && make -s -j 2
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then
qmake && make -s -j 2
;
fi
after_success:
- cd ./../tests
- sudo pip install cpp-coveralls
Expand Down
2 changes: 1 addition & 1 deletion 3rdparty/qredisclient
57 changes: 47 additions & 10 deletions src/app/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "logger.h"
#include "qmlutils.h"
#include "common/tabviewmodel.h"
#include "models/connectionconf.h"
#include "models/configmanager.h"
#include "models/connectionsmanager.h"
Expand All @@ -20,7 +21,8 @@
#include "modules/value-editor/valueviewmodel.h"
#include "modules/value-editor/viewmodel.h"
#include "modules/value-editor/sortfilterproxymodel.h"
#include "modules/console/consoleviewmodel.h"
#include "modules/console/consolemodel.h"
#include "modules/server-stats/serverstatsmodel.h"
#include "modules/bulk-operations/bulkoperationsmanager.h"


Expand All @@ -47,16 +49,22 @@ Application::Application(int &argc, char **argv)
initAppAnalytics();
initRedisClient();
initUpdater();
installTranslator();
}

void Application::initModels()
{
initConnectionsManager();

m_consoleModel = QSharedPointer<Console::ViewModel>(new Console::ViewModel());
m_consoleModel = QSharedPointer<TabViewModel>(new TabViewModel(getTabModelFactory<Console::Model>()));

connect(m_connections.data(), &ConnectionsManager::openConsole,
m_consoleModel.data(), &Console::ViewModel::openConsole);
m_consoleModel.data(), &TabViewModel::openTab);

m_serverStatsModel = QSharedPointer<TabViewModel>(new TabViewModel(getTabModelFactory<ServerStats::Model>()));

connect(m_connections.data(), &ConnectionsManager::openServerStats,
m_serverStatsModel.data(), &TabViewModel::openTab);
}

void Application::initAppInfo()
Expand All @@ -70,8 +78,16 @@ void Application::initAppInfo()
void Application::initAppFonts()
{
QSettings settings;
QString appFont = settings.value("app/appFont", "Open Sans").toString();
int appFontSize = settings.value("app/appFontSize", 11).toInt();
#ifdef Q_OS_MAC
QString defaultFontName("Helvetica Neue");
int defaultFontSize = 12;
#else
QString defaultFontName("Open Sans");
int defaultFontSize = 11;
#endif

QString appFont = settings.value("app/appFont", defaultFontName).toString();
int appFontSize = settings.value("app/appFontSize", defaultFontSize).toInt();

if (appFont == "Open Sans") {
int result = QFontDatabase::addApplicationFont("://fonts/OpenSans.ttc");
Expand Down Expand Up @@ -109,6 +125,7 @@ void Application::registerQmlRootObjects()
m_engine.rootContext()->setContextProperty("viewModel", m_keyValues.data()); // TODO: Remove legacy name usage in qml
m_engine.rootContext()->setContextProperty("valuesModel", m_keyValues.data());
m_engine.rootContext()->setContextProperty("consoleModel", m_consoleModel.data());
m_engine.rootContext()->setContextProperty("serverStatsModel", m_serverStatsModel.data());
m_engine.rootContext()->setContextProperty("appLogger", m_logger);
m_engine.rootContext()->setContextProperty("bulkOperations", m_bulkOperations.data());
}
Expand Down Expand Up @@ -151,10 +168,9 @@ void Application::initConnectionsManager()

if (config.isNull()) {
QMessageBox::critical(nullptr,
"Settings directory is not writable",
QString("Program can't save connections file to settings dir."
"Please change permissions or restart this program "
" with administrative privileges")
QObject::tr("Settings directory is not writable"),
QString(QObject::tr("RDM can't save connections file to settings directory. "
"Please change file permissions or restart RDM as administrator."))
);

throw std::runtime_error("invalid connections config");
Expand Down Expand Up @@ -188,8 +204,29 @@ void Application::initUpdater()
connect(m_updater.data(), SIGNAL(updateUrlRetrived(QString &)), this, SLOT(OnNewUpdateAvailable(QString &)));
}

void Application::installTranslator()
{
QString locale = QLocale::system().uiLanguages().first().replace( "-", "_" );

qDebug() << QLocale::system().uiLanguages();

if (locale.isEmpty() || locale == "C")
locale = "en_US";

qDebug() << "Detected locale:" << locale;

QTranslator* translator = new QTranslator((QObject *)this);
if (translator->load( QString( ":/translations/rdm_" ) + locale ))
{
qDebug() << "Load translations file for locale:" << locale;
QCoreApplication::installTranslator( translator );
} else {
delete translator;
}
}

void Application::OnNewUpdateAvailable(QString &url)
{
QMessageBox::information(nullptr, "New update available",
QString("Please download new version of Redis Desktop Manager: %1").arg(url));
QString(QObject::tr("Please download new version of Redis Desktop Manager: %1")).arg(url));
}
6 changes: 4 additions & 2 deletions src/app/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class QmlUtils;
class ConnectionsManager;
class Updater;
class LogHandler;
class TabViewModel;
namespace ValueEditor { class ViewModel; }
namespace Console { class ViewModel; }
namespace BulkOperations { class Manager; }


Expand All @@ -37,6 +37,7 @@ class Application : public QApplication
void initLog();
void initConnectionsManager();
void initUpdater();
void installTranslator();

private slots:
void OnNewUpdateAvailable(QString &url);
Expand All @@ -48,6 +49,7 @@ private slots:
QSharedPointer<Updater> m_updater;
QSharedPointer<ValueEditor::ViewModel> m_keyValues;
QSharedPointer<BulkOperations::Manager> m_bulkOperations;
QSharedPointer<Console::ViewModel> m_consoleModel;
QSharedPointer<TabViewModel> m_consoleModel;
QSharedPointer<TabViewModel> m_serverStatsModel;
LogHandler* m_logger;
};
1 change: 1 addition & 0 deletions src/app/models/connectionsmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class ConnectionsManager : public ConnectionsTree::Model, public BulkOperations:

void openConsole(QSharedPointer<RedisClient::Connection> connection);

void openServerStats(QSharedPointer<RedisClient::Connection> connection);

// Proxy-signals from TreeOperationsModel
void openValueTab(QSharedPointer<RedisClient::Connection> connection,
Expand Down
13 changes: 7 additions & 6 deletions src/app/models/key-models/hashkey.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "hashkey.h"
#include <qredisclient/connection.h>
#include <QObject>

HashKeyModel::HashKeyModel(QSharedPointer<RedisClient::Connection> connection,
QByteArray fullPath, int dbIndex, long long ttl)
Expand Down Expand Up @@ -47,7 +48,7 @@ QVariant HashKeyModel::getData(int rowIndex, int dataRole)
void HashKeyModel::updateRow(int rowIndex, const QVariantMap &row)
{
if (!isRowLoaded(rowIndex) || !isRowValid(row))
throw Exception("Invalid row");
throw Exception(QObject::tr("Invalid row"));

QPair<QByteArray, QByteArray> cachedRow = m_rowsCache[rowIndex];

Expand All @@ -70,7 +71,7 @@ void HashKeyModel::updateRow(int rowIndex, const QVariantMap &row)
void HashKeyModel::addRow(const QVariantMap &row)
{
if (!isRowValid(row))
throw Exception("Invalid row");
throw Exception(QObject::tr("Invalid row"));

setHashRow(row["key"].toByteArray(), row["value"].toByteArray(), false);
m_rowCount++;
Expand Down Expand Up @@ -101,20 +102,20 @@ void HashKeyModel::setHashRow(const QByteArray &hashKey, const QByteArray &hashV
result = m_connection->commandSync({(updateIfNotExist)? "HSET" : "HSETNX",
m_keyFullPath, hashKey, hashValue}, m_dbIndex);
} catch (const RedisClient::Connection::Exception& e) {
throw Exception("Connection error: " + QString(e.what()));
throw Exception(QObject::tr("Connection error: ") + QString(e.what()));
}

if (updateIfNotExist == false
&& result.getValue().toInt() == 0)
throw Exception("Value with same key already exist");
throw Exception(QObject::tr("Value with the same key already exist"));
}

void HashKeyModel::deleteHashRow(const QByteArray &hashKey)
{
try {
m_connection->commandSync({"HDEL", m_keyFullPath, hashKey}, m_dbIndex);
} catch (const RedisClient::Connection::Exception& e) {
throw Exception("Connection error: " + QString(e.what()));
throw Exception(QObject::tr("Connection error: ") + QString(e.what()));
}
}

Expand All @@ -130,7 +131,7 @@ void HashKeyModel::addLoadedRowsToCache(const QVariantList &rows, int rowStart)
++item;

if (item == rows.end())
throw Exception("Partial data loaded from server");
throw Exception(QObject::tr("Data was loaded from server partially."));

value.second = item->toByteArray();
result.push_back(value);
Expand Down
11 changes: 6 additions & 5 deletions src/app/models/key-models/keyfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "sortedsetkey.h"
#include "hashkey.h"
#include "listkey.h"
#include <QObject>

KeyFactory::KeyFactory()
{}
Expand All @@ -23,16 +24,16 @@ void KeyFactory::loadKey(QSharedPointer<RedisClient::Connection> connection,
QSharedPointer<ValueEditor::Model> result;

if (resp.isErrorMessage() || resp.getType() != RedisClient::Response::Type::Status) {
QString msg("Cannot load key %1, connection error occurred: %2");
QString msg(QObject::tr("Cannot load key %1, connection error occurred: %2"));
callback(result, msg.arg(printableString(keyFullPath)).arg(resp.toRawString()));
return;
}

QString type = resp.getValue().toString();

if (type == "none") {
QString msg("Cannot load key %1 because it doesn't exist in database."
" Please reload connection tree and try again.");
QString msg(QObject::tr("Cannot load key %1 because it doesn't exist in database."
" Please reload connection tree and try again."));
callback(result, msg.arg(printableString(keyFullPath)));
return;
}
Expand All @@ -42,7 +43,7 @@ void KeyFactory::loadKey(QSharedPointer<RedisClient::Connection> connection,
try {
ttlResult = connection->commandSync({"ttl", keyFullPath}, dbIndex);
} catch (const RedisClient::Connection::Exception& e) {
QString msg("Cannot load TTL for key %1, connection error occurred: %2");
QString msg(QObject::tr("Cannot load TTL for key %1, connection error occurred: %2"));
callback(result, msg.arg(printableString(keyFullPath)).arg(QString(e.what())));
return;
}
Expand All @@ -62,7 +63,7 @@ void KeyFactory::loadKey(QSharedPointer<RedisClient::Connection> connection,
try {
connection->runCommand(typeCmd);
} catch (const RedisClient::Connection::Exception& e) {
throw Exception("Cannot retrive type of the key: " + QString(e.what()));
throw Exception(QObject::tr("Cannot retrive type of the key: ") + QString(e.what()));
}
}

Expand Down
18 changes: 8 additions & 10 deletions src/app/models/key-models/listkey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ QString ListKeyModel::getType()
void ListKeyModel::updateRow(int rowIndex, const QVariantMap &row)
{
if (!isRowLoaded(rowIndex) || !isRowValid(row))
throw Exception("Invalid row");
throw Exception(QObject::tr("Invalid row"));

if (isActualPositionChanged(rowIndex))
throw Exception("Can't delete row from list, because row already has changed."
" Reload values and try again.");
throw Exception(QObject::tr("The row has been changed and can't be updated now. Reload and try again."));

QByteArray newRow(row["value"].toByteArray());
setListRow(rowIndex, newRow);
Expand All @@ -30,7 +29,7 @@ void ListKeyModel::updateRow(int rowIndex, const QVariantMap &row)
void ListKeyModel::addRow(const QVariantMap &row)
{
if (!isRowValid(row))
throw Exception("Invalid row");
throw Exception(QObject::tr("Invalid row"));

addListRow(row["value"].toByteArray());
m_rowCount++;
Expand All @@ -42,8 +41,7 @@ void ListKeyModel::removeRow(int i)
return;

if (isActualPositionChanged(i))
throw Exception("Can't delete row from list, because row already has changed."
" Reload values and try again.");
throw Exception(QObject::tr("The row has been changed and can't be deleted now. Reload and try again."));

// Replace value by system string
QString customSystemValue("---VALUE_REMOVED_BY_RDM---");
Expand Down Expand Up @@ -74,7 +72,7 @@ bool ListKeyModel::isActualPositionChanged(int row)
result = m_connection->commandSync({"LRANGE", m_keyFullPath, QString::number(row).toLatin1(),
QString::number(row).toLatin1()}, m_dbIndex);
} catch (const RedisClient::Connection::Exception& e) {
throw Exception("Connection error: " + QString(e.what()));
throw Exception(QObject::tr("Connection error: ") + QString(e.what()));
}

QVariantList currentState = result.getValue().toList();
Expand All @@ -87,7 +85,7 @@ void ListKeyModel::addListRow(const QByteArray &value)
try {
m_connection->commandSync({"LPUSH", m_keyFullPath, value}, m_dbIndex);
} catch (const RedisClient::Connection::Exception& e) {
throw Exception("Connection error: " + QString(e.what()));
throw Exception(QObject::tr("Connection error: ") + QString(e.what()));
}
}

Expand All @@ -97,7 +95,7 @@ void ListKeyModel::setListRow(int pos, const QByteArray &value)
m_connection->commandSync({"LSET", m_keyFullPath,
QString::number(pos).toLatin1(), value}, m_dbIndex);
} catch (const RedisClient::Connection::Exception& e) {
throw Exception("Connection error: " + QString(e.what()));
throw Exception(QObject::tr("Connection error: ") + QString(e.what()));
}
}

Expand All @@ -107,6 +105,6 @@ void ListKeyModel::deleteListRow(int count, const QByteArray &value)
m_connection->commandSync({"LREM", m_keyFullPath, QString::number(count).toLatin1(),
value}, m_dbIndex);
} catch (const RedisClient::Connection::Exception& e) {
throw Exception("Connection error: " + QString(e.what()));
throw Exception(QObject::tr("Connection error: ") + QString(e.what()));
}
}
8 changes: 4 additions & 4 deletions src/app/models/key-models/setkey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ QString SetKeyModel::getType()
void SetKeyModel::updateRow(int rowIndex, const QVariantMap &row)
{
if (!isRowLoaded(rowIndex) || !isRowValid(row))
throw Exception("Invalid row");
throw Exception(QObject::tr("Invalid row"));

QByteArray cachedRow = m_rowsCache[rowIndex];
QByteArray newRow(row["value"].toByteArray());
Expand All @@ -29,7 +29,7 @@ void SetKeyModel::updateRow(int rowIndex, const QVariantMap &row)
void SetKeyModel::addRow(const QVariantMap &row)
{
if (!isRowValid(row))
throw Exception("Invalid row");
throw Exception(QObject::tr("Invalid row"));

addSetRow(row["value"].toByteArray());
m_rowCount++;
Expand All @@ -54,7 +54,7 @@ void SetKeyModel::addSetRow(const QByteArray &value)
try {
m_connection->commandSync({"SADD", m_keyFullPath, value}, m_dbIndex);
} catch (const RedisClient::Connection::Exception& e) {
throw Exception("Connection error: " + QString(e.what()));
throw Exception(QObject::tr("Connection error: ") + QString(e.what()));
}
}

Expand All @@ -63,6 +63,6 @@ RedisClient::Response SetKeyModel::deleteSetRow(const QByteArray &value)
try {
return m_connection->commandSync({"SREM", m_keyFullPath, value}, m_dbIndex);
} catch (const RedisClient::Connection::Exception& e) {
throw Exception("Connection error: " + QString(e.what()));
throw Exception(QObject::tr("Connection error: ") + QString(e.what()));
}
}
Loading

0 comments on commit 2bed502

Please sign in to comment.