ctkXnatScanResource.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*=============================================================================
  2. Plugin: org.commontk.xnat
  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 "ctkXnatScanResource.h"
  16. #include "ctkXnatSession.h"
  17. #include "ctkXnatObjectPrivate.h"
  18. #include "ctkXnatScan.h"
  19. #include "ctkXnatFile.h"
  20. class ctkXnatScanResourcePrivate : public ctkXnatObjectPrivate
  21. {
  22. public:
  23. ctkXnatScanResourcePrivate()
  24. : ctkXnatObjectPrivate()
  25. {
  26. }
  27. void reset()
  28. {
  29. // uri.clear();
  30. }
  31. // QString uri;
  32. };
  33. ctkXnatScanResource::ctkXnatScanResource(ctkXnatScan* parent)
  34. : ctkXnatObject(*new ctkXnatScanResourcePrivate(), parent)
  35. {
  36. }
  37. ctkXnatScanResource::~ctkXnatScanResource()
  38. {
  39. }
  40. QString ctkXnatScanResource::resourceUri() const
  41. {
  42. return QString("%1/resources/%2").arg(parent()->resourceUri(), this->property("label"));
  43. }
  44. void ctkXnatScanResource::reset()
  45. {
  46. ctkXnatObject::reset();
  47. }
  48. void ctkXnatScanResource::fetchImpl()
  49. {
  50. QString scanResourceFilesUri = this->resourceUri() + "/files";
  51. ctkXnatSession* const session = this->session();
  52. QUuid queryId = session->httpGet(scanResourceFilesUri);
  53. QList<ctkXnatObject*> files = session->httpResults(queryId, ctkXnatFile::staticSchemaType());
  54. foreach (ctkXnatObject* file, files)
  55. {
  56. QString label = file->property("Name");
  57. if (!label.isEmpty())
  58. {
  59. file->setProperty("ID", label);
  60. }
  61. this->add(file);
  62. }
  63. }
  64. void ctkXnatScanResource::download(const QString& filename)
  65. {
  66. this->session()->download(this, filename);
  67. }