diff --git a/src/CredentialsManagement.cpp b/src/CredentialsManagement.cpp index de8f8a21..4e0d4394 100644 --- a/src/CredentialsManagement.cpp +++ b/src/CredentialsManagement.cpp @@ -1315,6 +1315,7 @@ void CredentialsManagement::on_pushButtonSaveCategories_clicked() wsClient->sendSetUserCategories(cat1, cat2, cat3, cat4); ui->pushButtonSaveCategories->hide(); m_pCredModel->updateCategories(cat1, cat2, cat3, cat4); + emit wsClient->updateCurrentCategories(cat1, cat2, cat3, cat4); ui->credDisplayCategoryInput->setItemText(1, cat1); ui->credDisplayCategoryInput->setItemText(2, cat2); ui->credDisplayCategoryInput->setItemText(3, cat3); diff --git a/src/MPDeviceBleImpl.cpp b/src/MPDeviceBleImpl.cpp index f2ba1350..8d5f2a4f 100644 --- a/src/MPDeviceBleImpl.cpp +++ b/src/MPDeviceBleImpl.cpp @@ -68,6 +68,17 @@ void MPDeviceBleImpl::getPlatInfo() mpDev->enqueueAndRunJob(jobs); } +void MPDeviceBleImpl::enforceCategory(int category) +{ + auto *jobs = new AsyncJobs("Set current category", mpDev); + + QByteArray catArr; + catArr.append(static_cast(category)); + jobs->append(new MPCommandJob(mpDev, MPCmd::SET_CUR_CATEGORY, catArr, bleProt->getDefaultSizeCheckFuncDone())); + + mpDev->enqueueAndRunJob(jobs); +} + void MPDeviceBleImpl::getDebugPlatInfo(const MessageHandlerCbData &cb) { auto *jobs = new AsyncJobs("Get Debug PlatInfo", mpDev); diff --git a/src/MPDeviceBleImpl.h b/src/MPDeviceBleImpl.h index 191f80ea..51ed8817 100644 --- a/src/MPDeviceBleImpl.h +++ b/src/MPDeviceBleImpl.h @@ -53,6 +53,7 @@ class MPDeviceBleImpl: public QObject bool isLastPacket(const QByteArray &data); void getPlatInfo(); + void enforceCategory(int category); void getDebugPlatInfo(const MessageHandlerCbData &cb); QVector calcDebugPlatInfo(const QByteArray &platInfo); diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 49db9d5c..995f17b8 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -223,6 +223,12 @@ MainWindow::MainWindow(WSClient *client, DbMasterController *mc, QWidget *parent m_notesFetched = true; wsClient->sendFetchNotes(); } + auto currentCategoryIndex = ui->comboBoxBleCurrentCategory->currentIndex(); + if (currentCategoryIndex != 0) + { + // When enforce current category is set sending category number to device + wsClient->sendCurrentCategory(currentCategoryIndex); + } } else { @@ -408,6 +414,10 @@ MainWindow::MainWindow(WSClient *client, DbMasterController *mc, QWidget *parent } ui->comboBoxSystrayIcon->blockSignals(false); + fillInitialCurrentCategories(); + connect(wsClient, &WSClient::displayUserCategories, this, &MainWindow::setCurrentCategoryOptions); + connect(wsClient, &WSClient::updateCurrentCategories, this, &MainWindow::setCurrentCategoryOptions); + ui->cbLoginPrompt->setDisabled(true); ui->cbPinForMMM->setDisabled(true); ui->cbStoragePrompt->setDisabled(true); @@ -1881,6 +1891,20 @@ void MainWindow::fillBLEBrightnessComboBox(QComboBox *cb) cb->addItem("100%", 144); } +void MainWindow::fillInitialCurrentCategories() +{ + QSettings s; + ui->comboBoxBleCurrentCategory->blockSignals(true); + ui->comboBoxBleCurrentCategory->clear(); + ui->comboBoxBleCurrentCategory->addItem(tr("Disabled"), 0); + ui->comboBoxBleCurrentCategory->addItem("1", 1); + ui->comboBoxBleCurrentCategory->addItem("2", 2); + ui->comboBoxBleCurrentCategory->addItem("3", 3); + ui->comboBoxBleCurrentCategory->addItem("4", 4); + ui->comboBoxBleCurrentCategory->setCurrentIndex(s.value("settings/enforced_category", 0).toInt()); + ui->comboBoxBleCurrentCategory->blockSignals(false); +} + void MainWindow::on_toolButton_clearBackupFilePath_released() { ui->lineEdit_dbBackupFilePath->clear(); @@ -2145,6 +2169,7 @@ void MainWindow::onDeviceDisconnected() noPasswordPromptChanged(false); ui->pushButtonSettingsSetToDefault->setVisible(false); m_notesFetched = false; + fillInitialCurrentCategories(); } ui->groupBox_UserSettings->hide(); wsClient->set_cardId(""); @@ -2324,3 +2349,28 @@ void MainWindow::sendRequestNotes(int bundle) wsClient->sendFetchNotes(); } } + +void MainWindow::on_comboBoxBleCurrentCategory_currentIndexChanged(int index) +{ + QSettings s; + s.setValue("settings/enforced_category", index); +} + +void MainWindow::setCurrentCategoryOptions(const QString &cat1, const QString &cat2, const QString &cat3, const QString &cat4) +{ + if (cat1.isEmpty() && cat2.isEmpty() && cat3.isEmpty() && cat4.isEmpty()) + { + // When BLE device is connected, but not unlocked daemon is sending categories with empty string + return; + } + QSettings s; + ui->comboBoxBleCurrentCategory->blockSignals(true); + ui->comboBoxBleCurrentCategory->clear(); + ui->comboBoxBleCurrentCategory->addItem(tr("Disabled"), 0); + ui->comboBoxBleCurrentCategory->addItem(cat1, 1); + ui->comboBoxBleCurrentCategory->addItem(cat2, 2); + ui->comboBoxBleCurrentCategory->addItem(cat3, 3); + ui->comboBoxBleCurrentCategory->addItem(cat4, 4); + ui->comboBoxBleCurrentCategory->setCurrentIndex(s.value("settings/enforced_category", 0).toInt()); + ui->comboBoxBleCurrentCategory->blockSignals(false); +} diff --git a/src/MainWindow.h b/src/MainWindow.h index 5fca7ff3..fb3b250e 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -199,6 +199,10 @@ private slots: void sendRequestNotes(int bundle); + void on_comboBoxBleCurrentCategory_currentIndexChanged(int index); + + void setCurrentCategoryOptions(const QString& cat1, const QString& cat2, const QString& cat3, const QString& cat4); + protected: virtual void keyPressEvent(QKeyEvent *event) override; virtual void keyReleaseEvent(QKeyEvent *event) override; @@ -240,6 +244,8 @@ private slots: void fillBLEBrightnessComboBox(QComboBox * cb); + void fillInitialCurrentCategories(); + Ui::MainWindow *ui = nullptr; QtAwesome* awesome; diff --git a/src/MainWindow.ui b/src/MainWindow.ui index eb0d775f..5abadcad 100644 --- a/src/MainWindow.ui +++ b/src/MainWindow.ui @@ -4074,6 +4074,46 @@ Hint: keep your mouse positioned over an option to get more details. + + + + + + when selected, you can set moolticute to set a given category upon device connection + + + Upon connection, force category: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 80 + 0 + + + + when selected, you can set moolticute to set a given category upon device connection + + + + + diff --git a/src/MessageProtocol/MessageProtocolBLE.cpp b/src/MessageProtocol/MessageProtocolBLE.cpp index c647050d..c179f938 100644 --- a/src/MessageProtocol/MessageProtocolBLE.cpp +++ b/src/MessageProtocol/MessageProtocolBLE.cpp @@ -373,6 +373,7 @@ void MessageProtocolBLE::fillCommandMapping() {MPCmd::DELETE_DATA_FILE , 0x003B}, {MPCmd::DELETE_NOTE_FILE , 0x003C}, {MPCmd::GET_TOTP_CODE , 0x0041}, + {MPCmd::SET_CUR_CATEGORY , 0x003E}, {MPCmd::CMD_DBG_OPEN_DISP_BUFFER , 0x8001}, {MPCmd::CMD_DBG_SEND_TO_DISP_BUFFER , 0x8002}, {MPCmd::CMD_DBG_CLOSE_DISP_BUFFER , 0x8003}, diff --git a/src/MooltipassCmds.h b/src/MooltipassCmds.h index e64c6366..e330bc9a 100644 --- a/src/MooltipassCmds.h +++ b/src/MooltipassCmds.h @@ -169,6 +169,7 @@ class MPCmd: public QObject DELETE_DATA_FILE , DELETE_NOTE_FILE , GET_TOTP_CODE , + SET_CUR_CATEGORY , CMD_DBG_MESSAGE , CMD_DBG_OPEN_DISP_BUFFER , CMD_DBG_SEND_TO_DISP_BUFFER , diff --git a/src/WSClient.cpp b/src/WSClient.cpp index 8d110ec3..fb56f89b 100644 --- a/src/WSClient.cpp +++ b/src/WSClient.cpp @@ -877,6 +877,14 @@ void WSClient::sendBatteryRequest() sendJsonData({{ "msg", "get_battery" }}); } +void WSClient::sendCurrentCategory(int category) +{ + QJsonObject o; + o["category"] = category; + sendJsonData({{ "msg", "enforce_current_category" }, + {"data", o}}); +} + void WSClient::sendNiMHReconditioning() { sendJsonData({{ "msg", "nimh_reconditioning" }}); diff --git a/src/WSClient.h b/src/WSClient.h index 7e01a51a..ab423673 100644 --- a/src/WSClient.h +++ b/src/WSClient.h @@ -114,6 +114,7 @@ class WSClient: public QObject void sendUserSettingsRequest(); void sendLoadParams(); void sendBatteryRequest(); + void sendCurrentCategory(int category); void sendNiMHReconditioning(); void sendSecurityChallenge(QString str); @@ -156,6 +157,7 @@ class WSClient: public QObject void displayUploadBundleResult(bool success); void displayAvailableUsers(const QString& num); void displayUserCategories(const QString& cat1, const QString& cat2, const QString& cat3, const QString& cat4); + void updateCurrentCategories(const QString& cat1, const QString& cat2, const QString& cat3, const QString& cat4); void updateUserSettingsOnUI(const QJsonObject& userSettings); void deviceConnected(); void deviceDisconnected(); diff --git a/src/WSServerCon.cpp b/src/WSServerCon.cpp index fc5e7903..f9b3a8a2 100644 --- a/src/WSServerCon.cpp +++ b/src/WSServerCon.cpp @@ -1523,6 +1523,17 @@ void WSServerCon::processMessageBLE(QJsonObject root, const MPDeviceProgressCb & sendJsonMessage(oroot); }); } + else if (root["msg"] == "enforce_current_category") + { + static constexpr int ENFORCE_CATEGORY_SUPPORT_FW = 9; + if (bleImpl->get_bundleVersion() < ENFORCE_CATEGORY_SUPPORT_FW) + { + qWarning() << "Enforce category is not supported in the current bundle version"; + return; + } + QJsonObject o = root["data"].toObject(); + bleImpl->enforceCategory(o["category"].toInt()); + } else { qDebug() << root["msg"] << " message have not implemented yet for BLE";