Commit a7659a8f by Belákovics Ádám

added error handling and basic config options

parent 56e78d3b
...@@ -101,8 +101,8 @@ void MainWindow::loadVMData(std::string id){ ...@@ -101,8 +101,8 @@ 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();
...@@ -114,6 +114,28 @@ void MainWindow::on_bLogin_clicked() ...@@ -114,6 +114,28 @@ void MainWindow::on_bLogin_clicked()
ui->tabWidget->setTabEnabled(2, true); ui->tabWidget->setTabEnabled(2, true);
loadAllData(); loadAllData();
ui->tabWidget->setCurrentIndex(1); 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 /// Tab 1 - Virtual Machines
...@@ -133,6 +155,7 @@ void MainWindow::renewClicked(std::string id){ ...@@ -133,6 +155,7 @@ void MainWindow::renewClicked(std::string id){
* \param id * \param id
*/ */
void MainWindow::startshutdownClicked(std::string id){ void MainWindow::startshutdownClicked(std::string id){
try{
std::string state = myController.getState(id); std::string state = myController.getState(id);
if(state == "inactive"){ if(state == "inactive"){
myController.startByID(id); myController.startByID(id);
...@@ -143,6 +166,10 @@ void MainWindow::startshutdownClicked(std::string id){ ...@@ -143,6 +166,10 @@ void MainWindow::startshutdownClicked(std::string id){
emit stateChanged(myController.getState(id), id); emit stateChanged(myController.getState(id), id);
loadVMData(id); loadVMData(id);
ui->listWidget->item(std::stoi(id))->setSelected(true); ui->listWidget->item(std::stoi(id))->setSelected(true);
}
catch(std::logic_error e){
showErrorMessage(e.what());
}
} }
/*! /*!
...@@ -150,6 +177,7 @@ void MainWindow::startshutdownClicked(std::string id){ ...@@ -150,6 +177,7 @@ void MainWindow::startshutdownClicked(std::string id){
* \param id * \param id
*/ */
void MainWindow::wakeupsleepClicked(std::string id){ void MainWindow::wakeupsleepClicked(std::string id){
try{
std::string state = myController.getState(id); std::string state = myController.getState(id);
if(state == "active"){ //sleep if(state == "active"){ //sleep
myController.sleepByID(id); myController.sleepByID(id);
...@@ -163,6 +191,17 @@ void MainWindow::wakeupsleepClicked(std::string id){ ...@@ -163,6 +191,17 @@ void MainWindow::wakeupsleepClicked(std::string id){
emit stateChanged(myController.getState(id), id); emit stateChanged(myController.getState(id), id);
loadVMData(id); loadVMData(id);
ui->listWidget->item(std::stoi(id))->setSelected(true); ui->listWidget->item(std::stoi(id))->setSelected(true);
}
catch(std::logic_error e){
showErrorMessage(e.what());
}
}
void MainWindow::showErrorMessage(std::string errorMsg){
QMessageBox msgBox;
msgBox.setWindowTitle("Error!");
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