logic: Added update checker connecting to online API

* connects to https://www.sourcetrail.com/api/v1/versions/latest
* sends information about OS, platform, license type, current version and a unique user token
* Automatic update check is enabled via Startscreen and performed once every 24 hours on window focus
* Update check can be forced by clicking on "check for new version" on start screen
* renamed TimePoint to TimeStamp

fortune cookie message = In Träumen und im Leben ist nichts unmöglich.
This commit is contained in:
Eberhard Graether
2017-08-08 14:18:14 +02:00
parent db1c3b3f40
commit ff65a3f285
67 changed files with 680 additions and 251 deletions
+12 -1
View File
@@ -42,7 +42,18 @@
font-weight: bold;
}
#updateLabel {
#updateButton {
margin: 1px 0 3px;
text-align: left;
padding: 0;
background: none;
border: none;
color: #007AC2;
font-size: 12px;
text-decoration: underline;
}
#updateCheckbox {
color: black;
font-size: 12px;
}
@@ -4,7 +4,8 @@
<!-- INTEGER: int e.g 123 -->
<!-- DECIMAL: float e.g 123.456 -->
<!-- STRING: string e.g hello -->
<!-- COLOR: int int int int - rgba e.g. 125 125 125 255 -->
<!-- UUID: string e.g. 00000000-0000-0000-0000-000000000000 -->
<!-- TIME: string in format "%Y-%m-%d %H:%M:%S" -->
<config>
<version><!-- INTEGER: Version number --></version>
@@ -77,6 +78,13 @@
</license>
<accepted_eula_version><!-- INTEGER: last accepted eula version --></accepted_eula_version>
<token><!-- UUID: identifier for this user --></token>
<update_check>
<automatic><!-- BOOL: whether to check automatically for new software updates --></automatic>
<time_stamp><!-- TIME: time of the last update check --></time_stamp>
</update_check>
</user>
<network>
+13 -2
View File
@@ -13,10 +13,10 @@
#include "utility/utilityUuid.h"
#include "utility/Version.h"
#include "component/controller/IDECommunicationController.h"
#include "component/NetworkFactory.h"
#include "component/view/DialogView.h"
#include "component/view/GraphViewStyle.h"
#include "component/controller/NetworkFactory.h"
#include "component/controller/IDECommunicationController.h"
#include "component/view/MainView.h"
#include "component/view/ViewFactory.h"
#include "data/storage/StorageCache.h"
@@ -24,6 +24,7 @@
#include "settings/ApplicationSettings.h"
#include "settings/ProjectSettings.h"
#include "settings/ColorScheme.h"
#include "UpdateChecker.h"
std::shared_ptr<Application> Application::s_instance;
std::string Application::s_uuid;
@@ -61,6 +62,8 @@ void Application::createInstance(
s_instance->m_ideCommunicationController =
networkFactory->createIDECommunicationController(s_instance->m_storageCache.get());
s_instance->m_ideCommunicationController->startListening();
s_instance->m_updateChecker = networkFactory->createUpdateChecker();
}
s_instance->startMessagingAndScheduling();
@@ -309,6 +312,14 @@ void Application::handleMessage(MessageSwitchColorScheme* message)
MessageRefresh().refreshUiOnly().noReloadStyle().dispatch();
}
void Application::handleMessage(MessageWindowFocus* message)
{
if (message->focusIn && ApplicationSettings::getInstance()->getAutomaticUpdateCheck())
{
m_updateChecker->checkUpdate();
}
}
void Application::startMessagingAndScheduling()
{
TaskScheduler::getInstance()->startSchedulerLoopThreaded();
+5
View File
@@ -12,6 +12,7 @@
#include "utility/messaging/type/MessageLoadProject.h"
#include "utility/messaging/type/MessageRefresh.h"
#include "utility/messaging/type/MessageSwitchColorScheme.h"
#include "utility/messaging/type/MessageWindowFocus.h"
class Bookmark;
class DialogView;
@@ -19,6 +20,7 @@ class IDECommunicationController;
class MainView;
class NetworkFactory;
class StorageCache;
class UpdateChecker;
class Version;
class ViewFactory;
@@ -29,6 +31,7 @@ class Application
, public MessageListener<MessageLoadProject>
, public MessageListener<MessageRefresh>
, public MessageListener<MessageSwitchColorScheme>
, public MessageListener<MessageWindowFocus>
{
public:
static void createInstance(const Version& version, ViewFactory* viewFactory, NetworkFactory* networkFactory);
@@ -69,6 +72,7 @@ private:
virtual void handleMessage(MessageLoadProject* message);
virtual void handleMessage(MessageRefresh* message);
virtual void handleMessage(MessageSwitchColorScheme* message);
virtual void handleMessage(MessageWindowFocus* message);
void startMessagingAndScheduling();
@@ -86,6 +90,7 @@ private:
std::shared_ptr<ComponentManager> m_componentManager;
std::shared_ptr<IDECommunicationController> m_ideCommunicationController;
std::shared_ptr<UpdateChecker> m_updateChecker;
MessageEnteredLicense::LicenseType m_licenseType;
};
+5 -4
View File
@@ -31,8 +31,6 @@ add_files(
component/controller/IDECommunicationController.h
component/controller/LogController.cpp
component/controller/LogController.h
component/controller/NetworkFactory.cpp
component/controller/NetworkFactory.h
component/controller/RefreshController.cpp
component/controller/RefreshController.h
component/controller/SearchController.cpp
@@ -96,6 +94,8 @@ add_files(
component/ComponentFactory.h
component/ComponentManager.cpp
component/ComponentManager.h
component/NetworkFactory.cpp
component/NetworkFactory.h
data/access/StorageAccess.cpp
data/access/StorageAccess.h
@@ -488,8 +488,8 @@ add_files(
utility/ScopedFunctor.cpp
utility/ScopedFunctor.h
utility/ScopedSwitcher.h
utility/TimePoint.cpp
utility/TimePoint.h
utility/TimeStamp.cpp
utility/TimeStamp.h
utility/tracing.cpp
utility/tracing.h
utility/types.h
@@ -509,4 +509,5 @@ add_files(
Application.h
LicenseChecker.cpp
LicenseChecker.h
UpdateChecker.h
)
+12
View File
@@ -0,0 +1,12 @@
#ifndef UPDATE_CHECKER_H
#define UPDATE_CHECKER_H
class UpdateChecker
{
public:
virtual ~UpdateChecker() {}
virtual void checkUpdate() = 0;
};
#endif // UPDATE_CHECKER_H
-2
View File
@@ -1,7 +1,5 @@
#include "component/ComponentManager.h"
#include "component/controller/NetworkFactory.h"
#include "component/controller/Controller.h"
#include "component/view/CompositeView.h"
#include "component/view/DialogView.h"
-1
View File
@@ -9,7 +9,6 @@
class CompositeView;
class DialogView;
class NetworkFactory;
class StorageAccess;
class TabbedView;
class View;
@@ -1,4 +1,4 @@
#include "component/controller/NetworkFactory.h"
#include "component/NetworkFactory.h"
NetworkFactory::NetworkFactory()
{
@@ -6,4 +6,4 @@ NetworkFactory::NetworkFactory()
NetworkFactory::~NetworkFactory()
{
}
}
@@ -5,6 +5,7 @@
class IDECommunicationController;
class StorageAccess;
class UpdateChecker;
class NetworkFactory
{
@@ -13,6 +14,7 @@ public:
virtual ~NetworkFactory();
virtual std::shared_ptr<IDECommunicationController> createIDECommunicationController(StorageAccess* storageAccess) const = 0;
virtual std::shared_ptr<UpdateChecker> createUpdateChecker() const = 0;
};
#endif // NETWORK_FACTORY_H
#endif // NETWORK_FACTORY_H
@@ -249,7 +249,7 @@ void BookmarkController::handleMessage(MessageCreateBookmark* message)
{
LOG_INFO_STREAM(<< "Creating Edge Bookmark");
EdgeBookmark bookmark(0, message->displayName, message->comment, TimePoint::now(), category);
EdgeBookmark bookmark(0, message->displayName, message->comment, TimeStamp::now(), category);
bookmark.setEdgeIds(m_activeEdgeIds);
if (!m_activeNodeIds.empty())
@@ -267,7 +267,7 @@ void BookmarkController::handleMessage(MessageCreateBookmark* message)
{
LOG_INFO_STREAM(<< "Creating Node Bookmark");
NodeBookmark bookmark(0, message->displayName, message->comment, TimePoint::now(), category);
NodeBookmark bookmark(0, message->displayName, message->comment, TimeStamp::now(), category);
if (message->nodeId)
{
bookmark.addNodeId(message->nodeId);
@@ -3,7 +3,7 @@
#include <memory>
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
#include "utility/types.h"
class SourceLocationFile;
@@ -25,7 +25,7 @@ struct CodeSnippetParams
Id titleId;
Id footerId;
TimePoint modificationTime;
TimeStamp modificationTime;
std::shared_ptr<SourceLocationFile> locationFile;
+2 -2
View File
@@ -4,7 +4,7 @@
#include <vector>
#include "utility/scheduling/Task.h"
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
class DialogView;
class FilePath;
@@ -28,7 +28,7 @@ private:
PersistentStorage* m_storage;
std::vector<FilePath> m_filePaths;
TimePoint m_start;
TimeStamp m_start;
};
#endif // TASK_CLEAN_STORAGE_H
+1 -1
View File
@@ -28,7 +28,7 @@ void TaskFinishParsing::doEnter(std::shared_ptr<Blackboard> blackboard)
Task::TaskState TaskFinishParsing::doUpdate(std::shared_ptr<Blackboard> blackboard)
{
TimePoint start = utility::durationStart();
TimeStamp start = utility::durationStart();
std::shared_ptr<DialogView> dialogView = Application::getInstance()->getDialogView();
+3 -3
View File
@@ -1,6 +1,6 @@
#include "Bookmark.h"
Bookmark::Bookmark(const Id id, const std::string& name, const std::string& comment, const TimePoint& timeStamp, const BookmarkCategory& category)
Bookmark::Bookmark(const Id id, const std::string& name, const std::string& comment, const TimeStamp& timeStamp, const BookmarkCategory& category)
: m_id(id)
, m_name(name)
, m_comment(comment)
@@ -44,12 +44,12 @@ void Bookmark::setComment(const std::string& comment)
m_comment = comment;
}
TimePoint Bookmark::getTimeStamp() const
TimeStamp Bookmark::getTimeStamp() const
{
return m_timeStamp;
}
void Bookmark::setTimeStamp(const TimePoint& timeStamp)
void Bookmark::setTimeStamp(const TimeStamp& timeStamp)
{
m_timeStamp = timeStamp;
}
+5 -5
View File
@@ -4,7 +4,7 @@
#include <vector>
#include <string>
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
#include "utility/types.h"
#include "BookmarkCategory.h"
@@ -12,7 +12,7 @@
class Bookmark
{
public:
Bookmark(const Id id, const std::string& name, const std::string& comment, const TimePoint& timeStamp, const BookmarkCategory& category);
Bookmark(const Id id, const std::string& name, const std::string& comment, const TimeStamp& timeStamp, const BookmarkCategory& category);
virtual ~Bookmark();
Id getId() const;
@@ -24,8 +24,8 @@ public:
std::string getComment() const;
void setComment(const std::string& comment);
TimePoint getTimeStamp() const;
void setTimeStamp(const TimePoint& timeStamp);
TimeStamp getTimeStamp() const;
void setTimeStamp(const TimeStamp& timeStamp);
BookmarkCategory getCategory() const;
void setCategory(const BookmarkCategory& category);
@@ -37,7 +37,7 @@ private:
Id m_id;
std::string m_name;
std::string m_comment;
TimePoint m_timeStamp;
TimeStamp m_timeStamp;
BookmarkCategory m_category;
bool m_isValid;
};
+4 -1
View File
@@ -1,6 +1,9 @@
#include "EdgeBookmark.h"
EdgeBookmark::EdgeBookmark(const Id id, const std::string& name, const std::string& comment, const TimePoint& timeStamp, const BookmarkCategory& category)
EdgeBookmark::EdgeBookmark(
const Id id, const std::string& name, const std::string& comment,
const TimeStamp& timeStamp, const BookmarkCategory& category
)
: Bookmark(id, name, comment, timeStamp, category)
{
}
+2 -1
View File
@@ -7,7 +7,8 @@ class EdgeBookmark
: public Bookmark
{
public:
EdgeBookmark(const Id id, const std::string& name, const std::string& comment, const TimePoint& timeStamp, const BookmarkCategory& category);
EdgeBookmark(const Id id, const std::string& name, const std::string& comment,
const TimeStamp& timeStamp, const BookmarkCategory& category);
virtual ~EdgeBookmark();
void addEdgeId(const Id edgeId);
+3 -1
View File
@@ -1,6 +1,8 @@
#include "NodeBookmark.h"
NodeBookmark::NodeBookmark(const Id id, const std::string& name, const std::string& comment, const TimePoint& timeStamp, const BookmarkCategory& category)
NodeBookmark::NodeBookmark(const Id id, const std::string& name, const std::string& comment,
const TimeStamp& timeStamp, const BookmarkCategory& category
)
: Bookmark(id, name, comment, timeStamp, category)
{
}
+2 -1
View File
@@ -7,7 +7,8 @@ class NodeBookmark
: public Bookmark
{
public:
NodeBookmark(const Id id, const std::string& name, const std::string& comment, const TimePoint& timeStamp, const BookmarkCategory& category);
NodeBookmark(const Id id, const std::string& name, const std::string& comment,
const TimeStamp& timeStamp, const BookmarkCategory& category);
virtual ~NodeBookmark();
void addNodeId(const Id nodeId);
+2 -2
View File
@@ -6,7 +6,7 @@
#include "utility/scheduling/Task.h"
#include "utility/scheduling/TaskRunner.h"
#include "utility/scheduling/TaskDecorator.h"
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
class DialogView;
class FileRegister;
@@ -27,7 +27,7 @@ private:
PersistentStorage* m_storage;
TimePoint m_start;
TimeStamp m_start;
};
#endif // TASK_PARSE_WRAPPER_H
+1 -1
View File
@@ -10,7 +10,7 @@
#include "utility/messaging/type/MessageNewErrors.h"
#include "utility/messaging/type/MessageStatus.h"
#include "utility/text/TextAccess.h"
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
#include "utility/tracing.h"
#include "utility/utility.h"
+2 -2
View File
@@ -1,7 +1,7 @@
#ifndef STORAGE_STATS_H
#define STORAGE_STATS_H
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
struct StorageStats
{
@@ -20,7 +20,7 @@ struct StorageStats
size_t completedFileCount;
size_t fileLOCCount;
TimePoint timestamp;
TimeStamp timestamp;
};
#endif // STORAGE_STATS_H
@@ -1,7 +1,7 @@
#include "data/storage/sqlite/SqliteStorage.h"
#include "utility/logging/logging.h"
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
SqliteStorage::SqliteStorage(const FilePath& dbFilePath)
: m_dbFilePath(dbFilePath.canonical())
@@ -127,12 +127,12 @@ bool SqliteStorage::isIncompatible() const
void SqliteStorage::setTime()
{
insertOrUpdateMetaValue("timestamp", TimePoint::now().toString());
insertOrUpdateMetaValue("timestamp", TimeStamp::now().toString());
}
TimePoint SqliteStorage::getTime() const
TimeStamp SqliteStorage::getTime() const
{
return TimePoint(getMetaValue("timestamp"));
return TimeStamp(getMetaValue("timestamp"));
}
void SqliteStorage::setupMetaTable()
+2 -2
View File
@@ -7,7 +7,7 @@
#include "utility/file/FilePath.h"
class SqliteStorageMigration;
class TimePoint;
class TimeStamp;
class SqliteStorage
{
@@ -43,7 +43,7 @@ public:
bool isIncompatible() const;
void setTime();
TimePoint getTime() const;
TimeStamp getTime() const;
protected:
void setupMetaTable();
+31
View File
@@ -4,6 +4,7 @@
#include "settings/migration/SettingsMigrationMoveKey.h"
#include "utility/ResourcePaths.h"
#include "utility/Status.h"
#include "utility/TimeStamp.h"
#include "utility/utility.h"
#include "utility/UserPaths.h"
@@ -405,6 +406,36 @@ void ApplicationSettings::setAcceptedEulaVersion(int version)
setValue<int>("user/accepted_eula_version", version);
}
std::string ApplicationSettings::getUserToken() const
{
return getValue<std::string>("user/token", "");
}
void ApplicationSettings::setUserToken(std::string token)
{
setValue<std::string>("user/token", token);
}
bool ApplicationSettings::getAutomaticUpdateCheck() const
{
return getValue<bool>("user/update_check/automatic", false);
}
void ApplicationSettings::setAutomaticUpdateCheck(bool automaticUpdates)
{
setValue<bool>("user/update_check/automatic", automaticUpdates);
}
TimeStamp ApplicationSettings::getLastUpdateCheck() const
{
return TimeStamp(getValue<std::string>("user/update_check/last", ""));
}
void ApplicationSettings::setLastUpdateCheck(const TimeStamp& time)
{
setValue<std::string>("user/update_check/last", time.toString());
}
int ApplicationSettings::getPluginPort() const
{
return getValue<int>("network/plugin_port", 6666);
+11
View File
@@ -5,6 +5,8 @@
#include "settings/Settings.h"
class TimeStamp;
class ApplicationSettings
: public Settings
{
@@ -117,6 +119,15 @@ public:
int getAcceptedEulaVersion() const;
void setAcceptedEulaVersion(int version);
std::string getUserToken() const;
void setUserToken(std::string token);
bool getAutomaticUpdateCheck() const;
void setAutomaticUpdateCheck(bool automaticUpdates);
TimeStamp getLastUpdateCheck() const;
void setLastUpdateCheck(const TimeStamp& time);
// network
int getPluginPort() const;
void setPluginPort(const int pluginPort);
-40
View File
@@ -1,40 +0,0 @@
#ifndef TIME_POINT_H
#define TIME_POINT_H
#include "boost/date_time/posix_time/posix_time.hpp"
class TimePoint // that name sounds pretty silly, was time stamp not ok?
{
public:
static TimePoint now();
TimePoint();
TimePoint(boost::posix_time::ptime t);
//TimePoint(time_t t);
TimePoint(std::string s);
bool isValid() const;
std::string toString() const;
std::string getDDMMYYYYString() const;
inline bool operator==(const TimePoint& rhs){ return m_time == rhs.m_time; }
inline bool operator!=(const TimePoint& rhs){ return m_time != rhs.m_time; }
inline bool operator<(const TimePoint& rhs){ return m_time < rhs.m_time; }
inline bool operator>(const TimePoint& rhs){ return m_time > rhs.m_time; }
inline bool operator<=(const TimePoint& rhs){ return m_time <= rhs.m_time; }
inline bool operator>=(const TimePoint& rhs){ return m_time >= rhs.m_time; }
inline float operator-(const TimePoint& rhs){ return deltaMS(rhs) / 1000.0f; }
size_t deltaMS(const TimePoint& other) const;
size_t deltaS(const TimePoint& other) const;
bool isSameDay(const TimePoint& other) const;
size_t deltaDays(const TimePoint& other) const; // days are counted beginning at 00:00, so a tp of 1.1.2017 23:59 is 1 day ago if it's the 2.1.2017 00:01
private:
boost::posix_time::ptime m_time;
};
#endif // TIME_POINT_H
@@ -1,26 +1,21 @@
#include "TimePoint.h"
#include "TimeStamp.h"
TimePoint TimePoint::now()
TimeStamp TimeStamp::now()
{
return TimePoint(boost::posix_time::microsec_clock::local_time());
return TimeStamp(boost::posix_time::microsec_clock::local_time());
}
TimePoint::TimePoint()
TimeStamp::TimeStamp()
: m_time(boost::posix_time::not_a_date_time)
{
}
TimePoint::TimePoint(boost::posix_time::ptime t)
TimeStamp::TimeStamp(boost::posix_time::ptime t)
: m_time(t)
{
}
//TimePoint::TimePoint(time_t t)
//{
// needs an implementation
//}
TimePoint::TimePoint(std::string s)
TimeStamp::TimeStamp(std::string s)
: m_time(boost::posix_time::not_a_date_time)
{
if (s.size())
@@ -29,12 +24,12 @@ TimePoint::TimePoint(std::string s)
}
}
bool TimePoint::isValid() const
bool TimeStamp::isValid() const
{
return m_time != boost::posix_time::not_a_date_time;
}
std::string TimePoint::toString() const
std::string TimeStamp::toString() const
{
std::stringstream stream;
boost::posix_time::time_facet* facet = new boost::posix_time::time_facet();
@@ -44,7 +39,7 @@ std::string TimePoint::toString() const
return stream.str();
}
std::string TimePoint::getDDMMYYYYString() const
std::string TimeStamp::getDDMMYYYYString() const
{
std::stringstream stream;
boost::posix_time::time_facet* facet = new boost::posix_time::time_facet();
@@ -54,17 +49,17 @@ std::string TimePoint::getDDMMYYYYString() const
return stream.str();
}
size_t TimePoint::deltaMS(const TimePoint& other) const
size_t TimeStamp::deltaMS(const TimeStamp& other) const
{
return (m_time - other.m_time).total_milliseconds();
}
size_t TimePoint::deltaS(const TimePoint& other) const
size_t TimeStamp::deltaS(const TimeStamp& other) const
{
return (m_time - other.m_time).total_seconds();
}
bool TimePoint::isSameDay(const TimePoint& other) const
bool TimeStamp::isSameDay(const TimeStamp& other) const
{
if (m_time.date().day() == other.m_time.date().day() &&
m_time.date().month() == other.m_time.date().month() &&
@@ -76,8 +71,14 @@ bool TimePoint::isSameDay(const TimePoint& other) const
return false;
}
size_t TimePoint::deltaDays(const TimePoint& other) const
size_t TimeStamp::deltaDays(const TimeStamp& other) const
{
boost::gregorian::date_duration deltaDate = m_time.date() - other.m_time.date();
return size_t(std::abs(deltaDate.days()));
}
long TimeStamp::deltaHours(const TimeStamp& other) const
{
boost::posix_time::time_duration delta = m_time - other.m_time;
return delta.total_seconds() / 3600;
}
+40
View File
@@ -0,0 +1,40 @@
#ifndef TIME_STAMP_H
#define TIME_STAMP_H
#include "boost/date_time/posix_time/posix_time.hpp"
class TimeStamp
{
public:
static TimeStamp now();
TimeStamp();
TimeStamp(boost::posix_time::ptime t);
TimeStamp(std::string s);
bool isValid() const;
std::string toString() const;
std::string getDDMMYYYYString() const;
inline bool operator==(const TimeStamp& rhs) { return m_time == rhs.m_time; }
inline bool operator!=(const TimeStamp& rhs) { return m_time != rhs.m_time; }
inline bool operator<(const TimeStamp& rhs) { return m_time < rhs.m_time; }
inline bool operator>(const TimeStamp& rhs) { return m_time > rhs.m_time; }
inline bool operator<=(const TimeStamp& rhs) { return m_time <= rhs.m_time; }
inline bool operator>=(const TimeStamp& rhs) { return m_time >= rhs.m_time; }
size_t deltaMS(const TimeStamp& other) const;
size_t deltaS(const TimeStamp& other) const;
bool isSameDay(const TimeStamp& other) const;
// days are counted beginning at 00:00, so a tp of 1.1.2017 23:59 is 1 day ago if it's the 2.1.2017 00:01
size_t deltaDays(const TimeStamp& other) const;
long deltaHours(const TimeStamp& other) const;
private:
boost::posix_time::ptime m_time;
};
#endif // TIME_STAMP_H
+1 -1
View File
@@ -10,7 +10,7 @@ FileInfo::FileInfo(const FilePath& path)
{
}
FileInfo::FileInfo(const FilePath& path, const TimePoint& lastWriteTime)
FileInfo::FileInfo(const FilePath& path, const TimeStamp& lastWriteTime)
: path(path)
, lastWriteTime(lastWriteTime)
{
+3 -3
View File
@@ -6,16 +6,16 @@
#include "boost/date_time.hpp"
#include "utility/file/FilePath.h"
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
struct FileInfo
{
FileInfo();
FileInfo(const FilePath& path);
FileInfo(const FilePath& path, const TimePoint& lastWriteTime);
FileInfo(const FilePath& path, const TimeStamp& lastWriteTime);
FilePath path;
TimePoint lastWriteTime;
TimeStamp lastWriteTime;
};
#endif // FILE_INFO_H
+2 -2
View File
@@ -143,7 +143,7 @@ unsigned long long FileSystem::getFileByteSize(const FilePath& filePath)
return boost::filesystem::file_size(filePath.path());
}
TimePoint FileSystem::getLastWriteTime(const FilePath& filePath)
TimeStamp FileSystem::getLastWriteTime(const FilePath& filePath)
{
boost::posix_time::ptime lastWriteTime;
if (filePath.exists())
@@ -151,7 +151,7 @@ TimePoint FileSystem::getLastWriteTime(const FilePath& filePath)
std::time_t t = boost::filesystem::last_write_time(filePath.path());
lastWriteTime = boost::posix_time::from_time_t(t);
}
return TimePoint(lastWriteTime);
return TimeStamp(lastWriteTime);
}
std::string FileSystem::getTimeStringNow() // TODO: move to utility
+2 -2
View File
@@ -5,7 +5,7 @@
#include <vector>
#include "utility/file/FileInfo.h"
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
class FileSystem
{
@@ -20,7 +20,7 @@ public:
static unsigned long long getFileByteSize(const FilePath& filePath);
static TimePoint getLastWriteTime(const FilePath& filePath);
static TimeStamp getLastWriteTime(const FilePath& filePath);
static std::string getTimeStringNow();
static bool exists(const FilePath& path);
@@ -3,7 +3,7 @@
#include <thread>
#include "utility/logging/logging.h"
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
#include "utility/utility.h"
std::string SharedMemoryGarbageCollector::s_memoryNamePrefix = "grbg_cllctr_";
@@ -101,11 +101,11 @@ void SharedMemoryGarbageCollector::stop()
}
bool otherRunningInstances = false;
TimePoint now = TimePoint::now();
TimeStamp now = TimeStamp::now();
for (SharedMemory::Map<SharedMemory::String, SharedMemory::String>::iterator it = instances->begin();
it != instances->end(); it++)
{
TimePoint timestamp = TimePoint(std::string(it->second.c_str()));
TimeStamp timestamp = TimeStamp(std::string(it->second.c_str()));
if (now.deltaS(timestamp) <= s_deleteThresholdSeconds)
{
otherRunningInstances = true;
@@ -163,7 +163,7 @@ void SharedMemoryGarbageCollector::update()
}
SharedMemory::String t(access.getAllocator());
t = TimePoint::now().toString().c_str();
t = TimeStamp::now().toString().c_str();
// update instances
{
@@ -231,11 +231,11 @@ void SharedMemoryGarbageCollector::update()
}
// delete old shared memories
TimePoint now = TimePoint::now();
TimeStamp now = TimeStamp::now();
for (SharedMemory::Map<SharedMemory::String, SharedMemory::String>::iterator it = timeStamps->begin();
it != timeStamps->end();)
{
TimePoint timestamp = TimePoint(std::string(it->second.c_str()));
TimeStamp timestamp = TimeStamp(std::string(it->second.c_str()));
if (now.deltaS(timestamp) > s_deleteThresholdSeconds)
{
LOG_INFO_STREAM(<< "collect garbage: " << it->first.c_str());
@@ -10,7 +10,7 @@ TaskDecoratorDelay::TaskDecoratorDelay(size_t delayMS)
void TaskDecoratorDelay::doEnter(std::shared_ptr<Blackboard> blackboard)
{
m_start = TimePoint::now();
m_start = TimeStamp::now();
}
Task::TaskState TaskDecoratorDelay::doUpdate(std::shared_ptr<Blackboard> blackboard)
@@ -23,7 +23,7 @@ Task::TaskState TaskDecoratorDelay::doUpdate(std::shared_ptr<Blackboard> blackbo
const int SLEEP_TIME_MS = 25;
std::this_thread::sleep_for(std::chrono::microseconds(SLEEP_TIME_MS));
m_delayComplete = (TimePoint::now().deltaMS(m_start) >= m_delayMS);
m_delayComplete = (TimeStamp::now().deltaMS(m_start) >= m_delayMS);
return Task::STATE_HOLD;
}
@@ -5,7 +5,7 @@
#include "utility/scheduling/TaskDecorator.h"
#include "utility/scheduling/TaskRunner.h"
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
class TaskDecoratorDelay
: public TaskDecorator
@@ -22,7 +22,7 @@ private:
const size_t m_delayMS;
TimePoint m_start;
TimeStamp m_start;
bool m_delayComplete;
};
+2 -2
View File
@@ -173,11 +173,11 @@ ScopedTrace::ScopedTrace(
m_event->functionName = functionName;
m_event->locationName = FilePath(fileName).fileName() + ":" + std::to_string(lineNumber);
m_timePoint = utility::durationStart();
m_TimeStamp = utility::durationStart();
}
ScopedTrace::~ScopedTrace()
{
m_event->time = utility::duration(m_timePoint);
m_event->time = utility::duration(m_TimeStamp);
Tracer::getInstance()->finishEvent(m_event);
}
+2 -2
View File
@@ -5,7 +5,7 @@
#include <stack>
#include <thread>
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
#include "utility/types.h"
struct TraceEvent
@@ -63,7 +63,7 @@ public:
private:
TraceEvent* m_event;
TimePoint m_timePoint;
TimeStamp m_TimeStamp;
};
+7 -7
View File
@@ -16,20 +16,20 @@ ApplicationArchitectureType utility::getApplicationArchitectureType()
return APPLICATION_ARCHITECTURE_UNKNOWN;
}
TimePoint utility::durationStart()
TimeStamp utility::durationStart()
{
return TimePoint::now();
return TimeStamp::now();
}
float utility::duration(const TimePoint& start)
float utility::duration(const TimeStamp& start)
{
TimePoint now = durationStart();
return now - start;
TimeStamp now = durationStart();
return float(now.deltaMS(start)) / 1000.0f;
}
float utility::duration(std::function<void()> func)
{
const TimePoint start = durationStart();
const TimeStamp start = durationStart();
func();
@@ -45,7 +45,7 @@ std::string utility::timeToString(const time_t time)
std::string utility::timeToString(const boost::posix_time::ptime time)
{
return TimePoint(time).toString();
return TimeStamp(time).toString();
}
std::string utility::timeToString(float secondsTotal)
+3 -3
View File
@@ -15,12 +15,12 @@
#include "utility/ApplicationArchitectureType.h"
#include "utility/file/FilePath.h"
#include "utility/math/Vector2.h"
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
namespace utility
{
TimePoint durationStart();
float duration(const TimePoint& start);
TimeStamp durationStart();
float duration(const TimeStamp& start);
float duration(std::function<void()> func);
std::string timeToString(const time_t time);
+4
View File
@@ -80,8 +80,12 @@ add_files(
qt/network/QtIDECommunicationController.h
qt/network/QtNetworkFactory.cpp
qt/network/QtNetworkFactory.h
qt/network/QtRequest.cpp
qt/network/QtRequest.h
qt/network/QtTcpWrapper.cpp
qt/network/QtTcpWrapper.h
qt/network/QtUpdateChecker.cpp
qt/network/QtUpdateChecker.h
qt/utility/QtContextMenu.cpp
qt/utility/QtContextMenu.h
+5 -4
View File
@@ -242,9 +242,10 @@ std::string QtBookmark::getDateString() const
{
std::string result = "n/a";
TimePoint creationDate = m_bookmark->getTimeStamp();
TimeStamp creationDate = m_bookmark->getTimeStamp();
TimeStamp now = TimeStamp::now();
float delta = TimePoint::now() - creationDate;
size_t delta = now.deltaS(creationDate);
if (delta < 3600.0f) // less than an hour ago
{
@@ -254,11 +255,11 @@ std::string QtBookmark::getDateString() const
{
result = std::to_string(int(delta / 3600.0f)) + " hours ago";
}
else if (creationDate.isSameDay(TimePoint::now())) // today
else if (creationDate.isSameDay(now)) // today
{
result = "today";
}
else if (creationDate.deltaDays(TimePoint::now()) == 1) // yesterday
else if (creationDate.deltaDays(now) == 1) // yesterday
{
result = "yesterday";
}
+1 -1
View File
@@ -114,7 +114,7 @@ QtCodeFile::~QtCodeFile()
{
}
void QtCodeFile::setModificationTime(const TimePoint modificationTime)
void QtCodeFile::setModificationTime(const TimeStamp modificationTime)
{
m_title->setModificationTime(modificationTime);
}
+2 -2
View File
@@ -18,7 +18,7 @@ class QtCodeFileTitleButton;
class QtCodeNavigator;
class QtCodeSnippet;
class QVBoxLayout;
class TimePoint;
class TimeStamp;
class QtCodeFile
: public QFrame
@@ -29,7 +29,7 @@ public:
QtCodeFile(const FilePath& filePath, QtCodeNavigator* navigator);
virtual ~QtCodeFile();
void setModificationTime(const TimePoint modificationTime);
void setModificationTime(const TimeStamp modificationTime);
const FilePath& getFilePath() const;
std::string getFileName() const;
+1 -1
View File
@@ -70,7 +70,7 @@ QtCodeFile* QtCodeFileList::getFile(const FilePath filePath)
return file;
}
void QtCodeFileList::addFile(const FilePath& filePath, bool isWholeFile, int refCount, TimePoint modificationTime, bool isComplete)
void QtCodeFileList::addFile(const FilePath& filePath, bool isWholeFile, int refCount, TimeStamp modificationTime, bool isComplete)
{
QtCodeFile* file = getFile(filePath);
file->setWholeFile(isWholeFile, refCount);
+1 -1
View File
@@ -28,7 +28,7 @@ public:
void clear();
QtCodeFile* getFile(const FilePath filePath);
void addFile(const FilePath& filePath, bool isWholeFile, int refCount, TimePoint modificationTime, bool isComplete);
void addFile(const FilePath& filePath, bool isWholeFile, int refCount, TimeStamp modificationTime, bool isComplete);
// QtCodeNaviatebale implementation
virtual QScrollArea* getScrollArea();
+2 -2
View File
@@ -7,7 +7,7 @@
#include <QFrame>
#include "utility/file/FilePath.h"
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
#include "qt/element/QtCodeNavigateable.h"
@@ -52,7 +52,7 @@ private:
struct FileData
{
FilePath filePath;
TimePoint modificationTime;
TimeStamp modificationTime;
bool isComplete;
std::string title;
@@ -47,7 +47,7 @@ void QtCodeFileTitleButton::setFilePath(const FilePath& filePath)
));
}
void QtCodeFileTitleButton::setModificationTime(const TimePoint modificationTime)
void QtCodeFileTitleButton::setModificationTime(const TimeStamp modificationTime)
{
if (modificationTime.isValid())
{
@@ -4,7 +4,7 @@
#include <QPushButton>
#include "utility/file/FilePath.h"
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
class QtCodeFileTitleButton
: public QPushButton
@@ -16,7 +16,7 @@ public:
virtual ~QtCodeFileTitleButton();
void setFilePath(const FilePath& filePath);
void setModificationTime(const TimePoint modificationTime);
void setModificationTime(const TimeStamp modificationTime);
void setIsComplete(bool isComplete);
void setProject(const std::string& name);
@@ -30,7 +30,7 @@ private slots:
private:
FilePath m_filePath;
TimePoint m_modificationTime;
TimeStamp m_modificationTime;
bool m_isComplete;
};
+1 -1
View File
@@ -155,7 +155,7 @@ void QtCodeNavigator::addCodeSnippet(const CodeSnippetParams& params)
}
}
void QtCodeNavigator::addFile(std::shared_ptr<SourceLocationFile> locationFile, int refCount, TimePoint modificationTime)
void QtCodeNavigator::addFile(std::shared_ptr<SourceLocationFile> locationFile, int refCount, TimeStamp modificationTime)
{
bool firstFile = m_references.size() == 0;
+1 -1
View File
@@ -35,7 +35,7 @@ public:
virtual ~QtCodeNavigator();
void addCodeSnippet(const CodeSnippetParams& params);
void addFile(std::shared_ptr<SourceLocationFile> locationFile, int refCount, TimePoint modificationTime);
void addFile(std::shared_ptr<SourceLocationFile> locationFile, int refCount, TimeStamp modificationTime);
void addedFiles();
+4 -4
View File
@@ -56,7 +56,7 @@ void QtProgressBar::paintEvent(QPaintEvent* event)
void QtProgressBar::start()
{
m_timePoint = TimePoint::now();
m_TimeStamp = TimeStamp::now();
m_timer->start(25);
}
@@ -68,15 +68,15 @@ void QtProgressBar::stop()
void QtProgressBar::animate()
{
TimePoint t = TimePoint::now();
size_t dt = t.deltaMS(m_timePoint);
TimeStamp t = TimeStamp::now();
size_t dt = t.deltaMS(m_TimeStamp);
if (dt < 5)
{
return;
}
m_timePoint = t;
m_TimeStamp = t;
m_count++;
update();
+2 -2
View File
@@ -4,7 +4,7 @@
#include <QWidget>
#include "qt/utility/QtDeviceScaledPixmap.h"
#include "utility/TimePoint.h"
#include "utility/TimeStamp.h"
class QTimer;
@@ -34,7 +34,7 @@ private:
size_t m_count;
QTimer* m_timer;
TimePoint m_timePoint;
TimeStamp m_TimeStamp;
QtDeviceScaledPixmap m_pixmap;
};
+8 -2
View File
@@ -1,6 +1,7 @@
#include "QtNetworkFactory.h"
#include "QtIDECommunicationController.h"
#include "QtUpdateChecker.h"
QtNetworkFactory::QtNetworkFactory()
{
@@ -11,6 +12,11 @@ QtNetworkFactory::~QtNetworkFactory()
}
std::shared_ptr<IDECommunicationController> QtNetworkFactory::createIDECommunicationController(StorageAccess* storageAccess) const
{
{
return std::make_shared<QtIDECommunicationController>(nullptr, storageAccess);
}
}
std::shared_ptr<UpdateChecker> QtNetworkFactory::createUpdateChecker() const
{
return std::make_shared<QtUpdateChecker>();
}
+7 -4
View File
@@ -1,15 +1,18 @@
#ifndef QT_NETWORK_FACTORY_H
#define QT_NETWORK_FACTORY_H
#include "component/controller/NetworkFactory.h"
#include "component/NetworkFactory.h"
class QtNetworkFactory : public NetworkFactory
class QtNetworkFactory
: public NetworkFactory
{
public:
QtNetworkFactory();
virtual ~QtNetworkFactory();
virtual std::shared_ptr<IDECommunicationController> createIDECommunicationController(StorageAccess* storageAccess) const;
virtual std::shared_ptr<IDECommunicationController>
createIDECommunicationController(StorageAccess* storageAccess) const override;
virtual std::shared_ptr<UpdateChecker> createUpdateChecker() const override;
};
#endif // QT_NETWORK_FACTORY_H
#endif // QT_NETWORK_FACTORY_H
+40
View File
@@ -0,0 +1,40 @@
#include "qt/network/QtRequest.h"
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include "utility/logging/logging.h"
QtRequest::QtRequest()
{
m_networkManager = new QNetworkAccessManager(this);
QObject::connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(finished(QNetworkReply*)));
}
void QtRequest::sendRequest(QString url)
{
LOG_INFO_STREAM(<< "send HTTP request: " << url.toStdString());
QNetworkRequest request;
request.setSslConfiguration(QSslConfiguration::defaultConfiguration());
request.setUrl(QUrl(url));
m_networkManager->get(request);
}
void QtRequest::finished(QNetworkReply *reply)
{
QVariant statusCodeV = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
QVariant redirectionTargetUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
if (reply->error() != QNetworkReply::NoError)
{
LOG_ERROR_STREAM(<< "An error occured during http request. ERRORCODE: " << reply->error());
}
QByteArray bytes = reply->readAll();
LOG_INFO_STREAM(<< "received HTTP reply: " << bytes.toStdString());
delete reply;
emit receivedData(bytes);
}
+29
View File
@@ -0,0 +1,29 @@
#ifndef QT_REQUEST_H
#define QT_REQUEST_H
#include <QByteArray>
#include <QObject>
class QNetworkAccessManager;
class QNetworkReply;
class QtRequest
: public QObject
{
Q_OBJECT
public:
QtRequest();
void sendRequest(QString url);
signals:
void receivedData(QByteArray bytes);
private slots:
void finished(QNetworkReply* reply);
private:
QNetworkAccessManager* m_networkManager;
};
#endif // QT_REQUEST_H
+148
View File
@@ -0,0 +1,148 @@
#include "qt/network/QtUpdateChecker.h"
#include <QDesktopServices>
#include <QMessageBox>
#include <QJsonDocument>
#include <QJsonObject>
#include <QUrl>
#include "LicenseChecker.h"
#include "qt/network/QtRequest.h"
#include "settings/ApplicationSettings.h"
#include "utility/Version.h"
#include "utility/utility.h"
#include "utility/utilityUuid.h"
void QtUpdateChecker::check(bool force)
{
ApplicationSettings* appSettings = ApplicationSettings::getInstance().get();
if (!force && TimeStamp::now().deltaHours(appSettings->getLastUpdateCheck()) < 24)
{
return;
}
appSettings->setLastUpdateCheck(TimeStamp::now());
appSettings->save();
QString urlString = "https://www.sourcetrail.com/api/v1/versions/latest";
// OS
std::string osString;
#if defined(Q_OS_WIN)
osString = "windows";
#elif defined(Q_OS_MACOS)
osString = "macOS";
#elif defined(Q_OS_LINUX)
osString = "linux";
#endif
if (!osString.size())
{
return;
}
urlString += ("?os=" + osString).c_str();
// architecture
std::string platformString = (utility::getApplicationArchitectureType() == APPLICATION_ARCHITECTURE_X86_64 ? "64" : "32");
urlString += ("&platform=" + platformString + "bit").c_str();
// version
urlString += ("&version=" + Version::getApplicationVersion().toDisplayString()).c_str();
// license
std::string licenseString;
switch (LicenseChecker::getInstance()->getCurrentLicenseType())
{
case MessageEnteredLicense::LICENSE_NONE:
licenseString = "trial";
break;
case MessageEnteredLicense::LICENSE_TEST:
licenseString = "test";
break;
case MessageEnteredLicense::LICENSE_NON_COMMERCIAL:
licenseString = "private";
break;
case MessageEnteredLicense::LICENSE_COMMERCIAL:
licenseString = "commercial";
break;
}
urlString += ("&license=" + licenseString).c_str();
// user token
std::string token = appSettings->getUserToken();
if (!token.size())
{
token = utility::getUuidString();
appSettings->setUserToken(token);
appSettings->save();
}
urlString += ("&token=" + token).c_str();
// send request
QtRequest* request = new QtRequest();
QObject::connect(request, &QtRequest::receivedData,
[force, request](QByteArray bytes)
{
do
{
QJsonDocument doc = QJsonDocument::fromJson(bytes);
if (!doc.isObject())
{
LOG_ERROR_STREAM(<< "Update response couldn't be parsed as JSON");
break;
}
QString version = doc.object().find("version")->toString();
QString url = doc.object().find("url")->toString();
Version updateVersion = Version::fromString(version.toStdString());
if (!updateVersion.isValid())
{
LOG_ERROR_STREAM(<< "update version string is not valid: " << version.toStdString());
break;
}
if (updateVersion > Version::getApplicationVersion())
{
QMessageBox msgBox;
msgBox.setText("Update Check");
msgBox.setInformativeText(
"Sourcetrial " + version + " is available for download: <a href=\"" + url + "\">" + url + "</a>");
msgBox.addButton("Close", QMessageBox::ButtonRole::NoRole);
QPushButton* but = msgBox.addButton("Download", QMessageBox::ButtonRole::YesRole);
msgBox.setDefaultButton(but);
if (msgBox.exec() == 1)
{
QDesktopServices::openUrl(QUrl(url, QUrl::TolerantMode));
}
}
else if (force)
{
QMessageBox msgBox;
msgBox.setText("Update Check");
msgBox.setInformativeText(
("Sourcetrial " + Version::getApplicationVersion().toDisplayString() + " is still up-to-date.").c_str());
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.exec();
}
}
while (false);
request->deleteLater();
}
);
request->sendRequest(urlString);
}
void QtUpdateChecker::checkUpdate()
{
check();
}
+15
View File
@@ -0,0 +1,15 @@
#ifndef QT_UPDATE_CHECKER_H
#define QT_UPDATE_CHECKER_H
#include "UpdateChecker.h"
class QtUpdateChecker
: public UpdateChecker
{
public:
static void check(bool force = false);
virtual void checkUpdate() override;
};
#endif // QT_UPDATE_CHECKER_H
+12 -9
View File
@@ -17,6 +17,7 @@
#include "component/view/View.h"
#include "data/bookmark/Bookmark.h"
#include "LicenseChecker.h"
#include "qt/network/QtUpdateChecker.h"
#include "qt/utility/QtContextMenu.h"
#include "qt/utility/utilityQt.h"
#include "qt/view/QtViewWidgetWrapper.h"
@@ -51,6 +52,7 @@
#include "utility/UserPaths.h"
#include "utility/utilityString.h"
QtViewToggle::QtViewToggle(View* view, QWidget *parent)
: QWidget(parent)
, m_view(view)
@@ -104,7 +106,7 @@ QtMainWindow::QtMainWindow()
, m_showDockWidgetTitleBars(true)
, m_windowStack(this)
{
setObjectName("QtMainWindow");
setObjectName("QtMainWindow");
setCentralWidget(nullptr);
setDockNestingEnabled(true);
@@ -112,13 +114,13 @@ QtMainWindow::QtMainWindow()
setWindowFlags(Qt::Widget);
#ifdef __linux__
if (std::getenv("SOURCETRAIL_VIA_SCRIPT") == nullptr)
{
QMessageBox::warning(this, "Run Sourcetrail via Script", "Please run Sourcetrail via Sourcetrail.sh");
}
if (std::getenv("SOURCETRAIL_VIA_SCRIPT") == nullptr)
{
QMessageBox::warning(this, "Run Sourcetrail via Script", "Please run Sourcetrail via Sourcetrail.sh");
}
#endif
QApplication* app = dynamic_cast<QApplication*>(QCoreApplication::instance());
QApplication* app = dynamic_cast<QApplication*>(QCoreApplication::instance());
app->installEventFilter(new MouseReleaseFilter(this));
app->setStyleSheet(utility::getStyleSheet(ResourcePaths::getGuiPath().concat(FilePath("main.css"))).c_str());
@@ -358,6 +360,7 @@ void QtMainWindow::keyPressEvent(QKeyEvent* event)
break;
case Qt::Key_Space:
QtUpdateChecker::check();
PRINT_TRACES();
break;
}
@@ -376,13 +379,13 @@ void QtMainWindow::closeEvent(QCloseEvent* event)
{
log->setEnabled(false);
}
MessageWindowClosed().dispatch();
MessageWindowClosed().dispatch();
}
void QtMainWindow::resizeEvent(QResizeEvent *event)
{
m_windowStack.centerSubWindows();
QMainWindow::resizeEvent(event);
m_windowStack.centerSubWindows();
QMainWindow::resizeEvent(event);
}
void QtMainWindow::about()
+43 -18
View File
@@ -1,21 +1,23 @@
#include "qt/window/QtStartScreen.h"
#include <QCheckBox>
#include <QLabel>
#include <QString>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QMessageBox>
#include "settings/ApplicationSettings.h"
#include "settings/ProjectSettings.h"
#include "utility/AppPath.h"
#include "utility/messaging/type/MessageLoadProject.h"
#include "utility/ResourcePaths.h"
#include "qt/utility/utilityQt.h"
#include "utility/Version.h"
#include "License.h"
#include "PublicKey.h"
#include "utility/AppPath.h"
#include "qt/network/QtUpdateChecker.h"
#include "qt/utility/utilityQt.h"
#include "settings/ApplicationSettings.h"
#include "settings/ProjectSettings.h"
QtRecentProjectButton::QtRecentProjectButton(QWidget* parent)
: QPushButton(parent)
@@ -158,12 +160,44 @@ void QtStartScreen::setupStartScreen()
QVBoxLayout* col = new QVBoxLayout();
layout->addLayout(col, 2);
QLabel* versionLabel = new QLabel(("Version " + Version::getApplicationVersion().toDisplayString()).c_str(), this);
versionLabel->setObjectName("versionLabel");
col->addWidget(versionLabel);
QPushButton* updateButton = new QPushButton("check for new version", this);
updateButton->setObjectName("updateButton");
updateButton->setCursor(Qt::PointingHandCursor);
connect(updateButton, &QPushButton::clicked,
[]()
{
QtUpdateChecker::check(true);
}
);
col->addWidget(updateButton);
QCheckBox* updateCheckbox = new QCheckBox("automatic update check");
updateCheckbox->setObjectName("updateCheckbox");
updateCheckbox->setChecked(ApplicationSettings::getInstance()->getAutomaticUpdateCheck());
connect(updateCheckbox, &QCheckBox::stateChanged,
[updateCheckbox]()
{
ApplicationSettings::getInstance()->setAutomaticUpdateCheck(updateCheckbox->isChecked());
ApplicationSettings::getInstance()->save();
if (updateCheckbox->isChecked())
{
QtUpdateChecker::check();
}
}
);
col->addWidget(updateCheckbox);
if (!licenseValid)
{
col->addSpacing(4);
col->addSpacing(20);
QLabel* welcomeLabel = new QLabel(
"Welcome to the trial version of <b>Sourcetrail</b>!<br /><br />"
"<b>Welcome to the trial version of Sourcetrail!</b><br />"
"Explore our preindexed projects to experience Sourcetrail's unique user interface. "
"More projects are available for download <a href=\"http://sourcetrail.com/downloads#extra\" style=\"color: #007AC2;\">here</a>.<br /><br />"
"If you want to use Sourcetrail on your own source code please "
@@ -175,6 +209,7 @@ void QtStartScreen::setupStartScreen()
welcomeLabel->setAlignment(Qt::AlignTop);
col->addWidget(welcomeLabel, 0, Qt::AlignHCenter | Qt::AlignTop);
col->addStrut(260);
col->addStretch();
QPushButton* openProjectButton = new QPushButton("Open Project", this);
@@ -201,17 +236,7 @@ void QtStartScreen::setupStartScreen()
}
else
{
QLabel* versionLabel = new QLabel(("Version " + Version::getApplicationVersion().toDisplayString()).c_str(), this);
versionLabel->setObjectName("versionLabel");
col->addWidget(versionLabel);
QLabel* updateLabel = new QLabel(
"<a href=\"https://sourcetrail.com/downloads\" style=\"color: #007AC2;\">check for new version</a>", this);
updateLabel->setOpenExternalLinks(true);
updateLabel->setObjectName("updateLabel");
col->addWidget(updateLabel);
col->addSpacing(20);
col->addSpacing(30);
std::string licenseString = license.getLicenseInfo();
+1 -1
View File
@@ -398,7 +398,7 @@ bool License::isExpired() const
}
else
{
Version version = Version::fromShortString(m_expire);
Version version = Version::fromString(m_expire);
return Version::getApplicationVersion() > version;
}
}
+102 -44
View File
@@ -1,60 +1,120 @@
#include "utility/Version.h"
#include <vector>
#include <sstream>
// since there are 4 version per year it is on digit
const int MINOR_VERSION_SHIFT = 10;
namespace {
template <typename ContainerType>
ContainerType split(const std::string& str, const std::string& delimiter)
{
size_t pos = 0;
size_t oldPos = 0;
ContainerType c;
do
{
pos = str.find(delimiter, oldPos);
c.push_back(str.substr(oldPos, pos - oldPos));
oldPos = pos + delimiter.size();
}
while (pos != std::string::npos);
return c;
}
}
Version Version::s_version;
#include <iostream>
Version Version::fromShortString(const std::string& versionString)
Version Version::fromString(const std::string& versionString)
{
Version version;
if (versionString.length() != 6 || versionString[4] != '.')
{
return version;
}
try
{
Version version;
std::vector<std::string> parts = split<std::vector<std::string>>(versionString, ".");
try
{
version.m_year = std::stoi(versionString.substr(0,4));
version.m_minorNumber = std::stoi(versionString.substr(5));
}
catch (std::invalid_argument e)
{
return Version();
}
if (parts.size())
{
version.m_year = std::stoi(parts[0]);
}
return version;
if (parts.size() > 1)
{
version.m_minorNumber = std::stoi(parts[1]);
}
if (parts.size() > 2)
{
std::vector<std::string> hashParts = split<std::vector<std::string>>(parts[2], "-");
if (hashParts.size())
{
version.m_commitNumber = std::stoi(hashParts[0]);
}
if (hashParts.size() > 1)
{
version.m_commitHash = hashParts[1];
}
}
return version;
}
catch (std::invalid_argument e)
{
// LOG_ERROR("Version string is invalid: " + versionString);
}
return Version();
}
bool Version::operator<(const Version& other) const
{
return (m_year * MINOR_VERSION_SHIFT + m_minorNumber) < (other.m_year * MINOR_VERSION_SHIFT + other.m_minorNumber);
if (m_year != other.m_year)
{
return m_year < other.m_year;
}
else if (m_minorNumber != other.m_minorNumber)
{
return m_minorNumber < other.m_minorNumber;
}
else
{
return m_commitNumber < other.m_commitNumber;
}
}
bool Version::operator>(const Version& other) const
{
return (m_year * MINOR_VERSION_SHIFT + m_minorNumber) > (other.m_year * MINOR_VERSION_SHIFT + other.m_minorNumber);
if (m_year != other.m_year)
{
return m_year > other.m_year;
}
else if (m_minorNumber != other.m_minorNumber)
{
return m_minorNumber > other.m_minorNumber;
}
else
{
return m_commitNumber > other.m_commitNumber;
}
}
Version& Version::operator +=(const int& number)
Version& Version::operator+=(const int& number)
{
int minor = this->m_minorNumber - 1 + number;
this->m_year += minor/4;
this->m_minorNumber = (minor%4) + 1;
return *this;
int minor = this->m_minorNumber - 1 + number;
this->m_year += minor/4;
this->m_minorNumber = (minor%4) + 1;
return *this;
}
bool Version::isValid()
{
if (m_minorNumber < 5 && m_minorNumber > 0
&& m_year > 2016)
{
return true;
}
return false;
if (m_minorNumber < 5 && m_minorNumber > 0
&& m_year > 2016)
{
return true;
}
return false;
}
void Version::setApplicationVersion(const Version& version)
@@ -68,37 +128,35 @@ const Version& Version::getApplicationVersion()
}
Version::Version(int year, int minor, int commit, const std::string& hash)
: m_year(year)
, m_minorNumber(minor)
, m_commitNumber(commit)
, m_commitHash(hash)
: m_year(year)
, m_minorNumber(minor)
, m_commitNumber(commit)
, m_commitHash(hash)
{
}
bool Version::isEmpty() const
{
return m_year == 0 && m_minorNumber == 0 && m_commitNumber == 0;
return m_year == 0 && m_minorNumber == 0 && m_commitNumber == 0;
}
std::string Version::toShortString() const
{
std::stringstream ss;
ss << m_year << '.' << m_minorNumber;
return ss.str();
std::stringstream ss;
ss << m_year << '.' << m_minorNumber;
return ss.str();
}
std::string Version::toString() const
{
std::stringstream ss;
ss << m_year << '.' << m_minorNumber;
ss << '-' << m_commitNumber << '-' << m_commitHash;
ss << m_year << '.' << m_minorNumber << '-' << m_commitNumber << '-' << m_commitHash;
return ss.str();
}
std::string Version::toDisplayString() const
{
std::stringstream ss;
ss << m_year << '.' << m_minorNumber;
ss << '.' << m_commitNumber;
ss << m_year << '.' << m_minorNumber << '.' << m_commitNumber;
return ss.str();
}
+9 -9
View File
@@ -3,32 +3,32 @@
#include <string>
class Version
{
public:
static Version fromString(const std::string& versionString);
static Version fromShortString(const std::string& versionString);
static Version fromShortString(const std::string& versionString);
static void setApplicationVersion(const Version& version);
static const Version& getApplicationVersion();
Version(int year = 0, int minor = 0, int commit = 0, const std::string& hash = "");
Version(int year = 0, int minor = 0, int commit = 0, const std::string& hash = "");
bool isEmpty() const;
std::string toString() const;
std::string toShortString() const;
std::string toShortString() const;
std::string toDisplayString() const;
bool operator<(const Version& other) const;
bool operator>(const Version& other) const;
Version& operator+=(const int& number);
bool isValid();
bool operator<(const Version& other) const;
bool operator>(const Version& other) const;
Version& operator+=(const int& number);
bool isValid();
private:
static Version s_version;
int m_year;
int m_year;
int m_minorNumber;
int m_commitNumber;
+3 -3
View File
@@ -90,7 +90,7 @@ std::string Generator::encodeLicense(
if (!version.empty())
{
Version tempVersion = Version::fromShortString(version);
Version tempVersion = Version::fromString(version);
if (tempVersion.isValid())
{
createLicense(user, licenseType, tempVersion.toShortString(), seats);
@@ -196,7 +196,7 @@ bool Generator::loadPrivateKeyFromFile()
Botan::Private_Key* privateKey = Botan::PKCS8::load_key(getPrivateKeyFilename(), m_rng, PRIVATE_KEY_PASSWORD);
Botan::RSA_PrivateKey *rsaKey = dynamic_cast<Botan::RSA_PrivateKey *>(privateKey);
if (!rsaKey)
{
std::cout << "The key is not a RSA key" << std::endl;
@@ -219,7 +219,7 @@ bool Generator::loadPrivateKeyFromString(const std::string& key)
Botan::DataSource_Memory in(key);
Botan::Private_Key* privateKey= Botan::PKCS8::load_key(in, m_rng, PRIVATE_KEY_PASSWORD);
Botan::RSA_PrivateKey *rsaKey = dynamic_cast<Botan::RSA_PrivateKey *>(privateKey);
if (!rsaKey)
{
std::cout << "The key is not a RSA key" << std::endl;
+4 -4
View File
@@ -20,7 +20,7 @@ public:
for (size_t i = 0; i < bookmarkCount; i++)
{
const Id categoryId = storage.addBookmarkCategory("test category");
storage.addBookmark("test bookmark", "test comment", TimePoint::now().toString(), categoryId);
storage.addBookmark("test bookmark", "test comment", TimeStamp::now().toString(), categoryId);
}
result = storage.getAllBookmarks().size();
@@ -42,7 +42,7 @@ public:
storage.setup();
const Id categoryId = storage.addBookmarkCategory("test category");
const Id bookmarkId = storage.addBookmark("test bookmark", "test comment", TimePoint::now().toString(), categoryId);
const Id bookmarkId = storage.addBookmark("test bookmark", "test comment", TimeStamp::now().toString(), categoryId);
for (size_t i = 0; i < bookmarkCount; i++)
{
@@ -67,7 +67,7 @@ public:
storage.setup();
const Id categoryId = storage.addBookmarkCategory("test category");
const Id bookmarkId = storage.addBookmark("test bookmark", "test comment", TimePoint::now().toString(), categoryId);
const Id bookmarkId = storage.addBookmark("test bookmark", "test comment", TimeStamp::now().toString(), categoryId);
storage.addBookmarkedNode(bookmarkId, "test name");
storage.removeBookmark(bookmarkId);
@@ -94,7 +94,7 @@ public:
storage.setup();
const Id categoryId = storage.addBookmarkCategory("test category");
const Id bookmarkId = storage.addBookmark("test bookmark", "test comment", TimePoint::now().toString(), categoryId);
const Id bookmarkId = storage.addBookmark("test bookmark", "test comment", TimeStamp::now().toString(), categoryId);
storage.addBookmarkedNode(bookmarkId, "test name");
storage.updateBookmark(bookmarkId, updatedName, updatedComment, categoryId);