You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
184 lines
4.6 KiB
184 lines
4.6 KiB
15 years ago
|
/***************************************************************************
|
||
|
standardscandialog.cpp - description
|
||
|
-------------------
|
||
|
begin : Son Aug 3 2003
|
||
|
copyright : (C) 2003 by Martin Witte
|
||
|
email : witte@kawo1.rwth-aachen.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; either version 2 of the License, or *
|
||
|
* (at your option) any later version. *
|
||
|
* *
|
||
|
***************************************************************************/
|
||
|
|
||
|
#include "include/standardscandialog.h"
|
||
|
#include "include/radiostation.h"
|
||
|
|
||
14 years ago
|
#include <tqprogressbar.h>
|
||
|
#include <tqlabel.h>
|
||
|
#include <tqpushbutton.h>
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdelocale.h>
|
||
15 years ago
|
|
||
|
#include <math.h>
|
||
|
|
||
13 years ago
|
StandardScanDialog::StandardScanDialog(TQWidget *parent)
|
||
|
: StandardScanDialogUI(parent, NULL, true),
|
||
15 years ago
|
m_count(0),
|
||
|
m_running(false),
|
||
|
m_oldPowerOn(false),
|
||
|
m_oldStation(NULL),
|
||
|
m_ignorePower(false)
|
||
|
{
|
||
14 years ago
|
TQObject::connect(buttonCancel, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotCancelDone()));
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
|
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();
|
||
13 years ago
|
m_startTime = TQDateTime::currentDateTime();
|
||
15 years ago
|
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;
|
||
14 years ago
|
TQString s;
|
||
15 years ago
|
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) {
|
||
13 years ago
|
int secs = m_startTime.secsTo(TQDateTime::currentDateTime());
|
||
15 years ago
|
int ms = (int)rint((1 - f) * (float) secs / f * 1000.0);
|
||
|
|
||
|
if (ms > 0 && ms < 86400000) // max one day
|
||
13 years ago
|
labelTime->setText(i18n("<p align=\"right\">%1</p>").arg(TQTime(0,0).addMSecs(ms).toString()));
|
||
15 years ago
|
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"
|