소스 검색

add user track logics

Le Tan 6 년 전
부모
커밋
5fff26a8b6
6개의 변경된 파일56개의 추가작업 그리고 0개의 파일을 삭제
  1. 7 0
      src/resources/user_stat.html
  2. 3 0
      src/resources/vnote.ini
  3. 13 0
      src/vconfigmanager.h
  4. 30 0
      src/vmainwindow.cpp
  5. 2 0
      src/vmainwindow.h
  6. 1 0
      src/vnote.qrc

+ 7 - 0
src/resources/user_stat.html

@@ -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>

+ 3 - 0
src/resources/vnote.ini

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

+ 13 - 0
src/vconfigmanager.h

@@ -631,6 +631,9 @@ public:
     bool getEnableSmartTable() const;
     void setEnableSmartTable(bool p_enabled);
 
+    bool getAllowUserTrack() const;
+    void setAllowUserTrack(bool p_enabled);
+
 private:
     void initEditorConfigs();
 
@@ -2919,4 +2922,14 @@ inline void VConfigManager::setEnableSmartTable(bool p_enabled)
     m_enableSmartTable = p_enabled;
     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

+ 30 - 0
src/vmainwindow.cpp

@@ -3,6 +3,7 @@
 #include <QPrinter>
 #include <QPrintDialog>
 #include <QPainter>
+#include <QWebEnginePage>
 
 #include "vmainwindow.h"
 #include "vdirectorytree.h"
@@ -3423,6 +3424,23 @@ void VMainWindow::kickOffStartUpTimer(const QStringList &p_files)
             VFile *file = vnote->getFile(docFile, true);
             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);
     }
 }
+
+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();
+            });
+}
+

+ 2 - 0
src/vmainwindow.h

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

+ 1 - 0
src/vnote.qrc

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