Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/toonzfolders.h"
Toshihiro Shimizu 890ddd
#include "tsystem.h"
Toshihiro Shimizu 890ddd
#include "tenv.h"
Toshihiro Shimizu 890ddd
//#include "appmainshell.h"
Toshihiro Shimizu 890ddd
#include "tconvert.h"
turtletooth 8d9ba3
#include "toonz/preferences.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace TEnv;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath ToonzFolder::getModulesDir() {
Shinya Kitaoka 120a6e
  return getProfileFolder() + "layouts";
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePathSet ToonzFolder::getProjectsFolders() {
Shinya Kitaoka 120a6e
  TFilePathSet fps =
Shinya Kitaoka 120a6e
      getSystemVarPathSetValue(getSystemVarPrefix() + "PROJECTS");
Shinya Kitaoka 120a6e
  if (fps.empty()) fps.push_back(TEnv::getStuffDir() + "Projects");
Shinya Kitaoka 120a6e
  return fps;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath ToonzFolder::getFirstProjectsFolder() {
Shinya Kitaoka 120a6e
  TFilePathSet fps = getProjectsFolders();
Shinya Kitaoka 120a6e
  if (fps.empty())
Shinya Kitaoka 120a6e
    return TFilePath();
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    return *fps.begin();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath ToonzFolder::getLibraryFolder() {
Shinya Kitaoka 120a6e
  TFilePath fp = getSystemVarPathValue(getSystemVarPrefix() + "LIBRARY");
Shinya Kitaoka 120a6e
  if (fp == TFilePath()) fp = getStuffDir() + "library";
Shinya Kitaoka 120a6e
  return fp;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath ToonzFolder::getStudioPaletteFolder() {
Shinya Kitaoka 120a6e
  TFilePath fp = getSystemVarPathValue(getSystemVarPrefix() + "STUDIOPALETTE");
Shinya Kitaoka 120a6e
  if (fp == TFilePath()) fp = getStuffDir() + "studiopalette";
Shinya Kitaoka 120a6e
  return fp;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath ToonzFolder::getFxPresetFolder() {
Shinya Kitaoka 120a6e
  TFilePath fp = getSystemVarPathValue(getSystemVarPrefix() + "FXPRESETS");
Shinya Kitaoka 120a6e
  if (fp == TFilePath()) fp = getStuffDir() + "fxs";
Shinya Kitaoka 120a6e
  return fp;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath ToonzFolder::getCacheRootFolder() {
Shinya Kitaoka 120a6e
  TFilePath fp = getSystemVarPathValue(getSystemVarPrefix() + "CACHEROOT");
Shinya Kitaoka 120a6e
  if (fp == TFilePath()) fp = getStuffDir() + "cache";
Shinya Kitaoka 120a6e
  return fp;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath ToonzFolder::getProfileFolder() {
Shinya Kitaoka 120a6e
  TFilePath fp = getSystemVarPathValue(getSystemVarPrefix() + "PROFILES");
Shinya Kitaoka 120a6e
  if (fp == TFilePath()) fp = getStuffDir() + "profiles";
Shinya Kitaoka 120a6e
  return fp;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath ToonzFolder::getReslistPath(bool forCleanup) {
Shinya Kitaoka 120a6e
  return getFirstProjectsFolder() +
Shinya Kitaoka 120a6e
         (forCleanup ? "cleanupreslist.txt" : "reslist.txt");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath ToonzFolder::getTemplateModuleDir() {
Shinya Kitaoka 120a6e
  // return getModulesDir() + getModuleName();
Shinya Kitaoka 120a6e
  return getModulesDir() + "settings";
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath ToonzFolder::getMyModuleDir() {
Shinya Kitaoka 120a6e
  TFilePath fp(getTemplateModuleDir());
Shinya Kitaoka 120a6e
  return fp.withName(fp.getWideName() + L"." +
Shinya Kitaoka 120a6e
                     TSystem::getUserName().toStdWString());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath ToonzFolder::getModuleFile(TFilePath filename) {
Shinya Kitaoka 120a6e
  TFilePath fp = getMyModuleDir() + filename;
Shinya Kitaoka 120a6e
  if (TFileStatus(fp).doesExist()) return fp;
Shinya Kitaoka 120a6e
  fp = getTemplateModuleDir() + filename;
Shinya Kitaoka 120a6e
  return fp;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath ToonzFolder::getModuleFile(std::string fn) {
Shinya Kitaoka 120a6e
  return ToonzFolder::getModuleFile(TFilePath(fn));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
// turtle
Shinya Kitaoka 120a6e
TFilePath ToonzFolder::getRoomsDir() {
Shinya Kitaoka 120a6e
  return getProfileFolder() + "layouts/rooms";
turtletooth 8d9ba3
}
turtletooth 8d9ba3
Shinya Kitaoka 120a6e
TFilePath ToonzFolder::getTemplateRoomsDir() {
Shinya Kitaoka 120a6e
  return getRoomsDir() +
Shinya Kitaoka 120a6e
         Preferences::instance()->getCurrentRoomChoice().toStdWString();
Shinya Kitaoka 120a6e
  // TFilePath fp(getMyModuleDir() + TFilePath(mySettingsFileName));
Shinya Kitaoka 120a6e
  // return getRoomsDir() + getModuleName();
turtletooth 8d9ba3
}
turtletooth 8d9ba3
Shinya Kitaoka 120a6e
TFilePath ToonzFolder::getMyRoomsDir() {
Shinya Kitaoka 120a6e
  // TFilePath fp(getTemplateRoomsDir());
Shinya Kitaoka 120a6e
  TFilePath fp(getProfileFolder());
Shinya Kitaoka 120a6e
  return fp.withName(
Shinya Kitaoka 120a6e
      fp.getWideName() + L"/layouts/personal/" +
Shinya Kitaoka 120a6e
      Preferences::instance()->getCurrentRoomChoice().toStdWString() + L"." +
Shinya Kitaoka 120a6e
      TSystem::getUserName().toStdWString());
turtletooth 8d9ba3
}
turtletooth 8d9ba3
Shinya Kitaoka 120a6e
TFilePath ToonzFolder::getRoomsFile(TFilePath filename) {
Shinya Kitaoka 120a6e
  TFilePath fp = getMyRoomsDir() + filename;
Shinya Kitaoka 120a6e
  if (TFileStatus(fp).doesExist()) return fp;
Shinya Kitaoka 120a6e
  fp = getTemplateRoomsDir() + filename;
Shinya Kitaoka 120a6e
  return fp;
turtletooth 8d9ba3
}
turtletooth 8d9ba3
Shinya Kitaoka 120a6e
TFilePath ToonzFolder::getRoomsFile(std::string fn) {
Shinya Kitaoka 120a6e
  return ToonzFolder::getRoomsFile(TFilePath(fn));
turtletooth 8d9ba3
}
turtletooth 8d9ba3
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
FolderListenerManager::FolderListenerManager() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
FolderListenerManager::~FolderListenerManager() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
FolderListenerManager *FolderListenerManager::instance() {
Shinya Kitaoka 120a6e
  static FolderListenerManager _instance;
Shinya Kitaoka 120a6e
  return &_instance;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FolderListenerManager::notifyFolderChanged(const TFilePath &path) {
Shinya Kitaoka 120a6e
  for (std::set<listener *="">::iterator i = m_listeners.begin();</listener>
Shinya Kitaoka 120a6e
       i != m_listeners.end(); ++i)
Shinya Kitaoka 120a6e
    (*i)->onFolderChanged(path);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FolderListenerManager::addListener(Listener *listener) {
Shinya Kitaoka 120a6e
  m_listeners.insert(listener);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FolderListenerManager::removeListener(Listener *listener) {
Shinya Kitaoka 120a6e
  m_listeners.erase(listener);
Toshihiro Shimizu 890ddd
}