Exemplo n.º 1
0
void Qaul::QaulCheckEvents(void)
{
    int myEvent = Qaullib_TimedCheckAppEvent();

    if(myEvent > 0)
    {
        if(myEvent == QAUL_EVENT_CHOOSEFILE)
        {
            // open file selection
            QString fileName = QFileDialog::getOpenFileName(
                        this,
                        tr("Add File"),
                        "/home",
                        tr("Files (*.*)"));
            // file was selected
            if(fileName != NULL)
            {
                qDebug() << "file selected " << fileName;
                Qaullib_FilePicked(2, fileName.toLocal8Bit().data());
            }
            else
            {
                qDebug() << "file selection canceld ";
            }

        }
        else if(myEvent == QAUL_EVENT_OPENFILE)
        {
            // open file in default application
            QString filepath = "file://";
            filepath += Qaullib_GetAppEventOpenPath();
            qDebug() << filepath;
            QDesktopServices::openUrl(QUrl(filepath));
        }
        else if(myEvent == QAUL_EVENT_OPENURL)
        {
            // open URL in browser
            QString urlpath = Qaullib_GetAppEventOpenURL();
            qDebug() << urlpath;
            QDesktopServices::openUrl(QUrl(urlpath));
        }
        else if(myEvent == QAUL_EVENT_QUIT)
        {
            // quit application
            QApplication::quit();
        }
        else if(myEvent == QAUL_EVENT_NOTIFY && myEvent == QAUL_EVENT_RING)
        {
            // play beep
            // does not work under linux
            QApplication::beep();
        }
    }
}
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
gboolean qaul_timerEvent(gpointer data)
{
    int myEvent;
    gchar myFilePath[MAX_URL_LEN +8];
	GError *myError;
	GtkWidget *myDialog;
	char *myFileChoose;

    myEvent = Qaullib_TimedCheckAppEvent();

    if(myEvent > 0)
    {
		printf("qaul_timerEvent: event [%i] found \n", myEvent);

    	if(myEvent == QAUL_EVENT_CHOOSEFILE)
        {
			printf("QAUL_EVENT_CHOOSEFILE \n");
    		myDialog = gtk_file_chooser_dialog_new("Choose File",
								  GTK_WINDOW(qaulMainWindow),
								  GTK_FILE_CHOOSER_ACTION_OPEN,
								  GTK_STOCK_CANCEL,
								  GTK_RESPONSE_CANCEL,
								  GTK_STOCK_OPEN,
								  GTK_RESPONSE_ACCEPT,
								  NULL);
			if (gtk_dialog_run(GTK_DIALOG(myDialog)) == GTK_RESPONSE_ACCEPT)
			{
				myFileChoose = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(myDialog));
				Qaullib_FilePicked(2, myFileChoose);
				g_free(myFileChoose);
			}
			gtk_widget_destroy(myDialog);
        }
        else if(myEvent == QAUL_EVENT_OPENFILE)
        {
			printf("QAUL_EVENT_OPENFILE \n");

        	// open file in default program
            myError = NULL;
            g_snprintf(myFilePath, MAX_URL_LEN +8, "file://%s", Qaullib_GetAppEventOpenPath());
            if(gtk_show_uri(gdk_screen_get_default(), myFilePath, gtk_get_current_event_time(), &myError))
				printf("Open file %s\n", myFilePath);
			else
				printf("Error opening file %s\n", myFilePath);

        	if(myError != NULL)
        	{
        		g_printerr("Error QAUL_EVENT_OPENFILE: %s\n", myError->message);
        		g_error_free(myError);
        	}
        }
        else if(myEvent == QAUL_EVENT_OPENURL)
        {
			printf("QAUL_EVENT_OPENURL \n");

        	// open URL in default browser
        	myError = NULL;
            if(gtk_show_uri(
					NULL,
					Qaullib_GetAppEventOpenURL(),
					GDK_CURRENT_TIME,
					&myError
				))
				printf("Open URL %s\n", Qaullib_GetAppEventOpenURL());
			else
				printf("Error opening URL %s\n", Qaullib_GetAppEventOpenURL());

        	if(myError != NULL)
        	{
        		g_printerr("Error QAUL_EVENT_OPENURL: %s\n", myError->message);
        		g_error_free(myError);
        	}
        }
        else if(myEvent == QAUL_EVENT_QUIT)
        {
			printf("QAUL_EVENT_QUIT \n");

            // quit application
			qaul_onquit();
			gtk_main_quit();
        }
        else if(myEvent == QAUL_EVENT_NOTIFY || myEvent == QAUL_EVENT_RING)
        {
			printf("QAUL_EVENT_NOTIFY || QAUL_EVENT_RING \n");

            // play beep
            gdk_beep();
        }
        else if(myEvent == QAUL_EVENT_GETINTERFACES)
        {
			printf("QAUL_EVENT_GETINTERFACES \n");

            // search for Interfaces
            if(qaul_network_devices_json(network_dbus_connection, network_json_txt))
            {
            	// set Interfaces
            	Qaullib_SetInterfaceJson(network_json_txt);
            }
        }
    }

	return TRUE;
}