<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 <QHash>
#include <QTemporaryFile>

#include "models.h"
#include "meegolocale.h"

static const QString noteBookRole = "noteBook";
static const QString noteRole = "note";

using namespace meego;

ItemData::ItemData(QObject *parent) :
    QObject(parent),
    m_storage(0)
{

}

ItemData::ItemData(const AbstractDataStorage::ItemData &itemData, QObject *parent) :
    QObject(parent),
    m_storage(0),
    m_itemData(itemData)
{

}

void ItemData::setTitle(const QString &title)
{
    if (!m_storage)
        return;

    if (m_itemData.title == title)
        return;

    if (!setTitleHelper(title))
        return;

    m_itemData.title = title;
    emit titleChanged();
}

void ItemData::setPosition(qint32 position)
{
    if (!m_storage)
        return;

    if (m_itemData.position == position)
        return;

    if (!setPositionHelper(position))
        return;

    m_itemData.position = position;
    emit positionChanged();
}
//----------------------------------------------------------------------------------------------
NoteBook::NoteBook(QObject *parent) :
    ItemData(parent)
{

}

NoteBook::NoteBook(const AbstractDataStorage::NoteBook &noteBook, QObject *parent) :
    ItemData(noteBook, parent)
{

}

bool NoteBook::setTitleHelper(const QString &title)
{
    return m_storage->updateNoteBookTitle(m_itemData.id, title);
}

bool NoteBook::setPositionHelper(qint32 position)
{
    return m_storage->updateNoteBookPosition(m_itemData.id, position);
}

int NoteBook::notesCount() const
{
    return m_storage ? m_storage->notesCount(id()) : 0;
}

void NoteBook::setStorage(AbstractDataStorage *storage)
{
    if (m_storage) {
        disconnect(m_storage, SIGNAL(noteCreated()));
        disconnect(m_storage, SIGNAL(noteRemoved()));
    }
    ItemData::setStorage(storage);
    if (m_storage) {
        connect(m_storage, SIGNAL(noteCreated()), SIGNAL(notesCountChanged()));
        connect(m_storage, SIGNAL(noteRemoved()), SIGNAL(notesCountChanged()));
    }
}

bool NoteBook::operator < (const NoteBook &other) const
{
    if (!m_storage)
        return false;

    if (id() == m_storage->defaultNoteBookId())
        return true;
    if (other.id() == m_storage->defaultNoteBookId())
        return false;

    //use Locale api
    meego::Locale locale;
    return locale.lessThan(title(), other.title());
}

bool NoteBook::operator > (const NoteBook &other) const
{
    if (!m_storage)
        return false;

    if (id() == m_storage->defaultNoteBookId())
        return true;
    if (other.id() == m_storage->defaultNoteBookId())
        return false;

    return title() > other.title();
}
//----------------------------------------------------------------------------------------------
Note::Note(QObject *parent) :
    ItemData(parent),
    m_noteBook(0)
{

}

Note::Note(const AbstractDataStorage::Note &note, NoteBook *noteBook, QObject *parent) :
    ItemData(note, parent),
    m_note(note),
    m_noteBook(noteBook)
{

}

bool Note::setTitleHelper(const QString &title)
{
    return m_storage->updateNoteTitle(m_note.noteBookId, m_note.id, title);
}

bool Note::setPositionHelper(qint32 position)
{
    return m_storage->updateNotePosition(m_note.noteBookId, m_note.id, position);
}

void Note::setNoteBook(NoteBook *noteBook)
{
    if (!m_storage)
        return;

    if (m_noteBook == noteBook)
        return;

    m_noteBook = noteBook;
    emit noteBookChanged();
}

void Note::setHtml(const QString &html)
{
    if (!m_storage)
        return;

    if (m_note.html == html)
        return;

    if (!m_storage->updateNoteHtml(m_note.noteBookId, m_note.id, html))
        return;

    m_note.html = html;
    emit htmlChanged();
}

bool Note::operator < (const Note &other) const
{
    if (!m_storage)
        return false;

    //use Locale api
    meego::Locale locale;
    return locale.lessThan(title(), other.title());
}

bool Note::operator > (const Note &other) const
{
    if (!m_storage)
        return false;
    return title() > other.title();
}
//----------------------------------------------------------------------------------------------
ItemsDataModel::ItemsDataModel(QObject *parent) :
    QAbstractListModel(parent),
    m_storage(0),
    m_sortOrder(ASC),
    m_sortingEnabled(false)
{

}

void ItemsDataModel::setStorage(AbstractDataStorage *storage)
{
    if (!storage)
        return;

    if (m_storage)
        disconnect(m_storage, SIGNAL(noteMoved()));

    m_storage = storage;

    if (m_storage)
        connect(m_storage, SIGNAL(noteMoved()), SLOT(noteMovedSlot()));
<commit_msg>change so Locale variable is declared once and static version is used. This should be better than declaring evertime in the sort function<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 <QHash>
#include <QTemporaryFile>

#include "models.h"
#include "meegolocale.h"

static const QString noteBookRole = "noteBook";
static const QString noteRole = "note";

using namespace meego;
static const Locale g_locale;

ItemData::ItemData(QObject *parent) :
    QObject(parent),
    m_storage(0)
{

}

ItemData::ItemData(const AbstractDataStorage::ItemData &itemData, QObject *parent) :
    QObject(parent),
    m_storage(0),
    m_itemData(itemData)
{

}

void ItemData::setTitle(const QString &title)
{
    if (!m_storage)
        return;

    if (m_itemData.title == title)
        return;

    if (!setTitleHelper(title))
        return;

    m_itemData.title = title;
    emit titleChanged();
}

void ItemData::setPosition(qint32 position)
{
    if (!m_storage)
        return;

    if (m_itemData.position == position)
        return;

    if (!setPositionHelper(position))
        return;

    m_itemData.position = position;
    emit positionChanged();
}
//----------------------------------------------------------------------------------------------
NoteBook::NoteBook(QObject *parent) :
    ItemData(parent)
{

}

NoteBook::NoteBook(const AbstractDataStorage::NoteBook &noteBook, QObject *parent) :
    ItemData(noteBook, parent)
{

}

bool NoteBook::setTitleHelper(const QString &title)
{
    return m_storage->updateNoteBookTitle(m_itemData.id, title);
}

bool NoteBook::setPositionHelper(qint32 position)
{
    return m_storage->updateNoteBookPosition(m_itemData.id, position);
}

int NoteBook::notesCount() const
{
    return m_storage ? m_storage->notesCount(id()) : 0;
}

void NoteBook::setStorage(AbstractDataStorage *storage)
{
    if (m_storage) {
        disconnect(m_storage, SIGNAL(noteCreated()));
        disconnect(m_storage, SIGNAL(noteRemoved()));
    }
    ItemData::setStorage(storage);
    if (m_storage) {
        connect(m_storage, SIGNAL(noteCreated()), SIGNAL(notesCountChanged()));
        connect(m_storage, SIGNAL(noteRemoved()), SIGNAL(notesCountChanged()));
    }
}

bool NoteBook::operator < (const NoteBook &other) const
{
    if (!m_storage)
        return false;

    if (id() == m_storage->defaultNoteBookId())
        return true;
    if (other.id() == m_storage->defaultNoteBookId())
        return false;

    return g_locale.lessThan(title(), other.title());
}

bool NoteBook::operator > (const NoteBook &other) const
{
    if (!m_storage)
        return false;

    if (id() == m_storage->defaultNoteBookId())
        return true;
    if (other.id() == m_storage->defaultNoteBookId())
        return false;

    return title() > other.title();
}
//----------------------------------------------------------------------------------------------
Note::Note(QObject *parent) :
    ItemData(parent),
    m_noteBook(0)
{

}

Note::Note(const AbstractDataStorage::Note &note, NoteBook *noteBook, QObject *parent) :
    ItemData(note, parent),
    m_note(note),
    m_noteBook(noteBook)
{

}

bool Note::setTitleHelper(const QString &title)
{
    return m_storage->updateNoteTitle(m_note.noteBookId, m_note.id, title);
}

bool Note::setPositionHelper(qint32 position)
{
    return m_storage->updateNotePosition(m_note.noteBookId, m_note.id, position);
}

void Note::setNoteBook(NoteBook *noteBook)
{
    if (!m_storage)
        return;

    if (m_noteBook == noteBook)
        return;

    m_noteBook = noteBook;
    emit noteBookChanged();
}

void Note::setHtml(const QString &html)
{
    if (!m_storage)
        return;

    if (m_note.html == html)
        return;

    if (!m_storage->updateNoteHtml(m_note.noteBookId, m_note.id, html))
        return;

    m_note.html = html;
    emit htmlChanged();
}

bool Note::operator < (const Note &other) const
{
    if (!m_storage)
        return false;

    return g_locale.lessThan(title(), other.title());
}

bool Note::operator > (const Note &other) const
{
    if (!m_storage)
        return false;
    return title() > other.title();
}
//----------------------------------------------------------------------------------------------
ItemsDataModel::ItemsDataModel(QObject *parent) :
    QAbstractListModel(parent),
    m_storage(0),
    m_sortOrder(ASC),
    m_sortingEnabled(false)
{

}

void ItemsDataModel::setStorage(AbstractDataStorage *storage)
{
    if (!storage)
        return;

    if (m_storage)
        disconnect(m_storage, SIGNAL(noteMoved()));

    m_storage = storage;

    if (m_storage)
        connect(m_storage, SIGNAL(noteMoved()), SLOT(noteMovedSlot()));

{'fraction_non_alphanumeric': 0.1793759041124199, 'fraction_numerical': 0.0039264310808018186, 'mean_word_length': 2.8317498020585905, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 35, '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': '1821842', 'n_tokens_mistral': 3038, 'n_tokens_neox': 2963, 'n_words': 646}