| 
									
										
										
										
											2020-10-25 07:53:40 +01:00
										 |  |  | // SPDX-License-Identifier: GPL-2.0
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "command_device.h"
 | 
					
						
							|  |  |  | #include "core/subsurface-qt/divelistnotifier.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Command { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-17 11:14:42 -07:00
										 |  |  | EditDeviceNickname::EditDeviceNickname(const struct divecomputer *dc, const QString &nicknameIn) : | 
					
						
							|  |  |  | 	nickname(nicknameIn.toStdString()) | 
					
						
							| 
									
										
										
										
											2020-10-25 07:53:40 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-08-17 11:14:42 -07:00
										 |  |  | 	index = get_or_add_device_for_dc(&device_table, dc); | 
					
						
							|  |  |  | 	if (index == -1) | 
					
						
							| 
									
										
										
										
											2020-10-25 07:53:40 +01:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-17 11:14:42 -07:00
										 |  |  | 	setText(Command::Base::tr("Set nickname of device %1 (serial %2) to %3").arg(dc->model, dc->serial, nicknameIn)); | 
					
						
							| 
									
										
										
										
											2020-10-25 07:53:40 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool EditDeviceNickname::workToBeDone() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return get_device(&device_table, index) != nullptr; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditDeviceNickname::redo() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	device *dev = get_device_mutable(&device_table, index); | 
					
						
							|  |  |  | 	if (!dev) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	std::swap(dev->nickName, nickname); | 
					
						
							| 
									
										
										
										
											2021-08-17 11:14:42 -07:00
										 |  |  | 	emit diveListNotifier.deviceEdited(); | 
					
						
							| 
									
										
										
										
											2020-10-25 07:53:40 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EditDeviceNickname::undo() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	redo(); // undo() and redo() do the same thing
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // namespace Command
 |