Exemplo n.º 1
0
Qaul::Qaul(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::Qaul)
{ 
    QDir myDir;
    QString qaulLocalDirectory = QDir::homePath();
    qaulLocalDirectory += "/.qaul";
    qDebug() << "Local path: " << qaulLocalDirectory;

    // create ~/.qaul directory
    if(!myDir.exists(qaulLocalDirectory))
    {
        qDebug() << "Local path does not exist yet";
        if(myDir.mkpath(qaulLocalDirectory))
        {
            qDebug() << "Local path created";

            // copy www folder into ~/.qaul directory
            this->QaulCopyDir(QApplication::applicationDirPath() +"/www", qaulLocalDirectory +"/www");
            //QaulCopyDir(const QString &srcPath, const QString &dstPath)
        }
    }

    // initialize library
    //QString qpath = QApplication::applicationDirPath();
    Qaullib_Init(qaulLocalDirectory.toLocal8Bit().data());

    // set download folder
    QString qaulDownloadDirectory = QDir::homePath();
    qaulDownloadDirectory += "/Downloads";
    qDebug() << "download path: " << qaulDownloadDirectory;
    if(!myDir.exists(qaulDownloadDirectory))
    {
        qDebug() << "Download path does not exist yet";
        if(myDir.mkpath(qaulDownloadDirectory))
        {
            qDebug() << "Download path created";
        }
    }
    Qaullib_SetConfDownloadFolder(qaulDownloadDirectory.toLocal8Bit().data());

    // start web server
    // TODO: make QDialog::exec() as modal information for the user if web server failes
    if(!Qaullib_WebserverStart()) qDebug() << "web server startup failed";

    ui->setupUi(this);

    // configure qaul
    qaulConfigureCounter = -1;
    // how many firewall rules are set
    qaulFirewallCounter = 0;
    // wait a second to open the window
    QaulConfigureDelay(1000);
}
Exemplo n.º 2
0
// ------------------------------------------------------------
int main(int argc, char *argv[])
{
	char cCurrentPath[FILENAME_MAX];

	if (!GetCurrentDir(cCurrentPath, sizeof(cCurrentPath)))
	{
		printf ("ERROR: couldn't get directory\n");
		return EXIT_FAILURE;
	}
	cCurrentPath[sizeof(cCurrentPath) - 1] = '\0';
	printf ("The current working directory is %s\n", cCurrentPath);

	Qaullib_Init(cCurrentPath);
	// enable debug menu
	qaul_conf_debug = 1;

	if(!Qaullib_WebserverStart())
		printf("Webserver startup failed\n");
	Qaullib_ConfigStart();

	printf("----------------------------------------------------\n");
	printf(" config started\n");
	printf("----------------------------------------------------\n");
	// The invoking of Qaullib_GetIP() is mandatory to load the IP.
	printf("IP: %s\n", Qaullib_GetIP());

	// wait until user name is set
	int username_flag = 0;
	while(Qaullib_ExistsUsername() == 0)
	{
		if(username_flag == 0)
		{
			username_flag = 1;
			printf("waiting until user name is set ...\n");
			printf("open web browser with http://localhost:8081/jqm_qaul.html to set it ...\n");
		}
		sleep(1);
	}
	printf("user name successfully set!\n");

	if(!Qaullib_IpcConnect())
		printf("Ipc connection failed\n");
	Qaullib_SetConfVoIP();
	if(!Qaullib_UDP_StartServer())
		printf("UDP server failed\n");
	if(!Qaullib_CaptiveStart())
		printf("Captive portal failed\n");
	Qaullib_ConfigurationFinished();

	// test config
	printf("IP: %s\n", Qaullib_GetIP());
	printf("Qaul started\n");

	// loop variables
	int socketCounter = 0;
	int ipcCounter = 0;

	printf("kill app to exit!\n");

	// main loop
	while (1) {
		usleep(10000);

		// get event
		int event = Qaullib_TimedCheckAppEvent();
		if(event == QAUL_EVENT_QUIT)
			printf("quit app\n");
		else if(event == QAUL_EVENT_CHOOSEFILE)
			printf("open file chooser\n");
		else if(event == QAUL_EVENT_OPENFILE)
			printf("open file\n");

		// check sockets
		if(socketCounter >= 10)
		{
			Qaullib_TimedSocketReceive();
			socketCounter = 0;
		}
		else
			socketCounter++;

		// get network node IPs
		// schedule downloads
		if(ipcCounter >= 500)
		{
			Qaullib_IpcSendCom(1);
			Qaullib_TimedDownload();
			ipcCounter = 0;
		}
		else
			ipcCounter++;
	}
}
Exemplo n.º 3
0
int main(int argc, char *argv[])
{
	char qaulUserPath[MAX_PATH_LEN];
	char qaulTmpPath[MAX_PATH_LEN];
	char qaulTmpPath2[MAX_PATH_LEN];

	qaulConfigureCounter = 0;
	qaulTimerEvents = 0;
	qaulTimerSockets = 0;
	qaulTimerTopology = 0;
	network_interface_found = 0;

	// initialize glib types
	g_type_init();

	// set paths
	sprintf(qaulUserPath, "%s/.qaul", (char*)g_get_home_dir());
	printf ("qaul.net home directory is %s\n", qaulUserPath);

	// create qaul user directory
	if(!g_file_test(qaulUserPath, G_FILE_TEST_EXISTS))
	{
		// create directory
		// http://www.gnu.org/software/libc/manual/html_node/Permission-Bits.html
		if(g_mkdir(qaulUserPath, S_IRUSR|S_IWUSR|S_IXUSR)== -1)
			printf("qaul.net home directory %s creation error.\n", qaulUserPath);
	}
	// check if we have to update
	sprintf(qaulTmpPath, "%s/%s", qaulUserPath, QAUL_VERSION);
	if(!g_file_test(qaulTmpPath, G_FILE_TEST_EXISTS))
	{
		printf("Update user folder to qaul.net version %s\n", QAUL_VERSION);
		// copy www folder
		sprintf(qaulTmpPath, "%s/www", QAUL_ROOT_PATH);
		sprintf(qaulTmpPath2, "%s/www", qaulUserPath);
		if(!qaul_copyDirectory(qaulTmpPath, qaulTmpPath2))
			printf("qaul copy directory error. source: %s target: %s\n", qaulTmpPath, qaulTmpPath2);
		// TODO: update data base
		// remove old data base if it exists
		sprintf(qaulTmpPath, "%s/qaullib.db", qaulUserPath);
		if(g_file_test(qaulTmpPath, G_FILE_TEST_EXISTS))
			if(g_remove(qaulTmpPath) == -1)
				printf("qaul.net database %s removal error\n", qaulTmpPath);
		// create qaul version file
		sprintf(qaulTmpPath, "%s/%s", qaulUserPath, QAUL_VERSION);
		if(!g_file_test(qaulTmpPath, G_FILE_TEST_EXISTS))
			if(!g_creat(qaulTmpPath, S_IRUSR|S_IWUSR) == -1)
				printf("qaul.net version file %s creation error\n", qaulTmpPath);
	}

	Qaullib_Init(qaulUserPath);
	// set configuration
	Qaullib_SetConf(QAUL_CONF_INTERFACE);
	// enable debug menu
	qaul_conf_debug = 1;

	if(!Qaullib_WebserverStart())
		printf("Webserver startup failed\n");

	// initialize dbus connection
	qaul_dbus_init(&network_dbus_connection);
	// start configuration timer
	qaulConfigureTimer = g_timeout_add(500, qaul_configure, NULL);

	// open window
	gtk_init(&argc,&argv);

    // Create a window that will contain the browser instance
    qaulMainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(qaulMainWindow), 400, 592);
    gtk_window_set_title(GTK_WINDOW(qaulMainWindow), "qaul.net - قول");
    sprintf(qaulTmpPath, "%s/app_icon.png", QAUL_ROOT_PATH);
    gtk_window_set_icon(GTK_WINDOW(qaulMainWindow), create_pixbuf(qaulTmpPath));

    // Create a browser instance
    WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new());

    // Create a scrollable area, and put the browser instance into it
    GtkWidget *scrolledWindow = gtk_scrolled_window_new(NULL, NULL);
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledWindow),
            GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
    gtk_container_add(GTK_CONTAINER(scrolledWindow), GTK_WIDGET(webView));

    // Set up callbacks so that if either the main window or the browser instance is
    // closed, the program will exit
    g_signal_connect(qaulMainWindow, "destroy", G_CALLBACK(destroyWindowCb), NULL);
    g_signal_connect(webView, "close-web-view", G_CALLBACK(closeWebViewCb), qaulMainWindow);

    // Put the scrollable area into the main window
    gtk_container_add(GTK_CONTAINER(qaulMainWindow), scrolledWindow);

    // Load a web page into the browser instance
    webkit_web_view_load_uri(webView, "http://127.0.0.1:8081/qaul.html");

    // Make sure that when the browser area becomes visible, it will get mouse
    // and keyboard events
    gtk_widget_grab_focus(GTK_WIDGET(webView));

    // Make sure the main window and all its contents are visible
    gtk_widget_show_all(qaulMainWindow);

    // Run the main GTK+ event loop
    gtk_main();

    return 0;
}