-
Notifications
You must be signed in to change notification settings - Fork 671
/
Copy pathSyncConnectionWizard.py
377 lines (346 loc) · 12.4 KB
/
SyncConnectionWizard.py
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
import names
import squish
import object
from os import path
from helpers.SetupClientHelper import (
getCurrentUserSyncPath,
setCurrentUserSyncPath,
)
from helpers.ConfigHelper import get_config
class SyncConnectionWizard:
ADD_FOLDER_SYNC_CONNECTION_WIZARD = {
"name": "FolderWizardSourcePage",
"type": "OCC::FolderWizardLocalPath",
"visible": 1,
"window": names.add_Folder_Sync_Connection_OCC_FolderWizard,
}
CHOOSE_LOCAL_SYNC_FOLDER = {
"name": "localFolderLineEdit",
"type": "QLineEdit",
"visible": 1,
"window": names.add_Folder_Sync_Connection_OCC_FolderWizard,
}
BACK_BUTTON = {
"window": names.add_Folder_Sync_Connection_OCC_FolderWizard,
"type": "QPushButton",
"text": "< &Back",
"visible": 1,
}
NEXT_BUTTON = {
"window": names.add_Folder_Sync_Connection_OCC_FolderWizard,
"type": "QPushButton",
"text": "&Next >",
"visible": 1,
}
SELECTIVE_SYNC_ROOT_FOLDER = {
"column": 0,
"container": names.add_Folder_Sync_Connection_Deselect_remote_folders_you_do_not_wish_to_synchronize_QTreeWidget,
"text": "ownCloud",
"type": "QModelIndex",
}
SYNC_DIALOG_FOLDER_TREE = {
"column": 0,
"container": names.deselect_remote_folders_you_do_not_wish_to_synchronize_ownCloud_QModelIndex,
"type": "QModelIndex",
}
ADD_SYNC_CONNECTION_BUTTON = {
"name": "qt_wizard_finish",
"type": "QPushButton",
"visible": 1,
"window": names.add_Folder_Sync_Connection_OCC_FolderWizard,
}
REMOTE_FOLDER_TREE = {
"container": names.add_Folder_Sync_Connection_groupBox_QGroupBox,
"name": "folderTreeWidget",
"type": "QTreeWidget",
"visible": 1,
}
VFS_CHECKBOX = {
"text": "Use virtual files instead of downloading content immediately",
"type": "QCheckBox",
"unnamed": 1,
"visible": 1,
"window": names.add_Folder_Sync_Connection_OCC_FolderWizard,
}
SELECTIVE_SYNC_TREE_HEADER = {
"container": names.add_Folder_Sync_Connection_Deselect_remote_folders_you_do_not_wish_to_synchronize_QTreeWidget,
"orientation": 1,
"type": "QHeaderView",
"unnamed": 1,
"visible": 1,
}
CANCEL_FOLDER_SYNC_CONNECTION_WIZARD = {
"window": names.add_Folder_Sync_Connection_OCC_FolderWizard,
"name": "qt_wizard_cancel",
"type": "QPushButton",
"visible": 1,
}
SPACE_NAME_SELECTOR = {
"container": names.quickWidget_scrollView_ScrollView,
"type": "Label",
"visible": True,
}
CREATE_REMOTE_FOLDER_BUTTON = {
"container": names.add_Folder_Sync_Connection_groupBox_QGroupBox,
"name": "addFolderButton",
"type": "QPushButton",
"visible": 1,
}
CREATE_REMOTE_FOLDER_INPUT = {
"buddy": names.create_Remote_Folder_Enter_the_name_of_the_new_folder_to_be_created_below_QLabel,
"type": "QLineEdit",
"unnamed": 1,
"visible": 1,
}
CREATE_REMOTE_FOLDER_CONFIRM_BUTTON = {
"text": "OK",
"type": "QPushButton",
"unnamed": 1,
"visible": 1,
"window": names.create_Remote_Folder_QInputDialog,
}
REFRESH_BUTTON = {
"container": names.add_Folder_Sync_Connection_groupBox_QGroupBox,
"name": "refreshButton",
"type": "QPushButton",
"visible": 1,
}
REMOTE_FOLDER_SELECTION_INPUT = {
"name": "folderEntry",
"type": "QLineEdit",
"visible": 1,
"window": names.add_Folder_Sync_Connection_OCC_FolderWizard,
}
ADD_FOLDER_SYNC_BUTTON = {
"checkable": False,
"container": names.stackedWidget_quickWidget_OCC_QmlUtils_OCQuickWidget,
"id": "addSyncButton",
"type": "Button",
"unnamed": 1,
"visible": True,
}
WARN_LABEL = {
"window": names.add_Folder_Sync_Connection_OCC_FolderWizard,
"name": "warnLabel",
"type": "QLabel",
"visible": 1,
}
@staticmethod
def setSyncPathInSyncConnectionWizardOc10(sync_path=''):
squish.waitForObject(SyncConnectionWizard.ADD_FOLDER_SYNC_CONNECTION_WIZARD)
squish.waitForObject(SyncConnectionWizard.CHOOSE_LOCAL_SYNC_FOLDER).setText("")
if sync_path:
squish.type(SyncConnectionWizard.CHOOSE_LOCAL_SYNC_FOLDER, sync_path)
setCurrentUserSyncPath(sync_path)
else:
squish.type(
SyncConnectionWizard.CHOOSE_LOCAL_SYNC_FOLDER,
getCurrentUserSyncPath(),
)
SyncConnectionWizard.nextStep()
@staticmethod
def setSyncPathInSyncConnectionWizard(sync_path=''):
if get_config('ocis'):
SyncConnectionWizard.setSyncPathInSyncConnectionWizardOcis(sync_path)
else:
SyncConnectionWizard.setSyncPathInSyncConnectionWizardOc10(sync_path)
@staticmethod
def nextStep():
squish.clickButton(squish.waitForObject(SyncConnectionWizard.NEXT_BUTTON))
@staticmethod
def back():
squish.clickButton(squish.waitForObject(SyncConnectionWizard.BACK_BUTTON))
@staticmethod
def selectRemoteDestinationFolder(folder):
squish.mouseClick(
squish.waitForObjectItem(SyncConnectionWizard.REMOTE_FOLDER_TREE, folder)
)
SyncConnectionWizard.nextStep()
@staticmethod
def deselectAllRemoteFolders():
# NOTE: checkbox does not have separate object
# click on (11,11) which is a checkbox
squish.mouseClick(
squish.waitForObject(SyncConnectionWizard.SELECTIVE_SYNC_ROOT_FOLDER),
11,
11,
squish.Qt.NoModifier,
squish.Qt.LeftButton,
)
@staticmethod
def enableOrDisableVfsSupport(action='disable'):
if not action in ['enable', 'disable']:
raise Exception("Invalid action: " + action)
checked = squish.waitForObjectExists(SyncConnectionWizard.VFS_CHECKBOX).checked
is_enable = action == 'enable'
if is_enable == checked:
return
squish.clickButton(squish.waitForObject(SyncConnectionWizard.VFS_CHECKBOX))
@staticmethod
def selectFoldersToSync(folders):
# first deselect all
SyncConnectionWizard.deselectAllRemoteFolders()
for folder in folders:
folder_levels = folder.strip("/").split("/")
parent_selector = None
for sub_folder in folder_levels:
if not parent_selector:
SyncConnectionWizard.SYNC_DIALOG_FOLDER_TREE['text'] = sub_folder
parent_selector = SyncConnectionWizard.SYNC_DIALOG_FOLDER_TREE
selector = parent_selector
else:
selector = {
"column": '0',
"container": parent_selector,
"text": sub_folder,
"type": 'QModelIndex',
}
if (
len(folder_levels) == 1
or folder_levels.index(sub_folder) == len(folder_levels) - 1
):
# NOTE: checkbox does not have separate object
# click on (11,11) which is a checkbox to unselect the folder
squish.mouseClick(
squish.waitForObject(selector),
11,
11,
squish.Qt.NoModifier,
squish.Qt.LeftButton,
)
else:
squish.doubleClick(squish.waitForObject(selector))
@staticmethod
def sortBy(headerText):
squish.mouseClick(
squish.waitForObject(
{
"container": SyncConnectionWizard.SELECTIVE_SYNC_TREE_HEADER,
"text": headerText,
"type": "HeaderViewItem",
"visible": True,
}
)
)
@staticmethod
def addSyncConnection():
squish.clickButton(
squish.waitForObject(SyncConnectionWizard.ADD_SYNC_CONNECTION_BUTTON)
)
@staticmethod
def getItemNameFromRow(row_index):
FOLDER_ROW = {
"row": row_index,
"container": SyncConnectionWizard.SELECTIVE_SYNC_ROOT_FOLDER,
"type": "QModelIndex",
}
return str(squish.waitForObjectExists(FOLDER_ROW).displayText)
@staticmethod
def isRootFolderChecked():
state = squish.waitForObject(SyncConnectionWizard.SELECTIVE_SYNC_ROOT_FOLDER)[
"checkState"
]
return state == "checked"
@staticmethod
def cancelFolderSyncConnectionWizard():
squish.clickButton(
squish.waitForObject(
SyncConnectionWizard.CANCEL_FOLDER_SYNC_CONNECTION_WIZARD
)
)
@staticmethod
def selectSpaceToSync(spaceName):
selector = SyncConnectionWizard.SPACE_NAME_SELECTOR.copy()
selector["text"] = spaceName
squish.mouseClick(squish.waitForObject(selector))
@staticmethod
def setSyncPathInSyncConnectionWizardOcis(sync_path):
if not sync_path:
sync_path = path.join(
getCurrentUserSyncPath(), get_config("syncConnectionName")
)
squish.type(
squish.waitForObject(SyncConnectionWizard.CHOOSE_LOCAL_SYNC_FOLDER),
"<Ctrl+A>",
)
squish.type(
SyncConnectionWizard.CHOOSE_LOCAL_SYNC_FOLDER,
sync_path,
)
SyncConnectionWizard.nextStep()
@staticmethod
def syncSpace(spaceName):
SyncConnectionWizard.selectSpaceToSync(spaceName)
SyncConnectionWizard.nextStep()
SyncConnectionWizard.setSyncPathInSyncConnectionWizard(
path.join(getCurrentUserSyncPath(), spaceName)
)
SyncConnectionWizard.addSyncConnection()
@staticmethod
def create_folder_in_remote_destination(folder_name):
squish.clickButton(
squish.waitForObject(SyncConnectionWizard.CREATE_REMOTE_FOLDER_BUTTON)
)
squish.type(
squish.waitForObject(SyncConnectionWizard.CREATE_REMOTE_FOLDER_INPUT),
folder_name,
)
squish.clickButton(
squish.waitForObject(
SyncConnectionWizard.CREATE_REMOTE_FOLDER_CONFIRM_BUTTON
)
)
@staticmethod
def refresh_remote():
squish.clickButton(squish.waitForObject(SyncConnectionWizard.REFRESH_BUTTON))
@staticmethod
def generate_remote_folder_selector(folder_name, parent_container=None):
if not parent_container:
parent_container = {
"container": names.groupBox_folderTreeWidget_QTreeWidget,
"text": "ownCloud",
"type": "QModelIndex",
}
return {
"container": parent_container,
"text": folder_name,
"type": "QModelIndex",
}
@staticmethod
def has_remote_folder(folder_name):
folder_tree = folder_name.strip("/").split("/")
parent_container = None
for folder in folder_tree:
folder_selector = SyncConnectionWizard.generate_remote_folder_selector(
folder, parent_container
)
try:
if parent_container:
squish.doubleClick(parent_container)
squish.waitForObject(folder_selector)
parent_container = folder_selector
except:
return False, None
return True, parent_container
@staticmethod
def is_remote_folder_selected(folder_selector):
return squish.waitForObjectExists(folder_selector).selected
@staticmethod
def select_space_to_sync(space_name):
SyncConnectionWizard.selectSpaceToSync(space_name)
SyncConnectionWizard.nextStep()
@staticmethod
def open_sync_connection_wizard():
squish.mouseClick(
squish.waitForObject(SyncConnectionWizard.ADD_FOLDER_SYNC_BUTTON)
)
@staticmethod
def get_local_sync_path():
return str(
squish.waitForObjectExists(
SyncConnectionWizard.CHOOSE_LOCAL_SYNC_FOLDER
).displayText
)
@staticmethod
def get_warn_label():
return str(squish.waitForObjectExists(SyncConnectionWizard.WARN_LABEL).text)