Add image widget and better system o the basic folder mecanism

This commit is contained in:
Edouard Dupin 2012-05-13 09:45:58 +02:00
parent d9e6126ff6
commit 4cba690678
11 changed files with 485 additions and 88 deletions

View File

@ -12,12 +12,17 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
ifeq ($(DEBUG),1)
LOCAL_CFLAGS := -D__PLATFORM__Android \
-Wno-write-strings \
-DDATA_IN_APK \
-DETK_DEBUG_LEVEL=3
-DETK_DEBUG_LEVEL=3 \
-Wall
else
LOCAL_CFLAGS := -D__PLATFORM__Android \
-Wno-write-strings \
-DETK_DEBUG_LEVEL=1 \
-DMODE_RELEASE
endif

View File

@ -14,17 +14,12 @@ ifeq ($(DEBUG),1)
LOCAL_CFLAGS := -D__PLATFORM__Linux \
-Wno-write-strings \
-DETK_DEBUG_LEVEL=3 \
-DEWOL_DEBUG_LEVEL=3 \
-DEWOL_VERSION_TAG_NAME="\"UNKNOW-debug\"" \
-DVERSION_BUILD_TIME="\"pasd_heure\"" \
-Wall
else
LOCAL_CFLAGS := -D__PLATFORM__Linux \
-Wno-write-strings \
-DETK_DEBUG_LEVEL=1 \
-DEWOL_DEBUG_LEVEL=1 \
-DEWOL_VERSION_TAG_NAME="\"UNKNOW-debug\"" \
-DVERSION_BUILD_TIME="\"pasd_heure\""
-DMODE_RELEASE
endif

View File

@ -27,16 +27,131 @@
#include <etk/DebugInternal.h>
#include <etk/File.h>
#include <unistd.h>
#include <stdlib.h>
#if defined(DATA_IN_APK)
#ifdef __PLATFORM__Android
# include <stdio.h>
# include <zip/zip.h>
#endif
// zip file of the apk file for Android ==> set to zip file apk access
static etk::UString s_fileAPK = "";
etk::UString baseApplName = "ewolNoName";
#ifdef __PLATFORM__Android
etk::UString baseFolderHome = "/sdcard/"; // home folder
etk::UString baseFolderData = "assets/"; // program Data
etk::UString baseFolderDataUser = "/sdcard/.tmp/userData/"; // Data specific user (local modification)
etk::UString baseFolderCache = "/sdcard/.tmp/cache/"; // Temporary data (can be removed the next time)
#else
etk::UString baseFolderHome = "~"; // home folder
etk::UString baseFolderData = "assets/"; // program Data
etk::UString baseFolderDataUser = "~/.tmp/userData/"; // Data specific user (local modification)
etk::UString baseFolderCache = "~/.tmp/cache/"; // Temporary data (can be removed the next time)
#endif
// for specific device contraint :
void etk::SetBaseFolderData(const char * folder)
{
#ifdef __PLATFORM__Android
baseFolderData = "assets/";
s_fileAPK = folder;
loadAPK(s_fileAPK);
#else
TK_ERROR("Not Availlable Outside Android");
#endif
}
void etk::SetBaseFolderDataUser(const char * folder)
{
#ifdef __PLATFORM__Android
baseFolderDataUser = folder;
#else
TK_ERROR("Not Availlable Outside Android");
#endif
}
void etk::SetBaseFolderCache(const char * folder)
{
#ifdef __PLATFORM__Android
baseFolderCache = folder;
#else
TK_ERROR("Not Availlable Outside Android");
#endif
}
void etk::InitDefaultFolder(const char * applName)
{
baseApplName = applName;
char * basicPath = getenv("HOME");
if (NULL == basicPath) {
TK_ERROR("ERROR while trying to get the path of the home folder");
baseFolderHome = "~";
} else {
baseFolderHome = basicPath;
}
#ifndef __PLATFORM__Android
#ifdef MODE_RELEASE
baseFolderData = "/usr/share/";
baseFolderData += baseApplName;
baseFolderData += "/";
#else
char cCurrentPath[FILENAME_MAX];
if (!getcwd(cCurrentPath, FILENAME_MAX)) {
baseFolderData = "./assets/";
} else {
cCurrentPath[FILENAME_MAX - 1] = '\0';
baseFolderData = cCurrentPath;
baseFolderData += "/assets/";
}
#endif
baseFolderDataUser = baseFolderHome;
baseFolderDataUser += "/.";
baseFolderDataUser += baseApplName;
baseFolderDataUser += "/";
baseFolderCache = "/tmp/";
baseFolderCache += baseApplName;
baseFolderCache += "/";
#endif
TK_INFO("baseFolderHome : \"" << baseFolderHome << "\"");
TK_INFO("baseFolderData : \"" << baseFolderData << "\"");
TK_INFO("baseFolderDataUser : \"" << baseFolderDataUser << "\"");
TK_INFO("baseFolderCache : \"" << baseFolderCache << "\"");
}
etk::UString etk::GetUserHomeFolder(void)
{
return baseFolderHome;
}
#ifdef __PLATFORM__Android
static struct zip * s_APKArchive = NULL;
static int32_t s_APKnbFiles = 0;
static void loadAPK(etk::UString& apkPath)
{
TK_DEBUG("Loading APK \"" << apkPath << "\"");
s_APKArchive = zip_open(apkPath.Utf8Data(), 0, NULL);
TK_ASSERT(s_APKArchive != NULL, "Error loading APK ... \"" << apkPath << "\"");
//Just for debug, print APK contents
s_APKnbFiles = zip_get_num_files(s_APKArchive);
TK_INFO("List all files in the APK : " << s_APKnbFiles << " files");
for (int iii=0; iii<s_APKnbFiles; iii++) {
const char* name = zip_get_name(s_APKArchive, iii, 0);
if (name == NULL) {
TK_ERROR("Error reading zip file name at index " << iii << " : \"" << zip_strerror(s_APKArchive) << "\"");
return;
}
TK_INFO(" File " << iii << " : \"" << name << "\"");
}
}
#endif
#undef __class__
#define __class__ "etk::File"
#define __class__ "File"
etk::CCout& etk::operator <<(etk::CCout &os, const etk::File &obj)
@ -116,7 +231,7 @@ const etk::File& etk::File::operator= (const etk::File &etkF )
TK_ERROR("Missing close the file : \"" << GetCompleateName() << "\"");
fClose();
}
#if defined(DATA_IN_APK)
#ifdef __PLATFORM__Android
m_idZipFile = etkF.m_idZipFile;
m_zipData = NULL;
m_zipDataSize = 0;
@ -163,61 +278,12 @@ bool etk::File::operator!= (const etk::File &etkF) const
}
etk::UString baseFolderData = "assets/";
#ifdef DATA_IN_APK
static etk::UString s_fileAPK = "";
static struct zip * s_APKArchive = NULL;
static int32_t s_APKnbFiles = 0;
static void loadAPK(etk::UString& apkPath)
{
TK_DEBUG("Loading APK \"" << apkPath << "\"");
s_APKArchive = zip_open(apkPath.Utf8Data(), 0, NULL);
TK_ASSERT(s_APKArchive != NULL, "Error loading APK ... \"" << apkPath << "\"");
//Just for debug, print APK contents
s_APKnbFiles = zip_get_num_files(s_APKArchive);
TK_INFO("List all files in the APK : " << s_APKnbFiles << " files");
for (int iii=0; iii<s_APKnbFiles; iii++) {
const char* name = zip_get_name(s_APKArchive, iii, 0);
if (name == NULL) {
TK_ERROR("Error reading zip file name at index " << iii << " : \"" << zip_strerror(s_APKArchive) << "\"");
return;
}
TK_INFO(" File " << iii << " : \"" << name << "\"");
}
}
#endif
etk::UString baseFolderDataUser = "~/.tmp/userData/";
etk::UString baseFolderCache = "~/.tmp/cache/";
// for specific device contraint :
void etk::SetBaseFolderData(const char * folder)
{
#if defined(DATA_IN_APK)
baseFolderData = "assets/";
s_fileAPK = folder;
loadAPK(s_fileAPK);
#else
baseFolderData = folder;
#endif
}
void etk::SetBaseFolderDataUser(const char * folder)
{
baseFolderDataUser = folder;
}
void etk::SetBaseFolderCache(const char * folder)
{
baseFolderCache = folder;
}
void etk::File::SetCompleateName(etk::UString &newFilename, etk::FileType_te type)
{
char buf[MAX_FILE_NAME];
memset(buf, 0, MAX_FILE_NAME);
char * ok;
#if defined(DATA_IN_APK)
#ifdef __PLATFORM__Android
m_idZipFile = -1;
m_zipData = NULL;
m_zipDataSize = 0;
@ -272,7 +338,7 @@ void etk::File::SetCompleateName(etk::UString &newFilename, etk::FileType_te typ
#if ETK_DEBUG_LEVEL > 3
mode = "FILE_TYPE_DATA";
#endif
#if defined(DATA_IN_APK)
#ifdef __PLATFORM__Android
etk::UString tmpFilename = baseFolderData + destFilename;
for (int iii=0; iii<s_APKnbFiles; iii++) {
const char* name = zip_get_name(s_APKArchive, iii, 0);
@ -416,7 +482,7 @@ etk::UString etk::File::GetExtention(void)
return tmpExt;
}
#ifdef DATA_IN_APK
#ifdef __PLATFORM__Android
bool etk::File::LoadDataZip(void)
{
if (NULL != m_zipData) {
@ -466,7 +532,7 @@ bool etk::File::LoadDataZip(void)
int32_t etk::File::Size(void)
{
#if defined(DATA_IN_APK)
#ifdef __PLATFORM__Android
if (etk::FILE_TYPE_DATA == m_type) {
if (true == LoadDataZip()) {
return m_zipDataSize;
@ -508,7 +574,7 @@ int32_t etk::File::Size(void)
bool etk::File::Exist(void)
{
#if defined(DATA_IN_APK)
#ifdef __PLATFORM__Android
if (etk::FILE_TYPE_DATA == m_type) {
if (m_idZipFile >= -1 && m_idZipFile < s_APKnbFiles) {
return true;
@ -547,7 +613,7 @@ bool etk::File::Exist(void)
bool etk::File::fOpenRead(void)
{
#if defined(DATA_IN_APK)
#ifdef __PLATFORM__Android
if (etk::FILE_TYPE_DATA == m_type) {
return LoadDataZip();
}
@ -583,7 +649,7 @@ bool etk::File::fOpenRead(void)
bool etk::File::fOpenWrite(void)
{
#if defined(DATA_IN_APK)
#ifdef __PLATFORM__Android
if (etk::FILE_TYPE_DATA == m_type) {
return false;
}
@ -619,7 +685,7 @@ bool etk::File::fOpenWrite(void)
bool etk::File::fClose(void)
{
#if defined(DATA_IN_APK)
#ifdef __PLATFORM__Android
if (etk::FILE_TYPE_DATA == m_type) {
if (NULL == m_zipData) {
TK_CRITICAL("File Already closed : \"" << GetCompleateName() << "\"");
@ -644,7 +710,7 @@ bool etk::File::fClose(void)
char * etk::File::fGets(char * elementLine, int32_t maxData)
{
memset(elementLine, 0, maxData);
#if defined(DATA_IN_APK)
#ifdef __PLATFORM__Android
char * element = elementLine;
if (etk::FILE_TYPE_DATA == m_type) {//char * tmpData = internalDataFiles[iii].data + m_readingOffset;
if (NULL == m_zipData) {
@ -681,7 +747,7 @@ char * etk::File::fGets(char * elementLine, int32_t maxData)
int32_t etk::File::fRead(void * data, int32_t blockSize, int32_t nbBlock)
{
#if defined(DATA_IN_APK)
#ifdef __PLATFORM__Android
if (etk::FILE_TYPE_DATA == m_type) {
if (NULL == m_zipData) {
((char*)data)[0] = '\0';
@ -702,7 +768,7 @@ int32_t etk::File::fRead(void * data, int32_t blockSize, int32_t nbBlock)
int32_t etk::File::fWrite(void * data, int32_t blockSize, int32_t nbBlock)
{
#if defined(DATA_IN_APK)
#ifdef __PLATFORM__Android
if (etk::FILE_TYPE_DATA == m_type) {
TK_CRITICAL("Can not write on data inside APK : \"" << GetCompleateName() << "\"");
return 0;
@ -714,7 +780,7 @@ int32_t etk::File::fWrite(void * data, int32_t blockSize, int32_t nbBlock)
bool etk::File::fSeek(long int offset, int origin)
{
#if defined(DATA_IN_APK)
#ifdef __PLATFORM__Android
if (etk::FILE_TYPE_DATA == m_type) {
if (NULL == m_zipData) {
return false;
@ -752,7 +818,7 @@ bool etk::File::fSeek(long int offset, int origin)
char * etk::File::GetDirectPointer(void)
{
#if defined(DATA_IN_APK)
#ifdef __PLATFORM__Android
if (etk::FILE_TYPE_DATA == m_type) {
if (NULL == m_zipData) {
return NULL;

View File

@ -94,7 +94,7 @@ namespace etk
private :
etk::FileType_te m_type;
FILE * m_PointerFile;
#if defined(DATA_IN_APK)
#ifdef __PLATFORM__Android
bool LoadDataZip(void);
int32_t m_idZipFile;
char * m_zipData;
@ -111,6 +111,8 @@ namespace etk
void SetBaseFolderData(const char * folder);
void SetBaseFolderDataUser(const char * folder);
void SetBaseFolderCache(const char * folder);
void InitDefaultFolder(const char * applName);
etk::UString GetUserHomeFolder(void);
}

View File

@ -2119,4 +2119,7 @@ template<class CLASS_TYPE> class RegExp {
}; // end of etk namespace
#undef __class__
#define __class__ (NULL)
#endif

View File

@ -24,6 +24,7 @@
#include <etk/Types.h>
#include <etk/File.h>
#include <ewol/ewol.h>
#include <ewol/Debug.h>
#include <ewol/threadMsg.h>
@ -91,6 +92,7 @@ static void* BaseAppEntry(void* param)
EWOL_INFO("v" EWOL_VERSION_TAG_NAME);
EWOL_INFO("Build Date: " VERSION_BUILD_TIME);
etk::InitDefaultFolder("ewolApplNoName");
/*
struct sched_param pr;

View File

@ -101,6 +101,7 @@ void ewol::Button::SetImage(etk::UString imageName)
m_imageSelected = imageName;
m_hasAnImage = true;
}
MarkToReedraw();
}
//!< EObject name :
@ -168,6 +169,7 @@ bool ewol::Button::CalculateMinSize(void)
void ewol::Button::SetLabel(etk::UString newLabel)
{
m_label = newLabel;
MarkToReedraw();
}
void ewol::Button::SetValue(bool val)

View File

@ -0,0 +1,206 @@
/**
*******************************************************************************
* @file ewol/widget/Image.cpp
* @brief ewol Image widget system (Sources)
* @author Edouard DUPIN
* @date 12/05/2012
* @par Project
* ewol
*
* @par Copyright
* Copyright 2011 Edouard DUPIN, all right reserved
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY.
*
* Licence summary :
* You can modify and redistribute the sources code and binaries.
* You can send me the bug-fix
*
* Term of the licence in in the file licence.txt.
*
*******************************************************************************
*/
#include <ewol/widget/Image.h>
#include <ewol/OObject.h>
#include <ewol/WidgetManager.h>
extern const char * const ewolEventImagePressed = "ewol-image-Pressed";
/**
* @brief Initilise the basic widget property ==> due to the android system
* @note all widget that have template might have this initializer ...
* @param ---
* @return ---
*/
void ewol::WIDGET_ImageInit(void)
{
}
#undef __class__
#define __class__ "Image"
void ewol::Image::Init(void)
{
AddEventId(ewolEventImagePressed);
#ifdef __PLATFORM__Android
m_padding.y = 12;
m_padding.x = 12;
#else
m_padding.y = 4;
m_padding.x = 4;
#endif
m_textColorBg = etk::color::color_Black;
m_textColorBg.alpha = 0x00;
m_imageSize = 32;
}
ewol::Image::Image(etk::UString dataFile, int32_t size)
{
m_imageSelected = dataFile;
Init();
if (size>0) {
m_imageSize = size;
}
}
ewol::Image::~Image(void)
{
}
//!< EObject name :
extern const char * const ewol::TYPE_EOBJECT_WIDGET_IMAGE = "Image";
/**
* @brief Check if the object has the specific type.
* @note In Embended platforme, it is many time no -rtti flag, then it is not possible to use dynamic cast ==> this will replace it
* @param[in] objectType type of the object we want to check
* @return true if the object is compatible, otherwise false
*/
bool ewol::Image::CheckObjectType(const char * const objectType)
{
if (NULL == objectType) {
EWOL_ERROR("check error : \"" << ewol::TYPE_EOBJECT_WIDGET_IMAGE << "\" != NULL(pointer) ");
return false;
}
if (objectType == ewol::TYPE_EOBJECT_WIDGET_IMAGE) {
return true;
} else {
if(true == ewol::Drawable::CheckObjectType(objectType)) {
return true;
}
EWOL_ERROR("check error : \"" << ewol::TYPE_EOBJECT_WIDGET_IMAGE << "\" != \"" << objectType << "\"");
return false;
}
}
/**
* @brief Get the current Object type of the EObject
* @note In Embended platforme, it is many time no -rtti flag, then it is not possible to use dynamic cast ==> this will replace it
* @param[in] objectType type description
* @return true if the object is compatible, otherwise false
*/
const char * const ewol::Image::GetObjectType(void)
{
return ewol::TYPE_EOBJECT_WIDGET_IMAGE;
}
void ewol::Image::SetPadding(coord2D_ts newPadding)
{
m_padding = newPadding;
}
bool ewol::Image::CalculateMinSize(void)
{
m_minSize.x = m_padding.x*2 + m_imageSize;
m_minSize.y = m_padding.y*2 + m_imageSize;
MarkToReedraw();
return true;
}
void ewol::Image::SetFile(etk::UString newFile)
{
m_imageSelected = newFile;
MarkToReedraw();
}
void ewol::Image::OnRegenerateDisplay(void)
{
if (true == NeedRedraw()) {
// clean the object list ...
ClearOObjectList();
int32_t tmpSizeX = m_minSize.x;
int32_t tmpSizeY = m_minSize.y;
int32_t tmpOriginX = (m_size.x - m_minSize.x) / 2;
int32_t tmpOriginY = (m_size.y - m_minSize.y) / 2;
if (true==m_userFillX) {
tmpSizeX = m_size.x;
tmpOriginX = 0;
}
if (true==m_userFillY) {
tmpSizeY = m_size.y;
tmpOriginY = 0;
}
tmpOriginX += m_padding.x;
tmpOriginY += m_padding.y;
tmpSizeX -= 2*m_padding.x;
tmpSizeY -= 2*m_padding.y;
ewol::OObject2DTextured * tmpImage = NULL;
tmpImage = new ewol::OObject2DTextured(m_imageSelected, m_imageSize, m_imageSize);
tmpImage->Rectangle(tmpOriginX, tmpOriginY, m_imageSize, m_imageSize);
ewol::OObject2DColored * tmpOObjects = new ewol::OObject2DColored;
tmpOObjects->SetColor(m_textColorBg);
tmpOObjects->Rectangle( tmpOriginX, tmpOriginY, tmpSizeX, tmpSizeY);
// add all needed objects ...
if (NULL != tmpOObjects) {
AddOObject(tmpOObjects);
}
if (NULL != tmpImage) {
AddOObject(tmpImage);
}
}
}
/**
* @brief Event on an input of this Widget
* @param[in] IdInput Id of the current Input (PC : left=1, right=2, middle=3, none=0 / Tactil : first finger=1 , second=2 (only on this widget, no knowledge at ouside finger))
* @param[in] typeEvent ewol type of event like EVENT_INPUT_TYPE_DOWN/EVENT_INPUT_TYPE_MOVE/EVENT_INPUT_TYPE_UP/EVENT_INPUT_TYPE_SINGLE/EVENT_INPUT_TYPE_DOUBLE/...
* @param[in] pos Absolute position of the event
* @return true the event is used
* @return false the event is not used
*/
bool ewol::Image::OnEventInput(int32_t IdInput, eventInputType_te typeEvent, coord2D_ts pos)
{
//EWOL_DEBUG("Event on BT ...");
if (1 == IdInput) {
if( ewol::EVENT_INPUT_TYPE_SINGLE == typeEvent
|| ewol::EVENT_INPUT_TYPE_DOUBLE == typeEvent
|| ewol::EVENT_INPUT_TYPE_TRIPLE == typeEvent) {
GenerateEventId(ewolEventImagePressed);
return true;
}
}
return false;
}

View File

@ -0,0 +1,91 @@
/**
*******************************************************************************
* @file ewol/widget/Image.h
* @brief ewol Image widget system (header)
* @author Edouard DUPIN
* @date 12/05/2012
* @par Project
* ewol
*
* @par Copyright
* Copyright 2011 Edouard DUPIN, all right reserved
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY.
*
* Licence summary :
* You can modify and redistribute the sources code and binaries.
* You can send me the bug-fix
*
* Term of the licence in in the file licence.txt.
*
*******************************************************************************
*/
#ifndef __EWOL_IMAGE_H__
#define __EWOL_IMAGE_H__
#include <etk/Types.h>
#include <ewol/Debug.h>
#include <ewol/widget/Drawable.h>
extern const char * const ewolEventImagePressed;
namespace ewol {
class Image :public ewol::Drawable
{
public:
Image(etk::UString dataFile, int32_t size=-1); // automatic considering in the appl Data older
/**
* @brief Check if the object has the specific type.
* @note In Embended platforme, it is many time no -rtti flag, then it is not possible to use dynamic cast ==> this will replace it
* @param[in] objectType type of the object we want to check
* @return true if the object is compatible, otherwise false
*/
virtual bool CheckObjectType(const char * const objectType);
/**
* @brief Get the current Object type of the EObject
* @note In Embended platforme, it is many time no -rtti flag, then it is not possible to use dynamic cast ==> this will replace it
* @param[in] objectType type description
* @return true if the object is compatible, otherwise false
*/
virtual const char * const GetObjectType(void);
void Init(void);
virtual ~Image(void);
virtual bool CalculateMinSize(void);
void SetFile(etk::UString newFile);
void SetPadding(coord2D_ts newPadding);
private:
etk::UString m_imageSelected;
coord2D_ts m_padding;
color_ts m_textColorBg; //!< Background color
int32_t m_imageSize;
public:
virtual void OnRegenerateDisplay(void);
public:
/**
* @brief Event on an input of this Widget
* @param[in] IdInput Id of the current Input (PC : left=1, right=2, middle=3, none=0 / Tactil : first finger=1 , second=2 (only on this widget, no knowledge at ouside finger))
* @param[in] typeEvent ewol type of event like EVENT_INPUT_TYPE_DOWN/EVENT_INPUT_TYPE_MOVE/EVENT_INPUT_TYPE_UP/EVENT_INPUT_TYPE_SINGLE/EVENT_INPUT_TYPE_DOUBLE/...
* @param[in] pos Absolute position of the event
* @return true the event is used
* @return false the event is not used
*/
virtual bool OnEventInput(int32_t IdInput, eventInputType_te typeEvent, coord2D_ts pos);
};
/**
* @brief Initilise the basic widget property ==> due to the android system
* @note all widget that have template might have this initializer ...
* @param ---
* @return ---
*/
void WIDGET_ImageInit(void);
extern const char * const TYPE_EOBJECT_WIDGET_IMAGE;
};
#define EWOL_CAST_WIDGET_IMAGE(curentPointer) EWOL_CAST(ewol::TYPE_EOBJECT_WIDGET_IMAGE,ewol::Image,curentPointer)
#endif

View File

@ -27,6 +27,7 @@
#include <ewol/widget/SizerVert.h>
#include <ewol/widget/List.h>
#include <ewol/widget/Spacer.h>
#include <ewol/widget/Image.h>
#include <ewol/WidgetManager.h>
//#include <etk/Vector.h>
#include <etk/VectorType.h>
@ -406,6 +407,7 @@ extern const char * const ewolEventFileChooserValidate = "ewol-event-file
extern const char * const ewolEventFileChooserHidenFileChange = "ewol-event-file-chooser-Show/Hide-hiden-Files";
extern const char * const ewolEventFileChooserEntryFolder = "ewol-event-file-chooser-modify-entry-folder";
extern const char * const ewolEventFileChooserEntryFile = "ewol-event-file-chooser-modify-entry-file";
extern const char * const ewolEventFileChooserHome = "ewol-event-file-chooser-home";
ewol::FileChooser::FileChooser(void)
@ -430,6 +432,7 @@ ewol::FileChooser::FileChooser(void)
FileChooserFileList * myListFile = NULL;
FileChooserFolderList * myListFolder = NULL;
ewol::Label * myLabel = NULL;
ewol::Image * myImage = NULL;
#ifdef __PLATFORM__Android
m_folder = "/mnt/sdcard/";
SetDisplayRatio(0.90);
@ -449,21 +452,26 @@ ewol::FileChooser::FileChooser(void)
mySizerHori = new ewol::SizerHori();
mySizerVert->SubWidgetAdd(mySizerHori);
myLabel = new ewol::Label("Folder : ");
myLabel->SetFillY(true);
mySizerHori->SubWidgetAdd(myLabel);
myImage = new ewol::Image("icon/Folder.svg");
myImage->SetFillY(true);
mySizerHori->SubWidgetAdd(myImage);
m_widgetCurrentFolder = new ewol::Entry(m_folder);
m_widgetCurrentFolder->RegisterOnEvent(this, ewolEventEntryModify, ewolEventFileChooserEntryFolder);
m_widgetCurrentFolder->SetExpendX(true);
m_widgetCurrentFolder->SetFillX(true);
m_widgetCurrentFolder->SetWidth(200);
mySizerHori->SubWidgetAdd(m_widgetCurrentFolder);
myImage = new ewol::Image("icon/Home.svg");
myImage->RegisterOnEvent(this, ewolEventImagePressed, ewolEventFileChooserHome);
myImage->SetFillY(true);
mySizerHori->SubWidgetAdd(myImage);
mySizerHori = new ewol::SizerHori();
mySizerVert->SubWidgetAdd(mySizerHori);
myLabel = new ewol::Label("File Name : ");
myLabel->SetFillY(true);
mySizerHori->SubWidgetAdd(myLabel);
myImage = new ewol::Image("icon/File.svg");
myImage->SetFillY(true);
mySizerHori->SubWidgetAdd(myImage);
m_widgetCurrentFileName = new ewol::Entry(m_file);
m_widgetCurrentFileName->RegisterOnEvent(this, ewolEventEntryModify, ewolEventFileChooserEntryFile);
m_widgetCurrentFileName->SetExpendX(true);
@ -508,9 +516,11 @@ ewol::FileChooser::FileChooser(void)
mySpacer->SetExpendX(true);
mySizerHori->SubWidgetAdd(mySpacer);
m_widgetValidate = new ewol::Button("Validate");
m_widgetValidate->SetImage("icon/Load.svg");
m_widgetValidate->RegisterOnEvent(this, ewolEventButtonPressed, ewolEventFileChooserValidate);
mySizerHori->SubWidgetAdd(m_widgetValidate);
m_widgetCancel = new ewol::Button("Cancel");
m_widgetCancel->SetImage("icon/Remove.svg");
m_widgetCancel->RegisterOnEvent(this, ewolEventButtonPressed, ewolEventFileChooserCancel);
mySizerHori->SubWidgetAdd(m_widgetCancel);
@ -617,23 +627,19 @@ void ewol::FileChooser::OnReceiveMessage(ewol::EObject * CallerObject, const cha
if (ewolEventFileChooserEntryFolder == eventId) {
//==> change the folder name
// TODO : Change the folder, if it exit ...
return;
} else if (ewolEventFileChooserEntryFile == eventId) {
//==> change the file name
if (NULL != m_widgetCurrentFileName) {
m_file = m_widgetCurrentFileName->GetValue();
}
// TODO : Remove file selection
return;
} else if (ewolEventFileChooserCancel == eventId) {
//==> Auto remove ...
GenerateEventId(eventId);
MarkToRemove();
return;
} else if (ewolEventFileChooserHidenFileChange == eventId) {
// regenerate the display ...
UpdateCurrentFolder();
return;
} else if (ewolEventFileChooserSelectFolder == eventId) {
//==> this is an internal event ...
FileChooserFolderList * myListFolder = EWOL_CAST_WIDGET_FOLDER_LIST(m_widgetListFolder);
@ -658,7 +664,6 @@ void ewol::FileChooser::OnReceiveMessage(ewol::EObject * CallerObject, const cha
SetFileName("");
UpdateCurrentFolder();
m_hasSelectedFile = false;
return;
} else if (ewolEventFileChooserSelectFile == eventId) {
m_hasSelectedFile = true;
FileChooserFileList * myListFile = EWOL_CAST_WIDGET_FILE_LIST(m_widgetListFile);
@ -670,7 +675,26 @@ void ewol::FileChooser::OnReceiveMessage(ewol::EObject * CallerObject, const cha
// select the File ==> generate a validate
GenerateEventId(ewolEventFileChooserValidate);
MarkToRemove();
return;
} else if(ewolEventFileChooserHome == eventId) {
etk::UString tmpUserFolder = etk::GetUserHomeFolder();
char buf[MAX_FILE_NAME];
memset(buf, 0, MAX_FILE_NAME);
char * ok;
EWOL_DEBUG("new PATH : \"" << tmpUserFolder << "\"");
ok = realpath(tmpUserFolder.Utf8Data(), buf);
if (!ok) {
EWOL_ERROR("Error to get the real path");
m_folder = "/";
} else {
m_folder = buf;
}
if (m_folder != "/" ) {
m_folder += "/";
}
SetFileName("");
UpdateCurrentFolder();
m_hasSelectedFile = false;
}
return;
};

View File

@ -28,6 +28,7 @@ FILE_LIST = ewol/ewol.cpp \
ewol/Windows.cpp \
ewol/ShortCutManager.cpp \
ewol/widget/Button.cpp \
ewol/widget/Image.cpp \
ewol/widget/ButtonColor.cpp \
ewol/widget/CheckBox.cpp \
ewol/widget/ColorBar.cpp \