Ejemplo n.º 1
0
    def on_recover_button_clicked(self, widget):
        model, iter = self.list_selection.get_selected()

        if iter:
            list_path = model[iter][0]
            list_name = model[iter][1]

            backup_iter = self.backup_combobox.get_active_iter()

            if backup_iter:
                backup_path = self.backup_model[backup_iter][0]
                backup_name = self.backup_model[backup_iter][1]

                dialog = QuestionDialog(message=_('Would you like to recover the '
                                        'backup "<b>%(backup_name)s</b>" for "<b>%(list_name)s</b>"?') % \
                                                {'backup_name': backup_name,
                                                 'list_name': list_name})
                response = dialog.run()
                dialog.destroy()

                if response == Gtk.ResponseType.YES:
                    if proxy.restore_source(backup_path, list_path):
                        self.infobar.response(Gtk.ResponseType.CLOSE)
                    else:
                        ErrorDialog(title=_('Recovery Failed!'),
                                    message=_(
                                        'You may need to check the permission '
                                        'of source list.')).launch()
Ejemplo n.º 2
0
 def on_restart_button_clicked(self, widget):
     global SYSTEM_DIR, USER_DIR
     SYSTEM_DIR, USER_DIR = update_dir()
     if is_right_path():
         self.remove_all_children()
         self.create_interface()
     else:
         ErrorDialog(message=_('The templates path is still incorrect, please reset it!')).launch()
Ejemplo n.º 3
0
def show_message(*args):
    from ubuntutweak.gui.dialogs import ErrorDialog
    message = _(
        'The Ubuntu Tweak daemon didn\'t start correctly. This means that some '
        'advanced features may not work.\n'
        'If you want to help developers debugging, try to run "<b>sudo /usr/share/ubuntu-tweak/ubuntu-tweak-daemon</b>" in a terminal.'
    )
    ErrorDialog(message=message).launch()
Ejemplo n.º 4
0
def open_bug_report():
    if system.is_supported():
        webbrowser.open('https://bugs.launchpad.net/ubuntu-tweak/+filebug')
    else:
        from ubuntutweak.gui.dialogs import ErrorDialog
        ErrorDialog(
            title=_(
                "Sorry, your distribution is not supported by Ubuntu Tweak"),
            message=
            _("You can't file bug for this issue. Please only use Ubuntu Tweak on Ubuntu. Or it may kill your cat."
              )).launch()
Ejemplo n.º 5
0
    def on_source_data_downloaded(self, widget):
        path = widget.get_downloaded_file()
        tarfile = utdata.create_tarfile(path)

        if tarfile.is_valid():
            tarfile.extract(consts.CONFIG_ROOT)
            self.update_source_data()
            utdata.save_synced_timestamp(SOURCE_ROOT)
            self.update_timestamp()
        else:
            ErrorDialog(
                _('An error occurred whilst downloading the file')).launch()
Ejemplo n.º 6
0
    def on_rename_item(self, widget):
        model, iter = self.get_selection().get_selected()
        filepath = model.get_value(iter, self.DIR_PATH)

        if filepath != self.dir:
            model.set_value(iter, self.DIR_EDITABLE, True)

            column = self.get_column(0)
            path = self.model.get_path(iter)
            self.set_cursor(path, column, True)
        else:
            ErrorDialog(_("Can't rename the root folder")).launch()
Ejemplo n.º 7
0
    def on_app_data_downloaded(self, widget):
        log.debug("on_app_data_downloaded")
        path = widget.get_downloaded_file()
        tarfile = utdata.create_tarfile(path)

        if tarfile.is_valid():
            tarfile.extract(consts.CONFIG_ROOT)
            self.update_app_data()
            utdata.save_synced_timestamp(APPCENTER_ROOT)
            self.update_timestamp()
        else:
            ErrorDialog(_('An error occurred while downloading the file.')).launch()
Ejemplo n.º 8
0
    def on_cellrenderer_edited(self, cellrenderertext, path, new_text):
        iter = self.model.get_iter_from_string(path)
        filepath = self.model.get_value(iter, self.DIR_PATH)
        old_text = self.model.get_value(iter, self.DIR_TITLE)

        if old_text == new_text or new_text not in os.listdir(os.path.dirname(filepath)):
            newpath = os.path.join(os.path.dirname(filepath), new_text)
            os.rename(filepath, newpath)
            self.model.set_value(iter, self.DIR_TITLE, new_text)
            self.model.set_value(iter, self.DIR_PATH, newpath)
            self.model.set_value(iter, self.DIR_EDITABLE, False)
        else:
            ErrorDialog(_("Can't rename!\n\nThere are files in it!")).launch()
Ejemplo n.º 9
0
    def on_backup_button_clicked(self, widget):
        model, iter = self.list_selection.get_selected()

        if iter:
            path = model[iter][0]

            dialog = GetTextDialog(
                message=_('Please enter the name for your backup:'),
                text=self.get_time_stamp())
            response = dialog.run()
            dialog.destroy()
            backup_name = dialog.get_text()

            if response == Gtk.ResponseType.YES and backup_name:
                if self.is_valid_backup_name(backup_name):
                    if proxy.backup_source(path, backup_name):
                        self.update_backup_model()
                    else:
                        ErrorDialog(message=_('Backup Failed!')).launch()
                else:
                    ErrorDialog(message=_(
                        'Please only use alphanumeric characters'
                        ' and "_" and "-".'),
                                title=_('Backup name is invalid')).launch()
Ejemplo n.º 10
0
    def on_save_button_clicked(self, widget):
        text = self.textview.get_text().strip()

        if self.auto_backup_setting.get_value():
            proxy.backup_source(self.textview.get_path(),
                                self.get_time_stamp())
            self.update_backup_model()

        if proxy.edit_source(self.textview.get_path(), text) == 'error':
            ErrorDialog(message=_('Please check the permission of the '
                                  'sources.list file'),
                        title=_('Save failed!')).launch()
        else:
            self.save_button.set_sensitive(False)
            self.redo_button.set_sensitive(False)
Ejemplo n.º 11
0
    def on_delete_item(self, widget):
        model, iter = self.get_selection().get_selected()
        if not iter:
            return
        filepath = model.get_value(iter, self.DIR_PATH)

        if filepath != self.dir:
            if os.path.isdir(filepath):
                shutil.rmtree(filepath)
            else:
                os.remove(filepath)

            self.emit('deleted')
            self.update_model()
        else:
            ErrorDialog(_("Can't delete the root folder")).launch()
Ejemplo n.º 12
0
    def on_delete_button_clicked(self, widget):
        if self.textview.get_path() == SOURCES_LIST:
            ErrorDialog(_('You can\'t delete sources.list!')).launch()
        else:
            dialog = QuestionDialog(message=_(
                'The "%s" will be deleted!\nDo you wish to continue?') %
                                    self.textview.get_path())
            response = dialog.run()
            dialog.destroy()
            if response == Gtk.ResponseType.YES:
                model, iter = self.list_selection.get_selected()

                if iter:
                    list_path = model[iter][0]
                    proxy.delete_source(list_path)
                    self.update_source_model()
                    self.update_backup_model()
Ejemplo n.º 13
0
    def on_backup_edit_button_clicked(self, widget):
        iter = self.backup_combobox.get_active_iter()
        path = self.backup_model[iter][0]
        name = self.backup_model[iter][1]

        dialog = GetTextDialog(
            message=_('Please enter a new name for your backup:'), text=name)
        response = dialog.run()
        dialog.destroy()
        new_name = dialog.get_text()

        if response == Gtk.ResponseType.YES and new_name and name != new_name:
            if self.is_valid_backup_name(new_name):
                proxy.rename_backup(path, name, new_name)
                self.update_backup_model()
            else:
                ErrorDialog(message=_('Please only use alphanumeric characters'
                                      ' and "_" and "-".'),
                            title=_('Backup name is invalid')).launch()
Ejemplo n.º 14
0
 def on_sync_button_clicked(self, widget):
     dialog = CheckUpdateDialog(widget.get_toplevel(), self.url)
     dialog.run()
     dialog.destroy()
     if dialog.status == True:
         dialog = QuestionDialog(_("Update available, would you like to update?"))
         response = dialog.run()
         dialog.destroy()
         if response == Gtk.ResponseType.YES:
             dialog = FetchingDialog(get_app_data_url(), self.get_toplevel())
             dialog.connect('destroy', self.on_app_data_downloaded)
             dialog.run()
             dialog.destroy()
     elif dialog.error == True:
         ErrorDialog(_("Network Error, please check your network connection - or the remote server may be down.")).launch()
     else:
         utdata.save_synced_timestamp(APPCENTER_ROOT)
         self.update_timestamp()
         InfoDialog(_("No update available.")).launch()
Ejemplo n.º 15
0
    def upgrade_sources(self):
        dialog = QuestionDialog(
            title=_('Upgrade Third Party Sources'),
            message=
            _('After a successful distribution upgrade, '
              'any third-party sources you use will be disabled by default.\n'
              'Would you like to re-enable any sources disabled by Update Manager?'
              ))

        response = dialog.run()
        dialog.destroy()
        if response == Gtk.ResponseType.YES:
            proxy.upgrade_sources(self.__get_disable_string(), UPGRADE_DICT)
            if not self.check_source_upgradable():
                InfoDialog(_('Upgrade Successful!')).launch()
            else:
                ErrorDialog(_('Upgrade Failed!')).launch()
            self.emit('call', 'ubuntutweak.modules.sourceeditor',
                      'update_source_combo', {})
            self.update_sourceview()
Ejemplo n.º 16
0
                try:
                    page = module()
                except Exception, e:
                    log.error(e)
                    module = create_broken_module_class(name)
                    page = module()

                page.show_all()
                index = self.notebook.append_page(page, Gtk.Label(label=name))

            self._save_loaded_info(name, module, index)
            self.navigation_dict[feature] = name, None
            self.set_current_module(module, index)
            self.update_jump_buttons()
        else:
            dialog = ErrorDialog(title=_('No module named "%s"') % name,
                                 message=_('Please ensure you have entered the correct module name.'))
            dialog.launch()
            self.notebook.set_current_page(self.feature_dict[self.current_feature])

    def update_jump_buttons(self, disable=False):
        if not disable:
            back, forward = self.navigation_dict[self.current_feature]
            self.back_button.set_sensitive(bool(back))
            self.next_button.set_sensitive(bool(forward))
        else:
            self.back_button.set_sensitive(False)
            self.next_button.set_sensitive(False)

    def on_back_button_clicked(self, widget):
        self.navigation_dict[self.current_feature] = tuple(reversed(self.navigation_dict[self.current_feature]))
        self.notebook.set_current_page(self.feature_dict[self.current_feature])
Ejemplo n.º 17
0
                try:
                    page = module()
                except Exception, e:
                    log.error(e)
                    module = create_broken_module_class(name)
                    page = module()

                page.show_all()
                index = self.notebook.append_page(page, Gtk.Label(label=name))

            self._save_loaded_info(name, module, index)
            self.navigation_dict[feature] = name, None
            self.set_current_module(module, index)
            self.update_jump_buttons()
        else:
            dialog = ErrorDialog(title=_('No module named "%s"') % name,
                                 message=_('Please ensure you have entered the correct module name.'))
            dialog.launch()
            self.notebook.set_current_page(self.feature_dict[self.current_feature])

    def update_jump_buttons(self, disable=False):
        if not disable:
            back, forward = self.navigation_dict[self.current_feature]
            self.back_button.set_sensitive(bool(back))
            self.next_button.set_sensitive(bool(forward))
        else:
            self.back_button.set_sensitive(False)
            self.next_button.set_sensitive(False)

    @log_func(log)
    def on_back_button_clicked(self, widget):
        self.navigation_dict[self.current_feature] = tuple(reversed(self.navigation_dict[self.current_feature]))
Ejemplo n.º 18
0
 def on_file_set(self, widget):
     try:
         tf = ThemeFile(widget.get_filename())
     except Exception, e:
         log.error(e)
         ErrorDialog(message=_('Theme file is invalid')).launch()
Ejemplo n.º 19
0
    def on_install_extension(self, dialog_label, klass, feature, setting,
                             update_func, error_message):
        dialog = Gtk.FileChooserDialog(
            dialog_label,
            action=Gtk.FileChooserAction.OPEN,
            buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN,
                     Gtk.ResponseType.ACCEPT))
        filter = Gtk.FileFilter()
        filter.set_name(_('Ubuntu Tweak Extension (*.py, *.tar.gz)'))
        filter.add_pattern('*.py')
        filter.add_pattern('*.tar.gz')
        dialog.add_filter(filter)
        dialog.set_current_folder(self.clips_location_setting.get_value()
                                  or GLib.get_home_dir())

        filename = ''
        install_done = False
        not_extension = False

        if dialog.run() == Gtk.ResponseType.ACCEPT:
            filename = dialog.get_filename()
        dialog.destroy()

        if filename:
            self.clips_location_setting.set_value(os.path.dirname(filename))

            log.debug("Start to check the class in %s" % filename)
            if filename.endswith('.tar.gz'):
                tar_file = TarFile(filename)
                if tar_file.is_valid():
                    tar_file.extract(TEMP_ROOT)
                    #TODO if multi-root
                    if tar_file.get_root_name():
                        temp_dir = os.path.join(TEMP_ROOT,
                                                tar_file.get_root_name())

                if ModuleLoader.is_target_class(temp_dir, klass):
                    target = os.path.join(
                        ModuleLoader.get_user_extension_dir(feature),
                        os.path.basename(temp_dir))
                    copy = True
                    if os.path.exists(target):
                        dialog = QuestionDialog(message=_(
                            "Would you like to remove it then install again?"),
                                                title=_(
                                                    '"%s" has already installed'
                                                    %
                                                    os.path.basename(target)))
                        response = dialog.run()
                        dialog.destroy()

                        if response == Gtk.ResponseType.YES:
                            shutil.rmtree(target)
                        else:
                            copy = False

                    if copy:
                        log.debug("Now copying tree...")
                        shutil.move(temp_dir, target)
                    else:
                        shutil.rmtree(temp_dir)
                else:
                    not_extension = True
            else:
                if ModuleLoader.is_target_class(filename, klass):
                    shutil.copy(filename,
                                ModuleLoader.get_user_extension_dir(feature))
                    install_done = True
                else:
                    not_extension = True

        if install_done:
            update_func(feature)

            # To force empty the clips_setting to make load_cips
            value = setting.get_value()
            setting.set_value([''])
            setting.set_value(value)

        if not_extension:
            ErrorDialog(message=error_message %
                        os.path.basename(filename)).launch()
Ejemplo n.º 20
0
 def show_backup_failed_dialog(self):
     ErrorDialog(title=_("Backup Failed!")).launch()
Ejemplo n.º 21
0
    def on_enable_toggled(self, cell, path):
        model = self.get_model()
        iter = model.get_iter((int(path), ))

        id = model.get_value(iter, self.COLUMN_ID)
        name = model.get_value(iter, self.COLUMN_NAME)
        enabled = model.get_value(iter, self.COLUMN_ENABLED)
        url = model.get_value(iter, self.COLUMN_URL)

        if self.view_mode == 'view':
            conflicts = SOURCE_PARSER.get_conflicts(id)
            dependencies = SOURCE_PARSER.get_dependencies(id)

            #Convert to real model, because will involke the set method
            if type(model) == Gtk.TreeModelFilter:
                iter = model.convert_iter_to_child_iter(iter)
                model = model.get_model()

            if not enabled and conflicts:
                conflict_list = []
                conflict_name_list = []
                for conflict_id in conflicts:
                    if self.get_source_enabled(conflict_id):
                        conflict_list.append(conflict_id)
                        name_list = [
                            r[self.COLUMN_NAME] for r in model
                            if r[self.COLUMN_ID] == conflict_id
                        ]
                        if name_list:
                            conflict_name_list.extend(name_list)

                if conflict_list and conflict_name_list:
                    full_name = ', '.join(conflict_name_list)
                    ErrorDialog(_('You can\'t enable this Source because'
                                  '<b>"%(SOURCE)s"</b> conflicts with it.\nTo '
                                  'continue you need to disable <b>"%(SOURCE)s"</b>' \
                                  'first.') % {'SOURCE': full_name}).launch()

                    model.set(iter, self.COLUMN_ENABLED, enabled)
                    return

            if enabled is False and dependencies:
                depend_list = []
                depend_name_list = []
                for depend_id in dependencies:
                    if self.get_source_enabled(depend_id) is False:
                        depend_list.append(depend_id)
                        name_list = [
                            r[self.COLUMN_NAME] for r in model
                            if r[self.COLUMN_ID] == depend_id
                        ]
                        if name_list:
                            depend_name_list.extend(name_list)

                if depend_list and depend_name_list:
                    full_name = ', '.join(depend_name_list)

                    dialog = QuestionDialog(title=_('Dependency Notice'),
                                            message= _('To enable this Source, You need to enable <b>"%s"</b> at first.\nDo you wish to continue?') \
                                % full_name)
                    if dialog.run() == Gtk.ResponseType.YES:
                        for depend_id in depend_list:
                            self.set_source_enabled(depend_id)
                        self.set_source_enabled(id)
                    else:
                        model.set(iter, self.COLUMN_ENABLED, enabled)

                    dialog.destroy()
                    return

            if enabled and SOURCE_PARSER.has_reverse_depends(id):
                depend_list = []
                depend_name_list = []
                for depend_id in SOURCE_PARSER.get_reverse_depends(id):
                    if self.get_source_enabled(depend_id):
                        depend_list.append(depend_id)
                        name_list = [
                            r[self.COLUMN_NAME] for r in model
                            if r[self.COLUMN_ID] == depend_id
                        ]
                        if name_list:
                            depend_name_list.extend(name_list)

                if depend_list and depend_name_list:
                    full_name = ', '.join(depend_name_list)

                    ErrorDialog(_('You can\'t disable this Source because '
                                '<b>"%(SOURCE)s"</b> depends on it.\nTo continue '
                                'you need to disable <b>"%(SOURCE)s"</b> first.') \
                                     % {'SOURCE': full_name}).launch()

                    model.set(iter, self.COLUMN_ENABLED, enabled)
                    return

            self.do_source_enable(iter, not enabled)
        else:
            #TODO purge dependencies
            status = not enabled
            model.set(iter, self.COLUMN_ENABLED, status)

            if status:
                self.to_purge.append(url)
            else:
                self.to_purge.remove(url)

            self.emit('new_purge', self.to_purge)