Skip to content

Commit

Permalink
Disable download button if user has archive access. Refs #8264.
Browse files Browse the repository at this point in the history
  • Loading branch information
jawrainey committed Feb 21, 2014
1 parent 281f145 commit d5a6ec2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 19 deletions.
Expand Up @@ -110,6 +110,8 @@ namespace MantidQt
std::set<std::string> getDataFileExtensions(Mantid::API::Column_sptr column);
/// Add the list of file extensions to the "Filter type..." drop-down.
void populateDataFileType(const std::set<std::string> &extensions);
/// Disable the download button if user can access the files locally from the archives.
void disableDownloadButtonIfArchives(int row);

private slots:
/// When the facility login button is clicked
Expand Down Expand Up @@ -158,8 +160,8 @@ namespace MantidQt
// SLOTS for: "Datafile information"
///////////////////////////////////////////////////////////////////////////////

/// Enables the download & load button if user has selected a data file to download.
void enableDownloadButtons();
/// Disable load/download buttons if no datafile is selected.
void disableDatafileButtons();
/// Performs filterDataFileType() for specified filer type.
void doFilter(const int &index);
/// Downloads selected datFiles to a specified location.
Expand Down
53 changes: 36 additions & 17 deletions Code/Mantid/MantidQt/MantidWidgets/src/CatalogSearch.cpp
Expand Up @@ -13,6 +13,8 @@
#include <QUrl>
#include <QDesktopWidget>

#include <fstream>

namespace MantidQt
{
namespace MantidWidgets
Expand Down Expand Up @@ -998,27 +1000,42 @@ namespace MantidQt
}
}

///////////////////////////////////////////////////////////////////////////////
// SLOTS for: "DataFile information"
///////////////////////////////////////////////////////////////////////////////

/**
* Enables the download & load button if user has selected a data file to download. Otherwise, disables them.
* Disable the download button if user can access the files locally from the archives.
* @param row :: The row the user has selected from the table.
*/
void CatalogSearch::enableDownloadButtons()
void CatalogSearch::disableDownloadButtonIfArchives(int row)
{
QModelIndexList indexes = m_icatUiForm.dataFileResultsTbl->selectionModel()->selection().indexes();
QTableWidget* table = m_icatUiForm.dataFileResultsTbl;
// The location of the file selected in the archives.
std::string location = table->item(row,headerIndexByName(table, "Location"))->text().toStdString();
Mantid::Kernel::CatalogInfo catalogInfo = Mantid::Kernel::ConfigService::Instance().getFacility().catalogInfo();
std::string fileLocation = catalogInfo.transformArchivePath(location);

// If the user has selected a data file to download, then enable relevant buttons.
// Otherwise null would be passed to download/load, which causes an exception.
if (!indexes.empty())
std::ifstream hasAccessToArchives(fileLocation);
if (hasAccessToArchives)
{
m_icatUiForm.dataFileDownloadBtn->setEnabled(true);
m_icatUiForm.dataFileLoadBtn->setEnabled(true);
m_icatUiForm.dataFileDownloadBtn->setEnabled(false);
}
else
{
// Otherwise, disable the buttons to prevent the user from downloading/loading nothing.
m_icatUiForm.dataFileDownloadBtn->setEnabled(true);
}
// Allow the user to load the datafile regardless.
m_icatUiForm.dataFileLoadBtn->setEnabled(true);
}

///////////////////////////////////////////////////////////////////////////////
// SLOTS for: "DataFile information"
///////////////////////////////////////////////////////////////////////////////

/**
* Disable the load/download button to prevent the user from downloading/loading nothing.
*/
void CatalogSearch::disableDatafileButtons()
{
if (m_icatUiForm.dataFileResultsTbl->selectionModel()->selection().indexes().empty())
{
m_icatUiForm.dataFileDownloadBtn->setEnabled(false);
m_icatUiForm.dataFileLoadBtn->setEnabled(false);
}
Expand Down Expand Up @@ -1119,8 +1136,6 @@ namespace MantidQt
if (toggled) table->item(row, 0)->setCheckState(Qt::Checked);
else table->item(row, 0)->setCheckState(Qt::Unchecked);
}

enableDownloadButtons();
}

/**
Expand Down Expand Up @@ -1173,9 +1188,13 @@ namespace MantidQt

for (int i = 0; i < indexes.count(); ++i)
{
table->item(indexes.at(i).row(), 0)->setCheckState(Qt::Checked);
int row = indexes.at(i).row();
table->item(row, 0)->setCheckState(Qt::Checked);
/// Disable/Enable download button if user has access to the archives.
disableDownloadButtonIfArchives(row);
}
enableDownloadButtons();
// Disable load/download buttons if no datafile is selected.
disableDatafileButtons();
}


Expand Down

0 comments on commit d5a6ec2

Please sign in to comment.