summaryrefslogblamecommitdiffstats
path: root/src/fbgui.cpp
blob: d7fc65e8b37027c45b08906dad042c954c2a181e (plain) (tree)
1
2
3
4
5
6
7
8
9
                  
                               
                      
                            
 
                       
                    
               
 

                 

                                     
                              
                                                            
                                            



                                                                                                                  


            

                                
                                                   



                                                                     
 



                                                                                  
                             
                                                 
 



                                                                    




                                                                              


                                    
                                                                          

                                      
                                             

                                                       

                             
 

                                                               
 
 
                                                                            

                                        
                                                                                    
                                                               

                  
 


                           
                               

                    
#include "fbgui.h"
#include "CommandLineOptions.h"
#include "fbbrowser.h"
#include "DownloadManager.h"

#include <QApplication>
#include <QSettings>
#include <QUrl>

void printUsage()
{
    // 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);
}

int main(int argc, char *argv[])
{
    // 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();
}