add user track logics

This commit is contained in:
Le Tan 2019-01-25 09:05:28 +08:00
parent 1675b944c4
commit 5fff26a8b6
6 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,7 @@
<html>
<head>
<script type="text/javascript" src="http://tajs.qq.com/stats?sId=66167380" charset="UTF-8"></script>
</head>
<body>
</body>
</html>

View File

@ -283,6 +283,9 @@ split_tag_file_list=false
; 3 - software; ; 3 - software;
windows_opengl=0 windows_opengl=0
; Whether allow VNote to send request for couting users
allow_user_track=true
[editor] [editor]
; Auto indent as previous line ; Auto indent as previous line
auto_indent=true auto_indent=true

View File

@ -631,6 +631,9 @@ public:
bool getEnableSmartTable() const; bool getEnableSmartTable() const;
void setEnableSmartTable(bool p_enabled); void setEnableSmartTable(bool p_enabled);
bool getAllowUserTrack() const;
void setAllowUserTrack(bool p_enabled);
private: private:
void initEditorConfigs(); void initEditorConfigs();
@ -2919,4 +2922,14 @@ inline void VConfigManager::setEnableSmartTable(bool p_enabled)
m_enableSmartTable = p_enabled; m_enableSmartTable = p_enabled;
setConfigToSettings("editor", "enable_smart_table", m_enableSmartTable); setConfigToSettings("editor", "enable_smart_table", m_enableSmartTable);
} }
inline bool VConfigManager::getAllowUserTrack() const
{
return getConfigFromSettings("global", "allow_user_track").toBool();
}
inline void VConfigManager::setAllowUserTrack(bool p_enabled)
{
setConfigToSettings("global", "allow_user_track", p_enabled);
}
#endif // VCONFIGMANAGER_H #endif // VCONFIGMANAGER_H

View File

@ -3,6 +3,7 @@
#include <QPrinter> #include <QPrinter>
#include <QPrintDialog> #include <QPrintDialog>
#include <QPainter> #include <QPainter>
#include <QWebEnginePage>
#include "vmainwindow.h" #include "vmainwindow.h"
#include "vdirectorytree.h" #include "vdirectorytree.h"
@ -3423,6 +3424,23 @@ void VMainWindow::kickOffStartUpTimer(const QStringList &p_files)
VFile *file = vnote->getFile(docFile, true); VFile *file = vnote->getFile(docFile, true);
m_editArea->openFile(file, OpenFileMode::Read); m_editArea->openFile(file, OpenFileMode::Read);
} }
if (g_config->versionChanged()) {
// Ask user whether allow tracking.
int ret = VUtils::showMessage(QMessageBox::Information,
tr("Collect User Statistics"),
tr("VNote would like to send a request to count active users."
"Do you allow this request?"),
tr("A request to https://tajs.qq.com/stats will be sent if allowed."),
QMessageBox::Ok | QMessageBox::No,
QMessageBox::Ok,
this);
g_config->setAllowUserTrack(ret == QMessageBox::Ok);
}
if (g_config->getAllowUserTrack()) {
QTimer::singleShot(60000, this, SLOT(collectUserStat()));
}
}); });
} }
@ -3524,3 +3542,15 @@ void VMainWindow::setupFileListSplitOut(bool p_enabled)
m_nbSplitter->setStretchFactor(1, 2); m_nbSplitter->setStretchFactor(1, 2);
} }
} }
void VMainWindow::collectUserStat() const
{
QWebEnginePage *page = new QWebEnginePage;
page->load(QUrl("qrc:/resources/user_stat.html"));
connect(page, &QWebEnginePage::loadFinished,
this, [page](bool) {
VUtils::sleepWait(2000);
page->deleteLater();
});
}

View File

@ -212,6 +212,8 @@ private slots:
void splitFileListOut(bool p_enabled); void splitFileListOut(bool p_enabled);
void collectUserStat() const;
protected: protected:
void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE; void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;

View File

@ -287,5 +287,6 @@
<file>resources/icons/table.svg</file> <file>resources/icons/table.svg</file>
<file>utils/wavedrom/wavedrom.min.js</file> <file>utils/wavedrom/wavedrom.min.js</file>
<file>utils/wavedrom/wavedrom-theme.js</file> <file>utils/wavedrom/wavedrom-theme.js</file>
<file>resources/user_stat.html</file>
</qresource> </qresource>
</RCC> </RCC>