Skip to content

Commit

Permalink
GUI: Add some menus
Browse files Browse the repository at this point in the history
It is now possible to index several videos without restarting the
application, even when demuxing parts of them.
  • Loading branch information
cantabile committed Jul 31, 2016
1 parent cb87b1b commit 73919e1
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 22 deletions.
128 changes: 106 additions & 22 deletions src/GUIWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,7 @@ void GUIWindow::startIndexing() {
if (!d2v_file) {
errorPopup(QStringLiteral("Failed to open d2v file '%1' for writing: %2").arg(d2v_edit->text()).arg(strerror(errno)));

start_stop_button->setText("&Engage");
container_widget->setEnabled(true);
enableInterface(true);

return;
}
Expand All @@ -292,8 +291,7 @@ void GUIWindow::startIndexing() {
fclose(d2v_file);
closeAudioFiles(audio_files, f.fctx);

start_stop_button->setText("&Engage");
container_widget->setEnabled(true);
enableInterface(true);

return;
}
Expand All @@ -307,8 +305,7 @@ void GUIWindow::startIndexing() {
fclose(d2v_file);
closeAudioFiles(audio_files, f.fctx);

start_stop_button->setText("&Engage");
container_widget->setEnabled(true);
enableInterface(true);

return;
}
Expand Down Expand Up @@ -353,8 +350,7 @@ void GUIWindow::startDemuxing() {
if (!video_file) {
errorPopup(QStringLiteral("Failed to open video file '%1' for writing: %2").arg(video_file_name).arg(strerror(errno)));

start_stop_button->setText("&Engage");
container_widget->setEnabled(true);
enableInterface(true);

return;
}
Expand Down Expand Up @@ -427,9 +423,9 @@ GUIWindow::GUIWindow(QWidget *parent)

QGroupBox *range_box = new QGroupBox("Input colour range", this);
range_group = new QButtonGroup(this);
range_group->addButton(new QRadioButton("&Limited (TV)", this), D2V::ColourRangeLimited);
range_group->addButton(new QRadioButton("Limited (&TV)", this), D2V::ColourRangeLimited);
range_group->button(D2V::ColourRangeLimited)->setChecked(true);
range_group->addButton(new QRadioButton("&Full (PC)", this), D2V::ColourRangeFull);
range_group->addButton(new QRadioButton("Full (&PC)", this), D2V::ColourRangeFull);

audio_list = new QListWidget(this);
audio_list->setSelectionMode(QAbstractItemView::ExtendedSelection);
Expand Down Expand Up @@ -472,6 +468,22 @@ GUIWindow::GUIWindow(QWidget *parent)
container_widget = new QStackedWidget(this);


QMenuBar *bar = menuBar();

QMenu *file_menu = bar->addMenu(QStringLiteral("&File"));
QMenu *help_menu = bar->addMenu(QStringLiteral("&Help"));

QAction *open_action = new QAction(QStringLiteral("&Open video files"), this);
open_action->setShortcut(QKeySequence(QStringLiteral("Ctrl+O")));

QAction *quit_action = new QAction(QStringLiteral("&Quit"), this);
quit_action->setShortcut(QKeySequence(QStringLiteral("Ctrl+Q")));;

QAction *about_action = new QAction(QStringLiteral("&About D2V Witch"), this);

QAction *aboutqt_action = new QAction(QStringLiteral("About &Qt"), this);


connect(input_list, &ListWidget::deletePressed, remove_button, &QPushButton::click);

connect(add_button, &QPushButton::clicked, [this] () {
Expand All @@ -482,6 +494,13 @@ GUIWindow::GUIWindow(QWidget *parent)

fake_file.close();

if (container_widget->currentWidget() == demuxing_page) {
input_list->clear();
fake_file.clear();

container_widget->setCurrentWidget(indexing_page);
}

for (int i = 0; i < file_names.size(); i++) {
input_list->addItem(file_names[i]);
fake_file.push_back(file_names[i].toStdString());
Expand Down Expand Up @@ -630,8 +649,7 @@ GUIWindow::GUIWindow(QWidget *parent)
stop_processing = true;
}

container_widget->setEnabled(working);
start_stop_button->setText(working ? "&Engage" : "Canc&el");
enableInterface(working);

if (!working) {
if (container_widget->currentWidget() == indexing_page)
Expand All @@ -641,6 +659,62 @@ GUIWindow::GUIWindow(QWidget *parent)
}
});

connect(open_action, &QAction::triggered, add_button, &QPushButton::click);

connect(quit_action, &QAction::triggered, this, &GUIWindow::close);

connect(about_action, &QAction::triggered, [this] () {
unsigned lavf = avformat_version();
unsigned lavc = avcodec_version();
unsigned lavu = avutil_version();

QString about = QStringLiteral(
"<a href='https://github.com/dubhater/D2VWitch'>https://github.com/dubhater/D2VWitch</a><br />"
"<br />"
"Copyright (c) 2016, John Smith<br />"
"<br />"
"Permission to use, copy, modify, and/or distribute this software for "
"any purpose with or without fee is hereby granted, provided that the "
"above copyright notice and this permission notice appear in all copies.<br />"
"<br />"
"THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL "
"WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED "
"WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR "
"BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES "
"OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, "
"WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, "
"ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS "
"SOFTWARE.<br />"
"<br />"
"D2V Witch version: %1<br />"
"libavformat version: %2.%3.%4<br />"
"libavcodec version: %5.%6.%7<br />"
"libavutil version: %8.%9.%10<br />"
"<br />"
"libavformat configuration:<br />"
"%11<br />"
"<br />"
"libavcodec configuration:<br />"
"%12<br />"
"<br />"
"libavutil configuration:<br />"
"%13<br />"
);
about = about.arg(PACKAGE_VERSION);
about = about.arg((lavf >> 16) & 0xff).arg((lavf >> 8) & 0xff).arg(lavf & 0xff);
about = about.arg((lavc >> 16) & 0xff).arg((lavc >> 8) & 0xff).arg(lavc & 0xff);
about = about.arg((lavu >> 16) & 0xff).arg((lavu >> 8) & 0xff).arg(lavu & 0xff);
about = about.arg(avformat_configuration());
about = about.arg(avcodec_configuration());
about = about.arg(avutil_configuration());

QMessageBox::about(this, QStringLiteral("About D2V Witch"), about);
});

connect(aboutqt_action, &QAction::triggered, [this] () {
QMessageBox::aboutQt(this);
});


QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(input_list);
Expand Down Expand Up @@ -709,6 +783,14 @@ GUIWindow::GUIWindow(QWidget *parent)
setCentralWidget(central_widget);


file_menu->addAction(open_action);
file_menu->addSeparator();
file_menu->addAction(quit_action);

help_menu->addAction(about_action);
help_menu->addAction(aboutqt_action);


// Fix broken tab order. It's unclear why video_frame_slider isn't in this position already,
// since it is constructed after video_frame_spin.
QWidget::setTabOrder(video_frame_spin, video_frame_slider);
Expand Down Expand Up @@ -773,8 +855,7 @@ void GUIWindow::indexingFinished(D2V new_d2v) {
logMessage(QStringLiteral("Indexing cancelled by user."));
}

start_stop_button->setText(QStringLiteral("&Engage"));
container_widget->setEnabled(true);
enableInterface(true);

if (!f.seek(0))
logMessage(QString::fromStdString(f.getError()));
Expand All @@ -797,8 +878,7 @@ void GUIWindow::demuxingFinished(D2V new_d2v) {
if (!demuxed_fake_file.open()) {
errorPopup(demuxed_fake_file.getError());

start_stop_button->setText("&Engage");
container_widget->setEnabled(true);
enableInterface(true);

if (!f.seek(0))
logMessage(QString::fromStdString(f.getError()));
Expand All @@ -811,8 +891,7 @@ void GUIWindow::demuxingFinished(D2V new_d2v) {
if (!demuxed_f.initFormat(demuxed_fake_file)) {
errorPopup(demuxed_f.getError());

start_stop_button->setText("&Engage");
container_widget->setEnabled(true);
enableInterface(true);

if (!f.seek(0))
logMessage(QString::fromStdString(f.getError()));
Expand All @@ -827,8 +906,7 @@ void GUIWindow::demuxingFinished(D2V new_d2v) {
if (!new_d2v_file) {
errorPopup(QStringLiteral("Failed to open d2v file '%1' for writing: %2").arg(new_d2v_name).arg(strerror(errno)));

start_stop_button->setText("&Engage");
container_widget->setEnabled(true);
enableInterface(true);

if (!f.seek(0))
logMessage(QString::fromStdString(f.getError()));
Expand Down Expand Up @@ -861,8 +939,7 @@ void GUIWindow::demuxingFinished(D2V new_d2v) {
logMessage(QStringLiteral("Video demuxing cancelled by user."));
}

start_stop_button->setText(QStringLiteral("&Engage"));
container_widget->setEnabled(true);
enableInterface(true);

if (!f.seek(0))
logMessage(QString::fromStdString(f.getError()));
Expand Down Expand Up @@ -1128,6 +1205,13 @@ void GUIWindow::dropEvent(QDropEvent *event) {
}


void GUIWindow::enableInterface(bool enable) {
container_widget->setEnabled(enable);
menuBar()->setEnabled(enable);
start_stop_button->setText(enable ? "&Engage" : "Canc&el");
}


IndexingWorker::IndexingWorker(const QString &_d2v_file_name, FILE *_d2v_file, const D2V::AudioFilesMap &_audio_files, FakeFile *_fake_file, FFMPEG *_f, AVStream *_video_stream, D2V::ColourRange _input_range, GUIWindow *_window)
: d2v(_d2v_file_name.toStdString(), _d2v_file, _audio_files, _fake_file, _f, _video_stream, _input_range, ::updateProgress, _window, ::logMessage, _window)
{
Expand Down
1 change: 1 addition & 0 deletions src/GUIWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class GUIWindow : public QMainWindow {
void createVapourSynthFilterChain();
void dragEnterEvent(QDragEnterEvent *event);
void dropEvent(QDropEvent *event);
void enableInterface(bool enable);

public:
explicit GUIWindow(QWidget *parent = 0);
Expand Down

0 comments on commit 73919e1

Please sign in to comment.