<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
 */

#include "emailfeedmodel.h"

#include <QDebug>

#include <QDateTime>
#include <QStringList>
#include <QDesktopServices>

#include <actions.h>

#include <emailmessagelistmodel.h>

const int FetchBatch = 10;

// TODO: firm up this decision and move to a more central place
const int BodyPreviewSize = 160;  // big enough for an SMS, larger than a tweet

EmailFeedModel::EmailFeedModel(QVariant account, QObject *parent):
        McaFeedModel(parent)
{
    // TODO: pass the account id when Carl makes that available
    m_source = new EmailMessageListModel(this);
    m_source->setAccountKey(account);
    m_actions = new McaActions;

    connect(m_source, SIGNAL(rowsInserted(QModelIndex,int,int)),
            this, SLOT(sourceRowsInserted(QModelIndex,int,int)));
    connect(m_source, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
            this, SLOT(sourceRowsRemoved(QModelIndex,int,int)));
    connect(m_source, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
            this, SLOT(sourceDataChanged(QModelIndex,QModelIndex)));
    connect(m_source, SIGNAL(modelReset()),
            this, SLOT(resetModel()));
    connect(m_actions, SIGNAL(standardAction(QString,QString)),
            this, SLOT(performAction(QString,QString)));
    if(canFetchMore(QModelIndex())) fetchMore(QModelIndex());
}

EmailFeedModel::~EmailFeedModel()
{
    delete m_source;
}

//
// public member functions
//
void EmailFeedModel::setSearchText(const QString &text)
{
    qDebug () << "Set Search: " << text;
    if (text.isEmpty() || m_searchText!=text) {
        m_source->setSearch(text);
        m_searchText=text;
    }
}

int EmailFeedModel::rowCount(const QModelIndex &parent) const
{
    Q_UNUSED(parent);
    return m_messages.count();
}

QVariant EmailFeedModel::data(const QModelIndex &index, int role) const
{
    int row = index.row();
    if (row >= m_messages.count())
        return QVariant();

    EmailMessage *message = m_messages.at(row);<commit_msg>Fixed BMC#20274 - memory leaks in "emailfeedmodel.cpp".<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
 */

#include "emailfeedmodel.h"

#include <QDebug>

#include <QDateTime>
#include <QStringList>
#include <QDesktopServices>

#include <actions.h>

#include <emailmessagelistmodel.h>

const int FetchBatch = 10;

// TODO: firm up this decision and move to a more central place
const int BodyPreviewSize = 160;  // big enough for an SMS, larger than a tweet

EmailFeedModel::EmailFeedModel(QVariant account, QObject *parent):
        McaFeedModel(parent)
{
    // TODO: pass the account id when Carl makes that available
    m_source = new EmailMessageListModel(this);
    m_source->setAccountKey(account);
    m_actions = new McaActions;

    connect(m_source, SIGNAL(rowsInserted(QModelIndex,int,int)),
            this, SLOT(sourceRowsInserted(QModelIndex,int,int)));
    connect(m_source, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
            this, SLOT(sourceRowsRemoved(QModelIndex,int,int)));
    connect(m_source, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
            this, SLOT(sourceDataChanged(QModelIndex,QModelIndex)));
    connect(m_source, SIGNAL(modelReset()),
            this, SLOT(resetModel()));
    connect(m_actions, SIGNAL(standardAction(QString,QString)),
            this, SLOT(performAction(QString,QString)));
    if(canFetchMore(QModelIndex())) fetchMore(QModelIndex());
}

EmailFeedModel::~EmailFeedModel()
{
    delete m_source;
    delete m_actions;
    int count = m_messages.count();
    for (int i = 0; i < count; i++)
    {
        delete m_messages.at(0);
        m_messages.removeAt(0);
    }
}

//
// public member functions
//
void EmailFeedModel::setSearchText(const QString &text)
{
    qDebug () << "Set Search: " << text;
    if (text.isEmpty() || m_searchText!=text) {
        m_source->setSearch(text);
        m_searchText=text;
    }
}

int EmailFeedModel::rowCount(const QModelIndex &parent) const
{
    Q_UNUSED(parent);
    return m_messages.count();
}

QVariant EmailFeedModel::data(const QModelIndex &index, int role) const
{
    int row = index.row();
    if (row >= m_messages.count())
        return QVariant();

    EmailMessage *message = m_messages.at(row);
{'fraction_non_alphanumeric': 0.12195647489765137, 'fraction_numerical': 0.007326007326007326, 'mean_word_length': 4.073224043715847, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '892790', 'n_tokens_mistral': 1495, 'n_tokens_neox': 1447, 'n_words': 343}