2
* Copyright (C) 2013-2015 Canonical, Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 3, as published
6
* by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License along
14
* with this program. If not, see <http://www.gnu.org/licenses/>.
18
#include "docviewerfile.h"
22
5
#include <QMimeDatabase>
7
#include "docviewerFile.h"
30
import DocumentViewer 1.0
12
import org.docviewer.file 1.0
54
36
DocviewerFile::DocviewerFile(QObject *parent) :
58
connect(this, SIGNAL(pathChanged()), this, SLOT(open()));
61
DocviewerFile::~DocviewerFile()
66
void DocviewerFile::setPath(const QString &path)
71
QFileInfo file(QDir::currentPath(), path);
73
m_path = file.absoluteFilePath();
76
qDebug() << "[FILE] Path parsed as:" << m_path;
79
void DocviewerFile::open()
84
QFileInfo file(m_path);
87
qDebug() << "[FILE] Extracting information from the file...";
89
/** Get info of the file **/
90
m_info["size"] = file.size();
91
m_info["lastModified"] = file.lastModified();
92
m_info["creationTime"] = file.created();
41
DocviewerFile::~DocviewerFile() {
45
void DocviewerFile::setPath(QString p) {
100
qDebug() << "[FILE] ERROR: Requested file does not exist!";
102
Q_EMIT errorChanged();
106
void DocviewerFile::setMimetype()
50
this->path = QFileInfo(QDir::currentPath(), p).absoluteFilePath();
53
qDebug() << "[FILE] Path parsed as:" << this->path;
60
void DocviewerFile::open() {
66
qDebug() << "[FILE] Extracting informations from the file...";
68
/**Get info of the file**/
72
lastmodified = file.lastModified();
73
emit lastmodifiedChanged();
75
creationTime = file.created();
76
emit creationTimeChanged();
82
qDebug() << "[FILE] ERROR: Requested file does not exist!";
89
void DocviewerFile::readMimeType()
108
QMimeType mime = QMimeDatabase().mimeTypeForFile(m_path);
110
m_mimetype["name"] = mime.name();
111
m_mimetype["description"] = mime.comment();
113
// Use a more user-friendly value for 'name' when Qt can not determinate the
115
if (m_mimetype.value("name") == "application/octet-stream")
116
m_mimetype["name"] = "Unknown";
118
qDebug() << "[FILE] Requested file mime type:" << m_mimetype.value("name");
119
Q_EMIT mimetypeChanged();
92
mimetype = db.mimeTypeForFile(this->path).name();
94
if (mimetype == "application/octet-stream") {
95
// Returned by Qt when it cannot determinate the mime type
99
qDebug() << "[FILE] Mime type for the requested file is" << mimetype;
100
emit mimetypeChanged();