| 
									
										
										
										
											2015-12-01 10:45:34 -08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc. | 
					
						
							| 
									
										
										
										
											2016-12-09 18:21:47 +01:00
										 |  |  |  * Copyright (C) 2016 Furrtek | 
					
						
							| 
									
										
										
										
											2015-12-01 10:45:34 -08:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This file is part of PortaPack. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program 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 2, or (at your option) | 
					
						
							|  |  |  |  * any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program 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 this program; see the file COPYING.  If not, write to | 
					
						
							|  |  |  |  * the Free Software Foundation, Inc., 51 Franklin Street, | 
					
						
							|  |  |  |  * Boston, MA 02110-1301, USA. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "ui_sd_card_status_view.hpp"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <string>
 | 
					
						
							|  |  |  | #include <algorithm>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-09 21:05:11 +02:00
										 |  |  | #include "bitmap.hpp"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-01 10:45:34 -08:00
										 |  |  | namespace ui { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* SDCardStatusView *****************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-03 13:24:38 -08:00
										 |  |  | namespace detail { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const Bitmap& bitmap_sd_card(const sd_card::Status status) { | 
					
						
							|  |  |  | 	switch(status) { | 
					
						
							|  |  |  | 	case sd_card::Status::IOError: | 
					
						
							|  |  |  | 	case sd_card::Status::MountError: | 
					
						
							|  |  |  | 	case sd_card::Status::ConnectError: | 
					
						
							|  |  |  | 		return bitmap_sd_card_error; | 
					
						
							| 
									
										
										
										
											2015-12-01 10:45:34 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-03 13:24:38 -08:00
										 |  |  | 	case sd_card::Status::NotPresent: | 
					
						
							|  |  |  | 		return bitmap_sd_card_unknown; | 
					
						
							| 
									
										
										
										
											2016-02-03 10:34:17 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-03 13:24:38 -08:00
										 |  |  | 	case sd_card::Status::Present: | 
					
						
							|  |  |  | 		return bitmap_sd_card_unknown; | 
					
						
							| 
									
										
										
										
											2015-12-01 10:45:34 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-03 13:24:38 -08:00
										 |  |  | 	case sd_card::Status::Mounted: | 
					
						
							|  |  |  | 		return bitmap_sd_card_ok; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		return bitmap_sd_card_unknown; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-12-01 10:45:34 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-03 13:24:38 -08:00
										 |  |  | static constexpr Color color_sd_card_error = Color::red(); | 
					
						
							|  |  |  | static constexpr Color color_sd_card_unknown = Color::yellow(); | 
					
						
							|  |  |  | static constexpr Color color_sd_card_ok = Color::green(); | 
					
						
							| 
									
										
										
										
											2015-12-01 10:45:34 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-03 13:24:38 -08:00
										 |  |  | const Color color_sd_card(const sd_card::Status status) { | 
					
						
							| 
									
										
										
										
											2015-12-01 10:45:34 -08:00
										 |  |  | 	switch(status) { | 
					
						
							|  |  |  | 	case sd_card::Status::IOError: | 
					
						
							|  |  |  | 	case sd_card::Status::MountError: | 
					
						
							|  |  |  | 	case sd_card::Status::ConnectError: | 
					
						
							| 
									
										
										
										
											2016-02-03 13:24:38 -08:00
										 |  |  | 		return color_sd_card_error; | 
					
						
							| 
									
										
										
										
											2015-12-01 10:45:34 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	case sd_card::Status::NotPresent: | 
					
						
							| 
									
										
										
										
											2016-02-03 13:24:38 -08:00
										 |  |  | 		return color_sd_card_unknown; | 
					
						
							| 
									
										
										
										
											2015-12-01 10:45:34 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	case sd_card::Status::Present: | 
					
						
							| 
									
										
										
										
											2016-02-03 13:24:38 -08:00
										 |  |  | 		return color_sd_card_unknown; | 
					
						
							| 
									
										
										
										
											2015-12-01 10:45:34 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	case sd_card::Status::Mounted: | 
					
						
							| 
									
										
										
										
											2016-02-03 13:24:38 -08:00
										 |  |  | 		return color_sd_card_ok; | 
					
						
							| 
									
										
										
										
											2015-12-01 10:45:34 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2016-02-03 13:24:38 -08:00
										 |  |  | 		return color_sd_card_unknown; | 
					
						
							| 
									
										
										
										
											2015-12-01 10:45:34 -08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-02-03 13:24:38 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } /* namespace detail */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-03 15:50:14 -08:00
										 |  |  | SDCardStatusView::SDCardStatusView( | 
					
						
							|  |  |  | 	const Rect parent_rect | 
					
						
							| 
									
										
										
										
											2016-05-09 21:05:11 +02:00
										 |  |  | ) : Image { parent_rect, &bitmap_sd_card_unknown, detail::color_sd_card_unknown, Color::black() } | 
					
						
							| 
									
										
										
										
											2016-02-03 15:50:14 -08:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-03 13:24:38 -08:00
										 |  |  | void SDCardStatusView::on_show() { | 
					
						
							|  |  |  | 	sd_card_status_signal_token = sd_card::status_signal += [this](const sd_card::Status status) { | 
					
						
							|  |  |  | 		this->on_status(status); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SDCardStatusView::on_hide() { | 
					
						
							|  |  |  | 	sd_card::status_signal -= sd_card_status_signal_token; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SDCardStatusView::paint(Painter& painter) { | 
					
						
							|  |  |  | 	const auto status = sd_card::status(); | 
					
						
							| 
									
										
										
										
											2016-02-03 15:50:14 -08:00
										 |  |  | 	set_bitmap(&detail::bitmap_sd_card(status)); | 
					
						
							|  |  |  | 	set_foreground(detail::color_sd_card(status)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Image::paint(painter); | 
					
						
							| 
									
										
										
										
											2016-02-03 13:24:38 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-12-01 10:45:34 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-03 13:24:38 -08:00
										 |  |  | void SDCardStatusView::on_status(const sd_card::Status) { | 
					
						
							| 
									
										
										
										
											2016-02-03 15:50:14 -08:00
										 |  |  | 	// Don't update image properties here, they might change. Wait until paint.
 | 
					
						
							| 
									
										
										
										
											2016-02-03 13:24:38 -08:00
										 |  |  | 	set_dirty(); | 
					
						
							| 
									
										
										
										
											2015-12-01 10:45:34 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } /* namespace ui */ |