/* * This file is part of openauto project. * Copyright (C) 2018 f1x.studio (Michal Szwaj) * * openauto is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * openauto is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with openauto. If not, see . */ #include #include #include namespace f1x { namespace openauto { namespace autoapp { namespace configuration { const std::string Configuration::cConfigFileName = "openauto.ini"; const std::string Configuration::cGeneralShowClockKey = "General.ShowClock"; const std::string Configuration::cGeneralShowBigClockKey = "General.ShowBigClock"; const std::string Configuration::cGeneralOldGUIKey = "General.OldGUI"; const std::string Configuration::cGeneralAlphaTransKey = "General.AlphaTrans"; const std::string Configuration::cGeneralHideMenuToggleKey = "General.HideMenuToggle"; const std::string Configuration::cGeneralHideAlphaKey = "General.HideAlpha"; const std::string Configuration::cGeneralShowLuxKey = "General.ShowLux"; const std::string Configuration::cGeneralShowCursorKey = "General.ShowCursor"; const std::string Configuration::cGeneralHideBrightnessControlKey = "General.HideBrightnessControl"; const std::string Configuration::cGeneralHandednessOfTrafficTypeKey = "General.HandednessOfTrafficType"; const std::string Configuration::cGeneralMp3MasterPathKey = "General.Mp3MasterPath"; const std::string Configuration::cGeneralMp3SubFolderKey = "General.Mp3SubFolder"; const std::string Configuration::cGeneralMp3TrackKey = "General.Mp3Track"; const std::string Configuration::cGeneralMp3AutoPlayKey = "General.Mp3AutoPlay"; const std::string Configuration::cGeneralShowAutoPlayKey = "General.ShowAutoPlay"; const std::string Configuration::cVideoFPSKey = "Video.FPS"; const std::string Configuration::cVideoResolutionKey = "Video.Resolution"; const std::string Configuration::cVideoScreenDPIKey = "Video.ScreenDPI"; const std::string Configuration::cVideoOMXLayerIndexKey = "Video.OMXLayerIndex"; const std::string Configuration::cVideoMarginWidth = "Video.MarginWidth"; const std::string Configuration::cVideoMarginHeight = "Video.MarginHeight"; const std::string Configuration::cAudioMusicAudioChannelEnabled = "Audio.MusicAudioChannelEnabled"; const std::string Configuration::cAudioSpeechAudioChannelEnabled = "Audio.SpeechAudioChannelEnabled"; const std::string Configuration::cAudioOutputBackendType = "Audio.OutputBackendType"; const std::string Configuration::cBluetoothAdapterTypeKey = "Bluetooth.AdapterType"; const std::string Configuration::cBluetoothRemoteAdapterAddressKey = "Bluetooth.RemoteAdapterAddress"; const std::string Configuration::cInputEnableTouchscreenKey = "Input.EnableTouchscreen"; const std::string Configuration::cInputPlayButtonKey = "Input.PlayButton"; const std::string Configuration::cInputPauseButtonKey = "Input.PauseButton"; const std::string Configuration::cInputTogglePlayButtonKey = "Input.TogglePlayButton"; const std::string Configuration::cInputNextTrackButtonKey = "Input.NextTrackButton"; const std::string Configuration::cInputPreviousTrackButtonKey = "Input.PreviousTrackButton"; const std::string Configuration::cInputHomeButtonKey = "Input.HomeButton"; const std::string Configuration::cInputPhoneButtonKey = "Input.PhoneButton"; const std::string Configuration::cInputCallEndButtonKey = "Input.CallEndButton"; const std::string Configuration::cInputVoiceCommandButtonKey = "Input.VoiceCommandButton"; const std::string Configuration::cInputLeftButtonKey = "Input.LeftButton"; const std::string Configuration::cInputRightButtonKey = "Input.RightButton"; const std::string Configuration::cInputUpButtonKey = "Input.UpButton"; const std::string Configuration::cInputDownButtonKey = "Input.DownButton"; const std::string Configuration::cInputScrollWheelButtonKey = "Input.ScrollWheelButton"; const std::string Configuration::cInputBackButtonKey = "Input.BackButton"; const std::string Configuration::cInputEnterButtonKey = "Input.EnterButton"; Configuration::Configuration() { this->load(); } void Configuration::load() { boost::property_tree::ptree iniConfig; try { boost::property_tree::ini_parser::read_ini(cConfigFileName, iniConfig); handednessOfTrafficType_ = static_cast(iniConfig.get(cGeneralHandednessOfTrafficTypeKey, static_cast(HandednessOfTrafficType::LEFT_HAND_DRIVE))); showClock_ = iniConfig.get(cGeneralShowClockKey, true); showBigClock_ = iniConfig.get(cGeneralShowBigClockKey, false); oldGUI_ = iniConfig.get(cGeneralOldGUIKey, false); alphaTrans_ = iniConfig.get(cGeneralAlphaTransKey, 50); hideMenuToggle_ = iniConfig.get(cGeneralHideMenuToggleKey, false); hideAlpha_ = iniConfig.get(cGeneralHideAlphaKey, false); showLux_ = iniConfig.get(cGeneralShowLuxKey, false); showCursor_ = iniConfig.get(cGeneralShowCursorKey, false); hideBrightnessControl_ = iniConfig.get(cGeneralHideBrightnessControlKey, false); mp3MasterPath_ = iniConfig.get(cGeneralMp3MasterPathKey, "/media/MYMEDIA"); mp3SubFolder_ = iniConfig.get(cGeneralMp3SubFolderKey, "/"); mp3Track_ = iniConfig.get(cGeneralMp3TrackKey, 0); mp3AutoPlay_ = iniConfig.get(cGeneralMp3AutoPlayKey, false); showAutoPlay_ = iniConfig.get(cGeneralShowAutoPlayKey, false); videoFPS_ = static_cast(iniConfig.get(cVideoFPSKey, aasdk::proto::enums::VideoFPS::_30)); videoResolution_ = static_cast(iniConfig.get(cVideoResolutionKey, aasdk::proto::enums::VideoResolution::_480p)); screenDPI_ = iniConfig.get(cVideoScreenDPIKey, 100); omxLayerIndex_ = iniConfig.get(cVideoOMXLayerIndexKey, 1); videoMargins_ = QRect(0, 0, iniConfig.get(cVideoMarginWidth, 0), iniConfig.get(cVideoMarginHeight, 0)); enableTouchscreen_ = iniConfig.get(cInputEnableTouchscreenKey, true); this->readButtonCodes(iniConfig); bluetoothAdapterType_ = static_cast(iniConfig.get(cBluetoothAdapterTypeKey, static_cast(BluetoothAdapterType::NONE))); bluetoothRemoteAdapterAddress_ = iniConfig.get(cBluetoothRemoteAdapterAddressKey, ""); musicAudioChannelEnabled_ = iniConfig.get(cAudioMusicAudioChannelEnabled, true); speechAudiochannelEnabled_ = iniConfig.get(cAudioSpeechAudioChannelEnabled, true); audioOutputBackendType_ = static_cast(iniConfig.get(cAudioOutputBackendType, static_cast(AudioOutputBackendType::RTAUDIO))); } catch(const boost::property_tree::ini_parser_error& e) { OPENAUTO_LOG(warning) << "[Configuration] failed to read configuration file: " << cConfigFileName << ", error: " << e.what() << ". Using default configuration."; this->reset(); } } void Configuration::reset() { handednessOfTrafficType_ = HandednessOfTrafficType::LEFT_HAND_DRIVE; showClock_ = true; showBigClock_ = false; oldGUI_ = false; alphaTrans_ = 50; hideMenuToggle_ = false; hideAlpha_ = false; showLux_ = false; showCursor_ = false; hideBrightnessControl_ = false; mp3MasterPath_ = "/media/MYMEDIA"; mp3SubFolder_ = "/"; mp3Track_ = 0; mp3AutoPlay_ = false; showAutoPlay_ = false; videoFPS_ = aasdk::proto::enums::VideoFPS::_30; videoResolution_ = aasdk::proto::enums::VideoResolution::_480p; screenDPI_ = 100; omxLayerIndex_ = 1; videoMargins_ = QRect(0, 0, 0, 0); enableTouchscreen_ = true; buttonCodes_.clear(); bluetoothAdapterType_ = BluetoothAdapterType::NONE; bluetoothRemoteAdapterAddress_ = ""; musicAudioChannelEnabled_ = true; speechAudiochannelEnabled_ = true; audioOutputBackendType_ = AudioOutputBackendType::QT; } void Configuration::save() { boost::property_tree::ptree iniConfig; iniConfig.put(cGeneralHandednessOfTrafficTypeKey, static_cast(handednessOfTrafficType_)); iniConfig.put(cGeneralShowClockKey, showClock_); iniConfig.put(cGeneralShowBigClockKey, showBigClock_); iniConfig.put(cGeneralOldGUIKey, oldGUI_); iniConfig.put(cGeneralAlphaTransKey, alphaTrans_); iniConfig.put(cGeneralHideMenuToggleKey, hideMenuToggle_); iniConfig.put(cGeneralHideAlphaKey, hideAlpha_); iniConfig.put(cGeneralShowLuxKey, showLux_); iniConfig.put(cGeneralShowCursorKey, showCursor_); iniConfig.put(cGeneralHideBrightnessControlKey, hideBrightnessControl_); iniConfig.put(cGeneralMp3MasterPathKey, mp3MasterPath_); iniConfig.put(cGeneralMp3SubFolderKey, mp3SubFolder_); iniConfig.put(cGeneralMp3TrackKey, mp3Track_); iniConfig.put(cGeneralMp3AutoPlayKey, mp3AutoPlay_); iniConfig.put(cGeneralShowAutoPlayKey, showAutoPlay_); iniConfig.put(cVideoFPSKey, static_cast(videoFPS_)); iniConfig.put(cVideoResolutionKey, static_cast(videoResolution_)); iniConfig.put(cVideoScreenDPIKey, screenDPI_); iniConfig.put(cVideoOMXLayerIndexKey, omxLayerIndex_); iniConfig.put(cVideoMarginWidth, videoMargins_.width()); iniConfig.put(cVideoMarginHeight, videoMargins_.height()); iniConfig.put(cInputEnableTouchscreenKey, enableTouchscreen_); this->writeButtonCodes(iniConfig); iniConfig.put(cBluetoothAdapterTypeKey, static_cast(bluetoothAdapterType_)); iniConfig.put(cBluetoothRemoteAdapterAddressKey, bluetoothRemoteAdapterAddress_); iniConfig.put(cAudioMusicAudioChannelEnabled, musicAudioChannelEnabled_); iniConfig.put(cAudioSpeechAudioChannelEnabled, speechAudiochannelEnabled_); iniConfig.put(cAudioOutputBackendType, static_cast(audioOutputBackendType_)); boost::property_tree::ini_parser::write_ini(cConfigFileName, iniConfig); } bool Configuration::hasTouchScreen() const { auto touchdevs = QTouchDevice::devices(); OPENAUTO_LOG(info) << "[Touchdev] " << "Querying available touch devices [" << touchdevs.length() << " available]"; for (int i = 0; i < touchdevs.length(); i++) { if (touchdevs[i]->type() == QTouchDevice::TouchScreen) { OPENAUTO_LOG(info) << "[Touchdev] Device " << i << ": " << touchdevs[i]->name().toStdString() << ", type " << touchdevs[i]->type(); return true; } } return false; } void Configuration::setHandednessOfTrafficType(HandednessOfTrafficType value) { handednessOfTrafficType_ = value; } HandednessOfTrafficType Configuration::getHandednessOfTrafficType() const { return handednessOfTrafficType_; } void Configuration::showClock(bool value) { showClock_ = value; } bool Configuration::showClock() const { return showClock_; } void Configuration::showBigClock(bool value) { showBigClock_ = value; } bool Configuration::showBigClock() const { return showBigClock_; } void Configuration::oldGUI(bool value) { oldGUI_ = value; } bool Configuration::oldGUI() const { return oldGUI_; } size_t Configuration::getAlphaTrans() const { return alphaTrans_; } void Configuration::setAlphaTrans(size_t value) { alphaTrans_ = value; } void Configuration::hideMenuToggle(bool value) { hideMenuToggle_ = value; } bool Configuration::hideMenuToggle() const { return hideMenuToggle_; } void Configuration::hideAlpha(bool value) { hideAlpha_ = value; } bool Configuration::hideAlpha() const { return hideAlpha_; } void Configuration::showLux(bool value) { showLux_ = value; } bool Configuration::showLux() const { return showLux_; } void Configuration::showCursor(bool value) { showCursor_ = value; } bool Configuration::showCursor() const { return showCursor_; } void Configuration::hideBrightnessControl(bool value) { hideBrightnessControl_ = value; } bool Configuration::hideBrightnessControl() const { return hideBrightnessControl_; } std::string Configuration::getMp3MasterPath() const { return mp3MasterPath_; } void Configuration::setMp3MasterPath(const std::string& value) { mp3MasterPath_ = value; } std::string Configuration::getMp3SubFolder() const { return mp3SubFolder_; } void Configuration::setMp3Track(int32_t value) { mp3Track_ = value; } void Configuration::setMp3SubFolder(const std::string& value) { mp3SubFolder_ = value; } int32_t Configuration::getMp3Track() const { return mp3Track_; } void Configuration::mp3AutoPlay(bool value) { mp3AutoPlay_ = value; } bool Configuration::mp3AutoPlay() const { return mp3AutoPlay_; } void Configuration::showAutoPlay(bool value) { showAutoPlay_ = value; } bool Configuration::showAutoPlay() const { return showAutoPlay_; } aasdk::proto::enums::VideoFPS::Enum Configuration::getVideoFPS() const { return videoFPS_; } void Configuration::setVideoFPS(aasdk::proto::enums::VideoFPS::Enum value) { videoFPS_ = value; } aasdk::proto::enums::VideoResolution::Enum Configuration::getVideoResolution() const { return videoResolution_; } void Configuration::setVideoResolution(aasdk::proto::enums::VideoResolution::Enum value) { videoResolution_ = value; } size_t Configuration::getScreenDPI() const { return screenDPI_; } void Configuration::setScreenDPI(size_t value) { screenDPI_ = value; } void Configuration::setOMXLayerIndex(int32_t value) { omxLayerIndex_ = value; } int32_t Configuration::getOMXLayerIndex() const { return omxLayerIndex_; } void Configuration::setVideoMargins(QRect value) { videoMargins_ = value; } QRect Configuration::getVideoMargins() const { return videoMargins_; } bool Configuration::getTouchscreenEnabled() const { return enableTouchscreen_; } void Configuration::setTouchscreenEnabled(bool value) { enableTouchscreen_ = value; } Configuration::ButtonCodes Configuration::getButtonCodes() const { return buttonCodes_; } void Configuration::setButtonCodes(const ButtonCodes& value) { buttonCodes_ = value; } BluetoothAdapterType Configuration::getBluetoothAdapterType() const { return bluetoothAdapterType_; } void Configuration::setBluetoothAdapterType(BluetoothAdapterType value) { bluetoothAdapterType_ = value; } std::string Configuration::getBluetoothRemoteAdapterAddress() const { return bluetoothRemoteAdapterAddress_; } void Configuration::setBluetoothRemoteAdapterAddress(const std::string& value) { bluetoothRemoteAdapterAddress_ = value; } bool Configuration::musicAudioChannelEnabled() const { return musicAudioChannelEnabled_; } void Configuration::setMusicAudioChannelEnabled(bool value) { musicAudioChannelEnabled_ = value; } bool Configuration::speechAudioChannelEnabled() const { return speechAudiochannelEnabled_; } void Configuration::setSpeechAudioChannelEnabled(bool value) { speechAudiochannelEnabled_ = value; } AudioOutputBackendType Configuration::getAudioOutputBackendType() const { return audioOutputBackendType_; } void Configuration::setAudioOutputBackendType(AudioOutputBackendType value) { audioOutputBackendType_ = value; } void Configuration::readButtonCodes(boost::property_tree::ptree& iniConfig) { this->insertButtonCode(iniConfig, cInputPlayButtonKey, aasdk::proto::enums::ButtonCode::PLAY); this->insertButtonCode(iniConfig, cInputPauseButtonKey, aasdk::proto::enums::ButtonCode::PAUSE); this->insertButtonCode(iniConfig, cInputTogglePlayButtonKey, aasdk::proto::enums::ButtonCode::TOGGLE_PLAY); this->insertButtonCode(iniConfig, cInputNextTrackButtonKey, aasdk::proto::enums::ButtonCode::NEXT); this->insertButtonCode(iniConfig, cInputPreviousTrackButtonKey, aasdk::proto::enums::ButtonCode::PREV); this->insertButtonCode(iniConfig, cInputHomeButtonKey, aasdk::proto::enums::ButtonCode::HOME); this->insertButtonCode(iniConfig, cInputPhoneButtonKey, aasdk::proto::enums::ButtonCode::PHONE); this->insertButtonCode(iniConfig, cInputCallEndButtonKey, aasdk::proto::enums::ButtonCode::CALL_END); this->insertButtonCode(iniConfig, cInputVoiceCommandButtonKey, aasdk::proto::enums::ButtonCode::MICROPHONE_1); this->insertButtonCode(iniConfig, cInputLeftButtonKey, aasdk::proto::enums::ButtonCode::LEFT); this->insertButtonCode(iniConfig, cInputRightButtonKey, aasdk::proto::enums::ButtonCode::RIGHT); this->insertButtonCode(iniConfig, cInputUpButtonKey, aasdk::proto::enums::ButtonCode::UP); this->insertButtonCode(iniConfig, cInputDownButtonKey, aasdk::proto::enums::ButtonCode::DOWN); this->insertButtonCode(iniConfig, cInputScrollWheelButtonKey, aasdk::proto::enums::ButtonCode::SCROLL_WHEEL); this->insertButtonCode(iniConfig, cInputBackButtonKey, aasdk::proto::enums::ButtonCode::BACK); this->insertButtonCode(iniConfig, cInputEnterButtonKey, aasdk::proto::enums::ButtonCode::ENTER); } void Configuration::insertButtonCode(boost::property_tree::ptree& iniConfig, const std::string& buttonCodeKey, aasdk::proto::enums::ButtonCode::Enum buttonCode) { if(iniConfig.get(buttonCodeKey, false)) { buttonCodes_.push_back(buttonCode); } } void Configuration::writeButtonCodes(boost::property_tree::ptree& iniConfig) { iniConfig.put(cInputPlayButtonKey, std::find(buttonCodes_.begin(), buttonCodes_.end(), aasdk::proto::enums::ButtonCode::PLAY) != buttonCodes_.end()); iniConfig.put(cInputPauseButtonKey, std::find(buttonCodes_.begin(), buttonCodes_.end(), aasdk::proto::enums::ButtonCode::PAUSE) != buttonCodes_.end()); iniConfig.put(cInputTogglePlayButtonKey, std::find(buttonCodes_.begin(), buttonCodes_.end(), aasdk::proto::enums::ButtonCode::TOGGLE_PLAY) != buttonCodes_.end()); iniConfig.put(cInputNextTrackButtonKey, std::find(buttonCodes_.begin(), buttonCodes_.end(), aasdk::proto::enums::ButtonCode::NEXT) != buttonCodes_.end()); iniConfig.put(cInputPreviousTrackButtonKey, std::find(buttonCodes_.begin(), buttonCodes_.end(), aasdk::proto::enums::ButtonCode::PREV) != buttonCodes_.end()); iniConfig.put(cInputHomeButtonKey, std::find(buttonCodes_.begin(), buttonCodes_.end(), aasdk::proto::enums::ButtonCode::HOME) != buttonCodes_.end()); iniConfig.put(cInputPhoneButtonKey, std::find(buttonCodes_.begin(), buttonCodes_.end(), aasdk::proto::enums::ButtonCode::PHONE) != buttonCodes_.end()); iniConfig.put(cInputCallEndButtonKey, std::find(buttonCodes_.begin(), buttonCodes_.end(), aasdk::proto::enums::ButtonCode::CALL_END) != buttonCodes_.end()); iniConfig.put(cInputVoiceCommandButtonKey, std::find(buttonCodes_.begin(), buttonCodes_.end(), aasdk::proto::enums::ButtonCode::MICROPHONE_1) != buttonCodes_.end()); iniConfig.put(cInputLeftButtonKey, std::find(buttonCodes_.begin(), buttonCodes_.end(), aasdk::proto::enums::ButtonCode::LEFT) != buttonCodes_.end()); iniConfig.put(cInputRightButtonKey, std::find(buttonCodes_.begin(), buttonCodes_.end(), aasdk::proto::enums::ButtonCode::RIGHT) != buttonCodes_.end()); iniConfig.put(cInputUpButtonKey, std::find(buttonCodes_.begin(), buttonCodes_.end(), aasdk::proto::enums::ButtonCode::UP) != buttonCodes_.end()); iniConfig.put(cInputDownButtonKey, std::find(buttonCodes_.begin(), buttonCodes_.end(), aasdk::proto::enums::ButtonCode::DOWN) != buttonCodes_.end()); iniConfig.put(cInputScrollWheelButtonKey, std::find(buttonCodes_.begin(), buttonCodes_.end(), aasdk::proto::enums::ButtonCode::SCROLL_WHEEL) != buttonCodes_.end()); iniConfig.put(cInputBackButtonKey, std::find(buttonCodes_.begin(), buttonCodes_.end(), aasdk::proto::enums::ButtonCode::BACK) != buttonCodes_.end()); iniConfig.put(cInputEnterButtonKey, std::find(buttonCodes_.begin(), buttonCodes_.end(), aasdk::proto::enums::ButtonCode::ENTER) != buttonCodes_.end()); } } } } }