[Libreoffice-commits] core.git: sfx2/source

Aybuke Ozdemir aybuke.147 at gmail.com
Sun Jan 10 04:23:27 PST 2016


 sfx2/source/control/unoctitm.cxx |   30 +++++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)

New commits:
commit d61c16966b017abdbebf5ec0c2131de5a91c67f8
Author: Aybuke Ozdemir <aybuke.147 at gmail.com>
Date:   Sat Dec 5 16:19:56 2015 +0200

    tdf#95505 Dump usage stats to text file
    
    1de031c94b2ef9c4ae45a8906b250a95d3c47c47
    
    Change-Id: I1de031c94b2ef9c4ae45a8906b250a95d3c47c47
    Reviewed-on: https://gerrit.libreoffice.org/20413
    Reviewed-by: jan iversen <jani at documentfoundation.org>
    Tested-by: jan iversen <jani at documentfoundation.org>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx
index 8645826..1a82906 100644
--- a/sfx2/source/control/unoctitm.cxx
+++ b/sfx2/source/control/unoctitm.cxx
@@ -65,6 +65,9 @@
 #include "statcach.hxx"
 #include <sfx2/msgpool.hxx>
 #include <sfx2/objsh.hxx>
+#include <osl/file.hxx>
+#include <rtl/ustring.hxx>
+#include <unotools/pathoptions.hxx>
 
 #include <iostream>
 #include <map>
@@ -74,6 +77,8 @@
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
 #include <comphelper/lok.hxx>
 
+#define USAGE "file:///~/.config/libreofficedev/4/user/usage.txt"
+
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::uno;
 using namespace ::com::sun::star::util;
@@ -640,13 +645,28 @@ void UsageInfo::save()
     if (!mbIsCollecting)
         return;
 
-    // TODO - do a real saving here, not only dump to the screen
-    std::cerr << "Usage information:" << std::endl;
-    for (UsageMap::const_iterator it = maUsage.begin(); it != maUsage.end(); ++it)
+    const OUString path(USAGE);
+    osl::File file(path);
+
+    if( file.open(osl_File_OpenFlag_Read | osl_File_OpenFlag_Write | osl_File_OpenFlag_Create) == osl::File::E_None )
     {
-        std::cerr << it->first << ';' << it->second << std::endl;
+        OString jan = "Usage information:\n";
+
+        for (UsageMap::const_iterator it = maUsage.begin(); it != maUsage.end(); ++it)
+            jan += "\n" + it->first.toUtf8() + ";" + OString::number(it->second);
+
+        jan += "\nUsage information end\n";
+        sal_uInt64 written = 0;
+        file.write(jan.pData->buffer, jan.getLength(), written);
+        file.close();
+    }
+
+    else{
+        std::cerr << "Usage information:" << std::endl;
+        for (UsageMap::const_iterator it = maUsage.begin(); it != maUsage.end(); ++it)
+            std::cerr << it->first << ';' << it->second << std::endl;
+        std::cerr << "Usage information end" << std::endl;
     }
-    std::cerr << "Usage information end" << std::endl;
 }
 
 class theUsageInfo : public rtl::Static<UsageInfo, theUsageInfo> {};


More information about the Libreoffice-commits mailing list