AccountManager::AccountManager() : QObject( qApp ), d(new Private()) { setObjectName( "KopeteAccountManager" ); connect( Solid::Networking::notifier(), SIGNAL(shouldConnect()), this, SLOT(networkConnected()) ); connect( Solid::Networking::notifier(), SIGNAL(shouldDisconnect()), this, SLOT(networkDisconnected()) ); connect( Solid::PowerManagement::notifier(), SIGNAL(resumingFromSuspend()), this, SLOT(resume()) ); #ifdef __GNUC__ #warning TODO: Switch to a org.kde.Solid.PowerManagement Sleeping/Suspending signal when available. #endif QDBusConnection::systemBus().connect( "org.freedesktop.UPower", "/org/freedesktop/UPower", "", "Sleeping", this, SLOT( suspend() ) ); d->suspended = false; }
TestClient::TestClient() : KMainWindow( 0 ), m_status( AppDisconnected ), m_view( new QWidget( this ) ) { ui.setupUi( m_view ); setCentralWidget(m_view); networkStatusChanged( Solid::Networking::status() ); appDisconnected(); kDebug() << "About to connect"; connect( Solid::Networking::notifier(), SIGNAL(statusChanged(Solid::Networking::Status)), SLOT(networkStatusChanged(Solid::Networking::Status)) ); kDebug() << "Connected."; connect( Solid::Networking::notifier(), SIGNAL(shouldConnect()), this, SLOT(doConnect()) ); connect( Solid::Networking::notifier(), SIGNAL(shouldDisconnect()), this, SLOT(doDisconnect()) ); connect( ui.connectButton, SIGNAL(clicked()), SLOT(connectButtonClicked()) ); }
int tr_trackerPulse( tr_tracker_t * tc ) { tr_torrent_t * tor = tc->tor; tr_info_t * inf = &tor->info; uint64_t now = tr_date(); if( ( tc->status & TC_STATUS_IDLE ) && shouldConnect( tc ) ) { tc->resolve = tr_netResolveInit( inf->trackerAddress ); tr_inf( "Tracker: connecting to %s:%d (%s)", inf->trackerAddress, inf->trackerPort, tc->started ? "sending 'started'" : ( tc->completed ? "sending 'completed'" : ( tc->stopped ? "sending 'stopped'" : ( 0 < tc->newPort ? "sending 'stopped' to change port" : "getting peers" ) ) ) ); tc->status = TC_STATUS_RESOLVE; tc->dateTry = tr_date(); } if( tc->status & TC_STATUS_RESOLVE ) { int ret; struct in_addr addr; ret = tr_netResolvePulse( tc->resolve, &addr ); if( ret == TR_RESOLVE_WAIT ) { return 0; } else { tr_netResolveClose( tc->resolve ); } if( ret == TR_RESOLVE_ERROR ) { tc->status = TC_STATUS_IDLE; return 0; } if( tr_fdSocketWillCreate( tor->fdlimit, 1 ) ) { tc->status = TC_STATUS_IDLE; return 0; } tc->socket = tr_netOpen( addr, htons( inf->trackerPort ) ); if( tc->socket < 0 ) { tr_fdSocketClosed( tor->fdlimit, 1 ); tc->status = TC_STATUS_IDLE; return 0; } tc->status = TC_STATUS_CONNECT; } if( tc->status & TC_STATUS_CONNECT ) { /* We are connecting to the tracker. Try to send the query */ sendQuery( tc ); } if( tc->status & TC_STATUS_RECV ) { /* Try to get something */ recvAnswer( tc ); } if( tc->status > TC_STATUS_IDLE && now > tc->dateTry + 60000 ) { /* Give up if the request wasn't successful within 60 seconds */ tr_inf( "Tracker: timeout reached (60 s)" ); tr_netClose( tc->socket ); tr_fdSocketClosed( tor->fdlimit, 1 ); tc->status = TC_STATUS_IDLE; tc->dateTry = tr_date(); } return 0; }