Skip to content

Commit

Permalink
Hide catalog menu items if not logged in. Refs #8192.
Browse files Browse the repository at this point in the history
  • Loading branch information
jawrainey committed Nov 14, 2013
1 parent e1362e3 commit 54ae08e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
23 changes: 14 additions & 9 deletions Code/Mantid/MantidPlot/src/ApplicationWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1292,8 +1292,6 @@ void ApplicationWindow::initMainMenu()
icat = new QMenu(this);
icat->setObjectName("CatalogMenu");
icat->addAction(actionCatalogLogin);//Login menu item
icat->addAction(actionCatalogSearch); // ICAT GUI menu item
icat->addAction(actionCatalogLogout);//logout menu item
disableActions();
}

Expand Down Expand Up @@ -17442,7 +17440,12 @@ void ApplicationWindow::panOnPlot()
/// Handler for ICat Login Menu
void ApplicationWindow::CatalogLogin()
{
mantidUI->executeAlgorithm("CatalogLogin",1);
// Executes the catalog login algorithm, and returns true if user can login.
if (mantidUI->isValidCatalogLogin())
{
icat->addAction(actionCatalogSearch);
icat->addAction(actionCatalogLogout);
}
}

void ApplicationWindow::CatalogSearch()
Expand All @@ -17460,6 +17463,14 @@ void ApplicationWindow::CatalogSearch()
}
}

void ApplicationWindow::CatalogLogout()
{
auto logout = mantidUI->createAlgorithm("CatalogLogout");
mantidUI->executeAlgorithmAsync(logout);
icat->removeAction(actionCatalogSearch);
icat->removeAction(actionCatalogLogout);
}

void ApplicationWindow::setGeometry(MdiSubWindow* usr_win,QWidget* user_interface)
{
QRect frame = QRect(usr_win->frameGeometry().topLeft() - usr_win->geometry().topLeft(),
Expand All @@ -17472,12 +17483,6 @@ void ApplicationWindow::setGeometry(MdiSubWindow* usr_win,QWidget* user_interfac
addMdiSubWindow(usr_win);
}

void ApplicationWindow::CatalogLogout()
{
auto logout = mantidUI->createAlgorithm("CatalogLogout");
mantidUI->executeAlgorithmAsync(logout);
}

/**
* Write a message to the log window. The message priority will be information
* or error if error=true
Expand Down
16 changes: 16 additions & 0 deletions Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2032,6 +2032,22 @@ void MantidUI::enableSaveNexus(const QString& wsName)
appWindow()->enablesaveNexus(wsName);
}

/**
* Executes the catalog login algorithm.
* Returns true if login was a success.
*/
bool MantidUI::isValidCatalogLogin()
{
auto catalogAlgorithm = this->createAlgorithm("CatalogLogin");
auto loginDialog = this->createAlgorithmDialog(catalogAlgorithm);

if(loginDialog->exec() == QDialog::Accepted)
{
if (catalogAlgorithm->execute()) return true;
}
return false;
}

/** This method is sueful for saving the currently loaded workspaces to project file on save.
* saves the names of all the workspaces loaded into mantid workspace tree
* into a string and calls save nexus on each workspace to save the data to a nexus file.
Expand Down
3 changes: 3 additions & 0 deletions Code/Mantid/MantidPlot/src/Mantid/MantidUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ public slots:
void saveProject(bool save);
void enableSaveNexus(const QString & wsName);

/// Verifies if the Catalog login was a success.
bool isValidCatalogLogin();

signals:
//A signal to indicate that we want a script to produce a dialog
void showPropertyInputDialog(const QString & algName);
Expand Down

0 comments on commit 54ae08e

Please sign in to comment.