ApplicationUI::ApplicationUI(bb::cascades::Application *app) : QObject(app) { // create scene document from main.qml asset // set parent to created document to ensure it exists for the whole application lifetime QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this); // Expose this class to QML such that our Q_INVOKABLE methods defined in applicationui.hpp // can be called from our QML classes. qml->setContextProperty("cpp", this); // create root object for the UI AbstractPane *root = qml->createRootObject<AbstractPane>(); // set created root object as a scene app->setScene(root); // The code from here down to "void ApplicationUI::logEvent" is used to determine the device // location and log the result to the Flurry server. Any errors in the process will also be // logged QGeoPositionInfoSource *source = QGeoPositionInfoSource::createDefaultSource(this); if (source) { bool positionUpdatedConnected = connect(source, SIGNAL(positionUpdated (const QGeoPositionInfo &)), this, SLOT(positionUpdated (const QGeoPositionInfo &))); if (positionUpdatedConnected) { source->requestUpdate(); } else { qDebug() << "positionUpdated connection failed"; Flurry::Analytics::LogError("positionUpdated connection failed"); } } else {
Client::Client(QWidget *parent) : QMainWindow(parent), networkSession(0) { sysInfo = new QSystemDeviceInfo(this); QGeoPositionInfo::QGeoPositionInfo(info); QGeoPositionInfoSource *source = QGeoPositionInfoSource::createDefaultSource(this); if(source){ connect(source, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(positonUpdated(QGeoPositionInfo))); source->requestUpdate(); } hostLabel = new QLabel(tr("&Server name:")); QString ipAddress; QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses(); for (int i = 0; i < ipAddressesList.size(); ++i) { if (ipAddressesList.at(i) != QHostAddress::LocalHost && ipAddressesList.at(i).toIPv4Address()) { ipAddress = ipAddressesList.at(i).toString(); //#############KOSTIL'################## ipAddress = "91.221.60.166"; break; } } if (ipAddress.isEmpty()) ipAddress = QHostAddress(QHostAddress::LocalHost).toString(); hostLineEdit = new QLineEdit(ipAddress); hostLabel->setBuddy(hostLineEdit); statusLabel = new QLabel(tr("")); alarmTypeUnus = new QPushButton(tr("Fire")); alarmTypeDuo = new QPushButton(tr("Pain")); alarmTypeTres = new QPushButton(tr("Breakin")); quitButton = new QPushButton(tr("Quit")); sendButton = new QPushButton(tr("Send datastring")); buttonBox = new QDialogButtonBox; buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole); tcpSocket = new QTcpSocket(this); connect(quitButton, SIGNAL(clicked()), this, SLOT(close())); connect(alarmTypeUnus, SIGNAL(clicked()), this, SLOT(pressedUnus())); connect(alarmTypeDuo, SIGNAL(clicked()), this, SLOT(pressedDuo())); connect(alarmTypeTres, SIGNAL(clicked()), this, SLOT(pressedTres())); connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(displayError(QAbstractSocket::SocketError))); QGridLayout *mainLayout = new QGridLayout; mainLayout->addWidget(hostLabel, 0, 0); mainLayout->addWidget(hostLineEdit, 0, 1); mainLayout->addWidget(alarmTypeUnus, 3, 0); mainLayout->addWidget(alarmTypeDuo, 3, 1); mainLayout->addWidget(alarmTypeTres, 3, 2); mainLayout->addWidget(buttonBox, 4, 0); setLayout(mainLayout); setWindowTitle(tr("Alarm Client")); QNetworkConfigurationManager manager; if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) { QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); settings.beginGroup(QLatin1String("QtNetwork")); const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString(); settings.endGroup(); QNetworkConfiguration config = manager.configurationFromIdentifier(id); if ((config.state() & QNetworkConfiguration::Discovered) != QNetworkConfiguration::Discovered) { config = manager.defaultConfiguration(); } networkSession = new QNetworkSession(config, this); connect(networkSession, SIGNAL(opened()), this, SLOT(sessionOpened())); statusLabel->setText(tr("Opening network session.")); networkSession->open(); } }