File: logbook.cpp

package info (click to toggle)
js8call 2.5.2%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,720 kB
  • sloc: cpp: 562,651; sh: 898; python: 132; ansic: 102; makefile: 4
file content (115 lines) | stat: -rw-r--r-- 2,934 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
#include "logbook.h"
#include <QDebug>
#include <QFontMetrics>
#include <QStandardPaths>
#include <QDir>

namespace
{
  auto logFileName = "js8call_log.adi";
  auto countryFileName = "cty.dat";
}

void LogBook::init()
{
  QDir dataPath {QStandardPaths::writableLocation (QStandardPaths::AppLocalDataLocation)};
  QString countryDataFilename;
  if (dataPath.exists (countryFileName))
    {
      // User override
      countryDataFilename = dataPath.absoluteFilePath (countryFileName);
    }
  else
    {
      countryDataFilename = QString {":/"} + countryFileName;
    }

  _countries.init(countryDataFilename);
  _countries.load();

  _worked.init(_countries.getCountryNames());

  _log.init(dataPath.absoluteFilePath (logFileName));
  _log.load();

  _setAlreadyWorkedFromLog();
}


void LogBook::_setAlreadyWorkedFromLog()
{
  QList<QString> calls = _log.getCallList();
  QString c;
  foreach(c,calls)
    {
      QString countryName = _countries.find(c);
      if (countryName.length() > 0)
        {
          _worked.setAsWorked(countryName);
        }
    }
}

bool LogBook::hasWorkedBefore(const QString &call, const QString &band){
    return _log.match(call, band);
}

void LogBook::match(/*in*/const QString call,
                    /*out*/ QString &countryName,
                    bool &callWorkedBefore,
                    bool &countryWorkedBefore) const
{
    if(call.isEmpty()){
        return;
    }

    QString currentBand = "";  // match any band
    callWorkedBefore = _log.match(call, currentBand);
    countryName = _countries.find(call);

    if (countryName.length() > 0){  //  country was found
        countryWorkedBefore = _worked.getHasWorked(countryName);
    } else {
        countryName = "where?"; //error: prefix not found
        countryWorkedBefore = false;
    }
}

bool LogBook::findCallDetails(
                    /*in*/
                    const QString call,
                    /*out*/
                    QString &grid,
                    QString &date,
                    QString &name,
                    QString &comment) const
{
    if(call.isEmpty()){
        return false;
    }

    auto qsos = _log.find(call);
    if(qsos.isEmpty()){
        return false;
    }

    foreach(auto qso, qsos){
        if(grid.isEmpty() && !qso.grid.isEmpty()) grid = qso.grid;
        if(date.isEmpty() && !qso.date.isEmpty()) date = qso.date;
        if(name.isEmpty() && !qso.name.isEmpty()) name = qso.name;
        if(comment.isEmpty() && !qso.comment.isEmpty()) comment = qso.comment;
    }

    return true;
}

void LogBook::addAsWorked(const QString call, const QString band, const QString mode, const QString submode, const QString grid, const QString date, const QString name, const QString comment)
{
  _log.add(call,band,mode,submode,grid,date,name,comment);
  QString countryName = _countries.find(call);
  if (countryName.length() > 0)
    _worked.setAsWorked(countryName);
}