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> * Get <span style=\" font-weight:600;\">Mantid</span> Scripts from "
37 "the mantid developers and the community;</p>"
38 "<p> * Keep those scripts up to date automatically. </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 will be listed as part of the "
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>"
104 if (!repo_ptr->isValid()) {
115 g_log.
warning() <<
"ScriptRepository installation: " << ex.
what() <<
'\n';
116 g_log.
information() <<
"ScriptRepository installation failed with this information: " << ex.
systemError() <<
'\n';
117 QMessageBox::warning(
this,
"Installation Failed", QString(ex.
what()));
122 g_log.
error() <<
"Unknown error occurred to install ScriptRepository. It "
123 "will not be shown.\n";
131 connect(
ui->reloadPushButton, SIGNAL(clicked()),
this, SLOT(
updateModel()));
132 connect(
ui->pbHelp, SIGNAL(clicked()),
this, SLOT(
helpClicked()));
133 connect(
model, SIGNAL(executingThread(
bool)),
ui->reloadPushButton, SLOT(setDisabled(
bool)));
136 ui->repo_treeView->setModel(
model);
137 ui->repo_treeView->setItemDelegateForColumn(1,
new RepoDelegate(
this));
139 ui->repo_treeView->setColumnWidth(0, 290);
142 connect(
ui->repo_treeView, SIGNAL(activated(
const QModelIndex &)),
this, SLOT(
cell_activated(
const QModelIndex &)));
143 connect(
ui->repo_treeView, SIGNAL(currentCell(
const QModelIndex &)),
this, SLOT(
currentChanged(
const QModelIndex &)));
144 const ConfigServiceImpl &config = ConfigService::Instance();
146 connect(
ui->folderPathLabel, SIGNAL(linkActivated(QString)),
this, SLOT(
openFolderLink(QString)));
158 enum EXC_OPTIONS { NOTWANTED, NODIRECTORY };
163 if (QMessageBox::Ok != QMessageBox::question(
this,
"Install Script Repository?",
install_mantid_label,
164 QMessageBox::Ok | QMessageBox::Cancel)) {
168 const ConfigServiceImpl &config = ConfigService::Instance();
169 QString loc = QString::fromStdString(config.getString(
"ScriptLocalRepository"));
171 bool sureAboutDir =
false;
173 while (!sureAboutDir) {
174 dir = QFileDialog::getExistingDirectory(
this, tr(
"Where do you want to install Script Repository?"), loc,
175 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
183 if (0 == QDir(dir).entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot).
count()) {
189 QMessageBox::StandardButton sel =
190 QMessageBox::question(
this,
"Are you sure you want to install the Script Repository here?",
192 if (QMessageBox::Yes == sel)
196 }
catch (EXC_OPTIONS &ex) {
197 if (ex == NODIRECTORY) {
199 QMessageBox::warning(
this,
"Installation Failed",
"Invalid Folder to install Script Repository!\n");
207 repo_ptr->install(dir.toStdString());
209 g_log.
information() <<
"ScriptRepository installed at " << dir.toStdString() <<
'\n';
214 const QString loc = QString::fromStdString(installDir);
215 const QString loc_info =
"<html><head/><body><p><a href=\"%1\"><span style=\" "
216 "text-decoration: underline; "
217 "color:#0000ff;\">%2</span></a></p></body></html>";
222 path_label = QString(
"%1...%2").arg(loc.left(20)).arg(loc.right(27));
225 ui->folderPathLabel->setText(loc_info.arg(loc).arg(path_label));
226 ui->folderPathLabel->setToolTip(QString(
"Click here to open Script Repository Folder: %1.").arg(loc));
239 if (!model_repo_ptr->isValid()) {
246 connect(
model, SIGNAL(executingThread(
bool)),
ui->reloadPushButton, SLOT(setDisabled(
bool)));
247 ui->repo_treeView->setModel(
model);
264 RepoModel *_model = qobject_cast<RepoModel *>(
ui->repo_treeView->model());
266 QString path = _model->
filePath(in);
267 if (path.isEmpty()) {
282 RepoModel *_model = qobject_cast<RepoModel *>(
ui->repo_treeView->model());
287 ui->desc_textBrowser->setText(description);
288 QString author_name = _model->
author(in);
289 if (author_name.isEmpty())
290 ui->authorNameLabel->setText(
"");
292 ui->authorNameLabel->setText(QString(
"<b>Author:</b> ") + author_name);
331 const QModelIndex &
index)
const {
333 if (!
index.isValid())
335 if (painter->device() ==
nullptr)
339 QString state =
index.model()->data(
index, Qt::DisplayRole).toString();
340 auto icon = getIcon(state);
346 QRect iconRect(option.rect);
347 int min_val = iconRect.width() < iconRect.height() ? iconRect.width() : iconRect.height();
349 iconRect.setWidth(min_val);
350 iconRect.setHeight(min_val);
351 iconRect.moveCenter(option.rect.center());
353 int icon_size = (int)(min_val * .8);
358 icon.paint(painter, iconRect, Qt::AlignCenter);
363 QStyleOptionButton button;
364 button.rect = iconRect;
366 button.iconSize = QSize(icon_size, icon_size);
367 button.state = QStyle::State_Enabled;
369 QApplication::style()->drawControl(QStyle::CE_PushButton, &button, painter);
375 icon = Icons::getIcon(
"mdi.download");
377 icon = Icons::getIcon(
"mdi.transfer-down");
379 icon = Icons::getIcon(
"mdi.check-bold");
381 icon = Icons::getIcon(
"mdi.progress-download");
383 icon = Icons::getIcon(
"mdi.pencil");
412 const QStyleOptionViewItem & ,
413 const QModelIndex &
index) {
415 if (event->type() == QEvent::MouseButtonPress) {
430 const QModelIndex & )
const {
431 return QSize(35, 35);
461 const QModelIndex &
index)
const {
462 if (!
index.isValid())
464 if (painter->device() ==
nullptr)
467 QStyleOptionViewItem modifiedOption(option);
469 QPoint p = modifiedOption.rect.center();
470 QSize curr = modifiedOption.rect.size();
471 int min_value = (int)((curr.width() < curr.height()) ? curr.width() : curr.height() * .8);
473 modifiedOption.rect.setSize(QSize(min_value, min_value));
474 modifiedOption.rect.moveCenter(p);
476 QString state =
index.model()->data(
index, Qt::DisplayRole).toString();
479 modifiedOption.state |= QStyle::State_On;
480 else if (state ==
"false")
481 modifiedOption.state |= QStyle::State_Off;
485 QApplication::style()->drawPrimitive(QStyle::PE_IndicatorItemViewItemCheck, &modifiedOption, painter);
511 const QStyleOptionViewItem & ,
512 const QModelIndex &
index) {
513 if (event->type() == QEvent::MouseButtonPress) {
515 QString action =
"setFalse";
516 if (
value ==
"false")
531 const std::string error_msg =
"Unable to open \"" + link.toStdString() +
"\". Reason: ";
536 const QUrl url = QUrl::fromLocalFile(link);
537 if (!url.isValid()) {
538 g_log.
error() << error_msg <<
"Invalid (malformed) URL.\n";
544 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 & 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 Download icons.
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 users, who will want to share and downloa...
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 ScriptRepository base class
Mantid::Kernel::SingletonHolder< ScriptRepositoryFactoryImpl > ScriptRepositoryFactory
Kernel::Logger g_log("DetermineSpinStateOrder")
Mantid::Kernel::SingletonHolder< ConfigServiceImpl > ConfigService