Skip to content
Snippets Groups Projects
Commit 1ab194ea authored by Gesner Passos's avatar Gesner Passos
Browse files

Deal with the installation of ScriptRepository

make the installation more friendly.

re #6175
parent 711cdee5
No related branches found
No related tags found
No related merge requests found
...@@ -4,21 +4,30 @@ ...@@ -4,21 +4,30 @@
#include <QDebug> #include <QDebug>
#include "MantidAPI/ScriptRepository.h" #include "MantidAPI/ScriptRepository.h"
#include "MantidAPI/ScriptRepositoryFactory.h" #include "MantidAPI/ScriptRepositoryFactory.h"
#include "MantidKernel/ConfigService.h"
#include <QtConcurrentRun> #include <QtConcurrentRun>
#include <QMessageBox> #include <QMessageBox>
#include <QTime> #include <QTime>
#include <QCoreApplication> #include <QCoreApplication>
#include <QLabel> #include <QLabel>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QPushButton>
#include <QFileDialog>
namespace MantidQt namespace MantidQt
{ {
namespace API namespace API
{ {
/** Allow the application to be alive while giving some time to this Widget to ensure that /** Allow the application to be alive while giving some time to this Widget to ensure that
the installation process is going on well.*/ the installation process is going on well.*/
void delay() void delay()
{ {
QTime dieTime= QTime::currentTime().addSecs(1); QTime dieTime= QTime::currentTime().addSecs(3);
while( QTime::currentTime() < dieTime ) while( QTime::currentTime() < dieTime )
QCoreApplication::processEvents(QEventLoop::AllEvents, 100); QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
} }
...@@ -35,7 +44,7 @@ namespace API ...@@ -35,7 +44,7 @@ namespace API
Mantid::API::ScriptRepository_sptr repo_ptr = ScriptRepositoryFactory::Instance().create("GitScriptRepository"); Mantid::API::ScriptRepository_sptr repo_ptr = ScriptRepositoryFactory::Instance().create("GitScriptRepository");
try{ try{
repo_ptr->update(); repo_ptr->update();
QMessageBox::information(NULL, "Install Script Repository", "Script Repository Installed!\n"); // QMessageBox::information(NULL, "Install Script Repository", "Script Repository Installed!\n");
}catch(Mantid::API::ScriptRepoException & ex){ }catch(Mantid::API::ScriptRepoException & ex){
qWarning() << "Update exception: " << ex.what() << endl; qWarning() << "Update exception: " << ex.what() << endl;
return -1; return -1;
...@@ -53,7 +62,7 @@ namespace API ...@@ -53,7 +62,7 @@ namespace API
try{ try{
repo_ptr->update(); repo_ptr->update();
}catch(Mantid::API::ScriptRepoException & ex){ }catch(Mantid::API::ScriptRepoException & ex){
qWarning() << "Update exception: " << ex.what() << endl; qWarning() << "Update of Script Repository failure: " << ex.what() << endl;
return -1; return -1;
} }
return 0; return 0;
...@@ -68,6 +77,8 @@ namespace API ...@@ -68,6 +77,8 @@ namespace API
ui(new Ui::ScriptRepositoryView) ui(new Ui::ScriptRepositoryView)
{ {
using Mantid::API::ScriptRepositoryFactory; using Mantid::API::ScriptRepositoryFactory;
using Mantid::Kernel::ConfigServiceImpl;
using Mantid::Kernel::ConfigService;
Mantid::API::ScriptRepository_sptr repo_ptr = ScriptRepositoryFactory::Instance().create("GitScriptRepository"); Mantid::API::ScriptRepository_sptr repo_ptr = ScriptRepositoryFactory::Instance().create("GitScriptRepository");
if (!repo_ptr->isValid()){ if (!repo_ptr->isValid()){
...@@ -82,30 +93,54 @@ namespace API ...@@ -82,30 +93,54 @@ namespace API
deleteLater(); deleteLater();
return; return;
} }
ConfigServiceImpl & config = ConfigService::Instance();
QString loc = QString::fromStdString(config.getString("ScriptLocalRepository"));
QString dir = QFileDialog::getExistingDirectory(this, tr("Where do you want to install Script Repository?"),
loc,
QFileDialog::ShowDirsOnly
| QFileDialog::DontResolveSymlinks);
//configuring
if (dir.isEmpty())
{
QMessageBox::warning(this, "Installation Failed",
"Invalid Folder to install Script Repository!\n");
close();
deleteLater();
return;
}
QString local_path = dir + "/scriptRepository";
qDebug() << "setting scriptlocalrepository to " << local_path << "\n";
config.setString("ScriptLocalRepository", local_path.toStdString());
config.saveConfig(config.getUserFilename());
// installing in a new thread // installing in a new thread
QFuture<int> install = QtConcurrent::run(install_repository); QFuture<int> install = QtConcurrent::run(install_repository);
// give some time to the thread to start
delay(); delay();
if (install.isResultReadyAt(0)){ if (install.isResultReadyAt(0)){
// this means that the installation failed (no connection, probably) if (install.resultAt(0) < 0){
QMessageBox::information(this,"Installa Script Repository Failed!", QMessageBox::warning(this, "Installatin Failed",
"The installation failed. Please check your internet connection and try again\n"); "The installation of Script Repository Failed\n"
close(); "It may be internet connection or firewall, or the proxy definition.\n"
} "Look at the result log to get some hints\n");
close();
if (QMessageBox::Yes == QMessageBox::question(this, "Install Script Repository", deleteLater();
"Installing Script Repository. It may take a couple of minutes...\n"
"Do you want to do it in background?\n"
"You will have to open the interface again after some minutes.\n",
QMessageBox::Yes|QMessageBox::No)){
QLabel * inf = new QLabel("Running Script Repository Installation in background!\n",this);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(inf);
this->setLayout(layout);
return; return;
}; }
install.resultAt(0); }else{
// give some time to the thread to start
QLabel * inf = new QLabel("Running Script Repository Installation in background!\n"
"Please, check the Result Log to see the progress of the installation\n\n"
"After completing installation, please, reopen the Script Repository Interface\n",
this);
QPushButton * close = new QPushButton("Close");
connect(close, SIGNAL(clicked()), this, SLOT(close()));
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(inf);
layout->addWidget(close);
this->setLayout(layout);
return;
}
} }
ui->setupUi(this); ui->setupUi(this);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment