summaryrefslogtreecommitdiffstats
path: root/noatun/modules/infrared/infrared.cpp
blob: bd8a65bd41f8f018a4bd134093e4fcdcb79615a1 (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
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
112
113
114
115
116
117
118
119
120

#include <stdio.h>

#include <unistd.h>
#include <noatun/player.h>
#include <noatun/app.h>

#include <tdelocale.h>
#include <tqtimer.h>

#include "infrared.h"
#include "lirc.h"
#include "irprefs.h"

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


InfraRed::InfraRed()
	: TQObject(),
	  Plugin()
{
	NOATUNPLUGINC(InfraRed);
	m_lirc = new Lirc(this);
	connect(m_lirc,
	        TQT_SIGNAL(commandReceived(const TQString &, const TQString &, int)),
	        TQT_SLOT(slotCommand(const TQString &, const TQString &, int)));

	IRPrefs::s_lirc = m_lirc;
	volume=0;
	TQTimer::singleShot(0, this, TQT_SLOT(start()));
}

InfraRed::~InfraRed()
{
}

void InfraRed::start()
{
	new IRPrefs(this);
}

void InfraRed::slotCommand(const TQString &remote, const TQString &button, int repeat)
{
	switch (IRPrefs::actionFor(remote, button, repeat))
	{
	case IRPrefs::None:
		break;
	
	case IRPrefs::Play:
		napp->player()->play();
		break;
	
	case IRPrefs::Stop:
		napp->player()->stop();
		break;
	
	case IRPrefs::Pause:
		napp->player()->playpause();
		break;
	
	case IRPrefs::Mute:
		if (napp->player()->volume())
		{
			volume=napp->player()->volume();
			napp->player()->setVolume(0);
		}
		else
		{
			napp->player()->setVolume(volume);
		}
		break;
	
	case IRPrefs::Previous:
		napp->player()->back();
		break;
	
	case IRPrefs::Next:
		napp->player()->forward();
		break;
	
	case IRPrefs::VolumeDown:
		napp->player()->setVolume(napp->player()->volume() - 4);
		break;
	
	case IRPrefs::VolumeUp:
		napp->player()->setVolume(napp->player()->volume() + 4);
		break;

	case IRPrefs::SeekBackward:  // - 3 seconds
		napp->player()->skipTo( TQMAX(0, napp->player()->getTime() - 3000) );
		break;

	case IRPrefs::SeekForward:  // + 3 seconds
		napp->player()->skipTo( TQMIN(napp->player()->getLength(),
		                             napp->player()->getTime() + 3000) );
		break;
	case IRPrefs::ShowPlaylist:
		napp->player()->toggleListView();
		break;
	case IRPrefs::NextSection:
		// This and the next case theoretically shouldn't bypass player()
		// but I'm making this change as inobtrusive as possible. That
		// means restricting the change to infrared and not messing around
		// in libnoatun -- Neil
		napp->playlist()->nextSection();
		break;
	case IRPrefs::PreviousSection:
		napp->playlist()->previousSection();
		break;
	}
}

#include "infrared.moc"