diff options
| -rw-r--r-- | src/fbgui.cpp | 24 | ||||
| -rw-r--r-- | src/fbgui.h | 5 | ||||
| -rw-r--r-- | src/javascriptInterface.cpp | 2 | ||||
| -rw-r--r-- | src/main.cpp | 52 |
4 files changed, 48 insertions, 35 deletions
diff --git a/src/fbgui.cpp b/src/fbgui.cpp index 6c2eead..dbee71f 100644 --- a/src/fbgui.cpp +++ b/src/fbgui.cpp @@ -14,19 +14,14 @@ QString binPath(""); QString downloadPath(binPath + "/downloads"); QUrl baseURL(DEFAULT_URL); bool debug = false; - -fbgui::fbgui(QApplication *parent) +//------------------------------------------------------------------------------------------- +fbgui::fbgui() { if (debug) qDebug() << "Application dir path: " << QApplication::applicationDirPath(); - /* Lookup hostname */ - QHostInfo hostInfo = QHostInfo::fromName(baseURL.host()); - if (hostInfo.error() != QHostInfo::NoError){ - if (debug) qDebug() << "Lookup of " << baseURL.host() << "failed." << "Exiting..."; - exit(EXIT_FAILURE); - } + checkHost(); - /* Browser init. */ + /* Init "browser" */ QWebView* webView = new QWebView(this); webView->load(baseURL); @@ -45,6 +40,13 @@ fbgui::fbgui(QApplication *parent) setWindowFlags(Qt::SplashScreen); showFullScreen(); setCentralWidget(webView); - + show(); +} +//------------------------------------------------------------------------------------------- +void fbgui::checkHost() const { + QHostInfo hostInfo = QHostInfo::fromName(baseURL.host()); + if (hostInfo.error() != QHostInfo::NoError){ + if (debug) qDebug() << "Lookup of " << baseURL.host() << "failed." << "Exiting..."; + exit(EXIT_FAILURE); + } } - diff --git a/src/fbgui.h b/src/fbgui.h index ed773cd..0f06551 100644 --- a/src/fbgui.h +++ b/src/fbgui.h @@ -17,7 +17,10 @@ class fbgui : public QMainWindow Q_OBJECT public: - fbgui(QApplication *parent); + fbgui(); + +private: + void checkHost() const; }; diff --git a/src/javascriptInterface.cpp b/src/javascriptInterface.cpp index 2808dda..a0b4254 100644 --- a/src/javascriptInterface.cpp +++ b/src/javascriptInterface.cpp @@ -17,7 +17,6 @@ javascriptInterface::javascriptInterface(QWebFrame *parent) { //------------------------------------------------------------------------------------------------------- javascriptInterface::~javascriptInterface() {} //------------------------------------------------------------------------------------------------------- -/* TEST */ QString javascriptInterface::getSysInfo(QString info) { sysInfo si; @@ -28,7 +27,6 @@ QString javascriptInterface::getSysInfo(QString info) //------------------------------------------------------------------------------------------------------- void javascriptInterface::attachToDOM() { - // Attaches itself to the DOM _parent->addToJavaScriptWindowObject(QString("jsObject"), this); } //------------------------------------------------------------------------------------------------------- diff --git a/src/main.cpp b/src/main.cpp index bd4951d..b53f25e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,7 +13,7 @@ void printHelp() qout << QObject::tr("Usage: ./fbgui [OPTIONS]") << endl; qout << QObject::tr("Options:") << endl; qout << "-u <URL>, --url=<URL> " << QObject::tr("Set which URL to load.") << endl; - qout << "-d <dir>, --downloaddir <dir> " << QObject::tr("Specifiy the download directory.") << endl; + qout << "-d <dir>, --downloaddir=<dir> " << QObject::tr("Specifiy the download directory.") << endl; qout << "-D, --debug " << QObject::tr("Activate debug mode.") << endl; qout << "-h, --help " << QObject::tr("Prints usage information.") << endl; qout.flush(); @@ -34,7 +34,7 @@ int main(int argc, char *argv[]) app.installTranslator(&translator); /* Parse cmdline argus. */ - QMap<QString, QString> clo; + QMap<QString, QString> clOpts; int longIndex = 0; static const char *optString = "u:hDd:"; static const struct option longOpts[] = @@ -42,7 +42,7 @@ int main(int argc, char *argv[]) {"url", required_argument, NULL, 'u'}, {"downloaddir", required_argument, NULL, 'd'}, {"debug", no_argument, NULL, 'D'}, - {"help", no_argument, NULL, 'h'} + {"help", no_argument, NULL, 'h'} }; int opt = getopt_long(argc, argv, optString, longOpts, &longIndex); while (opt != -1) @@ -50,25 +50,25 @@ int main(int argc, char *argv[]) switch(opt) { case 'u': - clo.insert("url", optarg); + clOpts.insert("url", optarg); break; case 'd': - clo.insert("downloadDir", optarg); + clOpts.insert("downloadDir", optarg); break; case 'D': - clo.insert("debug", "debug"); + clOpts.insert("debug", "debug"); break; case 'h': - clo.insert("help", "help"); + clOpts.insert("help", "help"); break; } opt = getopt_long(argc, argv, optString, longOpts, &longIndex); } // Print help - if (clo.contains("help")) + if (clOpts.contains("help")) printHelp(); // Debug mode - if (clo.contains("debug")){ + if (clOpts.contains("debug")){ debug = true; qDebug() << "Debug mode activated."; } @@ -76,28 +76,38 @@ int main(int argc, char *argv[]) QSettings confFileSettings(app.applicationDirPath() + "/fbgui.conf", QSettings::IniFormat); confFileSettings.setIniCodec("UTF-8"); - if (clo.contains("url")) - baseURL = QUrl(clo.value("url")); - else if (confFileSettings.contains("default/url")) - baseURL = confFileSettings.value("default/url").toUrl(); - else - baseURL = DEFAULT_URL; + if (clOpts.contains("url")) { + baseURL = QUrl(clOpts.value("url")); + if (debug) qDebug() << "URL loaded from cmdline."; + } + else if (confFileSettings.contains("default/url")) { + baseURL = confFileSettings.value("default/url").toUrl(); + if (debug) qDebug() << "URL loaded from config file."; + } + else { + baseURL = DEFAULT_URL; + if (debug) qDebug() << "URL set by default."; + } if (debug) qDebug() << "Base URL: " << baseURL.toString(); // Setting target downloads directory. - if (clo.contains("downloadDir")){ - downloadPath = clo.value("downloadDir"); + if (clOpts.contains("downloadDir")){ + downloadPath = clOpts.value("downloadDir"); + if (debug) qDebug() << "Download directory loaded from cmdline."; } else if (confFileSettings.contains("default/downloadDirectory")){ downloadPath = confFileSettings.value("default/downloadDirectory").toString(); + if (debug) qDebug() << "Download directory loaded from config file."; } else + { downloadPath = "/downloads"; // Default download dir. + if (debug) qDebug() << "Download directory set by default."; + } if (debug) qDebug() << "Download directory: " << downloadPath; - // Start fbgui. - fbgui gui(&app); - gui.setAttribute(Qt::WA_QuitOnClose, true); - gui.show(); + + fbgui gui; + gui.setAttribute(Qt::WA_QuitOnClose, true); return app.exec(); } |
