Beispiel #1
0
    def __init__(self, use_default=False):
        super(ProfileIcon, self).__init__()
        apply_styling_to_screen(common_css_path("profile_world_icon.css"))

        username = get_mixed_username()
        username_label = Gtk.Label(username)
        username_label.get_style_context().add_class("heading_desktop_label")

        # this is faster
        if use_default:
            level_label = Gtk.Label("Level 1")
            level_label.get_style_context().add_class("subheading_desktop_label")

            progress_img = Gtk.Image.new_from_file(self._get_progress_path(0))
            avatar_img = Gtk.Image.new_from_file(self._get_local_avatar_path())
        else:
            level, progress, _ = calculate_kano_level()
            level_label = Gtk.Label("Level {}".format(level))

            progress_img = Gtk.Image.new_from_file(self._get_progress_path(progress))
            avatar_img = Gtk.Image.new_from_file(self._get_avatar_path())

        level_label.get_style_context().add_class("subheading_desktop_label")
        self.put(progress_img, 0, 0)
        self.put(avatar_img, 13, 13)
        self.put(username_label, 90, 20)
        self.put(level_label, 90, 38)
Beispiel #2
0
def send_data(text, full_info, subject="", network_send=True):
    '''
    Sends the data to our servers through a post request
    '''
    files = {}
    # packs all the information into 'files'
    if full_info:
        files['report'] = get_metadata_archive()
    # This is the actual info: subject, text, email, username
    payload = {
        "text": text,
        "email": get_email(),
        "username": get_mixed_username(),
        "category": "os",
        "subject": subject
    }

    if not network_send:
        return True, None

    # send the bug report and remove all the created files
    success, error, data = request_wrapper('post', '/feedback',
                                           data=payload, files=files)
    delete_tmp_dir()

    if not success:
        return False, error
    if full_info:
        # kano-profile stat collection
        increment_app_state_variable_with_dialog('kano-feedback',
                                                 'bugs_submitted', 1)
        # logs were sent, clean up
        logging.cleanup()

    return True, None
Beispiel #3
0
    def add_username_as_label(self):
        '''This replaces the username entry with a label containing the
        username.
        '''
        username = get_mixed_username()
        title_label = Gtk.Label(_(" Username:  "******"bold_label")
        self.username_label.get_style_context().add_class("desc_label")

        hbox = Gtk.Box()
        hbox.pack_start(title_label, False, False, 0)
        hbox.pack_start(self.username_label, False, False, 0)

        vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        vbox.pack_start(hbox, False, False, 0)
        align = Gtk.Alignment(xscale=0, xalign=0.5)
        align.add(vbox)

        # Needs adjustment
        align.set_padding(0, 0, 100, 0)

        self.pack_start(align, False, False, 15)
        self.labelled_entries = LabelledEntries(
            [{"heading": _("Password"), "subheading": ""}]
        )
        self.password_entry = self.labelled_entries.get_entry(0)
        vbox.pack_start(self.labelled_entries, False, False, 15)
Beispiel #4
0
    def add_username_as_label(self):
        '''This replaces the username entry with a label containing the
        username.
        '''
        username = get_mixed_username()
        title_label = Gtk.Label(_(" Username:  "******"Password"),
            'subheading': ""
        }])
        self.password_entry = self.labelled_entries.get_entry(0)
        vbox.pack_start(self.labelled_entries, False, False, 15)
def send_data(text, full_info, subject='', network_send=True, logs_path=''):
    """Sends the data to our servers through a post request.

    It uses :func:`~get_metadata_archive` to gather all the logs on
    the system.

    Args:
        text (str): The description of the email when sending the logs
        full_info (bool): Whether to attach all logs to the payload
        subject (str): The title of the email when sending the logs
        network_send (bool): Whether to send the data to our servers
        logs_path (str): Path to an existing logs archive to use instead

    Returns:
        bool, error: Whether the operation was successful or there was
        an error as returned by :func:`kano_world.functions.request_wrapper`
    """

    from kano_world.functions import get_email, get_mixed_username

    files = {}
    # packs all the information into 'files'
    if full_info:
        if logs_path and os.path.exists(logs_path):
            files['report'] = open(logs_path, 'rb')
        else:
            files['report'] = get_metadata_archive(title=subject, desc=text)
    # This is the actual info: subject, text, email, username
    payload = {
        "text": text,
        "email": get_email(),
        "username": get_mixed_username(),
        "category": "os",
        "subject": subject
    }

    if not network_send:
        return True, None

    # send the bug report and remove all the created files
    success, error, data = request_wrapper('post',
                                           '/feedback',
                                           data=payload,
                                           files=files)
    delete_tmp_dir()

    if not success:
        return False, error
    if full_info:
        # kano-profile stat collection
        from kano_profile.badges import increment_app_state_variable_with_dialog
        increment_app_state_variable_with_dialog('kano-feedback',
                                                 'bugs_submitted', 1)
        # logs were sent, clean up
        logging.cleanup()

    return True, None
def send_data(text, full_info, subject='', network_send=True, logs_path=''):
    """Sends the data to our servers through a post request.

    It uses :func:`~get_metadata_archive` to gather all the logs on
    the system.

    Args:
        text (str): The description of the email when sending the logs
        full_info (bool): Whether to attach all logs to the payload
        subject (str): The title of the email when sending the logs
        network_send (bool): Whether to send the data to our servers
        logs_path (str): Path to an existing logs archive to use instead

    Returns:
        bool, error: Whether the operation was successful or there was
        an error as returned by :func:`kano_world.functions.request_wrapper`
    """

    from kano_world.functions import get_email, get_mixed_username

    files = {}
    # packs all the information into 'files'
    if full_info:
        if logs_path and os.path.exists(logs_path):
            files['report'] = open(logs_path, 'rb')
        else:
            files['report'] = get_metadata_archive(title=subject, desc=text)
    # This is the actual info: subject, text, email, username
    payload = {
        "text": text,
        "email": get_email(),
        "username": get_mixed_username(),
        "category": "os",
        "subject": subject
    }

    if not network_send:
        return True, None

    # send the bug report and remove all the created files
    success, error, data = request_wrapper('post', '/feedback',
                                           data=payload, files=files)
    delete_tmp_dir()

    if not success:
        return False, error
    if full_info:
        # kano-profile stat collection
        from kano_profile.badges import increment_app_state_variable_with_dialog
        increment_app_state_variable_with_dialog('kano-feedback',
                                                 'bugs_submitted', 1)
        # logs were sent, clean up
        logging.cleanup()

    return True, None
Beispiel #7
0
def get_wifi_info():
    '''
    Returns a string with wifi specific info
    '''
    # Get username here
    world_username = "******".format(get_mixed_username())
    kwifi_cache = "**kwifi_cache**\n {}\n\n".format(get_kwifi_cache())
    wlaniface = "**wlaniface**\n {}\n\n".format(get_wlaniface())
    ifconfig = "**ifconfig**\n {}\n\n".format(get_networks_info())
    wpalog = "**wpalog**\n {}\n\n".format(get_wpalog())

    return world_username + kwifi_cache + wlaniface + ifconfig + wpalog
Beispiel #8
0
def get_wifi_info():
    '''
    Returns a string with wifi specific info
    '''
    # Get username here
    world_username = "******".format(get_mixed_username())
    kwifi_cache = "**kwifi_cache**\n {}\n\n".format(get_kwifi_cache())
    wlaniface = "**wlaniface**\n {}\n\n".format(get_wlaniface())
    ifconfig = "**ifconfig**\n {}\n\n".format(get_networks_info())
    wpalog = "**wpalog**\n {}\n\n".format(get_wpalog())

    return world_username + kwifi_cache + wlaniface + ifconfig + wpalog
Beispiel #9
0
    def __init__(self, win):
        Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL)

        self.win = win
        self.win.set_decorated(False)
        self.win.set_main_widget(self)

        self.heading = Heading(_("Reset your password"),
                               _("We'll send a new password to your email"))
        self.pack_start(self.heading.container, False, False, 10)

        self.labelled_entries = LabelledEntries([{
            'heading': _("Username"),
            'subheading': ""
        }])
        align = Gtk.Alignment(xscale=0, xalign=0.5)
        self.pack_start(align, False, False, 15)

        self.labelled_entries.set(0, 0, 1, 1)
        self.labelled_entries.set_hexpand(True)

        align.add(self.labelled_entries)

        # Get the currently logged on user, the kid can override it
        # FIXME: Is this necessary?
        username = get_mixed_username()

        self.username_entry = self.labelled_entries.get_entry(0)
        self.username_entry.set_text(username)
        self.username_entry.select_region(0, -1)
        self.username_entry.connect('key-release-event', self.activate)

        self.button = KanoButton(_("RESET PASSWORD"))
        self.button.pack_and_align()
        self.button.connect('button-release-event', self.activate)
        self.button.connect('key-release-event', self.activate)
        self.button.set_padding(30, 30, 0, 0)

        self.pack_start(self.button.align, False, False, 0)
        self.win.show_all()
Beispiel #10
0
    def __init__(self):
        Gtk.Button.__init__(self)
        attach_cursor_events(self)
        self.get_style_context().add_class('home_button')

        # Get the username or kano world name
        # Get username here
        username = get_mixed_username()
        if len(username) > 12:
            username = username[:12] + u'\N{HORIZONTAL ELLIPSIS}'

        # Info about the different settings
        title_label = Gtk.Label(username, xalign=0)
        title_label.get_style_context().add_class("home_button_name")

        level, dummy, dummy = calculate_kano_level()
        level_label = Gtk.Label(_("Level {}").format(level), xalign=0)
        level_label.get_style_context().add_class("home_button_level")

        vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        vbox.pack_start(title_label, False, False, 0)
        vbox.pack_start(level_label, False, False, 0)

        self.add(vbox)
Beispiel #11
0
    def __init__(self):
        Gtk.Button.__init__(self)
        attach_cursor_events(self)
        self.get_style_context().add_class('home_button')

        # Get the username or kano world name
        # Get username here
        username = get_mixed_username()
        if len(username) > 12:
            username = username[:12] + u'\N{HORIZONTAL ELLIPSIS}'

        # Info about the different settings
        title_label = Gtk.Label(username, xalign=0)
        title_label.get_style_context().add_class('home_button_name')

        level, dummy, dummy = calculate_kano_level()
        level_label = Gtk.Label(_("Level {}").format(level), xalign=0)
        level_label.get_style_context().add_class('home_button_level')

        vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        vbox.pack_start(title_label, False, False, 0)
        vbox.pack_start(level_label, False, False, 0)

        self.add(vbox)
def send_question_response(answers, interactive=True, tags=['os', 'feedback-widget'],
                           debug=False, dry_run=False):
    '''
    This function is used by the Feedback widget to network-send the responses.
    The information (question_id, answer, username and email) is sent to a Kano API endpoint.

    answers is a list of tuples each having a Question ID and an Answer literal.

    The answers will be all packed into a payload object and sent in one single network transaction.
    '''

    from kano_world.functions import get_email, get_mixed_username

    ok_msg_title = _('Thank you')  # noqa: F821
    ok_msg_body = _(  # noqa: F821
        'We will use your feedback to improve your experience'
    )

    if interactive and not try_connect() or not try_login():
        # The answer will be saved as offline, act as if it was sent correctly
        thank_you = KanoDialog(ok_msg_title, ok_msg_body)
        thank_you.dialog.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
        thank_you.run()

        return False

    payload = {
        'email': get_email(),
        'username': get_mixed_username(),
        'answers': [
            {
                'question_id': answer[0],
                'text': answer[1],
                'tags': tags
            } for answer in answers
        ]
    }

    if debug:
        print 'PAYLOAD construction:'
        print json.dumps(payload, sort_keys=True,
                         indent=4, separators=(',', ': '))

    # Send the answers unless we are testing the API
    if dry_run:
        return True

    success, error, dummy = request_wrapper('post', '/questions/responses',
                                            data=json.dumps(payload),
                                            headers=content_type_json)

    # Retry on error only if in GUI mode
    if not success:
        logger.error('Error while sending feedback: {}'.format(error))

        if not interactive:
            return False

        retry = KanoDialog(
            title_text=_('Unable to send'),  # noqa: F821
            description_text=_(  # noqa: F821
                'Error while sending your feedback. Do you want to retry?'
            ),
            button_dict={
                _('Close feedback').upper(): {  # noqa: F821
                    'return_value': False,
                    'color': 'red'
                },
                _('Retry').upper(): {  # noqa: F821
                    'return_value': True,
                    'color': 'green'
                }
            }
        )

        if retry.run():
            # Try again until they say no
            return send_question_response([(answer[0], answer)], interactive=interactive)

        return False

    if interactive:
        thank_you = KanoDialog(ok_msg_title, ok_msg_body)
        thank_you.dialog.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
        thank_you.run()

    return True
Beispiel #13
0
def send_question_response(answers, interactive=True, tags=['os', 'feedback-widget'],
                           debug=False, dry_run=False):
    '''
    This function is used by the Feedback widget to network-send the responses.
    The information (question_id, answer, username and email) is sent to a Kano API endpoint.

    answers is a list of tuples each having a Question ID and an Answer literal.

    The answers will be all packed into a payload object and sent in one single network transaction.
    '''

    ok_msg_title = _('Thank you')
    ok_msg_body = _('We will use your feedback to improve your experience')

    if interactive and not try_connect() or not try_login():
        # The answer will be saved as offline, act as if it was sent correctly
        thank_you = KanoDialog(ok_msg_title, ok_msg_body)
        thank_you.dialog.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
        thank_you.run()

        return False

    payload = {
        'email': get_email(),
        'username': get_mixed_username(),
        'answers': [
            { 'question_id': answer[0],
              'text': answer[1],
              'tags': tags } for answer in answers
        ]
    }

    if debug:
        print 'PAYLOAD construction:'
        print json.dumps(payload, sort_keys=True,
                         indent=4, separators=(',', ': '))

    # Send the answers unless we are testing the API
    if dry_run:
        return True

    success, error, dummy = request_wrapper('post', '/questions/responses',
                                            data=json.dumps(payload),
                                            headers=content_type_json)

    # Retry on error only if in GUI mode
    if not success:
        logger.error('Error while sending feedback: {}'.format(error))

        if not interactive:
            return False

        retry = KanoDialog(
            title_text=_('Unable to send'),
            description_text=_('Error while sending your feedback. Do you want to retry?'),
            button_dict={
                _('Close feedback').upper():
                    {
                        'return_value': False,
                        'color': 'red'
                    },
                _('Retry').upper():
                    {
                        'return_value': True,
                        'color': 'green'
                    }
            }
        )

        if retry.run():
            # Try again until they say no
            return send_question_response([(answer[0], answer)], interactive=interactive)

        return False

    if interactive:
        thank_you = KanoDialog(ok_msg_title, ok_msg_body)
        thank_you.dialog.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
        thank_you.run()

    return True
Beispiel #14
0
def send_question_response(question_id, answer, interactive=True):
    '''
    This function is used by the Feedback widget.
    The information (question_id, answer, username and email) is sent to an API
    endpoint.
    '''

    ok_msg_title = 'Thank you'
    ok_msg_body = 'We will use your feedback to improve your experience'

    if interactive and not try_connect() or not try_login():
        # The answer will be saved as offline, act as if it was sent correctly
        thank_you = KanoDialog(ok_msg_title, ok_msg_body)
        thank_you.dialog.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
        thank_you.run()

        return False

    payload = {
        'email': get_email(),
        'username': get_mixed_username(),
        'answers': [
            {
                'question_id': question_id,
                'text': answer,
                'tags': ['os', 'feedback-widget']
            }
        ]
    }

    # Send data
    success, error, dummy = request_wrapper('post', '/questions/responses',
                                            data=json.dumps(payload),
                                            headers=content_type_json)

    if not success:
        logger.error('Error while sending feedback: {}'.format(error))

        retry = KanoDialog(
            title_text='Unable to send',
            description_text=('Error while sending your feedback. ' \
                              'Do you want to retry?'),
            button_dict={
                'Close feedback'.upper():
                    {
                        'return_value': False,
                        'color': 'red'
                    },
                'Retry'.upper():
                    {
                        'return_value': True,
                        'color': 'green'
                    }
            }
        )

        if retry.run():
            # Try again until they say no
            return send_question_response(question_id=question_id,
                                          answer=answer,
                                          interactive=interactive)

        return False


    thank_you = KanoDialog(ok_msg_title, ok_msg_body)
    thank_you.dialog.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
    thank_you.run()

    return True