20#include <config_folders.h>
23#include <com/sun/star/frame/Desktop.hpp>
24#include <com/sun/star/frame/XSynchronousDispatch.hpp>
25#include <com/sun/star/lang/XServiceInfo.hpp>
27#include <osl/file.hxx>
28#include <rtl/bootstrap.hxx>
40class RecoveryUI :
public ::cppu::WeakImplHelper< css::lang::XServiceInfo ,
41 css::frame::XSynchronousDispatch >
61 css::uno::Reference< css::uno::XComponentContext >
m_xContext;
67 RecoveryUI::EJob m_eJob;
77 explicit RecoveryUI(css::uno::Reference< css::uno::XComponentContext > xContext);
88 virtual css::uno::Any SAL_CALL dispatchWithReturnValue(
const css::util::URL& aURL,
89 const css::uno::Sequence< css::beans::PropertyValue >& lArguments )
override;
99 EJob impl_classifyJob(
const css::util::URL& aURL);
101 bool impl_doEmergencySave();
103 bool impl_doRecovery();
105 void impl_showAllRecoveredDocs();
107 bool impl_doBringToFront();
110RecoveryUI::RecoveryUI(css::uno::Reference< css::uno::XComponentContext > xContext)
112 , m_pParentWindow(nullptr)
113 , m_eJob(RecoveryUI::E_JOB_UNKNOWN)
118OUString SAL_CALL RecoveryUI::getImplementationName()
120 return "com.sun.star.comp.svx.RecoveryUI";
123sal_Bool SAL_CALL RecoveryUI::supportsService(
const OUString& sServiceName)
128css::uno::Sequence< OUString > SAL_CALL RecoveryUI::getSupportedServiceNames()
130 return {
"com.sun.star.dialog.RecoveryUI" };
133css::uno::Any SAL_CALL RecoveryUI::dispatchWithReturnValue(
const css::util::URL& aURL,
134 const css::uno::Sequence< css::beans::PropertyValue >& )
141 RecoveryUI::EJob eJob = impl_classifyJob(aURL);
146 case RecoveryUI::E_DO_EMERGENCY_SAVE:
148 bool bRet = impl_doEmergencySave();
153 case RecoveryUI::E_DO_RECOVERY:
155 bool bRet = impl_doRecovery();
160 case RecoveryUI::E_DO_BRINGTOFRONT:
162 bool bRet = impl_doBringToFront();
178OUString GetCrashConfigDir()
182 OUString ustrValue =
"${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER
"/bootstrap.ini:UserInstallation}";
184 OUString ustrValue =
"~";
186 OUString ustrValue =
"$SYSUSERCONFIG";
188 rtl::Bootstrap::expandMacros( ustrValue );
191 ustrValue +=
"/user/crashdata";
198#define LCKFILE "crashdat.lck"
200#define LCKFILE ".crash_report_unsent"
204OUString GetUnsentURL()
211bool delete_pending_crash()
213 OUString aUnsentURL = GetUnsentURL();
214 return ( FileBase::E_None == File::remove( aUnsentURL ) );
217RecoveryUI::EJob RecoveryUI::impl_classifyJob(
const css::util::URL& aURL)
219 m_eJob = RecoveryUI::E_JOB_UNKNOWN;
223 m_eJob = RecoveryUI::E_DO_EMERGENCY_SAVE;
225 m_eJob = RecoveryUI::E_DO_RECOVERY;
227 m_eJob = RecoveryUI::E_DO_BRINGTOFRONT;
233struct DialogReleaseGuard
235 RecoveryUI& m_rRecoveryUI;
237 DialogReleaseGuard(RecoveryUI& rRecoveryUI,
weld::Dialog* p)
238 : m_rRecoveryUI(rRecoveryUI)
240 m_rRecoveryUI.SetActiveDialog(p);
242 ~DialogReleaseGuard()
244 m_rRecoveryUI.SetActiveDialog(
nullptr);
248bool RecoveryUI::impl_doEmergencySave()
254 std::unique_ptr<svxdr::SaveDialog> xDialog(
new svxdr::SaveDialog(m_pParentWindow, pCore.get()));
255 DialogReleaseGuard dialogReleaseGuard(*
this, xDialog->getDialog());
258 short nRet = xDialog->run();
262bool RecoveryUI::impl_doRecovery()
269 std::unique_ptr<svxdr::RecoveryDialog> xDialog(
new svxdr::RecoveryDialog(m_pParentWindow, pCore.get()));
270 DialogReleaseGuard dialogReleaseGuard(*
this, xDialog->getDialog());
273 short nRet = xDialog->run();
275 impl_showAllRecoveredDocs();
277 delete_pending_crash();
282void RecoveryUI::impl_showAllRecoveredDocs()
284 css::uno::Reference< css::frame::XDesktop2 > xDesktop = css::frame::Desktop::create( m_xContext );
286 css::uno::Reference< css::container::XIndexAccess > xTaskContainer(
287 xDesktop->getFrames(),
288 css::uno::UNO_QUERY_THROW);
290 sal_Int32 c = xTaskContainer->getCount();
296 css::uno::Reference< css::frame::XFrame > xTask;
297 xTaskContainer->getByIndex(i) >>= xTask;
301 css::uno::Reference< css::awt::XWindow > xWindow = xTask->getContainerWindow();
305 xWindow->setVisible(
true);
307 catch(
const css::uno::RuntimeException&)
309 catch(
const css::uno::Exception&)
314bool RecoveryUI::impl_doBringToFront()
316 if (!m_pDialog || !m_pDialog->get_visible())
318 m_pDialog->present();
324extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
326 css::uno::XComponentContext *context,
327 css::uno::Sequence<css::uno::Any>
const &)
329 return cppu::acquire(
new RecoveryUI(context));
Reference< XComponentContext > m_xContext
#define DLG_RET_OK_AUTOLUNCH
#define RECOVERY_CMDPART_DO_EMERGENCY_SAVE
#define RECOVERY_CMDPART_DO_RECOVERY
#define RECOVERY_CMDPART_PROTOCOL
#define RECOVERY_CMDPART_DO_BRINGTOFRONT
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_svx_RecoveryUI_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)