165 lines
4.7 KiB
C++
165 lines
4.7 KiB
C++
// This file is part of JustVideo.
|
|
|
|
// JustVideo is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// JustVideo is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
#include "main_widget.h"
|
|
|
|
MainGui::MainGui(QWidget *parent) : QMainWindow(parent)
|
|
{
|
|
layout()->setSpacing(0);
|
|
}
|
|
|
|
void MainGui::closeEvent(QCloseEvent *event)
|
|
{
|
|
emit killSes();
|
|
|
|
QMainWindow::closeEvent(event);
|
|
}
|
|
|
|
MainWidget::MainWidget(shared_t *share, QMenuBar *mainMenuBar, MainGui *parent, Actions *acts) : QStackedWidget(parent)
|
|
{
|
|
shared = share;
|
|
actions = acts;
|
|
menuBar = mainMenuBar;
|
|
mainGui = parent;
|
|
homepage = new QWidget(this);
|
|
|
|
actions->live->setVisible(false);
|
|
actions->footage->setVisible(false);
|
|
|
|
addWidget(homepage);
|
|
setCurrentWidget(homepage);
|
|
|
|
parentWidget()->setWindowTitle(QString(APP_NAME));
|
|
|
|
connect(actions, &Actions::contentClose, this, &MainWidget::reset);
|
|
connect(actions, &Actions::contentOpen, this, &MainWidget::open);
|
|
|
|
connect(parent, &MainGui::killSes, acts->closeFolder, &QAction::trigger);
|
|
}
|
|
|
|
void MainWidget::reset()
|
|
{
|
|
actions->live->setVisible(false);
|
|
actions->footage->setVisible(false);
|
|
|
|
setCurrentWidget(homepage);
|
|
|
|
parentWidget()->setWindowTitle(QString(APP_NAME));
|
|
}
|
|
|
|
void MainWidget::open()
|
|
{
|
|
parentWidget()->setWindowTitle(shared->playPath + " - " + QString(APP_NAME));
|
|
|
|
if (shared->isJM)
|
|
{
|
|
actions->live->setVisible(true);
|
|
actions->footage->setVisible(true);
|
|
|
|
auto mntLoc = QDir::cleanPath(shared->playPath);
|
|
auto confPath = mntLoc + QDir::separator() + "etc" + QDir::separator() + "jmotion";
|
|
auto confFiles = lsFiles(confPath);
|
|
auto confs = QList<shared_t>();
|
|
auto pageConfs = QList<shared_t>();
|
|
|
|
for (auto &&confFile : confFiles)
|
|
{
|
|
shared_t conf;
|
|
|
|
if (rdConf(confPath + QDir::separator() + confFile, &conf))
|
|
{
|
|
confs.append(conf);
|
|
}
|
|
}
|
|
|
|
if (confs.isEmpty())
|
|
{
|
|
QMessageBox::critical(this, tr("JustMotion Config Error"), tr("Did not find any config files in: '") + mntLoc + "' check the folder for any conf files in the etc/jmotion subfolder.");
|
|
|
|
actions->closeFolder->trigger();
|
|
}
|
|
else
|
|
{
|
|
auto page = 1;
|
|
|
|
for (auto &&conf : confs)
|
|
{
|
|
pageConfs.append(conf);
|
|
|
|
if (pageConfs.size() == shared->maxViewsPerPage)
|
|
{
|
|
mwMultiViewBuild(pageConfs, page++); pageConfs.clear();
|
|
}
|
|
}
|
|
|
|
if (!pageConfs.isEmpty())
|
|
{
|
|
mwMultiViewBuild(pageConfs, page);
|
|
}
|
|
|
|
for (auto &&conf : confs)
|
|
{
|
|
mwSingleLiveViewBuild(QDir::cleanPath(mntLoc + QDir::separator() + conf.buffPath + QDir::separator() + "live"), conf.camName);
|
|
}
|
|
|
|
for (auto &&conf : confs)
|
|
{
|
|
mwSingleFootageViewBuild(QDir::cleanPath(mntLoc + QDir::separator() + conf.recPath), conf.camName);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
actions->live->setVisible(false);
|
|
actions->footage->setVisible(false);
|
|
|
|
playPathBuild();
|
|
}
|
|
}
|
|
|
|
void MainWidget::setView(QWidget *widget)
|
|
{
|
|
if (currentWidget() == homepage)
|
|
{
|
|
setCurrentWidget(widget);
|
|
}
|
|
}
|
|
|
|
void MainWidget::addVidWidget(VidWidget *vidWidget)
|
|
{
|
|
QCoreApplication::instance()->installEventFilter(vidWidget);
|
|
|
|
connect(vidWidget, &VidWidget::mainWindowsVis, mainGui, &MainGui::setVisible);
|
|
|
|
setView(vidWidget);
|
|
}
|
|
|
|
void MainWidget::playPathBuild()
|
|
{
|
|
addVidWidget(new VidWidget(shared, "", shared->playPath, false, true, nullptr, actions->closeFolder, this));
|
|
}
|
|
|
|
void MainWidget::mwSingleLiveViewBuild(const QString &path, const QString &camName)
|
|
{
|
|
addVidWidget(new VidWidget(shared, camName, path, false, false, actions->liveSelect, actions->closeFolder, this));
|
|
}
|
|
|
|
void MainWidget::mwSingleFootageViewBuild(const QString &path, const QString &camName)
|
|
{
|
|
addVidWidget(new VidWidget(shared, camName, path, false, true, actions->footageSelect, actions->closeFolder, this));
|
|
}
|
|
|
|
void MainWidget::mwMultiViewBuild(QList<shared_t> confs, int page)
|
|
{
|
|
setView(new VidGrid(shared, confs, shared->playPath, page, actions->liveSelect, actions->closeFolder, this));
|
|
}
|