1 /* Webcamoid, webcam capture application.
2  * Copyright (C) 2017  Gonzalo Exequiel Pedone
3  *
4  * Webcamoid is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Webcamoid is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Webcamoid. If not, see <http://www.gnu.org/licenses/>.
16  *
17  * Web-Site: http://webcamoid.github.io/
18  */
19 
20 #include <akelement.h>
21 
22 #include "desktopcaptureglobals.h"
23 
24 class DesktopCaptureGlobalsPrivate
25 {
26     public:
27         QString m_captureLib;
28         QStringList m_preferredLibrary;
29 
30         DesktopCaptureGlobalsPrivate();
31 };
32 
DesktopCaptureGlobals(QObject * parent)33 DesktopCaptureGlobals::DesktopCaptureGlobals(QObject *parent):
34     QObject(parent)
35 {
36     this->d = new DesktopCaptureGlobalsPrivate;
37     this->resetCaptureLib();
38 }
39 
~DesktopCaptureGlobals()40 DesktopCaptureGlobals::~DesktopCaptureGlobals()
41 {
42     delete this->d;
43 }
44 
captureLib() const45 QString DesktopCaptureGlobals::captureLib() const
46 {
47     return this->d->m_captureLib;
48 }
49 
subModules() const50 QStringList DesktopCaptureGlobals::subModules() const
51 {
52     return AkElement::listSubModules("DesktopCapture");
53 }
54 
setCaptureLib(const QString & captureLib)55 void DesktopCaptureGlobals::setCaptureLib(const QString &captureLib)
56 {
57     if (this->d->m_captureLib == captureLib)
58         return;
59 
60     this->d->m_captureLib = captureLib;
61     emit this->captureLibChanged(captureLib);
62 }
63 
resetCaptureLib()64 void DesktopCaptureGlobals::resetCaptureLib()
65 {
66     auto subModules = AkElement::listSubModules("DesktopCapture");
67 
68     for (auto &framework: this->d->m_preferredLibrary)
69         if (subModules.contains(framework)) {
70             this->setCaptureLib(framework);
71 
72             return;
73         }
74 
75     if (this->d->m_captureLib.isEmpty() && !subModules.isEmpty())
76         this->setCaptureLib(subModules.first());
77     else
78         this->setCaptureLib("");
79 }
80 
DesktopCaptureGlobalsPrivate()81 DesktopCaptureGlobalsPrivate::DesktopCaptureGlobalsPrivate()
82 {
83     this->m_preferredLibrary = QStringList {
84         "avfoundation",
85         "androidscreen",
86         "qtscreen",
87     };
88 }
89 
90 #include "moc_desktopcaptureglobals.cpp"
91