forked from mltframework/shotcut
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunlinkedfilesdialog.cpp
More file actions
145 lines (135 loc) · 5.98 KB
/
unlinkedfilesdialog.cpp
File metadata and controls
145 lines (135 loc) · 5.98 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
* Copyright (c) 2016-2020 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 "unlinkedfilesdialog.h"
#include "ui_unlinkedfilesdialog.h"
#include "settings.h"
#include "mltxmlchecker.h"
#include "util.h"
#include <Logger.h>
#include <QFileDialog>
#include <QStringList>
UnlinkedFilesDialog::UnlinkedFilesDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::UnlinkedFilesDialog)
{
ui->setupUi(this);
}
UnlinkedFilesDialog::~UnlinkedFilesDialog()
{
delete ui;
}
void UnlinkedFilesDialog::setModel(QStandardItemModel &model)
{
QStringList headers;
headers << tr("Missing");
headers << tr("Replacement");
model.setHorizontalHeaderLabels(headers);
ui->tableView->setModel(&model);
ui->tableView->resizeColumnsToContents();
}
void UnlinkedFilesDialog::on_tableView_doubleClicked(const QModelIndex &index)
{
// Use File Open dialog to choose a replacement.
QString path = Settings.openPath();
#ifdef Q_OS_MAC
path.append("/*");
#endif
QStringList filenames = QFileDialog::getOpenFileNames(this, tr("Open File"), path,
QString(), nullptr, Util::getFileDialogOptions());
if (filenames.length() > 0) {
QAbstractItemModel *model = ui->tableView->model();
QModelIndex firstColIndex = model->index(index.row(), MltXmlChecker::MissingColumn);
QModelIndex secondColIndex = model->index(index.row(), MltXmlChecker::ReplacementColumn);
QString hash = Util::getFileHash(filenames[0]);
if (hash == model->data(firstColIndex, MltXmlChecker::ShotcutHashRole)) {
// If the hashes match set icon to OK.
QIcon icon(":/icons/oxygen/32x32/status/task-complete.png");
model->setData(firstColIndex, icon, Qt::DecorationRole);
} else {
// Otherwise, set icon to warning.
QIcon icon(":/icons/oxygen/32x32/status/task-attempt.png");
model->setData(firstColIndex, icon, Qt::DecorationRole);
}
// Add chosen filename to the model.
QString filePath = QDir::toNativeSeparators(filenames[0]);
model->setData(secondColIndex, filePath);
model->setData(secondColIndex, filePath, Qt::ToolTipRole);
model->setData(secondColIndex, hash, MltXmlChecker::ShotcutHashRole);
QFileInfo fi(QFileInfo(filenames.first()));
Settings.setOpenPath(fi.path());
lookInDir(fi.dir());
}
}
bool UnlinkedFilesDialog::lookInDir(const QDir &dir, bool recurse)
{
LOG_DEBUG() << dir.canonicalPath();
// returns true if outstanding is > 0
unsigned outstanding = 0;
QAbstractItemModel *model = ui->tableView->model();
for (int row = 0; row < model->rowCount(); row++) {
QModelIndex replacementIndex = model->index(row, MltXmlChecker::ReplacementColumn);
if (model->data(replacementIndex, MltXmlChecker::ShotcutHashRole).isNull())
++outstanding;
}
if (outstanding)
foreach (const QString &fileName,
dir.entryList(QDir::Files | QDir::Readable | QDir::NoDotAndDotDot)) {
QString hash = Util::getFileHash(dir.absoluteFilePath(fileName));
for (int row = 0; row < model->rowCount(); row++) {
QModelIndex replacementIndex = model->index(row, MltXmlChecker::ReplacementColumn);
if (model->data(replacementIndex, MltXmlChecker::ShotcutHashRole).isNull()) {
QModelIndex missingIndex = model->index(row, MltXmlChecker::MissingColumn);
QFileInfo missingInfo(model->data(missingIndex).toString());
QString missingHash = model->data(missingIndex, MltXmlChecker::ShotcutHashRole).toString();
if (hash == missingHash || fileName == missingInfo.fileName()) {
if (hash == missingHash) {
QIcon icon(":/icons/oxygen/32x32/status/task-complete.png");
model->setData(missingIndex, icon, Qt::DecorationRole);
} else {
QIcon icon(":/icons/oxygen/32x32/status/task-attempt.png");
model->setData(missingIndex, icon, Qt::DecorationRole);
}
QString filePath = QDir::toNativeSeparators(dir.absoluteFilePath(fileName));
model->setData(replacementIndex, filePath);
model->setData(replacementIndex, filePath, Qt::ToolTipRole);
model->setData(replacementIndex, hash, MltXmlChecker::ShotcutHashRole);
QCoreApplication::processEvents();
if (--outstanding)
break;
else
return false;
}
}
}
}
if (outstanding && recurse) {
foreach (const QString &dirName,
dir.entryList(QDir::Dirs | QDir::Executable | QDir::NoDotAndDotDot)) {
if (!lookInDir(dir.absoluteFilePath(dirName), true))
break;
}
}
return outstanding;
}
void UnlinkedFilesDialog::on_searchFolderButton_clicked()
{
QString dirName = QFileDialog::getExistingDirectory(this, windowTitle(), Settings.openPath(),
Util::getFileDialogOptions());
if (!dirName.isEmpty()) {
lookInDir(dirName);
}
}