Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/mumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Adam <dev@robert-adam.de>2022-09-09 13:54:48 +0300
committerRobert Adam <dev@robert-adam.de>2022-09-09 14:03:47 +0300
commit7c08eaba1e42b3b9c93efe069446e0981a85cd53 (patch)
tree2e2eff3b27663b6510cc2c26810b1584a6b26d80 /src/mumble
parent3c5c411d4bd3184162ae44dc926a5688f832d481 (diff)
FIX(client): Explicitly store shortcut type in DB
When storing shortcuts in the database (which happens only for server-specific shortcuts), the assumption has been that the type of the stored shortcut is always "Whisper/Shout" because up to now this is the only shortcut that can be server-specific. However, this approach is not very future-proof, which is why this commit makes sure that from now on, we explicitly store the type of the shortcut as well.
Diffstat (limited to 'src/mumble')
-rw-r--r--src/mumble/Database.cpp31
-rw-r--r--src/mumble/Messages.cpp4
2 files changed, 24 insertions, 11 deletions
diff --git a/src/mumble/Database.cpp b/src/mumble/Database.cpp
index 63677dd1a..d4aeb30fe 100644
--- a/src/mumble/Database.cpp
+++ b/src/mumble/Database.cpp
@@ -10,6 +10,7 @@
#include "Utils.h"
#include "Version.h"
#include "Global.h"
+#include "GlobalShortcutTypes.h"
#include <QSettings>
#include <QtCore/QStandardPaths>
@@ -163,7 +164,9 @@ Database::Database(const QString &dbname) {
execQueryAndLogFailure(
query, QLatin1String("CREATE TABLE IF NOT EXISTS `shortcut` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `digest` "
- "BLOB, `shortcut` BLOB, `target` BLOB, `suppress` INTEGER)"));
+ "BLOB, `type` INTEGER, `shortcut` BLOB, `target` BLOB, `suppress` INTEGER)"));
+ query.exec(QLatin1String(
+ "ALTER TABLE `shortcut` ADD COLUMN `type` INTEGER")); // Upgrade path, failing this query is not noteworthy
execQueryAndLogFailure(query,
QLatin1String("CREATE INDEX IF NOT EXISTS `shortcut_host_port` ON `shortcut`(`digest`)"));
@@ -546,13 +549,25 @@ QList< Shortcut > Database::getShortcuts(const QByteArray &digest) {
QList< Shortcut > ql;
QSqlQuery query(db);
- query.prepare(QLatin1String("SELECT `shortcut`,`target`,`suppress` FROM `shortcut` WHERE `digest` = ?"));
+ query.prepare(QLatin1String("SELECT `type`, `shortcut`,`target`,`suppress` FROM `shortcut` WHERE `digest` = ?"));
query.addBindValue(digest);
execQueryAndLogFailure(query);
while (query.next()) {
Shortcut sc;
- QByteArray a = query.value(0).toByteArray();
+ QVariant type = query.value(0);
+
+ if (type.isNull()) {
+ // The shortcut's type was originally not explicitly stored, because the assumption was that the only
+ // server-specific shortcuts (which are the ones we're dealing with here) are those configuring whispers or
+ // shouts. Thus, if the field is not set, we assume that we're loading a shortcut from that era, which means
+ // that we'll assume it to be a whisper/shout shortcut as well.
+ sc.iIndex = GlobalShortcutType::Whisper_Shout;
+ } else {
+ sc.iIndex = type.toInt();
+ }
+
+ QByteArray a = query.value(1).toByteArray();
{
QDataStream s(&a, QIODevice::ReadOnly);
@@ -560,7 +575,7 @@ QList< Shortcut > Database::getShortcuts(const QByteArray &digest) {
s >> sc.qlButtons;
}
- a = query.value(1).toByteArray();
+ a = query.value(2).toByteArray();
{
QDataStream s(&a, QIODevice::ReadOnly);
@@ -568,7 +583,7 @@ QList< Shortcut > Database::getShortcuts(const QByteArray &digest) {
s >> sc.qvData;
}
- sc.bSuppress = query.value(2).toBool();
+ sc.bSuppress = query.value(3).toBool();
ql << sc;
}
return ql;
@@ -590,12 +605,14 @@ void Database::setShortcuts(const QByteArray &digest, const QList< Shortcut > &s
query.addBindValue(digest);
execQueryAndLogFailure(query);
- query.prepare(
- QLatin1String("INSERT INTO `shortcut` (`digest`, `shortcut`, `target`, `suppress`) VALUES (?,?,?,?)"));
+ query.prepare(QLatin1String(
+ "INSERT INTO `shortcut` (`digest`, `type`, `shortcut`, `target`, `suppress`) VALUES (?,?,?,?,?)"));
for (const Shortcut &sc : shortcuts) {
if (sc.isServerSpecific()) {
query.addBindValue(digest);
+ query.addBindValue(sc.iIndex);
+
QByteArray a;
{
QDataStream s(&a, QIODevice::WriteOnly);
diff --git a/src/mumble/Messages.cpp b/src/mumble/Messages.cpp
index 631c11896..6e581ae9e 100644
--- a/src/mumble/Messages.cpp
+++ b/src/mumble/Messages.cpp
@@ -160,10 +160,6 @@ void MainWindow::msgServerSync(const MumbleProto::ServerSync &msg) {
QList< Shortcut > sc = Global::get().db->getShortcuts(Global::get().sh->qbaDigest);
if (!sc.isEmpty()) {
- for (int i = 0; i < sc.count(); ++i) {
- Shortcut &s = sc[i];
- s.iIndex = Global::get().mw->gsWhisper->idx;
- }
Global::get().s.qlShortcuts << sc;
GlobalShortcutEngine::engine->bNeedRemap = true;
}