示例#1
0
int main(int argc, char *argv[])
{ 
    QApplication::setGraphicsSystem("raster");
    QApplication a(argc, argv);

    QTextCodec::setCodecForTr(QTextCodec::codecForLocale());

    QString privatePathQt(QApplication::applicationDirPath());
    QString path(privatePathQt);
    path = QDir::toNativeSeparators(path);

    Server server;
    if (!server.listen(QHostAddress::Any, 6177)) {
        std::cerr << "Failed to bind to port" << std::endl;
        return 1;
    }

    QDeclarativeView view;
    view.engine()->setOfflineStoragePath(path);
    QObject::connect((QObject*)view.engine(), SIGNAL(quit()), &a, SLOT(quit()));

    view.setSource(QUrl("qrc:/qml/main.qml"));
    view.show();

    QString md5;
    QString dbname="DemoDB";
    QByteArray ba;
    ba = QCryptographicHash::hash (dbname.toAscii(), QCryptographicHash::Md5);
    md5.append(ba.toHex());
    md5.append(".sqlite");

    path.append(QDir::separator()).append("Databases");
    path.append(QDir::separator()).append(md5);
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName(path);
    if (!db.open()) {
        std::cerr << "Cannot open database" << std::endl;
        return 1;
    }

    OrderManager orderManager;
    view.rootContext()->setContextProperty("server", &server);
    view.rootContext()->setContextProperty("orderManager", &orderManager);

    Client client;
    QObject::connect(&orderManager, SIGNAL(send()), &client, SLOT(sendOrder()));
    QObject::connect(&server, SIGNAL(paied(quint32)), &orderManager, SLOT(payOrder(quint32)));

    DeviceManager deviceManager;
    QObject::connect(&deviceManager, SIGNAL(registerSignal()), &client, SLOT(sendRegistration()));
    view.rootContext()->setContextProperty("deviceManager", &deviceManager);
    deviceManager.registerDevice();

    return a.exec();
}
void Client::registerWithServer(){
	RegisterDialog rd(this);
	if(rd.exec()){
		QString name = rd.name();
		QString pass = rd.pass();
		userLineEdit->setText(name);
		passLineEdit->setText(pass);

		disconnect(tcpSocket, SIGNAL(connected()), this, SLOT(sendLoginInfo()));
		requestNewConnection();
		connect(tcpSocket, SIGNAL(connected()), this, SLOT(sendRegistration()));
	}
}
示例#3
0
void XmppReg::processStanza(const Stanza& s)
{
	QDomNode node;
	switch (state)
	{
	case Start:
		if (s.type() != "result")
		{
			//emit error();
			return;
		}
		node = s.node().firstChild().firstChild();
		while (!node.isNull())
		{
			printf("[XMPPREG] node = %s\n", node.localName().toLatin1().constData());
			if (node.localName() == "username")
				needUsername = true;
			if (node.localName() == "password")
				needPassword = true;
			if (node.localName() == "email")
				needEmail = true;
			node = node.nextSibling();
		}
		sendRegistration();
		state = WaitResult;
		break;
	case WaitResult:
		if (s.type() == "result")
		{
			//registerOk = true;
			emit finished();
		}
		if (s.type() == "error")
		{
			;
			//registerOk = false;
			//emit error();
		}
		break;
	}
}