FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sqlitebrowser/src/RemoteLocalFilesModel.cpp at master · PeterDaveHello/sqlitebrowser · GitHub
PeterDaveHello
/
sqlitebrowser
Public
forked from
sqlitebrowser/sqlitebrowser
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
sqlitebrowser
/
src
/
RemoteLocalFilesModel.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
191 lines (159 loc) · 5.84 KB
Breadcrumbs
sqlitebrowser
/
src
/
RemoteLocalFilesModel.cpp
Copy path
File metadata and controls
191 lines (159 loc) · 5.84 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
include
<
QFile
>
#
include
<
QFileInfo
>
#
include
<
QImage
>
#
include
<
QTreeWidgetItem
>
#
include
<
QUrl
>
#
include
"
Data.h
"
#
include
"
RemoteDatabase.h
"
#
include
"
RemoteLocalFilesModel.h
"
#
include
"
RemoteNetwork.h
"
#
include
"
Settings.h
"
using
json = nlohmann::json;
RemoteLocalFilesModel::RemoteLocalFilesModel
(QObject* parent, RemoteDatabase& remote) :
QAbstractItemModel(parent),
remoteDatabase(remote)
{
QStringList header;
header <<
tr
(
"
Name
"
) <<
tr
(
"
Branch
"
) <<
tr
(
"
Last modified
"
) <<
tr
(
"
Size
"
) <<
tr
(
"
Commit
"
) <<
tr
(
"
File
"
);
rootItem =
new
QTreeWidgetItem
(header);
}
RemoteLocalFilesModel::~RemoteLocalFilesModel
()
{
delete
rootItem;
}
void
RemoteLocalFilesModel::setIdentity
(
const
QString& cert_filename)
{
current_cert_filename = cert_filename;
current_user_name =
RemoteNetwork::get
().
getInfoFromClientCert
(cert_filename, RemoteNetwork::CertInfoUser);
refresh
();
}
void
RemoteLocalFilesModel::refresh
()
{
beginResetModel
();
//
Remove all data except for the root item
while
(rootItem->
childCount
())
delete
rootItem->
child
(
0
);
//
Get list of locally checked out databases
auto
files = remoteDatabase.
localGetLocalFiles
(current_cert_filename);
//
Loop through that list
for
(
const
auto
& file : files)
{
QString user_name = file.
user_name
();
//
Check if there is already a node for this user
QTreeWidgetItem* user_node =
nullptr
;
for
(
int
i=
0
;i<rootItem->
childCount
();i++)
{
if
(rootItem->
child
(i)->
text
(ColumnName) == user_name)
{
user_node = rootItem->
child
(i);
break
;
}
}
//
If there is no node for this user yet create one
if
(user_node ==
nullptr
)
{
user_node =
new
QTreeWidgetItem
(rootItem);
user_node->
setText
(ColumnName, user_name);
user_node->
setIcon
(ColumnName,
QIcon
(user_name == current_user_name ?
"
:/icons/folder_user
"
:
"
:/icons/folder
"
));
}
//
Get file information
QFile
file_info
(
Settings::getValue
(
"
remote
"
,
"
clonedirectory
"
).
toString
() +
"
/
"
+
QString::fromStdString
(file.
file
));
//
Add file to user node
QTreeWidgetItem* file_node =
new
QTreeWidgetItem
(user_node);
file_node->
setText
(ColumnName,
QString::fromStdString
(file.
name
));
file_node->
setIcon
(ColumnName,
QIcon
(
"
:/icons/database
"
));
file_node->
setText
(ColumnBranch,
QString::fromStdString
(file.
branch
));
file_node->
setText
(ColumnLastModified,
QLocale::system
().
toString
(
QFileInfo
(file_info).
lastModified
().
toLocalTime
(), QLocale::ShortFormat));
file_node->
setText
(ColumnSize,
humanReadableSize
(
static_cast
<
unsigned
long
>(file_info.
size
())));
file_node->
setText
(ColumnCommit,
QString::fromStdString
(file.
commit_id
));
file_node->
setText
(ColumnFile,
QString::fromStdString
(file.
file
));
}
//
Refresh the view
endResetModel
();
}
QModelIndex
RemoteLocalFilesModel::index
(
int
row,
int
column,
const
QModelIndex& parent)
const
{
if
(!
hasIndex
(row, column, parent))
return
QModelIndex
();
QTreeWidgetItem *parentItem;
if
(!parent.
isValid
())
parentItem = rootItem;
else
parentItem =
static_cast
<QTreeWidgetItem*>(parent.
internalPointer
());
QTreeWidgetItem* childItem = parentItem->
child
(row);
if
(childItem)
return
createIndex
(row, column, childItem);
else
return
QModelIndex
();
}
QModelIndex
RemoteLocalFilesModel::parent
(
const
QModelIndex& index)
const
{
if
(!index.
isValid
())
return
QModelIndex
();
QTreeWidgetItem* childItem =
static_cast
<QTreeWidgetItem*>(index.
internalPointer
());
QTreeWidgetItem* parentItem = childItem->
parent
();
if
(parentItem == rootItem)
return
QModelIndex
();
else
return
createIndex
(
0
,
0
, parentItem);
}
QVariant
RemoteLocalFilesModel::data
(
const
QModelIndex& index,
int
role)
const
{
if
(!index.
isValid
())
return
QVariant
();
//
Get the item the index points at
QTreeWidgetItem* item =
static_cast
<QTreeWidgetItem*>(index.
internalPointer
());
//
Return data depending on the role
switch
(role)
{
case
Qt::DisplayRole:
case
Qt::EditRole:
return
item->
text
(index.
column
());
case
Qt::DecorationRole:
return
item->
icon
(index.
column
());
default
:
return
QVariant
();
}
}
QVariant
RemoteLocalFilesModel::headerData
(
int
section, Qt::Orientation orientation,
int
role)
const
{
//
Get the header string from the root item
if
(orientation == Qt::Horizontal && role == Qt::DisplayRole)
return
rootItem->
data
(section, role);
return
QVariant
();
}
int
RemoteLocalFilesModel::rowCount
(
const
QModelIndex& parent)
const
{
if
(parent.
column
() >
0
)
return
0
;
if
(!parent.
isValid
())
return
rootItem->
childCount
();
else
return
static_cast
<QTreeWidgetItem*>(parent.
internalPointer
())->
childCount
();
}
int
RemoteLocalFilesModel::columnCount
(
const
QModelIndex&
/*
parent
*/
)
const
{
return
rootItem->
columnCount
();
}
bool
RemoteLocalFilesModel::removeRows
(
int
row,
int
count,
const
QModelIndex& parent)
{
for
(
int
i=
0
;i<count;i++)
remoteDatabase.
localDeleteFile
(
index
(row + i, ColumnFile, parent).
data
().
toString
());
//
Remove rows from view
beginRemoveRows
(parent, row, row + count -
1
);
for
(
int
i=count-
1
;i>=
0
;i--)
{
auto
item =
static_cast
<QTreeWidgetItem*>(
index
(row + i,
0
, parent).
internalPointer
());
item->
parent
()->
removeChild
(item);
}
endRemoveRows
();
//
If parent node is empty, remove that one too. Make sure to not remove the root node
if
(parent.
isValid
() && !
index
(
0
,
0
, parent).
isValid
())
{
beginRemoveRows
(parent.
parent
(),
0
,
0
);
auto
item =
static_cast
<QTreeWidgetItem*>(parent.
internalPointer
());
item->
parent
()->
removeChild
(item);
endRemoveRows
();
}
return
true
;
}
Back
|
FazBrowse Home
|
New Git URL