Commit c4b1a103 authored by Edric Milaret's avatar Edric Milaret Committed by gerrit2

videoview: fix selection of source

ALso litle code refactoring

Change-Id: I01de12122a7c4b6bb980031033329528c5ea6426
Tuleap: #317
parent 6b68a489
......@@ -168,21 +168,27 @@ VideoView::showContextMenu(const QPoint& pos)
QPoint globalPos = this->mapToGlobal(pos);
QMenu menu;
Media::Video* outVideo = nullptr;
int activeIndex = -1;
if (auto call = CallModel::instance().selectedCall()) {
outVideo = call->firstMedia<Media::Video>(Media::Media::Direction::OUT);
if (outVideo)
activeIndex = outVideo->sourceModel()->activeIndex();
}
for (auto device : Video::DeviceModel::instance().devices()) {
std::unique_ptr<QAction> deviceAction(new QAction(device->name(), this));
deviceAction->setCheckable(true);
if (device == Video::DeviceModel::instance().activeDevice())
deviceAction->setChecked(true);
if (outVideo)
if (outVideo->sourceModel()->getDeviceIndex(device) == activeIndex)
deviceAction->setChecked(true);
auto ptr = deviceAction.release();
menu.addAction(ptr);
connect(ptr, &QAction::toggled, [=](bool checked) {
if (checked == true) {
if (auto call = CallModel::instance().selectedCall()) {
if (auto outVideo = call->firstMedia<Media::Video>(Media::Media::Direction::OUT)) {
outVideo->sourceModel()->switchTo(device);
}
}
if (outVideo)
outVideo->sourceModel()->switchTo(device);
Video::DeviceModel::instance().setActive(device);
}
});
......@@ -192,21 +198,33 @@ VideoView::showContextMenu(const QPoint& pos)
auto shareAction = new QAction(tr("Share entire screen"), this);
menu.addAction(shareAction);
connect(shareAction, &QAction::triggered, [=]() {
if (auto call = CallModel::instance().selectedCall()) {
if (auto outVideo = call->firstMedia<Media::Video>(Media::Media::Direction::OUT)) {
outVideo->sourceModel()->setDisplay(0, QApplication::desktop()->rect());
}
}
});
shareAction->setCheckable(true);
auto shareAreaAction = new QAction(tr("Share screen area"), this);
menu.addAction(shareAreaAction);
shareAreaAction->setCheckable(true);
connect(shareAreaAction, &QAction::triggered, [=]() {
SelectAreaDialog selec;
selec.exec();
});
auto shareFileAction = new QAction(tr("Share file"), this);
menu.addAction(shareFileAction);
shareFileAction->setCheckable(true);
switch(activeIndex) {
case Video::SourceModel::ExtendedDeviceList::SCREEN:
shareAction->setChecked(true);
break;
case Video::SourceModel::ExtendedDeviceList::FILE:
shareFileAction->setChecked(true);
break;
}
connect(shareAction, &QAction::triggered, [=]() {
if (outVideo)
outVideo->sourceModel()->setDisplay(0, QApplication::desktop()->rect());
});
connect(shareFileAction, &QAction::triggered, [=]() {
QFileDialog dialog(this);
dialog.setFileMode(QFileDialog::AnyFile);
......@@ -214,11 +232,8 @@ VideoView::showContextMenu(const QPoint& pos)
if (!dialog.exec())
return;
fileNames = dialog.selectedFiles();
if (auto call = CallModel::instance().selectedCall()) {
if (auto outVideo = call->firstMedia<Media::Video>(Media::Media::Direction::OUT)) {
outVideo->sourceModel()->setFile(QUrl::fromLocalFile(fileNames.at(0)));
}
}
if (outVideo)
outVideo->sourceModel()->setFile(QUrl::fromLocalFile(fileNames.at(0)));
});
menu.exec(globalPos);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment