<commit_before>/*
 *  eventlistmodel.cpp  -  model class for lists of alarms or templates
 *  Program:  kalarm
 *  Copyright © 2007 by <NAME> <<EMAIL>>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include "kalarm.h"

#include <QApplication>
#include <QPixmap>

#include <klocale.h>
#include <kiconloader.h>
#include <kdebug.h>

#include "resources/alarmresource.h"
#include "resources/alarmresources.h"
#include "resources/kcalendar.h"
#include "alarmcalendar.h"
#include "alarmtext.h"
#include "preferences.h"
#include "synchtimer.h"
#include "eventlistmodel.moc"


/*=============================================================================
= Class: EventListModel
= Contains all active/archived alarms, or all alarm templates, unsorted.
=============================================================================*/

EventListModel* EventListModel::mAlarmInstance = 0;
EventListModel* EventListModel::mTemplateInstance = 0;
QPixmap* EventListModel::mTextIcon = 0;
QPixmap* EventListModel::mFileIcon = 0;
QPixmap* EventListModel::mCommandIcon = 0;
QPixmap* EventListModel::mEmailIcon = 0;
QSize    EventListModel::mIconSize;
int      EventListModel::mTimeHourPos = -2;


EventListModel* EventListModel::alarms()
{
	if (!mAlarmInstance)
	{
		mAlarmInstance = new EventListModel(static_cast<KCalEvent::Status>(KCalEvent::ACTIVE | KCalEvent::ARCHIVED));
		Preferences::connect(SIGNAL(archivedColourChanged(const QColor&)), mAlarmInstance, SLOT(slotUpdateArchivedColour(const QColor&)));
		Preferences::connect(SIGNAL(disabledColourChanged(const QColor&)), mAlarmInstance, SLOT(slotUpdateDisabledColour(const QColor&)));
		Preferences::connect(SIGNAL(workTimeChanged(const QTime&, const QTime&, const QBitArray&)), mAlarmInstance, SLOT(slotUpdateWorkingHours()));
	}
	return mAlarmInstance;
}

EventListModel* EventListModel::templates()
{
	if (!mTemplateInstance)
		mTemplateInstance = new EventListModel(KCalEvent::TEMPLATE);
	return mTemplateInstance;
}

EventListModel::EventListModel(KCalEvent::Status status, QObject* parent)
	: QAbstractTableModel(parent),
	  mStatus(status)
{
	// Load the current list of alarms.
	// The list will be updated whenever a signal is received notifying changes.
	// We need to store the list so that when deletions occur, the deleted alarm's
	// position in the list can be determined.
	mEvents = AlarmCalendar::resources()->events(mStatus);
for(int x=0; x<mEvents.count(); ++x)kDebug()<<"Event"<<(void*)mEvents[x];
	if (!mTextIcon)
	{
		mTextIcon    = new QPixmap(SmallIcon("text"));
		mFileIcon    = new QPixmap(SmallIcon("document-open"));
		mCommandIcon = new QPixmap(SmallIcon("exec"));
		mEmailIcon   = new QPixmap(SmallIcon("mail"));
		mIconSize = mTextIcon->size().expandedTo(mFileIcon->size()).expandedTo(mCommandIcon->size()).expandedTo(mEmailIcon->size());
	}
	MinuteTimer::connect(this, SLOT(slotUpdateTimeTo()));
#ifdef __GNUC__
#warning Need to update when a resource is reloaded, to prevent crash
#endif
	connect(AlarmResources::instance(), SIGNAL(resourceStatusChanged(AlarmResource*, AlarmResources::Change)), SLOT(slotResourceStatusChanged(AlarmResource*, AlarmResources::Change)));
}

int EventListModel::rowCount(const QModelIndex& parent) const
{
	if (parent.isValid())
		return 0;
	return mEvents.count();
}

int EventListModel::columnCount(const QModelIndex& parent) const
{
	if (parent.isValid())
		return 0;
	return ColumnCount;
}

QModelIndex EventListModel::index(int row, int column, const QModelIndex& parent) const<commit_msg>Remove warning<commit_after>/*
 *  eventlistmodel.cpp  -  model class for lists of alarms or templates
 *  Program:  kalarm
 *  Copyright © 2007 by <NAME> <<EMAIL>>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include "kalarm.h"

#include <QApplication>
#include <QPixmap>

#include <klocale.h>
#include <kiconloader.h>
#include <kdebug.h>

#include "resources/alarmresource.h"
#include "resources/alarmresources.h"
#include "resources/kcalendar.h"
#include "alarmcalendar.h"
#include "alarmtext.h"
#include "preferences.h"
#include "synchtimer.h"
#include "eventlistmodel.moc"


/*=============================================================================
= Class: EventListModel
= Contains all active/archived alarms, or all alarm templates, unsorted.
=============================================================================*/

EventListModel* EventListModel::mAlarmInstance = 0;
EventListModel* EventListModel::mTemplateInstance = 0;
QPixmap* EventListModel::mTextIcon = 0;
QPixmap* EventListModel::mFileIcon = 0;
QPixmap* EventListModel::mCommandIcon = 0;
QPixmap* EventListModel::mEmailIcon = 0;
QSize    EventListModel::mIconSize;
int      EventListModel::mTimeHourPos = -2;


EventListModel* EventListModel::alarms()
{
	if (!mAlarmInstance)
	{
		mAlarmInstance = new EventListModel(static_cast<KCalEvent::Status>(KCalEvent::ACTIVE | KCalEvent::ARCHIVED));
		Preferences::connect(SIGNAL(archivedColourChanged(const QColor&)), mAlarmInstance, SLOT(slotUpdateArchivedColour(const QColor&)));
		Preferences::connect(SIGNAL(disabledColourChanged(const QColor&)), mAlarmInstance, SLOT(slotUpdateDisabledColour(const QColor&)));
		Preferences::connect(SIGNAL(workTimeChanged(const QTime&, const QTime&, const QBitArray&)), mAlarmInstance, SLOT(slotUpdateWorkingHours()));
	}
	return mAlarmInstance;
}

EventListModel* EventListModel::templates()
{
	if (!mTemplateInstance)
		mTemplateInstance = new EventListModel(KCalEvent::TEMPLATE);
	return mTemplateInstance;
}

EventListModel::EventListModel(KCalEvent::Status status, QObject* parent)
	: QAbstractTableModel(parent),
	  mStatus(status)
{
	// Load the current list of alarms.
	// The list will be updated whenever a signal is received notifying changes.
	// We need to store the list so that when deletions occur, the deleted alarm's
	// position in the list can be determined.
	mEvents = AlarmCalendar::resources()->events(mStatus);
for(int x=0; x<mEvents.count(); ++x)kDebug()<<"Event"<<(void*)mEvents[x];
	if (!mTextIcon)
	{
		mTextIcon    = new QPixmap(SmallIcon("text"));
		mFileIcon    = new QPixmap(SmallIcon("document-open"));
		mCommandIcon = new QPixmap(SmallIcon("exec"));
		mEmailIcon   = new QPixmap(SmallIcon("mail"));
		mIconSize = mTextIcon->size().expandedTo(mFileIcon->size()).expandedTo(mCommandIcon->size()).expandedTo(mEmailIcon->size());
	}
	MinuteTimer::connect(this, SLOT(slotUpdateTimeTo()));
	connect(AlarmResources::instance(), SIGNAL(resourceStatusChanged(AlarmResource*, AlarmResources::Change)), SLOT(slotResourceStatusChanged(AlarmResource*, AlarmResources::Change)));
}

int EventListModel::rowCount(const QModelIndex& parent) const
{
	if (parent.isValid())
		return 0;
	return mEvents.count();
}

int EventListModel::columnCount(const QModelIndex& parent) const
{
	if (parent.isValid())
		return 0;
	return ColumnCount;
}

QModelIndex EventListModel::index(int row, int column, const QModelIndex& parent) const
{'fraction_non_alphanumeric': 0.14940864108134203, 'fraction_numerical': 0.00627564566739078, 'mean_word_length': 6.288478452066842, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, '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': '1276420', 'n_tokens_mistral': 2587, 'n_tokens_neox': 2473, 'n_words': 685}