Explorar o código

Added possibility to set a default file download path to ctkXnatSession.
If the specified location does not exist its value will be set to the current
working directory

Andreas Fetzer %!s(int64=10) %!d(string=hai) anos
pai
achega
6bf620dbe9
Modificáronse 2 ficheiros con 46 adicións e 0 borrados
  1. 27 0
      Libs/XNAT/Core/ctkXnatSession.cpp
  2. 19 0
      Libs/XNAT/Core/ctkXnatSession.h

+ 27 - 0
Libs/XNAT/Core/ctkXnatSession.cpp

@@ -37,6 +37,7 @@
 
 #include <QDateTime>
 #include <QDebug>
+#include <QDir>
 #include <QScopedPointer>
 #include <QStringBuilder>
 #include <QNetworkCookie>
@@ -61,6 +62,7 @@ public:
   QScopedPointer<ctkXnatAPI> xnat;
   QScopedPointer<ctkXnatDataModel> dataModel;
   QString sessionId;
+  QString defaultFilePath;
 
   QMap<QString, QString> sessionProperties;
 
@@ -87,6 +89,7 @@ ctkXnatSessionPrivate::ctkXnatSessionPrivate(const ctkXnatLoginProfile& loginPro
                                              ctkXnatSession* q)
   : loginProfile(loginProfile)
   , xnat(new ctkXnatAPI())
+  , defaultFilePath("")
   , q(q)
 {
   // TODO This is a workaround for connecting to sites with self-signed
@@ -467,6 +470,30 @@ QString ctkXnatSession::password() const
 }
 
 //----------------------------------------------------------------------------
+void ctkXnatSession::setDefaultFilePath(const QString &path)
+{
+  Q_D(ctkXnatSession);
+
+  QDir directory(path);
+  if (directory.exists())
+  {
+    d->defaultFilePath = path;
+  }
+  else
+  {
+    d->defaultFilePath = QDir::currentPath();
+    qWarning() << "Specified directory: ["<<path<<"] does not exists! Setting default filepath to :"<<d->defaultFilePath;
+  }
+}
+
+//----------------------------------------------------------------------------
+QString ctkXnatSession::defaultFilePath() const
+{
+  Q_D(const ctkXnatSession);
+  return d->defaultFilePath;
+}
+
+//----------------------------------------------------------------------------
 ctkXnatDataModel* ctkXnatSession::dataModel() const
 {
   Q_D(const ctkXnatSession);

+ 19 - 0
Libs/XNAT/Core/ctkXnatSession.h

@@ -139,6 +139,25 @@ public:
    */
   QString password() const;
 
+  /**
+    * @brief Sets the default location where files will be save after being downloaded
+    *
+    * Sets the default directory into which file downloads will be saved.
+    * By default this value is empty and files will be stored into the directory
+    * of the executable.
+    * If the path does not exists a warning will be printed and the path will be
+    * set to the current working directory
+    *
+    * @param path the path to the download location
+    */
+  void setDefaultFilePath(const QString& path);
+
+  /**
+    * @brief returns the default download location
+    * @return the default download directory as string
+    */
+  QString defaultFilePath() const;
+
   ctkXnatDataModel* dataModel() const;
 
   /**