diff options
| author | Jonathan Bauer | 2011-03-06 12:08:34 +0100 |
|---|---|---|
| committer | Jonathan Bauer | 2011-03-06 12:08:34 +0100 |
| commit | 5443c7182151c7f9082e58f207d7c88e11826d08 (patch) | |
| tree | 47913f4393444d1aeec838adc2d85c5961bae024 /src | |
| parent | url short option fixed (diff) | |
| download | fbgui-5443c7182151c7f9082e58f207d7c88e11826d08.tar.gz fbgui-5443c7182151c7f9082e58f207d7c88e11826d08.tar.xz fbgui-5443c7182151c7f9082e58f207d7c88e11826d08.zip | |
updated code structure, main loop now separate from fbgui class.......
Diffstat (limited to 'src')
| -rw-r--r-- | src/CommandLineOptions.cpp | 43 | ||||
| -rw-r--r-- | src/CommandLineOptions.h | 25 | ||||
| -rw-r--r-- | src/fbgui.cpp | 78 | ||||
| -rw-r--r-- | src/fbgui.h | 19 | ||||
| -rw-r--r-- | src/fbgui.pro | 16 |
5 files changed, 30 insertions, 151 deletions
diff --git a/src/CommandLineOptions.cpp b/src/CommandLineOptions.cpp deleted file mode 100644 index 945cff9..0000000 --- a/src/CommandLineOptions.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * This class parses the command line options. - */ - -#include <QDebug> -#include <getopt.h> -#include <cstdlib> -#include "CommandLineOptions.h" - -CommandLineOptions::CommandLineOptions(int argc, char * const argv[]){ - qDebug() << "Received " << argc << "arguments."; - for (int i = argc; i != 0; i--) - qDebug() << i << " argument: " << argv[i]; - // Parse command line arguments. - int longIndex = 0; - static const char *optString = "u:h"; - static const struct option longOpts[] = - { - {"url", required_argument, NULL, 'u'}, - {"help", no_argument, NULL, 'h'} - }; - // getopt_long returns the index of the next argument to be read, -1 if there are no more arguments. - int opt = getopt_long(argc, argv, optString, longOpts, &longIndex); - while (opt != -1) - { - switch(opt) - { - case 'u': - options.insert("url", optarg); - qDebug() << "Added URL to clOptions:" << optarg; - break; - case 'h': - options.insert("help", "help"); - qDebug() << "Added help to clOptions."; - break; - } - opt = getopt_long(argc, argv, optString, longOpts, &longIndex); - } -} - -CommandLineOptions::~CommandLineOptions(){ - -} diff --git a/src/CommandLineOptions.h b/src/CommandLineOptions.h deleted file mode 100644 index dc56d34..0000000 --- a/src/CommandLineOptions.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef COMMANDLINEOPTIONS_H -#define COMMANDLINEOPTIONS_H - -#include <QMap> -#include <QString> - -class CommandLineOptions { - public: - CommandLineOptions(int argc, char * const argv[]); - ~CommandLineOptions(); - - bool contains(const QString& key) const { - return options.contains(key); - } - - QString value(const QString& key) const { - return options.value(key); - } - private: - QMap<QString, QString> options; -}; - - - -#endif // COMMANDLINEOPTIONS_H diff --git a/src/fbgui.cpp b/src/fbgui.cpp index d7fc65e..4ae9174 100644 --- a/src/fbgui.cpp +++ b/src/fbgui.cpp @@ -1,77 +1,21 @@ #include "fbgui.h" -#include "CommandLineOptions.h" #include "fbbrowser.h" #include "DownloadManager.h" -#include <QApplication> -#include <QSettings> +#include <iostream> #include <QUrl> -void printUsage() +fbgui::fbgui(QApplication *parent) { - // Prints usage information. - // TODO: Complete usage info. - QTextStream qout(stdout); - 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 << "-h, --help " << QObject::tr("Prints usage information.") << endl; - // qout << "-qws " << QObject::tr("Set this application to also be the server application.") << endl; - // qout << " " << QObject::tr("Skip this option if you have a QT server application") << endl; - exit(1); + // Test if parent is accessible? + qDebug() << "Still alive?"; + qDebug() << "Parent name: " << parent->objectName(); + /* Create the browser and connect to quit() */ + fbb = new fbbrowser(QUrl("http://132.230.4.3/webkitTest.html")); + QObject::connect(fbb, SIGNAL(killApp()), parent, SLOT(quit())); + fbb->show(); } - -int main(int argc, char *argv[]) +fbgui::~fbgui() { - // This is the main object of a QT Application. - // The third argument sets the application as the GUI-Server, - // so the same as using "-qws" when calling the application. - QApplication a(argc, argv, QApplication::GuiServer); - a.setQuitOnLastWindowClosed(true); - - // Note: The QT arguments (-qws, -display etc) seems to be gone at this point. - // So we should be able to ignore the QT arguments when calling fbgui, - // and add them "manually" to argc/argv here? Testworthy! - - /* SETTINGS TEST */ - CommandLineOptions clOptions(argc, argv); - - // TODO: Use QSettings for accessing the ini file but - // check first if option was set from cmdline. - // (if it was, dont set it from ini). - - // Check if help was requested, if so printUsage() and exit. - if (clOptions.contains("help")) - { - qDebug() << "Help requested. Printing usage info. Exiting..."; - printUsage(); - return EXIT_SUCCESS; - } - - // Check if URL was given at cmdline argument, if not set default. - QUrl url; - if (clOptions.contains("url")) - url = clOptions.value("url"); - else - url = QUrl("qrc:/html/errorPage.html"); - /* SETTINGS TEST */ - - - // Get the application path and prints on screen. - qDebug() << "Application Path: " << a.applicationDirPath(); -; - - // Create a new Framebuffer-Browser object for displaying the given URL. - fbbrowser* fbb = new fbbrowser(url); - - // Listen to the signalQuitAll() Signal to kill the app from within the browser. - QObject::connect(fbb, SIGNAL(killApp()), &a, SLOT(quit())); - // Alternative - - - // Display the browser. - fbb->show(); - - // Execute the application. - return a.exec(); + delete fbb; } diff --git a/src/fbgui.h b/src/fbgui.h index 281acd6..1345812 100644 --- a/src/fbgui.h +++ b/src/fbgui.h @@ -1,21 +1,22 @@ #ifndef FBGUI_H #define FBGUI_H -#include <QtGui> -#include <QUrl> +#include <QtCore> +#include <QApplication> - -//QT_BEGIN_NAMESPACE -//QT_END_NAMESPACE - -class fbgui : public QMainWindow +class fbbrowser; +class fbgui : public QObject { Q_OBJECT public: - fbgui(); + fbgui(QApplication *parent); ~fbgui(); - void printUsage(); + +private: + fbbrowser* fbb; + QUrl _url; + }; #endif // FBGUI_H diff --git a/src/fbgui.pro b/src/fbgui.pro index 7c1a19e..6ed7dec 100644 --- a/src/fbgui.pro +++ b/src/fbgui.pro @@ -6,14 +6,16 @@ QT += core \ gui \ webkit \ network -HEADERS += CommandLineOptions.h \ +HEADERS += fbgui.h \ + fbbrowser.h \ JSObject.h \ - DownloadManager.h \ - fbbrowser.h -SOURCES += CommandLineOptions.cpp \ - JSObject.cpp \ + DownloadManager.h + +SOURCES += main.cpp \ fbgui.cpp \ - DownloadManager.cpp \ - fbbrowser.cpp + fbbrowser.cpp \ + JSObject.cpp \ + DownloadManager.cpp + FORMS += fbbrowser.ui RESOURCES += fbgui.qrc |
