~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to noatun/noatun/modules/net/net.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "net.h"
 
2
#include <player.h>
 
3
#include <noatunapp.h>
 
4
 
 
5
extern "C"
 
6
{
 
7
        Plugin *create_plugin()
 
8
        {
 
9
                return new Net();
 
10
        }
 
11
}
 
12
 
 
13
 
 
14
Net::Net() : QServerSocket(7539, 10), Plugin()
 
15
{
 
16
        NOATUNPLUGINC(Net);
 
17
        mFDs.setAutoDelete(true);
 
18
        connect(napp->player(), SIGNAL(newSong()), SLOT(newSong()));
 
19
}
 
20
 
 
21
Net::~Net()
 
22
{
 
23
}
 
24
 
 
25
 
 
26
void Net::newConnection(int fd)
 
27
{
 
28
        QSocket *s=new QSocket;
 
29
        s->setSocket(fd);
 
30
        mFDs.append(s);
 
31
}
 
32
 
 
33
void Net::newSong()
 
34
{
 
35
        if (!napp->player()->current())
 
36
                return;
 
37
                
 
38
        for (QSocket *i=mFDs.first(); i!=0; i=mFDs.next())
 
39
        {
 
40
                QCString line;
 
41
                line=napp->player()->current()->title().latin1();
 
42
                line+='\n';
 
43
                ::write(i->socket(), (const void*)line.data(), line.length());
 
44
        }
 
45
}
 
46
 
 
47
void Net::closed()
 
48
{
 
49
        for (QSocket *i=mFDs.first(); i!=0; i=mFDs.next())
 
50
        {
 
51
                if (sender()==i)
 
52
                        mFDs.removeRef(i);
 
53
        }
 
54
}
 
55
 
 
56
 
 
57
 
 
58
#include "net.moc"