[libcamera-devel] qcam: Centralize toggling of Capture Script Action
diff mbox series

Message ID 20220711165327.675198-1-utkarsh02t@gmail.com
State Superseded
Headers show
Series
  • [libcamera-devel] qcam: Centralize toggling of Capture Script Action
Related show

Commit Message

Utkarsh Tiwari July 11, 2022, 4:53 p.m. UTC
Centralize the use of scriptExecAction_ in a single
function toggleScriptAction().

Call toggleScriptAction() with a true value to
reset script_ and set the icon to show availability
to load script to the user.
Call with a false value to set the icon to show
the stopping icon.

Signed-off-by: Utkarsh Tiwari <utkarsh02t@gmail.com>
---
This patch applies on top of series
https://lists.libcamera.org/pipermail/libcamera-devel/2022-June/031151.html

 src/qcam/main_window.cpp | 26 ++++++++++++++++++--------
 src/qcam/main_window.h   |  2 ++
 2 files changed, 20 insertions(+), 8 deletions(-)

Patch
diff mbox series

diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp
index a13a8b34..d4b3d629 100644
--- a/src/qcam/main_window.cpp
+++ b/src/qcam/main_window.cpp
@@ -161,8 +161,7 @@  MainWindow::MainWindow(CameraManager *cm, const OptionsParser::Options &options)
 		}
 
 		/* Show stopping availability. */
-		scriptExecAction_->setIcon(QIcon(":x-square.svg"));
-		scriptExecAction_->setText("Stop Script execution");
+		toggleScriptAction(false);
 	}
 
 	startStopAction_->setChecked(true);
@@ -252,6 +251,8 @@  int MainWindow::createToolbars()
 						      QIcon(":file.svg")),
 				     "Open Capture Script");
 	connect(action, &QAction::triggered, this, &MainWindow::chooseScript);
+
+	/* Do not operate directly call toggleScriptAction */
 	scriptExecAction_ = action;
 
 	return 0;
@@ -289,10 +290,7 @@  void MainWindow::chooseScript()
 		 * This is the second valid press of load script button,
 		 * It indicates stopping, Stop and set button for new script.
 		 */
-		script_.reset();
-		scriptExecAction_->setIcon(QIcon::fromTheme("document-open",
-							    QIcon(":file.svg")));
-		scriptExecAction_->setText("Open Capture Script");
+		toggleScriptAction(true);
 		return;
 	}
 
@@ -323,14 +321,26 @@  void MainWindow::chooseScript()
 	 * Valid script verified
 	 * Set the button to indicate stopping availibility.
 	 */
-	scriptExecAction_->setIcon(QIcon(":x-square.svg"));
-	scriptExecAction_->setText("Stop Script execution");
+	toggleScriptAction(false);
 
 	/* Start capture again if we were capturing before. */
 	if (wasCapturing)
 		toggleCapture(true);
 }
 
+void MainWindow::toggleScriptAction(bool showAvailable)
+{
+	if (showAvailable) {
+		script_.reset();
+		scriptExecAction_->setIcon(QIcon::fromTheme("document-open",
+							    QIcon(":file.svg")));
+		scriptExecAction_->setText("Open Capture Script");
+	} else {
+		scriptExecAction_->setIcon(QIcon(":x-square.svg"));
+		scriptExecAction_->setText("Stop Script execution");
+	}
+}
+
 /* -----------------------------------------------------------------------------
  * Camera Selection
  */
diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h
index 4d19ab64..6f131b17 100644
--- a/src/qcam/main_window.h
+++ b/src/qcam/main_window.h
@@ -90,6 +90,8 @@  private:
 
 	void chooseScript();
 
+	void toggleScriptAction(bool showAvailable);
+
 	/* UI elements */
 	QToolBar *toolbar_;
 	QAction *startStopAction_;