Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/app/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,24 @@ void Application::initUpdater()

void Application::installTranslator()
{
QString locale = QLocale::system().uiLanguages().first().replace( "-", "_" );
QSettings settings;
QString preferredLocale = settings.value("app/locale", "system").toString();

QString locale;

if (preferredLocale == "system") {
settings.setValue("app/locale", "system");
locale = QLocale::system().uiLanguages().first().replace( "-", "_" );

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

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

qDebug() << "Detected locale:" << locale;
qDebug() << "Detected locale:" << locale;
} else {
locale = preferredLocale;
}

QTranslator* translator = new QTranslator((QObject *)this);
if (translator->load( QString( ":/translations/rdm_" ) + locale ))
Expand Down
48 changes: 33 additions & 15 deletions src/app/models/treeoperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,25 @@ void TreeOperations::getDatabases(std::function<void (RedisClient::DatabaseList)

RedisClient::DatabaseList availableDatabeses = m_connection->getKeyspaceInfo();

//detect all databases
RedisClient::Response scanningResp;
int dbIndex = (availableDatabeses.size() == 0)? 0 : availableDatabeses.lastKey() + 1;

while (true) {
try {
scanningResp = m_connection->commandSync("select", QString::number(dbIndex));
} catch (const RedisClient::Connection::Exception& e) {
throw ConnectionsTree::Operations::Exception(QObject::tr("Connection error: ") + QString(e.what()));
if (m_connection->mode() != RedisClient::Connection::Mode::Cluster) {
//detect all databases
RedisClient::Response scanningResp;
int dbIndex = (availableDatabeses.size() == 0)? 0 : availableDatabeses.lastKey() + 1;

while (true) {
try {
scanningResp = m_connection->commandSync("select", QString::number(dbIndex));
} catch (const RedisClient::Connection::Exception& e) {
throw ConnectionsTree::Operations::Exception(QObject::tr("Connection error: ") + QString(e.what()));
}

if (!scanningResp.isOkMessage())
break;

availableDatabeses.insert(dbIndex, 0);
++dbIndex;
}

if (!scanningResp.isOkMessage())
break;

availableDatabeses.insert(dbIndex, 0);
++dbIndex;
}

emit m_manager.openServerStats(m_connection);
Expand All @@ -63,7 +66,11 @@ void TreeOperations::getDatabaseKeys(uint dbIndex, QString filter,
QString keyPattern = filter.isEmpty() ? static_cast<ServerConfig>(m_connection->getConfig()).keysPattern() : filter;

try {
m_connection->getDatabaseKeys(callback, keyPattern, dbIndex);
if (m_connection->mode() == RedisClient::Connection::Mode::Cluster) {
m_connection->getClusterKeys(callback, keyPattern);
} else {
m_connection->getDatabaseKeys(callback, keyPattern, dbIndex);
}
} catch (const RedisClient::Connection::Exception& error) {
callback(RedisClient::Connection::RawKeysList(), QString(QObject::tr("Cannot load keys: %1")).arg(error.what()));
}
Expand Down Expand Up @@ -153,3 +160,14 @@ void TreeOperations::flushDb(int dbIndex, std::function<void(const QString&)> ca
throw ConnectionsTree::Operations::Exception(QObject::tr("FlushDB error: ") + QString(e.what()));
}
}

QString TreeOperations::mode()
{
if (m_connection->mode() == RedisClient::Connection::Mode::Cluster) {
return QString("cluster");
} else if (m_connection->mode() == RedisClient::Connection::Mode::Sentinel) {
return QString("sentinel");
} else {
return QString("standalone");
}
}
2 changes: 2 additions & 0 deletions src/app/models/treeoperations.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class TreeOperations : public QObject, public ConnectionsTree::Operations

virtual void flushDb(int dbIndex, std::function<void(const QString&)> callback) override;

virtual QString mode() override;

private:
QSharedPointer<RedisClient::Connection> m_connection;
ConnectionsManager& m_manager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void AbstractNamespaceItem::renderChilds()
QSharedPointer<TreeItem> self = getSelf().toStrongRef();

if (!self) {
qDebug() << "Cannot render keys: invalid parent item";
qDebug() << "Cannot render keys: invalid parent item";
return;
}

Expand Down
4 changes: 3 additions & 1 deletion src/modules/connections-tree/items/databaseitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class DatabaseItem : public QObject, public AbstractNamespaceItem

QString getIconUrl() const override;

QString getType() const override { return "database"; }
QString getType() const override { return "database"; }

int itemDepth() const override { return 1; }

bool isLocked() const override;

Expand Down
2 changes: 2 additions & 0 deletions src/modules/connections-tree/items/keyitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class KeyItem : public TreeItem

QString getType() const override { return "key"; }

int itemDepth() const override { return m_fullPath.count(m_operations->getNamespaceSeparator().toUtf8()) + 2; }

QList<QSharedPointer<TreeItem>> getAllChilds() const override;

bool supportChildItems() const override;
Expand Down
15 changes: 11 additions & 4 deletions src/modules/connections-tree/items/namespaceitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,21 @@ NamespaceItem::NamespaceItem(const QByteArray &fullPath,
const KeysTreeRenderer::RenderingSettigns& settings)
: AbstractNamespaceItem(model, parent, operations, settings),
m_fullPath(fullPath),
m_removed(false)
m_removed(false),
m_rendering(false)
{
m_displayName = m_fullPath.mid(m_fullPath.lastIndexOf(settings.nsSeparator) + 1);

m_eventHandlers.insert("click", [this]() {
if (m_childItems.size() != 0)
return;
if (m_childItems.size() == 0) {
m_rendering = true;
m_model.itemChanged(getSelf());

renderChilds();
renderChilds();

m_rendering = false;
m_model.itemChanged(getSelf());
}
});

m_eventHandlers.insert("delete", [this]() {
Expand All @@ -42,6 +48,7 @@ QByteArray NamespaceItem::getName() const

QString NamespaceItem::getIconUrl() const
{
if (m_rendering) return QString("qrc:/images/wait.svg");
return QString("qrc:/images/namespace.svg");
}

Expand Down
3 changes: 3 additions & 0 deletions src/modules/connections-tree/items/namespaceitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class NamespaceItem : public QObject, public AbstractNamespaceItem

QString getType() const override { return "namespace"; }

int itemDepth() const override { return m_fullPath.count(m_renderingSettings.nsSeparator.toUtf8()) + 2; }

bool isLocked() const override;

bool isEnabled() const override;
Expand All @@ -36,5 +38,6 @@ class NamespaceItem : public QObject, public AbstractNamespaceItem
QByteArray m_fullPath;
QByteArray m_displayName;
bool m_removed;
bool m_rendering;
};
}
21 changes: 15 additions & 6 deletions src/modules/connections-tree/items/serveritem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ServerItem::ServerItem(const QString& name, QSharedPointer<Operations> operation
if (isDatabaseListLoaded())
return;

load();
load();
});

m_eventHandlers.insert("console", [this]() {
Expand All @@ -35,25 +35,26 @@ ServerItem::ServerItem(const QString& name, QSharedPointer<Operations> operation

m_eventHandlers.insert("reload", [this]() {
reload();
emit m_model.itemChanged(getSelf());
});

m_eventHandlers.insert("unload", [this]() {
unload();
unload();
});

m_eventHandlers.insert("edit", [this]() {
confirmAction(nullptr, tr("Value and Console tabs related to this "
"connection will be closed. Do you want to continue?"), [this]()
{
unload();
unload();
emit editActionRequested();
});
});

m_eventHandlers.insert("delete", [this]() {
confirmAction(nullptr, tr("Do you really want delete connection?"), [this]()
{
unload();
unload();
emit deleteActionRequested();
});
});
Expand All @@ -71,8 +72,16 @@ QString ServerItem::getDisplayName() const
QString ServerItem::getIconUrl() const
{
if (m_locked) return QString("qrc:/images/wait.svg");
if (isDatabaseListLoaded()) return QString("qrc:/images/server.svg");
return QString("qrc:/images/server.svg"); //offline
if (isDatabaseListLoaded()) {
if (m_operations->mode() == "cluster") {
return QString("qrc:/images/cluster.svg");
} else if (m_operations->mode() == "sentinel") {
return QString("qrc:/images/sentinel.svg");
} else {
return QString("qrc:/images/server.svg");
}
}
return QString("qrc:/images/server_offline.svg");
}

QList<QSharedPointer<TreeItem> > ServerItem::getAllChilds() const
Expand Down
2 changes: 2 additions & 0 deletions src/modules/connections-tree/items/serveritem.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class ServerItem : public QObject, public TreeItem

QString getType() const override { return "server"; }

int itemDepth() const override { return 0; }

QList<QSharedPointer<TreeItem>> getAllChilds() const override;

uint childCount(bool recursive = false) const override;
Expand Down
4 changes: 3 additions & 1 deletion src/modules/connections-tree/items/treeitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ class TreeItem {

virtual QString getIconUrl() const = 0;

virtual QString getType() const = 0;
virtual QString getType() const = 0;

virtual int itemDepth() const = 0;

virtual QList<QSharedPointer<TreeItem>> getAllChilds() const = 0;

Expand Down
31 changes: 24 additions & 7 deletions src/modules/connections-tree/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ QVariant Model::data(const QModelIndex &index, int role) const
case itemType: return item->getType();
case itemOriginalName: return item->getName();
case itemIsInitiallyExpanded: return item->isExpanded();
case itemDepth: return item->itemDepth();
}

return QVariant();
Expand All @@ -44,6 +45,7 @@ QHash<int, QByteArray> Model::roleNames() const
roles[itemName] = "name";
roles[itemType] = "type";
roles[itemIsInitiallyExpanded] = "expanded";
roles[Qt::DecorationRole] = "icon";
return roles;
}

Expand Down Expand Up @@ -108,12 +110,25 @@ int Model::rowCount(const QModelIndex &parent) const
if (!parentItem)
return m_treeItems.size();

if (parent.column() > 0)
return 0;

return parentItem->childCount();
}

bool Model::hasChildren(const QModelIndex &parent)
{
const TreeItem* parentItem = getItemFromIndex(parent);

if (!parentItem)
return m_treeItems.size() > 0;

if (parentItem->getType() == "key")
return false;

if (parentItem->getType() == "namespace" || parentItem->getType() == "server")
return true;

return parentItem->childCount() > 0;
}

QModelIndex Model::getIndexFromItem(QWeakPointer<TreeItem> item)
{
if (item && item.toStrongRef()) {
Expand Down Expand Up @@ -146,7 +161,7 @@ void Model::onItemChanged(QWeakPointer<TreeItem> item)

auto index = getIndexFromItem(item);

if (!index.isValid() || item.toStrongRef()->childCount() == 0)
if (!index.isValid())
return;

emit dataChanged(index, index);
Expand All @@ -167,6 +182,8 @@ void Model::onItemChildsLoaded(QWeakPointer<TreeItem> item)
emit beginInsertRows(index, 0, treeItem->childCount() - 1);
emit endInsertRows();

emit dataChanged(index, index);

if (treeItem->getType() == "database") {
emit expand(index);

Expand All @@ -176,7 +193,7 @@ void Model::onItemChildsLoaded(QWeakPointer<TreeItem> item)
} else {
qDebug() << "Namespace reopening is disabled in settings";
m_expanded.clear();
}
}
} else if (treeItem->getType() == "server" || treeItem->getType() == "namespace") {
emit expand(index);
}
Expand Down Expand Up @@ -210,9 +227,9 @@ void Model::onExpandItem(QWeakPointer<TreeItem> item)
}


QVariant Model::getItemIcon(const QModelIndex &index)
QVariant Model::getItemDepth(const QModelIndex &index)
{
return data(index, Qt::DecorationRole);
return data(index, itemDepth);
}

QVariant Model::getItemType(const QModelIndex &index)
Expand Down
7 changes: 5 additions & 2 deletions src/modules/connections-tree/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ namespace ConnectionsTree {
itemOriginalName,
itemType,
itemFullPath,
itemIsInitiallyExpanded
itemIsInitiallyExpanded,
itemDepth
};

public:
Expand All @@ -39,6 +40,8 @@ namespace ConnectionsTree {

int rowCount(const QModelIndex & parent = QModelIndex()) const;

bool hasChildren(const QModelIndex &parent = QModelIndex());

inline int columnCount(const QModelIndex & parent = QModelIndex()) const
{
Q_UNUSED(parent);
Expand Down Expand Up @@ -94,7 +97,7 @@ namespace ConnectionsTree {
void onExpandItem(QWeakPointer<TreeItem> item);

public slots:
QVariant getItemIcon(const QModelIndex &index);
QVariant getItemDepth(const QModelIndex &index);

QVariant getItemType(const QModelIndex &index);

Expand Down
2 changes: 2 additions & 0 deletions src/modules/connections-tree/operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ namespace ConnectionsTree {

virtual void flushDb(int dbIndex, std::function<void(const QString&)> callback) = 0;

virtual QString mode() = 0;

virtual ~Operations() {}

};
Expand Down
Loading