diff --git a/googletakeout.cc b/googletakeout.cc index eb061239d..5ba243c83 100644 --- a/googletakeout.cc +++ b/googletakeout.cc @@ -40,24 +40,17 @@ #include "src/core/file.h" // for File #include "src/core/logging.h" // for Debug, FatalMsg, Warning -#define MYNAME "Google Takeout" -#define TIMELINE_OBJECTS "timelineObjects" -static const QList takeout_month_names{ - "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", - "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER" -}; - -static void takeout_fatal(const QString& message) { +void GoogleTakeoutFormat::takeout_fatal(const QString& message) { fatal(FatalMsg() << MYNAME << ": " << message); } -static void takeout_warning(const QString& message) { +void GoogleTakeoutFormat::takeout_warning(const QString& message) { Warning() << MYNAME << ": " << message; } /* create a waypoint from late7/lone7 and optional metadata */ -static Waypoint* takeout_waypoint( +Waypoint* GoogleTakeoutFormat::takeout_waypoint( int lat_e7, int lon_e7, const QString* shortname, @@ -81,7 +74,7 @@ static Waypoint* takeout_waypoint( return waypoint; } -static bool track_maybe_add_wpt(route_head* route, Waypoint* waypoint) { +bool GoogleTakeoutFormat::track_maybe_add_wpt(route_head* route, Waypoint* waypoint) { if (waypoint->latitude == 0 && waypoint->longitude == 0) { if (global_opts.debug_level >= 2) { Debug(2) << "Track " << route->rte_name << "@" << @@ -95,7 +88,7 @@ static bool track_maybe_add_wpt(route_head* route, Waypoint* waypoint) { return true; } -static QList readJson( +QList GoogleTakeoutFormat::GoogleTakeoutInputStream::readJson( const QString& source) { if (global_opts.debug_level >= 2) { @@ -142,7 +135,7 @@ static QList readJson( return timeline; } -static QList readDir( +QList GoogleTakeoutFormat::GoogleTakeoutInputStream::readDir( const QString& source) { if (global_opts.debug_level >= 2) { @@ -158,6 +151,10 @@ static QList readDir( * folders */ if (baseName.length() == 4 && baseName.toInt() > 0) { + static const QList takeout_month_names{ + "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", + "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER" + }; for (auto&& month : takeout_month_names) { const QString path = source + "/" + baseName + "_" + month + ".json"; const QFileInfo info{path}; @@ -337,7 +334,6 @@ GoogleTakeoutFormat::add_activity_segment(const QJsonObject& activitySegment) * TODO: do something with simplifiedRawPath */ int n_points = 0; - Waypoint* waypoint = nullptr; auto* route = new route_head; const QJsonObject startLoc = activitySegment[START_LOCATION].toObject(); const QJsonObject endLoc = activitySegment[END_LOCATION].toObject(); @@ -347,7 +343,7 @@ GoogleTakeoutFormat::add_activity_segment(const QJsonObject& activitySegment) track_add_head(route); QString timestamp; timestamp = activitySegment[DURATION][START_TIMESTAMP].toString(); - waypoint = takeout_waypoint( + Waypoint* waypoint = takeout_waypoint( startLoc[LOCATION_LATE7].toInt(), startLoc[LOCATION_LONE7].toInt(), nullptr, nullptr, @@ -404,7 +400,7 @@ GoogleTakeoutFormat::add_activity_segment(const QJsonObject& activitySegment) return n_points; } -void GoogleTakeoutInputStream::loadSource(const QString& source) { +void GoogleTakeoutFormat::GoogleTakeoutInputStream::loadSource(const QString& source) { const QFileInfo info{source}; if (info.isDir()) { sources += readDir(source); @@ -415,7 +411,7 @@ void GoogleTakeoutInputStream::loadSource(const QString& source) { } } -QJsonValue GoogleTakeoutInputStream::next() { +QJsonValue GoogleTakeoutFormat::GoogleTakeoutInputStream::next() { if (!timelineObjects.isEmpty()) { QJsonValue nextObject = timelineObjects.first(); timelineObjects.removeFirst(); diff --git a/googletakeout.h b/googletakeout.h index b3489d928..fcfe55aac 100644 --- a/googletakeout.h +++ b/googletakeout.h @@ -26,7 +26,6 @@ #include // for QJsonValue #include // for QList #include // for QString -#include // for qMakeStringPrivate, QStringLiteral #include // for QVector #include "defs.h" @@ -38,29 +37,6 @@ * * TODO: Allow date ranges */ -class GoogleTakeoutInputStream -{ -public: - /* Special Member Functions */ - GoogleTakeoutInputStream() = default; - GoogleTakeoutInputStream(const QString& source) : sources({source}) {} - - /* Member Functions */ - - // Returns the next timelineObject, or a null QJsonValue if we're at the end - QJsonValue next(); - -private: - /* Member Functions */ - - void loadSource(const QString& source); - - /* Data Members */ - - QList sources; - QList timelineObjects; -}; - /* Read-only Google Timeline Location History gpsbabel Format */ class GoogleTakeoutFormat : public Format { @@ -75,7 +51,7 @@ class GoogleTakeoutFormat : public Format ff_type get_type() const override { - return ff_type_file; + return ff_type_file; } QVector get_cap() const override @@ -90,35 +66,68 @@ class GoogleTakeoutFormat : public Format private: /* Constants */ - const QString PLACE_VISIT = QStringLiteral("placeVisit"); - const QString ACTIVITY_SEGMENT = QStringLiteral("activitySegment"); - const QString ACTIVITY_TYPE = QStringLiteral("activityType"); - const QString LOCATION = QStringLiteral("location"); - const QString LOCATION_LATE7 = QStringLiteral("latitudeE7"); - const QString LOCATION_LONE7 = QStringLiteral("longitudeE7"); - const QString NAME = QStringLiteral("name"); - const QString ADDRESS = QStringLiteral("address"); - const QString DURATION = QStringLiteral("duration"); - const QString START_TIMESTAMP = QStringLiteral("startTimestamp"); - const QString START_LOCATION = QStringLiteral("startLocation"); - const QString END_TIMESTAMP = QStringLiteral("endTimestamp"); - const QString END_LOCATION = QStringLiteral("endLocation"); - const QString TIMESTAMP = QStringLiteral("timestamp"); - const QString SIMPLE_PATH = QStringLiteral("simplifiedRawPath"); - const QString POINTS = QStringLiteral("points"); - const QString WAYPOINT_PATH = QStringLiteral("waypointPath"); - const QString WAYPOINTS = QStringLiteral("waypoints"); - // for some reason that probably only a former Google engineer knows,); - // we use = QStringLiteral("latE7"/"lngE7" here instead of "latitudeE7"/"longitudeE7".); - // +10 points for brevity, but -100 points for inconsistency.); - const QString LATE7 = QStringLiteral("latE7"); - const QString LONE7 = QStringLiteral("lngE7"); + static constexpr char MYNAME[] = "Google Takeout"; + static constexpr char TIMELINE_OBJECTS[] = "timelineObjects"; + static constexpr char16_t PLACE_VISIT[] = u"placeVisit"; + static constexpr char16_t ACTIVITY_SEGMENT[] = u"activitySegment"; + static constexpr char16_t ACTIVITY_TYPE[] = u"activityType"; + static constexpr char16_t LOCATION[] = u"location"; + static constexpr char16_t LOCATION_LATE7[] = u"latitudeE7"; + static constexpr char16_t LOCATION_LONE7[] = u"longitudeE7"; + static constexpr char16_t NAME[] = u"name"; + static constexpr char16_t ADDRESS[] = u"address"; + static constexpr char16_t DURATION[] = u"duration"; + static constexpr char16_t START_TIMESTAMP[] = u"startTimestamp"; + static constexpr char16_t START_LOCATION[] = u"startLocation"; + static constexpr char16_t END_TIMESTAMP[] = u"endTimestamp"; + static constexpr char16_t END_LOCATION[] = u"endLocation"; + static constexpr char16_t TIMESTAMP[] = u"timestamp"; + static constexpr char16_t SIMPLE_PATH[] = u"simplifiedRawPath"; + static constexpr char16_t POINTS[] = u"points"; + static constexpr char16_t WAYPOINT_PATH[] = u"waypointPath"; + static constexpr char16_t WAYPOINTS [] = u"waypoints"; + // for some reason that probably only a former Google engineer knows,; + // we use[] = u"latE7"/"lngE7" here instead of "latitudeE7"/"longitudeE7".; + // +10 points for brevity, but -100 points for inconsistency.; + static constexpr char16_t LATE7[] = u"latE7"; + static constexpr char16_t LONE7[] = u"lngE7"; + + /* Types */ + + class GoogleTakeoutInputStream + { + public: + /* Special Member Functions */ + GoogleTakeoutInputStream() = default; + GoogleTakeoutInputStream(const QString& source) : sources({source}) {} + + /* Member Functions */ - /* Member Functions */ + // Returns the next timelineObject, or a null QJsonValue if we're at the end + QJsonValue next(); + + private: + /* Member Functions */ + static QList readJson(const QString& source); + static QList readDir(const QString& source); + void loadSource(const QString& source); + + /* Data Members */ + + QList sources; + QList timelineObjects; + }; + + /* Member Functions */ + + static void takeout_fatal(const QString& message); + static void takeout_warning(const QString& message); + Waypoint* takeout_waypoint(int lat_e7, int lon_e7, const QString* shortname, const QString* description, const QString* start_str); + static bool track_maybe_add_wpt(route_head* route, Waypoint* waypoint); + static void title_case(QString& title); void add_place_visit(const QJsonObject& placeVisit); int add_activity_segment(const QJsonObject& activitySegment); - static void title_case(QString& title); /* Data Members */