Commit 3bd7ad72 authored by Harald Sitter's avatar Harald Sitter 🏳️‍🌈
Browse files

clang-format run

parent a82ab1e8
/***********************************************************************
* SPDX-FileCopyrightText: 2020 Shubham <aryan100jangid@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
***********************************************************************/
* SPDX-FileCopyrightText: 2020 Shubham <aryan100jangid@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
***********************************************************************/
#include "testFileTree.h"
......
/***********************************************************************
* SPDX-FileCopyrightText: 2020 Shubham <aryan100jangid@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
***********************************************************************/
* SPDX-FileCopyrightText: 2020 Shubham <aryan100jangid@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
***********************************************************************/
#ifndef TESTFILETREE_H
#define TESTFILETREE_H
......@@ -17,8 +17,8 @@ class TestFileTree : public QObject
public:
TestFileTree();
~TestFileTree() override;
~TestFileTree() override;
private:
void testFileName();
void testFileSize();
......
......@@ -102,7 +102,6 @@ private Q_SLOTS:
qDebug() << entries.keys();
}
// During development there were some bugs with iterating C:/, make sure this finishes eventually and has some entries.
void testCDrive()
{
......@@ -114,7 +113,6 @@ private Q_SLOTS:
QVERIFY(entries.size() > 3); // windows, programs, users
}
void testBadPath()
{
for (const auto &entry : DirectoryIterator(QByteArrayLiteral("/tmp/filelighttest1312312312313123123123"))) {
......
/***********************************************************************
* SPDX-FileCopyrightText: 2003-2004 Max Howell <max.howell@methylblue.com>
* SPDX-FileCopyrightText: 2008-2009 Martin Sandsmark <martin.sandsmark@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
***********************************************************************/
* SPDX-FileCopyrightText: 2003-2004 Max Howell <max.howell@methylblue.com>
* SPDX-FileCopyrightText: 2008-2009 Martin Sandsmark <martin.sandsmark@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
***********************************************************************/
#include "Config.h"
......@@ -23,28 +23,26 @@ int Config::minFontPitch;
uint Config::defaultRingDepth;
Filelight::MapScheme Config::scheme;
QStringList Config::skipList;
const QSet<QByteArray> Config::remoteFsTypes = { "smbfs", "nfs", "afs" };
const QSet<QByteArray> Config::remoteFsTypes = {"smbfs", "nfs", "afs"};
void
Filelight::Config::read()
void Filelight::Config::read()
{
const KConfigGroup config = KSharedConfig::openConfig()->group("filelight_part");
scanAcrossMounts = config.readEntry("scanAcrossMounts", false);
scanRemoteMounts = config.readEntry("scanRemoteMounts", false);
scanAcrossMounts = config.readEntry("scanAcrossMounts", false);
scanRemoteMounts = config.readEntry("scanRemoteMounts", false);
varyLabelFontSizes = config.readEntry("varyLabelFontSizes", true);
showSmallFiles = config.readEntry("showSmallFiles", false);
contrast = config.readEntry("contrast", 75);
antialias = config.readEntry("antialias", true);
minFontPitch = config.readEntry("minFontPitch", QFont().pointSize() - 3);
scheme = (MapScheme) config.readEntry("scheme", 0);
skipList = config.readEntry("skipList", QStringList());
defaultRingDepth = 4;
showSmallFiles = config.readEntry("showSmallFiles", false);
contrast = config.readEntry("contrast", 75);
antialias = config.readEntry("antialias", true);
minFontPitch = config.readEntry("minFontPitch", QFont().pointSize() - 3);
scheme = (MapScheme)config.readEntry("scheme", 0);
skipList = config.readEntry("skipList", QStringList());
defaultRingDepth = 4;
}
void
Filelight::Config::write()
void Filelight::Config::write()
{
KConfigGroup config = KSharedConfig::openConfig()->group("filelight_part");
......@@ -56,6 +54,6 @@ Filelight::Config::write()
config.writeEntry("antialias", antialias);
config.writeEntry("minFontPitch", minFontPitch);
config.writeEntry("scheme", (int)scheme); // TODO: make the enum belong to a qwidget,
//and use magic macros to make it save this properly
// and use magic macros to make it save this properly
config.writePathEntry("skipList", skipList);
}
/***********************************************************************
* SPDX-FileCopyrightText: 2003-2004 Max Howell <max.howell@methylblue.com>
* SPDX-FileCopyrightText: 2008-2009 Martin Sandsmark <martin.sandsmark@kde.org>
* SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
***********************************************************************/
* SPDX-FileCopyrightText: 2003-2004 Max Howell <max.howell@methylblue.com>
* SPDX-FileCopyrightText: 2008-2009 Martin Sandsmark <martin.sandsmark@kde.org>
* SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
***********************************************************************/
#ifndef Config_H
#define Config_H
......@@ -31,7 +31,7 @@ public:
static void read();
static void write();
//keep everything positive, avoid using DON'T, NOT or NO
// keep everything positive, avoid using DON'T, NOT or NO
static bool scanAcrossMounts;
static bool scanRemoteMounts;
......
/***********************************************************************
* SPDX-FileCopyrightText: 2003-2004 Max Howell <max.howell@methylblue.com>
* SPDX-FileCopyrightText: 2008-2013 Martin Sandsmark <martin.sandsmark@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
***********************************************************************/
* SPDX-FileCopyrightText: 2003-2004 Max Howell <max.howell@methylblue.com>
* SPDX-FileCopyrightText: 2008-2013 Martin Sandsmark <martin.sandsmark@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
***********************************************************************/
#ifndef DEFINE_H
#define DEFINE_H
......
......@@ -6,11 +6,11 @@
#include "directoryEntry.h"
#ifdef Q_OS_WINDOWS
#include "windowsWalker.h"
template<class T = WindowsWalker>
#include "windowsWalker.h"
template<class T = WindowsWalker>
#else
#include "posixWalker.h"
template<class T = POSIXWalker>
#include "posixWalker.h"
template<class T = POSIXWalker>
#endif
class DirectoryIterator
{
......@@ -40,7 +40,6 @@ public:
std::shared_ptr<T> m_walker = std::make_shared<T>(QByteArray()); // always have a valid walker to simplify accessing into it
private:
friend bool operator==(const DirectoryIterator &lhs, const DirectoryIterator &rhs) noexcept
{
return lhs.m_walker->m_entry.name == rhs.m_walker->m_entry.name;
......
/***********************************************************************
* SPDX-FileCopyrightText: 2003-2004 Max Howell <max.howell@methylblue.com>
* SPDX-FileCopyrightText: 2008-2009 Martin Sandsmark <martin.sandsmark@kde.org>
* SPDX-FileCopyrightText: 2017 Harald Sitter <sitter@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
***********************************************************************/
* SPDX-FileCopyrightText: 2003-2004 Max Howell <max.howell@methylblue.com>
* SPDX-FileCopyrightText: 2008-2009 Martin Sandsmark <martin.sandsmark@kde.org>
* SPDX-FileCopyrightText: 2017 Harald Sitter <sitter@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
***********************************************************************/
#include "fileTree.h"
#include <QDir>
#include <QUrl>
QString File::displayName() const {
QString File::displayName() const
{
const QString decodedName = QString::fromUtf8(m_name);
return url().isLocalFile() ? QDir::toNativeSeparators(decodedName) : decodedName;
}
......@@ -30,7 +31,7 @@ QUrl File::url(const Folder *root) const
QString path;
if (root == this) {
root = nullptr; //prevent returning empty string when there is something we could return
root = nullptr; // prevent returning empty string when there is something we could return
}
for (const File *d = this; d != root && d; d = d->parent()) {
......
/***********************************************************************
* SPDX-FileCopyrightText: 2003-2004 Max Howell <max.howell@methylblue.com>
* SPDX-FileCopyrightText: 2008-2009 Martin Sandsmark <martin.sandsmark@kde.org>
* SPDX-FileCopyrightText: 2017-2022 Harald Sitter <sitter@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
***********************************************************************/
* SPDX-FileCopyrightText: 2003-2004 Max Howell <max.howell@methylblue.com>
* SPDX-FileCopyrightText: 2008-2009 Martin Sandsmark <martin.sandsmark@kde.org>
* SPDX-FileCopyrightText: 2017-2022 Harald Sitter <sitter@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
***********************************************************************/
#ifndef FILETREE_H
#define FILETREE_H
#include <QByteArray> //qstrdup
#include <KFormat>
#include <QByteArray> //qstrdup
#include <stdlib.h>
typedef quint64 FileSize;
typedef quint64 Dirsize; //**** currently unused
typedef quint64 Dirsize; //**** currently unused
class Folder;
......@@ -26,25 +26,35 @@ public:
Q_OBJECT
public:
File(const char *name, FileSize size) : m_parent(nullptr), m_name(qstrdup(name)), m_size(size) {}
virtual ~File() {
delete [] m_name;
File(const char *name, FileSize size)
: m_parent(nullptr)
, m_name(qstrdup(name))
, m_size(size)
{
}
virtual ~File()
{
delete[] m_name;
}
Folder *parent() const {
Folder *parent() const
{
return m_parent;
}
/** Do not use for user visible strings. Use name instead. */
const char *name8Bit() const {
const char *name8Bit() const
{
return m_name;
}
void setName(const QByteArray &newName) {
delete [] m_name;
void setName(const QByteArray &newName)
{
delete[] m_name;
m_name = qstrdup(newName.constData());
}
/** Decoded name. Use when you need a QString. */
QString decodedName() const {
QString decodedName() const
{
return QString::fromUtf8(m_name);
}
/**
......@@ -53,11 +63,13 @@ public:
*/
QString displayName() const;
FileSize size() const {
FileSize size() const
{
return m_size;
}
virtual bool isFolder() const {
virtual bool isFolder() const
{
return false;
}
......@@ -66,7 +78,8 @@ public:
* Only use for display.
*/
QString displayPath(const Folder * = nullptr) const;
QString humanReadableSize() const {
QString humanReadableSize() const
{
return KFormat().formatByteSize(m_size);
}
......@@ -74,34 +87,44 @@ public:
QUrl url(const Folder *root = nullptr) const;
protected:
File(const char *name, FileSize size, Folder *parent) : m_parent(parent), m_name(qstrdup(name)), m_size(size) {}
File(const char *name, FileSize size, Folder *parent)
: m_parent(parent)
, m_name(qstrdup(name))
, m_size(size)
{
}
Folder *m_parent; //0 if this is treeRoot
Folder *m_parent; // 0 if this is treeRoot
char *m_name; // partial path name (e.g. 'boot/' or 'foo.svg')
FileSize m_size; // in units of bytes; sum of all children's sizes
private:
File(const File&);
void operator=(const File&);
File(const File &);
void operator=(const File &);
};
class Folder : public File
{
Q_OBJECT
Q_PROPERTY(uint children MEMBER m_children CONSTANT)
public:
Folder(const char *name) : File(name, 0), m_children(0) {} //DON'T pass the full path!
Folder(const char *name)
: File(name, 0)
, m_children(0)
{
} // DON'T pass the full path!
~Folder() override
{
qDeleteAll(files);
}
uint children() const {
uint children() const
{
return m_children;
}
bool isFolder() const override {
bool isFolder() const override
{
return true;
}
......@@ -110,7 +133,7 @@ public:
Folder *ret = new Folder(m_name);
for (const File *child : files) {
if (child->isFolder()) {
ret->append(((Folder*)child)->duplicate());
ret->append(((Folder *)child)->duplicate());
} else {
ret->append(child->name8Bit(), child->size());
}
......@@ -118,28 +141,29 @@ public:
return ret;
}
///appends a Folder
void append(Folder *d, const char *name=nullptr)
/// appends a Folder
void append(Folder *d, const char *name = nullptr)
{
if (name) {
delete [] d->m_name;
delete[] d->m_name;
d->m_name = qstrdup(name);
} //directories that had a fullpath copy just their names this way
} // directories that had a fullpath copy just their names this way
m_children += d->children(); //doesn't include the dir itself
m_children += d->children(); // doesn't include the dir itself
d->m_parent = this;
append((File*)d); //will add 1 to filecount for the dir itself
append((File *)d); // will add 1 to filecount for the dir itself
}
///appends a File
/// appends a File
void append(const char *name, FileSize size)
{
append(new File(name, size, this));
}
/// removes a file
void remove(const File *f) {
files.removeAll(const_cast<File*>(f));
void remove(const File *f)
{
files.removeAll(const_cast<File *>(f));
const FileSize childSize = f->size();
delete f;
......@@ -150,8 +174,9 @@ public:
}
// Removes a file, but does not delete
const File *take(const File *f) {
files.removeAll(const_cast<File*>(f));
const File *take(const File *f)
{
files.removeAll(const_cast<File *>(f));
const FileSize childSize = f->size();
for (Folder *d = this; d; d = d->parent()) {
......@@ -178,8 +203,8 @@ private:
uint m_children;
private:
Folder(const Folder&); //undefined
void operator=(const Folder&); //undefined
Folder(const Folder &); // undefined
void operator=(const Folder &); // undefined
};
#endif
/***********************************************************************
* SPDX-FileCopyrightText: 2003-2004 Max Howell <max.howell@methylblue.com>
* SPDX-FileCopyrightText: 2008-2009 Martin Sandsmark <martin.sandsmark@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
***********************************************************************/
* SPDX-FileCopyrightText: 2003-2004 Max Howell <max.howell@methylblue.com>
* SPDX-FileCopyrightText: 2008-2009 Martin Sandsmark <martin.sandsmark@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
***********************************************************************/
#include "historyAction.h"
#include "filelight_debug.h"
#include <KActionCollection>
#include <KConfig>
#include <KConfigGroup>
#include <KStandardShortcut>
#include <KLocalizedString>
#include <KStandardShortcut>
#include <QGuiApplication>
#include <QIcon>
inline HistoryAction::HistoryAction(const QIcon& icon, const QString& text, KActionCollection* ac)
: QAction(icon, text, ac)
, m_text(text)
inline HistoryAction::HistoryAction(const QIcon &icon, const QString &text, KActionCollection *ac)
: QAction(icon, text, ac)
, m_text(text)
{
// .ui files make this false, but we can't rely on UI file as it isn't compiled in :(
setEnabled(false);
}
void HistoryAction::setHelpText(const QUrl& url)
void HistoryAction::setHelpText(const QUrl &url)
{
QString text = url.path();
setStatusTip(text);
......@@ -33,10 +32,10 @@ void HistoryAction::setHelpText(const QUrl& url)
setWhatsThis(text);
}
void HistoryAction::push(const QUrl &path)
{
if (path.isEmpty()) return;
if (path.isEmpty())
return;
if (m_list.isEmpty() || (!m_list.isEmpty() && (m_list.last() != path)))
m_list.append(path);
......@@ -55,26 +54,28 @@ QUrl HistoryAction::pop()
return s;
}
HistoryCollection::HistoryCollection(KActionCollection *ac, QObject *parent)
: QObject(parent)
, m_b(new HistoryAction(QIcon::fromTheme(QGuiApplication::layoutDirection() == Qt::LeftToRight ? QStringLiteral("go-previous") : QStringLiteral("go-previous-symbolic-rtl")), i18nc("Go to the last path viewed", "Back"), ac))
, m_f(new HistoryAction(QIcon::fromTheme(QGuiApplication::layoutDirection() == Qt::LeftToRight ? QStringLiteral("go-next") : QStringLiteral("go-next-symbolic-rtl")), i18nc("Go to forward in the history of paths viewed", "Forward"), ac))
, m_receiver(nullptr)
: QObject(parent)
, m_b(new HistoryAction(
QIcon::fromTheme(QGuiApplication::layoutDirection() == Qt::LeftToRight ? QStringLiteral("go-previous") : QStringLiteral("go-previous-symbolic-rtl")),
i18nc("Go to the last path viewed", "Back"),
ac))
, m_f(new HistoryAction(
QIcon::fromTheme(QGuiApplication::layoutDirection() == Qt::LeftToRight ? QStringLiteral("go-next") : QStringLiteral("go-next-symbolic-rtl")),
i18nc("Go to forward in the history of paths viewed", "Forward"),
ac))
, m_receiver(nullptr)
{
ac->addAction(QStringLiteral( "go_back" ), m_b);
ac->addAction(QStringLiteral( "go_forward" ), m_f);
ac->addAction(QStringLiteral("go_back"), m_b);
ac->addAction(QStringLiteral("go_forward"), m_f);
connect(m_b, &QAction::triggered, this, &HistoryCollection::pop);
connect(m_f, &QAction::triggered, this, &HistoryCollection::pop);
}
void HistoryCollection::push(const QUrl& url) //slot
void HistoryCollection::push(const QUrl &url) // slot
{
if (!url.isEmpty())
{
if (!m_receiver)
{
if (!url.isEmpty()) {
if (!m_receiver) {
m_f->clear();
m_receiver = m_b;
}
......@@ -84,9 +85,9 @@ void HistoryCollection::push(const QUrl& url) //slot
m_receiver = nullptr;
}
void HistoryCollection::pop() //slot
void HistoryCollection::pop() // slot
{
QUrl url = ((HistoryAction*)sender())->pop();
QUrl url = ((HistoryAction *)sender())->pop();
m_receiver = (sender() == m_b) ? m_f : m_b;
......@@ -108,7 +109,5 @@ void HistoryCollection::restore(const KConfigGroup &configgroup)
m_b->m_list = QUrl::fromStringList(configgroup.readPathEntry("backHistory", QStringList()));
m_f->m_list = QUrl::fromStringList(configgroup.readPathEntry("forwardHistory", QStringList()));
//TODO texts are not updated - no matter
// TODO texts are not updated - no matter
}
/***********************************************************************
* SPDX-FileCopyrightText: 2003-2004 Max Howell <max.howell@methylblue.com>
* SPDX-FileCopyrightText: 2008-2014 Martin Sandsmark <martin.sandsmark@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
***********************************************************************/
* SPDX-FileCopyrightText: 2003-2004 Max Howell <max.howell@methylblue.com>
* SPDX-FileCopyrightText: 2008-2014 Martin Sandsmark <martin.sandsmark@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
***********************************************************************/
#ifndef HISTORYACTION_H
#define HISTORYACTION_H
......@@ -23,18 +23,20 @@ class HistoryAction : QAction
friend class HistoryCollection;
public:
virtual void setEnabled(bool b = true) {
virtual void setEnabled(bool b = true)
{
QAction::setEnabled(b && !m_list.isEmpty());
}
void clear() {
void clear()
{
m_list.clear();
setEnabled(false);
QAction::setText(m_text);
}
private:
void setHelpText(const QUrl& url);
void setHelpText(const QUrl &url);
void push(const QUrl &url);
QUrl pop();
......@@ -43,7 +45,6 @@ private:
QList<QUrl> m_list;
};
class HistoryCollection : public QObject
{
Q_OBJECT
......@@ -55,13 +56,14 @@ public:
void restore(const KConfigGroup &configgroup);
public Q_SLOTS:
void push(const QUrl& url);
void stop() {
void push(const QUrl &url);
void stop()
{
m_receiver = nullptr;
}
Q_SIGNALS:
void activated(const QUrl&);
void activated(const QUrl &);
private Q_SLOTS:
void pop();
......
/***********************************************************************
* SPDX-FileCopyrightText: 2003-2004 Max Howell <max.howell@methylblue.com>
* SPDX-FileCopyrightText: 2008-2009 Martin Sandsmark <martin.sandsmark@kde.org>
* SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
***********************************************************************/
* SPDX-FileCopyrightText: 2003-2004 Max Howell <max.howell@methylblue.com>