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){ ...@@ -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 * \brief Login Button handler, connects to server, if authentication is succesful enables all tabs, and loads all data
*/ */
void MainWindow::on_bLogin_clicked() void MainWindow::on_bLogin_clicked()
{ { try{
std::string serverUrl = ui->iCloudServer->text().toStdString(); std::string serverUrl = parseConfig();//"https://vm.ik.bme.hu:9366/occi/";
myController.connect(serverUrl); myController.connect(serverUrl);
std::string username = ui->iUsername->text().toStdString(); std::string username = ui->iUsername->text().toStdString();
std::string password = ui->iPassword->text().toStdString(); std::string password = ui->iPassword->text().toStdString();
if(!myController.login(username, password)){ if(!myController.login(username, password)){
ui->lInfo->setText("Invalid username or password..."); ui->lInfo->setText("Invalid username or password...");
return; return;
}
ui->tabWidget->setTabEnabled(1, true);
ui->tabWidget->setTabEnabled(2, true);
loadAllData();
ui->tabWidget->setCurrentIndex(1);
} }
ui->tabWidget->setTabEnabled(1, true); catch(std::logic_error e){
ui->tabWidget->setTabEnabled(2, true); QMessageBox msgBox;
loadAllData(); msgBox.setText(e.what());
ui->tabWidget->setCurrentIndex(1); 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 /// Tab 1 - Virtual Machines
...@@ -133,16 +155,21 @@ void MainWindow::renewClicked(std::string id){ ...@@ -133,16 +155,21 @@ void MainWindow::renewClicked(std::string id){
* \param id * \param id
*/ */
void MainWindow::startshutdownClicked(std::string id){ void MainWindow::startshutdownClicked(std::string id){
std::string state = myController.getState(id); try{
if(state == "inactive"){ std::string state = myController.getState(id);
myController.startByID(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 { catch(std::logic_error e){
myController.shutdownByID(id); 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){ ...@@ -150,19 +177,31 @@ void MainWindow::startshutdownClicked(std::string id){
* \param id * \param id
*/ */
void MainWindow::wakeupsleepClicked(std::string id){ void MainWindow::wakeupsleepClicked(std::string id){
std::string state = myController.getState(id); try{
if(state == "active"){ //sleep std::string state = myController.getState(id);
myController.sleepByID(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 catch(std::logic_error e){
myController.wakeupByID(id); showErrorMessage(e.what());
} }
else{ }
throw std::runtime_error("undefined VM STATE!!!");
} void MainWindow::showErrorMessage(std::string errorMsg){
emit stateChanged(myController.getState(id), id); QMessageBox msgBox;
loadVMData(id); msgBox.setWindowTitle("Error!");
ui->listWidget->item(std::stoi(id))->setSelected(true); msgBox.setText(errorMsg.c_str());
msgBox.exec();
} }
/*! /*!
......
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
#include "controller.h" #include "controller.h"
#include "vmchooserdialog.h" #include "vmchooserdialog.h"
#include <qtermwidget5/qtermwidget.h> #include <qtermwidget5/qtermwidget.h>
#include <iostream>
#include <fstream>
#include <string>
namespace Ui { namespace Ui {
class MainWindow; class MainWindow;
...@@ -25,6 +28,8 @@ public: ...@@ -25,6 +28,8 @@ public:
void addVM(std::string id, std::string name); void addVM(std::string id, std::string name);
void loadAllData(); void loadAllData();
void loadVMData(std::string id); void loadVMData(std::string id);
std::string parseConfig();
void showErrorMessage(std::string errorMsg);
signals: signals:
void stateChanged(std::string state, std::string id); void stateChanged(std::string state, std::string id);
......
...@@ -95,7 +95,7 @@ ...@@ -95,7 +95,7 @@
<enum>QTabWidget::Rounded</enum> <enum>QTabWidget::Rounded</enum>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>0</number>
</property> </property>
<property name="iconSize"> <property name="iconSize">
<size> <size>
...@@ -108,7 +108,7 @@ ...@@ -108,7 +108,7 @@
<string>Welcome</string> <string>Welcome</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_4"> <layout class="QGridLayout" name="gridLayout_4">
<item row="10" column="1"> <item row="8" column="1">
<widget class="QPushButton" name="bLogin"> <widget class="QPushButton" name="bLogin">
<property name="toolTip"> <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> <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 @@ ...@@ -121,7 +121,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="9" column="1"> <item row="7" column="1">
<widget class="QLineEdit" name="iPassword"> <widget class="QLineEdit" name="iPassword">
<property name="palette"> <property name="palette">
<palette> <palette>
...@@ -171,7 +171,7 @@ ...@@ -171,7 +171,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="2" rowspan="10"> <item row="3" column="2" rowspan="8">
<spacer name="horizontalSpacer_2"> <spacer name="horizontalSpacer_2">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
...@@ -187,7 +187,7 @@ ...@@ -187,7 +187,7 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="3" column="0" rowspan="10"> <item row="3" column="0" rowspan="8">
<spacer name="horizontalSpacer"> <spacer name="horizontalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
...@@ -203,7 +203,7 @@ ...@@ -203,7 +203,7 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="12" column="1"> <item row="10" column="1">
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
...@@ -219,14 +219,14 @@ ...@@ -219,14 +219,14 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="8" column="1"> <item row="6" column="1">
<widget class="QLabel" name="lPassword"> <widget class="QLabel" name="lPassword">
<property name="text"> <property name="text">
<string>Password</string> <string>Password</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="1"> <item row="5" column="1">
<widget class="QLineEdit" name="iUsername"> <widget class="QLineEdit" name="iUsername">
<property name="palette"> <property name="palette">
<palette> <palette>
...@@ -283,7 +283,7 @@ ...@@ -283,7 +283,7 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="6" column="1"> <item row="4" column="1">
<widget class="QLabel" name="lUsername"> <widget class="QLabel" name="lUsername">
<property name="text"> <property name="text">
<string>Username</string> <string>Username</string>
...@@ -313,7 +313,7 @@ ...@@ -313,7 +313,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="11" column="1"> <item row="9" column="1">
<widget class="QLabel" name="lInfo"> <widget class="QLabel" name="lInfo">
<property name="palette"> <property name="palette">
<palette> <palette>
...@@ -360,57 +360,6 @@ ...@@ -360,57 +360,6 @@
</property> </property>
</widget> </widget>
</item> </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> </layout>
</widget> </widget>
<widget class="QWidget" name="tVM"> <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