File: QTVConfigImpl.cpp

package info (click to toggle)
dvr 3.2-8
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 896 kB
  • ctags: 394
  • sloc: cpp: 3,192; makefile: 134; sh: 100; yacc: 39
file content (178 lines) | stat: -rw-r--r-- 4,980 bytes parent folder | download
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*********************************************************************************************************
DVR, Digital Video Recorder - a tool to record movies (audio/video), using realtime compression

It uses libavifile (see http://divx.euro.ru) and some code from kwintv (see wenk@mathematik.uni-kl.de)

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, etc.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY, etc.

copyright(C) february 2001, Pierre Hbert (pierre.hebert@netcourrier.com)
*********************************************************************************************************/
#include <iostream>
#include <qradiobutton.h>
#include <qlayout.h>
#include <qbuttongroup.h>
#include <qlineedit.h>
#include <qlistbox.h>
#include <qlabel.h>

#include "QTVConfigImpl.h"
#include "v4l.h"

QTVConfigImpl::QTVConfigImpl( QWidget* parent,  const char* name) : QTVConfig( parent, name ) {}


void QTVConfigImpl::setV4L(V4L *v) {
  v4l=v;
  buttons=new QRadioButton*[v4l->videoChannels().size()];
  qbg_video_source->setColumnLayout(0, Qt::Vertical );
  QVBoxLayout *qbg_video_sourceLayout = new QVBoxLayout( qbg_video_source->layout() );

  qbg_video_sourceLayout->setAlignment( Qt::AlignTop );
  qbg_video_sourceLayout->setSpacing( 6 );
  qbg_video_sourceLayout->setMargin( 11 );

  for(unsigned long c=0; c<v4l->videoChannels().size(); c++) {
		buttons[c]=new QRadioButton(qbg_video_source, QString(v4l->videoChannels()[c].name));
		buttons[c]->setText(QString(v4l->videoChannels()[c].name));
		buttons[c]->setBackgroundOrigin(ParentOrigin);
		connect(buttons[c], SIGNAL(clicked()), this, SLOT(changeParameter()));
		qbg_video_sourceLayout->addWidget(buttons[c]);
		if(v4l->currentVideoChannel()==c) buttons[c]->toggle();
	}

	QRadioButton *b[4]={ qrb_pal, qrb_ntsc, qrb_secam, qrb_auto };
	for(int c=0; c<4; c++) {
		if(v4l->videoChannels()[v4l->currentVideoChannel()].norm==c) {
      b[c]->toggle();
      break;
    }
	}

	QString d;
	d.sprintf("%s (%s)", v->deviceName().c_str(), v->deviceFileName().c_str());
	qlb_video_device->setText(d);
}

/*  
 *  Destroys the object and frees any allocated resources
 */
QTVConfigImpl::~QTVConfigImpl()
{
    // no need to delete child widgets, Qt does it all for us
}

void QTVConfigImpl::setChannelList(QList<pair<QString*, unsigned long> > *cl, const QString &cc) {
	unsigned long freq;
  if(v4l->hasTuner()) {
    freq=v4l->tunerFrequency();
  } else {
    freq=0;
  }
	
	channels=cl;
	current_channel=cc;
	pair<QString*, unsigned long> *e;
	for(e=channels->first(); e!=0; e=channels->next()) {
		qlb_channels->insertItem(*(e->first));
		if(freq==e->second) {
			qle_channel_name->setText(current_channel);
		}
	}
	
	qlb_channels->sort();
}

int QTVConfigImpl::getChannel() const {
	for(unsigned long c=0; c<v4l->videoChannels().size(); c++) {
		if(buttons[c]->isChecked()) return c;
	}
	return 0;
}

int QTVConfigImpl::getNorm() const {
	QRadioButton *b[4]={ qrb_pal, qrb_ntsc, qrb_secam, qrb_auto };
	for(int c=0; c<4; c++) {
		if(b[c]->isChecked()) return c;
	}
	return 0;
}

void QTVConfigImpl::changeParameter() {
	emit(parameterChanged());
}

void QTVConfigImpl::addCurrentChannel() {
	unsigned long freq=v4l->tunerFrequency();
	
	pair<QString*, unsigned long> *e;
	bool found=false;
	for(e=channels->first(); e!=0; e=channels->next()) {
		if(e->second==freq) {
			//new element
			pair<QString*, unsigned long> *n=new pair<QString*, unsigned long>;
			n->first=new QString(qle_channel_name->text());
			n->second=freq;
			
			//update the list box
			for(unsigned int i=0; i<qlb_channels->count(); i++) {
				if(qlb_channels->text(i)==*(e->first)) {
					qlb_channels->removeItem(i);
					qlb_channels->insertItem(*(n->first));
					break;
				}
			}
			
			//update the channel list
			delete e->first;
			channels->remove(e);
			channels->append(n);
			
			found=true;
			break;
		}
	}
	if(!found) {
		e=new pair<QString*, unsigned long>;
		e->first=new QString(qle_channel_name->text());
		e->second=freq;
		channels->append(e);
		qlb_channels->insertItem(*(e->first));
	}
	
	qlb_channels->sort();
}

void QTVConfigImpl::removeCurrentChannel() {
	pair<QString*, unsigned long> *e;
	for(e=channels->first(); e!=0; e=channels->next()) {
		if(*(e->first)==qle_channel_name->text()) {
			delete e->first;
			channels->remove();
			break;
		}
	}
	
	for(unsigned int i=0; i<qlb_channels->count(); i++) {
		if(qlb_channels->text(i)==qle_channel_name->text()) {
			qlb_channels->removeItem(i);
			break;
		}
	}
	
	qlb_channels->sort();
}

void QTVConfigImpl::changeChannel(const QString &channel_name) {
	pair<QString*, unsigned long> *e;
	for(e=channels->first(); e!=0; e=channels->next()) {
		if(*(e->first)==channel_name) {
			current_channel=channel_name;
      if(v4l->hasTuner()) {
        v4l->setTunerFrequency(e->second);
      }
			break;
		}
	}
}