Skip to content

Commit

Permalink
[filemanager] Add some properties to FileInfo required by gallery. Co…
Browse files Browse the repository at this point in the history
…ntributes to JB#52724
  • Loading branch information
adenexter committed Jan 27, 2021
1 parent 7d57db0 commit 82a94ec
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/plugin/statfileinfo.cpp
Expand Up @@ -164,3 +164,47 @@ FileInfo::FileInfo(QObject *parent)
FileInfo::~FileInfo()
{
}

QUrl FileInfo::url() const
{
return m_url;
}

void FileInfo::setUrl(const QUrl &url)
{
if (m_url != url) {
const bool wasLocal = m_localFile;

m_url = url;

if (!m_url.isEmpty() && m_url.isLocalFile()) {
m_localFile = true;

StatFileInfo::setFile(m_url.toLocalFile());
} else {
m_localFile = false;

StatFileInfo::setFile(QString());
}

if (m_localFile != wasLocal) {
emit localFileChanged();
}

emit urlChanged();
}
}

bool FileInfo::isLocalFile() const
{
return m_localFile;
}

void FileInfo::setFile(const QString &file)
{
if (file.isEmpty()) {
setUrl(QUrl());
} else {
setUrl(QUrl::fromLocalFile(file));
}
}
17 changes: 17 additions & 0 deletions src/plugin/statfileinfo.h
Expand Up @@ -36,6 +36,7 @@
#include <QFileInfo>
#include <QDateTime>
#include <QDir>
#include <QUrl>
#include <sys/stat.h>

#include "archiveinfo.h"
Expand Down Expand Up @@ -149,6 +150,7 @@ bool operator!=(const StatFileInfo &lhs, const StatFileInfo &rhs);
class FileInfo : public QObject, protected StatFileInfo
{
Q_OBJECT
Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged)
Q_PROPERTY(QString file READ file WRITE setFile NOTIFY fileChanged)
Q_PROPERTY(QString fileName READ fileName NOTIFY fileChanged)
Q_PROPERTY(QString mimeType READ mimeType NOTIFY fileChanged)
Expand All @@ -163,14 +165,29 @@ class FileInfo : public QObject, protected StatFileInfo
Q_PROPERTY(QDateTime accessed READ lastAccessed NOTIFY fileChanged)
Q_PROPERTY(QString baseName READ baseName NOTIFY fileChanged)
Q_PROPERTY(QString directoryPath READ absolutePath NOTIFY fileChanged)
Q_PROPERTY(bool exists READ exists NOTIFY fileChanged)
Q_PROPERTY(bool localFile READ isLocalFile NOTIFY localFileChanged)
public:
explicit FileInfo(QObject *parent = nullptr);
~FileInfo() override;

QUrl url() const;
void setUrl(const QUrl &url);

bool isLocalFile() const;

void setFile(const QString &file);

Q_INVOKABLE void refresh() { StatFileInfo::refresh(); }

signals:
void fileChanged() override;
void urlChanged();
void localFileChanged();

private:
QUrl m_url;
bool m_localFile = false;
};

#endif // STATFILEINFO_H

0 comments on commit 82a94ec

Please sign in to comment.