<commit_before>/*
 * This file is part of accounts-ui
 *
 * Copyright (C) 2009-2010 Nokia Corporation.
 *
 * Contact: <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * version 2.1 as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 */

//project
#include "service-settings-widget.h"
#include "abstract-service-setup-context.h"
#include "settings-page.h"
#include "service-helper.h"

//M
#include <MBasicListItem>
#include <MLayout>
#include <MLinearLayoutPolicy>
#include <MGridLayoutPolicy>
#include <MLabel>
#include <MButton>
#include <MLocale>
#include <MImageWidget>

//Qt
#include <QDebug>
#include <QDomElement>

namespace AccountsUI {

ServiceSettingsWidgetListItem::ServiceSettingsWidgetListItem(QGraphicsWidget *parent)
        : MBasicListItem(MBasicListItem::IconWithTitleAndSubtitle, parent)
{
    setStyleName("CommonLargePanel");
    setObjectName("wgServiceSettingsWidgetListItem");

    horizontalLayout = new MLayout(this);

    horizontalLayout->setContentsMargins(0, 0, 0, 0);
    MLinearLayoutPolicy *horizontalLayoutPolicy
            = new MLinearLayoutPolicy(horizontalLayout, Qt::Horizontal);
    horizontalLayoutPolicy->setSpacing(0);

    MLayout *titleSubtitleLayout = new MLayout(horizontalLayout);
    titleSubtitleLayout->setContentsMargins(0, 0, 0, 0);
    MLinearLayoutPolicy *titleSubtitleLayoutPolicy = new MLinearLayoutPolicy(titleSubtitleLayout, Qt::Vertical);
    titleSubtitleLayoutPolicy->setSpacing(0);

    titleLabelWidget()->setStyleName("CommonTitleInverted");
    titleSubtitleLayoutPolicy->addItem(titleLabelWidget(), Qt::AlignLeft | Qt::AlignTop);
    subtitleLabelWidget()->setStyleName("CommonSubTitleInverted");
    titleSubtitleLayoutPolicy->addItem(subtitleLabelWidget(), Qt::AlignLeft | Qt::AlignTop);
    // Add an empty item to push the subtitle up
    titleSubtitleLayoutPolicy->addItem(new QGraphicsWidget());

    horizontalLayoutPolicy->addItem(titleSubtitleLayout, Qt::AlignLeft | Qt::AlignCenter);

    MImageWidget *image = imageWidget();
    image->setImage("icon-m-common-drilldown-arrow-inverse");
    image->setStyleName("CommonDrillDownIcon");
    image->setObjectName("wgServiceSettingsWidgetDrillDownIcon");
    image->setVisible(false);
    horizontalLayoutPolicy->addItem(image, Qt::AlignCenter);
}

ServiceSettingsWidgetListItem::~ServiceSettingsWidgetListItem()
{}


QGraphicsLayout *ServiceSettingsWidgetListItem::createLayout()
{
    subtitleLabelWidget()->setWordWrap(true);
    subtitleLabelWidget()->setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
    subtitleLabelWidget()->setTextElide(false);
    return MBasicListItem::createLayout();
}

void ServiceSettingsWidgetListItem::showDrillDownButton()
{
    setStyleName("CommonPanelInverted");
    imageWidget()->setVisible(true);
}

class ServiceSettingsWidgetPrivate
{
public:
    ServiceSettingsWidgetPrivate()
        : context(0)
         ,enableServiceButton(0)
    {}

    ~ServiceSettingsWidgetPrivate()
    {}

    AbstractServiceSetupContext *context;
    MButton *enableServiceButton;
};

ServiceSettingsWidget::ServiceSettingsWidget(AbstractServiceSetupContext *context,
                                             QGraphicsItem *parent,
                                             int settingsConf,
                                             bool enabled)
    : MWidget(parent),
    d_ptr(new ServiceSettingsWidgetPrivate())
{
    Q_D(ServiceSettingsWidget);

    d->context = context;
    QString catalog = d->context->service()->trCatalog();
    if (!catalog.isEmpty()) {
         MLocale locale;
         locale.installTrCatalog(catalog);
         MLocale::setDefault(locale);
    }

    MLayout *containerMainLayout = new MLayout(this);
    MLinearLayoutPolicy *mainPolicy = new MLinearLayoutPolicy(containerMainLayout, Qt::Vertical);
    mainPolicy->setSpacing(0);
    mainPolicy->setContentsMargins(0,0,0,0);

    MWidget *upperWidget = new MWidget(this);
    MLayout *upperLayout = new MLayout(upperWidget);
    MLinearLayoutPolicy *containerMainPolicy = new MLinearLayoutPolicy(upperLayout, Qt::Horizontal);
    containerMainPolicy->setSpacing(0);
    containerMainPolicy->setContentsMargins(0,0,0,0);

    ServiceSettingsWidgetListItem *serviceInfo = 0;

    if (settingsConf & EnableButton) {
        if (context) {
            d->enableServiceButton = new MButton(this);
            d->enableServiceButton->setViewType(MButton::switchType);
            d->enableServiceButton->setStyleName("CommonLeftSwitchInverted");
            d->enableServiceButton->setObjectName("wgServiceSettingsWidgetServiceButton");
            d->enableServiceButton->setCheckable(true);

            ServiceHelper *serviceHelper =
                new ServiceHelper(const_cast<Accounts::Service*>(context->service()), this);

            serviceInfo = new ServiceSettingsWidgetListItem();
            serviceInfo->setTitle(serviceHelper->prettyName());
            QString subTitle = serviceHelper->description();

            if (settingsConf != (MandatorySettings | EnableButton)) {
                if (!serviceHelper->shortDescription().isEmpty())
                    subTitle = serviceHelper->shortDescription();
            }

            serviceInfo->setSubtitle(subTitle);
            /*
             * no signals during widget creation
             * */
            d->enableServiceButton->setChecked(enabled);
            connect(d->enableServiceButton, SIGNAL(toggled(bool)), this, SLOT(enabled(bool)));

            containerMainPolicy->addItem(d->enableServiceButton, Qt::AlignRight | Qt::AlignVCenter);
            containerMainPolicy->addItem(serviceInfo, Qt::AlignLeft | Qt::AlignVCenter);

            mainPolicy->addItem(upperWidget);
        }
    }

    if (context) {
        MWidget *widget = context->widget(0, (settingsConf & NonMandatorySettings));

        if (widget) {
            if (serviceInfo) {
                serviceInfo->showDrillDownButton();
                connect(serviceInfo, SIGNAL(clicked()),
                        this, SLOT(openSettingsPage()));
            }

            if ((settingsConf & NonMandatorySettings) ||
                (settingsConf & MandatorySettings)) {
                    mainPolicy->addItem(widget);<commit_msg>Bugfix #251845 - Facebook service selection view (when setting up account), texts are not shown properly and layout needs tuning<commit_after>/*
 * This file is part of accounts-ui
 *
 * Copyright (C) 2009-2010 Nokia Corporation.
 *
 * Contact: <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * version 2.1 as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 */

//project
#include "service-settings-widget.h"
#include "abstract-service-setup-context.h"
#include "settings-page.h"
#include "service-helper.h"

//M
#include <MBasicListItem>
#include <MLayout>
#include <MLinearLayoutPolicy>
#include <MGridLayoutPolicy>
#include <MLabel>
#include <MButton>
#include <MLocale>
#include <MImageWidget>

//Qt
#include <QDebug>
#include <QDomElement>

namespace AccountsUI {

ServiceSettingsWidgetListItem::ServiceSettingsWidgetListItem(QGraphicsWidget *parent)
        : MBasicListItem(MBasicListItem::IconWithTitleAndSubtitle, parent)
{
    setStyleName("CommonLargePanel");
    setObjectName("wgServiceSettingsWidgetListItem");

    horizontalLayout = new MLayout(this);

    horizontalLayout->setContentsMargins(0, 0, 0, 0);
    MLinearLayoutPolicy *horizontalLayoutPolicy
            = new MLinearLayoutPolicy(horizontalLayout, Qt::Horizontal);
    horizontalLayoutPolicy->setSpacing(0);

    MLayout *titleSubtitleLayout = new MLayout(horizontalLayout);
    titleSubtitleLayout->setContentsMargins(0, 0, 0, 0);
    MLinearLayoutPolicy *titleSubtitleLayoutPolicy = new MLinearLayoutPolicy(titleSubtitleLayout, Qt::Vertical);
    titleSubtitleLayoutPolicy->setSpacing(0);

    titleLabelWidget()->setStyleName("CommonTitleInverted");
    titleSubtitleLayoutPolicy->addItem(titleLabelWidget(), Qt::AlignLeft | Qt::AlignTop);
    subtitleLabelWidget()->setStyleName("CommonSubTitleInverted");
    titleSubtitleLayoutPolicy->addItem(subtitleLabelWidget(), Qt::AlignLeft | Qt::AlignTop);

    horizontalLayoutPolicy->addItem(titleSubtitleLayout, Qt::AlignLeft | Qt::AlignCenter);

    subtitleLabelWidget()->setWordWrap(true);
    subtitleLabelWidget()->setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
    subtitleLabelWidget()->setTextElide(false);

    MImageWidget *image = imageWidget();
    image->setImage("icon-m-common-drilldown-arrow-inverse");
    image->setStyleName("CommonDrillDownIcon");
    image->setObjectName("wgServiceSettingsWidgetDrillDownIcon");
    image->setVisible(false);
    horizontalLayoutPolicy->addItem(image, Qt::AlignCenter);
}

ServiceSettingsWidgetListItem::~ServiceSettingsWidgetListItem()
{}


QGraphicsLayout *ServiceSettingsWidgetListItem::createLayout()
{
    return horizontalLayout;
}

void ServiceSettingsWidgetListItem::showDrillDownButton()
{
    setStyleName("CommonLargePanelInverted");
    imageWidget()->setVisible(true);
}

class ServiceSettingsWidgetPrivate
{
public:
    ServiceSettingsWidgetPrivate()
        : context(0)
         ,enableServiceButton(0)
    {}

    ~ServiceSettingsWidgetPrivate()
    {}

    AbstractServiceSetupContext *context;
    MButton *enableServiceButton;
};

ServiceSettingsWidget::ServiceSettingsWidget(AbstractServiceSetupContext *context,
                                             QGraphicsItem *parent,
                                             int settingsConf,
                                             bool enabled)
    : MWidget(parent),
    d_ptr(new ServiceSettingsWidgetPrivate())
{
    Q_D(ServiceSettingsWidget);

    d->context = context;
    QString catalog = d->context->service()->trCatalog();
    if (!catalog.isEmpty()) {
         MLocale locale;
         locale.installTrCatalog(catalog);
         MLocale::setDefault(locale);
    }

    MLayout *containerMainLayout = new MLayout(this);
    MLinearLayoutPolicy *mainPolicy = new MLinearLayoutPolicy(containerMainLayout, Qt::Vertical);
    mainPolicy->setSpacing(0);
    mainPolicy->setContentsMargins(0,0,0,0);

    MWidget *upperWidget = new MWidget(this);
    MLayout *upperLayout = new MLayout(upperWidget);
    MLinearLayoutPolicy *containerMainPolicy = new MLinearLayoutPolicy(upperLayout, Qt::Horizontal);
    containerMainPolicy->setSpacing(0);
    containerMainPolicy->setContentsMargins(0,0,0,0);

    ServiceSettingsWidgetListItem *serviceInfo = 0;

    if (settingsConf & EnableButton) {
        if (context) {
            d->enableServiceButton = new MButton(this);
            d->enableServiceButton->setViewType(MButton::switchType);
            d->enableServiceButton->setStyleName("CommonLeftSwitchInverted");
            d->enableServiceButton->setObjectName("wgServiceSettingsWidgetServiceButton");
            d->enableServiceButton->setCheckable(true);

            ServiceHelper *serviceHelper =
                new ServiceHelper(const_cast<Accounts::Service*>(context->service()), this);

            serviceInfo = new ServiceSettingsWidgetListItem();
            serviceInfo->setTitle(serviceHelper->prettyName());
            QString subTitle = serviceHelper->description();

            if (settingsConf != (MandatorySettings | EnableButton)) {
                if (!serviceHelper->shortDescription().isEmpty())
                    subTitle = serviceHelper->shortDescription();
            }

            serviceInfo->setSubtitle(subTitle);
            /*
             * no signals during widget creation
             * */
            d->enableServiceButton->setChecked(enabled);
            connect(d->enableServiceButton, SIGNAL(toggled(bool)), this, SLOT(enabled(bool)));

            containerMainPolicy->addItem(d->enableServiceButton, Qt::AlignRight | Qt::AlignCenter);
            containerMainPolicy->addItem(serviceInfo, Qt::AlignLeft | Qt::AlignTop);

            mainPolicy->addItem(upperWidget);
        }
    }

    if (context) {
        MWidget *widget = context->widget(0, (settingsConf & NonMandatorySettings));

        if (widget) {
            if (serviceInfo) {
                serviceInfo->showDrillDownButton();
                connect(serviceInfo, SIGNAL(clicked()),
                        this, SLOT(openSettingsPage()));
            }

            if ((settingsConf & NonMandatorySettings) ||
                (settingsConf & MandatorySettings)) {
                    mainPolicy->addItem(widget);
{'fraction_non_alphanumeric': 0.10597586105387106, 'fraction_numerical': 0.007065057403591404, 'mean_word_length': 3.6299829642248724, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 136, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 13, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2967574', 'n_tokens_mistral': 3621, 'n_tokens_neox': 3480, 'n_words': 734}