Example #1
0
Server::Server(QObject *parent) :
    QObject(parent), tcpServer(0), networkSession(0), memBuf(NULL)
{
    QNetworkConfigurationManager manager;
    if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) {
        // Get saved network configuration
        QSettings settings(QSettings::UserScope, QLatin1String("QtProject"));
        settings.beginGroup(QLatin1String("QtNetwork"));
        const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString();
        settings.endGroup();

        // If the saved network configuration is not currently discovered use the system default
        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()));

        QTextStream out(stdout);
        out << tr("Opening network session.");

        networkSession->open();
    } else {
        sessionOpened();
    }

    connect(tcpServer, SIGNAL(newConnection()), this, SLOT(sendImage()));
}
Example #2
0
bool Network::openConnection(QString &netInterface)
{
    // Internet Access Point
    QNetworkConfigurationManager manager;

    const bool canStartIAP = (manager.capabilities()
        & QNetworkConfigurationManager::CanStartAndStopInterfaces);

    // If there is a default access point, use it
    QNetworkConfiguration cfg = manager.defaultConfiguration();

    if (!cfg.isValid() || !canStartIAP) {
        return false;
    }

    // Open session
    m_session = new QNetworkSession(cfg);
    m_session->open();
    // Waits for session to be open and continues after that
    m_session->waitForOpened();

    // Show interface name to the user
    QNetworkInterface iff = m_session->interface();
    netInterface = iff.humanReadableName();
    return true;
}
Example #3
0
Server::Server()
{
    QNetworkConfigurationManager manager;
    if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired)
    {
        // Get saved network configuration
        QSettings settings(QSettings::UserScope, QLatin1String("QtProject"));
        settings.beginGroup(QLatin1String("QtNetwork"));
        const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString();
        settings.endGroup();

        // If the saved network configuration is not currently discovered use the system default
        QNetworkConfiguration config = manager.configurationFromIdentifier(id);
        if ((config.state() & QNetworkConfiguration::Discovered) != QNetworkConfiguration::Discovered)
        {
            config = manager.defaultConfiguration();
        }

        networkSession = new QNetworkSession(config, this);
        if (networkSession)
        {
            connect(networkSession, SIGNAL(opened()), this, SLOT(sessionOpened()));

            TRACE_INFO(NET, "Opening network session...\n");
            networkSession->open();
        }
    }
    else
    {
        sessionOpened();
    }

        fortunes << tr("You've been leading a dog's life. Stay off the furniture.")
                 << tr("You've got to think about tomorrow.")
                 << tr("You will be surprised by a loud noise.")
                 << tr("You will feel hungry again in another hour.")
                 << tr("You might have mail.")
                 << tr("You cannot kill time without injuring eternity.")
                 << tr("Computers are not intelligent. They only think they are.");

        if (tcpServer)
        {
            connect(tcpServer, SIGNAL(newConnection()), this, SLOT(sendDatas()));
        }
/*
        connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));

        QHBoxLayout *buttonLayout = new QHBoxLayout;
        buttonLayout->addStretch(1);
        buttonLayout->addWidget(quitButton);
        buttonLayout->addStretch(1);

        QVBoxLayout *mainLayout = new QVBoxLayout;
        mainLayout->addWidget(statusLabel);
        mainLayout->addLayout(buttonLayout);
        setLayout(mainLayout);

        setWindowTitle(tr("Fortune Server"));
*/
}
Example #4
0
int OcNetwork::bearerType()
{
    QNetworkConfiguration netConf = this->activeConfiguration();

    QLOG_DEBUG() << "Network bearer type name: " << netConf.bearerTypeName();

    QNetworkConfiguration::BearerType bt;
    bt = netConf.bearerType();
    int btNum;

    switch (bt) {
        case QNetworkConfiguration::BearerEthernet:
        case QNetworkConfiguration::BearerWLAN:
            btNum = 1;
            break;
        case QNetworkConfiguration::Bearer2G:
        case QNetworkConfiguration::BearerCDMA2000:
        case QNetworkConfiguration::BearerWCDMA:
        case QNetworkConfiguration::BearerHSPA:
            btNum = 2;
            break;
        case QNetworkConfiguration::BearerUnknown:
        default:
            btNum = 0;
            break;
    }

    return btNum;

}
BigBlobbyClient::BigBlobbyClient() :
  networkSession_( NULL ),
  tcpSocket_( new QTcpSocket( this ) ),
  portNumber_( DEFAULT_PORT_NUMBER ),
  log_( logger::FileLogger::instance() )
{
    connect( tcpSocket_, SIGNAL( readyRead() ), this, SLOT( readBigBlobbyResponse() ) );
    connect( tcpSocket_, SIGNAL( error( QAbstractSocket::SocketError ) ),
             this, SLOT( displayError( QAbstractSocket::SocketError ) ) );

    QNetworkConfigurationManager manager;

    if( manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired ) {
        // Get saved network configuration
        QSettings settings( QSettings::UserScope, QLatin1String( "BigBlobby" ) );
        settings.beginGroup( QLatin1String( "QtNetwork" ) );
        const QString id = settings.value( QLatin1String( "DefaultNetworkConfiguration" ) ).toString();
        settings.endGroup();

        // If the saved network configuration is not currently discovered use the system default
        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() ) );
        networkSession_->open();
    }
}
Example #6
0
TcpEchoServer::TcpEchoServer(quint16 port, QObject *parent)
:   QObject(parent), tcpServer(0), networkSession(0)
{
    QNetworkConfigurationManager manager;
    if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) {
        // Get saved network configuration
        QSettings settings(QSettings::UserScope, QLatin1String("QtProject"));
        settings.beginGroup(QLatin1String("QtNetwork"));
        const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString();
        settings.endGroup();

        // If the saved network configuration is not currently discovered use the system default
        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()));

        qDebug() << "Opening network session.";
        networkSession->open();
    } else {
        sessionOpened(port);
    }
}
Example #7
0
void Server::sessionOpened()//change ip address here
{
    // Save the used configuration
    if (networkSession) {
        QNetworkConfiguration config = networkSession->configuration();
        QString id;
        if (config.type() == QNetworkConfiguration::UserChoice)
            id = networkSession->sessionProperty(QLatin1String("UserChoiceConfiguration")).toString();
        else
            id = config.identifier();

        QSettings settings(QSettings::UserScope, QLatin1String("QtProject"));
        settings.beginGroup(QLatin1String("QtNetwork"));
        settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id);
        settings.endGroup();
    }

    tcpServer = new QTcpServer(this);
//    if (!tcpServer->listen(QHostAddress::LocalHost,PORT)) {
        if (!tcpServer->listen()) {

        QMessageBox::critical(this, tr("Fortune Server"),
                              tr("Unable to start the server: %1.")
                              .arg(tcpServer->errorString()));
        close();
        return;
    }
    QString ipAddress = IP_ADDRESS;
    // if we did not find one, use IPv4 localhost
    if (ipAddress.isEmpty())
        ipAddress = QHostAddress(QHostAddress::LocalHost).toString();
     qDebug() << "The server is running on:\nIP:"<< ipAddress <<"\nPort:"<< tcpServer->serverPort() <<"\n";
}
 foreach(const QNetworkConfiguration p, configs) {
     printConfigurationDetails(p);
     QVERIFY(p.isValid());
     QVERIFY(!(p.state() & QNetworkConfiguration::Undefined));
     QVERIFY(p.state() & QNetworkConfiguration::Defined);
     QVERIFY(p.state() & QNetworkConfiguration::Discovered);
 }
Example #9
0
Client::Client(QString purpose) : networkSession(0)
{
    Client::purpose = purpose;
    tcpSocket = new QTcpSocket;
    Client::blockSize = 0;
    qDebug() << connect(tcpSocket, &QTcpSocket::readyRead, this, &Client::readData);
    //connect(tcpSocket, &QTcpSocket::error, this, &Client::displayError);

    QNetworkConfigurationManager manager;
    if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired)
    {
        // Get saved network configuration
        QSettings settings(QSettings::UserScope, QLatin1String("QtProject"));
        settings.beginGroup(QLatin1String("QtNetwork"));
        const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString();
        settings.endGroup();

        // If the saved network configuration is not currently discovered use the system default
        QNetworkConfiguration config = manager.configurationFromIdentifier(id);
        if ((config.state() & QNetworkConfiguration::Discovered) !=
            QNetworkConfiguration::Discovered) {
            config = manager.defaultConfiguration();
        }

        networkSession = new QNetworkSession(config, this);
        qDebug() << connect(networkSession, &QNetworkSession::opened, this, &Client::sessionOpened);
    }
    qDebug() << "Client set up, waiting";
}
Example #10
0
void Server::StartServer()
{
    shotTimer->stop();
    is_config_mode = false;
    emit write_message(tr("Network session starting."));

    QNetworkConfigurationManager manager;
    if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) {
        // Get saved network configuration
        QSettings settings(QSettings::UserScope, QLatin1String("QtProject"));
        settings.beginGroup(QLatin1String("QtNetwork"));
        const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString();
        settings.endGroup();

        // If the saved network configuration is not currently discovered use the system default
        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(sessionOpen()));

        emit write_message(tr("Opening network session."));
        networkSession->open();
    } else {
        sessionOpen();
    }

    connect(tcpServer, SIGNAL(newConnection()), this, SLOT(recieveConnection()));
}
void lc::ClientHelpNotificationServer::OpenSession() {
    // Save the used configuration
    if ( networkSession ) {
        QNetworkConfiguration config = networkSession->configuration();
        QString id;
        if ( config.type() == QNetworkConfiguration::UserChoice ) {
            id = networkSession->sessionProperty( QLatin1String{ "UserChoiceConfiguration" } ).toString();
        } else {
            id = config.identifier();
        }

        QSettings settings( QSettings::UserScope, QLatin1String{ "QtProject" } );
        settings.beginGroup( QLatin1String{ "QtNetwork" } );
        settings.setValue( QLatin1String{ "DefaultNetworkConfiguration" }, id );
        settings.endGroup();
    }

    helpMessageServer = new QTcpServer{ this };
    if ( !helpMessageServer->listen( hostAddress, settings->clientHelpNotificationServerPort ) ) {
        QMessageBox messageBox{ QMessageBox::Critical, tr( "Unable to start the client help notification server" ),
                    tr( "Unable to start the client help notification server.\nThe following error occurred:\n\n%1." ).arg( helpMessageServer->errorString() ), QMessageBox::Ok };
        messageBox.exec();
        return;
    }
}
Example #12
0
/*!
    Starts the backend.  Returns \c true if the backend is started.  Returns \c false if the backend
    could not be started due to an unopened or roaming session.  The caller should recall this
    function once the session has been opened or the roaming process has finished.
*/
bool QNetworkAccessBackend::start()
{
#ifndef QT_NO_BEARERMANAGEMENT
    // For bearer, check if session start is required
    QSharedPointer<QNetworkSession> networkSession(manager->getNetworkSession());
    if (networkSession) {
        // session required
        if (networkSession->isOpen() &&
            networkSession->state() == QNetworkSession::Connected) {
            // Session is already open and ready to use.
            // copy network session down to the backend
            setProperty("_q_networksession", QVariant::fromValue(networkSession));
        } else {
            // Session not ready, but can skip for loopback connections

            // This is not ideal.
            const QString host = reply->url.host();

            if (host == QLatin1String("localhost") ||
                QHostAddress(host).isLoopback() ||
                reply->url.isLocalFile()) {
                // Don't need an open session for localhost access.
            } else {
                // need to wait for session to be opened
                return false;
            }
        }
    }
#endif

#ifndef QT_NO_NETWORKPROXY
#ifndef QT_NO_BEARERMANAGEMENT
    // Get the proxy settings from the network session (in the case of service networks,
    // the proxy settings change depending which AP was activated)
    QNetworkSession *session = networkSession.data();
    QNetworkConfiguration config;
    if (session) {
        QNetworkConfigurationManager configManager;
        // The active configuration tells us what IAP is in use
        QVariant v = session->sessionProperty(QLatin1String("ActiveConfiguration"));
        if (v.isValid())
            config = configManager.configurationFromIdentifier(qvariant_cast<QString>(v));
        // Fallback to using the configuration if no active configuration
        if (!config.isValid())
            config = session->configuration();
        // or unspecified configuration if that is no good either
        if (!config.isValid())
            config = QNetworkConfiguration();
    }
    reply->proxyList = manager->queryProxy(QNetworkProxyQuery(config, url()));
#else // QT_NO_BEARERMANAGEMENT
    // Without bearer management, the proxy depends only on the url
    reply->proxyList = manager->queryProxy(QNetworkProxyQuery(url()));
#endif
#endif

    // now start the request
    open();
    return true;
}
Example #13
0
Server::Server(QWidget *parent) : QDialog(parent)
{
    networkSession=0;
    tcpServer=0;
    ui = new Ui::Server;
    ui->setupUi(this);
    val=0;
    ui->quit_button->setAutoDefault(false);

    QNetworkConfigurationManager manager;
    if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) {
        // Get saved network configuration
        QSettings settings(QSettings::UserScope, QLatin1String("QtProject"));
        settings.beginGroup(QLatin1String("QtNetwork"));
        const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString();
        settings.endGroup();

        // If the saved network configuration is not currently discovered use the system default
        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()));

        networkSession->open();
    } else {
        sessionOpened();
    }
    connect(ui->quit_button, SIGNAL(clicked()), this, SLOT(close()));
    connect(tcpServer, SIGNAL(newConnection()), this, SLOT(conn()));
}
lc::ClientHelpNotificationServer::ClientHelpNotificationServer( QObject *argParent ) :
    QObject{ argParent },
    hostAddress{ settings->serverIP }
{
    QNetworkConfigurationManager manager;
    if ( manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired ) {
        // Get saved network configuration
        QSettings settings{ QSettings::UserScope, QLatin1String{ "QtProject" } };
        settings.beginGroup( QLatin1String{ "QtNetwork" } );
        const QString id = settings.value( QLatin1String{ "DefaultNetworkConfiguration" } ).toString();
        settings.endGroup();

        // If the saved network configuration is not currently discovered use the system default
        QNetworkConfiguration config = manager.configurationFromIdentifier( id );
        if ( ( config.state() & QNetworkConfiguration::Discovered ) != QNetworkConfiguration::Discovered ) {
            config = manager.defaultConfiguration();
        }
        networkSession = new QNetworkSession{ config, this };
        connect( networkSession, &QNetworkSession::opened,
                 this, &ClientHelpNotificationServer::OpenSession );
        networkSession->open();
    } else {
        OpenSession();
    }

    connect( helpMessageServer, &QTcpServer::newConnection,
             this, &ClientHelpNotificationServer::SendReply );
}
bool TCPClientProducer::init()
{
    assert( m_networkSession == 0 );
    assert( m_tcpSocket != 0 );

    QNetworkConfigurationManager manager;
    if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired)
    {
        // Get saved network configuration
        QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
        settings.beginGroup(QLatin1String("QtNetwork"));
        const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString();
        settings.endGroup();

        // If the saved network configuration is not currently discovered use the system default
        QNetworkConfiguration config = manager.configurationFromIdentifier(id);
        if ((config.state() & QNetworkConfiguration::Discovered) !=
            QNetworkConfiguration::Discovered)
        {
            config = manager.defaultConfiguration();
        }

        m_networkSession = new QNetworkSession(config);
        connect(m_networkSession, SIGNAL(opened()), this, SLOT(sessionOpened()));

        qDebug() << "Opening network session.";
        m_networkSession->open();
    }
    return true;
}
Example #16
0
Server::Server(QWidget *parent) :
	QDialog(parent),
	mTcpServer(0),
	mNetworkSession(0) {
	QNetworkConfigurationManager manager;
	if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) {
		// Get saved network configuration
		QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
		settings.beginGroup(QLatin1String("QtNetwork"));
		const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString();
		settings.endGroup();

		// If the saved network configuration is not currently discovered use the system default
		QNetworkConfiguration config = manager.configurationFromIdentifier(id);
		if ((config.state() & QNetworkConfiguration::Discovered) != QNetworkConfiguration::Discovered) {
			config = manager.defaultConfiguration();
		}

		mNetworkSession = new QNetworkSession(config, this);
		connect(mNetworkSession, SIGNAL(opened()), this, SLOT(sessionOpened()));

		mNetworkSession->open();
	} else {
		sessionOpened();
	}

	mIPAddressMapper = new QSignalMapper;
	connect(mTcpServer, SIGNAL(newConnection()), this, SLOT(acceptClientConnection()));
	connect(mIPAddressMapper, SIGNAL(mapped(QString)), this, SIGNAL(clientDisconnected(QString)));
}
Example #17
0
void Server::sessionOpened()
{
	// Save the used configuration
	if (mNetworkSession) {
		QNetworkConfiguration config = mNetworkSession->configuration();
		QString id;
		if (config.type() == QNetworkConfiguration::UserChoice)
			id = mNetworkSession->sessionProperty(QLatin1String("UserChoiceConfiguration")).toString();
		else
			id = config.identifier();

		QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
		settings.beginGroup(QLatin1String("QtNetwork"));
		settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id);
		settings.endGroup();
	}

	mTcpServer = new QTcpServer(this);
	if (!mTcpServer->listen(QHostAddress::AnyIPv4, 55555)) {
		QMessageBox::critical(this, tr("qReal Server"),
							  tr("Unable to start the server: %1.")
							  .arg(mTcpServer->errorString()));
		close();
		return;
	}
}
Example #18
0
void Server::sessionOpened()
 {
     // Save the used configuration
     if (networkSession)
     {
         QNetworkConfiguration config = networkSession->configuration();
         QString id;
         if (config.type() == QNetworkConfiguration::UserChoice)
             id = networkSession->sessionProperty(QLatin1String("UserChoiceConfiguration")).toString();
         else
             id = config.identifier();
     }

     tcpServer = new QTcpServer(this);
     if (!tcpServer->listen(QHostAddress::LocalHost, tcpServer->serverPort()))
     {
         QMessageBox::critical(this, "Server",
                               "Unable to start the server: " + tcpServer->errorString());
         close();
         return;
     }

     serverStatusLabel->setText(tr("The server is running on\n\nIP: %1\nport: %2\n\n")
                          .arg(tcpServer->serverAddress().toString()).arg(tcpServer->serverPort()));
 }
Example #19
0
Server::Server(QWidget *parent) :
    QDialog(parent), tcpServer(0), clientSocket(0), networkSession(0),
    blockSize(0)
{
    serverStatusLabel = new QLabel(tr("Status"));
    messageLabel = new QLabel(tr("Message:"));
    quitButton = new QPushButton(tr("Quit"));
    quitButton->setAutoDefault(false);
    sendMessageButton = new QPushButton(tr("Send Message"));

    chatBox = new QTextEdit;
    chatBox->setReadOnly(true);

    messageLineEdit = new QLineEdit;
    messageLineEdit->setEnabled(false);

    QNetworkConfigurationManager manager;
    if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired)
    {
        // Get saved network configuration
        QSettings settings(QSettings::UserScope, QLatin1String("QtProject"));
        settings.beginGroup(QLatin1String("QtNetwork"));
        const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString();
        settings.endGroup();

        // If the saved network configuration is not currently discovered use the system default
        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()));

        serverStatusLabel->setText("Opening network session.");
        networkSession->open();
    }
    else
        sessionOpened();


    QGridLayout *mainLayout = new QGridLayout;
    mainLayout->addWidget(serverStatusLabel, 0, 0);
    mainLayout->addWidget(messageLabel, 2, 0);
    mainLayout->addWidget(messageLineEdit, 3, 0);
    mainLayout->addWidget(sendMessageButton, 4, 0);
    mainLayout->addWidget(chatBox, 5, 0);
    mainLayout->addWidget(quitButton, 6, 0, 1, 2);
    setLayout(mainLayout);


    connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
    connect(sendMessageButton, SIGNAL(clicked()), this, SLOT(sendMessage()));
    connect(tcpServer, SIGNAL(newConnection()), this, SLOT(clientProcessing()));

    setWindowTitle("Server");
}
Example #20
0
BearerMonitor::BearerMonitor(QWidget *parent)
:   QWidget(parent)
{
    setupUi(this);
#ifdef MAEMO_UI
    newSessionButton->hide();
    deleteSessionButton->hide();
#else
    delete tabWidget->currentWidget();
    sessionGroup->hide();
#endif
    updateConfigurations();
    onlineStateChanged(!manager.allConfigurations(QNetworkConfiguration::Active).isEmpty());
    QNetworkConfiguration defaultConfiguration = manager.defaultConfiguration();
    for (int i = 0; i < treeWidget->topLevelItemCount(); ++i) {
        QTreeWidgetItem *item = treeWidget->topLevelItem(i);

        if (item->data(0, Qt::UserRole).toString() == defaultConfiguration.identifier()) {
            treeWidget->setCurrentItem(item);
            showConfigurationFor(item);
            break;
        }
    }
    connect(&manager, SIGNAL(onlineStateChanged(bool)), this ,SLOT(onlineStateChanged(bool)));
    connect(&manager, SIGNAL(configurationAdded(const QNetworkConfiguration&)),
            this, SLOT(configurationAdded(const QNetworkConfiguration&)));
    connect(&manager, SIGNAL(configurationRemoved(const QNetworkConfiguration&)),
            this, SLOT(configurationRemoved(const QNetworkConfiguration&)));
    connect(&manager, SIGNAL(configurationChanged(const QNetworkConfiguration&)),
            this, SLOT(configurationChanged(const QNetworkConfiguration)));
    connect(&manager, SIGNAL(updateCompleted()), this, SLOT(updateConfigurations()));

#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
    connect(registerButton, SIGNAL(clicked()), this, SLOT(registerNetwork()));
    connect(unregisterButton, SIGNAL(clicked()), this, SLOT(unregisterNetwork()));
#else // Q_OS_WIN && !Q_OS_WINRT
    nlaGroup->hide();
#endif

    connect(treeWidget, SIGNAL(itemActivated(QTreeWidgetItem*,int)),
            this, SLOT(createSessionFor(QTreeWidgetItem*)));

    connect(treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
            this, SLOT(showConfigurationFor(QTreeWidgetItem*)));

    connect(newSessionButton, SIGNAL(clicked()),
            this, SLOT(createNewSession()));
#ifndef MAEMO_UI
    connect(deleteSessionButton, SIGNAL(clicked()),
            this, SLOT(deleteSession()));
#endif
    connect(scanButton, SIGNAL(clicked()),
            this, SLOT(performScan()));

    // Just in case update all configurations so that all
    // configurations are up to date.
    manager.updateConfigurations();
}
Example #21
0
static void updateItem(QTreeWidgetItem *item, const QNetworkConfiguration &config)
{
    item->setText(0, config.name());
    item->setData(0, Qt::UserRole, config.identifier());

    QFont font = item->font(1);
    font.setBold((config.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active);
    item->setFont(0, font);
}
Example #22
0
Server::Server(/*  QWidget *parent  */)
:   /*QDialog(parent),*/ tcpServer(0), networkSession(0)
{
    //statusLabel = new QLabel;
    //quitButton = new QPushButton(tr("Quit"));
    //quitButton->setAutoDefault(false);

    QNetworkConfigurationManager manager;
    if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) {
        // Get saved network configuration
        QSettings settings(QSettings::UserScope, QLatin1String("QtProject"));
        settings.beginGroup(QLatin1String("QtNetwork"));
        const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString();
        settings.endGroup();

        // If the saved network configuration is not currently discovered use the system default
        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."));
        std::cout << "Opening network session." << std::endl;

        networkSession->open();
    } else {
        sessionOpened();
    }

        fortunes << tr("bla bla bue ee ee e e.")
                 << tr("You've got to think about tomorrow.")
                 << tr("You wi Q_OBJECTll be surprised by a loud noise.")
                 << tr("You will feel hungry again in another hour.")
                 << tr("You might have mail.")
                 << tr("You cannot kill time without injuring eternity.")
                 << tr("Computers are not intelligent. They only think they are.");

        ///connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
        connect(tcpServer, SIGNAL(newConnection()), this, SLOT(sendFortune()));

//        QHBoxLayout *buttonLayout = new QHBoxLayout;
//        buttonLayout->addStretch(1);
//        buttonLayout->addWidget(quitButton);
//        buttonLayout->addStretch(1);

//        QVBoxLayout *mainLayout = new QVBoxLayout;
//        mainLayout->addWidget(statusLabel);
//        mainLayout->addLayout(buttonLayout);
//        setLayout(mainLayout);

//        setWindowTitle(tr("Fortune Server"));
}
NetworkSessionManagerPrivate::NetworkSessionManagerPrivate(NetworkSessionManager *parent)
    : q_ptr(parent),
      networkSession(0),
#ifdef __ARMEL__
      isSessionReady(false)
#else
      isSessionReady(true)
#endif
{}

NetworkSessionManagerPrivate::~NetworkSessionManagerPrivate()
{
    if (networkSession)
        delete networkSession;
}

void NetworkSessionManagerPrivate::startSession()
{
    Q_Q(NetworkSessionManager);

#ifndef __ARMEL__
    emit q->sessionReady();
    return;
#endif

    if (networkSession && !isSessionReady) {
        networkSession->open();
    } else {

        QNetworkConfigurationManager manager;
        QNetworkConfiguration cfg = manager.defaultConfiguration();

        if (!cfg.isValid()) {
            QLatin1String msg("Network configuration manager -"
                          "invalid default configuration");
            qWarning() << msg;
            emit q->error(NetworkSessionManager::Configuration);
            return;
        }

        if (networkSession == 0) {
            networkSession = new QNetworkSession(cfg);

            connect(networkSession,
                    SIGNAL(error(QNetworkSession::SessionError)),
                    SLOT(sessionErrorHandler(QNetworkSession::SessionError)));
            connect(networkSession,
                    SIGNAL(stateChanged(QNetworkSession::State)),
                    SLOT(sessionStateHandler(QNetworkSession::State)));
            connect(networkSession, SIGNAL(opened()), SLOT(sessionOpened()));
        }

        // pops up connectivity if needed
        networkSession->open();
    }
}
Example #24
0
bool AutoConnect::init() {
    QList<QNetworkConfiguration> configurations = mManager.allConfigurations ( QNetworkConfiguration::Defined );

    QNetworkConfiguration config;
    foreach(config, configurations) {
        qDebug() << "Network: " << config.name();
        if (config.name() == mSSID) {
            mConnectConfig = config;
        }
    }
Example #25
0
RSSListing::RSSListing(QWidget *parent)
    : QWidget(parent), currentReply(0)
{
#ifdef Q_OS_SYMBIAN
    // Set Internet Access Point
    QNetworkConfigurationManager manager;
    const bool canStartIAP = manager.capabilities() & QNetworkConfigurationManager::CanStartAndStopInterfaces;

    // Is there default access point, use it
    QNetworkConfiguration cfg = manager.defaultConfiguration();
    if (!cfg.isValid() || !canStartIAP) {
        // Available Access Points not found
        QMessageBox::warning(this, "Error", "No access point");
        return;
    }

    m_session = new QNetworkSession(cfg);
    m_session->open();
    m_session->waitForOpened();
#endif

    lineEdit = new QLineEdit(this);
    lineEdit->setText("http://labs.qt.nokia.com/blogs/feed");

    fetchButton = new QPushButton(tr("Fetch"), this);

    treeWidget = new QTreeWidget(this);
    connect(treeWidget, SIGNAL(itemActivated(QTreeWidgetItem*,int)),
            this, SLOT(itemActivated(QTreeWidgetItem*)));
    QStringList headerLabels;
    headerLabels << tr("Title") << tr("Link");
    treeWidget->setHeaderLabels(headerLabels);
    treeWidget->header()->setResizeMode(QHeaderView::ResizeToContents);

    connect(&manager, SIGNAL(finished(QNetworkReply*)),
             this, SLOT(finished(QNetworkReply*)));

    connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(fetch()));
    connect(fetchButton, SIGNAL(clicked()), this, SLOT(fetch()));

    QVBoxLayout *layout = new QVBoxLayout(this);

    QHBoxLayout *hboxLayout = new QHBoxLayout;

    hboxLayout->addWidget(lineEdit);
    hboxLayout->addWidget(fetchButton);

    layout->addLayout(hboxLayout);
    layout->addWidget(treeWidget);

    setWindowTitle(tr("RSS listing example"));
#if !defined(Q_OS_SYMBIAN) && !defined(Q_WS_MAEMO_5)
    resize(640,480);
#endif
}
Example #26
0
MapZoom::MapZoom()
    : QMainWindow(0)
{
    map = new LightMaps(this);
    setCentralWidget(map);
    map->setFocus();

    QAction *osloAction = new QAction(tr("&Oslo"), this);
    QAction *berlinAction = new QAction(tr("&Berlin"), this);
    QAction *jakartaAction = new QAction(tr("&Jakarta"), this);
    QAction *nightModeAction = new QAction(tr("Night Mode"), this);
    nightModeAction->setCheckable(true);
    nightModeAction->setChecked(false);
    QAction *osmAction = new QAction(tr("About OpenStreetMap"), this);
    connect(osloAction, SIGNAL(triggered()), SLOT(chooseOslo()));
    connect(berlinAction, SIGNAL(triggered()), SLOT(chooseBerlin()));
    connect(jakartaAction, SIGNAL(triggered()), SLOT(chooseJakarta()));
    connect(nightModeAction, SIGNAL(triggered()), map, SLOT(toggleNightMode()));
    connect(osmAction, SIGNAL(triggered()), SLOT(aboutOsm()));

    QMenu *menu = menuBar()->addMenu(tr("&Options"));
    menu->addAction(osloAction);
    menu->addAction(berlinAction);
    menu->addAction(jakartaAction);
    menu->addSeparator();
    menu->addAction(nightModeAction);
    menu->addAction(osmAction);

    QNetworkConfigurationManager manager;
    if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) {
        // Get saved network configuration
        QSettings settings(QSettings::UserScope, QLatin1String("QtProject"));
        settings.beginGroup(QLatin1String("QtNetwork"));
        const QString id =
            settings.value(QLatin1String("DefaultNetworkConfiguration")).toString();
        settings.endGroup();

        // If the saved network configuration is not currently discovered use the system
        // default
        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()));

        networkSession->open();
    } else {
        networkSession = 0;
    }

    setWindowTitle(tr("Light Maps"));
}
Example #27
0
void FtpClient::init()
{
    qDebug() << "FtpClient:: " << port << " Init";
    // if we did not find one, use IPv4 localhost
    if (ipAddress.isEmpty())
        ipAddress = QHostAddress(QHostAddress::LocalHost).toString();

    qDebug() << "FtpClient:: " << port << " Init connect";
    // from abtractsocket
    connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),
            this, SLOT(handleError(QAbstractSocket::SocketError)));
    connect(tcpSocket, SIGNAL(connected()), this, SLOT(handleConnected()));
    connect(tcpSocket, SIGNAL(disconnected()), this, SLOT(handleDisconnected()));
    connect(tcpSocket, SIGNAL(hostFound()), this, SLOT(handleHostFound()));
    connect(tcpSocket, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&,QAuthenticator*)), this, SLOT(handleProxyAuthenticationRequired(const QNetworkProxy&,QAuthenticator*)));
    connect(tcpSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(handleStateChanged(QAbstractSocket::SocketState)));
    // from QIODevice
    connect(tcpSocket, SIGNAL(aboutToClose()), this, SLOT(handleAboutToClose()));
    connect(tcpSocket, SIGNAL(bytesWritten(qint64)), this, SLOT(handleBytesWritten(qint64)));
    connect(tcpSocket, SIGNAL(readChannelFinished()), this, SLOT(handleReadChannelFinished()));
    connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(handleReadyRead()));


    qDebug() << "FtpClient:: " << port << " Init NetworkConfigurationManager manager";
    QNetworkConfigurationManager manager;
    if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) {
        qDebug() << "FtpClient::Init QNetworkConfigurationManager::NetworkSessionRequired";
        // Get saved network configuration
        QSettings settings(QSettings::UserScope, QLatin1String(SETTING_STR));
        settings.beginGroup(QLatin1String("QtNetwork"));
        const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString();
        settings.endGroup();

        // If the saved network configuration is not currently discovered use the system default
        QNetworkConfiguration config = manager.configurationFromIdentifier(id);
        if ((config.state() & QNetworkConfiguration::Discovered) !=
            QNetworkConfiguration::Discovered) {
            config = manager.defaultConfiguration();
        }

        qDebug() << "FtpClient:: " << port << " Init new QNetworkSession(config, this)";
        networkSession = new QNetworkSession(config, this);
        qDebug() << "FtpClient:: " << port << " Init connect(networkSession, SIGNAL(opened()), this, SLOT(handleSessionOpened()))";
        connect(networkSession, SIGNAL(opened()), this, SLOT(handleSessionOpened()));

        qDebug() << "FtpClient:: " << port << " Init networkSession->open()";
        networkSession->open();
    } else {
        qDebug() << "FtpClient:: Init " << port << " tcpSocket->connectToHost())" << " ipAddress " << ipAddress << " port " << port;
        tcpSocket->connectToHost(QHostAddress(ipAddress),  port);
    }

    mInitiated = true;
}
Example #28
0
 int main(int argc, char *argv[])
 {
     QApplication app(argc, argv);

     QNetworkConfigurationManager manager;
     if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) {
         // Get saved network configuration
         QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
         settings.beginGroup(QLatin1String("QtNetwork"));
         const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString();
         settings.endGroup();

         // If the saved network configuration is not currently discovered use the system default
         QNetworkConfiguration config = manager.configurationFromIdentifier(id);
         if ((config.state() & QNetworkConfiguration::Discovered) !=
             QNetworkConfiguration::Discovered) {
             config = manager.defaultConfiguration();
         }

         QNetworkSession *networkSession = new QNetworkSession(config, &app);
         networkSession->open();
         networkSession->waitForOpened();

         if (networkSession->isOpen()) {
             // Save the used configuration
             QNetworkConfiguration config = networkSession->configuration();
             QString id;
             if (config.type() == QNetworkConfiguration::UserChoice) {
                 id = networkSession->sessionProperty(
                         QLatin1String("UserChoiceConfiguration")).toString();
             } else {
                 id = config.identifier();
             }

             QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
             settings.beginGroup(QLatin1String("QtNetwork"));
             settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id);
             settings.endGroup();
         }
     }

     //ChatDialog dialog;
     InitialWindow window;

 #ifdef Q_OS_SYMBIAN
     // Make application better looking and more usable on small screen
    // dialog.showMaximized();
 #else
  //   dialog.show();
     window.show();
 #endif
     return app.exec();
 }
Example #29
0
void GuiBehind::initConnection()
{
    // Connection
    QNetworkConfigurationManager manager;
    const bool canStartIAP = (manager.capabilities() & QNetworkConfigurationManager::CanStartAndStopInterfaces);
    QNetworkConfiguration cfg = manager.defaultConfiguration();
    if (!cfg.isValid() || (!canStartIAP && cfg.state() != QNetworkConfiguration::Active)) return;
    mNetworkSession = new QNetworkSession(cfg, this);
    connect(mNetworkSession, SIGNAL(opened()), this, SLOT(connectOpened()));
    connect(mNetworkSession, SIGNAL(error(QNetworkSession::SessionError)), this, SLOT(connectError(QNetworkSession::SessionError)));
    mNetworkSession->open();
}
Example #30
0
void Client::sessionOpened()
{
    // Save the used configuration
    QNetworkConfiguration config = networkSession->configuration();
    QString id;
    if (config.type() == QNetworkConfiguration::UserChoice)
        id = networkSession->sessionProperty(QLatin1String("UserChoiceConfiguration")).toString();
    else
        id = config.identifier();

    enableSendButton();
}