summaryrefslogtreecommitdiff
path: root/FoxOperatorActions.hpp
blob: d104b6a24f869c4e3a4fdc09972d931b03c8567b (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
#ifndef FOX_OPERATOR_ACTIONS_HPP
#define FOX_OPERATOR_ACTIONS_HPP

#include <QQueue>
#include <QString>

namespace FoxOperatorActions
{
  inline QString callsign (QString const& line)
  {
    return line.left (12).trimmed ();
  }

  inline int queuedHoundIndex (QQueue<QString> const& queue, QString const& line)
  {
    auto const target = callsign (line);
    if (target.isEmpty ()) return -1;

    for (int index = 0; index < queue.size (); ++index)
      {
        if (callsign (queue.at (index)) == target) return index;
      }
    return -1;
  }

  inline bool moveQueuedHoundToFront (QQueue<QString>& queue, QString const& line)
  {
    auto const index = queuedHoundIndex (queue, line);
    if (index < 0) return false;

    if (index > 0)
      {
        auto const live_line = queue.takeAt (index);
        queue.prepend (live_line);
      }
    return true;
  }

  inline bool removeQueuedHound (QQueue<QString>& queue, QString const& line)
  {
    auto const target = callsign (line);
    if (target.isEmpty ()) return false;

    bool removed {false};
    for (int index = queue.size () - 1; index >= 0; --index)
      {
        if (callsign (queue.at (index)) == target)
          {
            queue.removeAt (index);
            removed = true;
          }
      }
    return removed;
  }

  template<typename QsoMap>
  bool timeoutIfActive (QQueue<QString> const& in_progress, QsoMap& qsos,
                        QString const& line, int timeout_value)
  {
    auto const target = callsign (line);
    if (target.isEmpty () || !in_progress.contains (target)) return false;

    auto qso = qsos.find (target);
    if (qso == qsos.end ()) return false;

    qso.value ().ncall = timeout_value;
    return true;
  }
}

#endif // FOX_OPERATOR_ACTIONS_HPP