forked from obsproject/obs-studio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui-validation.cpp
More file actions
119 lines (94 loc) · 3.09 KB
/
Copy pathui-validation.cpp
File metadata and controls
119 lines (94 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "ui-validation.hpp"
#include <obs.hpp>
#include <QString>
#include <QMessageBox>
#include <QPushButton>
#include <obs-app.hpp>
#include <obs-service.h>
static int CountVideoSources()
{
int count = 0;
auto countSources = [](void *param, obs_source_t *source) {
if (!source)
return true;
uint32_t flags = obs_source_get_output_flags(source);
if ((flags & OBS_SOURCE_VIDEO) != 0)
(*reinterpret_cast<int *>(param))++;
return true;
};
obs_enum_sources(countSources, &count);
return count;
}
bool UIValidation::NoSourcesConfirmation(QWidget *parent)
{
// There are sources, don't need confirmation
if (CountVideoSources() != 0)
return true;
// Ignore no video if no parent is visible to alert on
if (!parent->isVisible())
return true;
QString msg = QTStr("NoSources.Text");
msg += "\n\n";
msg += QTStr("NoSources.Text.AddSource");
QMessageBox messageBox(parent);
messageBox.setWindowTitle(QTStr("NoSources.Title"));
messageBox.setText(msg);
QAbstractButton *yesButton =
messageBox.addButton(QTStr("Yes"), QMessageBox::YesRole);
messageBox.addButton(QTStr("No"), QMessageBox::NoRole);
messageBox.setIcon(QMessageBox::Question);
messageBox.exec();
if (messageBox.clickedButton() != yesButton)
return false;
else
return true;
}
StreamSettingsAction
UIValidation::StreamSettingsConfirmation(QWidget *parent, OBSService service)
{
// Custom services can user API key in URL or user/pass combo.
// So only check there is a URL
char const *serviceType = obs_service_get_type(service);
bool isCustomUrlService = (strcmp(serviceType, "rtmp_custom") == 0);
char const *streamUrl = obs_service_get_url(service);
char const *streamKey = obs_service_get_key(service);
bool hasStreamUrl = (streamUrl != NULL && streamUrl[0] != '\0');
bool hasStreamKey = ((streamKey != NULL && streamKey[0] != '\0') ||
isCustomUrlService);
if (hasStreamUrl && hasStreamKey)
return StreamSettingsAction::ContinueStream;
QString msg;
if (!hasStreamUrl && !hasStreamKey) {
msg = QTStr("Basic.Settings.Stream.MissingUrlAndApiKey");
} else if (!hasStreamKey) {
msg = QTStr("Basic.Settings.Stream.MissingStreamKey");
} else {
msg = QTStr("Basic.Settings.Stream.MissingUrl");
}
QMessageBox messageBox(parent);
messageBox.setWindowTitle(
QTStr("Basic.Settings.Stream.MissingSettingAlert"));
messageBox.setText(msg);
QPushButton *cancel;
QPushButton *settings;
#ifdef __APPLE__
#define ACCEPT_BUTTON QMessageBox::AcceptRole
#define REJECT_BUTTON QMessageBox::ResetRole
#else
#define ACCEPT_BUTTON QMessageBox::NoRole
#define REJECT_BUTTON QMessageBox::NoRole
#endif
settings = messageBox.addButton(
QTStr("Basic.Settings.Stream.StreamSettingsWarning"),
ACCEPT_BUTTON);
cancel = messageBox.addButton(QTStr("Cancel"), REJECT_BUTTON);
messageBox.setDefaultButton(settings);
messageBox.setEscapeButton(cancel);
messageBox.setIcon(QMessageBox::Warning);
messageBox.exec();
if (messageBox.clickedButton() == settings)
return StreamSettingsAction::OpenSettings;
if (messageBox.clickedButton() == cancel)
return StreamSettingsAction::Cancel;
return StreamSettingsAction::ContinueStream;
}