15#include "MantidQtIcons/Icon.h"
20#include <QtConcurrentRun>
41 QString info = QString::fromStdString(ex.
what());
43 info.replace(
"\n",
"</p><p>");
59 : m_label(
std::move(label)), keypath(
std::move(path)), parentItem(parent) {}
89 return static_cast<int>(parentItem->childItems.indexOf(
const_cast<RepoItem *
>(
this)));
110 repo_ptr = ScriptRepositoryFactory::Instance().create(
"ScriptRepositoryImpl");
155 if (!
index.isValid())
157 const auto *item =
static_cast<RepoItem *
>(
index.internalPointer());
159 const QString &path = item->
path();
163 if (role == Qt::DisplayRole) {
164 switch (
index.column()) {
166 return item->label();
171 status =
repo_ptr->fileStatus(path.toStdString());
175 status =
repo_ptr->fileStatus(path.toStdString());
176 if (status == REMOTE_ONLY || status == LOCAL_ONLY)
178 inf =
repo_ptr->fileInfo(path.toStdString());
179 return inf.
auto_update ? QString(
"true") : QString(
"false");
185 if (role == Qt::DecorationRole) {
186 if (
index.column() == 0) {
187 inf =
repo_ptr->fileInfo(path.toStdString());
189 status =
repo_ptr->fileStatus(path.toStdString());
191 return Icons::getIcon(
"mdi.folder-network-outline",
"black", 1.2);
193 return Icons::getIcon(
"mdi.folder-open-outline",
"black", 1.2);
195 int pos =
static_cast<int>(QString(path).lastIndexOf(
'.'));
197 return Icons::getIcon(
"mdi.file-question",
"black", 1.2);
198 if (path.contains(
"readme", Qt::CaseInsensitive))
199 return Icons::getIcon(
"mdi.file-document-outline",
"black", 1.2);
201 QString extension = QString(path).remove(0, pos);
202 if (extension ==
".py" || extension ==
".PY")
203 return Icons::getIcon(
"mdi.language-python",
"black", 1.2);
204 else if (extension ==
".ui")
205 return Icons::getIcon(
"mdi.file-document-box-outline",
"black", 1.2);
206 else if (extension ==
".docx" || extension ==
".doc" || extension ==
".odf")
207 return Icons::getIcon(
"mdi.file-outline",
"black", 1.2);
208 else if (extension ==
".pdf")
209 return Icons::getIcon(
"mdi.file-pdf-outline",
"black", 1.2);
211 return Icons::getIcon(
"mdi.file-question",
"black", 1.2);
217 if (role == Qt::ToolTipRole) {
218 if (
index.column() == 1) {
220 return "Downloading... Be patient.";
221 status =
repo_ptr->fileStatus(path.toStdString());
222 inf =
repo_ptr->fileInfo(path.toStdString());
226 return (inf.
directory) ?
"Click here to download this folder and all its files"
227 :
"Click here to download this file";
230 return (inf.
directory) ?
"This folder is up-to-date" :
"This file is up-to-date";
233 return "This file has been modified locally";
235 return (inf.
directory) ?
"There is a new version of the files inside "
236 "this folder. Click here to install them."
237 :
"There is a new version of this file "
238 "available. Click here to install it.";
240 return (inf.
directory) ?
"Files in this folder may have changed both locally and "
241 "remotely.\nClick here to install the remote version, "
242 "a backup of the local version will also be created."
243 :
"This file may have changed both locally and "
244 "remotely.\nClick here to install the remote version, "
245 "a backup of the local version will also be created.";
248 return "This file only exists in your local folder";
250 }
else if (
index.column() == 2) {
251 return "Enable or disable this item to be downloaded automatically "
252 "when new versions will be available";
303 if (!
index.isValid())
305 if (role != Qt::EditRole)
308 if (
index.column() == 0)
311 int count_changed = 0;
312 const auto *item =
static_cast<RepoItem *
>(
index.internalPointer());
313 std::string path = item->
path().toStdString();
317 QString action =
value.toString();
318 if (
index.column() == 2) {
320 if (action ==
"setTrue")
322 else if (action ==
"setFalse")
327 count_changed =
repo_ptr->setAutoUpdate(path, option);
331 if (
index.column() == 1) {
332 if (action ==
"Download") {
334 QWidget *father = qobject_cast<QWidget *>(QObject::parent());
335 QMessageBox::information(father,
"Wait",
"Downloading... ");
365 if (!
index.isValid())
367 if (
index.column() == 0)
368 return QAbstractItemModel::flags(
index);
370 return QAbstractItemModel::flags(
index) | Qt::ItemIsEditable;
387 if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
420 if (!hasIndex(row, column,
parent))
421 return QModelIndex();
433 return createIndex(row, column, childItem);
435 return QModelIndex();
444 if (!
index.isValid())
445 return QModelIndex();
447 auto *childItem =
static_cast<RepoItem *
>(
index.internalPointer());
452 return QModelIndex();
454 return createIndex(parentItem->
row(), 0, parentItem);
487 const auto *item =
static_cast<RepoItem *
>(
index.internalPointer());
492 desc = QString::fromStdString(
repo_ptr->description(item->path().toStdString()));
500 const auto *item =
static_cast<RepoItem *
>(
index.internalPointer());
501 QString
author =
"Not defined";
505 author = QString::fromStdString(
repo_ptr->info(item->path().toStdString()).author);
517 const auto *item =
static_cast<RepoItem *
>(
index.internalPointer());
526 QString path =
repo_path +
"/" + item->path();
552 if (parents.last()->path() == folder)
553 return parents.last();
556 if (folder.isEmpty())
557 return parents.first();
561 QStringList folder_parts = folder.split(
"/");
566 bool try_to_find =
true;
568 for (
int i = 0; i < folder_parts.size(); i++) {
570 aux_folder = folder_parts[i];
572 aux_folder +=
"/" + folder_parts[i];
578 const auto it = std::find_if(parents.cbegin(), parents.cend(),
579 [&aux_folder](
const auto &
parent) { return parent->path() == aux_folder; });
580 if (it != parents.cend()) {
613 std::vector<std::string> list =
repo_ptr->listFiles();
621 for (
const auto &number : list) {
623 QString lineData = QString::fromStdString(number);
626 QStringList pathStrings = lineData.split(
"/");
628 QString current_file = pathStrings.last();
630 pathStrings.removeLast();
631 if (pathStrings.size() > 0)
632 folder = pathStrings.join(
"/");
637 if (parentOfFolder == root) {
645 if (
repo_ptr->info(lineData.toStdString()).directory) {
658 bool showWarning)
const {
662 QWidget *father = qobject_cast<QWidget *>(QObject::parent());
663 QString info = QString::fromStdString(ex.
what());
665 info.replace(
"\n",
"</p><p>");
666 QMessageBox::warning(father, title, QString(
"<html><body><p>%1</p></body></html>").arg(info));
672 if (!info.isEmpty()) {
673 QMessageBox::warning(qobject_cast<QWidget *>(QObject::parent()),
"Download Failed",
674 QString(
"<html><body><p>%1</p></body></html>").arg(info));
678 QModelIndex top_left = createIndex(0, 0, repo_item);
679 QModelIndex bottom_right = createIndex(0, 2, repo_item);
680 emit dataChanged(top_left, bottom_right);
685 const auto *item =
static_cast<RepoItem *
>(
index.internalPointer());
double value
The value of the point.
std::map< DeltaEMode::Type, std::string > index
static QString download_thread(Mantid::API::ScriptRepository_sptr &pt, const std::string &path)
Executes the download from ScriptRepository.
A nested class to help RepoModel to implement the QAbstractItemModel.
RepoItem * parent() const
access to the parent of this entry
void appendChild(RepoItem *child)
This method is the very responsible to allow the reconstruction of the hierarchical tree,...
int row() const
To which row this repoItem belongs?
RepoItem(QString label, QString path="/", RepoItem *parent=nullptr)
int childCount() const
Return the number of children that this entry may find.
const QString & path() const
access to the script repository path
RepoItem * child(int row) const
Gives access to the row_th children of RepoItem.
~RepoItem()
destruct all the childItems.
RepoModel(QObject *parent=nullptr)
constructor
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Count how many file/folders are direct children of the given folder, through the abstraction of QMode...
Qt::ItemFlags flags(const QModelIndex &index) const override
information on the available interaction
static const QString & localChangedSt()
Mantid::API::ScriptRepository_sptr repo_ptr
pointer to the ScriptRepository
QString filePath(const QModelIndex &index)
Return the operative system file path if it exists.
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
header strings
QModelIndex download_index
QFutureWatcher< QString > download_watcher
void executingThread(bool)
QString author(const QModelIndex &index)
bool isDownloading(const QModelIndex &index) const
static const QString & remoteChangedSt()
QString repo_path
ScriptLocalRepository path, to be able to retrieve the absolute path.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
provide the number of the columns
const QString & fromStatus(Mantid::API::SCRIPTSTATUS status) const
auxiliary method to match the ScriptStatus to string
static const QString & updatedSt()
static const QString & bothChangedSt()
RepoItem * rootItem
pointer to the RepoItem root
RepoItem * getParent(const QString &folder, QList< RepoItem * > &parents)
auxiliary method to help populating the model
QVariant data(const QModelIndex &index, int role) const override
access to the ScriptRepository data
void handleExceptions(const Mantid::API::ScriptRepoException &ex, const QString &title, bool showWarning=true) const
auxiliary method to deal with exceptions
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
change data
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
access to the index
QFuture< QString > download_threads
QModelIndex parent(const QModelIndex &index) const override
access to parent
QString fileDescription(const QModelIndex &index)
Return the description of the file for a defined entry.
static const QString & localOnlySt()
void setupModelData(RepoItem *parent)
auxiliary method to populate the model
static const QString & downloadSt()
static const QString & remoteOnlySt()
~RepoModel() override
destructor
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...
std::string getString(const std::string &keyName, bool pathAbsolute=true) const
Searches for a configuration property.
The Logger class is in charge of the publishing messages from the framework through various channels.
void information(const std::string &msg)
Logs at information level.
const QString LOCALCHANGED
const QString REMOTECHANGED
const QString BOTHUNCHANGED
const QString BOTHCHANGED
std::shared_ptr< ScriptRepository > ScriptRepository_sptr
shared pointer to the ScriptRepository base class
Mantid::Kernel::SingletonHolder< ScriptRepositoryFactoryImpl > ScriptRepositoryFactory
SCRIPTSTATUS
Represent the possible states for a given file:
Kernel::Logger g_log("DetermineSpinStateOrder")
Mantid::Kernel::SingletonHolder< ConfigServiceImpl > ConfigService
Information about the files inside the repository.
bool auto_update
Whether the file is marked for auto-update.
bool directory
Flag to indicate whether the entry is a directory.