From 35da89fa1428f5286304fc707252242554d49ea6 Mon Sep 17 00:00:00 2001 From: Jan Holesovsky Date: Wed, 8 Oct 2014 10:55:15 +0200 Subject: 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 --- sfx2/source/control/unoctitm.cxx | 113 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) (limited to 'sfx2') 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 #include #include +#include #include #include #include @@ -39,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -62,6 +64,7 @@ #include +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 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 {}; + +/// Extracts information about the command + args, and stores that. +void collectUsageInformation(const util::URL& rURL, const uno::Sequence& rArgs) +{ + if (/*TODO disabled now, bind this to a config option instead*/true) + return; + + OUStringBuffer aBuffer; + + // app identification [uh, several UNO calls :-(] + uno::Reference xContext = ::comphelper::getProcessComponentContext(); + uno::Reference xModuleManager(frame::ModuleManager::create(xContext)); + uno::Reference xDesktop = frame::Desktop::create(xContext); + uno::Reference 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 && -- cgit