2013-11-17 20:37:06 +01:00
|
|
|
/**
|
|
|
|
* @author Edouard DUPIN
|
|
|
|
*
|
|
|
|
* @copyright 2010, Edouard DUPIN, all right reserved
|
|
|
|
*
|
|
|
|
* @license GPL v3 (see license file)
|
|
|
|
*/
|
|
|
|
|
2013-12-13 21:50:40 +01:00
|
|
|
#include <ewol/context/Context.h>
|
2013-11-17 20:37:06 +01:00
|
|
|
#include <appl/debug.h>
|
|
|
|
#include <appl/Gui/WorkerCloseAllFile.h>
|
|
|
|
|
2014-08-07 23:41:48 +02:00
|
|
|
appl::WorkerCloseAllFile::WorkerCloseAllFile() {
|
2013-11-20 21:57:00 +01:00
|
|
|
addObjectType("appl::WorkerCloseAllFile");
|
2013-11-17 20:37:06 +01:00
|
|
|
// load buffer manager:
|
2014-08-07 23:41:48 +02:00
|
|
|
m_bufferManager = appl::BufferManager::create();
|
|
|
|
}
|
|
|
|
|
|
|
|
void appl::WorkerCloseAllFile::init() {
|
2014-09-12 21:52:03 +02:00
|
|
|
ewol::object::Worker::init();
|
2014-06-05 22:01:24 +02:00
|
|
|
if (m_bufferManager == nullptr) {
|
2013-11-17 20:37:06 +01:00
|
|
|
APPL_ERROR("can not call unexistant buffer manager ... ");
|
2014-09-12 21:52:03 +02:00
|
|
|
destroy();
|
2013-11-17 20:37:06 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// List all current open file :
|
|
|
|
for (int64_t iii=m_bufferManager->size()-1; iii>=0; --iii) {
|
2014-08-07 23:41:48 +02:00
|
|
|
std::shared_ptr<appl::Buffer> tmpBuffer = m_bufferManager->get(iii);
|
2014-06-05 22:01:24 +02:00
|
|
|
if (tmpBuffer == nullptr) {
|
2013-11-17 20:37:06 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (tmpBuffer->isModify() == false) {
|
2014-08-07 23:41:48 +02:00
|
|
|
APPL_TODO("destroy object");
|
|
|
|
tmpBuffer->destroy();
|
2013-11-17 20:37:06 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
m_bufferNameList.push_back(tmpBuffer->getFileName());
|
|
|
|
}
|
|
|
|
// checkif an element has something to do in the queue
|
|
|
|
if (m_bufferNameList.size() == 0) {
|
2014-09-12 21:52:03 +02:00
|
|
|
destroy();
|
2013-11-17 20:37:06 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// create the worker :
|
2014-09-15 07:21:22 +02:00
|
|
|
m_worker = appl::WorkerCloseFile::create();
|
2016-02-19 23:33:00 +01:00
|
|
|
m_worker->signalCloseDone.connect(shared_from_this(), &appl::WorkerCloseAllFile::onCallbackCloseDone);
|
2014-09-15 07:21:22 +02:00
|
|
|
m_worker->startAction(m_bufferNameList.front());
|
2013-11-17 20:37:06 +01:00
|
|
|
// remove first element :
|
|
|
|
m_bufferNameList.erase(m_bufferNameList.begin());
|
|
|
|
if (m_bufferNameList.size() == 0) {
|
2014-09-12 21:52:03 +02:00
|
|
|
destroy();
|
2013-11-17 20:37:06 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-15 21:37:39 +02:00
|
|
|
appl::WorkerCloseAllFile::~WorkerCloseAllFile() {
|
2014-09-12 21:52:03 +02:00
|
|
|
APPL_ERROR("Remove Worker");
|
2013-11-17 20:37:06 +01:00
|
|
|
}
|
|
|
|
|
2014-08-25 05:55:06 +02:00
|
|
|
void appl::WorkerCloseAllFile::onCallbackCloseDone() {
|
2014-06-05 22:01:24 +02:00
|
|
|
if (m_bufferManager == nullptr) {
|
2013-11-17 20:37:06 +01:00
|
|
|
// nothing to do in this case ==> can do nothing ...
|
|
|
|
return;
|
|
|
|
}
|
2014-08-25 05:55:06 +02:00
|
|
|
if (m_bufferNameList.size() == 0) {
|
2014-09-12 21:52:03 +02:00
|
|
|
destroy();
|
2014-08-25 05:55:06 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// create the worker :
|
2014-09-15 07:21:22 +02:00
|
|
|
m_worker = appl::WorkerCloseFile::create();
|
2016-02-19 23:33:00 +01:00
|
|
|
m_worker->signalCloseDone.connect(shared_from_this(), &appl::WorkerCloseAllFile::onCallbackCloseDone);
|
2014-09-15 07:21:22 +02:00
|
|
|
m_worker->startAction(m_bufferNameList.front());
|
2014-08-25 05:55:06 +02:00
|
|
|
// remove first element :
|
|
|
|
m_bufferNameList.erase(m_bufferNameList.begin());
|
|
|
|
if (m_bufferNameList.size() == 0) {
|
2014-09-12 21:52:03 +02:00
|
|
|
destroy();
|
2014-08-25 05:55:06 +02:00
|
|
|
return;
|
2013-11-17 20:37:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|