12#include "MantidQtIcons/Icon.h"
17#include <QCoreApplication>
34 "<html><head/><body><p>The <span style=\" font-weight:600;\">"
35 "Script Repository</span> allows you to:</p>"
36 "<p> * Share your scripts and reduction algorithms;</p>"
37 "<p> * Get <span style=\" font-weight:600;\">Mantid</span> Scripts from "
38 "the mantid developers and the community. </p>"
39 "<p><span style=\" font-style:italic;\">"
40 "N.B. The installation usually requires a couple of minutes, depending on "
41 "your network bandwidth. </span></p>"
42 "<p>More Information available at "
43 "<a href=\"http://docs.mantidproject.org/workbench/scriptrepository\"><span style=\" "
44 "text-decoration: underline; color:#0000ff;\">"
45 "http://docs.mantidproject.org/workbench/scriptrepository</span></a></p></br><p><span "
46 "style=\" font-weight:600;\">"
47 "Would you like to install it now?</span></p></body></html>";
50 "Installing Script Repository Installation in background!</span></p>"
51 "<p>You may continue to use mantid.</p>"
52 "<p>The Result Log willl give you information of the installation "
54 "<p>When finished, please, reopen the <span style=\" "
55 "font-weight:600;\">Script Repository</span>. </p></body></html>";
58 "<span style=\" font-weight:600;\">Failed</span>!</p>"
59 "<p>Please, check the Result Log to see why the installation failed. "
62const QString
dir_not_empty_label =
"<html><head/><body><p>The directory/folder that you have selected is not "
64 "<p>Are you sure that you want to install the script repository here? All "
65 "the files and directories found in "
66 "the selected directory/folder could be shared in the repository by "
68 "<p>If you are not sure, please choose 'no' and then select an empty (or "
69 "newly created) directory/folder.</p>"
70 "<p>If this is your home directory, desktop or similar you should "
71 "definitely choose 'no'.</p>"
72 "<p>If you are sure of what you are doing, please choose 'yes'. The "
73 "installation may take a couple of minutes.</p>"
105 if (!repo_ptr->isValid()) {
116 g_log.
warning() <<
"ScriptRepository installation: " << ex.
what() <<
'\n';
117 g_log.
information() <<
"ScriptRepository installation failed with this information: " << ex.
systemError() <<
'\n';
118 QMessageBox::warning(
this,
"Installation Failed", QString(ex.
what()));
123 g_log.
error() <<
"Unknown error occurred to install ScriptRepository. It "
124 "will not be shown.\n";
132 connect(
ui->reloadPushButton, SIGNAL(clicked()),
this, SLOT(
updateModel()));
133 connect(
ui->pbHelp, SIGNAL(clicked()),
this, SLOT(
helpClicked()));
134 connect(
model, SIGNAL(executingThread(
bool)),
ui->reloadPushButton, SLOT(setDisabled(
bool)));
137 ui->repo_treeView->setModel(
model);
138 ui->repo_treeView->setItemDelegateForColumn(1,
new RepoDelegate(
this));
141 ui->repo_treeView->setColumnWidth(0, 290);
144 connect(
ui->repo_treeView, SIGNAL(activated(
const QModelIndex &)),
this, SLOT(
cell_activated(
const QModelIndex &)));
145 connect(
ui->repo_treeView, SIGNAL(currentCell(
const QModelIndex &)),
this, SLOT(
currentChanged(
const QModelIndex &)));
146 const ConfigServiceImpl &config = ConfigService::Instance();
148 connect(
ui->folderPathLabel, SIGNAL(linkActivated(QString)),
this, SLOT(
openFolderLink(QString)));
160 enum EXC_OPTIONS { NOTWANTED, NODIRECTORY };
165 if (QMessageBox::Ok != QMessageBox::question(
this,
"Install Script Repository?",
install_mantid_label,
166 QMessageBox::Ok | QMessageBox::Cancel)) {
170 const ConfigServiceImpl &config = ConfigService::Instance();
171 QString loc = QString::fromStdString(config.getString(
"ScriptLocalRepository"));
173 bool sureAboutDir =
false;
175 while (!sureAboutDir) {
176 dir = QFileDialog::getExistingDirectory(
this, tr(
"Where do you want to install Script Repository?"), loc,
177 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
185 if (0 == QDir(dir).entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot).
count()) {
191 QMessageBox::StandardButton sel =
192 QMessageBox::question(
this,
"Are you sure you want to install the Script Repository here?",
194 if (QMessageBox::Yes == sel)
198 }
catch (EXC_OPTIONS &ex) {
199 if (ex == NODIRECTORY) {
201 QMessageBox::warning(
this,
"Installation Failed",
"Invalid Folder to install Script Repository!\n");
209 repo_ptr->install(dir.toStdString());
211 g_log.
information() <<
"ScriptRepository installed at " << dir.toStdString() <<
'\n';
216 const QString loc = QString::fromStdString(installDir);
217 const QString loc_info =
"<html><head/><body><p><a href=\"%1\"><span style=\" "
218 "text-decoration: underline; "
219 "color:#0000ff;\">%2</span></a></p></body></html>";
224 path_label = QString(
"%1...%2").arg(loc.left(20)).arg(loc.right(27));
227 ui->folderPathLabel->setText(loc_info.arg(loc).arg(path_label));
228 ui->folderPathLabel->setToolTip(QString(
"Click here to open Script Repository Folder: %1.").arg(loc));
241 if (!model_repo_ptr->isValid()) {
248 connect(
model, SIGNAL(executingThread(
bool)),
ui->reloadPushButton, SLOT(setDisabled(
bool)));
249 ui->repo_treeView->setModel(
model);
266 RepoModel *_model = qobject_cast<RepoModel *>(
ui->repo_treeView->model());
268 QString path = _model->
filePath(in);
269 if (path.isEmpty()) {
284 RepoModel *_model = qobject_cast<RepoModel *>(
ui->repo_treeView->model());
289 ui->desc_textBrowser->setText(description);
290 QString author_name = _model->
author(in);
291 if (author_name.isEmpty())
292 ui->authorNameLabel->setText(
"");
294 ui->authorNameLabel->setText(QString(
"<b>Author:</b> ") + author_name);
333 const QModelIndex &
index)
const {
335 if (!
index.isValid())
337 if (painter->device() ==
nullptr)
341 QString state =
index.model()->data(
index, Qt::DisplayRole).toString();
342 auto icon = getIcon(state);
345 QRect buttonRect(option.rect);
346 int min_val = buttonRect.width() < buttonRect.height() ? buttonRect.width() : buttonRect.height();
348 buttonRect.setWidth(min_val);
349 buttonRect.setHeight(min_val);
350 buttonRect.moveCenter(option.rect.center());
353 QStyleOptionButton button;
354 button.rect = buttonRect;
356 int icon_size = (int)(min_val * .8);
357 button.iconSize = QSize(icon_size, icon_size);
358 button.state = QStyle::State_Enabled;
360 QApplication::style()->drawControl(QStyle::CE_PushButton, &button, painter);
366 icon = Icons::getIcon(
"mdi.download");
368 icon = Icons::getIcon(
"mdi.transfer-down");
370 icon = Icons::getIcon(
"mdi.check-bold");
372 icon = Icons::getIcon(
"mdi.upload");
374 icon = Icons::getIcon(
"mdi.progress-download");
376 icon = Icons::getIcon(
"mdi.progress-upload");
403 const QStyleOptionViewItem & ,
404 const QModelIndex &
index) {
406 if (event->type() == QEvent::MouseButtonPress) {
408 QString action =
"Download";
423 const QModelIndex & )
const {
424 return QSize(35, 35);
454 const QModelIndex &
index)
const {
455 if (!
index.isValid())
457 if (painter->device() ==
nullptr)
460 QStyleOptionViewItem modifiedOption(option);
462 QPoint p = modifiedOption.rect.center();
463 QSize curr = modifiedOption.rect.size();
464 int min_value = (int)((curr.width() < curr.height()) ? curr.width() : curr.height() * .8);
466 modifiedOption.rect.setSize(QSize(min_value, min_value));
467 modifiedOption.rect.moveCenter(p);
469 QString state =
index.model()->data(
index, Qt::DisplayRole).toString();
472 modifiedOption.state |= QStyle::State_On;
473 else if (state ==
"false")
474 modifiedOption.state |= QStyle::State_Off;
478 QApplication::style()->drawPrimitive(QStyle::PE_IndicatorItemViewItemCheck, &modifiedOption, painter);
504 const QStyleOptionViewItem & ,
505 const QModelIndex &
index) {
506 if (event->type() == QEvent::MouseButtonPress) {
508 QString action =
"setFalse";
509 if (
value ==
"false")
536 const QModelIndex &
index)
const {
538 if (!
index.isValid())
540 if (painter->device() ==
nullptr)
545 QString entry_type =
index.model()->data(
index, Qt::DisplayRole).toString();
547 if (entry_type ==
"protected")
550 icon = Icons::getIcon(
"mdi.trash-can");
553 QRect buttonRect(option.rect);
554 int min_val = buttonRect.width() < buttonRect.height() ? buttonRect.width() : buttonRect.height();
556 buttonRect.setWidth(min_val);
557 buttonRect.setHeight(min_val);
558 buttonRect.moveCenter(option.rect.center());
561 QStyleOptionButton button;
562 button.rect = buttonRect;
564 int icon_size = (int)(min_val * .8);
565 button.iconSize = QSize(icon_size, icon_size);
566 button.state = QStyle::State_Enabled;
568 QApplication::style()->drawControl(QStyle::CE_PushButton, &button, painter);
591 const QStyleOptionViewItem & ,
592 const QModelIndex &
index) {
594 if (event->type() == QEvent::MouseButtonPress) {
595 QString entry =
index.model()->data(
index, Qt::DisplayRole).toString();
596 if (entry ==
"protected")
598 QString action =
"delete";
612 const std::string error_msg =
"Unable to open \"" + link.toStdString() +
"\". Reason: ";
617 const QUrl url = QUrl::fromLocalFile(link);
618 if (!url.isValid()) {
619 g_log.
error() << error_msg <<
"Invalid (malformed) URL.\n";
625 g_log.
error() << error_msg <<
"Could not find directory.\n";
double value
The value of the point.
std::map< DeltaEMode::Type, std::string > index
static void showPage(const std::string &url=std::string())
static bool openUrl(const QUrl &url)
Opens a url in the appropriate web browser.
RepoModel : Wrapper for ScriptRepository to fit the Model View Qt Framework.
static const QString & localChangedSt()
QString filePath(const QModelIndex &index)
Return the operative system file path if it exists.
Mantid::API::ScriptRepository_sptr getRepoPtr()
QString author(const QModelIndex &index)
static const QString & remoteChangedSt()
static const QString & updatedSt()
static const QString & uploadSt()
static const QString & bothChangedSt()
QVariant data(const QModelIndex &index, int role) const override
access to the ScriptRepository data
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
change data
QString fileDescription(const QModelIndex &index)
Return the description of the file for a defined entry.
static const QString & localOnlySt()
static const QString & downloadSt()
static const QString & remoteOnlySt()
Delegate to show the checkbox for configuring the auto update.
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override
Reacts to the iteraction with the user when he clicks on the buttons displayed at paint.
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Draws the column 2 (AutoUpdate) of ScriptRepositoryView.
CheckBoxDelegate(QObject *parent=nullptr)
Delegate to show the icon to remove the entry from the local and central repository.
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Draws the column 3 (delete) of ScriptRepositoryView.
RemoveEntryDelegate(QObject *parent=nullptr)
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override
Reacts to the iteraction with the user when he clicks on the buttons displayed at paint.
Delegate to show the icons Download and Upload.
RepoDelegate(QObject *parent=nullptr)
QIcon getIcon(const QString &state) const
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override
Reacts to the iteraction with the user when he clicks on the buttons displayed at paint.
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Draws the column 1 (Status) of ScriptRepositoryView.
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
Provides the ideal size for this column.
ScriptRepositoryView : Provide the User Interface to the ScriptRepository.
~ScriptRepositoryView() override
Destructor.
ScriptRepositoryView(QWidget *parent=nullptr)
Creates the widget for the ScriptRepositoryView.
bool chooseLocationAndInstall(Mantid::API::ScriptRepository_sptr repo_ptr)
Prompt the user with where to install the script repository, and install it.
void openFolderLink(const QString &)
Attempt to open the given folder link using an appropriate application.
void helpClicked()
Open the ScriptRepository Page on Web Browser.
Ui::ScriptRepositoryView * ui
void loadScript(const QString)
void currentChanged(const QModelIndex ¤t)
This method will be executed every time the user change the selection.
void updateModel()
This method refreshes the ScriptRepository and allows it to check list the files again.
void cell_activated(const QModelIndex &)
Allows the user to open a file to investigate it.
void updateLocationString(const std::string &installDir)
The ScriptRepository class is intended to be used mainly by the users, who will be willing to share a...
const char * what() const noexcept override
Returns the message string.
const std::string & systemError() const
Returns the error description with technical details on the origin and cause.
The ConfigService class provides a simple facade to access the Configuration functionality of the Man...
The Logger class is in charge of the publishing messages from the framework through various channels.
void error(const std::string &msg)
Logs at error level.
void warning(const std::string &msg)
Logs at warning level.
void information(const std::string &msg)
Logs at information level.
const QString installation_in_progress
const QString install_mantid_label
const QString dir_not_empty_label
const QString installation_failed
std::shared_ptr< ScriptRepository > ScriptRepository_sptr
shared pointer to the function base class
Mantid::Kernel::SingletonHolder< ScriptRepositoryFactoryImpl > ScriptRepositoryFactory
Kernel::Logger g_log("DetermineSpinStateOrder")
Mantid::Kernel::SingletonHolder< ConfigServiceImpl > ConfigService