FridgeGrid is a tool intended to help planning cycle exact code for effects on old school hardware. Think of it as a combination of grid paper and fridge magnets in digital form with save and load functions. https://xayax.net/tools/fridgegrid/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DocumentsDir.cpp 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * src/fridgegrid/MainWindow.cpp
  3. * written by Sven Oliver Moll
  4. *
  5. * distributed under the terms of the GNU General Public License (GPL)
  6. * available at http://www.gnu.org/licenses/gpl.html
  7. */
  8. /* class declaration */
  9. #include "DocumentsDir.hpp"
  10. /* system headers */
  11. /* Qt headers */
  12. #include <QCoreApplication>
  13. #include <QFileInfoList>
  14. #include <QSettings>
  15. #include <QStandardPaths>
  16. /* local library headers */
  17. /* local headers */
  18. #define SETTINGS_CREATETEMPLATESDIR "CreateTemplatesDir"
  19. DocumentsDir::DocumentsDir()
  20. : mDir()
  21. {
  22. QSettings settings;
  23. QDir templatesDir( getTemplatesDirName() );
  24. if( !settings.contains( SETTINGS_CREATETEMPLATESDIR ) )
  25. {
  26. settings.setValue( SETTINGS_CREATETEMPLATESDIR, true );
  27. }
  28. if( !templatesDir.exists() &&
  29. settings.value( SETTINGS_CREATETEMPLATESDIR ).toBool() )
  30. {
  31. generateTemplateDir();
  32. }
  33. }
  34. QFileInfoList DocumentsDir::getTemplates() const
  35. {
  36. return QDir( getTemplatesDirName() ).entryInfoList( QStringList("*.xml"), QDir::Files );
  37. }
  38. QString DocumentsDir::getTemplatesDirName() const
  39. {
  40. QSettings settings;
  41. if( settings.value( SETTINGS_CREATETEMPLATESDIR ).toBool() )
  42. {
  43. return QStandardPaths::writableLocation( QStandardPaths::DocumentsLocation ) +
  44. "/" + QCoreApplication::applicationName() + "/Templates";
  45. }
  46. else
  47. {
  48. return ":/templates/";
  49. }
  50. }
  51. void DocumentsDir::generateTemplateDir()
  52. {
  53. QFileInfoList fil( QDir(":/templates/").entryInfoList() );
  54. QDir templatesDir( getTemplatesDirName() );
  55. if( !templatesDir.mkpath( "." ) )
  56. {
  57. return;
  58. }
  59. foreach( const QFileInfo &fi, fil )
  60. {
  61. QString srcFile( fi.absoluteFilePath() );
  62. QString destFile( templatesDir.absoluteFilePath( fi.fileName() ) );
  63. if( QFile::copy( srcFile, destFile ) )
  64. {
  65. QFile::setPermissions( destFile, QFile::permissions( destFile ) | QFile::WriteUser );
  66. }
  67. }
  68. }