summaryrefslogtreecommitdiffhomepage
path: root/compat
diff options
context:
space:
mode:
Diffstat (limited to 'compat')
-rw-r--r--compat/camera-names.cpp23
-rw-r--r--compat/camera-names.hpp3
2 files changed, 16 insertions, 10 deletions
diff --git a/compat/camera-names.cpp b/compat/camera-names.cpp
index 40edba49..8e777028 100644
--- a/compat/camera-names.cpp
+++ b/compat/camera-names.cpp
@@ -28,16 +28,22 @@
int camera_name_to_index(const QString &name)
{
auto list = get_camera_names();
- auto it = std::find(list.cbegin(), list.cend(), name);
+ auto it = std::find_if(list.cbegin(), list.cend(), [&name](const auto& tuple) {
+ const auto& [str, idx] = tuple;
+ return str == name;
+ });
if (it != list.cend())
- return std::distance(list.cbegin(), it);
+ {
+ const auto& [ str, idx ] = *it;
+ return idx;
+ }
return -1;
}
-std::vector<QString> get_camera_names()
+std::vector<std::tuple<QString, int>> get_camera_names()
{
- std::vector<QString> ret;
+ std::vector<std::tuple<QString, int>> ret;
#ifdef _WIN32
// Create the System Device Enumerator.
HRESULT hr;
@@ -70,7 +76,7 @@ std::vector<QString> get_camera_names()
{
// Display the name in your UI somehow.
QString str((QChar*)var.bstrVal, int(std::wcslen(var.bstrVal)));
- ret.push_back(str);
+ ret.push_back({ str, ret.size() });
}
VariantClear(&var);
pPropBag->Release();
@@ -101,16 +107,15 @@ std::vector<QString> get_camera_names()
close(fd);
continue;
}
- ret.push_back(QString((const char*)video_cap.card));
+ ret.push_back({ QString((const char*)video_cap.card), i});
close(fd);
}
}
#endif
#ifdef __APPLE__
QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
- foreach (const QCameraInfo &cameraInfo, cameras) {
- ret.push_back(cameraInfo.description());
- }
+ for (const QCameraInfo &cameraInfo : cameras)
+ ret.push_back({ cameraInfo.description(), ret.size() });
#endif
return ret;
diff --git a/compat/camera-names.hpp b/compat/camera-names.hpp
index bda15e81..3585edfe 100644
--- a/compat/camera-names.hpp
+++ b/compat/camera-names.hpp
@@ -10,9 +10,10 @@
#include <vector>
#include <QString>
+# include <tuple>
#include "export.hpp"
-OTR_COMPAT_EXPORT std::vector<QString> get_camera_names();
+OTR_COMPAT_EXPORT std::vector<std::tuple<QString, int>> get_camera_names();
OTR_COMPAT_EXPORT int camera_name_to_index(const QString &name);