12#include "MantidQtIcons/Icon.h"
16#include <QCoreApplication>
33 "Script Repository</span> allows you to:</p>"
34 "<p> * Share your scripts and reduction algorithms;</p>"
35 "<p> * Get <span style=\" font-weight:600;\">Mantid</span> Scripts from "
36 "the mantid developers and the community. </p>"
37 "<p><span style=\" font-style:italic;\">"
38 "N.B. The installation usually requires a couple of minutes, depending on "
39 "your network bandwidth. </span></p>"
40 "<p>More Information available at "
41 "<a href=\"http://www.mantidproject.org/ScriptRepository\"><span style=\" "
42 "text-decoration: underline; color:#0000ff;\">"
43 "http://www.mantidproject.org/ScriptRepository</span></a></p></br><p><span "
44 "style=\" font-weight:600;\">"
45 "Would you like to install it now?</span></p></body></html>";
48 "Installing Script Repository Installation in background!</span></p>"
49 "<p>You may continue to use mantid.</p>"
50 "<p>The Result Log willl give you information of the installation "
52 "<p>When finished, please, reopen the <span style=\" "
53 "font-weight:600;\">Script Repository</span>. </p></body></html>";
56 "<span style=\" font-weight:600;\">Failed</span>!</p>"
57 "<p>Please, check the Result Log to see why the installation failed. "
60const QString
dir_not_empty_label =
"<html><head/><body><p>The directory/folder that you have selected is not "
62 "<p>Are you sure that you want to install the script repository here? All "
63 "the files and directories found in "
64 "the selected directory/folder could be shared in the repository by "
66 "<p>If you are not sure, please choose 'no' and then select an empty (or "
67 "newly created) directory/folder.</p>"
68 "<p>If this is your home directory, desktop or similar you should "
69 "definitely choose 'no'.</p>"
70 "<p>If you are sure of what you are doing, please choose 'yes'. The "
71 "installation may take a couple of minutes.</p>"
95 enum EXC_OPTIONS { NOTWANTED, NODIRECTORY };
103 if (!repo_ptr->isValid()) {
106 if (QMessageBox::Ok != QMessageBox::question(
this,
"Install Script Repository?",
install_mantid_label,
107 QMessageBox::Ok | QMessageBox::Cancel)) {
111 ConfigServiceImpl &config = ConfigService::Instance();
112 QString loc = QString::fromStdString(config.getString(
"ScriptLocalRepository"));
114 bool sureAboutDir =
false;
117 while (!sureAboutDir) {
118 dir = QFileDialog::getExistingDirectory(
this, tr(
"Where do you want to install Script Repository?"), loc,
119 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
127 if (0 == QDir(dir).entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot).
count()) {
133 QMessageBox::StandardButton sel =
134 QMessageBox::question(
this,
"Are you sure you want to install the Script Repository here?",
136 if (QMessageBox::Yes == sel)
142 repo_ptr->install(dir.toStdString());
143 g_log.
information() <<
"ScriptRepository installed at " << dir.toStdString() <<
'\n';
148 }
catch (EXC_OPTIONS &ex) {
149 if (ex == NODIRECTORY)
151 QMessageBox::warning(
this,
"Installation Failed",
"Invalid Folder to install Script Repository!\n");
158 g_log.
warning() <<
"ScriptRepository installation: " << ex.what() <<
'\n';
159 g_log.
information() <<
"ScriptRepository installation failed with this information: " << ex.systemError() <<
'\n';
160 QMessageBox::warning(
this,
"Installation Failed", QString(ex.what()));
165 g_log.
error() <<
"Unknown error occurred to install ScriptRepository. It "
166 "will not be shown.\n";
175 connect(
ui->reloadPushButton, SIGNAL(clicked()),
this, SLOT(
updateModel()));
176 connect(
ui->pbHelp, SIGNAL(clicked()),
this, SLOT(
helpClicked()));
177 connect(
model, SIGNAL(executingThread(
bool)),
ui->reloadPushButton, SLOT(setDisabled(
bool)));
180 ui->repo_treeView->setModel(
model);
181 ui->repo_treeView->setItemDelegateForColumn(1,
new RepoDelegate(
this));
184 ui->repo_treeView->setColumnWidth(0, 290);
187 connect(
ui->repo_treeView, SIGNAL(activated(
const QModelIndex &)),
this, SLOT(
cell_activated(
const QModelIndex &)));
188 connect(
ui->repo_treeView, SIGNAL(currentCell(
const QModelIndex &)),
this, SLOT(
currentChanged(
const QModelIndex &)));
190 const ConfigServiceImpl &config = ConfigService::Instance();
191 const QString loc = QString::fromStdString(config.getString(
"ScriptLocalRepository"));
192 const QString loc_info =
"<html><head/><body><p><a href=\"%1\"><span style=\" "
193 "text-decoration: underline; "
194 "color:#0000ff;\">%2</span></a></p></body></html>";
199 path_label = QString(
"%1...%2").arg(loc.left(20)).arg(loc.right(27));
202 ui->folderPathLabel->setText(loc_info.arg(loc).arg(path_label));
203 ui->folderPathLabel->setToolTip(QString(
"Click here to open Script Repository Folder: %1.").arg(loc));
204 connect(
ui->folderPathLabel, SIGNAL(linkActivated(QString)),
this, SLOT(
openFolderLink(QString)));
217 connect(
model, SIGNAL(executingThread(
bool)),
ui->reloadPushButton, SLOT(setDisabled(
bool)));
218 ui->repo_treeView->setModel(
model);
235 RepoModel *_model = qobject_cast<RepoModel *>(
ui->repo_treeView->model());
237 QString path = _model->
filePath(in);
238 if (path.isEmpty()) {
253 RepoModel *_model = qobject_cast<RepoModel *>(
ui->repo_treeView->model());
258 ui->desc_textBrowser->setText(description);
259 QString author_name = _model->
author(in);
260 if (author_name.isEmpty())
261 ui->authorNameLabel->setText(
"");
263 ui->authorNameLabel->setText(QString(
"<b>Author:</b> ") + author_name);
304 const QModelIndex &
index)
const {
306 if (!
index.isValid())
308 if (painter->device() ==
nullptr)
312 QString state =
index.model()->data(
index, Qt::DisplayRole).toString();
313 auto icon = getIcon(state);
316 QRect buttonRect(option.rect);
317 int min_val = buttonRect.width() < buttonRect.height() ? buttonRect.width() : buttonRect.height();
319 buttonRect.setWidth(min_val);
320 buttonRect.setHeight(min_val);
321 buttonRect.moveCenter(option.rect.center());
324 QStyleOptionButton button;
325 button.rect = buttonRect;
327 int icon_size = (int)(min_val * .8);
328 button.iconSize = QSize(icon_size, icon_size);
329 button.state = QStyle::State_Enabled;
331 QApplication::style()->drawControl(QStyle::CE_PushButton, &button, painter);
337 icon = Icons::getIcon(
"mdi.download");
339 icon = Icons::getIcon(
"mdi.transfer-down");
341 icon = Icons::getIcon(
"mdi.check-bold");
343 icon = Icons::getIcon(
"mdi.upload");
345 icon = Icons::getIcon(
"mdi.progress-download");
347 icon = Icons::getIcon(
"mdi.progress-upload");
374 const QStyleOptionViewItem & ,
375 const QModelIndex &
index) {
377 if (event->type() == QEvent::MouseButtonPress) {
379 QString action =
"Download";
394 const QModelIndex & )
const {
395 return QSize(35, 35);
425 const QModelIndex &
index)
const {
426 if (!
index.isValid())
428 if (painter->device() ==
nullptr)
431 QStyleOptionViewItem modifiedOption(option);
433 QPoint p = modifiedOption.rect.center();
434 QSize curr = modifiedOption.rect.size();
435 int min_value = (int)((curr.width() < curr.height()) ? curr.width() : curr.height() * .8);
437 modifiedOption.rect.setSize(QSize(min_value, min_value));
438 modifiedOption.rect.moveCenter(p);
440 QString state =
index.model()->data(
index, Qt::DisplayRole).toString();
443 modifiedOption.state |= QStyle::State_On;
444 else if (state ==
"false")
445 modifiedOption.state |= QStyle::State_Off;
449 QApplication::style()->drawPrimitive(QStyle::PE_IndicatorItemViewItemCheck, &modifiedOption, painter);
475 const QStyleOptionViewItem & ,
476 const QModelIndex &
index) {
477 if (event->type() == QEvent::MouseButtonPress) {
479 QString action =
"setFalse";
480 if (
value ==
"false")
507 const QModelIndex &
index)
const {
509 if (!
index.isValid())
511 if (painter->device() ==
nullptr)
516 QString entry_type =
index.model()->data(
index, Qt::DisplayRole).toString();
518 if (entry_type ==
"protected")
521 icon = Icons::getIcon(
"mdi.trash-can");
524 QRect buttonRect(option.rect);
525 int min_val = buttonRect.width() < buttonRect.height() ? buttonRect.width() : buttonRect.height();
527 buttonRect.setWidth(min_val);
528 buttonRect.setHeight(min_val);
529 buttonRect.moveCenter(option.rect.center());
532 QStyleOptionButton button;
533 button.rect = buttonRect;
535 int icon_size = (int)(min_val * .8);
536 button.iconSize = QSize(icon_size, icon_size);
537 button.state = QStyle::State_Enabled;
539 QApplication::style()->drawControl(QStyle::CE_PushButton, &button, painter);
562 const QStyleOptionViewItem & ,
563 const QModelIndex &
index) {
565 if (event->type() == QEvent::MouseButtonPress) {
566 QString entry =
index.model()->data(
index, Qt::DisplayRole).toString();
567 if (entry ==
"protected")
569 QString action =
"delete";
583 const std::string error_msg =
"Unable to open \"" + link.toStdString() +
"\". Reason: ";
588 const QUrl url = QUrl::fromLocalFile(link);
589 if (!url.isValid()) {
590 g_log.
error() << error_msg <<
"Invalid (malformed) URL.\n";
596 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 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.
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.
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.
The ScriptRepository class is intended to be used mainly by the users, who will be willing to share a...
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.
Manage the lifetime of a class intended to be a singleton.
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
Kernel::Logger g_log("ExperimentInfo")
static logger object