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=900 |
---|
35 | MSG_CHANGE_SUCCESS=_("Changes applied successfully") |
---|
36 | MSG_CHANGE_ERROR=_("An error ocurred applying changes. See log file for more information") |
---|
37 | |
---|
38 | class ProfileBox(Gtk.VBox): |
---|
39 | |
---|
40 | def __init__(self): |
---|
41 | |
---|
42 | Gtk.VBox.__init__(self) |
---|
43 | |
---|
44 | self.core=Core.Core.get_core() |
---|
45 | |
---|
46 | builder=Gtk.Builder() |
---|
47 | ui_path=RSRC + "/rsrc/lliurex-gdrive.ui" |
---|
48 | builder.add_from_file(ui_path) |
---|
49 | |
---|
50 | self.main_box=builder.get_object("profile_data_box") |
---|
51 | self.profiles_list_label=builder.get_object("profiles_list_label") |
---|
52 | self.profile_list_box=builder.get_object("profile_list_box") |
---|
53 | self.profile_list_vp=builder.get_object("profile_list_viewport") |
---|
54 | self.msg_label=builder.get_object("msg_label") |
---|
55 | |
---|
56 | image = Gtk.Image() |
---|
57 | image.set_from_stock(Gtk.STOCK_ADD,Gtk.IconSize.MENU) |
---|
58 | self.add_new_profile_button=builder.get_object("add_new_profile_button") |
---|
59 | self.add_new_profile_button.set_image(image) |
---|
60 | self.new_profile_window=builder.get_object("new_profile_window") |
---|
61 | self.profile_label=builder.get_object("profile_label") |
---|
62 | self.profile_entry=builder.get_object("profile_entry") |
---|
63 | self.email_label=builder.get_object("email_label") |
---|
64 | self.email_entry=builder.get_object("email_entry") |
---|
65 | self.mountpoint_label=builder.get_object("mountpoint_label") |
---|
66 | self.mountpoint_entry=builder.get_object("mountpoint_entry") |
---|
67 | self.automount_label=builder.get_object("automount_label") |
---|
68 | self.automount_entry=builder.get_object("automount_entry") |
---|
69 | self.profile_msg=builder.get_object("profile_msg") |
---|
70 | self.profile_pbar=builder.get_object("profile_pbar") |
---|
71 | self.accept_add_profile_button=builder.get_object("accept_add_profile_button") |
---|
72 | self.cancel_add_profile_button=builder.get_object("cancel_add_profile_button") |
---|
73 | |
---|
74 | |
---|
75 | |
---|
76 | self.pack_start(self.main_box,True,True,0) |
---|
77 | self.connect_signals() |
---|
78 | self.set_css_info() |
---|
79 | |
---|
80 | self.current_status={} |
---|
81 | self.edition=False |
---|
82 | self.profile_pbar.hide() |
---|
83 | |
---|
84 | self.init_threads() |
---|
85 | |
---|
86 | #self.current_var=None |
---|
87 | #self.current_id=None |
---|
88 | |
---|
89 | #self.thread=threading.Thread() |
---|
90 | #self.thread_ret=None |
---|
91 | |
---|
92 | #def __init__ |
---|
93 | |
---|
94 | def init_threads(self): |
---|
95 | |
---|
96 | self.create_profile_t=multiprocessing.Process(target=self.create_profile) |
---|
97 | self.create_mountpoint_t=threading.Thread(target=self.create_mountpoint) |
---|
98 | self.edit_profile_t=threading.Thread(target=self.edit_profile) |
---|
99 | |
---|
100 | |
---|
101 | self.create_profile_t.daemon=True |
---|
102 | self.create_mountpoint_t.daemon=True |
---|
103 | self.edit_profile_t.daemon=True |
---|
104 | |
---|
105 | self.create_mountpoint_t.done=False |
---|
106 | self.edit_profile_t.done=False |
---|
107 | |
---|
108 | self.create_profile_t.launched=False |
---|
109 | self.create_mountpoint_t.launched=False |
---|
110 | self.edit_profile_t.launched=False |
---|
111 | |
---|
112 | GObject.threads_init() |
---|
113 | |
---|
114 | |
---|
115 | def set_css_info(self): |
---|
116 | |
---|
117 | self.style_provider=Gtk.CssProvider() |
---|
118 | |
---|
119 | f=Gio.File.new_for_path(CSS_FILE) |
---|
120 | self.style_provider.load_from_file(f) |
---|
121 | |
---|
122 | Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(),self.style_provider,Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) |
---|
123 | self.profiles_list_label.set_name("OPTION_LABEL") |
---|
124 | self.profile_label.set_name("OPTION_LABEL") |
---|
125 | self.email_label.set_name("OPTION_LABEL") |
---|
126 | self.mountpoint_label.set_name("OPTION_LABEL") |
---|
127 | self.automount_label.set_name("OPTION_LABEL") |
---|
128 | self.msg_label.set_name("MSG_LABEL") |
---|
129 | self.profile_msg.set_name("MSG_LABEL") |
---|
130 | |
---|
131 | |
---|
132 | |
---|
133 | #def set-css_info |
---|
134 | |
---|
135 | |
---|
136 | def connect_signals(self): |
---|
137 | |
---|
138 | self.add_new_profile_button.connect("clicked",self.add_new_profile_button_clicked) |
---|
139 | self.accept_add_profile_button.connect("clicked",self.accept_add_profile_clicked) |
---|
140 | self.cancel_add_profile_button.connect("clicked",self.cancel_add_profile_clicked) |
---|
141 | self.new_profile_window.connect("delete_event",self.hide_window) |
---|
142 | |
---|
143 | |
---|
144 | #def connect_signals |
---|
145 | |
---|
146 | def load_info(self,info): |
---|
147 | |
---|
148 | self.profiles_info=info |
---|
149 | |
---|
150 | for item in self.profiles_info: |
---|
151 | profile=item |
---|
152 | email=self.profiles_info[item]["email"] |
---|
153 | mountpoint=self.profiles_info[item]["mountpoint"] |
---|
154 | self.new_profile_button(profile,email,mountpoint) |
---|
155 | print self.profiles_info[item]["automount"] |
---|
156 | |
---|
157 | |
---|
158 | print self.profiles_info |
---|
159 | |
---|
160 | #def load_info() |
---|
161 | |
---|
162 | def hide_window(self,widget,event): |
---|
163 | |
---|
164 | widget.hide() |
---|
165 | return True |
---|
166 | |
---|
167 | #def hide_window |
---|
168 | |
---|
169 | def init_profile_dialog_button(self): |
---|
170 | |
---|
171 | self.accept_add_profile_button.show() |
---|
172 | image = Gtk.Image() |
---|
173 | image.set_from_stock(Gtk.STOCK_CANCEL,Gtk.IconSize.MENU) |
---|
174 | self.cancel_add_profile_button.set_image(image) |
---|
175 | self.cancel_add_profile_button.set_label(_("Cancel")) |
---|
176 | self.cancel_add_profile_button.show() |
---|
177 | |
---|
178 | #def init_profile_dialog_button |
---|
179 | |
---|
180 | def disable_entry_profile_dialog(self): |
---|
181 | |
---|
182 | self.profile_entry.set_editable(False) |
---|
183 | self.email_entry.set_editable(False) |
---|
184 | self.mountpoint_entry.set_sensitive(False) |
---|
185 | self.automount_entry.set_sensitive(False) |
---|
186 | |
---|
187 | #def disable_entry_profile_dialog |
---|
188 | |
---|
189 | def enable_entry_profile_dialog(self): |
---|
190 | |
---|
191 | if not self.edition: |
---|
192 | self.profile_entry.set_editable(True) |
---|
193 | self.email_entry.set_editable(True) |
---|
194 | |
---|
195 | else: |
---|
196 | self.profile_entry.set_editable(False) |
---|
197 | self.email_entry.set_editable(False) |
---|
198 | |
---|
199 | self.mountpoint_entry.set_sensitive(True) |
---|
200 | self.automount_entry.set_sensitive(True) |
---|
201 | |
---|
202 | #def enable_entry_profile_dialog |
---|
203 | |
---|
204 | def change_cancel_button(self): |
---|
205 | |
---|
206 | image = Gtk.Image() |
---|
207 | image.set_from_stock(Gtk.STOCK_CLOSE,Gtk.IconSize.MENU) |
---|
208 | self.cancel_add_profile_button.set_image(image) |
---|
209 | self.cancel_add_profile_button.set_label(_("Close")) |
---|
210 | self.cancel_add_profile_button.show() |
---|
211 | |
---|
212 | #def change_cancel_button |
---|
213 | |
---|
214 | def add_new_profile_button_clicked(self,widget): |
---|
215 | |
---|
216 | self.edition=False |
---|
217 | |
---|
218 | self.enable_entry_profile_dialog() |
---|
219 | self.profile_entry.set_text("") |
---|
220 | self.email_entry.set_text("") |
---|
221 | self.mountpoint_entry.set_filename(os.environ["HOME"]) |
---|
222 | self.automount_entry.set_active(False) |
---|
223 | self.profile_msg.set_text("") |
---|
224 | |
---|
225 | |
---|
226 | self.init_threads() |
---|
227 | |
---|
228 | self.msg_label.set_text("") |
---|
229 | self.profile_msg.hide() |
---|
230 | self.profile_pbar.hide() |
---|
231 | self.init_profile_dialog_button() |
---|
232 | self.new_profile_window.show() |
---|
233 | |
---|
234 | |
---|
235 | #def add_new_profile_button_clicked |
---|
236 | |
---|
237 | def delete_profile_clicked(self,button,hbox): |
---|
238 | |
---|
239 | self.msg_label.set_text("") |
---|
240 | profile=hbox.get_children()[1].get_text().split("\n")[0] |
---|
241 | profile=profile.decode("utf-8") |
---|
242 | self.profiles_info.pop(profile) |
---|
243 | |
---|
244 | delete=self.core.LliurexGoogleDriveManager.delete_profile(self.profiles_info,profile) |
---|
245 | self.msg_label.show() |
---|
246 | |
---|
247 | if delete: |
---|
248 | self.profile_msg.set_name("MSG_LABEL") |
---|
249 | self.msg_label.set_text(MSG_CHANGE_SUCCESS) |
---|
250 | self.profile_list_box.remove(hbox) |
---|
251 | else: |
---|
252 | self.msg_label.set_name("MSG_ERROR_LABEL") |
---|
253 | self.msg_label.set_text(MSG_CHANGE_ERROR) |
---|
254 | |
---|
255 | self.profiles_info=self.core.LliurexGoogleDriveManager.profiles_config.copy() |
---|
256 | |
---|
257 | |
---|
258 | # def delete_profile_clicked |
---|
259 | |
---|
260 | |
---|
261 | def sync_profile_clicked(self,button,hbox): |
---|
262 | |
---|
263 | self.msg_label.set_text("") |
---|
264 | profile=hbox.get_children()[1].get_text().split("\n")[0] |
---|
265 | mountpoint=hbox.get_children()[3].get_text() |
---|
266 | status_info=self.core.LliurexGoogleDriveManager.check_mountpoint_status(mountpoint) |
---|
267 | self.msg_label.show() |
---|
268 | self.msg_label.set_name("MSG_LABEL") |
---|
269 | if self.current_status[profile]==status_info["status"]: |
---|
270 | |
---|
271 | status_mod=self.core.LliurexGoogleDriveManager.sync_profile(profile,mountpoint) |
---|
272 | if status_mod["result"]: |
---|
273 | status_info=self.core.LliurexGoogleDriveManager.check_mountpoint_status(mountpoint) |
---|
274 | self.msg_label.set_text(MSG_CHANGE_SUCCESS) |
---|
275 | # if status_mod["action"]=="Mount": |
---|
276 | # mount_image=Gtk.Image.new_from_file(MOUNT_ON_IMAGE) |
---|
277 | # button.set_tooltip_text(_("Dismount profile")) |
---|
278 | # button.set_name("MOUNT_ITEM_BUTTON") |
---|
279 | # else: |
---|
280 | # mount_image=Gtk.Image.new_from_file(MOUNT_OFF_IMAGE) |
---|
281 | # button.set_tooltip_text(_("Mount profile")) |
---|
282 | # button.set_name("DELETE_ITEM_BUTTON") |
---|
283 | |
---|
284 | else: |
---|
285 | self.msg_label.set_name("MSG_ERROR_LABEL") |
---|
286 | self.msg_label.set_text(MSG_CHANGE_ERROR) |
---|
287 | |
---|
288 | |
---|
289 | |
---|
290 | info=self.item_status_info(status_info) |
---|
291 | self.current_status[profile]=status_info["status"] |
---|
292 | button.set_tooltip_text(info["tooltip"]) |
---|
293 | button.set_name(info["css"]) |
---|
294 | hbox.get_children()[4].set_image(info["img"]) |
---|
295 | |
---|
296 | |
---|
297 | #def mount_profile_clicked |
---|
298 | |
---|
299 | def edit_profile_clicked(self,button,hbox): |
---|
300 | |
---|
301 | self.edition=True |
---|
302 | self.enable_entry_profile_dialog() |
---|
303 | |
---|
304 | self.profile_to_edit=hbox |
---|
305 | profile=self.profile_to_edit.get_children()[1].get_text().split("\n")[0] |
---|
306 | self.profile_entry.set_text(profile) |
---|
307 | #self.profile_entry.set_editable(False) |
---|
308 | email=self.profile_to_edit.get_children()[1].get_text().split("\n")[1] |
---|
309 | self.email_entry.set_text(email) |
---|
310 | #self.email_entry.set_editable(False) |
---|
311 | mountpoint=self.profile_to_edit.get_children()[3].get_text() |
---|
312 | self.mountpoint_entry.set_filename(mountpoint) |
---|
313 | automount=self.profiles_info[profile.decode("utf-8")]["automount"] |
---|
314 | self.automount_entry.set_active(automount) |
---|
315 | |
---|
316 | |
---|
317 | self.init_threads() |
---|
318 | |
---|
319 | self.profile_msg.hide() |
---|
320 | self.profile_pbar.hide() |
---|
321 | self.msg_label.set_text("") |
---|
322 | self.init_profile_dialog_button() |
---|
323 | self.new_profile_window.show() |
---|
324 | |
---|
325 | #def edit_profile_clicked |
---|
326 | |
---|
327 | |
---|
328 | def new_profile_button(self,profile_name,email,mountpoint): |
---|
329 | |
---|
330 | hbox=Gtk.HBox() |
---|
331 | profile_image=Gtk.Image.new_from_file(PROFILE_IMAGE) |
---|
332 | profile_image.set_margin_left(10) |
---|
333 | profile_image.set_halign(Gtk.Align.CENTER) |
---|
334 | profile_image.set_valign(Gtk.Align.CENTER) |
---|
335 | profile_info="<span font='Roboto'><b>"+profile_name+"</b></span>\n"+"<span font='Roboto'>"+email+"</span>" |
---|
336 | profile=Gtk.Label() |
---|
337 | profile.set_markup(profile_info) |
---|
338 | profile.set_margin_left(5) |
---|
339 | profile.set_margin_right(15) |
---|
340 | profile.set_margin_top(21) |
---|
341 | profile.set_margin_bottom(21) |
---|
342 | folder_image=Gtk.Image.new_from_file(FOLDER_IMAGE) |
---|
343 | folder_image.set_margin_left(20) |
---|
344 | folder_image.set_halign(Gtk.Align.CENTER) |
---|
345 | folder_image.set_valign(Gtk.Align.CENTER) |
---|
346 | folder=Gtk.Label() |
---|
347 | folder.set_text(mountpoint) |
---|
348 | folder.set_margin_left(10) |
---|
349 | delete=Gtk.Button() |
---|
350 | delete_image=Gtk.Image.new_from_file(DELETE_IMAGE) |
---|
351 | delete.add(delete_image) |
---|
352 | delete.set_halign(Gtk.Align.CENTER) |
---|
353 | delete.set_valign(Gtk.Align.CENTER) |
---|
354 | delete.set_name("DELETE_ITEM_BUTTON") |
---|
355 | delete.connect("clicked",self.delete_profile_clicked,hbox) |
---|
356 | delete.set_tooltip_text(_("Delete profile")) |
---|
357 | edit=Gtk.Button() |
---|
358 | edit_image=Gtk.Image.new_from_file(EDIT_IMAGE) |
---|
359 | edit.add(edit_image) |
---|
360 | edit.set_halign(Gtk.Align.CENTER) |
---|
361 | edit.set_valign(Gtk.Align.CENTER) |
---|
362 | edit.set_name("EDIT_ITEM_BUTTON") |
---|
363 | edit.connect("clicked",self.edit_profile_clicked,hbox) |
---|
364 | edit.set_tooltip_text(_("Edit profile")) |
---|
365 | mount=Gtk.Button() |
---|
366 | |
---|
367 | status_info=self.core.LliurexGoogleDriveManager.check_mountpoint_status(mountpoint) |
---|
368 | self.current_status[profile_name]=status_info["status"] |
---|
369 | print self.current_status |
---|
370 | info=self.item_status_info(status_info) |
---|
371 | # if status["status"]: |
---|
372 | # mount_image=Gtk.Image.new_from_file(MOUNT_ON_IMAGE) |
---|
373 | # mount.set_tooltip_text(_("Dismount profile")) |
---|
374 | # mount.set_name("MOUNT_ITEM_BUTTON") |
---|
375 | |
---|
376 | # else: |
---|
377 | # mount_image=Gtk.Image.new_from_file(MOUNT_OFF_IMAGE) |
---|
378 | # mount.set_tooltip_text(_("Mount profile")) |
---|
379 | # mount.set_name("DELETE_ITEM_BUTTON") |
---|
380 | mount_image=info["img"] |
---|
381 | mount.set_tooltip_text(info["tooltip"]) |
---|
382 | mount.set_name(info["css"]) |
---|
383 | mount.add(mount_image) |
---|
384 | mount.set_halign(Gtk.Align.CENTER) |
---|
385 | mount.set_valign(Gtk.Align.CENTER) |
---|
386 | #mount.set_name("MOUNT_ITEM_BUTTON") |
---|
387 | mount.connect("clicked",self.sync_profile_clicked,hbox) |
---|
388 | |
---|
389 | hbox.pack_start(profile_image,False,False,0) |
---|
390 | hbox.pack_start(profile,False,False,0) |
---|
391 | hbox.pack_start(folder_image,False,False,0) |
---|
392 | hbox.pack_start(folder,False,False,0) |
---|
393 | hbox.pack_end(delete,False,False,10) |
---|
394 | hbox.pack_end(edit,False,False,10) |
---|
395 | hbox.pack_end(mount,False,False,10) |
---|
396 | hbox.show_all() |
---|
397 | hbox.set_name("PROFILE_BOX") |
---|
398 | self.profile_list_box.pack_start(hbox,False,False,5) |
---|
399 | self.profile_list_box.queue_draw() |
---|
400 | hbox.queue_draw() |
---|
401 | |
---|
402 | #def new_profile_button |
---|
403 | |
---|
404 | def item_status_info(self,status_info): |
---|
405 | |
---|
406 | size=status_info["size"] |
---|
407 | used=status_info["used%"] |
---|
408 | |
---|
409 | if status_info["status"]: |
---|
410 | img=Gtk.Image.new_from_file(MOUNT_ON_IMAGE) |
---|
411 | tooltip=_("Dismount now") |
---|
412 | css="MOUNT_ITEM_BUTTON" |
---|
413 | |
---|
414 | else: |
---|
415 | img=Gtk.Image.new_from_file(MOUNT_ON_IMAGE) |
---|
416 | tooltip=_("Mount now") |
---|
417 | css="DELETE_ITEM_BUTTON" |
---|
418 | |
---|
419 | return {"img":img ,"tooltip":tooltip, "css":css} |
---|
420 | |
---|
421 | #def item_status_info |
---|
422 | |
---|
423 | def accept_add_profile_clicked(self,widget): |
---|
424 | |
---|
425 | self.disable_entry_profile_dialog() |
---|
426 | |
---|
427 | profile=self.profile_entry.get_text() |
---|
428 | |
---|
429 | self.new_profile=profile.strip(" ").decode("utf-8") |
---|
430 | email=self.email_entry.get_text() |
---|
431 | self.new_email=email.strip(" ") |
---|
432 | self.new_mountpoint=self.mountpoint_entry.get_filename().decode("utf-8") |
---|
433 | self.new_automount=self.automount_entry.get_state() |
---|
434 | |
---|
435 | check_form=self.check_profile_info() |
---|
436 | self.profile_msg.show() |
---|
437 | |
---|
438 | if check_form["result"]: |
---|
439 | self.profiles_info[self.new_profile]={} |
---|
440 | self.profiles_info[self.new_profile]["email"]=self.new_email |
---|
441 | self.profiles_info[self.new_profile]["mountpoint"]=self.new_mountpoint |
---|
442 | self.profiles_info[self.new_profile]["automount"]=self.new_automount |
---|
443 | self.profile_msg.set_name("MSG_LABEL") |
---|
444 | if not self.edition: |
---|
445 | if not self.create_profile_t.launched: |
---|
446 | self.profile_msg.set_text(_("Connecting with google to get account access...")) |
---|
447 | self.profile_pbar.show() |
---|
448 | self.retry=0 |
---|
449 | GLib.timeout_add(100,self.pulsate_add_profile) |
---|
450 | |
---|
451 | |
---|
452 | else: |
---|
453 | if not self.edit_profile_t.launched: |
---|
454 | self.profile_msg.set_text(_("Apply changes")) |
---|
455 | self.profile_pbar.show() |
---|
456 | GLib.timeout_add(100,self.pulsate_edit_profile) |
---|
457 | else: |
---|
458 | self.profile_msg.set_name("MSG_ERROR_LABEL") |
---|
459 | self.profile_msg.set_text(check_form["msg"]) |
---|
460 | self.enable_entry_profile_dialog() |
---|
461 | |
---|
462 | |
---|
463 | |
---|
464 | |
---|
465 | #def accept_add_profile_clicked |
---|
466 | |
---|
467 | def check_profile_info(self): |
---|
468 | |
---|
469 | msg_check="" |
---|
470 | |
---|
471 | check_form=self.core.LliurexGoogleDriveManager.check_profile_info(self.new_profile,self.new_mountpoint,self.edition) |
---|
472 | |
---|
473 | if not check_form["result"]: |
---|
474 | if check_form["code"]==1: |
---|
475 | msg_check=_("You must indicate a profile") |
---|
476 | |
---|
477 | else: |
---|
478 | if check_form["code"]==2: |
---|
479 | msg_check=_("Profile already exists") |
---|
480 | else: |
---|
481 | msg_check=_("Mounting point already used by another profile") |
---|
482 | |
---|
483 | |
---|
484 | return {"result":check_form["result"],"msg":msg_check} |
---|
485 | |
---|
486 | #def check_profile_info |
---|
487 | |
---|
488 | def pulsate_add_profile(self): |
---|
489 | |
---|
490 | self.retry=self.retry+1 |
---|
491 | self.profile_pbar.pulse() |
---|
492 | |
---|
493 | if not self.create_profile_t.launched: |
---|
494 | self.accept_add_profile_button.hide() |
---|
495 | self.cancel_add_profile_button.hide() |
---|
496 | |
---|
497 | self.create_profile_t.start() |
---|
498 | self.create_profile_t.launched=True |
---|
499 | |
---|
500 | if not self.create_profile_t.is_alive(): |
---|
501 | if not self.create_mountpoint_t.launched: |
---|
502 | self.profile_msg.set_name("MSG_LABEL") |
---|
503 | self.profile_msg.set_text(_("Creating profile... ")) |
---|
504 | self.create_mountpoint_t.start() |
---|
505 | self.create_mountpoint_t.launched=True |
---|
506 | |
---|
507 | if self.create_mountpoint_t.done: |
---|
508 | self.profile_pbar.hide() |
---|
509 | if self.create_result: |
---|
510 | self.new_profile_button(self.new_profile,self.new_email,self.new_mountpoint) |
---|
511 | self.profiles_info=self.core.LliurexGoogleDriveManager.profiles_config.copy() |
---|
512 | self.profile_msg.set_text(_("Profile created successfully")) |
---|
513 | self.change_cancel_button() |
---|
514 | |
---|
515 | else: |
---|
516 | |
---|
517 | self.profile_msg.set_name("MSG_ERROR_LABEL") |
---|
518 | self.profile_msg.set_text(_("An error ocurred creating profile. See log file for more information")) |
---|
519 | self.cancel_add_profile_button.show() |
---|
520 | |
---|
521 | |
---|
522 | return False |
---|
523 | |
---|
524 | if self.create_profile_t.launched: |
---|
525 | if self.create_profile_t.is_alive(): |
---|
526 | self.kill_create_profile() |
---|
527 | return True |
---|
528 | |
---|
529 | |
---|
530 | if self.create_mountpoint_t.launched: |
---|
531 | if not self.create_mountpoint_t.done: |
---|
532 | return True |
---|
533 | |
---|
534 | #def_pulsate_add_profile |
---|
535 | |
---|
536 | def kill_create_profile(self): |
---|
537 | |
---|
538 | if self.retry>MAX_RETRY_INTENTS: |
---|
539 | parent=psutil.Process(self.create_profile_t.pid) |
---|
540 | for child in parent.children(recursive=True): |
---|
541 | child.kill() |
---|
542 | self.create_profile_t.terminate() |
---|
543 | self.profile_msg.set_name("MSG_ERROR_LABEL") |
---|
544 | self.profile_msg.set_text(_("Error getting authorization")) |
---|
545 | |
---|
546 | return True |
---|
547 | |
---|
548 | #def kill_create_profile |
---|
549 | |
---|
550 | def create_profile(self): |
---|
551 | |
---|
552 | result=self.core.LliurexGoogleDriveManager.create_profile(self.new_profile) |
---|
553 | |
---|
554 | #def create_profile |
---|
555 | |
---|
556 | def create_mountpoint(self): |
---|
557 | |
---|
558 | self.create_result=self.core.LliurexGoogleDriveManager.create_mountpoint(self.profiles_info,self.new_profile) |
---|
559 | self.create_mountpoint_t.done=True |
---|
560 | |
---|
561 | #def create_mountpoint |
---|
562 | |
---|
563 | def pulsate_edit_profile(self): |
---|
564 | |
---|
565 | if not self.edit_profile_t.launched: |
---|
566 | self.edit_profile_t.start() |
---|
567 | self.edit_profile_t.launched=True |
---|
568 | self.accept_add_profile_button.hide() |
---|
569 | self.cancel_add_profile_button.hide() |
---|
570 | |
---|
571 | if self.edit_profile_t.done: |
---|
572 | self.profile_pbar.hide() |
---|
573 | if self.edit_result: |
---|
574 | self.profile_msg.set_name("MSG_LABEL") |
---|
575 | self.profile_to_edit.get_children()[3].set_text(self.new_mountpoint) |
---|
576 | self.profiles_info=self.core.LliurexGoogleDriveManager.profiles_config.copy() |
---|
577 | self.profile_msg.set_text(MSG_CHANGE_SUCCESS) |
---|
578 | self.change_cancel_button() |
---|
579 | |
---|
580 | else: |
---|
581 | self.profile_msg.set_name("MSG_ERROR_LABEL") |
---|
582 | self.profile_msg.set_text(MSG_CHANGE_ERROR) |
---|
583 | self.cancel_add_profile_button.show() |
---|
584 | return False |
---|
585 | |
---|
586 | |
---|
587 | if self.edit_profile_t.launched: |
---|
588 | if not self.edit_profile_t.done: |
---|
589 | return True |
---|
590 | |
---|
591 | #def pulsate_edit_profile |
---|
592 | |
---|
593 | def edit_profile(self): |
---|
594 | |
---|
595 | self.edit_result=self.core.LliurexGoogleDriveManager.edit_profile(self.profiles_info,self.new_profile) |
---|
596 | self.edit_profile_t.done=True |
---|
597 | |
---|
598 | #def edit_profile |
---|
599 | |
---|
600 | def cancel_add_profile_clicked(self,widget): |
---|
601 | |
---|
602 | self.new_profile_window.hide() |
---|
603 | |
---|
604 | |
---|
605 | #def cancel_add_profile_clicked |
---|
606 | |
---|
607 | #class profilebox |
---|