-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.h
204 lines (159 loc) · 4.61 KB
/
types.h
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#pragma once
#include <string>
#include <stdexcept>
#include <QDebug>
#include <QString>
#include <QFileInfo>
#include <QDateTime>
#include <QVariant>
#include <QMetaObject>
#include <QMetaEnum>
#include <boost/concept_check.hpp>
#include "3rdparty/qtwebdav/webdav_url_info.h"
struct UrlInfo : public QUrlInfo {
UrlInfo() {check();};
UrlInfo(const UrlInfo& other) : QUrlInfo(other) {check();}
UrlInfo(const QUrlInfo& info) : QUrlInfo(info) {check();}
UrlInfo(const QFileInfo& info)
: QUrlInfo(
info.absoluteFilePath(),
info.permissions(), info.owner(), info.group(),
info.size(), info.lastModified().toUTC(), info.lastRead().toUTC(),
info.isDir(), info.isFile(), info.isSymLink(),
info.isWritable(), info.isReadable(), info.isExecutable()
)
{
check();
}
UrlInfo(const QVariantMap& data) {
setName(data["name"].toString());
setLastModified(data["lastModified"].toDateTime());
setPermissions(data["permissions"].value<int>());
setSize(data["size"].value<quint64>());
}
inline QVariantMap dump() const {
QVariantMap data;
data["name"] = name();
data["lastModified"] = lastModified();
data["permissions"] = static_cast<int>(permissions());
data["size"] = size();
return data;
}
bool empty() const {
return (lastModified() == QDateTime()) || (size() == -1);
}
bool ready() const {
return (lastModified() != QDateTime()) && (size() != -1) && (permissions() != 0);
}
private:
void check() {
if (isDir() && !name().endsWith("/")) {
setName(name() + "/");
}
}
};
/// describes action needed to perform
class action_t {
Q_GADGET
Q_ENUMS(type_e)
public:
typedef int TypeMask;
enum type_e {
error = 0,
upload = 1 << 0,
download = 1 << 1,
compare = 1 << 2,
forgot = 1 << 3,
remove_local = 1 << 4,
remove_remote = 1 << 5,
local_changed = 1 << 6,
remote_changed= 1 << 7,
unchanged = 1 << 8,
conflict = 1 << 9,
upload_dir = 1 << 10,
download_dir = 1 << 11,
} type;
static QString type_text(type_e t) {
QMetaEnum e = action_t::staticMetaObject.enumerator(action_t::staticMetaObject.indexOfEnumerator("type_e"));
return e.valueToKey(t);
}
QString type_text() const {
return action_t::type_text(type);
}
action_t(type_e t, const QString& key, const UrlInfo& l = UrlInfo(), const UrlInfo& r = UrlInfo())
: type(t), key(key), local(l), remote(r)
{}
action_t() {}
inline bool empty() const {return key.isEmpty();}
inline bool operator==(const action_t& other) const {
return type == other.type && key == other.key;
}
QString key;
UrlInfo local;
UrlInfo remote;
};
struct conflict_ctx {
const action_t action;
QString local_file;
QString remote_file;
QString result_file;
};
inline QDebug operator<<(QDebug dbg, const action_t &a)
{
dbg.nospace() << "#action_t(" << "type:" << a.type_text() << ":" << a.key << ")";
return dbg.space();
}
inline QDebug operator<<(QDebug dbg, const QFile::Permissions &perms)
{
dbg.nospace() << "#Permissions(" << static_cast<int>(perms) << ")";
return dbg.space();
}
struct connection_t {
QString schema;
QString host;
quint32 port;
QString login;
QString password;
};
typedef QList<action_t> Actions;
class qt_exception_t : public std::runtime_error
{
const QString msg;
public:
explicit qt_exception_t(const QString& msg)
: std::runtime_error(msg.toLocal8Bit().constData())
, msg(msg) {}
~qt_exception_t() throw() {};
const QString& message() const {return msg;}
};
class ne_exception_t : public std::runtime_error
{
const int code_;
const QString msg_;
public:
explicit ne_exception_t(int code, const QString& msg)
: std::runtime_error(msg.toLocal8Bit().constData())
, code_(code), msg_(msg) {}
~ne_exception_t() throw() {};
const QString& message() const {return msg_;}
int code() const {return code_;}
};
class Package : public QObject {
Q_OBJECT
public:
template <typename F>
Package(QObject* recepient, const F& func, Qt::ConnectionType type = Qt::QueuedConnection)
: func_(func)
{
moveToThread(recepient->thread());
QMetaObject::invokeMethod(this, "fire", type);
}
virtual ~Package() {};
private:
Q_SLOT void fire()
{
if (func_) func_();
deleteLater();
}
std::function<void()> func_;
};