summaryrefslogblamecommitdiffstats
path: root/src/fbgui.cpp
blob: c6f7e0d34884ea50745c6f80491e2d993d958a2d (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.
    QApplication a(argc, argv);

    // 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();
		// Not quite sure what the best exit statement is.
		// Maybe better a.quit() ?
		//exit(0);
		// Probably use the EXIT_SUCCESS / EXIT_FAILURE constants as defined in "man exit"
		return EXIT_SUCCESS;
	}

	// Check if URL was given at cmdline argument, if not set default.
	// TODO: fix short options parsing, doesn't work atm.
	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();
    QObject::connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));

    // 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()));

    // Display the browser.
    fbb->show();

    // Execute the application.
    return a.exec();
}