Skip to content

Commit 8cc964f

Browse files
authored
0.9.0-alpha3 (#3762)
- Add Redis Cluster support - Add Redis Sentinel support - Fix issues with rendering in connections tree - Update translations - Add ability to change language in Settings dialog #3753
1 parent f00eb52 commit 8cc964f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1429
-487
lines changed

src/app/app.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,24 @@ void Application::initUpdater()
206206

207207
void Application::installTranslator()
208208
{
209-
QString locale = QLocale::system().uiLanguages().first().replace( "-", "_" );
209+
QSettings settings;
210+
QString preferredLocale = settings.value("app/locale", "system").toString();
211+
212+
QString locale;
213+
214+
if (preferredLocale == "system") {
215+
settings.setValue("app/locale", "system");
216+
locale = QLocale::system().uiLanguages().first().replace( "-", "_" );
210217

211-
qDebug() << QLocale::system().uiLanguages();
218+
qDebug() << QLocale::system().uiLanguages();
212219

213-
if (locale.isEmpty() || locale == "C")
214-
locale = "en_US";
220+
if (locale.isEmpty() || locale == "C")
221+
locale = "en_US";
215222

216-
qDebug() << "Detected locale:" << locale;
223+
qDebug() << "Detected locale:" << locale;
224+
} else {
225+
locale = preferredLocale;
226+
}
217227

218228
QTranslator* translator = new QTranslator((QObject *)this);
219229
if (translator->load( QString( ":/translations/rdm_" ) + locale ))

src/app/models/treeoperations.cpp

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,25 @@ void TreeOperations::getDatabases(std::function<void (RedisClient::DatabaseList)
3434

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

37-
//detect all databases
38-
RedisClient::Response scanningResp;
39-
int dbIndex = (availableDatabeses.size() == 0)? 0 : availableDatabeses.lastKey() + 1;
40-
41-
while (true) {
42-
try {
43-
scanningResp = m_connection->commandSync("select", QString::number(dbIndex));
44-
} catch (const RedisClient::Connection::Exception& e) {
45-
throw ConnectionsTree::Operations::Exception(QObject::tr("Connection error: ") + QString(e.what()));
37+
if (m_connection->mode() != RedisClient::Connection::Mode::Cluster) {
38+
//detect all databases
39+
RedisClient::Response scanningResp;
40+
int dbIndex = (availableDatabeses.size() == 0)? 0 : availableDatabeses.lastKey() + 1;
41+
42+
while (true) {
43+
try {
44+
scanningResp = m_connection->commandSync("select", QString::number(dbIndex));
45+
} catch (const RedisClient::Connection::Exception& e) {
46+
throw ConnectionsTree::Operations::Exception(QObject::tr("Connection error: ") + QString(e.what()));
47+
}
48+
49+
if (!scanningResp.isOkMessage())
50+
break;
51+
52+
availableDatabeses.insert(dbIndex, 0);
53+
++dbIndex;
4654
}
4755

48-
if (!scanningResp.isOkMessage())
49-
break;
50-
51-
availableDatabeses.insert(dbIndex, 0);
52-
++dbIndex;
5356
}
5457

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

6568
try {
66-
m_connection->getDatabaseKeys(callback, keyPattern, dbIndex);
69+
if (m_connection->mode() == RedisClient::Connection::Mode::Cluster) {
70+
m_connection->getClusterKeys(callback, keyPattern);
71+
} else {
72+
m_connection->getDatabaseKeys(callback, keyPattern, dbIndex);
73+
}
6774
} catch (const RedisClient::Connection::Exception& error) {
6875
callback(RedisClient::Connection::RawKeysList(), QString(QObject::tr("Cannot load keys: %1")).arg(error.what()));
6976
}
@@ -153,3 +160,14 @@ void TreeOperations::flushDb(int dbIndex, std::function<void(const QString&)> ca
153160
throw ConnectionsTree::Operations::Exception(QObject::tr("FlushDB error: ") + QString(e.what()));
154161
}
155162
}
163+
164+
QString TreeOperations::mode()
165+
{
166+
if (m_connection->mode() == RedisClient::Connection::Mode::Cluster) {
167+
return QString("cluster");
168+
} else if (m_connection->mode() == RedisClient::Connection::Mode::Sentinel) {
169+
return QString("sentinel");
170+
} else {
171+
return QString("standalone");
172+
}
173+
}

src/app/models/treeoperations.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class TreeOperations : public QObject, public ConnectionsTree::Operations
4040

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

43+
virtual QString mode() override;
44+
4345
private:
4446
QSharedPointer<RedisClient::Connection> m_connection;
4547
ConnectionsManager& m_manager;

src/modules/connections-tree/items/abstractnamespaceitem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ void AbstractNamespaceItem::renderChilds()
170170
QSharedPointer<TreeItem> self = getSelf().toStrongRef();
171171

172172
if (!self) {
173-
qDebug() << "Cannot render keys: invalid parent item";
173+
qDebug() << "Cannot render keys: invalid parent item";
174174
return;
175175
}
176176

src/modules/connections-tree/items/databaseitem.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ class DatabaseItem : public QObject, public AbstractNamespaceItem
2424

2525
QString getIconUrl() const override;
2626

27-
QString getType() const override { return "database"; }
27+
QString getType() const override { return "database"; }
28+
29+
int itemDepth() const override { return 1; }
2830

2931
bool isLocked() const override;
3032

src/modules/connections-tree/items/keyitem.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class KeyItem : public TreeItem
2222

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

25+
int itemDepth() const override { return m_fullPath.count(m_operations->getNamespaceSeparator().toUtf8()) + 2; }
26+
2527
QList<QSharedPointer<TreeItem>> getAllChilds() const override;
2628

2729
bool supportChildItems() const override;

src/modules/connections-tree/items/namespaceitem.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,21 @@ NamespaceItem::NamespaceItem(const QByteArray &fullPath,
1414
const KeysTreeRenderer::RenderingSettigns& settings)
1515
: AbstractNamespaceItem(model, parent, operations, settings),
1616
m_fullPath(fullPath),
17-
m_removed(false)
17+
m_removed(false),
18+
m_rendering(false)
1819
{
1920
m_displayName = m_fullPath.mid(m_fullPath.lastIndexOf(settings.nsSeparator) + 1);
2021

2122
m_eventHandlers.insert("click", [this]() {
22-
if (m_childItems.size() != 0)
23-
return;
23+
if (m_childItems.size() == 0) {
24+
m_rendering = true;
25+
m_model.itemChanged(getSelf());
2426

25-
renderChilds();
27+
renderChilds();
28+
29+
m_rendering = false;
30+
m_model.itemChanged(getSelf());
31+
}
2632
});
2733

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

4349
QString NamespaceItem::getIconUrl() const
4450
{
51+
if (m_rendering) return QString("qrc:/images/wait.svg");
4552
return QString("qrc:/images/namespace.svg");
4653
}
4754

src/modules/connections-tree/items/namespaceitem.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class NamespaceItem : public QObject, public AbstractNamespaceItem
2424

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

27+
int itemDepth() const override { return m_fullPath.count(m_renderingSettings.nsSeparator.toUtf8()) + 2; }
28+
2729
bool isLocked() const override;
2830

2931
bool isEnabled() const override;
@@ -36,5 +38,6 @@ class NamespaceItem : public QObject, public AbstractNamespaceItem
3638
QByteArray m_fullPath;
3739
QByteArray m_displayName;
3840
bool m_removed;
41+
bool m_rendering;
3942
};
4043
}

src/modules/connections-tree/items/serveritem.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ ServerItem::ServerItem(const QString& name, QSharedPointer<Operations> operation
2626
if (isDatabaseListLoaded())
2727
return;
2828

29-
load();
29+
load();
3030
});
3131

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

3636
m_eventHandlers.insert("reload", [this]() {
3737
reload();
38+
emit m_model.itemChanged(getSelf());
3839
});
3940

4041
m_eventHandlers.insert("unload", [this]() {
41-
unload();
42+
unload();
4243
});
4344

4445
m_eventHandlers.insert("edit", [this]() {
4546
confirmAction(nullptr, tr("Value and Console tabs related to this "
4647
"connection will be closed. Do you want to continue?"), [this]()
4748
{
48-
unload();
49+
unload();
4950
emit editActionRequested();
5051
});
5152
});
5253

5354
m_eventHandlers.insert("delete", [this]() {
5455
confirmAction(nullptr, tr("Do you really want delete connection?"), [this]()
5556
{
56-
unload();
57+
unload();
5758
emit deleteActionRequested();
5859
});
5960
});
@@ -71,8 +72,16 @@ QString ServerItem::getDisplayName() const
7172
QString ServerItem::getIconUrl() const
7273
{
7374
if (m_locked) return QString("qrc:/images/wait.svg");
74-
if (isDatabaseListLoaded()) return QString("qrc:/images/server.svg");
75-
return QString("qrc:/images/server.svg"); //offline
75+
if (isDatabaseListLoaded()) {
76+
if (m_operations->mode() == "cluster") {
77+
return QString("qrc:/images/cluster.svg");
78+
} else if (m_operations->mode() == "sentinel") {
79+
return QString("qrc:/images/sentinel.svg");
80+
} else {
81+
return QString("qrc:/images/server.svg");
82+
}
83+
}
84+
return QString("qrc:/images/server_offline.svg");
7685
}
7786

7887
QList<QSharedPointer<TreeItem> > ServerItem::getAllChilds() const

0 commit comments

Comments
 (0)