summaryrefslogtreecommitdiffstats
path: root/noatun/modules/net/net.cpp
blob: 5e3ba707e634be9da3e613efc024d26eec8feb8a (plain)
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
#include "net.h"
#include <noatun/player.h>
#include <noatun/app.h>

extern "C"
{
	KDE_EXPORT Plugin *create_plugin()
	{
		return new Net();
	}
}


Net::Net() : QServerSocket(7539, 10), Plugin()
{
	mFDs.setAutoDelete(true);
	connect(napp->player(), SIGNAL(newSong()), SLOT(newSong()));
}

Net::~Net()
{
}


void Net::newConnection(int fd)
{
	QSocket *s=new QSocket;
	s->setSocket(fd);
	mFDs.append(s);
}

void Net::newSong()
{
	if (!napp->player()->current())
		return;
		
	for (QSocket *i=mFDs.first(); i!=0; i=mFDs.next())
	{
		QCString line;
		line=napp->player()->current().title().latin1();
		line+='\n';
		::write(i->socket(), (const void*)line.data(), line.length());
	}
}

void Net::closed()
{
	for (QSocket *i=mFDs.first(); i!=0; i=mFDs.next())
	{
		if (sender()==i)
			mFDs.removeRef(i);
	}
}



#include "net.moc"