~mateo-salta/nitroshare/nitroshare

« back to all changes in this revision

Viewing changes to src/widgets/CBroadcastDiscoveryWidget.cpp

  • Committer: Nathan Osman
  • Date: 2012-06-29 23:22:49 UTC
  • Revision ID: admin@quickmediasolutions.com-20120629232249-17eu8xp4ta0ooqyp
Finished implementing broadcast discovery page in wizard.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
   You should have received a copy of the GNU General Public License
15
15
   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
16
 
 
17
#include <QDebug>
 
18
#include <QPixmap>
 
19
 
17
20
#include <util/network.h>
18
21
#include <widgets/CBroadcastDiscoveryWidget.h>
19
22
#include "ui_CBroadcastDiscoveryWidget.h"
34
37
 
35
38
void CBroadcastDiscoveryWidget::StartBroadcasting()
36
39
{
37
 
    ui->DiscoveryLabel->setText(tr("Broadcast discovery in progress..."));
 
40
    /* We may already be broadcasting, so stop. */
 
41
    StopBroadcasting();
 
42
 
 
43
    qDebug() << "Started broadcasting on all network interfaces.";
 
44
    ui->DiscoveryLabel->setText(tr("Searching for other machines..."));
 
45
 
 
46
    /* Listen for any incoming pings. */
 
47
    m_listener = new CBasicListener;
 
48
    connect(m_listener, SIGNAL(Ping(QHostAddress,QVariantMap)), SLOT(OnPing(QHostAddress)));
 
49
 
 
50
    m_listener->Init();
38
51
 
39
52
    /* For each of the usable network interfaces, create a broadcaster
40
53
       that immediately begins listening / broadcasting. */
46
59
 
47
60
        m_broadcasters.append(broadcaster);
48
61
    }
49
 
 
50
 
    /* And we also listen for any incoming pings. */
51
 
    m_listener = new CBasicListener;
52
 
    connect(m_listener, SIGNAL(Ping(QHostAddress,QByteArray)), SLOT(OnPing(QHostAddress)));
53
 
 
54
 
    m_listener->Init();
55
62
}
56
63
 
57
64
void CBroadcastDiscoveryWidget::StopBroadcasting()
58
65
{
 
66
    qDebug() << "Stopped broadcasting on all network interfaces.";
 
67
 
59
68
    /* Free all of the broadcasters and the listener. */
60
69
    qDeleteAll(m_broadcasters);
 
70
    m_broadcasters.clear();
61
71
 
62
72
    if(m_listener)
63
73
    {
73
83
    foreach(CBasicBroadcaster * broadcaster, m_broadcasters)
74
84
        if(broadcaster->HasAddress(address))
75
85
        {
76
 
            ui->DiscoveryLabel->setText(tr("Found interface broadcasting to us."));
 
86
            ui->DiscoveryStatus->setPixmap(QPixmap(":/images/success.png"));
 
87
            ui->DiscoveryLabel->setText(tr("Network discovery complete!"));
 
88
 
 
89
            m_interface = broadcaster->GetName();
77
90
        }
78
91
}