1 /* -*- c++ -*- */
2 /*
3 * Gqrx SDR: Software defined radio receiver powered by GNU Radio and Qt
4 * https://gqrx.dk/
5 *
6 * Copyright 2020 Oliver Grossmann.
7 *
8 * Gqrx is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3, or (at your option)
11 * any later version.
12 *
13 * Gqrx is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with Gqrx; see the file COPYING. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street,
21 * Boston, MA 02110-1301, USA.
22 */
23 #include <Qt>
24 #include <QFile>
25 #include <QStringList>
26 #include <QTextStream>
27 #include <QString>
28 #include <QSet>
29 #include <QTimer>
30 #include <algorithm>
31 #include "dxc_spots.h"
32 #include <stdio.h>
33 #include <wchar.h>
34
35 DXCSpots* DXCSpots::m_pThis = 0;
36
DXCSpots()37 DXCSpots::DXCSpots()
38 {
39 }
40
create()41 void DXCSpots::create()
42 {
43 m_pThis = new DXCSpots;
44 }
45
Get()46 DXCSpots& DXCSpots::Get()
47 {
48 return *m_pThis;
49 }
50
add(DXCSpotInfo & info)51 void DXCSpots::add(DXCSpotInfo &info)
52 {
53 info.time = QTime::currentTime();
54 // check only callsign, so if present remove and re-append
55 // if check also frequency we can only change the time
56 if (m_DXCSpotList.contains(info))
57 m_DXCSpotList.removeAt(m_DXCSpotList.indexOf(info));
58 m_DXCSpotList.append(info);
59 std::stable_sort(m_DXCSpotList.begin(),m_DXCSpotList.end());
60 emit( dxcSpotsUpdated() );
61 QTimer::singleShot(m_DXCSpotTimeout * 1000, this, SLOT(checkSpotTimeout()));
62 }
63
checkSpotTimeout()64 void DXCSpots::checkSpotTimeout()
65 {
66 for (int i = 0; i < m_DXCSpotList.size(); i++)
67 {
68 if ( m_DXCSpotTimeout <= m_DXCSpotList[i].time.secsTo(QTime::currentTime() ))
69 {
70 m_DXCSpotList.removeAt(i);
71 }
72 }
73 std::stable_sort(m_DXCSpotList.begin(),m_DXCSpotList.end());
74 emit( dxcSpotsUpdated() );
75 }
76
getDXCSpotsInRange(qint64 low,qint64 high)77 QList<DXCSpotInfo> DXCSpots::getDXCSpotsInRange(qint64 low, qint64 high)
78 {
79 DXCSpotInfo info;
80 info.frequency=low;
81 QList<DXCSpotInfo>::const_iterator lb = std::lower_bound(m_DXCSpotList.begin(), m_DXCSpotList.end(), info);
82 info.frequency=high;
83 QList<DXCSpotInfo>::const_iterator ub = std::upper_bound(m_DXCSpotList.begin(), m_DXCSpotList.end(), info);
84
85 QList<DXCSpotInfo> found;
86
87 while (lb != ub)
88 {
89 const DXCSpotInfo& info = *lb;
90 found.append(info);
91 lb++;
92 }
93
94 return found;
95 }
96
GetColor() const97 const QColor DXCSpotInfo::GetColor() const
98 {
99 return DXCSpotInfo::color;
100 }
101