<commit_before>/*
 * Copyright 2011 Intel Corporation.
 *
 * This program is licensed under the terms and conditions of the
 * Apache License, version 2.0.  The full text of the Apache License is at 	
 * http://www.apache.org/licenses/LICENSE-2.0
 */

import QtQuick 1.0
import MeeGo.Components 0.1
import MeeGo.Settings 0.1
import MeeGo.App.Email 0.1

Item {
    Rectangle {
        anchors.fill: parent
        color: "#eaf6fb"
    }

    height: contentCol.height

    onHeightChanged: {
        settingsPage.height = height;
    }

    Column {
        id: contentCol
        width: settingsPage.width
        ControlGroup {
            id: content
            children: [
                Item { width: 1; height: 20; },
                TextControl { //this is a read-only element just so the user can see what preset was set
                    label: qsTr("Account description:")
                    Component.onCompleted: setText(emailAccount.description);
                    enabled: false
                    // hide this field for "other" type accounts
                    visible: emailAccount.preset != 0
                    id: descriptField
                },
                TextControl {
                    id: nameField
                    label: qsTr("Your name:")
                    Component.onCompleted: setText(emailAccount.name) //done to supress onTextChanged
                    onTextChanged: emailAccount.name = text
                    //KNOWN BUG: if you get an error, and then switch to a new langauge in the middle of setup (can you?), the error text does not update
                    errorText: registerSaveRestoreState.restoreRequired ?
                                   registerSaveRestoreState.value("email-register-nameField-errorText") : ""
                },
                TextControl {
                    id: addressField
                    label: qsTr("Email address:")
                    Component.onCompleted: setText(emailAccount.address)
                    inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhEmailCharactersOnly
                    onTextChanged: emailAccount.address = text
                    errorText: registerSaveRestoreState.restoreRequired ?
                                   registerSaveRestoreState.value("email-register-addressField-errorText") : ""
                },
                PasswordControl {
                    id: passwordField
                    label: qsTr("Password:")
                    Component.onCompleted: setText(emailAccount.password)
                    onTextChanged: emailAccount.password = text
                    //errorText: registerSaveRestoreState.restoreRequired ? //TODO: make the password encrypted such that its not stored in plain-text
                    //               registerSaveRestoreState.value("email-register-passwordField-errorText") : ""
                },
                Item { width: 1; height: 40; }
            ]
        }
        BottomToolBar {
            width: settingsPage.width
            content: BottomToolBarRow {
                leftContent: Button {
                    text: qsTr("Next")
                    function validate() {
                        var errors = 0;
                        if (nameField.text.length === 0) {
                            nameField.errorText = qsTr("This field is required");
                            errors++;
                        } else {
                            nameField.errorText = "";
                        }
                        if (addressField.text.length === 0) {
                            addressField.errorText = qsTr("This field is required");
                            errors++;
                        } else {
                            addressField.errorText = "";
                        }
                        if (passwordField.text.length === 0) {
                            passwordField.errorText = qsTr("This field is required");
                            errors++;
                        } else {
                            passwordField.errorText = "";
                        }

/*
                        // Added By Daewon.Park
                        var accountList = accountListModel.getAllEmailAddresses();
                        for(var i = 0; i < accountList.length; i++) {
                            console.log("Account : " + addressField.text + " : " + accountList[i]);
                            if(addressField.text === accountList[i]) {
                                addressField.errorText = qsTr("Same account is already registered");
                                errors++;
                                break;
                            }
                        }
*/

                        return errors === 0;
                    }
                    onClicked: {
                        if (validate()) {
                            emailAccount.applyPreset();
                            if (emailAccount.preset != 0) {
                                settingsPage.state = "DetailsScreen";
                            } else {
                                settingsPage.state = "ManualScreen";
                                loader.item.message = qsTr("Please fill in account details:");
                            }
                        }
                    }
                }
                rightContent:  Button {
                    text: qsTr("Cancel")
                    onClicked: {
                        verifyCancel.show();
                    }
                }
            }

            Component.onCompleted: {
                show();
            }
        }
    }

    ModalMessageBox {
        id: verifyCancel
        acceptButtonText: qsTr ("Yes")
        cancelButtonText: qsTr ("No")
        title: qsTr ("Discard changes")
        text: qsTr ("You have made changes to your settings. Are you sure you want to cancel?")
        onAccepted: {
            settingsPage.state = settingsPage.getHomescreen();
        }
    }
    // Added By Daewon.Park
    /*EmailAccountListModel {
        id : accountListModel
    }*/


    SaveRestoreState {
        id: registerSaveRestoreState
        onSaveRequired: {
            setValue("email-register-nameField-errorText",nameField.errorText);
            setValue("email-register-addressField-errorText",addressField.errorText);
            setValue("email-register-verifyCancel-visible",verifyCancel.visible);
            sync();
        }
    }

}<commit_msg>Revert's Carl's previous commit, as the pending issues is fixed.<commit_after>/*
 * Copyright 2011 Intel Corporation.
 *
 * This program is licensed under the terms and conditions of the
 * Apache License, version 2.0.  The full text of the Apache License is at 	
 * http://www.apache.org/licenses/LICENSE-2.0
 */

import QtQuick 1.0
import MeeGo.Components 0.1
import MeeGo.Settings 0.1
import MeeGo.App.Email 0.1

Item {
    Rectangle {
        anchors.fill: parent
        color: "#eaf6fb"
    }

    height: contentCol.height

    onHeightChanged: {
        settingsPage.height = height;
    }

    Column {
        id: contentCol
        width: settingsPage.width
        ControlGroup {
            id: content
            children: [
                Item { width: 1; height: 20; },
                TextControl { //this is a read-only element just so the user can see what preset was set
                    label: qsTr("Account description:")
                    Component.onCompleted: setText(emailAccount.description);
                    enabled: false
                    // hide this field for "other" type accounts
                    visible: emailAccount.preset != 0
                    id: descriptField
                },
                TextControl {
                    id: nameField
                    label: qsTr("Your name:")
                    Component.onCompleted: setText(emailAccount.name) //done to supress onTextChanged
                    onTextChanged: emailAccount.name = text
                    //KNOWN BUG: if you get an error, and then switch to a new langauge in the middle of setup (can you?), the error text does not update
                    errorText: registerSaveRestoreState.restoreRequired ?
                                   registerSaveRestoreState.value("email-register-nameField-errorText") : ""
                },
                TextControl {
                    id: addressField
                    label: qsTr("Email address:")
                    Component.onCompleted: setText(emailAccount.address)
                    inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhEmailCharactersOnly
                    onTextChanged: emailAccount.address = text
                    errorText: registerSaveRestoreState.restoreRequired ?
                                   registerSaveRestoreState.value("email-register-addressField-errorText") : ""
                },
                PasswordControl {
                    id: passwordField
                    label: qsTr("Password:")
                    Component.onCompleted: setText(emailAccount.password)
                    onTextChanged: emailAccount.password = text
                    //errorText: registerSaveRestoreState.restoreRequired ? //TODO: make the password encrypted such that its not stored in plain-text
                    //               registerSaveRestoreState.value("email-register-passwordField-errorText") : ""
                },
                Item { width: 1; height: 40; }
            ]
        }
        BottomToolBar {
            width: settingsPage.width
            content: BottomToolBarRow {
                leftContent: Button {
                    text: qsTr("Next")
                    function validate() {
                        var errors = 0;
                        if (nameField.text.length === 0) {
                            nameField.errorText = qsTr("This field is required");
                            errors++;
                        } else {
                            nameField.errorText = "";
                        }
                        if (addressField.text.length === 0) {
                            addressField.errorText = qsTr("This field is required");
                            errors++;
                        } else {
                            addressField.errorText = "";
                        }
                        if (passwordField.text.length === 0) {
                            passwordField.errorText = qsTr("This field is required");
                            errors++;
                        } else {
                            passwordField.errorText = "";
                        }

                        // Added By Daewon.Park
                        var accountList = accountListModel.getAllEmailAddresses();
                        for(var i = 0; i < accountList.length; i++) {
                            console.log("Account : " + addressField.text + " : " + accountList[i]);
                            if(addressField.text === accountList[i]) {
                                addressField.errorText = qsTr("Same account is already registered");
                                errors++;
                                break;
                            }
                        }

                        return errors === 0;
                    }
                    onClicked: {
                        if (validate()) {
                            emailAccount.applyPreset();
                            if (emailAccount.preset != 0) {
                                settingsPage.state = "DetailsScreen";
                            } else {
                                settingsPage.state = "ManualScreen";
                                loader.item.message = qsTr("Please fill in account details:");
                            }
                        }
                    }
                }
                rightContent:  Button {
                    text: qsTr("Cancel")
                    onClicked: {
                        verifyCancel.show();
                    }
                }
            }

            Component.onCompleted: {
                show();
            }
        }
    }

    ModalMessageBox {
        id: verifyCancel
        acceptButtonText: qsTr ("Yes")
        cancelButtonText: qsTr ("No")
        title: qsTr ("Discard changes")
        text: qsTr ("You have made changes to your settings. Are you sure you want to cancel?")
        onAccepted: {
            settingsPage.state = settingsPage.getHomescreen();
        }
    }
    // Added By Daewon.Park
    EmailAccountListModel {
        id : accountListModel
    }


    SaveRestoreState {
        id: registerSaveRestoreState
        onSaveRequired: {
            setValue("email-register-nameField-errorText",nameField.errorText);
            setValue("email-register-addressField-errorText",addressField.errorText);
            setValue("email-register-verifyCancel-visible",verifyCancel.visible);
            sync();
        }
    }

}
{'fraction_non_alphanumeric': 0.08085138963325932, 'fraction_numerical': 0.004746956588316362, 'mean_word_length': 1.157938212456633, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '489605', 'n_tokens_mistral': 3087, 'n_tokens_neox': 2848, 'n_words': 691}