ctkXnatConnectionFactory.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 "ctkXnatConnectionFactory.h"
  16. #include "ctkXnatConnection.h"
  17. #include "ctkXnatObject.h"
  18. #include "ctkXnatServer.h"
  19. #include <QDebug>
  20. // ctkXnatConnectionFactory class
  21. ctkXnatConnection* ctkXnatConnectionFactory::makeConnection(const QString& url, const QString& user, const QString& password)
  22. {
  23. // create XNAT connection
  24. ctkXnatConnection* connection = new ctkXnatConnection;
  25. // test XNAT connection
  26. try
  27. {
  28. testConnection(connection);
  29. }
  30. catch (...)
  31. {
  32. delete connection;
  33. throw;
  34. }
  35. connection->setUrl(url);
  36. qDebug() << "ctkXnatConnectionFactory::makeConnection(const QString& url, const QString& user, const QString& password) url:" << url;
  37. connection->setUserName(user);
  38. connection->setPassword(password);
  39. // return XNAT connection
  40. return connection;
  41. }
  42. void ctkXnatConnectionFactory::testConnection(ctkXnatConnection* connection)
  43. {
  44. // test connection by retrieving project names from XNAT
  45. ctkXnatServer* server = connection->server();
  46. // TODO E.g. get version
  47. }