1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | |
---|
4 | import gi |
---|
5 | gi.require_version('Gtk', '3.0') |
---|
6 | from gi.repository import Gtk, Pango, GdkPixbuf, Gdk, Gio, GObject,GLib |
---|
7 | |
---|
8 | import copy |
---|
9 | import gettext |
---|
10 | import Core |
---|
11 | |
---|
12 | import Dialog |
---|
13 | import time |
---|
14 | import threading |
---|
15 | import multiprocessing |
---|
16 | import sys |
---|
17 | import os |
---|
18 | import psutil |
---|
19 | |
---|
20 | import gettext |
---|
21 | gettext.textdomain('lliurex-gdrive') |
---|
22 | _ = gettext.gettext |
---|
23 | |
---|
24 | |
---|
25 | |
---|
26 | RSRC="/usr/share/lliurex-gdrive/" |
---|
27 | CSS_FILE="/usr/share/lliurex-gdrive/lliurex-gdrive.css" |
---|
28 | PROFILE_IMAGE=RSRC+"rsrc/profile.svg" |
---|
29 | FOLDER_IMAGE=RSRC+"rsrc/folder.svg" |
---|
30 | MOUNT_ON_IMAGE=RSRC+"rsrc/mount_on.svg" |
---|
31 | MOUNT_OFF_IMAGE=RSRC+"rsrc/mount_off.svg" |
---|
32 | EDIT_IMAGE=RSRC+"rsrc/edit.svg" |
---|
33 | DELETE_IMAGE=RSRC+"rsrc/trash.svg" |
---|
34 | MAX_RETRY_INTENTS=1200 |
---|
35 | |
---|
36 | |
---|
37 | class ProfileBox(Gtk.VBox): |
---|
38 | |
---|
39 | def __init__(self): |
---|
40 | |
---|
41 | Gtk.VBox.__init__(self) |
---|
42 | |
---|
43 | self.core=Core.Core.get_core() |
---|
44 | |
---|
45 | builder=Gtk.Builder() |
---|
46 | builder.set_translation_domain('lliurex-gdrive') |
---|
47 | ui_path=RSRC + "/rsrc/lliurex-gdrive.ui" |
---|
48 | builder.add_from_file(ui_path) |
---|
49 | |
---|
50 | self.stack = Gtk.Stack() |
---|
51 | self.stack.set_transition_duration(1000) |
---|
52 | self.stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT) |
---|
53 | |
---|
54 | self.main_box=builder.get_object("profile_data_box") |
---|
55 | self.profiles_list_label=builder.get_object("profiles_list_label") |
---|
56 | self.profile_list_box=builder.get_object("profile_list_box") |
---|
57 | self.profile_list_vp=builder.get_object("profile_list_viewport") |
---|
58 | self.msg_label=builder.get_object("msg_label") |
---|
59 | |
---|
60 | image = Gtk.Image() |
---|
61 | image.set_from_stock(Gtk.STOCK_ADD,Gtk.IconSize.MENU) |
---|
62 | |
---|
63 | self.add_new_profile_button=builder.get_object("add_new_profile_button") |
---|
64 | self.add_new_profile_button.set_image(image) |
---|
65 | self.new_profile_window=builder.get_object("new_profile_window") |
---|
66 | self.data=builder.get_object("data") |
---|
67 | self.edit_profile_box=builder.get_object("edit_profile_box") |
---|
68 | self.profile_label=builder.get_object("profile_label") |
---|
69 | self.profile_entry=builder.get_object("profile_entry") |
---|
70 | self.email_label=builder.get_object("email_label") |
---|
71 | self.email_entry=builder.get_object("email_entry") |
---|
72 | self.mountpoint_label=builder.get_object("mountpoint_label") |
---|
73 | self.mountpoint_entry=builder.get_object("mountpoint_entry") |
---|
74 | self.automount_label=builder.get_object("automount_label") |
---|
75 | self.automount_entry=builder.get_object("automount_entry") |
---|
76 | self.root_folder_param_label=builder.get_object("root_folder_param_label") |
---|
77 | self.root_folder_param_entry=builder.get_object("root_folder_param_entry") |
---|
78 | self.gdrive_folder_label=builder.get_object("gdrive_folder_label") |
---|
79 | self.gdrive_folder_entry=builder.get_object("gdrive_folder_entry") |
---|
80 | self.gdrive_folder_entry.set_width_chars(30) |
---|
81 | self.gdrive_folder_entry.set_max_width_chars(30) |
---|
82 | self.gdrive_folder_entry.set_xalign(-1) |
---|
83 | self.gdrive_folder_entry.set_ellipsize(Pango.EllipsizeMode.START) |
---|
84 | self.edit_gdrive_folder_button=builder.get_object("edit_gdrive_folder_button") |
---|
85 | |
---|
86 | self.profile_msg=builder.get_object("profile_msg") |
---|
87 | self.profile_pbar=builder.get_object("profile_pbar") |
---|
88 | self.accept_add_profile_button=builder.get_object("accept_add_profile_button") |
---|
89 | self.cancel_add_profile_button=builder.get_object("cancel_add_profile_button") |
---|
90 | |
---|
91 | self.gdrive_combobox_box=builder.get_object("gdrive_combobox_box") |
---|
92 | self.gdrive_combobox_label=builder.get_object("gdrive_combobox_label") |
---|
93 | self.gdrive_combobox=builder.get_object("gdrive_combobox") |
---|
94 | self.return_combobox_button=builder.get_object("return_combobox_button") |
---|
95 | |
---|
96 | |
---|
97 | self.syncfolders_model=Gtk.ListStore(str) |
---|
98 | rende=Gtk.CellRendererText() |
---|
99 | rende.set_property("ellipsize-set",True) |
---|
100 | rende.set_property("ellipsize",Pango.EllipsizeMode.START) |
---|
101 | rende.set_property("width-chars",65) |
---|
102 | rende.set_property("max-width-chars",65) |
---|
103 | self.gdrive_combobox.set_model(self.syncfolders_model) |
---|
104 | self.gdrive_combobox.pack_start(rende,False) |
---|
105 | self.gdrive_combobox.add_attribute(rende,"text",0) |
---|
106 | |
---|
107 | self.gdrive_combobox.set_active(0) |
---|
108 | |
---|
109 | self.pack_start(self.main_box,True,True,0) |
---|
110 | self.connect_signals() |
---|
111 | self.set_css_info() |
---|
112 | self.stack.show() |
---|
113 | self.stack.add_titled(self.edit_profile_box,"edit","Edit") |
---|
114 | self.stack.add_titled(self.gdrive_combobox_box,"folder", "Folder") |
---|
115 | self.data.pack_start(self.stack,True,False,5) |
---|
116 | |
---|
117 | self.data.pack_start(self.edit_profile_box,True,True,0) |
---|
118 | |
---|
119 | |
---|
120 | self.current_status={} |
---|
121 | self.edition=False |
---|
122 | self.root_folder=False |
---|
123 | self.read=False |
---|
124 | self.profile_pbar.hide() |
---|
125 | |
---|
126 | self.init_threads() |
---|
127 | self.check_initial_connection() |
---|
128 | |
---|
129 | |
---|
130 | #def __init__ |
---|
131 | |
---|
132 | def init_threads(self): |
---|
133 | |
---|
134 | self.create_profile_t=multiprocessing.Process(target=self.create_profile) |
---|
135 | self.create_mountpoint_t=threading.Thread(target=self.create_mountpoint) |
---|
136 | self.edit_profile_t=threading.Thread(target=self.edit_profile) |
---|
137 | self.check_connection_t=threading.Thread(target=self.check_connection) |
---|
138 | self.read_mountpoint_t=threading.Thread(target=self.read_mountpoint) |
---|
139 | self.check_form_t=threading.Thread(target=self.check_form) |
---|
140 | |
---|
141 | |
---|
142 | self.create_profile_t.daemon=True |
---|
143 | self.create_mountpoint_t.daemon=True |
---|
144 | self.edit_profile_t.daemon=True |
---|
145 | self.check_connection_t.daemon=True |
---|
146 | self.read_mountpoint_t.daemon=True |
---|
147 | self.check_form_t.daemon=True |
---|
148 | |
---|
149 | self.create_mountpoint_t.done=False |
---|
150 | self.edit_profile_t.done=False |
---|
151 | self.read_mountpoint_t.done=False |
---|
152 | self.check_form_t.done=False |
---|
153 | |
---|
154 | self.create_profile_t.launched=False |
---|
155 | self.create_mountpoint_t.launched=False |
---|
156 | self.edit_profile_t.launched=False |
---|
157 | self.read_mountpoint_t.launched=False |
---|
158 | self.check_form_t.launched=False |
---|
159 | |
---|
160 | |
---|
161 | GObject.threads_init() |
---|
162 | |
---|
163 | #def init_threads |
---|
164 | |
---|
165 | def set_css_info(self): |
---|
166 | |
---|
167 | self.style_provider=Gtk.CssProvider() |
---|
168 | |
---|
169 | f=Gio.File.new_for_path(CSS_FILE) |
---|
170 | self.style_provider.load_from_file(f) |
---|
171 | |
---|
172 | Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(),self.style_provider,Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) |
---|
173 | self.profiles_list_label.set_name("OPTION_LABEL") |
---|
174 | self.profile_label.set_name("OPTION_LABEL") |
---|
175 | self.email_label.set_name("OPTION_LABEL") |
---|
176 | self.mountpoint_label.set_name("OPTION_LABEL") |
---|
177 | self.automount_label.set_name("OPTION_LABEL") |
---|
178 | self.msg_label.set_name("MSG_LABEL") |
---|
179 | self.profile_msg.set_name("MSG_LABEL") |
---|
180 | self.root_folder_param_label.set_name("OPTION_LABEL") |
---|
181 | self.gdrive_combobox_label.set_name("OPTION_LABEL") |
---|
182 | self.gdrive_folder_label.set_name("OPTION_LABEL") |
---|
183 | self.gdrive_folder_entry.set_name("GDRIVE_FOLDER") |
---|
184 | |
---|
185 | |
---|
186 | #def set-css_info |
---|
187 | |
---|
188 | |
---|
189 | def connect_signals(self): |
---|
190 | |
---|
191 | self.add_new_profile_button.connect("clicked",self.add_new_profile_button_clicked) |
---|
192 | self.accept_add_profile_button.connect("clicked",self.accept_add_profile_clicked) |
---|
193 | self.cancel_add_profile_button.connect("clicked",self.cancel_add_profile_clicked) |
---|
194 | self.new_profile_window.connect("delete_event",self.hide_window) |
---|
195 | self.mountpoint_entry.connect("file-set",self.check_mountpoint_folder) |
---|
196 | self.gdrive_combobox.connect("changed",self.on_gdrive_combobox_changed) |
---|
197 | self.root_folder_param_entry.connect("notify::active",self.root_folder_clicked) |
---|
198 | self.return_combobox_button.connect("clicked",self.return_combobox_button_clicked) |
---|
199 | self.edit_gdrive_folder_button.connect("clicked",self.edit_gdrive_folder_button_clicked) |
---|
200 | |
---|
201 | |
---|
202 | #def connect_signals |
---|
203 | |
---|
204 | |
---|
205 | def check_initial_connection(self): |
---|
206 | |
---|
207 | self.initial_connection=self.core.LliurexGoogleDriveManager.check_google_connection() |
---|
208 | |
---|
209 | return |
---|
210 | |
---|
211 | #def check_initial_connection |
---|
212 | |
---|
213 | def load_info(self,info): |
---|
214 | |
---|
215 | self.profiles_info=info |
---|
216 | for item in self.profiles_info: |
---|
217 | profile=item |
---|
218 | email=self.profiles_info[item]["email"] |
---|
219 | mountpoint=self.profiles_info[item]["mountpoint"] |
---|
220 | self.new_profile_button(profile,email,mountpoint) |
---|
221 | |
---|
222 | |
---|
223 | #def load_info() |
---|
224 | |
---|
225 | def hide_window(self,widget,event): |
---|
226 | |
---|
227 | widget.hide() |
---|
228 | return True |
---|
229 | |
---|
230 | #def hide_window |
---|
231 | |
---|
232 | def init_profile_dialog_button(self): |
---|
233 | |
---|
234 | self.accept_add_profile_button.show() |
---|
235 | image = Gtk.Image() |
---|
236 | image.set_from_stock(Gtk.STOCK_CANCEL,Gtk.IconSize.MENU) |
---|
237 | self.cancel_add_profile_button.set_image(image) |
---|
238 | self.cancel_add_profile_button.set_label(_("Cancel")) |
---|
239 | self.cancel_add_profile_button.show() |
---|
240 | |
---|
241 | #def init_profile_dialog_button |
---|
242 | |
---|
243 | def disable_entry_profile_dialog(self): |
---|
244 | |
---|
245 | self.profile_entry.set_sensitive(False) |
---|
246 | self.email_entry.set_sensitive(False) |
---|
247 | self.mountpoint_entry.set_sensitive(False) |
---|
248 | self.automount_entry.set_sensitive(False) |
---|
249 | self.root_folder_param_entry.set_sensitive(False) |
---|
250 | self.edit_gdrive_folder_button.set_sensitive(False) |
---|
251 | |
---|
252 | #def disable_entry_profile_dialog |
---|
253 | |
---|
254 | def enable_entry_profile_dialog(self): |
---|
255 | |
---|
256 | if not self.edition: |
---|
257 | |
---|
258 | self.new_profile_window.set_title(_("Create new profile")) |
---|
259 | self.profile_entry.set_sensitive(True) |
---|
260 | self.profile_entry.grab_focus() |
---|
261 | self.email_entry.set_sensitive(True) |
---|
262 | self.root_folder_param_entry.hide() |
---|
263 | self.root_folder_param_label.hide() |
---|
264 | self.gdrive_folder_label.hide() |
---|
265 | self.gdrive_folder_entry.hide() |
---|
266 | self.edit_gdrive_folder_button.hide() |
---|
267 | |
---|
268 | else: |
---|
269 | self.new_profile_window .set_title(_("Edit profile")) |
---|
270 | self.profile_entry.set_sensitive(False) |
---|
271 | self.email_entry.set_sensitive(False) |
---|
272 | self.root_folder_param_label.show() |
---|
273 | self.root_folder_param_entry.show() |
---|
274 | self.root_folder_param_entry.set_sensitive(True) |
---|
275 | |
---|
276 | if self.root_folder: |
---|
277 | self.edit_gdrive_folder_button.show() |
---|
278 | self.edit_gdrive_folder_button.set_sensitive(True) |
---|
279 | else: |
---|
280 | if self.read: |
---|
281 | self.edit_gdrive_folder_button.show() |
---|
282 | self.edit_gdrive_folder_button.set_sensitive(True) |
---|
283 | |
---|
284 | self.mountpoint_entry.set_sensitive(True) |
---|
285 | self.automount_entry.set_sensitive(True) |
---|
286 | |
---|
287 | #def enable_entry_profile_dialog |
---|
288 | |
---|
289 | def change_cancel_button(self): |
---|
290 | |
---|
291 | image = Gtk.Image() |
---|
292 | image.set_from_stock(Gtk.STOCK_CLOSE,Gtk.IconSize.MENU) |
---|
293 | self.cancel_add_profile_button.set_image(image) |
---|
294 | self.cancel_add_profile_button.set_label(_("Close")) |
---|
295 | self.cancel_add_profile_button.show() |
---|
296 | |
---|
297 | #def change_cancel_button |
---|
298 | |
---|
299 | def add_new_profile_button_clicked(self,widget): |
---|
300 | |
---|
301 | self.edition=False |
---|
302 | self.core.lgd.check_plabel.set_text(_("Checking connection to google...")) |
---|
303 | self.core.lgd.check_window.show() |
---|
304 | self.init_threads() |
---|
305 | self.check_connection_t.start() |
---|
306 | GLib.timeout_add(100,self.pulsate_add_connection) |
---|
307 | |
---|
308 | #def add_new_profile_button_clicked |
---|
309 | |
---|
310 | def pulsate_add_connection(self): |
---|
311 | |
---|
312 | if self.check_connection_t.is_alive(): |
---|
313 | self.core.lgd.check_pbar.pulse() |
---|
314 | return True |
---|
315 | |
---|
316 | else: |
---|
317 | self.core.lgd.check_window.hide() |
---|
318 | self.enable_entry_profile_dialog() |
---|
319 | #ENCODING TO UNICODE |
---|
320 | if self.connection: |
---|
321 | self.profile_entry.set_text("") |
---|
322 | self.email_entry.set_text("") |
---|
323 | self.mountpoint_entry.set_filename(os.environ["HOME"]) |
---|
324 | self.automount_entry.set_active(False) |
---|
325 | self.profile_msg.set_text("") |
---|
326 | |
---|
327 | |
---|
328 | self.init_threads() |
---|
329 | |
---|
330 | self.msg_label.set_text("") |
---|
331 | self.profile_msg.hide() |
---|
332 | self.profile_pbar.hide() |
---|
333 | self.init_profile_dialog_button() |
---|
334 | self.new_profile_window.show() |
---|
335 | |
---|
336 | else: |
---|
337 | msg_error=self.get_msg(8) |
---|
338 | self.msg_label.set_name("MSG_ERROR_LABEL") |
---|
339 | self.msg_label.set_text(msg_error) |
---|
340 | |
---|
341 | return False |
---|
342 | |
---|
343 | |
---|
344 | #def add_new_profile_button_clicked |
---|
345 | |
---|
346 | def delete_profile_clicked(self,button,hbox): |
---|
347 | |
---|
348 | dialog = Gtk.MessageDialog(None,0,Gtk.MessageType.WARNING, Gtk.ButtonsType.YES_NO, "Lliurex GDrive") |
---|
349 | dialog.format_secondary_text(_("Do you want delete the profile?")) |
---|
350 | response=dialog.run() |
---|
351 | dialog.destroy() |
---|
352 | |
---|
353 | |
---|
354 | if response==Gtk.ResponseType.YES: |
---|
355 | profile=hbox.get_children()[1].get_text().split("\n")[0] |
---|
356 | #ENCODING TO UNICODE |
---|
357 | profile=profile.decode("utf-8") |
---|
358 | self.delete_profile_t=threading.Thread(target=self.delete_profile,args=(profile,)) |
---|
359 | self.delete_profile_t.daemon=True |
---|
360 | GObject.threads_init() |
---|
361 | |
---|
362 | self.msg_label.set_text("") |
---|
363 | |
---|
364 | self.profiles_info.pop(profile) |
---|
365 | self.delete_profile_t.start() |
---|
366 | self.delete_profile_t.launched=True |
---|
367 | self.core.lgd.check_plabel.set_text(_("Applying changes...")) |
---|
368 | self.core.lgd.check_window.show() |
---|
369 | GLib.timeout_add(100,self.pulsate_delete_profile,profile,hbox) |
---|
370 | |
---|
371 | # def delete_profile_clicked |
---|
372 | |
---|
373 | def pulsate_delete_profile(self,profile,hbox): |
---|
374 | |
---|
375 | if self.delete_profile_t.is_alive(): |
---|
376 | self.core.lgd.check_pbar.pulse() |
---|
377 | return True |
---|
378 | |
---|
379 | else: |
---|
380 | self.msg_label.show() |
---|
381 | self.core.lgd.check_window.hide() |
---|
382 | if self.delete["result"]: |
---|
383 | self.msg_label.set_name("MSG_LABEL") |
---|
384 | self.profile_list_box.remove(hbox) |
---|
385 | else: |
---|
386 | self.msg_label.set_name("MSG_ERROR_LABEL") |
---|
387 | |
---|
388 | msg_text=self.get_msg(self.delete["code"]) |
---|
389 | self.msg_label.set_text(msg_text) |
---|
390 | self.profiles_info=self.core.LliurexGoogleDriveManager.profiles_config.copy() |
---|
391 | |
---|
392 | return False |
---|
393 | |
---|
394 | #def pulsate_delete_profile |
---|
395 | |
---|
396 | |
---|
397 | def delete_profile(self,profile): |
---|
398 | |
---|
399 | self.delete=self.core.LliurexGoogleDriveManager.delete_profile(self.profiles_info,profile) |
---|
400 | |
---|
401 | #def delete_profile |
---|
402 | |
---|
403 | def sync_profile_clicked(self,button,hbox): |
---|
404 | |
---|
405 | self.msg_label.set_text("") |
---|
406 | self.sync_profile_t=threading.Thread(target=self.sync_profile,args=(hbox,)) |
---|
407 | self.sync_profile_t.daemon=True |
---|
408 | GObject.threads_init() |
---|
409 | |
---|
410 | self.sync_profile_t.start() |
---|
411 | self.core.lgd.check_plabel.set_text(_("Applying changes...")) |
---|
412 | self.core.lgd.check_window.show() |
---|
413 | GLib.timeout_add(100,self.pulsate_sync_profile,button,hbox) |
---|
414 | |
---|
415 | |
---|
416 | #def sync_profile_cicked |
---|
417 | |
---|
418 | def pulsate_sync_profile(self,button,hbox): |
---|
419 | |
---|
420 | if self.sync_profile_t.is_alive(): |
---|
421 | self.core.lgd.check_pbar.pulse() |
---|
422 | return True |
---|
423 | |
---|
424 | else: |
---|
425 | self.core.lgd.check_window.hide() |
---|
426 | if self.status_mod["result"]: |
---|
427 | msg_text=self.get_msg(self.status_mod["code"]) |
---|
428 | self.msg_label.set_name("MSG_LABEL") |
---|
429 | self.msg_label.set_text(msg_text) |
---|
430 | |
---|
431 | else: |
---|
432 | msg_text=self.get_msg(self.status_mod["code"]) |
---|
433 | self.msg_label.set_name("MSG_ERROR_LABEL") |
---|
434 | self.msg_label.set_text(msg_text) |
---|
435 | |
---|
436 | |
---|
437 | info=self.item_status_info(self.status_info['status']) |
---|
438 | profile=hbox.get_children()[1].get_text().split("\n")[0] |
---|
439 | self.current_status[profile.decode("utf-8")]=self.status_info["status"] |
---|
440 | button.set_tooltip_text(info["tooltip"]) |
---|
441 | button.set_name(info["css"]) |
---|
442 | hbox.get_children()[4].set_image(info["img"]) |
---|
443 | |
---|
444 | return False |
---|
445 | |
---|
446 | #def pulsate_sync_profile |
---|
447 | |
---|
448 | def sync_profile(self,hbox): |
---|
449 | |
---|
450 | profile=hbox.get_children()[1].get_text().split("\n")[0] |
---|
451 | mountpoint=hbox.get_children()[3].get_text() |
---|
452 | # ENCODING TO UNICODE |
---|
453 | profile=profile.decode("utf-8") |
---|
454 | mountpoint=mountpoint.decode("utf-8") |
---|
455 | connect=True |
---|
456 | current_status=self.current_status[profile] |
---|
457 | self.status_mod,self.status_info=self.core.LliurexGoogleDriveManager.sync_profile(profile,mountpoint,current_status) |
---|
458 | |
---|
459 | #def sync_profile |
---|
460 | |
---|
461 | def edit_profile_clicked(self,button,hbox): |
---|
462 | |
---|
463 | self.edition=True |
---|
464 | self.read=False |
---|
465 | self.core.lgd.check_plabel.set_text(_("Checking connection to google...")) |
---|
466 | self.core.lgd.check_window.show() |
---|
467 | self.init_threads() |
---|
468 | self.check_connection_t.start() |
---|
469 | GLib.timeout_add(100,self.pulsate_edit_connection,hbox) |
---|
470 | |
---|
471 | |
---|
472 | #def edit_profile_clicked |
---|
473 | |
---|
474 | def pulsate_edit_connection(self,hbox): |
---|
475 | |
---|
476 | if self.check_connection_t.is_alive(): |
---|
477 | #self.disable_entry_profile_dialog() |
---|
478 | self.core.lgd.check_pbar.pulse() |
---|
479 | return True |
---|
480 | |
---|
481 | else: |
---|
482 | self.core.lgd.check_window.hide() |
---|
483 | self.enable_entry_profile_dialog() |
---|
484 | #ENCODING TO UNICODE |
---|
485 | if self.connection: |
---|
486 | self.stack.set_visible_child_name("edit") |
---|
487 | |
---|
488 | self.profile_to_edit=hbox |
---|
489 | self.profile=self.profile_to_edit.get_children()[1].get_text().split("\n")[0] |
---|
490 | self.profile_entry.set_text(self.profile) |
---|
491 | email=self.profile_to_edit.get_children()[1].get_text().split("\n")[1] |
---|
492 | self.email_entry.set_text(email) |
---|
493 | mountpoint=self.profile_to_edit.get_children()[3].get_text() |
---|
494 | self.mountpoint_entry.set_filename(mountpoint) |
---|
495 | automount=self.profiles_info[self.profile.decode("utf-8")]["automount"] |
---|
496 | self.automount_entry.set_active(automount) |
---|
497 | |
---|
498 | try: |
---|
499 | self.root_folder=self.profiles_info[self.profile.decode("utf-8")]["root_folder"] |
---|
500 | except Exception as e: |
---|
501 | self.root_folder=False |
---|
502 | |
---|
503 | if self.root_folder: |
---|
504 | self.gdrive_folder_label.show() |
---|
505 | self.gdrive_folder_entry.show() |
---|
506 | self.gdrive_folder_entry.set_text(self.profiles_info[self.profile.decode("utf-8")]["gdrive_folder"]) |
---|
507 | #self.gdrive_folder=self.gdrive_folder_entry.get_text() |
---|
508 | self.edit_gdrive_folder_button.show() |
---|
509 | self.edit_gdrive_folder_button.set_sensitive(True) |
---|
510 | else: |
---|
511 | self.gdrive_folder_label.hide() |
---|
512 | self.gdrive_folder_entry.set_text("") |
---|
513 | #self.gdrive_folder=self.gdrive_folder_entry.get_text() |
---|
514 | self.gdrive_folder_entry.hide() |
---|
515 | self.edit_gdrive_folder_button.hide() |
---|
516 | |
---|
517 | self.root_folder_param_entry.set_active(self.root_folder) |
---|
518 | |
---|
519 | self.init_threads() |
---|
520 | |
---|
521 | self.profile_msg.hide() |
---|
522 | self.profile_pbar.hide() |
---|
523 | self.msg_label.set_text("") |
---|
524 | self.init_profile_dialog_button() |
---|
525 | self.new_profile_window.show() |
---|
526 | |
---|
527 | else: |
---|
528 | msg_text=self.get_msg(8) |
---|
529 | self.msg_label.set_name("MSG_ERROR_LABEL") |
---|
530 | self.msg_label.set_text(msg_text) |
---|
531 | return False |
---|
532 | |
---|
533 | #def pulsate_edit_connection |
---|
534 | |
---|
535 | |
---|
536 | def check_connection(self): |
---|
537 | self.connection=self.core.LliurexGoogleDriveManager.check_google_connection() |
---|
538 | |
---|
539 | #def check_connection |
---|
540 | |
---|
541 | def new_profile_button(self,profile_name,email,mountpoint): |
---|
542 | |
---|
543 | hbox=Gtk.HBox() |
---|
544 | profile_image=Gtk.Image.new_from_file(PROFILE_IMAGE) |
---|
545 | profile_image.set_margin_left(10) |
---|
546 | profile_image.set_halign(Gtk.Align.CENTER) |
---|
547 | profile_image.set_valign(Gtk.Align.CENTER) |
---|
548 | profile_info="<span font='Roboto'><b>"+profile_name+"</b></span>\n"+"<span font='Roboto'>"+email+"</span>" |
---|
549 | profile=Gtk.Label() |
---|
550 | profile.set_markup(profile_info) |
---|
551 | profile.set_margin_left(10) |
---|
552 | profile.set_margin_right(15) |
---|
553 | profile.set_margin_top(21) |
---|
554 | profile.set_margin_bottom(21) |
---|
555 | profile.set_width_chars(25) |
---|
556 | profile.set_max_width_chars(25) |
---|
557 | profile.set_xalign(-1) |
---|
558 | profile.set_ellipsize(Pango.EllipsizeMode.END) |
---|
559 | folder_image=Gtk.Image.new_from_file(FOLDER_IMAGE) |
---|
560 | folder_image.set_margin_left(20) |
---|
561 | folder_image.set_halign(Gtk.Align.CENTER) |
---|
562 | folder_image.set_valign(Gtk.Align.CENTER) |
---|
563 | folder=Gtk.Label() |
---|
564 | folder.set_text(mountpoint) |
---|
565 | folder.set_margin_left(10) |
---|
566 | delete=Gtk.Button() |
---|
567 | delete_image=Gtk.Image.new_from_file(DELETE_IMAGE) |
---|
568 | delete.add(delete_image) |
---|
569 | delete.set_halign(Gtk.Align.CENTER) |
---|
570 | delete.set_valign(Gtk.Align.CENTER) |
---|
571 | delete.set_name("DELETE_ITEM_BUTTON") |
---|
572 | delete.connect("clicked",self.delete_profile_clicked,hbox) |
---|
573 | delete.set_tooltip_text(_("Delete profile")) |
---|
574 | edit=Gtk.Button() |
---|
575 | edit_image=Gtk.Image.new_from_file(EDIT_IMAGE) |
---|
576 | edit.add(edit_image) |
---|
577 | edit.set_halign(Gtk.Align.CENTER) |
---|
578 | edit.set_valign(Gtk.Align.CENTER) |
---|
579 | edit.set_name("EDIT_ITEM_BUTTON") |
---|
580 | edit.connect("clicked",self.edit_profile_clicked,hbox) |
---|
581 | edit.set_tooltip_text(_("Edit profile")) |
---|
582 | mount=Gtk.Button() |
---|
583 | |
---|
584 | if self.initial_connection: |
---|
585 | status_info=self.core.LliurexGoogleDriveManager.check_mountpoint_status(mountpoint) |
---|
586 | self.current_status[profile_name]=status_info["status"] |
---|
587 | info=self.item_status_info(status_info["status"]) |
---|
588 | else: |
---|
589 | info=self.item_status_info(None) |
---|
590 | self.current_status[profile_name]=None |
---|
591 | |
---|
592 | |
---|
593 | mount_image=info["img"] |
---|
594 | mount.set_tooltip_text(info["tooltip"]) |
---|
595 | mount.set_name(info["css"]) |
---|
596 | mount.add(mount_image) |
---|
597 | mount.set_halign(Gtk.Align.CENTER) |
---|
598 | mount.set_valign(Gtk.Align.CENTER) |
---|
599 | mount.connect("clicked",self.sync_profile_clicked,hbox) |
---|
600 | |
---|
601 | hbox.pack_start(profile_image,False,False,0) |
---|
602 | hbox.pack_start(profile,False,False,0) |
---|
603 | hbox.pack_start(folder_image,False,False,0) |
---|
604 | hbox.pack_start(folder,False,False,0) |
---|
605 | hbox.pack_end(delete,False,False,10) |
---|
606 | hbox.pack_end(edit,False,False,10) |
---|
607 | hbox.pack_end(mount,False,False,10) |
---|
608 | hbox.show_all() |
---|
609 | hbox.set_name("PROFILE_BOX") |
---|
610 | self.profile_list_box.pack_start(hbox,False,False,5) |
---|
611 | self.profile_list_box.queue_draw() |
---|
612 | hbox.queue_draw() |
---|
613 | |
---|
614 | #def new_profile_button |
---|
615 | |
---|
616 | def item_status_info(self,status_info): |
---|
617 | |
---|
618 | |
---|
619 | |
---|
620 | if status_info==None: |
---|
621 | img=Gtk.Image.new_from_file(MOUNT_ON_IMAGE) |
---|
622 | css="WARNING_ITEM_BUTTON" |
---|
623 | tooltip=_("Without connection. Clicked to update") |
---|
624 | css="WARNING_ITEM_BUTTON" |
---|
625 | elif status_info: |
---|
626 | img=Gtk.Image.new_from_file(MOUNT_ON_IMAGE) |
---|
627 | tooltip=_("Mounted. Clicked to dismount now") |
---|
628 | css="MOUNT_ITEM_BUTTON" |
---|
629 | else: |
---|
630 | img=Gtk.Image.new_from_file(MOUNT_ON_IMAGE) |
---|
631 | tooltip=_("Dismounted. Clicked to mount now") |
---|
632 | css="DELETE_ITEM_BUTTON" |
---|
633 | |
---|
634 | return {"img":img ,"tooltip":tooltip, "css":css} |
---|
635 | |
---|
636 | #def item_status_info |
---|
637 | |
---|
638 | def accept_add_profile_clicked(self,widget): |
---|
639 | |
---|
640 | self.disable_entry_profile_dialog() |
---|
641 | #ENCODING TO UNICODE |
---|
642 | profile=self.profile_entry.get_text() |
---|
643 | |
---|
644 | self.new_profile=profile.strip().decode("utf-8") |
---|
645 | email=self.email_entry.get_text() |
---|
646 | self.new_email=email.strip() |
---|
647 | self.new_mountpoint=self.mountpoint_entry.get_filename().decode("utf-8") |
---|
648 | self.new_automount=self.automount_entry.get_state() |
---|
649 | |
---|
650 | if not self.edition: |
---|
651 | self.new_root_folder=False |
---|
652 | self.new_gdrive_folder="" |
---|
653 | else: |
---|
654 | self.new_root_folder=self.root_folder_param_entry.get_state() |
---|
655 | if self.new_root_folder: |
---|
656 | try: |
---|
657 | self.new_gdrive_folder=self.gdrive_folder_entry.get_text().decode("utf-8") |
---|
658 | except Exception as e: |
---|
659 | print str(e) |
---|
660 | self.new_gdrive_folder="" |
---|
661 | else: |
---|
662 | self.new_gdrive_folder="" |
---|
663 | |
---|
664 | self.profile_msg.show() |
---|
665 | self.profile_msg.set_name("MSG_LABEL") |
---|
666 | self.profile_pbar.show() |
---|
667 | self.init_threads() |
---|
668 | if not self.check_form_t.launched: |
---|
669 | self.profile_msg.set_text(_("Validating entered data...")) |
---|
670 | GLib.timeout_add(100,self.pulsate_check_form) |
---|
671 | |
---|
672 | |
---|
673 | def pulsate_check_form(self): |
---|
674 | |
---|
675 | self.profile_pbar.pulse() |
---|
676 | |
---|
677 | if not self.check_form_t.launched: |
---|
678 | self.check_form_t.start() |
---|
679 | self.check_form_t.launched=True |
---|
680 | |
---|
681 | |
---|
682 | if self.check_form_t.done: |
---|
683 | |
---|
684 | if self.check_form_result['result']: |
---|
685 | self.profiles_info[self.new_profile]={} |
---|
686 | self.profiles_info[self.new_profile]["email"]=self.new_email |
---|
687 | self.profiles_info[self.new_profile]["mountpoint"]=self.new_mountpoint |
---|
688 | self.profiles_info[self.new_profile]["automount"]=self.new_automount |
---|
689 | self.profiles_info[self.new_profile]["root_folder"]=self.new_root_folder |
---|
690 | self.profiles_info[self.new_profile]["gdrive_folder"]=self.new_gdrive_folder |
---|
691 | |
---|
692 | self.profile_msg.set_name("MSG_LABEL") |
---|
693 | if not self.edition: |
---|
694 | if not self.create_profile_t.launched: |
---|
695 | self.profile_msg.set_text(_("Connecting with google to get account access...")) |
---|
696 | self.profile_pbar.show() |
---|
697 | self.retry=0 |
---|
698 | GLib.timeout_add(100,self.pulsate_add_profile) |
---|
699 | |
---|
700 | |
---|
701 | else: |
---|
702 | |
---|
703 | if not self.edit_profile_t.launched: |
---|
704 | self.profile_msg.set_text(_("Applying changes...")) |
---|
705 | self.profile_pbar.show() |
---|
706 | GLib.timeout_add(100,self.pulsate_edit_profile) |
---|
707 | else: |
---|
708 | self.profile_pbar.hide() |
---|
709 | self.profile_msg.set_name("MSG_ERROR_LABEL") |
---|
710 | #self.profile_msg.set_text(check_form["msg"]) |
---|
711 | self.profile_msg.set_text(self.get_msg(self.check_form_result["code"])) |
---|
712 | self.enable_entry_profile_dialog() |
---|
713 | return False |
---|
714 | |
---|
715 | if self.check_form_t.launched: |
---|
716 | if not self.check_form_t.done: |
---|
717 | return True |
---|
718 | |
---|
719 | def check_form(self): |
---|
720 | |
---|
721 | self.check_form_result=self.core.LliurexGoogleDriveManager.check_profile_info(self.new_profile,self.new_mountpoint,self.edition,self.new_root_folder,self.new_gdrive_folder) |
---|
722 | self.check_form_t.done=True |
---|
723 | #self.profile_msg.show() |
---|
724 | |
---|
725 | |
---|
726 | #def accept_add_profile_clicked |
---|
727 | |
---|
728 | def check_mountpoint_folder(self,widget): |
---|
729 | |
---|
730 | |
---|
731 | self.disable_entry_profile_dialog() |
---|
732 | #ENCODING TO UNICODE |
---|
733 | profile=self.profile_entry.get_text() |
---|
734 | |
---|
735 | new_profile=profile.strip().decode("utf-8") |
---|
736 | new_mountpoint=self.mountpoint_entry.get_filename().decode("utf-8") |
---|
737 | |
---|
738 | check_form=self.core.LliurexGoogleDriveManager.check_mountpoint_folder(new_profile,new_mountpoint,self.edition) |
---|
739 | |
---|
740 | if not check_form["result"]: |
---|
741 | self.profile_msg.show() |
---|
742 | self.profile_msg.set_name("MSG_ERROR_LABEL") |
---|
743 | self.profile_msg.set_text(self.get_msg(check_form["code"])) |
---|
744 | |
---|
745 | else: |
---|
746 | self.profile_msg.hide() |
---|
747 | |
---|
748 | self.enable_entry_profile_dialog() |
---|
749 | |
---|
750 | #def check_mountpoint_folder |
---|
751 | |
---|
752 | ''' |
---|
753 | def check_profile_info(self): |
---|
754 | |
---|
755 | msg_check="" |
---|
756 | |
---|
757 | check_form=self.core.LliurexGoogleDriveManager.check_profile_info(self.new_profile,self.new_mountpoint,self.edition) |
---|
758 | |
---|
759 | |
---|
760 | if not check_form["result"]: |
---|
761 | if check_form["code"]==1: |
---|
762 | msg_check=_("You must indicate a profile") |
---|
763 | |
---|
764 | elif check_form["code"]==2: |
---|
765 | msg_check=_("Profile can not contain blanks") |
---|
766 | |
---|
767 | elif check_form["code"]==3 : |
---|
768 | msg_check=_("Profile already exists") |
---|
769 | |
---|
770 | elif check_form["code"]==4: |
---|
771 | msg_check=_("Mount point already used by another profile") |
---|
772 | |
---|
773 | elif check_form["code"]==5: |
---|
774 | msg_check=_("The mount point must be an empty folder") |
---|
775 | |
---|
776 | elif check_form["code"]==6: |
---|
777 | msg_check=_("Mount point is not owned by user") |
---|
778 | |
---|
779 | |
---|
780 | return {"result":check_form["result"],"msg":msg_check} |
---|
781 | |
---|
782 | #def check_profile_info |
---|
783 | |
---|
784 | ''' |
---|
785 | |
---|
786 | def pulsate_add_profile(self): |
---|
787 | |
---|
788 | self.retry=self.retry+1 |
---|
789 | self.profile_pbar.pulse() |
---|
790 | |
---|
791 | if not self.create_profile_t.launched: |
---|
792 | self.accept_add_profile_button.hide() |
---|
793 | self.cancel_add_profile_button.hide() |
---|
794 | |
---|
795 | self.create_profile_t.start() |
---|
796 | self.create_profile_t.launched=True |
---|
797 | |
---|
798 | if not self.create_profile_t.is_alive(): |
---|
799 | if not self.create_mountpoint_t.launched: |
---|
800 | self.profile_msg.set_name("MSG_LABEL") |
---|
801 | self.profile_msg.set_text(_("Creating profile... ")) |
---|
802 | self.create_mountpoint_t.start() |
---|
803 | self.create_mountpoint_t.launched=True |
---|
804 | |
---|
805 | if self.create_mountpoint_t.done: |
---|
806 | self.profile_pbar.hide() |
---|
807 | if self.create_result["result"]: |
---|
808 | self.initial_connection=True |
---|
809 | self.new_profile_button(self.new_profile,self.new_email,self.new_mountpoint) |
---|
810 | self.profile_msg.set_text(_("Profile created successfully")) |
---|
811 | self.change_cancel_button() |
---|
812 | |
---|
813 | else: |
---|
814 | msg_text=self.get_msg(self.create_result["code"]) |
---|
815 | self.profile_msg.set_name("MSG_ERROR_LABEL") |
---|
816 | self.profile_msg.set_text(msg_text) |
---|
817 | self.cancel_add_profile_button.show() |
---|
818 | |
---|
819 | self.profiles_info=self.core.LliurexGoogleDriveManager.profiles_config.copy() |
---|
820 | return False |
---|
821 | |
---|
822 | if self.create_profile_t.launched: |
---|
823 | if self.create_profile_t.is_alive(): |
---|
824 | self.kill_create_profile() |
---|
825 | return True |
---|
826 | |
---|
827 | |
---|
828 | if self.create_mountpoint_t.launched: |
---|
829 | if not self.create_mountpoint_t.done: |
---|
830 | return True |
---|
831 | |
---|
832 | #def_pulsate_add_profile |
---|
833 | |
---|
834 | |
---|
835 | def get_msg(self,code): |
---|
836 | |
---|
837 | if code==0: |
---|
838 | msg_text=_("Changes applied successfully") |
---|
839 | |
---|
840 | elif code==1: |
---|
841 | msg_text=_("Error: Unable to create mount point") |
---|
842 | |
---|
843 | elif code==2: |
---|
844 | msg_text=_("Error: Unable to mount mount point") |
---|
845 | |
---|
846 | elif code==3: |
---|
847 | msg_text=_("Error: Mount point is not owned by user") |
---|
848 | |
---|
849 | elif code==4: |
---|
850 | msg_text=_("Error: No mount point indicated") |
---|
851 | |
---|
852 | elif code==5: |
---|
853 | msg_text=_("Error: Profile is not authorized to Google Drive") |
---|
854 | |
---|
855 | elif code==6: |
---|
856 | msg_text=_("Error: Unknow profile") |
---|
857 | |
---|
858 | elif code==7: |
---|
859 | msg_text=_("Error: Unable to dismount mount point") |
---|
860 | |
---|
861 | elif code==8: |
---|
862 | msg_text=_("Error: Unable to connect with google") |
---|
863 | |
---|
864 | elif code==9: |
---|
865 | msg_text=_("Status updated. Now you can change it") |
---|
866 | |
---|
867 | elif code==10: |
---|
868 | msg_text=_("You must indicate a profile") |
---|
869 | |
---|
870 | elif code==11: |
---|
871 | msg_text=_("Profile can not contain blanks") |
---|
872 | |
---|
873 | elif code==12: |
---|
874 | msg_text=_("Profile already exists") |
---|
875 | |
---|
876 | elif code==13: |
---|
877 | msg_text=_("Mount point already used by another profile") |
---|
878 | |
---|
879 | elif code==14: |
---|
880 | msg_text=_("The mount point must be an empty folder") |
---|
881 | |
---|
882 | elif code==15: |
---|
883 | msg_text=_("Mount point is not owned by user") |
---|
884 | |
---|
885 | elif code==16: |
---|
886 | msg_text=_("Path of mount point can not contain blanks") |
---|
887 | |
---|
888 | elif code==17: |
---|
889 | msg_text=_("Error: You must specify a GDrive folder or disable the option") |
---|
890 | |
---|
891 | elif code==18: |
---|
892 | msg_text=_("Error: Unable to mount mount point. The specified GDrive folder maybe not be correct") |
---|
893 | |
---|
894 | elif code==19: |
---|
895 | msg_text=_("Error: Synced Gdrive folder no longer exists") |
---|
896 | |
---|
897 | elif code==20: |
---|
898 | msg_text=_("Error: No folders found in Gdrive profile. You must disable the option") |
---|
899 | |
---|
900 | |
---|
901 | return msg_text |
---|
902 | |
---|
903 | |
---|
904 | #def get_msg |
---|
905 | |
---|
906 | def kill_create_profile(self): |
---|
907 | |
---|
908 | if self.retry>MAX_RETRY_INTENTS: |
---|
909 | parent=psutil.Process(self.create_profile_t.pid) |
---|
910 | for child in parent.children(recursive=True): |
---|
911 | child.kill() |
---|
912 | self.create_profile_t.terminate() |
---|
913 | self.profile_msg.set_name("MSG_ERROR_LABEL") |
---|
914 | self.profile_msg.set_text(_("Error getting authorization")) |
---|
915 | |
---|
916 | return True |
---|
917 | |
---|
918 | #def kill_create_profile |
---|
919 | |
---|
920 | def create_profile(self): |
---|
921 | |
---|
922 | result=self.core.LliurexGoogleDriveManager.create_profile(self.new_profile) |
---|
923 | |
---|
924 | #def create_profile |
---|
925 | |
---|
926 | def create_mountpoint(self): |
---|
927 | |
---|
928 | self.create_result=self.core.LliurexGoogleDriveManager.create_mountpoint(self.profiles_info,self.new_profile) |
---|
929 | self.create_mountpoint_t.done=True |
---|
930 | |
---|
931 | #def create_mountpoint |
---|
932 | |
---|
933 | def pulsate_edit_profile(self): |
---|
934 | |
---|
935 | self.profile_pbar.pulse() |
---|
936 | if not self.edit_profile_t.launched: |
---|
937 | self.edit_profile_t.start() |
---|
938 | self.edit_profile_t.launched=True |
---|
939 | self.accept_add_profile_button.hide() |
---|
940 | self.cancel_add_profile_button.hide() |
---|
941 | |
---|
942 | if self.edit_profile_t.done: |
---|
943 | self.profile_pbar.hide() |
---|
944 | if self.edit_result["result"]: |
---|
945 | self.profile_msg.set_name("MSG_LABEL") |
---|
946 | self.profile_to_edit.get_children()[3].set_text(self.new_mountpoint) |
---|
947 | self.profiles_info=self.core.LliurexGoogleDriveManager.profiles_config.copy() |
---|
948 | self.change_cancel_button() |
---|
949 | |
---|
950 | else: |
---|
951 | |
---|
952 | self.profile_msg.set_name("MSG_ERROR_LABEL") |
---|
953 | self.cancel_add_profile_button.show() |
---|
954 | |
---|
955 | msg_text=self.get_msg(self.edit_result["code"]) |
---|
956 | self.profile_msg.set_text(msg_text) |
---|
957 | |
---|
958 | return False |
---|
959 | |
---|
960 | |
---|
961 | if self.edit_profile_t.launched: |
---|
962 | if not self.edit_profile_t.done: |
---|
963 | return True |
---|
964 | |
---|
965 | #def pulsate_edit_profile |
---|
966 | |
---|
967 | def edit_profile(self): |
---|
968 | |
---|
969 | self.edit_result=self.core.LliurexGoogleDriveManager.edit_profile(self.profiles_info,self.new_profile) |
---|
970 | self.edit_profile_t.done=True |
---|
971 | |
---|
972 | #def edit_profile |
---|
973 | |
---|
974 | def cancel_add_profile_clicked(self,widget): |
---|
975 | |
---|
976 | self.new_profile_window.hide() |
---|
977 | |
---|
978 | |
---|
979 | #def cancel_add_profile_clicked |
---|
980 | |
---|
981 | def root_folder_clicked(self,widget,event): |
---|
982 | |
---|
983 | if self.root_folder_param_entry.get_active(): |
---|
984 | if not self.root_folder: |
---|
985 | |
---|
986 | self.init_read_mountpoint_dialog() |
---|
987 | |
---|
988 | else: |
---|
989 | self.root_folder=False |
---|
990 | self.gdrive_folder_label.hide() |
---|
991 | self.gdrive_folder_entry.hide() |
---|
992 | #self.gdrive_folder_entry.set_text("") |
---|
993 | self.edit_gdrive_folder_button.hide() |
---|
994 | |
---|
995 | #def root_folder_clicked |
---|
996 | |
---|
997 | |
---|
998 | #def pulsate_read_mountpoint |
---|
999 | |
---|
1000 | def init_read_mountpoint_dialog(self): |
---|
1001 | |
---|
1002 | if not self.read: |
---|
1003 | |
---|
1004 | if not self.read_mountpoint_t.launched: |
---|
1005 | self.disable_entry_profile_dialog() |
---|
1006 | self.profile_msg.set_name("MSG_LABEL") |
---|
1007 | self.profile_msg.show() |
---|
1008 | self.profile_msg.set_text(_("Getting folders from Google Drive profile ...")) |
---|
1009 | self.profile_pbar.show() |
---|
1010 | GLib.timeout_add(100,self.pulsate_read_mountpoint) |
---|
1011 | |
---|
1012 | else: |
---|
1013 | if len(self.syncfolders_model)>1: |
---|
1014 | self.stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT) |
---|
1015 | self.stack.set_visible_child_name("folder") |
---|
1016 | self.gdrive_combobox.set_active(0) |
---|
1017 | |
---|
1018 | #def init_read_mountpoint_dialog |
---|
1019 | |
---|
1020 | |
---|
1021 | def pulsate_read_mountpoint(self): |
---|
1022 | |
---|
1023 | self.profile_pbar.pulse() |
---|
1024 | |
---|
1025 | if not self.read_mountpoint_t.launched: |
---|
1026 | self.read_mountpoint_t.start() |
---|
1027 | self.read_mountpoint_t.launched=True |
---|
1028 | self.accept_add_profile_button.hide() |
---|
1029 | self.cancel_add_profile_button.hide() |
---|
1030 | |
---|
1031 | if self.read_mountpoint_t.done: |
---|
1032 | self.root_folder=False |
---|
1033 | self.enable_entry_profile_dialog() |
---|
1034 | self.profile_pbar.hide() |
---|
1035 | self.profile_msg.hide() |
---|
1036 | |
---|
1037 | if len(self.syncfolders_model)>1: |
---|
1038 | self.stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT) |
---|
1039 | |
---|
1040 | self.stack.set_visible_child_name("folder") |
---|
1041 | self.accept_add_profile_button.show() |
---|
1042 | self.cancel_add_profile_button.show() |
---|
1043 | else: |
---|
1044 | self.profile_msg.show() |
---|
1045 | self.profile_msg.set_name("MSG_ERROR_LABEL") |
---|
1046 | self.profile_msg.set_text(_("No folders detected on google drive profile")) |
---|
1047 | self.accept_add_profile_button.show() |
---|
1048 | self.cancel_add_profile_button.show() |
---|
1049 | |
---|
1050 | return False |
---|
1051 | |
---|
1052 | |
---|
1053 | if self.read_mountpoint_t.launched: |
---|
1054 | if not self.read_mountpoint_t.done: |
---|
1055 | return True |
---|
1056 | |
---|
1057 | |
---|
1058 | |
---|
1059 | def read_mountpoint(self): |
---|
1060 | |
---|
1061 | |
---|
1062 | folders=self.core.LliurexGoogleDriveManager.read_mountpoint_directory(self.profile) |
---|
1063 | |
---|
1064 | self.syncfolders_model.clear() |
---|
1065 | |
---|
1066 | if len(folders)>0: |
---|
1067 | |
---|
1068 | for item in folders: |
---|
1069 | self.syncfolders_model.append([item]) |
---|
1070 | |
---|
1071 | |
---|
1072 | self.read=True |
---|
1073 | |
---|
1074 | self.read_mountpoint_t.done=True |
---|
1075 | |
---|
1076 | #def read_mountpoint |
---|
1077 | |
---|
1078 | def edit_gdrive_folder_button_clicked(self,widget): |
---|
1079 | |
---|
1080 | |
---|
1081 | self.init_threads() |
---|
1082 | self.profile_msg.hide() |
---|
1083 | self.profile_msg.set_text("") |
---|
1084 | self.init_read_mountpoint_dialog() |
---|
1085 | |
---|
1086 | |
---|
1087 | |
---|
1088 | #def edit_gdrive_folder_button_clicked |
---|
1089 | |
---|
1090 | |
---|
1091 | def return_combobox_button_clicked(self,widget): |
---|
1092 | |
---|
1093 | |
---|
1094 | #self.gdrive_folder_entry.set_text(self.folder) |
---|
1095 | #self.gdrive_folder=folder |
---|
1096 | |
---|
1097 | |
---|
1098 | self.stack.set_transition_type(Gtk.StackTransitionType.SLIDE_RIGHT) |
---|
1099 | self.stack.set_visible_child_name("edit") |
---|
1100 | |
---|
1101 | self.gdrive_folder_label.show() |
---|
1102 | self.gdrive_folder_entry.show() |
---|
1103 | self.edit_gdrive_folder_button.set_sensitive(True) |
---|
1104 | |
---|
1105 | #def return_combobox_button_clicked |
---|
1106 | |
---|
1107 | def on_gdrive_combobox_changed (self,combo): |
---|
1108 | |
---|
1109 | |
---|
1110 | |
---|
1111 | tree_iter=combo.get_active_iter() |
---|
1112 | |
---|
1113 | |
---|
1114 | if tree_iter != None: |
---|
1115 | model = combo.get_model() |
---|
1116 | folder = model[tree_iter][0] |
---|
1117 | self.gdrive_folder_entry.set_text(folder) |
---|
1118 | |
---|
1119 | |
---|
1120 | #def on_gdrive_combobox_changeg |
---|
1121 | |
---|
1122 | |
---|
1123 | |
---|
1124 | |
---|
1125 | |
---|
1126 | #class profilebox |
---|
1127 | |
---|
1128 | |
---|
1129 | |
---|
1130 | |
---|