Skip to content

Commit

Permalink
Add support for Upload from the User Interaction point of view
Browse files Browse the repository at this point in the history
  • Loading branch information
gesnerpassos committed Apr 17, 2013
1 parent c225ed5 commit 84d6068
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 7 deletions.
24 changes: 23 additions & 1 deletion Code/Mantid/MantidQt/API/inc/MantidQtAPI/RepoModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
#include <QVariant>
#include <QStringList>
#include <QWidget>
#include <QDialog>
#include "MantidAPI/ScriptRepository.h"
class QLineEdit;
class QCheckBox;
class QTextEdit;

namespace MantidQt
{
Expand Down Expand Up @@ -121,9 +125,27 @@ const QString BOTHCHANGED = "CHANGED";
private:
RepoItem( const RepoItem& );
const RepoItem& operator=( const RepoItem& );
};

class UploadForm: public QDialog{
public:
UploadForm(const QString & file2upload, QWidget * parent = 0);
virtual ~UploadForm();
QString email();
QString author();
QString comment();
bool saveInfo();
void setEmail(const QString& );
void setAuthor(const QString&);
void lastSaveOption(bool option);

protected:
QLineEdit * author_le;
QLineEdit * email_le;
QCheckBox * save_ck;
QTextEdit * comment_te;
};

};

public:
/// constructor
Expand Down
100 changes: 94 additions & 6 deletions Code/Mantid/MantidQt/API/src/RepoModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ using Mantid::Kernel::ConfigServiceImpl;
using Mantid::Kernel::ConfigService;
#include <QDebug>
#include <stdexcept>
#include <QCheckBox>
#include <QLineEdit>
#include <QVBoxLayout>
#include <QFormLayout>
#include <QGroupBox>
#include <QDialogButtonBox>


/*
An auxiliary nested class to help RepoModel to rebuild the hierarchical
Expand Down Expand Up @@ -296,12 +303,33 @@ bool RepoModel::setData(const QModelIndex & index, const QVariant & value,
repo_ptr->download(path); // FIXME: deal with exceptions
ret = true;
}else if (action == "Upload"){
// implement upload
// attempt to set as parent the QView, to better display it.
QWidget * father = qobject_cast<QWidget*>(QObject::parent());
QMessageBox::information(father,
"Upload",
QString::fromStdString(path));
QWidget * father = qobject_cast<QWidget*>(QObject::parent());
UploadForm * form = new UploadForm(QString::fromStdString(path), father);
QSettings settings;
settings.beginGroup("Mantid/ScriptRepository");
QString email = settings.value("UploadEmail",QString()).toString();
QString author = settings.value("UploadAuthor",QString()).toString();
bool lastChk = settings.value("UploadSaveInfo",false).toBool();
if (!email.isEmpty())
form->setEmail(email);
if (!author.isEmpty())
form->setAuthor(author);
form->lastSaveOption(lastChk);
if (form->exec()){
settings.setValue("UploadEmail",form->saveInfo()?form->email():"");
settings.setValue("UploadAuthor",form->saveInfo()?form->author():"");
settings.setValue("UploadSaveInfo",form->saveInfo());

qWarning() << "Uploading... "<< QString::fromStdString(path) << form->comment()
<< form->author() << form->email() << endl;
repo_ptr->upload(path, form->comment().toStdString(),
form->author().toStdString(),
form->email().toStdString());
}else{
qWarning() << "Not uploading" << endl;
}
settings.endGroup();
delete form;
ret = true;
}

Expand Down Expand Up @@ -619,3 +647,63 @@ const QString & RepoModel::remoteChangedSt(){return REMOTECHANGED;};
const QString & RepoModel::updatedSt(){return BOTHUNCHANGED;};
/// @return string to define the BOTH_CHANGED state
const QString & RepoModel::bothChangedSt(){return BOTHCHANGED;};


RepoModel::UploadForm::UploadForm( const QString & file2upload,
QWidget * parent): QDialog(parent){
author_le = new QLineEdit();
email_le = new QLineEdit();
save_ck = new QCheckBox("Save your personal information");
save_ck->setToolTip("The author and email will be saved and will be written to you next time");
comment_te = new QTextEdit();

// setup the layout

QGroupBox * personalGroupBox = new QGroupBox("Personal Group Box");
QFormLayout * personalLayout = new QFormLayout();
personalLayout->addRow("Author",author_le);
personalLayout->addRow("Email",email_le);
QVBoxLayout * gpBox = new QVBoxLayout();
gpBox->addWidget(save_ck);
gpBox->addLayout(personalLayout);
personalGroupBox->setLayout(gpBox);

QLabel * cmLabel = new QLabel("Comment");
QDialogButtonBox * buttonBox = new QDialogButtonBox();
buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);

QVBoxLayout * layout = new QVBoxLayout();
layout->addWidget(personalGroupBox);
layout->addWidget(cmLabel);
layout->addWidget(comment_te);
layout->addWidget(buttonBox);
setLayout(layout);

setWindowTitle(QString("Upload - %2").arg(file2upload));
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
}
RepoModel::UploadForm::~UploadForm(){

}
QString RepoModel::UploadForm::email(){
return email_le->text();
}
QString RepoModel::UploadForm::author(){
return author_le->text();
}
QString RepoModel::UploadForm::comment(){
return comment_te->text();
}
bool RepoModel::UploadForm::saveInfo(){
return save_ck->isChecked();
}
void RepoModel::UploadForm::setEmail(const QString & email){
email_le->setText(email);
}
void RepoModel::UploadForm::setAuthor(const QString & author){
author_le->setText(author);
}
void RepoModel::UploadForm::lastSaveOption(bool option){
save_ck->setCheckState(option?Qt::Checked:Qt::Unchecked);
}

0 comments on commit 84d6068

Please sign in to comment.