diff --git a/toonz/sources/include/toonz/preferences.h b/toonz/sources/include/toonz/preferences.h index 968fe06..7b8c6e4 100644 --- a/toonz/sources/include/toonz/preferences.h +++ b/toonz/sources/include/toonz/preferences.h @@ -110,6 +110,12 @@ public: return m_replaceAfterSaveLevelAs; } + void setProjectRoot(int index); + int getProjectRoot() { return m_projectRoot; } + + void setCustomProjectRoot(std::wstring path); + QString getCustomProjectRoot() { return m_customProjectRoot; } + // Interface tab void setCurrentLanguage(int currentLanguage); @@ -428,8 +434,7 @@ private: std::vector m_levelFormats; QString m_units, m_cameraUnits, m_scanLevelType, m_currentRoomChoice, - m_oldUnits, m_oldCameraUnits, m_ffmpegPath; - ; + m_oldUnits, m_oldCameraUnits, m_ffmpegPath, m_customProjectRoot; double m_defLevelWidth, m_defLevelHeight, m_defLevelDpi; @@ -442,7 +447,7 @@ private: m_chunkSize, m_blanksCount, m_onionPaperThickness, m_step, m_shrink, m_textureSize, m_autocreationType, m_keyframeType, m_animationStep, m_ffmpegTimeout; // seconds - + int m_projectRoot; int m_currentLanguage, m_currentStyleSheet, m_undoMemorySize, // in megabytes m_dragCellsBehaviour, m_lineTestFpsCapture, m_defLevelType, m_xsheetStep, diff --git a/toonz/sources/toonz/preferencespopup.cpp b/toonz/sources/toonz/preferencespopup.cpp index f61fbc3..09064aa 100644 --- a/toonz/sources/toonz/preferencespopup.cpp +++ b/toonz/sources/toonz/preferencespopup.cpp @@ -45,6 +45,7 @@ #include #include #include +#include using namespace DVGui; @@ -278,6 +279,33 @@ void PreferencesPopup::onPixelsOnlyChanged(int index) { //----------------------------------------------------------------------------- +void PreferencesPopup::onProjectRootChanged() { + int index = 0; + if (m_projectRootStuff->isChecked()) index |= 0x08; + if (m_projectRootDocuments->isChecked()) index |= 0x04; + if (m_projectRootDesktop->isChecked()) index |= 0x02; + if (m_projectRootCustom->isChecked()) index |= 0x01; + m_pref->setProjectRoot(index); + if (index & 0x01) { + m_customProjectRootFileField->show(); + m_customProjectRootLabel->show(); + m_projectRootDirections->show(); + } else { + m_customProjectRootFileField->hide(); + m_customProjectRootLabel->hide(); + m_projectRootDirections->hide(); + } +} + +//----------------------------------------------------------------------------- + +void PreferencesPopup::onCustomProjectRootChanged() { + QString text = m_customProjectRootFileField->getPath(); + m_pref->setCustomProjectRoot(text.toStdWString()); +} + +//----------------------------------------------------------------------------- + void PreferencesPopup::onPixelUnitExternallySelected(bool on) { // call slot function onPixelsOnlyChanged() accordingly m_pixelsOnlyCB->setCheckState((on) ? Qt::Checked : Qt::Unchecked); @@ -911,6 +939,15 @@ PreferencesPopup::PreferencesPopup() new DVGui::IntLineEdit(this, m_pref->getDefaultTaskChunkSize(), 1, 2000); CheckBox *sceneNumberingCB = new CheckBox(tr("Show Info in Rendered Frames")); + m_projectRootDocuments = new CheckBox(tr("My Documents/OpenToonz*"), this); + m_projectRootDesktop = new CheckBox(tr("Desktop/OpenToonz*"), this); + m_projectRootStuff = new CheckBox(tr("Stuff Folder*"), this); + m_projectRootCustom = new CheckBox(tr("Custom*"), this); + m_customProjectRootFileField = new DVGui::FileField(this, QString("")); + m_customProjectRootLabel = new QLabel(tr("Custom Project Path(s): ")); + m_projectRootDirections = new QLabel( + tr("Advanced: Multiple paths can be separated by ** (No Spaces)")); + QLabel *note_general = new QLabel(tr("* Changes will take effect the next time you run Toonz")); note_general->setStyleSheet("font-size: 10px; font: italic;"); @@ -1113,6 +1150,20 @@ PreferencesPopup::PreferencesPopup() m_levelsBackup->setChecked(m_pref->isLevelsBackupEnabled()); sceneNumberingCB->setChecked(m_pref->isSceneNumberingEnabled()); + m_customProjectRootFileField->setPath(m_pref->getCustomProjectRoot()); + + int projectPaths = m_pref->getProjectRoot(); + m_projectRootStuff->setChecked(projectPaths & 0x08); + m_projectRootDocuments->setChecked(projectPaths & 0x04); + m_projectRootDesktop->setChecked(projectPaths & 0x02); + m_projectRootCustom->setChecked(projectPaths & 0x01); + + m_projectRootStuff->hide(); + if (!(projectPaths & 0x01)) { + m_customProjectRootFileField->hide(); + m_customProjectRootLabel->hide(); + m_projectRootDirections->hide(); + } //--- Interface ------------------------------ QStringList styleSheetList; for (int i = 0; i < m_pref->getStyleSheetCount(); i++) { @@ -1369,6 +1420,24 @@ PreferencesPopup::PreferencesPopup() Qt::AlignLeft | Qt::AlignVCenter); generalFrameLay->addWidget(sceneNumberingCB, 0, Qt::AlignLeft | Qt::AlignVCenter); + QGroupBox *projectGroupBox = + new QGroupBox(tr("Additional Project Locations"), this); + QGridLayout *projectRootLay = new QGridLayout(); + projectRootLay->setMargin(10); + projectRootLay->setHorizontalSpacing(5); + projectRootLay->setVerticalSpacing(10); + { + projectRootLay->addWidget(m_projectRootStuff, 0, 0); + projectRootLay->addWidget(m_projectRootDocuments, 1, 0); + projectRootLay->addWidget(m_projectRootDesktop, 2, 0); + projectRootLay->addWidget(m_projectRootCustom, 3, 0); + projectRootLay->addWidget(m_customProjectRootLabel, 4, 0, + Qt::AlignRight | Qt::AlignVCenter); + projectRootLay->addWidget(m_customProjectRootFileField, 4, 1, 1, 3); + projectRootLay->addWidget(m_projectRootDirections, 5, 0, 1, 4); + } + projectGroupBox->setLayout(projectRootLay); + generalFrameLay->addWidget(projectGroupBox, 0); generalFrameLay->addStretch(1); generalFrameLay->addWidget(note_general, 0); @@ -1848,7 +1917,16 @@ PreferencesPopup::PreferencesPopup() SLOT(onSceneNumberingChanged(int))); ret = ret && connect(m_chunkSizeFld, SIGNAL(editingFinished()), this, SLOT(onChunkSizeChanged())); - + ret = ret && connect(m_customProjectRootFileField, SIGNAL(pathChanged()), + this, SLOT(onCustomProjectRootChanged())); + ret = ret && connect(m_projectRootDocuments, SIGNAL(stateChanged(int)), + SLOT(onProjectRootChanged())); + ret = ret && connect(m_projectRootDesktop, SIGNAL(stateChanged(int)), + SLOT(onProjectRootChanged())); + ret = ret && connect(m_projectRootStuff, SIGNAL(stateChanged(int)), + SLOT(onProjectRootChanged())); + ret = ret && connect(m_projectRootCustom, SIGNAL(stateChanged(int)), + SLOT(onProjectRootChanged())); //--- Interface ---------------------- ret = ret && connect(styleSheetType, SIGNAL(currentIndexChanged(int)), SLOT(onStyleSheetTypeChanged(int))); diff --git a/toonz/sources/toonz/preferencespopup.h b/toonz/sources/toonz/preferencespopup.h index 7677d22..74290c8 100644 --- a/toonz/sources/toonz/preferencespopup.h +++ b/toonz/sources/toonz/preferencespopup.h @@ -58,7 +58,7 @@ private: DVGui::DoubleLineEdit *m_defLevelDpi; - QLabel *m_dpiLabel; + QLabel *m_dpiLabel, *m_customProjectRootLabel, *m_projectRootDirections; DVGui::IntLineEdit *m_minuteFld, *m_chunkSizeFld, *m_iconSizeLx, *m_iconSizeLy, *m_viewShrink, *m_viewStep, *m_blanksCount, @@ -68,7 +68,11 @@ private: QPushButton *m_addLevelFormat, *m_removeLevelFormat, *m_editLevelFormat; DVGui::CheckBox *m_inksOnly, *m_enableVersionControl, *m_levelsBackup, - *m_onionSkinVisibility, *m_pixelsOnlyCB, *m_onionSkinDuringPlayback; + *m_onionSkinVisibility, *m_pixelsOnlyCB, *m_projectRootDocuments, + *m_projectRootDesktop, *m_projectRootCustom, *m_projectRootStuff, + *m_onionSkinDuringPlayback; + + DVGui::FileField *m_customProjectRootFileField; DVGui::FileField *m_ffmpegPathFileFld; @@ -79,6 +83,8 @@ private: private slots: void onPixelsOnlyChanged(int index); + void onProjectRootChanged(); + void onCustomProjectRootChanged(); void onPixelUnitExternallySelected(bool on); void onUnitChanged(int index); void onCameraUnitChanged(int index); diff --git a/toonz/sources/toonzlib/preferences.cpp b/toonz/sources/toonzlib/preferences.cpp index 886e841..e7da85d 100644 --- a/toonz/sources/toonzlib/preferences.cpp +++ b/toonz/sources/toonzlib/preferences.cpp @@ -287,6 +287,8 @@ Preferences::Preferences() , m_multiLayerStylePickerEnabled(false) , m_paletteTypeOnLoadRasterImageAsColorModel(0) , m_showKeyframesOnXsheetCellArea(true) + , m_projectRoot(0x08) + , m_customProjectRoot("") , m_precompute(true) , m_ffmpegTimeout(30) { TCamera camera; @@ -392,6 +394,9 @@ Preferences::Preferences() m_oldCameraUnits = units; // end for pixels only + getValue(*m_settings, "projectRoot", m_projectRoot); + m_customProjectRoot = m_settings->value("customProjectRoot").toString(); + units = m_settings->value("linearUnits").toString(); if (units != "") m_units = units; setUnits(m_units.toStdString()); @@ -971,6 +976,22 @@ void Preferences::setPixelsOnly(bool state) { //----------------------------------------------------------------- +void Preferences::setProjectRoot(int index) { + // storing the index of the selection instead of the text + // to make translation work + m_projectRoot = index; + m_settings->setValue("projectRoot", m_projectRoot); +} + +//----------------------------------------------------------------- + +void Preferences::setCustomProjectRoot(std::wstring customProjectRoot) { + m_customProjectRoot = QString::fromStdWString(customProjectRoot); + m_settings->setValue("customProjectRoot", m_customProjectRoot); +} + +//----------------------------------------------------------------- + void Preferences::setUnits(std::string units) { m_units = QString::fromStdString(units); m_settings->setValue("linearUnits", m_units); diff --git a/toonz/sources/toonzlib/toonzfolders.cpp b/toonz/sources/toonzlib/toonzfolders.cpp index ff09da0..a8ccd6b 100644 --- a/toonz/sources/toonzlib/toonzfolders.cpp +++ b/toonz/sources/toonzlib/toonzfolders.cpp @@ -3,20 +3,75 @@ #include "toonz/toonzfolders.h" #include "tsystem.h" #include "tenv.h" -//#include "appmainshell.h" #include "tconvert.h" #include "toonz/preferences.h" +#include using namespace TEnv; +//------------------------------------------------------------------- +namespace { +TFilePath getMyDocumentsPath() { + QString documentsPath = + QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation)[0]; + return TFilePath(documentsPath); +} + +// Desktop Path +TFilePath getDesktopPath() { + QString desktopPath = + QStandardPaths::standardLocations(QStandardPaths::DesktopLocation)[0]; + return TFilePath(desktopPath); +} +} +//------------------------------------------------------------------- + TFilePath ToonzFolder::getModulesDir() { return getProfileFolder() + "layouts"; } TFilePathSet ToonzFolder::getProjectsFolders() { - TFilePathSet fps = + int location = Preferences::instance()->getProjectRoot(); + QString path = Preferences::instance()->getCustomProjectRoot(); + TFilePathSet fps; + int projectPaths = Preferences::instance()->getProjectRoot(); + bool stuff = projectPaths & 0x08; + bool documents = projectPaths & 0x04; + bool desktop = projectPaths & 0x02; + bool custom = projectPaths & 0x01; + + // make sure at least something is there + if (!desktop && !custom && !documents) stuff = 1; + TFilePathSet tempFps = getSystemVarPathSetValue(getSystemVarPrefix() + "PROJECTS"); - if (fps.empty()) fps.push_back(TEnv::getStuffDir() + "Projects"); + if (stuff) { + for (TFilePath tempPath : tempFps) { + if (TSystem::doesExistFileOrLevel(TFilePath(tempPath))) { + fps.push_back(TFilePath(tempPath)); + } + } + if (tempFps.size() == 0) fps.push_back(TEnv::getStuffDir() + "Projects"); + } + if (documents) { + fps.push_back(getMyDocumentsPath() + "OpenToonz"); + if (!TSystem::doesExistFileOrLevel(getMyDocumentsPath() + "OpenToonz")) { + TSystem::mkDir(getMyDocumentsPath() + "OpenToonz"); + } + } + if (desktop) { + fps.push_back(getDesktopPath() + "OpenToonz"); + if (!TSystem::doesExistFileOrLevel(getDesktopPath() + "OpenToonz")) { + TSystem::mkDir(getDesktopPath() + "OpenToonz"); + } + } + if (custom) { + QStringList paths = path.split("**"); + for (QString tempPath : paths) { + if (TSystem::doesExistFileOrLevel(TFilePath(tempPath))) { + fps.push_back(TFilePath(tempPath)); + } + } + } return fps; }