5 #include <QApplication>
9 #include <QTableWidget>
10 #include <QVBoxLayout>
13 #include <QTextStream>
22 #include <QDomDocument>
24 #include <QDomNodeList>
25 #include <QDomElement>
28 #include <QDomNamedNodeMap>
30 #include "vm_creation_wizard.h"
31 #include "vm_console_widget.h"
35 class VmXConsoleParent;
42 class NewPalacios: public QMainWindow {
46 NewPalacios(QWidget *parent = 0);
50 void closeEvent(QCloseEvent*);
53 void createVmInstance();
55 void exitApplication();
62 // Item click listener for tree items
63 void vmItemClickListener(QTreeWidgetItem*, int);
64 void finishLoadingVmsFromFile();
67 void deleteVm(QString);
68 void handleVmDeletion();
69 // Context menu for VMs
70 void vmContextMenu(const QPoint &p);
71 void consoleWindowClosed(QString);
72 void vmTabClosed(int);
73 // This slot will be triggered when play/menu start
74 // button is pressed. This will launch a dialog which
75 // will allow the user to select operating mode
77 // This slot will be triggered from the mode selection
78 // dialog when the user has finished selection.
79 void getVmMode(int, QString);
80 void updateTelemetry(bool);
81 void updateTelemetryView();
84 // These are used for debugging QProcess commands
85 //void processStarted();
86 //void processExit(int, QProcess::ExitStatus);
87 //void processError(QProcess::ProcessError);
90 void vmLoadingComplete();
93 void readExistingVmsFile();
94 // Check for Palacios setup
98 // Functions to setup different components of the window
99 void createCentralWidget();
100 void createActions();
102 void createToolBars();
103 void createStatusBar();
104 void createDockWindows();
106 void createEventHandler();
107 // Show error message boxes
108 void showMessage(QString err, bool error, bool warning=false);
109 // Update state of VM
110 void updateVmState(int);
111 // Create inactive VM
112 int createInactiveVm();
117 // Main view of the application.
118 QTabWidget* mVmControlPanel;
119 VmInfoWidget* mVmInfoWidget;
120 // This is used to represent the classes of VM
121 QTreeWidget* mVmTreeView;
122 QTextEdit* mVmTelemetryView;
124 // Progress dialog to inform user about background thread processing
125 //QProgressDialog* mProgress;
127 // Runs Palacios in terminal mode
128 QList<VmXConsoleParent*> mRunningVms;
130 bool mExitAppFromMenu;
131 // Used to identify VMs inside list
135 // Action variables used to handle events such as menu clicks, button clicks etc.
141 QAction* mVmActivate;
152 QToolBar* mVmToolBar;
153 QToolBar* mVmCtrlToolBar;
155 // This dialog will be used to give option
156 // to user to select from three modes of
158 VmModeDialog* mVmModeDialog;
161 bool isHeaderClicked;
163 // Process to read kernel logs
166 // Wizard to help in vm creation
167 NewVmWizard* mVmWizard;
169 // List of created VMs. Each VM object contains information parsed from
170 // the config files provided as part of VM creation
171 QList<VmInfo*> mVmList;
172 //QList<VM*> mVmList;
174 /* We save the information about VMs in a text file. We store the name of the VM instance
175 * and the path of the configuration file used to create the VM. Every time we create/add/delete
176 * a VM instance, this file is edited. This is simplest way as of now to store this information.
177 * If in future we need more information to be stored we could use a database and Qt's
178 * model-view system */
182 // Thread to load existing VM intances
183 LoadVmsThread* mLoadVmsThread;
184 // Thread to add a new VM instance
185 AddVmThread* mAddVmThread;
186 // Thread to delete a VM instance
187 DeleteVmThread* mDeleteVmThread;
190 QProcess* mTelemProc;
193 class VmModeDialog : public QWidget {
196 VmModeDialog(QWidget* parent = 0);
199 void selectMode(bool);
204 // This signal will be caught in the main window
205 // and the mode will be set accordingly
206 void setMode(int, QString);
217 QRadioButton* v3_stream;
218 QRadioButton* v3_cons;
219 QRadioButton* v3_vnc;
220 QWidget* v3_stream_info;
221 QLineEdit* v3_stream_name;
224 // Class to hold information about a VM instance
233 // Tells us about the state of the VM
235 STOPPED, PAUSED, RUNNING
238 // Tells about the category of VM
240 ACTIVE_INVENTORY, INACTIVE_INVENTORY, ACTIVE_NOT_INVENTORY
243 // Return state of VM
249 void setState(int state) {
250 this->mVmState = state;
253 void setCategory(int cat) {
254 this->mVmCategory = cat;
261 void setImageFile(QString img) {
262 this->mVmImageFile = img;
265 QString getImageFile() {
269 QString getVmName() {
273 void setVmName(QString name) {
274 this->mVmName = name;
277 QString getVmDevFile() {
281 void setVmDevFile(QString name) {
282 this->mVmDevFile = name;
285 QString getVmConfigFile() {
286 return this->mVmConfigFile;
289 void setVmConfigFile(QString file) {
290 this->mVmConfigFile = file;
298 QString mVmImageFile;
299 QString mVmConfigFile;
302 class VmInfoWidget: public QWidget {
305 VmInfoWidget(QWidget* parent = 0);
313 void parseElement(const QDomElement&, QTreeWidgetItem*);
314 void parseAttribute(const QDomElement&, QTreeWidgetItem*);
315 void parseText(const QDomElement&, QTreeWidgetItem*);
316 void updateInfoView(VmInfo* vm);
320 QTreeWidget* mVmInfoView;
323 class VmXConsoleParent: public QWidget {
326 VmXConsoleParent(QString name, QWidget* parent = 0);
327 void showWidget(int mode, QString devfile, QString streamName);
328 void showTelemetryInfo();
333 void windowClosingWithId(QString name);
334 void windowClosing();
337 void closeEvent(QCloseEvent* event);
340 bool mIsConsoleRunning;
342 VmConsoleWidget* mConsole;
345 class LoadVmsThread: public QObject {
348 static const int STATUS_OK = 0;
349 static const int ERROR_FILE_CANNOT_BE_OPENED = -1;
352 QList<VmInfo*> getVmList();
364 class AddVmThread: public QObject {
367 static const int STATUS_OK = 0;
368 static const int ERROR_V3CREATE_PATH = -1;
369 static const int ERROR_V3CREATE_IOCTL = -2;
370 static const int ERROR_V3CREATE_PROC = -3;
371 static const int ERROR_V3CREATE_DEV = -4;
372 static const int ERROR_V3CREATE_DB = -5;
374 AddVmThread(QString name, QString conf, QString img);
389 QString vmConfigFile;
394 class DeleteVmThread: public QObject {
397 static const int STATUS_OK = 0;
398 static const int ERROR_V3FREE_PATH = -1;
399 static const int ERROR_V3FREE_IOCTL = -2;
400 static const int ERROR_V3FREE_DB = -3;
401 static const int ERROR_V3FREE_INVALID_ARGUMENT = -4;
403 DeleteVmThread(int, QString, QString);
413 // These are used for debugging QProcess commands
414 //void processStarted();
415 //void processExit(int, QProcess::ExitStatus);
416 //void processError(QProcess::ProcessError);
425 #endif // NEWPALACIOS_H