<commit_before>/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (<EMAIL>)
**
** This file is part of meegotouch-controlpanelapplets.
**
** If you have questions regarding the use of this file, please contact
** Nokia at <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
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/

#include "batteryimage.h"

#include <QTimer>
#include <QStringList>
#include <MTheme>

#undef DEBUG
#include "../debug.h"

BatteryImage::BatteryImage (QGraphicsItem *parent) :
        MImageWidget (parent),
        m_PowerSave (false),
        m_ChargingSpeed (0),
        m_timer (NULL),
        m_batteryLevel (0),
        m_iconCurrentSet (IconTypeUnset),
        m_ImageIndex (-1)
{
    setZoomFactor (1.0);
    setIconSet ();
    setObjectName ("CommonMainIcon");
    connect (MTheme::instance (), SIGNAL (pixmapRequestsFinished ()),
             this, SLOT (updateImage ()));
}

void
BatteryImage::loadImages (
        BatteryImage::BatteryIconType type)
{
    if (!m_Images.isEmpty ()) {
        // Release the pixmaps
        foreach (const QPixmap *icon, m_Images)
            MTheme::instance ()->releasePixmap (icon);
        
        m_Images.clear ();
    }

    QString ID = "battery";
    switch (type) {
        case ICON_POWERSAVE:
            ID = "powersave";
            break;

        case ICON_CHARGING:
            ID = "charging";
            break;

        default:
            break;
    }

  m_Images <<
      getPixmap (QString ("icon-m-energy-management-%1-verylow").arg (ID)) <<
      getPixmap (QString ("icon-m-energy-management-%1-low").arg (ID)) <<
      getPixmap (QString ("icon-m-energy-management-%1").arg (ID) + "1") <<
      getPixmap (QString ("icon-m-energy-management-%1").arg (ID) + "2") <<
      getPixmap (QString ("icon-m-energy-management-%1").arg (ID) + "3") <<
      getPixmap (QString ("icon-m-energy-management-%1").arg (ID) + "4") <<
      getPixmap (QString ("icon-m-energy-management-%1").arg (ID) + "5") <<
      getPixmap (QString ("icon-m-energy-management-%1").arg (ID) + "6") <<
      getPixmap (QString ("icon-m-energy-management-%1").arg (ID) + "7") <<
      getPixmap (QString ("icon-m-energy-management-%1").arg (ID) + "8");
    
    m_iconCurrentSet = type;
}

BatteryImage::~BatteryImage ()
{
    delete m_timer;
    m_timer = NULL;

    if (!m_Images.isEmpty ()) {
        // Release the pixmaps
        foreach (const QPixmap *icon, m_Images)
            MTheme::instance ()->releasePixmap (icon);
        m_Images.clear ();
    }
}

/*!
 * Updates the battery energy level, stores the current level and updates the
 * image if it is necessary
 */
void
BatteryImage::updateBatteryLevel (
        int level)
{
    SYS_DEBUG ("level = %d", level);
    if (m_batteryLevel == level)
        return;
    m_batteryLevel = level;

    updateImage ();
}

void
BatteryImage::setIconSet ()
{
    BatteryImage::BatteryIconType type;

    type = ICON_NORMAL;

    if (m_PowerSave) {
        type = ICON_POWERSAVE;
    } else if (charging()) {
        type = ICON_CHARGING;
    }

    if (m_iconCurrentSet != type) {
        SYS_DEBUG ("*** new type = %d", type);
        stopTimer ();
        loadImages (type);
        maybeStartTimer ();
    }
}

void
BatteryImage::updateImage ()
{
    if (m_ImageIndex == -1)
        m_ImageIndex = m_batteryLevel;
<commit_msg>Fixes: a bugfix<commit_after>/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (<EMAIL>)
**
** This file is part of meegotouch-controlpanelapplets.
**
** If you have questions regarding the use of this file, please contact
** Nokia at <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
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/

#include "batteryimage.h"

#include <QTimer>
#include <QStringList>
#include <MTheme>

#undef DEBUG
#include "../debug.h"

BatteryImage::BatteryImage (QGraphicsItem *parent) :
        MImageWidget (parent),
        m_PowerSave (false),
        m_ChargingSpeed (0),
        m_timer (NULL),
        m_batteryLevel (0),
        m_iconCurrentSet (IconTypeUnset),
        m_ImageIndex (-1)
{
    setZoomFactor (1.0);
    setIconSet ();
    setObjectName ("CommonMainIcon");
    connect (MTheme::instance (), SIGNAL (pixmapRequestsFinished ()),
             this, SLOT (updateImage ()));
}

void
BatteryImage::loadImages (
        BatteryImage::BatteryIconType type)
{
    if (!m_Images.isEmpty ()) {
        // Release the pixmaps
        foreach (const QPixmap *icon, m_Images)
            MTheme::instance ()->releasePixmap (icon);
        
        m_Images.clear ();
    }

    QString ID = "battery";
    switch (type) {
        case ICON_POWERSAVE:
            ID = "powersave";
            break;

        case ICON_CHARGING:
            ID = "charging";
            break;

        default:
            break;
    }

  m_Images <<
      getPixmap (QString ("icon-m-energy-management-%1-verylow").arg (ID)) <<
      getPixmap (QString ("icon-m-energy-management-%1-low").arg (ID)) <<
      getPixmap (QString ("icon-m-energy-management-%1").arg (ID) + "1") <<
      getPixmap (QString ("icon-m-energy-management-%1").arg (ID) + "2") <<
      getPixmap (QString ("icon-m-energy-management-%1").arg (ID) + "3") <<
      getPixmap (QString ("icon-m-energy-management-%1").arg (ID) + "4") <<
      getPixmap (QString ("icon-m-energy-management-%1").arg (ID) + "5") <<
      getPixmap (QString ("icon-m-energy-management-%1").arg (ID) + "6") <<
      getPixmap (QString ("icon-m-energy-management-%1").arg (ID) + "7") <<
      getPixmap (QString ("icon-m-energy-management-%1").arg (ID) + "8");
    
    m_iconCurrentSet = type;
}

BatteryImage::~BatteryImage ()
{
    delete m_timer;
    m_timer = NULL;

    if (!m_Images.isEmpty ()) {
        // Release the pixmaps
        foreach (const QPixmap *icon, m_Images)
            MTheme::instance ()->releasePixmap (icon);
        m_Images.clear ();
    }
}

/*!
 * Updates the battery energy level, stores the current level and updates the
 * image if it is necessary
 */
void
BatteryImage::updateBatteryLevel (
        int level)
{
    SYS_DEBUG ("level = %d", level);
    if (m_batteryLevel == level)
        return;
    m_batteryLevel = level;

    updateImage ();
}

void
BatteryImage::setIconSet ()
{
    BatteryImage::BatteryIconType type;

    type = ICON_NORMAL;

    if (m_PowerSave) {
        type = ICON_POWERSAVE;
    } else if (charging()) {
        type = ICON_CHARGING;
    }

    stopTimer ();
    if (m_iconCurrentSet != type) {
        SYS_DEBUG ("*** new type = %d", type);
        loadImages (type);
    }
    maybeStartTimer ();
}

void
BatteryImage::updateImage ()
{
    if (m_ImageIndex == -1)
        m_ImageIndex = m_batteryLevel;

{'fraction_non_alphanumeric': 0.17821125265392782, 'fraction_numerical': 0.007961783439490446, 'mean_word_length': 2.8513030148186, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 17, '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': '910241', 'n_tokens_mistral': 2418, 'n_tokens_neox': 2325, 'n_words': 588}