forked from mltframework/shotcut
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfiledatedialog.cpp
More file actions
129 lines (113 loc) · 4.47 KB
/
filedatedialog.cpp
File metadata and controls
129 lines (113 loc) · 4.47 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
/*
* Copyright (c) 2019-2022 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 "filedatedialog.h"
#include "shotcut_mlt_properties.h"
#include "MltProducer.h"
#include "proxymanager.h"
#include <QComboBox>
#include <QDateTimeEdit>
#include <QDebug>
#include <QDialogButtonBox>
#include <QFileInfo>
#include <QVBoxLayout>
void addDateToCombo(QComboBox *combo, const QString &description, const QDateTime &date)
{
QDateTime local = date.toLocalTime();
QString text = local.toString("yyyy-MM-dd HH:mm:ss") + " [" + description + "]";
combo->addItem(text, local);
}
FileDateDialog::FileDateDialog(QString title, Mlt::Producer *producer, QWidget *parent)
: QDialog(parent)
, m_producer(producer)
, m_dtCombo(new QComboBox())
, m_dtEdit(new QDateTimeEdit())
{
setWindowTitle(tr("%1 File Date").arg(title));
int64_t milliseconds = producer->get_creation_time();
QDateTime creation_time;
if ( !milliseconds ) {
creation_time = QDateTime::currentDateTime();
} else {
// Set the date to the current producer date.
creation_time = QDateTime::fromMSecsSinceEpoch(milliseconds);
}
QVBoxLayout *VLayout = new QVBoxLayout(this);
populateDateOptions(producer);
m_dtCombo->setCurrentIndex(-1);
VLayout->addWidget(m_dtCombo);
connect(m_dtCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(dateSelected(int)));
m_dtEdit->setDisplayFormat("yyyy-MM-dd HH:mm:ss");
m_dtEdit->setCalendarPopup(true);
m_dtEdit->setTimeSpec(Qt::LocalTime);
m_dtEdit->setDateTime(creation_time);
VLayout->addWidget(m_dtEdit);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
| QDialogButtonBox::Cancel);
VLayout->addWidget(buttonBox);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
this->setLayout (VLayout);
this->setModal(true);
}
void FileDateDialog::accept()
{
m_producer->set_creation_time((int64_t)m_dtEdit->dateTime().toTimeSpec(
Qt::LocalTime).toMSecsSinceEpoch());
QDialog::accept();
}
void FileDateDialog::dateSelected(int index)
{
qDebug() << index;
if ( index > -1 ) {
m_dtEdit->setDateTime(m_dtCombo->itemData(index).toDateTime());
}
}
void FileDateDialog::populateDateOptions(Mlt::Producer *producer)
{
QDateTime dateTime;
// Add current value
int64_t milliseconds = producer->get_creation_time();
if ( milliseconds ) {
dateTime = QDateTime::fromMSecsSinceEpoch(milliseconds);
addDateToCombo(m_dtCombo, tr("Current Value"), dateTime);
}
// Add now time
addDateToCombo(m_dtCombo, tr("Now"), QDateTime::currentDateTime());
// Add system info for the file.
QString resource = ProxyManager::resource(*producer);
QFileInfo fileInfo(resource);
if (fileInfo.exists()) {
addDateToCombo(m_dtCombo, tr("System - Modified"), fileInfo.lastModified());
addDateToCombo(m_dtCombo, tr("System - Created"), fileInfo.birthTime());
}
// Add metadata dates
Mlt::Producer tmpProducer( *(producer->profile()), "avformat", resource.toUtf8().constData() );
if (tmpProducer.is_valid()) {
// Standard FFMpeg creation_time
dateTime = QDateTime::fromString(tmpProducer.get("meta.attr.creation_time.markup"),
Qt::ISODateWithMs);
if (dateTime.isValid()) {
addDateToCombo(m_dtCombo, tr("Metadata - Creation Time"), dateTime);
}
// Quicktime create date
dateTime = QDateTime::fromString(
tmpProducer.get("meta.attr.com.apple.quicktime.creationdate.markup"), Qt::ISODateWithMs);
if (dateTime.isValid()) {
addDateToCombo(m_dtCombo, tr("Metadata - QuickTime date"), dateTime);
}
}
}