From 26495d6c3663700f4ea6da2be2bb3c0ef2c3a2ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Tue, 11 Apr 2017 17:01:55 +0200 Subject: [PATCH] [apps] Add LED switch on/off to usb timer Change-Id: I6685ab5e21829eb9f2751819b635177a4955d403 --- apps/Makefile | 2 +- apps/apps_container.cpp | 4 ++-- apps/apps_container.h | 4 ++-- apps/exam_mode_timer.cpp | 20 -------------------- apps/usb_timer.cpp | 24 ++++++++++++++++++++++++ apps/{exam_mode_timer.h => usb_timer.h} | 8 ++++---- 6 files changed, 33 insertions(+), 29 deletions(-) delete mode 100644 apps/exam_mode_timer.cpp create mode 100644 apps/usb_timer.cpp rename apps/{exam_mode_timer.h => usb_timer.h} (52%) diff --git a/apps/Makefile b/apps/Makefile index 1267485d0..f66a8a5de 100644 --- a/apps/Makefile +++ b/apps/Makefile @@ -17,7 +17,6 @@ app_objs += $(addprefix apps/,\ battery_view.o\ constant.o\ global_preferences.o\ - exam_mode_timer.o\ exam_pop_up_controller.o\ i18n.o\ led_timer.o\ @@ -26,6 +25,7 @@ app_objs += $(addprefix apps/,\ node.o\ title_bar_view.o\ toolbox_node.o\ + usb_timer.o\ variable_box_controller.o\ variable_box_leaf_cell.o\ ) diff --git a/apps/apps_container.cpp b/apps/apps_container.cpp index fbdca4727..edef5fde1 100644 --- a/apps/apps_container.cpp +++ b/apps/apps_container.cpp @@ -26,7 +26,7 @@ AppsContainer::AppsContainer() : m_examPopUpController(ExamPopUpController()), m_ledTimer(LedTimer()), m_batteryTimer(BatteryTimer(this)), - m_examModeTimer(ExamModeTimer(this)) + m_USBTimer(USBTimer(this)) { refreshPreferences(); } @@ -128,7 +128,7 @@ Timer * AppsContainer::timerAtIndex(int i) { case 0: return &m_batteryTimer; case 1: - return &m_examModeTimer; + return &m_USBTimer; case 2: return &m_ledTimer; default: diff --git a/apps/apps_container.h b/apps/apps_container.h index 808157c30..4fc4ec23d 100644 --- a/apps/apps_container.h +++ b/apps/apps_container.h @@ -16,7 +16,7 @@ #include "exam_pop_up_controller.h" #include "led_timer.h" #include "battery_timer.h" -#include "exam_mode_timer.h" +#include "usb_timer.h" #define USE_PIC_VIEW_APP 0 #if USE_PIC_VIEW_APP @@ -62,7 +62,7 @@ private: ExamPopUpController m_examPopUpController; LedTimer m_ledTimer; BatteryTimer m_batteryTimer; - ExamModeTimer m_examModeTimer; + USBTimer m_USBTimer; }; #endif diff --git a/apps/exam_mode_timer.cpp b/apps/exam_mode_timer.cpp deleted file mode 100644 index 46abc4870..000000000 --- a/apps/exam_mode_timer.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "exam_mode_timer.h" -#include "global_preferences.h" -#include "apps_container.h" - -ExamModeTimer::ExamModeTimer(AppsContainer * container) : - Timer(3), - m_container(container), - m_previousPluggedState(false) -{ -} - -void ExamModeTimer::fire() { - if (!m_previousPluggedState && Ion::USB::isPlugged() && GlobalPreferences::sharedGlobalPreferences()->examMode() == GlobalPreferences::ExamMode::Activate) { - m_container->displayExamModePopUp(false, true); - m_previousPluggedState = true; - } - if (m_previousPluggedState && !Ion::USB::isPlugged()) { - m_previousPluggedState = false; - } -} diff --git a/apps/usb_timer.cpp b/apps/usb_timer.cpp new file mode 100644 index 000000000..0388ba792 --- /dev/null +++ b/apps/usb_timer.cpp @@ -0,0 +1,24 @@ +#include "usb_timer.h" +#include "global_preferences.h" +#include "apps_container.h" + +USBTimer::USBTimer(AppsContainer * container) : + Timer(2), + m_container(container), + m_previousPluggedState(false) +{ +} + +void USBTimer::fire() { + if (Ion::USB::isPlugged()) { + if (!m_previousPluggedState && GlobalPreferences::sharedGlobalPreferences()->examMode() == GlobalPreferences::ExamMode::Activate) { + m_container->displayExamModePopUp(false, true); + } + KDColor LEDColor = Ion::Battery::isCharging() ? KDColorBlue : KDColorGreen; + Ion::LED::setColor(LEDColor); + m_previousPluggedState = true; + } else { + Ion::LED::setColor(KDColorBlack); + m_previousPluggedState = false; + } +} diff --git a/apps/exam_mode_timer.h b/apps/usb_timer.h similarity index 52% rename from apps/exam_mode_timer.h rename to apps/usb_timer.h index a8c5d7ddc..5f49f6085 100644 --- a/apps/exam_mode_timer.h +++ b/apps/usb_timer.h @@ -1,13 +1,13 @@ -#ifndef APPS_EXAM_MODE_TIMER_H -#define APPS_EXAM_MODE_TIMER_H +#ifndef APPS_USB_TIMER_H +#define APPS_USB_TIMER_H #include class AppsContainer; -class ExamModeTimer : public Timer { +class USBTimer : public Timer { public: - ExamModeTimer(AppsContainer * container); + USBTimer(AppsContainer * container); private: void fire() override; AppsContainer * m_container;