def main(program_paths): DBusGMainLoop(set_as_default=True) config = Configuration() mediator = ConfigMediator(program_paths, config) mediator.show_all() gtk.main()
def on_show_config_dialog(self, widget): if self.config_dialog is None: class ProgramPaths(object): def __init__(self): self.COZY_BACKUP_APPLET_PATH = 'cozy-backup-applet' self.COZY_BACKUP_PATH = 'cozy-backup' self.config_dialog = ConfigMediator(ProgramPaths(), self.config, self.on_config_dialog_closed) self.config_dialog.present()
class CozyIcon(gtk.StatusIcon): def __init__(self, config, restore_backend, notification_service, mainloop, restore_client_connector, restore_control_center, location_manager): gtk.StatusIcon.__init__(self) self.notification_service = notification_service self.mainloop = mainloop self.config = config self.restore_client_connector = restore_client_connector self.restore_control_center = restore_control_center self.location_manager = location_manager self.restore_backend = restore_backend self.restore_backend.connect_to_signal('available', self.__on_backup_location_available) self.restore_backend.connect_to_signal('unavailable', self.__on_backup_location_unavailable) self.config_dialog = None self.restore_frontend = None self.__create_settings_and_exit_menu() self.__update_backup_availability() self.connect_object("popup-menu", CozyIcon.__on_popup_right_click_menu, self) self.connect_object("activate", CozyIcon.__on_popup_left_click_menu, self) if not self.config.backup_enabled: self.on_show_config_dialog(None) def __update_backup_availability(self): if self.restore_backend.is_backup_location_available(): self.__on_backup_location_available() else: self.__on_backup_location_unavailable() def __on_backup_location_available(self): self.set_from_icon_name(COZY_ICON_NAME) self.__create_available_menu() def __on_backup_location_unavailable(self): self.set_from_icon_name(COZY_ICON_NAME_UNAVAILABLE) self.__create_unavailable_menu() def __create_available_menu(self): self.left_click_menu = gtk.Menu() menu_item = gtk.MenuItem('Start Backup') self.left_click_menu.append(menu_item) menu_item.connect_object("activate", CozyIcon.on_start_backup, self) menu_item.show() menu_item = gtk.MenuItem('Start Restore Session...') self.left_click_menu.append(menu_item) menu_item.connect_object("activate", CozyIcon.on_start_restore_session, self) menu_item.show() def __create_unavailable_menu(self): self.left_click_menu = gtk.Menu() menu_item = gtk.MenuItem('Start Backup') self.left_click_menu.append(menu_item) menu_item.set_sensitive(False) menu_item.show() menu_item = gtk.MenuItem('Start Restore Session...') self.left_click_menu.append(menu_item) menu_item.set_sensitive(False) menu_item.show() def __create_settings_and_exit_menu(self): self.right_click_menu = gtk.Menu() menu_item = gtk.MenuItem('Settings...') self.right_click_menu.append(menu_item) menu_item.connect_object("activate", CozyIcon.on_show_config_dialog, self, 'Settings') menu_item.show() menu_item = gtk.MenuItem('About') self.right_click_menu.append(menu_item) menu_item.connect_object("activate", CozyIcon.on_about, self, 'About') menu_item.show() menu_item = gtk.MenuItem('Exit') self.right_click_menu.append(menu_item) menu_item.connect_object("activate", CozyIcon.on_exit, self, 'Exit') menu_item.show() def __show_message(self, title, message): menu = gtk.Menu() (x, y, p) = gtk.status_icon_position_menu(menu, self) self.notification_service.Notify("", 12, "", title, message, list(), {'x': x, 'y': y}, -1) def delete_event(self, widget, event): return False def on_show_config_dialog(self, widget): if self.config_dialog is None: class ProgramPaths(object): def __init__(self): self.COZY_BACKUP_APPLET_PATH = 'cozy-backup-applet' self.COZY_BACKUP_PATH = 'cozy-backup' self.config_dialog = ConfigMediator(ProgramPaths(), self.config, self.on_config_dialog_closed) self.config_dialog.present() def on_config_dialog_closed(self): self.config_dialog = None if not self.config.backup_enabled: self.mainloop.quit() else: backup_location = self.location_manager.get_backup_location(self.config) self.restore_backend.set_backup_location(backup_location) self.__update_backup_availability() if self.config.backup_location_type == 'absolute_path': message = "Your data will backed up automatically every full hour. " + \ "Whenever you would like to back up your data manually, click on the Symbol." else: message = "Whenever you would like to back up your data, click on the Symbol." self.__show_message("Finished Cozy Configuration", message) def on_about(self, widget): print 'FIXME: make about dialog' def on_exit(self, widget): self.mainloop.quit() def on_start_backup(self): cozy.back_up.back_up() def on_start_restore_session(self): class RestoreSessionThread(threading.Thread): def __init__(self, restore_client_connector, restore_control_center): threading.Thread.__init__(self) self.restore_client_connector = restore_client_connector self.restore_control_center = restore_control_center def run(self): restore_client = self.restore_client_connector.get_restore_client() self.restore_control_center.set_restore_client(restore_client) if self.restore_frontend is None: self.restore_frontend = RestoreFrontend(self.restore_control_center, self.on_restore_session_close) self.restore_session = RestoreSessionThread(self.restore_client_connector, self.restore_control_center) self.restore_session.start() def on_restore_session_close(self): self.restore_control_center.go_to_present() self.restore_frontend = None def __on_popup_left_click_menu(self): self.left_click_menu.popup(None, None, gtk.status_icon_position_menu, 0, gtk.get_current_event_time(), self) def __on_popup_right_click_menu(self, button, activate_time): self.right_click_menu.popup(None, None, gtk.status_icon_position_menu, 0, gtk.get_current_event_time(), self)