FotoBox
camera.cpp
Go to the documentation of this file.
1 /* camera.cpp
2  *
3  * Copyright (c) 2017 Thomas Kais
4  *
5  * This file is subject to the terms and conditions defined in
6  * file 'COPYING', which is part of this source code package.
7  */
8 #include "camera.h"
9 
10 #include "preferenceprovider.h"
11 
12 #include <QDateTime>
13 
14 namespace FotoBox {
15 
16 Camera::Camera(QObject *parent)
17  : QObject(parent)
18  , m_timeoutValue(TO_SECONDS * PreferenceProvider::instance().timeoutValue())
19  , m_photoSuffix(PreferenceProvider::instance().photoName())
20  , m_cameraMode(PreferenceProvider::instance().cameraMode())
21  , m_argList(PreferenceProvider::instance().argumentLine().split(QChar(' ')))
22  , m_process(this)
23 {
24  //call this function to save memory, if you are not interested in the output of the process
25  m_process.closeReadChannel(QProcess::StandardOutput);
26  m_process.closeReadChannel(QProcess::StandardError);
27 
28  //use 'photo folder' as working dir
29  m_process.setWorkingDirectory(PreferenceProvider::instance().photoFolder());
30 }
31 
32 auto Camera::shootPhoto() -> bool
33 {
34  //file name of photo
35  m_currentPhoto = QDateTime::currentDateTime().toString(QStringLiteral("yyyyMMdd_HH-mm-ss_")) + m_photoSuffix;
36  //add filename to argument
37  auto arguments = m_argList;
38  arguments = arguments.replaceInStrings(QStringLiteral("%1"), m_currentPhoto);
39 
40  //start programm with given arguments
41  m_process.start(m_cameraMode, arguments, {});
42  m_process.waitForFinished(m_timeoutValue);
43 
44  //check time out and process exit code
45  return (m_process.exitCode() == EXIT_SUCCESS);
46 }
47 
48 auto Camera::currentPhoto() const -> QString
49 {
50  return m_currentPhoto;
51 }
52 
53 } // end namespace FotoBox
auto currentPhoto() const -> QString
return member
Definition: camera.cpp:48
QString m_currentPhoto
Definition: camera.h:76
auto shootPhoto() -> bool
shoot a photo with gphoto2
Definition: camera.cpp:32
QProcess m_process
Definition: camera.h:88
Camera(QObject *parent=nullptr)
Camera constructor.
Definition: camera.cpp:16
Preference who stores the preferences.
static PreferenceProvider & instance()
get instance (Meyers Singleton)