From 5ff9a72ca5e7326e3bb13e6c1d36eb2be2111bfb Mon Sep 17 00:00:00 2001
From: Keisuke Ogaki <keisuke_ogaki@dwango.co.jp>
Date: May 24 2016 07:26:30 +0000
Subject: get layer name encoding from preference


---

diff --git a/toonz/sources/image/CMakeLists.txt b/toonz/sources/image/CMakeLists.txt
index f36123e..2bac510 100644
--- a/toonz/sources/image/CMakeLists.txt
+++ b/toonz/sources/image/CMakeLists.txt
@@ -85,7 +85,7 @@ if(WIN32)
     endif()
 endif()
 
-_find_toonz_library(TNZLIBS "tnzcore;tnzbase")
+_find_toonz_library(TNZLIBS "tnzcore;tnzbase;toonzlib")
 
 if(WIN32)
     set(EXTRA_LIBS
diff --git a/toonz/sources/image/psd/tiio_psd.cpp b/toonz/sources/image/psd/tiio_psd.cpp
index 6d00c14..3521f8a 100644
--- a/toonz/sources/image/psd/tiio_psd.cpp
+++ b/toonz/sources/image/psd/tiio_psd.cpp
@@ -1,6 +1,7 @@
 #include "tiio_psd.h"
 #include "trasterimage.h"
 #include "timageinfo.h"
+#include "toonz/preferences.h"
 
 #include <QtCore>
 
@@ -39,7 +40,7 @@ TLevelReaderPsd::TLevelReaderPsd(const TFilePath &path)
 
 #ifdef REF_LAYER_BY_NAME
 		if (layerStr != "frames") {
-			QTextCodec* layerNameCodec = QTextCodec::codecForName( "SJIS" );
+			QTextCodec* layerNameCodec = QTextCodec::codecForName( Preferences::instance()->getLayerNameEncoding().c_str() );
 			TPSDParser psdparser(m_path);
 			m_layerId = psdparser.getLevelIdByName(layerNameCodec->fromUnicode(layerStr).toStdString());
 		} else
diff --git a/toonz/sources/include/toonz/preferences.h b/toonz/sources/include/toonz/preferences.h
index 7f02001..f1cbeba 100644
--- a/toonz/sources/include/toonz/preferences.h
+++ b/toonz/sources/include/toonz/preferences.h
@@ -428,6 +428,7 @@ public:
 	int getShmSeg() const { return m_shmseg; } //! \sa The \p sysctl unix command.
 	int getShmAll() const { return m_shmall; } //! \sa The \p sysctl unix command.
 	int getShmMni() const { return m_shmmni; } //! \sa The \p sysctl unix command.
+	std::string getLayerNameEncoding() const {return m_layerNameEncoding; };
 
 	Q_SIGNALS :
 
@@ -537,6 +538,7 @@ private:
 	int m_paletteTypeOnLoadRasterImageAsColorModel;
 
 	bool m_showKeyframesOnXsheetCellArea;
+	std::string m_layerNameEncoding = "SJIS"; // Fixed to SJIS for now. You can add interface if you wanna change encoding.
 
 private:
 	Preferences();
diff --git a/toonz/sources/toonzlib/txshsimplelevel.cpp b/toonz/sources/toonzlib/txshsimplelevel.cpp
index 548d442..3be22b3 100644
--- a/toonz/sources/toonzlib/txshsimplelevel.cpp
+++ b/toonz/sources/toonzlib/txshsimplelevel.cpp
@@ -1099,7 +1099,7 @@ TFilePath getLevelPathAndSetNameWithPsdLevelName(TXshSimpleLevel *xshLevel)
 	if (list.size() >= 2 && list.at(1) != "frames") {
 		bool hasLayerId;
 		int layid = list.at(1).toInt(&hasLayerId);
-		QTextCodec* layerNameCodec = QTextCodec::codecForName( "SJIS" );
+		QTextCodec* layerNameCodec = QTextCodec::codecForName( Preferences::instance()->getLayerNameEncoding().c_str() );
 
 		if (hasLayerId) {
 			// An explicit photoshop layer id must be converted to the associated level name