ctkXnatSettings.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*=============================================================================
  2. Library: XNAT/Core
  3. Copyright (c) University College London,
  4. Centre for Medical Image Computing
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #include "ctkXnatSettings.h"
  16. #include <QDir>
  17. #include <QFileInfo>
  18. #include <QUuid>
  19. //----------------------------------------------------------------------------
  20. QString ctkXnatSettings::workSubdirectory() const
  21. {
  22. // set work directory name
  23. QDir workDir;
  24. QString workDirName = defaultWorkDirectory();
  25. if ( !workDirName.isEmpty() )
  26. {
  27. workDir = QDir(workDirName);
  28. }
  29. // generate random name for subdirectory
  30. QString subdir = QUuid::createUuid().toString();
  31. // create subdirectory in work directory
  32. bool subdirCreated = workDir.mkdir(subdir);
  33. // check whether subdirectory was created
  34. if ( !subdirCreated )
  35. {
  36. // display error message
  37. return QString();
  38. }
  39. // return full path of subdirectory
  40. return QFileInfo(workDir, subdir).absoluteFilePath();
  41. }