<commit_before>/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: <NAME> <<EMAIL>>
**
** This file is part of duicontrolpanel.
**
**
** This program 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
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/

/* -*- Mode: C; indent-tabs-mode: s; c-basic-offset: 4; tab-width: 4 -*- */
/* vim:set et ai sw=4 ts=4 sts=4: tw=80 cino="(0,W2s,i2s,t0,l1,:0" */

#include "dcpappletpage.h"

#include "dcpappletwidget.h"
#include <DcpAppletIf>
#include <DcpAppletMetadata>
#include <DcpAppletObject>
#include <DcpRetranslator>

#include <MLabel>
#include <MLocale>
#include <MAction>
#include <MSceneManager>
#include <mwidgetcreator.h>
#include <QProcess>
#include <QCoreApplication>
#include <MDismissEvent>
#include <QCloseEvent>

#include "dcpdebug.h"

M_REGISTER_WIDGET_NO_CREATE(DcpAppletPage)

DcpAppletPage::DcpAppletPage (DcpAppletObject *applet, int widgetId):
    DcpPage (),
    m_Applet(applet),
    m_WidgetId(widgetId),
    m_MainWidget (0),
    m_MissingLabel (0)
{
}


DcpAppletPage::~DcpAppletPage ()
{
    if (m_Applet) {
        m_Applet->metadata()->markInactive();
    }
}

void
DcpAppletPage::createContent ()
{
    DcpPage::createContent ();
    load();
}

bool 
DcpAppletPage::hasWidget ()
{
    return m_MainWidget;
}

bool 
DcpAppletPage::hasError ()
{
    return m_MissingLabel;
}

int 
DcpAppletPage::widgetId ()
{
    return m_WidgetId;
}

/*!
 * This function might do three things. If the applet variant has a binary
 * applet it will call the binary and load the main widget of the applet
 * variant. If the applet variant has an application command (a shell command
 * that should be called when the applet is activated) the function will execute
 * the shell command. Finaly if neither the applet binary is loaded nor the
 * shell command is available this function will create wome widgets to show
 * that the applet is not available.
 */
void
DcpAppletPage::load ()
{
    DCP_DEBUG ("");

    if (m_Applet) {
        m_Applet->metadata()->markActive();
        DcpRetranslator::instance()->ensureTranslationLoaded(
               m_Applet->metadata());

       if (m_Applet->isAppletLoaded()) {

            /*
             * If the plugin is available (loaded) we call it to create a new
             * view. (Here we got the widgetId from the plugin itself using the
             * DCP/Part key of the desktop file.)
             */
            if (m_WidgetId < 0) {
                m_WidgetId = m_Applet->getMainWidgetId();
            }
            loadWidget (m_WidgetId);

            return;
        } else if (m_Applet->metadata()->hasApplicationCommand ()) {
            /*
             * If the applet is not loaded from a binary file, but it has an
             * activation command line we execute an external application.
             */
            QString command = m_Applet->metadata()->applicationCommand();
            QProcess *process = new QProcess();

            /* redirect std io channels to /dev/null
             * because otherwise if command is applauncher's invoker 
             * it will pass pipes created by QProcess to the launched 
             * application, which are not valid anymore 
             * see bug 182372
             */            
            process->setStandardInputFile("/dev/null");
            process->setStandardOutputFile("/dev/null");
            process->setStandardErrorFile("/dev/null");

            // this will free up the QProcess when the process ended:
            connect (process, SIGNAL(finished ( int, QProcess::ExitStatus)),
                     process, SLOT(deleteLater()));

            process->start(command);
            return;
        }

        DCP_WARNING ("The applet has no loaded plugin nor an external "
                "command defined");
    } else {
        DCP_WARNING ("The applet is not valid.");
    }

    /*
     * Showing the 'plugin not available' label. We currently show this only if
     * the plugin is really not available, we will not show this if the plugin
     * is crashed. The plugin will be re-enabled (and most likely crash again)
     * when the user activates the applet by clicking on the brief.
     */
    if (!m_MissingLabel) {
        // FIXME: these are temporary translation ids and not present anywhere

        //% "Plugin not available"
        m_MissingLabel = new MLabel (qtTrId("dcp_no_applet_name"));
        m_MissingLabel->setAlignment (Qt::AlignCenter);
        appendWidget (m_MissingLabel);
        //% "Missing plugin"
        setTitle (qtTrId("dcp_no_applet_title"));
    }
}

/*!
 * This function returns if the page would like to prevent its closing,
 * when the user presses the close or back button.
 */<commit_msg>makes the error loading applet message visible<commit_after>/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: <NAME> <<EMAIL>>
**
** This file is part of duicontrolpanel.
**
**
** This program 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
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/

/* -*- Mode: C; indent-tabs-mode: s; c-basic-offset: 4; tab-width: 4 -*- */
/* vim:set et ai sw=4 ts=4 sts=4: tw=80 cino="(0,W2s,i2s,t0,l1,:0" */

#include "dcpappletpage.h"

#include "dcpappletwidget.h"
#include <DcpAppletIf>
#include <DcpAppletMetadata>
#include <DcpAppletObject>
#include <DcpRetranslator>

#include <MLabel>
#include <MLocale>
#include <MAction>
#include <MSceneManager>
#include <mwidgetcreator.h>
#include <QProcess>
#include <QCoreApplication>
#include <MDismissEvent>
#include <QCloseEvent>

#include "dcpdebug.h"

M_REGISTER_WIDGET_NO_CREATE(DcpAppletPage)

DcpAppletPage::DcpAppletPage (DcpAppletObject *applet, int widgetId):
    DcpPage (),
    m_Applet(applet),
    m_WidgetId(widgetId),
    m_MainWidget (0),
    m_MissingLabel (0)
{
}


DcpAppletPage::~DcpAppletPage ()
{
    if (m_Applet) {
        m_Applet->metadata()->markInactive();
    }
}

void
DcpAppletPage::createContent ()
{
    DcpPage::createContent ();
    load();
}

bool 
DcpAppletPage::hasWidget ()
{
    return m_MainWidget;
}

bool 
DcpAppletPage::hasError ()
{
    return m_MissingLabel;
}

int 
DcpAppletPage::widgetId ()
{
    return m_WidgetId;
}

/*!
 * This function might do three things. If the applet variant has a binary
 * applet it will call the binary and load the main widget of the applet
 * variant. If the applet variant has an application command (a shell command
 * that should be called when the applet is activated) the function will execute
 * the shell command. Finaly if neither the applet binary is loaded nor the
 * shell command is available this function will create wome widgets to show
 * that the applet is not available.
 */
void
DcpAppletPage::load ()
{
    DCP_DEBUG ("");

    if (m_Applet) {
        m_Applet->metadata()->markActive();
        DcpRetranslator::instance()->ensureTranslationLoaded(
               m_Applet->metadata());

       if (m_Applet->isAppletLoaded()) {

            /*
             * If the plugin is available (loaded) we call it to create a new
             * view. (Here we got the widgetId from the plugin itself using the
             * DCP/Part key of the desktop file.)
             */
            if (m_WidgetId < 0) {
                m_WidgetId = m_Applet->getMainWidgetId();
            }
            loadWidget (m_WidgetId);

            return;
        } else if (m_Applet->metadata()->hasApplicationCommand ()) {
            /*
             * If the applet is not loaded from a binary file, but it has an
             * activation command line we execute an external application.
             */
            QString command = m_Applet->metadata()->applicationCommand();
            QProcess *process = new QProcess();

            /* redirect std io channels to /dev/null
             * because otherwise if command is applauncher's invoker 
             * it will pass pipes created by QProcess to the launched 
             * application, which are not valid anymore 
             * see bug 182372
             */            
            process->setStandardInputFile("/dev/null");
            process->setStandardOutputFile("/dev/null");
            process->setStandardErrorFile("/dev/null");

            // this will free up the QProcess when the process ended:
            connect (process, SIGNAL(finished ( int, QProcess::ExitStatus)),
                     process, SLOT(deleteLater()));

            process->start(command);
            return;
        }

        DCP_WARNING ("The applet has no loaded plugin nor an external "
                "command defined");
    } else {
        DCP_WARNING ("The applet is not valid.");
    }

    /*
     * Showing the 'plugin not available' label. We currently show this only if
     * the plugin is really not available, we will not show this if the plugin
     * is crashed. The plugin will be re-enabled (and most likely crash again)
     * when the user activates the applet by clicking on the brief.
     */
    if (!m_MissingLabel) {
        // FIXME: these are temporary translation ids and not present anywhere

        //% "Plugin not available"
        m_MissingLabel = new MLabel (qtTrId("dcp_no_applet_name"));
        m_MissingLabel->setStyleName ("CommonTitleInverted");
        m_MissingLabel->setAlignment (Qt::AlignCenter);
        appendWidget (m_MissingLabel);
        //% "Missing plugin"
        setTitle (qtTrId("dcp_no_applet_title"));
        setTitleLabel ();
    }
}

/*!
 * This function returns if the page would like to prevent its closing,
 * when the user presses the close or back button.
 */
{'fraction_non_alphanumeric': 0.12779552715654952, 'fraction_numerical': 0.005421628424823313, 'mean_word_length': 2.7590975254730714, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 70, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6873905', 'n_tokens_mistral': 2979, 'n_tokens_neox': 2883, 'n_words': 969}