mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[usb] Removing residues from the USB protection
This commit is contained in:
@@ -32,8 +32,6 @@ public:
|
||||
void setShowPopUp(bool showPopUp) { m_showPopUp = showPopUp; }
|
||||
bool dfuUnlocked() const { return m_dfuUnlocked; }
|
||||
void setDfuUnlocked(bool unlocked) { m_dfuUnlocked = unlocked; }
|
||||
int dfuLevel() const { return m_dfuLevel; }
|
||||
void setDfuLevel(int level) { m_dfuLevel = level; }
|
||||
bool autocomplete() const { return m_autoComplete; }
|
||||
void setAutocomplete(bool autocomple) { m_autoComplete = autocomple; }
|
||||
bool syntaxhighlighting() const { return m_syntaxhighlighting; }
|
||||
@@ -65,7 +63,6 @@ private:
|
||||
m_tempExamMode(ExamMode::Standard),
|
||||
m_showPopUp(true),
|
||||
m_dfuUnlocked(false),
|
||||
m_dfuLevel(0),
|
||||
m_autoComplete(true),
|
||||
m_syntaxhighlighting(true),
|
||||
m_cursorSaving(true),
|
||||
@@ -84,7 +81,6 @@ private:
|
||||
mutable ExamMode m_tempExamMode;
|
||||
bool m_showPopUp;
|
||||
bool m_dfuUnlocked;
|
||||
uint8_t m_dfuLevel;
|
||||
bool m_autoComplete;
|
||||
bool m_syntaxhighlighting;
|
||||
bool m_cursorSaving;
|
||||
|
||||
@@ -25,7 +25,6 @@ app_settings_src = $(addprefix apps/settings/,\
|
||||
sub_menu/contributors_controller.cpp \
|
||||
sub_menu/math_options_controller.cpp \
|
||||
sub_menu/selectable_view_with_messages.cpp \
|
||||
sub_menu/usb_protection_controller.cpp \
|
||||
sub_menu/external_controller.cpp \
|
||||
sub_menu/brightness_controller.cpp\
|
||||
)
|
||||
|
||||
@@ -45,7 +45,6 @@ MainController::MainController(Responder * parentResponder, InputEventHandlerDel
|
||||
m_examModeController(this),
|
||||
m_aboutController(this),
|
||||
m_preferencesController(this),
|
||||
m_usbInfoController(this),
|
||||
m_externalController(this)
|
||||
{
|
||||
for (int i = 0; i < k_numberOfSimpleChevronCells; i++) {
|
||||
@@ -101,8 +100,6 @@ bool MainController::handleEvent(Ion::Events::Event event) {
|
||||
subController = &m_dateTimeController;
|
||||
} else if (title == I18n::Message::MathOptions) {
|
||||
subController = &m_mathOptionsController;
|
||||
} else if (title == I18n::Message::UsbSetting) {
|
||||
subController = &m_usbInfoController;
|
||||
} else if (title == I18n::Message::CodeApp) {
|
||||
subController = &m_codeOptionsController;
|
||||
} else if (title == I18n::Message::ExternalApps) {
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include "sub_menu/localization_controller.h"
|
||||
#include "sub_menu/math_options_controller.h"
|
||||
#include "sub_menu/preferences_controller.h"
|
||||
#include "sub_menu/usb_protection_controller.h"
|
||||
#include "sub_menu/external_controller.h"
|
||||
#include "sub_menu/brightness_controller.h"
|
||||
|
||||
@@ -83,7 +82,6 @@ private:
|
||||
ExamModeController m_examModeController;
|
||||
AboutController m_aboutController;
|
||||
PreferencesController m_preferencesController;
|
||||
UsbInfoController m_usbInfoController;
|
||||
ExternalController m_externalController;
|
||||
};
|
||||
|
||||
|
||||
@@ -222,8 +222,6 @@ void PreferencesController::setPreferenceWithValueIndex(I18n::Message message, i
|
||||
preferences->setSymbolOfFunction((Preferences::SymbolFunction)valueIndex);
|
||||
} else if (message == I18n::Message::FontSizes) {
|
||||
GlobalPreferences::sharedGlobalPreferences()->setFont(valueIndex == 0 ? KDFont::LargeFont : KDFont::SmallFont);
|
||||
} else if (message == I18n::Message::USBProtectionLevel) {
|
||||
GlobalPreferences::sharedGlobalPreferences()->setDfuLevel(valueIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,9 +248,6 @@ int PreferencesController::valueIndexForPreference(I18n::Message message) const
|
||||
if (message == I18n::Message::FontSizes) {
|
||||
return GlobalPreferences::sharedGlobalPreferences()->font() == KDFont::LargeFont ? 0 : 1;
|
||||
}
|
||||
if (message == I18n::Message::USBProtectionLevel) {
|
||||
return GlobalPreferences::sharedGlobalPreferences()->dfuLevel();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
#include "usb_protection_controller.h"
|
||||
|
||||
#include <apps/i18n.h>
|
||||
#include <apps/settings/main_controller.h>
|
||||
#include <assert.h>
|
||||
#include <ion/storage.h>
|
||||
#include <poincare/preferences.h>
|
||||
#include "../../apps_container.h"
|
||||
#include "../../global_preferences.h"
|
||||
|
||||
using namespace Poincare;
|
||||
using namespace Shared;
|
||||
|
||||
namespace Settings {
|
||||
|
||||
UsbInfoController::UsbInfoController(Responder *parentResponder):
|
||||
GenericSubController(parentResponder),
|
||||
m_usbProtectionLevelController(this),
|
||||
m_contentView(&m_selectableTableView)
|
||||
{
|
||||
m_switchCell.setMessageFont(KDFont::LargeFont);
|
||||
m_dfuLevelCell.setMessageFont(KDFont::LargeFont);
|
||||
}
|
||||
|
||||
bool UsbInfoController::handleEvent(Ion::Events::Event event) {
|
||||
if ((Ion::Events::OK == event || Ion::Events::EXE == event || Ion::Events::Right == event) && selectedRow() == 0) {
|
||||
bool dfuWasUnlocked = GlobalPreferences::sharedGlobalPreferences()->dfuUnlocked();
|
||||
GlobalPreferences::sharedGlobalPreferences()->setDfuUnlocked(!dfuWasUnlocked);
|
||||
m_selectableTableView.reloadCellAtLocation(0, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((Ion::Events::OK == event || Ion::Events::EXE == event || Ion::Events::Right == event) && selectedRow() == 1) {
|
||||
GenericSubController *subController = &m_usbProtectionLevelController;
|
||||
subController->setMessageTreeModel(m_messageTreeModel->childAtIndex(1));
|
||||
StackViewController *stack = stackController();
|
||||
m_lastSelect = selectedRow();
|
||||
stack->push(subController);
|
||||
return true;
|
||||
}
|
||||
|
||||
return GenericSubController::handleEvent(event);
|
||||
}
|
||||
|
||||
HighlightCell *UsbInfoController::reusableCell(int index, int type) {
|
||||
if (index == 0) {
|
||||
return &m_switchCell;
|
||||
}
|
||||
assert(index == 1);
|
||||
return &m_dfuLevelCell;
|
||||
}
|
||||
|
||||
int UsbInfoController::reusableCellCount(int type) {
|
||||
assert(type == 0);
|
||||
return 2;
|
||||
}
|
||||
|
||||
void UsbInfoController::willDisplayCellForIndex(HighlightCell *cell, int index) {
|
||||
GenericSubController::willDisplayCellForIndex(cell, index);
|
||||
|
||||
if (index == 0) {
|
||||
MessageTableCellWithSwitch *myCell = (MessageTableCellWithSwitch *)cell;
|
||||
SwitchView *mySwitch = (SwitchView *)myCell->accessoryView();
|
||||
mySwitch->setState(!GlobalPreferences::sharedGlobalPreferences()->dfuUnlocked());
|
||||
} else if (index == 1) {
|
||||
MessageTableCellWithChevronAndMessage *m_cell = (MessageTableCellWithChevronAndMessage *)cell;
|
||||
int currentLevel = GlobalPreferences::sharedGlobalPreferences()->dfuLevel();
|
||||
if (currentLevel == 0) {
|
||||
m_cell->setSubtitle(I18n::Message::USBDefaultLevelDesc);
|
||||
} else if (currentLevel == 1) {;
|
||||
m_cell->setSubtitle(I18n::Message::USBLowLevelDesc);
|
||||
} else {
|
||||
assert(currentLevel == 2);
|
||||
m_cell->setSubtitle(I18n::Message::USBParanoidLevelDesc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UsbInfoController::didEnterResponderChain(Responder *previousFirstResponder) {
|
||||
m_contentView.reload();
|
||||
I18n::Message infoMessages[] = {I18n::Message::USBExplanation1, I18n::Message::USBExplanation2, I18n::Message::USBExplanation3};
|
||||
m_contentView.setMessages(infoMessages, k_numberOfExplanationMessages);
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
#ifndef SETTINGS_usb_protection_controller_H
|
||||
#define SETTINGS_usb_protection_controller_H
|
||||
|
||||
#include "generic_sub_controller.h"
|
||||
#include "preferences_controller.h"
|
||||
#include "selectable_view_with_messages.h"
|
||||
|
||||
namespace Settings {
|
||||
|
||||
class UsbInfoController : public GenericSubController {
|
||||
public:
|
||||
UsbInfoController(Responder* parentResponder);
|
||||
View* view() override { return &m_contentView; }
|
||||
bool handleEvent(Ion::Events::Event event) override;
|
||||
TELEMETRY_ID("UsbInfo");
|
||||
void didEnterResponderChain(Responder* previousFirstResponder) override;
|
||||
HighlightCell* reusableCell(int index, int type) override;
|
||||
int reusableCellCount(int type) override;
|
||||
void willDisplayCellForIndex(HighlightCell* cell, int index) override;
|
||||
private:
|
||||
static constexpr int k_numberOfExplanationMessages = 3;
|
||||
PreferencesController m_usbProtectionLevelController;
|
||||
SelectableViewWithMessages m_contentView;
|
||||
MessageTableCellWithSwitch m_switchCell;
|
||||
MessageTableCellWithChevronAndMessage m_dfuLevelCell;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -5,8 +5,3 @@ ConnectedMessage3 = "getomega.dev/ide."
|
||||
ConnectedMessage4 = "Drücken Sie die Zurück-Taste am"
|
||||
ConnectedMessage5 = "Taschenrechner oder Kabel abziehen,"
|
||||
ConnectedMessage6 = "um die Verbindung zu trennen."
|
||||
DfuStatus = "Status des Rechners:"
|
||||
DfuStatusUnprotected = "UNGESCHÜTZT"
|
||||
USBProtectionLevel0 = "Standardschutz"
|
||||
USBProtectionLevel1 = "Omega Schutz"
|
||||
USBProtectionLevel2 = "Systemschutz"
|
||||
|
||||
@@ -5,8 +5,3 @@ ConnectedMessage3 = "getomega.dev/ide"
|
||||
ConnectedMessage4 = "Press the BACK key of your"
|
||||
ConnectedMessage5 = "calculator or unplug it to"
|
||||
ConnectedMessage6 = "disconnect it."
|
||||
DfuStatus = "Calculator status:"
|
||||
DfuStatusUnprotected = "UNPROTECTED"
|
||||
USBProtectionLevel0 = "Default Protection"
|
||||
USBProtectionLevel1 = "Omega Protection"
|
||||
USBProtectionLevel2 = "System Protection"
|
||||
|
||||
@@ -5,8 +5,3 @@ ConnectedMessage3 = "getomega.dev/ide"
|
||||
ConnectedMessage4 = "Pulse el botón RETURN de la"
|
||||
ConnectedMessage5 = "calculadora o desenchúfela para"
|
||||
ConnectedMessage6 = "desconectarla."
|
||||
DfuStatus = "Estado de la calculadora:"
|
||||
DfuStatusUnprotected = "DESABRIGADO"
|
||||
USBProtectionLevel0 = "Protección predeterminada"
|
||||
USBProtectionLevel1 = "Protección Omega"
|
||||
USBProtectionLevel2 = "Protección del sistema"
|
||||
|
||||
@@ -5,8 +5,3 @@ ConnectedMessage3 = "getomega.dev/ide"
|
||||
ConnectedMessage4 = "Appuyez sur la touche RETOUR"
|
||||
ConnectedMessage5 = "de la calculatrice ou débranchez-la"
|
||||
ConnectedMessage6 = "pour la déconnecter."
|
||||
DfuStatus = "Etat de la calculatrice:"
|
||||
DfuStatusUnprotected = "NON PROTÉGÉE"
|
||||
USBProtectionLevel0 = "Default Protection"
|
||||
USBProtectionLevel1 = "Omega Protection"
|
||||
USBProtectionLevel2 = "System Protection"
|
||||
|
||||
@@ -5,8 +5,3 @@ ConnectedMessage3 = "fel getomega.dev/ide ra."
|
||||
ConnectedMessage4 = "Nyomjon majd a VISSZA gombra"
|
||||
ConnectedMessage5 = "vagy huzza ki a kábelt azért"
|
||||
ConnectedMessage6 = "hogy a másolás véget érjen."
|
||||
DfuStatus = "Számológép állapota:"
|
||||
DfuStatusUnprotected = "VÉDTELEN"
|
||||
USBProtectionLevel0 = "Alapértelmezett védelem"
|
||||
USBProtectionLevel1 = "Omega védelem"
|
||||
USBProtectionLevel2 = "Rendszervédelem"
|
||||
|
||||
@@ -5,8 +5,3 @@ ConnectedMessage3 = "getomega.dev/ide"
|
||||
ConnectedMessage4 = "Premere sul tasto INDIETRO della"
|
||||
ConnectedMessage5 = "calcolatrice o scollegatela per"
|
||||
ConnectedMessage6 = "disconnetterla."
|
||||
DfuStatus = "Stato della calcolatrice:"
|
||||
DfuStatusUnprotected = "INDIFESO"
|
||||
USBProtectionLevel0 = "Protezione predefinita"
|
||||
USBProtectionLevel1 = "Protezione Omega"
|
||||
USBProtectionLevel2 = "Protezione del sistema"
|
||||
|
||||
@@ -5,8 +5,3 @@ ConnectedMessage3 = "getomega.dev/ide"
|
||||
ConnectedMessage4 = "Druk op de TERUG toets van je"
|
||||
ConnectedMessage5 = "rekenmachine of verwijder de"
|
||||
ConnectedMessage6 = " kabel om hem los te koppelen."
|
||||
DfuStatus = "Rekenmachine status:"
|
||||
DfuStatusUnprotected = "NIET BESCHERMD"
|
||||
USBProtectionLevel0 = "Standaardbeveiliging"
|
||||
USBProtectionLevel1 = "Omega Bescherming"
|
||||
USBProtectionLevel2 = "Systeembeveiliging"
|
||||
|
||||
@@ -5,8 +5,3 @@ ConnectedMessage3 = "getomega.dev/ide"
|
||||
ConnectedMessage4 = "Pressione o botão RETURN na"
|
||||
ConnectedMessage5 = "calculadora ou desligue-a para a"
|
||||
ConnectedMessage6 = "desconectar."
|
||||
DfuStatus = "Status da calculadora:"
|
||||
DfuStatusUnprotected = "DESPROTEGIDO"
|
||||
USBProtectionLevel0 = "Proteção padrão"
|
||||
USBProtectionLevel1 = "Proteção Ômega"
|
||||
USBProtectionLevel2 = "Proteção do sistema"
|
||||
|
||||
@@ -12,8 +12,8 @@ static constexpr I18n::Message sUSBConnectedMessages[] = {
|
||||
I18n::Message::BlankMessage,
|
||||
I18n::Message::ConnectedMessage4,
|
||||
I18n::Message::ConnectedMessage5,
|
||||
I18n::Message::ConnectedMessage6,
|
||||
I18n::Message::DfuStatus};
|
||||
I18n::Message::ConnectedMessage6
|
||||
};
|
||||
|
||||
static constexpr KDColor sUSBConnectedFGColors[] = {
|
||||
Palette::PrimaryText,
|
||||
@@ -34,37 +34,13 @@ USBConnectedController::USBConnectedController() :
|
||||
}
|
||||
|
||||
USBConnectedController::ContentView::ContentView() {
|
||||
// We set the styles of the messages
|
||||
for (uint8_t i = 0; i < k_numberOfMessages; i++) {
|
||||
for (uint8_t i = 0; i < k_numberOfUSBMessages; i++) {
|
||||
m_messageTextViews[i].setFont(i == 0 ? KDFont::LargeFont : KDFont::SmallFont);
|
||||
m_messageTextViews[i].setAlignment(0.5f, 0.5f);
|
||||
m_messageTextViews[i].setTextColor(sUSBConnectedFGColors[i]);
|
||||
m_messageTextViews[i].setBackgroundColor(Palette::BackgroundHard);
|
||||
}
|
||||
|
||||
// We set the texts of the firsts defaults messages
|
||||
for (uint8_t i = 0; i < k_numberOfUSBMessages; i++) {
|
||||
m_messageTextViews[i].setText(I18n::translate(sUSBConnectedMessages[i]));
|
||||
}
|
||||
|
||||
// Last message, depending of the USB protection level
|
||||
if (GlobalPreferences::sharedGlobalPreferences()->dfuUnlocked()) {
|
||||
m_messageTextViews[k_numberOfUSBMessages].setText(I18n::translate(I18n::Message::DfuStatusUnprotected));
|
||||
} else {
|
||||
int protectionLevel = GlobalPreferences::sharedGlobalPreferences()->dfuLevel();
|
||||
switch (protectionLevel) {
|
||||
case 0:
|
||||
m_messageTextViews[9].setText(I18n::translate(I18n::Message::USBProtectionLevel0));
|
||||
break;
|
||||
case 1:
|
||||
m_messageTextViews[9].setText(I18n::translate(I18n::Message::USBProtectionLevel1));
|
||||
break;
|
||||
default:
|
||||
assert(protectionLevel == 2);
|
||||
m_messageTextViews[9].setText(I18n::translate(I18n::Message::USBProtectionLevel2));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void USBConnectedController::ContentView::drawRect(KDContext *ctx, KDRect rect) const {
|
||||
@@ -72,7 +48,7 @@ void USBConnectedController::ContentView::drawRect(KDContext *ctx, KDRect rect)
|
||||
}
|
||||
|
||||
View *USBConnectedController::ContentView::subviewAtIndex(int index) {
|
||||
assert(index < k_numberOfMessages);
|
||||
assert(index < k_numberOfUSBMessages);
|
||||
return &(m_messageTextViews[index]);
|
||||
}
|
||||
|
||||
@@ -81,7 +57,7 @@ void USBConnectedController::ContentView::layoutSubviews(bool force) {
|
||||
KDCoordinate titleHeight = m_messageTextViews[0].minimalSizeForOptimalDisplay().height();
|
||||
KDCoordinate textHeight = KDFont::SmallFont->glyphSize().height();
|
||||
m_messageTextViews[0].setFrame(KDRect(0, k_titleMargin, width, titleHeight), force);
|
||||
for (uint8_t i = 1; i < k_numberOfMessages; i++) {
|
||||
for (uint8_t i = 1; i < k_numberOfUSBMessages; i++) {
|
||||
m_messageTextViews[i].setFrame(KDRect(0, k_paragraphHeight + (i - 1) * textHeight, width, textHeight), force);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,15 +16,14 @@ private:
|
||||
ContentView();
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
protected:
|
||||
int numberOfSubviews() const override { return k_numberOfMessages; }
|
||||
int numberOfSubviews() const override { return k_numberOfUSBMessages; }
|
||||
View * subviewAtIndex(int index) override;
|
||||
void layoutSubviews(bool force = false) override;
|
||||
private:
|
||||
constexpr static KDCoordinate k_titleMargin = 30;
|
||||
constexpr static KDCoordinate k_paragraphHeight = 80;
|
||||
constexpr static uint8_t k_numberOfUSBMessages = 9;
|
||||
constexpr static uint8_t k_numberOfMessages = k_numberOfUSBMessages + 1;
|
||||
MessageTextView m_messageTextViews[k_numberOfMessages];
|
||||
constexpr static uint8_t k_numberOfUSBMessages = 8;
|
||||
MessageTextView m_messageTextViews[k_numberOfUSBMessages];
|
||||
};
|
||||
ContentView m_contentView;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user