2016-05-02 22:01:55 +02:00
|
|
|
/** @file
|
2013-11-15 23:42:00 +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-15 23:42:00 +01:00
|
|
|
#include <appl/debug.h>
|
|
|
|
#include <appl/Gui/WorkerSaveFile.h>
|
2016-03-16 23:09:36 +01:00
|
|
|
#include <ewol/tools/message.h>
|
2013-11-15 23:42:00 +01:00
|
|
|
|
2014-08-20 22:34:31 +02:00
|
|
|
appl::WorkerSaveFile::WorkerSaveFile() :
|
2016-03-02 21:51:44 +01:00
|
|
|
signalSaveDone(this, "save-file-done", ""),
|
2016-03-10 22:37:37 +01:00
|
|
|
signalAbort(this, "save-file-abort", ""),
|
|
|
|
propertyBufferName(this, "buffer-name", "", ""),
|
|
|
|
propertyForceSave(this, "force-save", false, "request save in all case") {
|
2013-11-20 21:57:00 +01:00
|
|
|
addObjectType("appl::WorkerSaveFile");
|
2013-11-15 23:42:00 +01:00
|
|
|
// load buffer manager:
|
2014-08-07 23:41:48 +02:00
|
|
|
m_bufferManager = appl::BufferManager::create();
|
|
|
|
}
|
|
|
|
|
2016-03-10 22:37:37 +01:00
|
|
|
void appl::WorkerSaveFile::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-15 23:42:00 +01:00
|
|
|
APPL_ERROR("can not call unexistant buffer manager ... ");
|
2014-09-12 21:52:03 +02:00
|
|
|
destroy();
|
2013-11-15 23:42:00 +01:00
|
|
|
return;
|
|
|
|
}
|
2016-03-10 22:37:37 +01:00
|
|
|
if (*propertyBufferName == "") {
|
2013-11-17 20:37:06 +01:00
|
|
|
// need to find the curent file ...
|
2016-07-19 22:03:39 +02:00
|
|
|
ememory::SharedPtr<appl::Buffer> tmpp = m_bufferManager->getBufferSelected();
|
2014-06-05 22:01:24 +02:00
|
|
|
if (tmpp == nullptr) {
|
2013-11-17 20:37:06 +01:00
|
|
|
APPL_ERROR("No selected buffer now ...");
|
2014-09-12 21:52:03 +02:00
|
|
|
destroy();
|
2013-11-17 20:37:06 +01:00
|
|
|
return;
|
|
|
|
}
|
2016-03-10 22:37:37 +01:00
|
|
|
propertyBufferName.setDirect(tmpp->getFileName());
|
2013-11-17 20:37:06 +01:00
|
|
|
}
|
2016-03-10 22:37:37 +01:00
|
|
|
if (m_bufferManager->exist(*propertyBufferName) == false) {
|
|
|
|
APPL_ERROR("Try to save an non-existant file :" << *propertyBufferName);
|
2014-09-12 21:52:03 +02:00
|
|
|
destroy();
|
2013-11-15 23:42:00 +01:00
|
|
|
return;
|
|
|
|
}
|
2016-07-19 22:03:39 +02:00
|
|
|
ememory::SharedPtr<appl::Buffer> tmpBuffer = m_bufferManager->get(*propertyBufferName);
|
2014-06-05 22:01:24 +02:00
|
|
|
if (tmpBuffer == nullptr) {
|
2016-03-10 22:37:37 +01:00
|
|
|
APPL_ERROR("Error to get the buffer : " << *propertyBufferName);
|
2014-09-12 21:52:03 +02:00
|
|
|
destroy();
|
2013-11-15 23:42:00 +01:00
|
|
|
return;
|
|
|
|
}
|
2016-03-10 22:37:37 +01:00
|
|
|
if (*propertyForceSave == false) {
|
2013-11-17 20:37:06 +01:00
|
|
|
if (tmpBuffer->hasFileName() == true) {
|
|
|
|
tmpBuffer->storeFile();
|
2014-08-22 05:21:10 +02:00
|
|
|
signalSaveDone.emit();
|
2014-09-12 21:52:03 +02:00
|
|
|
destroy();
|
2013-11-17 20:37:06 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-08-07 23:41:48 +02:00
|
|
|
m_chooser = ewol::widget::FileChooser::create();
|
2016-07-19 22:03:39 +02:00
|
|
|
if (m_chooser == nullptr) {
|
2013-11-15 23:42:00 +01:00
|
|
|
APPL_ERROR("Can not allocate widget == > display might be in error");
|
2014-09-12 21:52:03 +02:00
|
|
|
destroy();
|
2013-11-15 23:42:00 +01:00
|
|
|
return;
|
|
|
|
}
|
2016-03-15 22:33:06 +01:00
|
|
|
m_chooser->propertyLabelTitle.set("_T{Save files As...}");
|
|
|
|
m_chooser->propertyLabelValidate.set("_T{Save}");
|
2016-03-10 22:37:37 +01:00
|
|
|
etk::FSNode tmpName(*propertyBufferName);
|
2016-02-15 22:04:10 +01:00
|
|
|
m_chooser->propertyPath.set(tmpName.getNameFolder());
|
|
|
|
m_chooser->propertyFile.set(tmpName.getNameFile());
|
2016-07-19 22:03:39 +02:00
|
|
|
ememory::SharedPtr<ewol::widget::Windows> tmpWindows = ewol::getContext().getWindows();
|
2014-06-05 22:01:24 +02:00
|
|
|
if (tmpWindows == nullptr) {
|
2013-11-15 23:42:00 +01:00
|
|
|
APPL_ERROR("Error to get the windows.");
|
2014-09-12 21:52:03 +02:00
|
|
|
destroy();
|
2013-11-15 23:42:00 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
tmpWindows->popUpWidgetPush(m_chooser);
|
2016-07-19 22:03:39 +02:00
|
|
|
m_chooser->signalValidate.connect(sharedFromThis(), &appl::WorkerSaveFile::onCallbackSaveAsValidate);
|
|
|
|
m_chooser->signalCancel.connect(sharedFromThis(), &appl::WorkerSaveFile::onCallbackCancel);
|
2013-11-15 23:42:00 +01:00
|
|
|
}
|
|
|
|
|
2014-05-15 21:37:39 +02:00
|
|
|
appl::WorkerSaveFile::~WorkerSaveFile() {
|
2014-09-12 21:52:03 +02:00
|
|
|
APPL_ERROR("Remove Worker");
|
|
|
|
}
|
|
|
|
|
|
|
|
void appl::WorkerSaveFile::onCallbackCancel() {
|
|
|
|
signalAbort.emit();
|
|
|
|
destroy();
|
2013-11-15 23:42:00 +01:00
|
|
|
}
|
|
|
|
|
2014-08-25 05:55:06 +02:00
|
|
|
void appl::WorkerSaveFile::onCallbackSaveAsValidate(const std::string& _value) {
|
2014-06-05 22:01:24 +02:00
|
|
|
if (m_bufferManager == nullptr) {
|
2013-11-15 23:42:00 +01:00
|
|
|
// nothing to do in this case ==> can do nothing ...
|
2014-09-12 21:52:03 +02:00
|
|
|
destroy();
|
2013-11-15 23:42:00 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-08-25 05:55:06 +02:00
|
|
|
if (_value == "") {
|
|
|
|
APPL_ERROR(" might be an error of the File chooser system...");
|
2014-09-12 21:52:03 +02:00
|
|
|
destroy();
|
2014-08-25 05:55:06 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-03-10 22:37:37 +01:00
|
|
|
if (m_bufferManager->exist(*propertyBufferName) == false) {
|
|
|
|
APPL_ERROR("Try to save an non-existant file :" << *propertyBufferName);
|
2014-09-12 21:52:03 +02:00
|
|
|
destroy();
|
2014-08-25 05:55:06 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-07-19 22:03:39 +02:00
|
|
|
ememory::SharedPtr<appl::Buffer> tmpBuffer = m_bufferManager->get(*propertyBufferName);
|
2014-08-25 05:55:06 +02:00
|
|
|
if (tmpBuffer == nullptr) {
|
2016-03-10 22:37:37 +01:00
|
|
|
APPL_ERROR("Error to get the buffer : " << *propertyBufferName);
|
2014-09-12 21:52:03 +02:00
|
|
|
destroy();
|
2014-08-25 05:55:06 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
tmpBuffer->setFileName(_value);
|
|
|
|
if (tmpBuffer->storeFile() == false) {
|
2016-03-16 23:09:36 +01:00
|
|
|
ewol::tools::message::displayWarning("We can not save the file : <br/><i>" + tmpBuffer->getFileName() + "</i>");
|
2014-08-25 05:55:06 +02:00
|
|
|
} else {
|
|
|
|
signalSaveDone.emit();
|
2013-11-15 23:42:00 +01:00
|
|
|
}
|
2014-09-12 21:52:03 +02:00
|
|
|
destroy();
|
2013-11-15 23:42:00 +01:00
|
|
|
}
|
|
|
|
|