Skip to content

Commit

Permalink
Resource view (#1456)
Browse files Browse the repository at this point in the history
* Add new resource dialog

* Add "Convert" option to Resource Dialog

* Show resource dialog when multiple files are added and need conversion.

* Show resource dialog when multiple files are dropped on the timeline.

The dialog only shows if any of the files need conversion.

* Show resource dialog when multiple files are dropped on the playlist

* Improve resource view table

* Add alternating row background colors
* Make the columns resizable
  • Loading branch information
bmatherly authored Aug 17, 2023
1 parent ddcfb7c commit 402e677
Show file tree
Hide file tree
Showing 22 changed files with 1,387 additions and 369 deletions.
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ add_executable(shotcut WIN32 MACOSX_BUNDLE
dialogs/listselectiondialog.ui
dialogs/longuitask.cpp dialogs/longuitask.h
dialogs/multifileexportdialog.cpp dialogs/multifileexportdialog.h
dialogs/resourcedialog.cpp dialogs/resourcedialog.h
dialogs/saveimagedialog.cpp dialogs/saveimagedialog.h
dialogs/slideshowgeneratordialog.cpp dialogs/slideshowgeneratordialog.h
dialogs/systemsyncdialog.cpp dialogs/systemsyncdialog.h
Expand Down Expand Up @@ -73,6 +74,7 @@ add_executable(shotcut WIN32 MACOSX_BUNDLE
models/motiontrackermodel.h models/motiontrackermodel.cpp
models/multitrackmodel.cpp models/multitrackmodel.h
models/playlistmodel.cpp models/playlistmodel.h
models/resourcemodel.cpp models/resourcemodel.h
openotherdialog.cpp openotherdialog.h
openotherdialog.ui
player.cpp player.h
Expand Down Expand Up @@ -102,6 +104,7 @@ add_executable(shotcut WIN32 MACOSX_BUNDLE
settings.cpp settings.h
sharedframe.cpp sharedframe.h
shotcut_mlt_properties.h
transcoder.cpp transcoder.h
spatialmedia/box.cpp spatialmedia/box.h
spatialmedia/container.cpp spatialmedia/container.h
spatialmedia/mpeg4_container.cpp spatialmedia/mpeg4_container.h
Expand Down Expand Up @@ -164,6 +167,7 @@ add_executable(shotcut WIN32 MACOSX_BUNDLE
widgets/producerpreviewwidget.cpp widgets/producerpreviewwidget.h
widgets/pulseaudiowidget.cpp widgets/pulseaudiowidget.h
widgets/pulseaudiowidget.ui
widgets/resourcewidget.cpp widgets/resourcewidget.h
widgets/scopes/audioloudnessscopewidget.cpp widgets/scopes/audioloudnessscopewidget.h
widgets/scopes/audiopeakmeterscopewidget.cpp widgets/scopes/audiopeakmeterscopewidget.h
widgets/scopes/audiospectrumscopewidget.cpp widgets/scopes/audiospectrumscopewidget.h
Expand Down
111 changes: 111 additions & 0 deletions src/dialogs/resourcedialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Copyright (c) 2023 Meltytech, LLC
*
* This program 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.
*
* This program 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "resourcedialog.h"

#include "Logger.h"
#include "mltcontroller.h"
#include "qmltypes/qmlapplication.h"
#include "transcodedialog.h"
#include "transcoder.h"
#include "widgets/resourcewidget.h"

#include <QDialogButtonBox>
#include <QMessageBox>
#include <QVBoxLayout>
#include <QPushButton>

ResourceDialog::ResourceDialog(QWidget *parent)
: QDialog(parent)
{
setWindowTitle(tr("Resources"));
setSizeGripEnabled(true) ;

QVBoxLayout *vlayout = new QVBoxLayout();
m_resourceWidget = new ResourceWidget(this);
vlayout->addWidget(m_resourceWidget);

// Button Box
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
buttonBox->button(QDialogButtonBox::Close)->setAutoDefault(false);
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
// Convert button
QPushButton *convertButton = buttonBox->addButton(tr("Convert Selected"),
QDialogButtonBox::ActionRole);
connect(convertButton, SIGNAL(pressed()), this, SLOT(convert()));
vlayout->addWidget(buttonBox);

setLayout(vlayout);
}

void ResourceDialog::search(Mlt::Producer *producer)
{
m_resourceWidget->search(producer);
}

void ResourceDialog::add(Mlt::Producer *producer)
{
m_resourceWidget->add(producer);
}

void ResourceDialog::selectTroubleClips()
{
m_resourceWidget->selectTroubleClips();
}

bool ResourceDialog::hasTroubleClips()
{
return m_resourceWidget->hasTroubleClips();
}

void ResourceDialog::convert()
{
QList<Mlt::Producer> producers(m_resourceWidget->getSelected());

// Only convert avformat producers
QMutableListIterator<Mlt::Producer> i(producers);
while (i.hasNext()) {
Mlt::Producer producer = i.next();
if (!QString(producer.get("mlt_service")).startsWith("avformat"))
i.remove();
}

if (producers.length() < 1) {
QMessageBox::warning(this, windowTitle(), tr("No resources to convert"));
return;
}

TranscodeDialog dialog(
tr("Choose an edit-friendly format below and then click OK to choose a file name. "
"After choosing a file name, a job is created. "
"When it is done, double-click the job to open it.\n"),
MLT.profile().progressive(), this);
dialog.setWindowTitle(tr("Convert..."));
dialog.setWindowModality(QmlApplication::dialogModality());
dialog.set709Convert(true);
Transcoder transcoder;
transcoder.setProducers(producers);
transcoder.convert(dialog);
accept();
}

void ResourceDialog::showEvent(QShowEvent *event)
{
m_resourceWidget->updateSize();
resize(m_resourceWidget->width() + 4, m_resourceWidget->height());
QDialog::showEvent(event);
}
50 changes: 50 additions & 0 deletions src/dialogs/resourcedialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2023 Meltytech, LLC
*
* This program 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.
*
* This program 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef RESOURCEDIALOG_H
#define RESOURCEDIALOG_H

#include <QDialog>

class ResourceWidget;

namespace Mlt {
class Producer;
}

class ResourceDialog : public QDialog
{
Q_OBJECT
public:
explicit ResourceDialog(QWidget *parent = 0);

void search(Mlt::Producer *producer);
void add(Mlt::Producer *producer);
void selectTroubleClips();
bool hasTroubleClips();

private slots:
void convert();

protected:
virtual void showEvent(QShowEvent *event) override;

private:
ResourceWidget *m_resourceWidget;
};

#endif // RESOURCEDIALOG_H
22 changes: 17 additions & 5 deletions src/docks/playlistdock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "dialogs/durationdialog.h"
#include "dialogs/filedatedialog.h"
#include "dialogs/longuitask.h"
#include "dialogs/resourcedialog.h"
#include "dialogs/slideshowgeneratordialog.h"
#include "mainwindow.h"
#include "settings.h"
Expand Down Expand Up @@ -1075,6 +1076,7 @@ void PlaylistDock::onDropped(const QMimeData *data, int row)
{
bool resetIndex = true;
if (data && data->hasUrls()) {
ResourceDialog dialog(this);
LongUiTask longTask(tr("Add Files"));
int insertNextAt = row;
bool first = true;
Expand Down Expand Up @@ -1114,14 +1116,17 @@ void PlaylistDock::onDropped(const QMimeData *data, int row)
if (first) {
first = false;
if (!MLT.producer() || !MLT.producer()->is_valid()) {
MAIN.open(path, nullptr, false);
Mlt::Properties properties;
properties.set(kShotcutSkipConvertProperty, 1);
MAIN.open(path, &properties, false);
if (MLT.producer() && MLT.producer()->is_valid()) {
producer = MLT.producer();
first = true;
}
}
}
producer = MLT.setupNewProducer(producer);
producer->set(kShotcutSkipConvertProperty, true);
if (!MLT.isLiveProducer(producer) || producer->get_int(kShotcutVirtualClip)) {
ProxyManager::generateIfNotExists(*producer);
if (row == -1)
Expand All @@ -1130,10 +1135,10 @@ void PlaylistDock::onDropped(const QMimeData *data, int row)
MAIN.undoStack()->push(new Playlist::InsertCommand(m_model, MLT.XML(producer), insertNextAt++));
} else {
LongUiTask::cancel();
DurationDialog dialog(this);
dialog.setDuration(MLT.profile().fps() * 5);
if (dialog.exec() == QDialog::Accepted) {
producer->set_in_and_out(0, dialog.duration() - 1);
DurationDialog durationDialog(this);
durationDialog.setDuration(MLT.profile().fps() * 5);
if (durationDialog.exec() == QDialog::Accepted) {
producer->set_in_and_out(0, durationDialog.duration() - 1);
if (row == -1)
MAIN.undoStack()->push(new Playlist::AppendCommand(m_model, MLT.XML(producer)));
else
Expand All @@ -1145,9 +1150,16 @@ void PlaylistDock::onDropped(const QMimeData *data, int row)
setIndex(0);
resetIndex = false;
}
dialog.add(producer);
delete producer;
}
}
if (dialog.hasTroubleClips()) {
dialog.selectTroubleClips();
dialog.setWindowTitle(tr("Dropped Files"));
longTask.cancel();
dialog.exec();
}
} else if (data && data->hasFormat(Mlt::XmlMimeType)) {
if (MLT.producer() && MLT.producer()->is_valid()) {
if (MLT.producer()->type() == mlt_service_playlist_type) {
Expand Down
Loading

0 comments on commit 402e677

Please sign in to comment.