summaryrefslogtreecommitdiffstats
path: root/src/fbgui.cpp
diff options
context:
space:
mode:
authorJonathan Bauer2011-04-24 21:36:26 +0200
committerJonathan Bauer2011-04-24 21:36:26 +0200
commit03ac351f38316d8f923f3797aa7dd0deade7ed5d (patch)
treec01e300c7a92ce728df907fd85e1a514876b6037 /src/fbgui.cpp
parentmore old tests... (diff)
downloadfbgui-03ac351f38316d8f923f3797aa7dd0deade7ed5d.tar.gz
fbgui-03ac351f38316d8f923f3797aa7dd0deade7ed5d.tar.xz
fbgui-03ac351f38316d8f923f3797aa7dd0deade7ed5d.zip
url status handling, 5sec delay before closing gui when exiting with failure (not actually returning 1 atm), lots of formatting...
Diffstat (limited to 'src/fbgui.cpp')
-rw-r--r--src/fbgui.cpp82
1 files changed, 42 insertions, 40 deletions
diff --git a/src/fbgui.cpp b/src/fbgui.cpp
index 3494b83..9a0ee1d 100644
--- a/src/fbgui.cpp
+++ b/src/fbgui.cpp
@@ -34,10 +34,8 @@ int debugMode = -1;
* @see DownloadManager
*/
fbgui::fbgui() {
+
// test for libsys function
- //SysInfoLibsysfs* sil = new SysInfoLibsysfs();
- //sil->getInfoAboutNetworkInterface();
- //sil->getInfoMainboardSerial();
//SysInfo si;
//qxtLog->debug() << si.getInfo("mbserial");
//si.getInfo("usb");
@@ -46,28 +44,22 @@ fbgui::fbgui() {
createActions();
// initialize javascript interface
- JavascriptInterface* jsi = new JavascriptInterface(
- _webView->page()->mainFrame());
+ JavascriptInterface* jsi = new JavascriptInterface(_webView->page()->mainFrame());
QObject::connect(jsi, SIGNAL(quitFbgui()), this, SLOT(close()));
- QObject::connect(jsi, SIGNAL(shutDownClient()), this,
- SLOT(performShutDown()));
+ QObject::connect(jsi, SIGNAL(shutDownClient()), this, SLOT(performShutDown()));
QObject::connect(_webView->page()->mainFrame(), SIGNAL(
javaScriptWindowObjectCleared()), jsi, SLOT(attachToDOM()));
// initialize download manager
DownloadManager* dm = new DownloadManager();
- QObject::connect(dm, SIGNAL(downloadInfo(const QString&, const double&)),
- jsi, SLOT(downloadInfo(const QString&, const double&)));
- QObject::connect(dm, SIGNAL(notify(const QString&)), jsi,
- SLOT(notify(const QString&)));
+ QObject::connect(dm, SIGNAL(downloadInfo(const QString&, const double&)), jsi,
+ SLOT(downloadInfo(const QString&, const double&)));
+ QObject::connect(dm, SIGNAL(notify(const QString&)), jsi, SLOT(notify(const QString&)));
QObject::connect(jsi, SIGNAL(requestFile(const QString&)), dm,
SLOT(downloadFile(const QString&)));
- QObject::connect(dm,
- SIGNAL(updateProgress(const int&, const double&, const QString&)),
- jsi,
+ QObject::connect(dm, SIGNAL(updateProgress(const int&, const double&, const QString&)), jsi,
SLOT(updateProgressBar(const int&, const double&, const QString&)));
- QObject::connect(dm, SIGNAL(downloadQueueEmpty()), jsi,
- SLOT(callbackOnFinished()));
+ QObject::connect(dm, SIGNAL(downloadQueueEmpty()), jsi, SLOT(callbackOnFinished()));
QObject::connect(dm, SIGNAL(downloadQueueEmpty()), this, SLOT(loadSystem()));
// move download manager to its own thread
@@ -80,7 +72,6 @@ fbgui::fbgui() {
} else {
_webView->load(QUrl("qrc:/html/preload.html"));
}
- //statusBar()->showMessage("Waiting for internet...");
// start watching for fileToTriggerURL
watchForTrigger();
@@ -92,7 +83,7 @@ fbgui::fbgui() {
showFullScreen();
}
fbgui::~fbgui() {
- //dmThread.quit();
+ dmThread.quit();
}
//-------------------------------------------------------------------------------------------
// Layout / actions setup
@@ -154,16 +145,15 @@ void fbgui::watchForTrigger() {
qxtLog->debug() << "[gui] Created: " << fileToTriggerURL;
file.close();
} else {
- qxtLog->debug() << "[gui] Creation of " << fileToTriggerURL
- << " failed! Exiting...";
- exit( EXIT_FAILURE);
+ qxtLog->debug() << "[gui] Creation of " << fileToTriggerURL << " failed!";
+ qxtLog->debug() << "[gui] Exiting in 5 seconds...";
+ QTimer::singleShot(5000, this, SLOT(close()));
}
}
// watch the path to trigger file
qxtLog->debug() << "[watcher] Watching " << fileToTriggerURL;
_watcher = new QFileSystemWatcher(QStringList(fileToTriggerURL), this);
- QObject::connect(_watcher, SIGNAL(fileChanged(const QString&)), this,
- SLOT(prepareURLLoad()));
+ QObject::connect(_watcher, SIGNAL(fileChanged(const QString&)), this, SLOT(prepareURLLoad()));
}
//-------------------------------------------------------------------------------------------
@@ -198,8 +188,8 @@ void fbgui::prepareURLLoad() {
bool fbgui::checkHost() const {
QHostInfo hostInfo = QHostInfo::fromName(baseURL.host());
if (hostInfo.error() != QHostInfo::NoError) {
- qxtLog->debug() << "[gui] Lookup of " << baseURL.host()
- << "failed. Exiting...";
+ qxtLog->debug() << "[gui] Lookup of " << baseURL.host() << "failed.";
+ qxtLog->debug() << "[gui] Host can not be reached.";
return false;
} else {
qxtLog->debug() << "[gui] Lookup of " << baseURL.host() << " succeeded.";
@@ -219,7 +209,7 @@ bool fbgui::checkHost() const {
*/
void fbgui::loadURL() {
if (checkHost()) {
- qxtLog->debug() << "[gui] Loading URL...";
+ qxtLog->debug() << "[gui] Loading URL: " << baseURL.toString() << " ...";
// Generate POST identification data needed by PBS.
QByteArray postData = generatePOSTData();
@@ -227,10 +217,22 @@ void fbgui::loadURL() {
// show cursor again since user is about to interact.
QWSServer::instance()->setCursorVisible(true);
+ QObject::connect(_webView, SIGNAL(loadFinished(bool)), this, SLOT(loadURLDone(bool)));
_webView->load(req, QNetworkAccessManager::PostOperation, postData);
}
// TODO: error page if no host.
}
+void fbgui::loadURLDone(bool success) {
+ // done contains the success of the loading: false / true
+ if (!success) {
+ qxtLog->debug() << "[gui] Loading failed. URL: " << _webView->url().toString();
+ qxtLog->debug() << "[gui] Exiting in 5 seconds...";
+ QTimer::singleShot(5000, this, SLOT(close()));
+ }
+ else {
+ qxtLog->debug() << "[gui] Loaded URL: " << _webView->url().toString();
+ }
+}
//-------------------------------------------------------------------------------------------
/**
* This method generates the POST data body.
@@ -382,24 +384,22 @@ void fbgui::prepareKexec() {
// load the kernel + initramfs + append of kcl into kexec.
QProcess *process = new QProcess(this);
QString cmdline = "kexec -l " + downloadPath.toUtf8() + "/kernel --initrd="
- + downloadPath.toUtf8() + "/initramfs --append=\"" + kcl.toUtf8()
- + "\"";
+ + downloadPath.toUtf8() + "/initramfs --append=\"" + kcl.toUtf8() + "\"";
qxtLog->debug() << "[gui] kexec cmdline: " << cmdline;
process->start(cmdline);
bool ret = process->waitForFinished();
if (!ret) {
- qxtLog->debug() << "[sysinfo] Failed to load kexec! Exiting...";
- exit( EXIT_FAILURE);
+ qxtLog->debug() << "[gui] Failed to execute: " << cmdline;
+ qxtLog->debug() << "[gui] Exiting in 5 seconds...";
+ QTimer::singleShot(5000, this, SLOT(close()));
} else {
- qxtLog->debug() << "[gui] Kexec load successfull.";
+ qxtLog->debug() << "[gui] Kexec load was successfull.";
if (debugMode < 0) {
// if process successfully finished, try to run kexec -e
runKexec();
} else {
- qxtLog->debug()
- << "[gui] Skipping execution of kexec - open debug shell.";
- qxtLog->debug()
- << "[gui] To start the system execute \"kexec -e\" in your shell.";
+ qxtLog->debug() << "[gui] Skipping execution of kexec - open debug shell.";
+ qxtLog->debug() << "[gui] To start the system execute \"kexec -e\" in your shell.";
close();
}
}
@@ -416,7 +416,8 @@ void fbgui::runKexec() {
process->startDetached("kexec -e");
if (!process->waitForStarted()) {
qxtLog->debug() << "[gui] Failed to execute: kexec -e";
- exit( EXIT_FAILURE);
+ qxtLog->debug() << "[gui] Exiting in 5 seconds...";
+ QTimer::singleShot(5000, this, SLOT(close()));
//TODO: Handle failure properly...
}
}
@@ -466,11 +467,12 @@ void fbgui::toggleDebugConsole() {
//
//-------------------------------------------------------------------------------------------
void fbgui::loadSystem() {
- // stop the thread for the download manager
- qxtLog->debug() << "[gui] Stopping download manager's thread...";
- dmThread.quit();
-
//show loading system page.
_webView->load(QUrl("qrc:/html/loadsystem.html"));
prepareKexec();
}
+//-------------------------------------------------------------------------------------------
+void fbgui::quitFailure() {
+}
+void fbgui::quitSuccess() {
+}