Commit a7659a8f by Belákovics Ádám

added error handling and basic config options

parent 56e78d3b
......@@ -101,19 +101,41 @@ void MainWindow::loadVMData(std::string id){
* \brief Login Button handler, connects to server, if authentication is succesful enables all tabs, and loads all data
*/
void MainWindow::on_bLogin_clicked()
{
std::string serverUrl = ui->iCloudServer->text().toStdString();
myController.connect(serverUrl);
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;
{ try{
std::string serverUrl = parseConfig();//"https://vm.ik.bme.hu:9366/occi/";
myController.connect(serverUrl);
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);
loadAllData();
ui->tabWidget->setCurrentIndex(1);
}
ui->tabWidget->setTabEnabled(1, true);
ui->tabWidget->setTabEnabled(2, true);
loadAllData();
ui->tabWidget->setCurrentIndex(1);
catch(std::logic_error e){
QMessageBox msgBox;
msgBox.setText(e.what());
msgBox.exec();
}
}
std::string MainWindow::parseConfig(){
std::string line;
std::ifstream myfile ("config.txt");
if (myfile.is_open())
{
while ( getline (myfile,line) )
{
return line;
}
myfile.close();
}
else
throw std::logic_error("Unable to configure client. Please add a config.txt with the cloud server's url!");
return "";
}
/// Tab 1 - Virtual Machines
......@@ -133,16 +155,21 @@ void MainWindow::renewClicked(std::string id){
* \param id
*/
void MainWindow::startshutdownClicked(std::string id){
std::string state = myController.getState(id);
if(state == "inactive"){
myController.startByID(id);
try{
std::string state = myController.getState(id);
if(state == "inactive"){
myController.startByID(id);
}
else {
myController.shutdownByID(id);
}
emit stateChanged(myController.getState(id), id);
loadVMData(id);
ui->listWidget->item(std::stoi(id))->setSelected(true);
}
else {
myController.shutdownByID(id);
catch(std::logic_error e){
showErrorMessage(e.what());
}
emit stateChanged(myController.getState(id), id);
loadVMData(id);
ui->listWidget->item(std::stoi(id))->setSelected(true);
}
/*!
......@@ -150,19 +177,31 @@ void MainWindow::startshutdownClicked(std::string id){
* \param id
*/
void MainWindow::wakeupsleepClicked(std::string id){
std::string state = myController.getState(id);
if(state == "active"){ //sleep
myController.sleepByID(id);
try{
std::string state = myController.getState(id);
if(state == "active"){ //sleep
myController.sleepByID(id);
}
else if(state == "suspended" || state == "inactive"){ //wake up
myController.wakeupByID(id);
}
else{
throw std::runtime_error("undefined VM STATE!!!");
}
emit stateChanged(myController.getState(id), id);
loadVMData(id);
ui->listWidget->item(std::stoi(id))->setSelected(true);
}
else if(state == "suspended" || state == "inactive"){ //wake up
myController.wakeupByID(id);
catch(std::logic_error e){
showErrorMessage(e.what());
}
else{
throw std::runtime_error("undefined VM STATE!!!");
}
emit stateChanged(myController.getState(id), id);
loadVMData(id);
ui->listWidget->item(std::stoi(id))->setSelected(true);
}
void MainWindow::showErrorMessage(std::string errorMsg){
QMessageBox msgBox;
msgBox.setWindowTitle("Error!");
msgBox.setText(errorMsg.c_str());
msgBox.exec();
}
/*!
......
......@@ -10,6 +10,9 @@
#include "controller.h"
#include "vmchooserdialog.h"
#include <qtermwidget5/qtermwidget.h>
#include <iostream>
#include <fstream>
#include <string>
namespace Ui {
class MainWindow;
......@@ -25,6 +28,8 @@ public:
void addVM(std::string id, std::string name);
void loadAllData();
void loadVMData(std::string id);
std::string parseConfig();
void showErrorMessage(std::string errorMsg);
signals:
void stateChanged(std::string state, std::string id);
......
......@@ -95,7 +95,7 @@
<enum>QTabWidget::Rounded</enum>
</property>
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<property name="iconSize">
<size>
......@@ -108,7 +108,7 @@
<string>Welcome</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_4">
<item row="10" column="1">
<item row="8" column="1">
<widget class="QPushButton" name="bLogin">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Log in&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
......@@ -121,7 +121,7 @@
</property>
</widget>
</item>
<item row="9" column="1">
<item row="7" column="1">
<widget class="QLineEdit" name="iPassword">
<property name="palette">
<palette>
......@@ -171,7 +171,7 @@
</property>
</widget>
</item>
<item row="3" column="2" rowspan="10">
<item row="3" column="2" rowspan="8">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
......@@ -187,7 +187,7 @@
</property>
</spacer>
</item>
<item row="3" column="0" rowspan="10">
<item row="3" column="0" rowspan="8">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
......@@ -203,7 +203,7 @@
</property>
</spacer>
</item>
<item row="12" column="1">
<item row="10" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
......@@ -219,14 +219,14 @@
</property>
</spacer>
</item>
<item row="8" column="1">
<item row="6" column="1">
<widget class="QLabel" name="lPassword">
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item row="7" column="1">
<item row="5" column="1">
<widget class="QLineEdit" name="iUsername">
<property name="palette">
<palette>
......@@ -283,7 +283,7 @@
</property>
</spacer>
</item>
<item row="6" column="1">
<item row="4" column="1">
<widget class="QLabel" name="lUsername">
<property name="text">
<string>Username</string>
......@@ -313,7 +313,7 @@
</property>
</widget>
</item>
<item row="11" column="1">
<item row="9" column="1">
<widget class="QLabel" name="lInfo">
<property name="palette">
<palette>
......@@ -360,57 +360,6 @@
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="lCloudServer">
<property name="text">
<string>Cloud Server:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLineEdit" name="iCloudServer">
<property name="palette">
<palette>
<active>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>240</red>
<green>240</green>
<blue>240</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
<property name="text">
<string>https://vm.ik.bme.hu:9366/occi/</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tVM">
......
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