<commit_before>/*
 * $Id$
 *
 * Copyright(C) 1998-2008 <NAME>
 *
 */

#include <qmfolder.h>

#include <qsstl.h>

#include <algorithm>

#include "foldermodel.h"

using namespace qm;
using namespace qs;


/****************************************************************************
 *
 * FolderModelBase
 *
 */

qm::FolderModelBase::~FolderModelBase()
{
}


/****************************************************************************
 *
 * FolderModel
 *
 */

qm::FolderModel::~FolderModel()
{
}


/****************************************************************************
 *
 * DefaultFolderModel
 *
 */

qm::DefaultFolderModel::DefaultFolderModel() :
	pCurrentAccount_(0),
	pCurrentFolder_(0),
	pTemporaryAccount_(0),
	pTemporaryFolder_(0)
{
}

qm::DefaultFolderModel::~DefaultFolderModel()
{
}

std::pair<Account*, Folder*> qm::DefaultFolderModel::getCurrent() const
{
	return std::make_pair(pCurrentAccount_, pCurrentFolder_);
}

std::pair<Account*, Folder*> qm::DefaultFolderModel::getTemporary() const
{
	return std::make_pair(pTemporaryAccount_, pTemporaryFolder_);
}

void qm::DefaultFolderModel::setCurrent(Account* pAccount,
										Folder* pFolder,
										bool bDelay)
{
	assert(!pAccount || !pFolder);
	assert(!pFolder || !pFolder->isHidden());
	
	if (pFolder) {
		if (pFolder != pCurrentFolder_) {
			pCurrentAccount_ = 0;
			pCurrentFolder_ = pFolder;
			fireFolderSelected(pFolder, bDelay);
		}
	}
	else {
		if (pAccount != pCurrentAccount_ || !pAccount) {
			pCurrentAccount_ = pAccount;
			pCurrentFolder_ = 0;
			fireAccountSelected(pAccount, bDelay);
		}
	}
}

void qm::DefaultFolderModel::setTemporary(Account* pAccount,
										  Folder* pFolder)
{
	pTemporaryAccount_ = pAccount;
	pTemporaryFolder_ = pFolder;
}

void qm::DefaultFolderModel::addFolderModelHandler(FolderModelHandler* pHandler)
{
	listHandler_.push_back(pHandler);
}

void qm::DefaultFolderModel::removeFolderModelHandler(FolderModelHandler* pHandler)
{
	HandlerList::iterator it = std::remove(listHandler_.begin(),
		listHandler_.end(), pHandler);
	listHandler_.erase(it, listHandler_.end());
}

void qm::DefaultFolderModel::fireAccountSelected(Account* pAccount,
												 bool bDelay) const
{
	FolderModelEvent event(pAccount, bDelay);
	for (HandlerList::const_iterator it = listHandler_.begin(); it != listHandler_.end(); ++it)
		(*it)->accountSelected(event);
}

void qm::DefaultFolderModel::fireFolderSelected(Folder* pFolder,
												bool bDelay) const
{
	assert(pFolder);
	
	FolderModelEvent event(pFolder, bDelay);
	for (HandlerList::const_iterator it = listHandler_.begin(); it != listHandler_.end(); ++it)
		(*it)->folderSelected(event);
}


/****************************************************************************
 *
 * FolderModelHandler
 *
 */

qm::FolderModelHandler::~FolderModelHandler()
{
}


/****************************************************************************
 *
 * DelayedFolderModelHandler
 *
 */

qm::DelayedFolderModelHandler::DelayedFolderModelHandler(FolderModelHandler* pHandler) :
	pHandler_(pHandler),
	bTimer_(false),
	pAccount_(0),
	pFolder_(0)<commit_msg>Use boost::bind.<commit_after>/*
 * $Id$
 *
 * Copyright(C) 1998-2008 <NAME>
 *
 */

#include <qmfolder.h>

#include <qsstl.h>

#include <algorithm>

#include <boost/bind.hpp>

#include "foldermodel.h"

using namespace qm;
using namespace qs;


/****************************************************************************
 *
 * FolderModelBase
 *
 */

qm::FolderModelBase::~FolderModelBase()
{
}


/****************************************************************************
 *
 * FolderModel
 *
 */

qm::FolderModel::~FolderModel()
{
}


/****************************************************************************
 *
 * DefaultFolderModel
 *
 */

qm::DefaultFolderModel::DefaultFolderModel() :
	pCurrentAccount_(0),
	pCurrentFolder_(0),
	pTemporaryAccount_(0),
	pTemporaryFolder_(0)
{
}

qm::DefaultFolderModel::~DefaultFolderModel()
{
}

std::pair<Account*, Folder*> qm::DefaultFolderModel::getCurrent() const
{
	return std::make_pair(pCurrentAccount_, pCurrentFolder_);
}

std::pair<Account*, Folder*> qm::DefaultFolderModel::getTemporary() const
{
	return std::make_pair(pTemporaryAccount_, pTemporaryFolder_);
}

void qm::DefaultFolderModel::setCurrent(Account* pAccount,
										Folder* pFolder,
										bool bDelay)
{
	assert(!pAccount || !pFolder);
	assert(!pFolder || !pFolder->isHidden());
	
	if (pFolder) {
		if (pFolder != pCurrentFolder_) {
			pCurrentAccount_ = 0;
			pCurrentFolder_ = pFolder;
			fireFolderSelected(pFolder, bDelay);
		}
	}
	else {
		if (pAccount != pCurrentAccount_ || !pAccount) {
			pCurrentAccount_ = pAccount;
			pCurrentFolder_ = 0;
			fireAccountSelected(pAccount, bDelay);
		}
	}
}

void qm::DefaultFolderModel::setTemporary(Account* pAccount,
										  Folder* pFolder)
{
	pTemporaryAccount_ = pAccount;
	pTemporaryFolder_ = pFolder;
}

void qm::DefaultFolderModel::addFolderModelHandler(FolderModelHandler* pHandler)
{
	listHandler_.push_back(pHandler);
}

void qm::DefaultFolderModel::removeFolderModelHandler(FolderModelHandler* pHandler)
{
	HandlerList::iterator it = std::remove(listHandler_.begin(),
		listHandler_.end(), pHandler);
	listHandler_.erase(it, listHandler_.end());
}

void qm::DefaultFolderModel::fireAccountSelected(Account* pAccount,
												 bool bDelay) const
{
	FolderModelEvent event(pAccount, bDelay);
	std::for_each(listHandler_.begin(), listHandler_.end(),
		boost::bind(&FolderModelHandler::accountSelected, _1, boost::cref(event)));
}

void qm::DefaultFolderModel::fireFolderSelected(Folder* pFolder,
												bool bDelay) const
{
	assert(pFolder);
	
	FolderModelEvent event(pFolder, bDelay);
	std::for_each(listHandler_.begin(), listHandler_.end(),
		boost::bind(&FolderModelHandler::folderSelected, _1, boost::cref(event)));
}


/****************************************************************************
 *
 * FolderModelHandler
 *
 */

qm::FolderModelHandler::~FolderModelHandler()
{
}


/****************************************************************************
 *
 * DelayedFolderModelHandler
 *
 */

qm::DelayedFolderModelHandler::DelayedFolderModelHandler(FolderModelHandler* pHandler) :
	pHandler_(pHandler),
	bTimer_(false),
	pAccount_(0),
	pFolder_(0)
{'fraction_non_alphanumeric': 0.24784413925263493, 'fraction_numerical': 0.005429575215586075, 'mean_word_length': 6.38561320754717, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 20, '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': '2743108', 'n_tokens_mistral': 2087, 'n_tokens_neox': 1881, 'n_words': 284}