Commit a354a4a4 by Belákovics Ádám

Replace mainwindow.cpp

parent 48592d0a
......@@ -6,9 +6,94 @@ MainWindow::MainWindow(QWidget *parent) :
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->tabWidget->setTabEnabled(1, false);
ui->tabWidget->setTabEnabled(2, false);
myController.connect();
}
void MainWindow::addVM(std::string id, std::string name){
QListWidgetItem* item = new QListWidgetItem(ui->listWidget);
ComputeWidget* cw = new ComputeWidget();
cw->setID(id);
cw->setName(name);
connect(cw, SIGNAL(renew(std::string)), this, SLOT(renewClicked(std::string)));
connect(cw, SIGNAL(start(std::string)), this, SLOT(startClicked(std::string)));
connect(cw, SIGNAL(wakeup(std::string)), this, SLOT(wakeupClicked(std::string)));
connect(cw, SIGNAL(sleep(std::string)), this, SLOT(sleepClicked(std::string)));
item->setSizeHint(cw->minimumSize());
ui->listWidget->addItem(item);
ui->listWidget->setItemWidget(item, cw);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::loadData(){
VM_names = myController.getVMs();
ui->listWidget->clear();
for(size_t i = 0; i < VM_names.size(); i++)
addVM(std::to_string(i), VM_names.at(i));
for(auto t : getTemplates(myController.session))
ui->lwTemplates->addItem(t.c_str());
}
void MainWindow::on_bLogin_clicked()
{
std::string username = ui->iUsername->text().toStdString();
std::string password = ui->iPassword->text().toStdString();
if(!myController.login(username, password)){
ui->lInfo->setText("Invalid username or password...");
return;
}
ui->tabWidget->setTabEnabled(1, true);
ui->tabWidget->setTabEnabled(2, true);
loadData();
ui->tabWidget->setCurrentIndex(1);
}
void MainWindow::renewClicked(std::string id){
myController.renewByID(id);
}
void MainWindow::startClicked(std::string id){
myController.startByID(id);
}
void MainWindow::wakeupClicked(std::string id){
myController.wakeupByID(id);
}
void MainWindow::sleepClicked(std::string id){
myController.sleepByID(id);
}
void MainWindow::on_listWidget_clicked(const QModelIndex &index)
{
ui->lStatus->setText(myController.getState(std::to_string(index.row())).c_str());
ComputeData data = myController.getDataByID(std::to_string(index.row()).c_str());
ui->lCPU->setText(std::to_string(data.cpu).c_str());
ui->lMemory->setText(std::to_string(data.memory).c_str());
ui->lCores->setText(std::to_string(data.cores).c_str());
ui->lHostname->setText((data.hostname+":21231").c_str()); //TODO
ui->lUsername->setText(data.username.c_str());
ui->lPassword->setText(data.password.c_str());
}
void MainWindow::on_bRefresh_clicked()
{
myController.refresh();
loadData();
}
void MainWindow::receive_chosen_template(Template t){
myController.newCompute(t);
}
void MainWindow::on_bNewVM_clicked()
{
VMChooserDialog* v = new VMChooserDialog(this);
emit send_templates(getTemplates(myController.session));
connect(v, SIGNAL(send_chosen_template(Template)), this, SLOT(receive_chosen_template(Template)));
v->exec();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment