1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
/***************************************************************************
* Copyright (C) 2006 by Ivan Vasić *
* ivasic@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include "addpeerwidget.h"
#include <util/constants.h>
#include <interfaces/torrentinterface.h>
#include <klocale.h>
#include <ksqueezedtextlabel.h>
#include <klineedit.h>
#include <knuminput.h>
#include <kmessagebox.h>
#include <qstring.h>
#include <qstringlist.h>
#include <qregexp.h>
#include <qvalidator.h>
using namespace kt;
using bt::Uint16;
//PeerSource
ManualPeerSource::ManualPeerSource()
{}
void ManualPeerSource::start()
{}
void ManualPeerSource::stop(bt::WaitJob* )
{}
ManualPeerSource::~ ManualPeerSource()
{}
void ManualPeerSource::signalPeersReady()
{
peersReady(this);
}
//AddPeerWidget
AddPeerWidget::AddPeerWidget(kt::TorrentInterface* tc, QWidget *parent, const char *name)
:AddPeerWidgetBase(parent, name), m_tc(tc)
{
if(!tc)
{
//oops, something went wrong...
m_status->setText(i18n("Torrent does not exist. Report this bug to KTorrent developers."));
m_ip->setEnabled(false);
m_port->setEnabled(false);
return;
}
m_peerSource = new ManualPeerSource();
//Register this peer source with ps manager.
m_tc->addPeerSource(m_peerSource);
}
AddPeerWidget::~ AddPeerWidget()
{
//Unregister this peer source with ps manager.
m_tc->removePeerSource(m_peerSource);
delete m_peerSource;
}
void AddPeerWidget::btnAdd_clicked()
{
int var=0;
QRegExp rx("[0-9]{1,3}(.[0-9]{1,3}){3,3}");
QRegExpValidator v( rx,0);
QString ip = m_ip->text();
if(v.validate( ip, var ) == QValidator::Acceptable)
{
m_peerSource->addPeer(ip, m_port->value());
m_peerSource->signalPeersReady();
m_status->setText(i18n("Potential peer added."));
}
else
{
KMessageBox::sorry(0, i18n("Malformed IP address."));
m_status->setText("");
}
}
#include "addpeerwidget.moc"
|