Skip to content

Commit 029a455

Browse files
committed
Add clang-format
1 parent 04ec57d commit 029a455

File tree

16 files changed

+181
-47
lines changed

16 files changed

+181
-47
lines changed

.clang-format

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
---
2+
Language: Cpp
3+
AccessModifierOffset: -4
4+
AlignAfterOpenBracket: DontAlign
5+
AlignArrayOfStructures: None
6+
AlignConsecutiveAssignments: None
7+
AlignConsecutiveMacros: None
8+
AlignConsecutiveBitFields: None
9+
AlignConsecutiveDeclarations: None
10+
AlignEscapedNewlines: DontAlign
11+
AlignOperands: false
12+
AlignTrailingComments: false
13+
AllowAllArgumentsOnNextLine: true
14+
AllowAllConstructorInitializersOnNextLine: true
15+
AllowAllParametersOfDeclarationOnNextLine: true
16+
AllowShortEnumsOnASingleLine: true
17+
AllowShortBlocksOnASingleLine: Never
18+
AllowShortCaseLabelsOnASingleLine: false
19+
AllowShortFunctionsOnASingleLine: None
20+
AllowShortLambdasOnASingleLine: All
21+
AllowShortIfStatementsOnASingleLine: Never
22+
AllowShortLoopsOnASingleLine: false
23+
AlwaysBreakAfterReturnType: None
24+
AlwaysBreakBeforeMultilineStrings: false
25+
AlwaysBreakTemplateDeclarations: Yes
26+
BinPackArguments: false
27+
BinPackParameters: false
28+
BreakBeforeBinaryOperators: None
29+
# BreakBeforeConceptDeclarations: Allowed
30+
BreakBeforeConceptDeclarations: false
31+
BreakBeforeBraces: Attach
32+
BreakBeforeInheritanceComma: false
33+
BreakInheritanceList: AfterComma
34+
BreakBeforeTernaryOperators: false
35+
BreakConstructorInitializers: BeforeColon
36+
BreakStringLiterals: false
37+
ColumnLimit: 0
38+
CompactNamespaces: false
39+
ConstructorInitializerIndentWidth: 4
40+
ContinuationIndentWidth: 4
41+
Cpp11BracedListStyle: true
42+
DeriveLineEnding: false
43+
DerivePointerAlignment: false
44+
DisableFormat: false
45+
EmptyLineAfterAccessModifier: Never
46+
EmptyLineBeforeAccessModifier: Leave
47+
ExperimentalAutoDetectBinPacking: false
48+
FixNamespaceComments: false
49+
IncludeBlocks: Preserve
50+
IndentAccessModifiers: false
51+
IndentCaseLabels: false
52+
IndentCaseBlocks: true
53+
IndentGotoLabels: false
54+
IndentPPDirectives: None
55+
IndentExternBlock: AfterExternBlock
56+
IndentRequires: false
57+
IndentWidth: 4
58+
IndentWrappedFunctionNames: false
59+
InsertTrailingCommas: Wrapped
60+
KeepEmptyLinesAtTheStartOfBlocks: true
61+
LambdaBodyIndentation: OuterScope
62+
MaxEmptyLinesToKeep: 2
63+
NamespaceIndentation: None
64+
PenaltyBreakAssignment: 2
65+
PenaltyBreakBeforeFirstCallParameter: 19
66+
PenaltyBreakComment: 300
67+
PenaltyBreakFirstLessLess: 120
68+
PenaltyBreakString: 1000
69+
PenaltyBreakTemplateDeclaration: 10
70+
PenaltyExcessCharacter: 1000000
71+
PenaltyReturnTypeOnItsOwnLine: 60
72+
PenaltyIndentedWhitespace: 0
73+
PointerAlignment: Right
74+
PPIndentWidth: -1
75+
ReferenceAlignment: Pointer
76+
ReflowComments: false
77+
ShortNamespaceLines: 1
78+
SortIncludes: CaseSensitive
79+
SortUsingDeclarations: false
80+
SpaceAfterCStyleCast: true
81+
SpaceAfterLogicalNot: false
82+
SpaceAfterTemplateKeyword: false
83+
SpaceAroundPointerQualifiers: Default
84+
SpaceBeforeAssignmentOperators: true
85+
SpaceBeforeCaseColon: false
86+
SpaceBeforeCpp11BracedList: true
87+
SpaceBeforeCtorInitializerColon: true
88+
SpaceBeforeInheritanceColon: true
89+
SpaceBeforeParens: ControlStatements
90+
SpaceBeforeRangeBasedForLoopColon: true
91+
SpaceBeforeSquareBrackets: false
92+
SpaceInEmptyBlock: false
93+
SpaceInEmptyParentheses: false
94+
SpacesBeforeTrailingComments: 1
95+
SpacesInAngles: Never
96+
SpacesInCStyleCastParentheses: false
97+
SpacesInConditionalStatement: false
98+
SpacesInContainerLiterals: false
99+
SpacesInLineCommentPrefix:
100+
Minimum: 1
101+
Maximum: -1
102+
SpacesInParentheses: false
103+
SpacesInSquareBrackets: false
104+
Standard: Latest
105+
TabWidth: 4
106+
UseCRLF: false
107+
UseTab: AlignWithSpaces
108+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
109+
# PackConstructorInitializers: CurrentLine
110+
...
111+

scripts/format-code.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env sh
2+
3+
git ls-files| grep -E '.*\.[ch]pp'| xargs clang-format -style=file -i
4+
5+
# return only with EXIT_SUCCESS if there were no changes
6+
# otherwise show the changes and return with error code
7+
STATUS="$(git status -s)"
8+
if [ -n "$STATUS" ]; then
9+
git --no-pager diff && false
10+
fi

src/Models/path_model.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
11
#include "path_model.hpp"
22
#include <bits/ranges_algo.h>
33

4-
PathModel::PathModel(QObject* parent) {
4+
PathModel::PathModel(QObject *parent) {
55
paths = PathRegistry::get()->paths;
66
connect(PathRegistry::get(), &PathRegistry::pathAdded, this, &PathModel::add_path);
77
}
88

9-
int PathModel::rowCount(const QModelIndex&) const {
9+
int PathModel::rowCount(const QModelIndex &) const {
1010
return paths.size();
1111
}
1212

13-
QVariant PathModel::data(const QModelIndex& index, int role) const {
14-
const auto& p = paths[index.row()];
13+
QVariant PathModel::data(const QModelIndex &index, int role) const {
14+
const auto &p = paths[index.row()];
1515
switch (role) {
16-
case PathRole: return QString::fromStdString(p.path);
17-
case UriRole: return QString::fromStdString(p.get_uri());
18-
case UsedRole: return p.used;
19-
case ThumbnailRole: return p.thumbnail;
20-
case ExistsRole: return p.exists;
21-
default: return QVariant();
16+
case PathRole:
17+
return QString::fromStdString(p.path);
18+
case UriRole:
19+
return QString::fromStdString(p.get_uri());
20+
case UsedRole:
21+
return p.used;
22+
case ThumbnailRole:
23+
return p.thumbnail;
24+
case ExistsRole:
25+
return p.exists;
26+
default:
27+
return QVariant();
2228
};
2329
}
2430

@@ -33,13 +39,13 @@ void PathModel::taint_used(int i) {
3339
}
3440

3541
void PathModel::taint_all_used() {
36-
std::ranges::for_each(paths, [&](auto& p){ p.used = true; });
42+
std::ranges::for_each(paths, [&](auto &p) { p.used = true; });
3743
emit dataChanged(index(0, 0), index(paths.size() - 1, 0));
3844
check_should_quit();
3945
}
4046

4147
void PathModel::refresh_folded_paths() {
42-
folded_uri_list = std::accumulate(paths.cbegin(), paths.cend(), QString(), [&](QString s, const auto p){ return s.append(QString::fromStdString(p.get_uri()) + "\n"); });
48+
folded_uri_list = std::accumulate(paths.cbegin(), paths.cend(), QString(), [&](QString s, const auto p) { return s.append(QString::fromStdString(p.get_uri()) + "\n"); });
4349
emit foldedUriListChanged(folded_uri_list);
4450
}
4551

@@ -51,7 +57,7 @@ void PathModel::add_path(Path p) {
5157

5258
void PathModel::check_should_quit() {
5359
const auto quit = Settings::get()->auto_quit_behavior;
54-
if (quit == Settings::AutoQuitBehavior::First || (quit == Settings::AutoQuitBehavior::All && std::ranges::all_of(paths, [](auto p){ return p.used; }))) {
60+
if (quit == Settings::AutoQuitBehavior::First || (quit == Settings::AutoQuitBehavior::All && std::ranges::all_of(paths, [](auto p) { return p.used; }))) {
5561
Backend::get()->quit_delayed();
5662
}
5763
}

src/Models/path_model.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#pragma once
22

3-
#include <vector>
4-
#include <qqml.h>
53
#include <QAbstractListModel>
4+
#include <qqml.h>
5+
#include <vector>
66

7+
#include "backend.hpp"
78
#include "path.hpp"
89
#include "path_registry.hpp"
910
#include "settings.hpp"
10-
#include "backend.hpp"
1111

1212
class PathModel : public QAbstractListModel {
1313
Q_OBJECT
@@ -16,10 +16,10 @@ class PathModel : public QAbstractListModel {
1616

1717
Q_PROPERTY(QString foldedUriList MEMBER folded_uri_list NOTIFY foldedUriListChanged)
1818
public:
19-
PathModel(QObject* parent = nullptr);
19+
PathModel(QObject *parent = nullptr);
2020

21-
virtual int rowCount(const QModelIndex&) const override;
22-
virtual QVariant data(const QModelIndex& index, int role) const override;
21+
virtual int rowCount(const QModelIndex &) const override;
22+
virtual QVariant data(const QModelIndex &index, int role) const override;
2323
virtual QHash<int, QByteArray> roleNames() const override;
2424

2525
Q_INVOKABLE void taint_used(int i);

src/Util/util.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#pragma once
22

33
#define SINGLETON(TYPE) \
4-
static TYPE* get() { \
4+
static TYPE *get() { \
55
static TYPE s; \
66
return &s; \
77
}
88

99
#define STRICT_SINGLETON(TYPE) \
1010
TYPE() = delete; \
1111
explicit TYPE(bool singleton_constructor) {}; \
12-
static TYPE* get() { \
12+
static TYPE *get() { \
1313
static TYPE s {true}; \
1414
return &s; \
1515
}

src/backend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "backend.hpp"
22

33
void Backend::quit_delayed() {
4-
QTimer::singleShot(10, [](){ QCoreApplication::quit(); });
4+
QTimer::singleShot(10, []() { QCoreApplication::quit(); });
55
}

src/getopts.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,22 @@
44

55
namespace Getopts {
66

7-
bool parse(QCoreApplication& app) {
7+
bool parse(QCoreApplication &app) {
88
QCommandLineParser p;
99
p.setApplicationDescription("Quickly drag and drop files from the terminal to applications.");
1010
p.addHelpOption();
1111
p.addVersionOption();
1212

13-
QCommandLineOption auto_quit_opt(QStringList() << "x" << "auto-quit", "Whether to autoquit after a drag is finished. 0 = disable, 1 = after first drag, 2 (default) = after all paths have been used", "number");
14-
QCommandLineOption no_ontop_opt(QStringList() << "t" << "no-ontop", "Do not keep the window on top of other windows");
15-
QCommandLineOption keep_opt(QStringList() << "k" << "keep", "Keep dropped files around in sink mode.");
13+
QCommandLineOption auto_quit_opt(QStringList() << "x"
14+
<< "auto-quit",
15+
"Whether to autoquit after a drag is finished. 0 = disable, 1 = after first drag, 2 (default) = after all paths have been used",
16+
"number");
17+
QCommandLineOption no_ontop_opt(QStringList() << "t"
18+
<< "no-ontop",
19+
"Do not keep the window on top of other windows");
20+
QCommandLineOption keep_opt(QStringList() << "k"
21+
<< "keep",
22+
"Keep dropped files around in sink mode.");
1623

1724
p.addOptions({auto_quit_opt, no_ontop_opt, keep_opt});
1825
p.process(app);
@@ -37,7 +44,7 @@ bool parse(QCoreApplication& app) {
3744
Settings::get()->keep_dropped_files = true;
3845
}
3946
// add all trailing arguments to the path list
40-
std::ranges::for_each(p.positionalArguments(), [](auto i){ PathRegistry::get()->add_path(i.toStdString()); });
47+
std::ranges::for_each(p.positionalArguments(), [](auto i) { PathRegistry::get()->add_path(i.toStdString()); });
4148
return true;
4249
}
4350

src/getopts.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#pragma once
22

3-
#include <iostream>
43
#include <QCommandLineParser>
4+
#include <iostream>
55

66
#include "path_registry.hpp"
77
#include "settings.hpp"
88

99
namespace Getopts {
10-
bool parse(QCoreApplication& app);
10+
bool parse(QCoreApplication &app);
1111
}

src/main.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
#include <QGuiApplication>
2-
#include <QQmlApplicationEngine>
3-
#include <QQuickStyle>
42
#include <QIcon>
3+
#include <QQmlApplicationEngine>
54
#include <QQmlContext>
5+
#include <QQuickStyle>
66

77
#include "getopts.hpp"
88

9-
int main(int argc, char* argv[])
10-
{
9+
int main(int argc, char *argv[]) {
1110
QCoreApplication::setOrganizationName("blobdrop");
1211
QCoreApplication::setApplicationName("blobdrop");
1312
QQuickStyle::setStyle(QLatin1String("Material"));
14-
constexpr const char* materialVariantName = "QT_QUICK_CONTROLS_MATERIAL_VARIANT";
13+
constexpr const char *materialVariantName = "QT_QUICK_CONTROLS_MATERIAL_VARIANT";
1514
if (!qEnvironmentVariableIsSet(materialVariantName)) {
1615
// dense Material style, more suited for desktop targets
1716
qputenv(materialVariantName, "Dense");

src/path.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#include "path.hpp"
22

3-
Path::Path(const std::string& p) : path(std::filesystem::absolute(p)) {
3+
Path::Path(const std::string &p)
4+
: path(std::filesystem::absolute(p)) {
45
try {
56
exists = std::filesystem::exists(path);
6-
} catch(const std::filesystem::filesystem_error& ex) {
7+
} catch (const std::filesystem::filesystem_error &ex) {
78
std::cerr << ex.what() << std::endl;
89
}
910
}

0 commit comments

Comments
 (0)