summaryrefslogtreecommitdiff
path: root/sfx2/source
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@collabora.com>2014-10-08 10:55:15 +0200
committerJan Holesovsky <kendy@collabora.com>2014-10-08 11:00:53 +0200
commit35da89fa1428f5286304fc707252242554d49ea6 (patch)
treec57b8af55077873b88b5e908f4f84233cf47f8a3 /sfx2/source
parent77d86709d5b03caccd8a28fbab7bf752d4bc3243 (diff)
usage info: Code to collect actions that the user performs.
Handles the .uno: and .slot: commands. Cannot load / save the info yet, only dumps it to the screen at the application exit. Disabled in the code now, needs a configuration option. Change-Id: I4e689f534fe5c8a5af84df472e47f276fb7af89b
Diffstat (limited to 'sfx2/source')
-rw-r--r--sfx2/source/control/unoctitm.cxx113
1 files changed, 113 insertions, 0 deletions
diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx
index b9b012af2693..f0c3c77362fb 100644
--- a/sfx2/source/control/unoctitm.cxx
+++ b/sfx2/source/control/unoctitm.cxx
@@ -30,6 +30,7 @@
#include <tools/urlobj.hxx>
#include <com/sun/star/util/URLTransformer.hpp>
#include <com/sun/star/util/XURLTransformer.hpp>
+#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/frame/XController.hpp>
#include <com/sun/star/frame/XFrameActionListener.hpp>
#include <com/sun/star/frame/XComponentLoader.hpp>
@@ -39,6 +40,7 @@
#include <com/sun/star/frame/status/ItemStatus.hpp>
#include <com/sun/star/frame/status/ItemState.hpp>
#include <com/sun/star/frame/DispatchResultState.hpp>
+#include <com/sun/star/frame/ModuleManager.hpp>
#include <com/sun/star/frame/status/Visibility.hpp>
#include <comphelper/processfactory.hxx>
#include <comphelper/sequence.hxx>
@@ -62,6 +64,7 @@
#include <boost/scoped_ptr.hpp>
+using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::util;
@@ -591,11 +594,121 @@ OUString SfxDispatchController_Impl::getSlaveCommand( const ::com::sun::star::ut
return aSlaveCommand;
}
+namespace {
+
+/// Class that collects the usage information.
+class UsageInfo {
+
+ typedef std::map<OUString, int> UsageMap;
+
+ /// Command vs. how many times it was used
+ UsageMap maUsage;
+
+public:
+ UsageInfo()
+ {
+ load();
+ }
+
+ ~UsageInfo()
+ {
+ save();
+ }
+
+ /// Increment command's use.
+ void increment(const OUString &rCommand);
+
+ /// Load the usage data from the previous session.
+ void load();
+
+ /// Save the usage data for the next session.
+ void save();
+};
+
+void UsageInfo::increment(const OUString &rCommand)
+{
+ UsageMap::iterator it = maUsage.find(rCommand);
+
+ if (it != maUsage.end())
+ ++(it->second);
+ else
+ maUsage[rCommand] = 1;
+}
+
+void UsageInfo::load()
+{
+ // TODO - do the real loading here
+}
+
+void UsageInfo::save()
+{
+ // 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)
+ {
+ std::cerr << it->first << ';' << it->second << std::endl;
+ }
+ std::cerr << "Usage information end" << std::endl;
+}
+
+class theUsageInfo : public rtl::Static<UsageInfo, theUsageInfo> {};
+
+/// Extracts information about the command + args, and stores that.
+void collectUsageInformation(const util::URL& rURL, const uno::Sequence<beans::PropertyValue>& rArgs)
+{
+ if (/*TODO disabled now, bind this to a config option instead*/true)
+ return;
+
+ OUStringBuffer aBuffer;
+
+ // app identification [uh, several UNO calls :-(]
+ uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
+ uno::Reference<frame::XModuleManager2> xModuleManager(frame::ModuleManager::create(xContext));
+ uno::Reference<frame::XDesktop2> xDesktop = frame::Desktop::create(xContext);
+ uno::Reference<frame::XFrame> xFrame = xDesktop->getCurrentFrame();
+
+ OUString aModule(xModuleManager->identify(xFrame));
+ sal_Int32 nLastDot = aModule.lastIndexOf('.');
+ if (nLastDot >= 0)
+ aModule = aModule.copy(nLastDot + 1);
+
+ aBuffer.append(aModule);
+ aBuffer.append(';');
+
+ // command
+ aBuffer.append(rURL.Protocol);
+ aBuffer.append(rURL.Path);
+ sal_Int32 nCount = rArgs.getLength();
+
+ // parameters - only their names, not the values (could be sensitive!)
+ if (nCount > 0)
+ {
+ aBuffer.append('(');
+ for (sal_Int32 n = 0; n < nCount; n++)
+ {
+ const ::com::sun::star::beans::PropertyValue& rProp = rArgs[n];
+ if (n > 0)
+ aBuffer.append(',');
+ aBuffer.append(rProp.Name);
+ }
+ aBuffer.append(')');
+ }
+
+ OUString aCommand(aBuffer.makeStringAndClear());
+
+ // store
+ theUsageInfo::get().increment(aCommand);
+}
+
+}
+
void SAL_CALL SfxDispatchController_Impl::dispatch( const ::com::sun::star::util::URL& aURL,
const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs,
const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchResultListener >& rListener )
throw (css::uno::RuntimeException, std::exception)
{
+ collectUsageInformation(aURL, aArgs);
+
SolarMutexGuard aGuard;
if (
pDispatch &&