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
179
180
181
182
183
|
/***************************************************************************
standardscandialog.cpp - description
-------------------
begin : Son Aug 3 2003
copyright : (C) 2003 by Martin Witte
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#include "include/standardscandialog.h"
#include "include/radiostation.h"
#include <tqprogressbar.h>
#include <tqlabel.h>
#include <tqpushbutton.h>
#include <klocale.h>
#include <math.h>
StandardScanDialog::StandardScanDialog(TQWidget *parent)
: StandardScanDialogUI(parent, NULL, true),
m_count(0),
m_running(false),
m_oldPowerOn(false),
m_oldStation(NULL),
m_ignorePower(false)
{
TQObject::connect(buttonCancel, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotCancelDone()));
}
StandardScanDialog::~StandardScanDialog()
{
stop();
}
bool StandardScanDialog::connectI (Interface *i)
{
bool a = ISeekRadioClient::connectI(i);
// bool b = IRadioSoundClient::connectI(i);
bool c = IRadioClient::connectI(i);
return a || /*b ||*/ c;
}
bool StandardScanDialog::disconnectI (Interface *i)
{
bool a = ISeekRadioClient::disconnectI(i);
// bool b = IRadioSoundClient::disconnectI(i);
bool c = IRadioClient::disconnectI(i);
return a || /*b ||*/ c;
}
void StandardScanDialog::start()
{
if (!m_running) {
m_running = true;
m_stations.all().clear();
m_startTime = TQDateTime::currentDateTime();
m_oldPowerOn = queryIsPowerOn();
m_oldStation = queryCurrentStation().copy();
sendToBeginning();
m_ignorePower = true;
sendPowerOn();
m_ignorePower = false;
sendStartSeekUp();
}
}
void StandardScanDialog::stop()
{
if (m_running) {
m_running = false;
sendStopSeek();
if (!m_oldPowerOn) sendPowerOff();
sendActivateStation(*m_oldStation);
delete m_oldStation;
m_oldStation = NULL;
}
}
bool StandardScanDialog::noticePowerChanged(bool on)
{
if (!on && !m_ignorePower) {
stop();
}
return true;
}
bool StandardScanDialog::noticeSeekStarted (bool /*up*/)
{
return false;
}
bool StandardScanDialog::noticeSeekFinished (const RadioStation &, bool goodQuality)
{
if (goodQuality) {
++m_count;
TQString s;
s.setNum(m_count);
RadioStation *st = queryCurrentStation().copy();
if (st->name().isNull()) {
st->setName(i18n("new station ") + s);
st->setShortName(s);
st->generateNewStationID();
}
int oldcount = m_stations.count();
m_stations.all().append(st);
if (oldcount != m_stations.count()) {
} else {
--m_count;
}
delete st;
}
if (rint(queryProgress() * 1000) < 1000) { // round to 4 digits
if (m_running) sendStartSeekUp();
}
return true;
}
bool StandardScanDialog::noticeSeekStopped ()
{
if (rint(queryProgress() * 1000) >= 1000) { // round to 4 digits
buttonCancel->setText(i18n("&Done"));
stop();
}
return true;
}
bool StandardScanDialog::noticeProgress (float f)
{
if (!m_running) return true;
progressBar->setProgress((int)rint(f * 100));
if (m_running) {
int secs = m_startTime.secsTo(TQDateTime::currentDateTime());
int ms = (int)rint((1 - f) * (float) secs / f * 1000.0);
if (ms > 0 && ms < 86400000) // max one day
labelTime->setText(i18n("<p align=\"right\">%1</p>").arg(TQTime(0,0).addMSecs(ms).toString()));
else
labelTime->setText(i18n("unknown"));
} else {
labelTime->setText(i18n("unknown"));
}
return true;
}
void StandardScanDialog::slotCancelDone()
{
if (m_running) {
stop();
reject();
} else {
accept();
}
}
#include "standardscandialog.moc"
|