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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
/*
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
2 of the License, or (at your option) any later version.
*/
#include <QPushButton>
#include <QJsonDocument>
#include <QJsonArray>
#include <QJsonObject>
#include <QLabel>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QTabWidget>
#include <QStackedWidget>
#include <QImage>
#include <QSqlDatabase>
#include <QSqlQuery>
#include "filepropertiesdialog.h"
#include "smtreemodel.h"
#include "smtreeitem.h"
#include "smtreeview.h"
#include "helper.h"
FilePropertiesDialog::FilePropertiesDialog(const QString &file, QWidget *parent, Qt::WindowFlags f) : SmDialog(parent, f), mFile(file){
mStack = new QStackedWidget;
mTab = new QTabWidget;
QString lText = QString(tr("<b>Properties - %1</b>")).arg(mFile);
QLabel *l = new QLabel(lText);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(l);
QWidget *formatWidget = new QWidget;
mFormatView = new SmTreeView;
mFormatModel = new SmTreeModel(QStringList() << tr("Key") << tr("Value"), this);
mFormatView->setModel(mFormatModel);
QHBoxLayout *formatLayout = new QHBoxLayout;
formatLayout->addWidget(mFormatView);
formatWidget->setLayout(formatLayout);
mTab->addTab(formatWidget, tr("Format"));
QWidget *streamWidget = new QWidget;
mStreamView = new SmTreeView;
mStreamModel = new SmTreeModel(QStringList() << tr("Key") << tr("Value"), this);
mStreamView->setModel(mStreamModel);
QHBoxLayout *streamLayout = new QHBoxLayout;
streamLayout->addWidget(mStreamView);
streamWidget->setLayout(streamLayout);
mTab->addTab(streamWidget, tr("Streams"));
mStack->addWidget(mTab);
QTabWidget *mPicsTab = new QTabWidget;
QWidget *picWidget = new QWidget;
mPicView = new SmTreeView;
mPicModel = new SmTreeModel(QStringList() << tr("Key") << tr("Value"), this);
mPicView->setModel(mPicModel);
QHBoxLayout *picLayout = new QHBoxLayout;
picLayout->addWidget(mPicView);
picWidget->setLayout(picLayout);
mPicsTab->addTab(picWidget, tr("Picture data"));
QWidget *archivedTab = new QWidget;
mArchivedAs = new QLabel;
QHBoxLayout *archivedL = new QHBoxLayout;
archivedL->addWidget(mArchivedAs);
archivedTab->setLayout(archivedL);
mPicsTab->addTab(archivedTab, tr("Archive"));
mStack->addWidget(mPicsTab);
mainLayout->addWidget(mStack);
mOk = new QPushButton(tr("Ok"));
connect(mOk, SIGNAL(clicked()), this, SLOT(accept()));
QHBoxLayout *buttonLayout = new QHBoxLayout;
buttonLayout->addStretch();
buttonLayout->addWidget(mOk);
buttonLayout->addStretch();
mainLayout->addLayout(buttonLayout);
setLayout(mainLayout);
QString mimeType = Helper::mimeType(mFile);
if(mimeType.startsWith("video")){
mStack->setCurrentIndex(0);
movieData();
}else if(mimeType.startsWith("image")){
mStack->setCurrentIndex(1);
pictureData();
}
}
void FilePropertiesDialog::movieData(){
QJsonDocument jsDoc = Helper::streamData(mFile);
if(jsDoc.isNull()){
return;
}
QJsonObject obj = jsDoc.object();
SmTreeItem *formatItem = new SmTreeItem(2);
movieDataRecursive(obj.value("format"), formatItem);
mFormatModel->setRoot(formatItem);
mFormatView->expandAll();
SmTreeItem *streamItem = new SmTreeItem(2);
QJsonArray streamA = obj.value("streams").toArray();
for(int i = 0; i < streamA.size(); ++i){
QString itemName = QString(tr("Stream %1 [%2]")).arg(QString::number(i + 1)).arg(streamA.at(i).toObject().value("codec_type").toString());
SmTreeItem *item = new SmTreeItem(QList<QVariant>() << itemName << QVariant(), streamItem);
streamItem->appendChild(item);
movieDataRecursive(streamA.at(i), item);
}
mStreamModel->setRoot(streamItem);
mStreamView->expandAll();
}
void FilePropertiesDialog::movieDataRecursive(QJsonValue start, SmTreeItem *appendTo){
QJsonObject sObject = start.toObject();
QJsonObject::const_iterator it;
for(it = sObject.constBegin(); it != sObject.constEnd(); ++it){
QList<QVariant> data = QList<QVariant>() << it.key() << it.value().toVariant();
if(it.key() == "duration"){
qint64 seconds = it.value().toString().toDouble();
Helper::Duration dur(seconds);
data[1] = dur.toString();
}
if(it.key() == "bit_rate"){
qint64 br = it.value().toString().toInt() / 1000;
data[1] = QString("%1 kb/s").arg(QString::number(br));
}
SmTreeItem *newItem = new SmTreeItem(data, appendTo);
appendTo->appendChild(newItem);
movieDataRecursive(*it, newItem);
}
}
void FilePropertiesDialog::pictureData(){
// the sheer numbers...
QImage img = QImage(mFile);
if(img.isNull()){
return;
}
SmTreeItem *rootItem = new SmTreeItem(2);
appendItem(QList<QVariant>() << tr("width") << img.width(), rootItem);
appendItem(QList<QVariant>() << tr("height") << img.height(), rootItem);
appendItem(QList<QVariant>() << tr("depth") << img.depth(), rootItem);
appendItem(QList<QVariant>() << tr("alpha channel") << (img.hasAlphaChannel() ? tr("yes") : tr("no")), rootItem);
appendItem(QList<QVariant>() << tr("qt format") << img.format(), rootItem);
appendItem(QList<QVariant>() << tr("byte count") << img.byteCount(), rootItem);
mPicModel->setRoot(rootItem);
//now let's see if the file is already in the archive
QString md5sum = Helper::md5Sum(mFile);
QSqlDatabase db = QSqlDatabase::database("treedb");
db.open();
QSqlQuery p(db);
p.prepare("SELECT tdescription_name FROM pics, pics_mappings, mapping_parents, mapping_description WHERE pics.cmd5sum = :md5 AND pics.ipicsid = pics_mappings.ipics_id AND pics_mappings.imappings_parents_id = mapping_parents.imapping_parents_id AND mapping_parents.idescription_id = mapping_description.idescription_id ORDER BY tdescription_name");
p.bindValue(":md5", md5sum);
p.exec();
QStringList archived;
while(p.next()){
archived << p.value(0).toString();
}
if(archived.empty()){
mArchivedAs->setText(tr("<center>File not found in Archive</center>"));
}else{
QString text = QString(tr("<p>Archived as:</p><ul>"));
foreach(QString a, archived){
text.append(QString(tr("<li>%1</li>")).arg(a));
}
text.append("</ul>");
mArchivedAs->setText(text);
}
}
void FilePropertiesDialog::appendItem(const QList<QVariant> &data, SmTreeItem *parent){
SmTreeItem *item = new SmTreeItem(data, parent);
parent->appendChild(item);
}
|