merge the formfield patch from ooo-build
[ooovba.git] / svx / source / dialog / docrecovery.cxx
blobcd828cfaa8c0661bec7555b463c0653e000e681e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: docrecovery.cxx,v $
10 * $Revision: 1.24 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <svx/dialmgr.hxx>
35 #include <svx/dialogs.hrc>
36 #include "docrecovery.hxx"
37 #include "docrecovery.hrc"
39 #include <comphelper/processfactory.hxx>
40 #include <comphelper/sequenceashashmap.hxx>
41 #include <comphelper/configurationhelper.hxx>
42 #include <svtools/imagemgr.hxx>
43 #include <svtools/xtextedt.hxx>
44 #include <tools/urlobj.hxx>
45 #include <vcl/msgbox.hxx>
46 #include <vcl/svapp.hxx>
47 #include <rtl/ustrbuf.hxx>
48 #include <vcl/scrbar.hxx>
50 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
51 #include <toolkit/unohlp.hxx>
52 #endif
54 //#include "com/sun/star/lang/XMultiServiceFactory.hpp"
55 #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
56 #include <com/sun/star/lang/XInitialization.hpp>
57 //#include <com/sun/star/beans/PropertyValue.hpp>
58 #include <com/sun/star/beans/NamedValue.hpp>
59 #include <com/sun/star/util/URL.hpp>
60 #include <com/sun/star/util/XURLTransformer.hpp>
61 #include <com/sun/star/frame/XDispatch.hpp>
62 #include <com/sun/star/awt/XWindow.hpp>
63 #include <com/sun/star/ui/dialogs/XFolderPicker.hpp>
64 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
65 #include <osl/file.hxx>
66 #include <osl/security.hxx>
67 #include <rtl/bootstrap.hxx>
68 #include <svtools/pathoptions.hxx>
69 #include <unotools/localfilehelper.hxx>
71 #define RET_BACK 100
73 //===============================================
74 // namespace
75 namespace svx{
76 namespace DocRecovery{
78 namespace css = ::com::sun::star;
80 using namespace ::rtl;
81 using namespace ::osl;
83 //===============================================
84 TabDialog4Recovery::TabDialog4Recovery(Window* pParent)
85 : TabDialog (pParent, SVX_RES( RID_SVX_TABDLG_DOCRECOVERY ))
86 , m_pActualPage(m_lTabPages.begin() )
90 //===============================================
91 TabDialog4Recovery::~TabDialog4Recovery()
93 m_lTabPages.clear();
96 //===============================================
97 void TabDialog4Recovery::addTabPage(IExtendedTabPage* pPage)
99 if (pPage)
100 m_lTabPages.push_back(pPage);
103 //===============================================
104 short TabDialog4Recovery::Execute()
106 ::vos::OGuard aLock(Application::GetSolarMutex());
108 Show();
109 m_pActualPage = m_lTabPages.begin();
110 while(sal_True)
112 IExtendedTabPage* pPage = *m_pActualPage;
113 SetViewWindow(pPage);
114 pPage->Show();
115 pPage->setDefButton();
116 short nRet = pPage->execute();
117 pPage->Hide();
119 switch(nRet)
121 case DLG_RET_OK :
123 ++m_pActualPage;
124 if (m_pActualPage == m_lTabPages.end())
125 return nRet;
127 break;
129 case DLG_RET_BACK :
131 if (m_pActualPage != m_lTabPages.begin())
132 --m_pActualPage;
134 break;
136 case DLG_RET_UNKNOWN :
137 case DLG_RET_CANCEL :
138 case DLG_RET_OK_AUTOLUNCH :
139 return nRet;
144 //===============================================
145 RecoveryCore::RecoveryCore(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR ,
146 sal_Bool bUsedForSaving)
147 : m_xSMGR ( xSMGR )
148 , m_pListener ( 0 )
149 , m_bListenForSaving(bUsedForSaving)
151 impl_startListening();
154 //===============================================
155 RecoveryCore::~RecoveryCore()
157 impl_stopListening();
160 //===============================================
161 css::uno::Reference< css::lang::XMultiServiceFactory > RecoveryCore::getSMGR()
163 return m_xSMGR;
166 //===============================================
167 TURLList* RecoveryCore::getURLListAccess()
169 return &m_lURLs;
172 //===============================================
173 sal_Bool RecoveryCore::existsBrokenTempEntries()
175 TURLList::const_iterator pIt;
176 for ( pIt = m_lURLs.begin();
177 pIt != m_lURLs.end() ;
178 ++pIt )
180 const TURLInfo& rInfo = *pIt;
181 if (RecoveryCore::isBrokenTempEntry(rInfo))
182 return sal_True;
185 return sal_False;
188 //===============================================
189 sal_Bool RecoveryCore::existsNonRecoveredEntries()
191 TURLList::const_iterator pIt;
192 for ( pIt = m_lURLs.begin();
193 pIt != m_lURLs.end() ;
194 ++pIt )
196 const TURLInfo& rInfo = *pIt;
197 if (rInfo.RecoveryState == E_NOT_RECOVERED_YET)
198 return sal_True;
201 return sal_False;
204 //===============================================
205 sal_Bool RecoveryCore::isBrokenTempEntry(const TURLInfo& rInfo)
207 if (!rInfo.TempURL.getLength())
208 return sal_False;
210 // Note: If the original files was recovery ... but a temp file
211 // exists ... an error inside the temp file exists!
212 if (
213 !(rInfo.RecoveryState == E_RECOVERY_FAILED ) &&
214 !(rInfo.RecoveryState == E_ORIGINAL_DOCUMENT_RECOVERED)
216 return sal_False;
218 return sal_True;
221 //===============================================
222 void RecoveryCore::saveBrokenTempEntries(const ::rtl::OUString& sPath)
224 if (!sPath.getLength())
225 return;
227 if (!m_xRealCore.is())
228 return;
230 // prepare all needed parameters for the following dispatch() request.
231 css::util::URL aCopyURL = impl_getParsedURL(RECOVERY_CMD_DO_ENTRY_BACKUP);
232 css::uno::Sequence< css::beans::PropertyValue > lCopyArgs(3);
233 lCopyArgs[0].Name = PROP_DISPATCHASYNCHRON;
234 lCopyArgs[0].Value <<= sal_False;
235 lCopyArgs[1].Name = PROP_SAVEPATH;
236 lCopyArgs[1].Value <<= sPath;
237 lCopyArgs[2].Name = PROP_ENTRYID;
238 // lCopyArgs[2].Value will be changed during next loop ...
240 // work on a copied list only ...
241 // Reason: We will get notifications from the core for every
242 // changed or removed element. And that will change our m_lURLs list.
243 // That's not a good idea, if we use a stl iterator inbetween .-)
244 TURLList lURLs = m_lURLs;
245 TURLList::const_iterator pIt;
246 for ( pIt = lURLs.begin();
247 pIt != lURLs.end() ;
248 ++pIt )
250 const TURLInfo& rInfo = *pIt;
251 if (!RecoveryCore::isBrokenTempEntry(rInfo))
252 continue;
254 lCopyArgs[2].Value <<= rInfo.ID;
255 m_xRealCore->dispatch(aCopyURL, lCopyArgs);
259 //===============================================
260 void RecoveryCore::saveAllTempEntries(const ::rtl::OUString& sPath)
262 if (!sPath.getLength())
263 return;
265 if (!m_xRealCore.is())
266 return;
268 // prepare all needed parameters for the following dispatch() request.
269 css::util::URL aCopyURL = impl_getParsedURL(RECOVERY_CMD_DO_ENTRY_BACKUP);
270 css::uno::Sequence< css::beans::PropertyValue > lCopyArgs(3);
271 lCopyArgs[0].Name = PROP_DISPATCHASYNCHRON;
272 lCopyArgs[0].Value <<= sal_False;
273 lCopyArgs[1].Name = PROP_SAVEPATH;
274 lCopyArgs[1].Value <<= sPath;
275 lCopyArgs[2].Name = PROP_ENTRYID;
276 // lCopyArgs[2].Value will be changed during next loop ...
278 // work on a copied list only ...
279 // Reason: We will get notifications from the core for every
280 // changed or removed element. And that will change our m_lURLs list.
281 // That's not a good idea, if we use a stl iterator inbetween .-)
282 TURLList lURLs = m_lURLs;
283 TURLList::const_iterator pIt;
284 for ( pIt = lURLs.begin();
285 pIt != lURLs.end() ;
286 ++pIt )
288 const TURLInfo& rInfo = *pIt;
289 if (!rInfo.TempURL.getLength())
290 continue;
292 lCopyArgs[2].Value <<= rInfo.ID;
293 m_xRealCore->dispatch(aCopyURL, lCopyArgs);
297 //===============================================
298 void RecoveryCore::forgetBrokenTempEntries()
300 if (!m_xRealCore.is())
301 return;
303 css::util::URL aRemoveURL = impl_getParsedURL(RECOVERY_CMD_DO_ENTRY_CLEANUP);
304 css::uno::Sequence< css::beans::PropertyValue > lRemoveArgs(2);
305 lRemoveArgs[0].Name = PROP_DISPATCHASYNCHRON;
306 lRemoveArgs[0].Value <<= sal_False;
307 lRemoveArgs[1].Name = PROP_ENTRYID;
308 // lRemoveArgs[1].Value will be changed during next loop ...
310 // work on a copied list only ...
311 // Reason: We will get notifications from the core for every
312 // changed or removed element. And that will change our m_lURLs list.
313 // That's not a good idea, if we use a stl iterator inbetween .-)
314 TURLList lURLs = m_lURLs;
315 TURLList::const_iterator pIt;
316 for ( pIt = lURLs.begin();
317 pIt != lURLs.end() ;
318 ++pIt )
320 const TURLInfo& rInfo = *pIt;
321 if (!RecoveryCore::isBrokenTempEntry(rInfo))
322 continue;
324 lRemoveArgs[1].Value <<= rInfo.ID;
325 m_xRealCore->dispatch(aRemoveURL, lRemoveArgs);
329 //===============================================
330 void RecoveryCore::forgetAllRecoveryEntries()
332 if (!m_xRealCore.is())
333 return;
335 css::util::URL aRemoveURL = impl_getParsedURL(RECOVERY_CMD_DO_ENTRY_CLEANUP);
336 css::uno::Sequence< css::beans::PropertyValue > lRemoveArgs(2);
337 lRemoveArgs[0].Name = PROP_DISPATCHASYNCHRON;
338 lRemoveArgs[0].Value <<= sal_False;
339 lRemoveArgs[1].Name = PROP_ENTRYID;
340 // lRemoveArgs[1].Value will be changed during next loop ...
342 // work on a copied list only ...
343 // Reason: We will get notifications from the core for every
344 // changed or removed element. And that will change our m_lURLs list.
345 // That's not a good idea, if we use a stl iterator inbetween .-)
346 TURLList lURLs = m_lURLs;
347 TURLList::const_iterator pIt;
348 for ( pIt = lURLs.begin();
349 pIt != lURLs.end() ;
350 ++pIt )
352 const TURLInfo& rInfo = *pIt;
353 lRemoveArgs[1].Value <<= rInfo.ID;
354 m_xRealCore->dispatch(aRemoveURL, lRemoveArgs);
358 //===============================================
359 void RecoveryCore::forgetBrokenRecoveryEntries()
361 if (!m_xRealCore.is())
362 return;
364 css::util::URL aRemoveURL = impl_getParsedURL(RECOVERY_CMD_DO_ENTRY_CLEANUP);
365 css::uno::Sequence< css::beans::PropertyValue > lRemoveArgs(2);
366 lRemoveArgs[0].Name = PROP_DISPATCHASYNCHRON;
367 lRemoveArgs[0].Value <<= sal_False;
368 lRemoveArgs[1].Name = PROP_ENTRYID;
369 // lRemoveArgs[1].Value will be changed during next loop ...
371 // work on a copied list only ...
372 // Reason: We will get notifications from the core for every
373 // changed or removed element. And that will change our m_lURLs list.
374 // That's not a good idea, if we use a stl iterator inbetween .-)
375 TURLList lURLs = m_lURLs;
376 TURLList::const_iterator pIt;
377 for ( pIt = lURLs.begin();
378 pIt != lURLs.end() ;
379 ++pIt )
381 const TURLInfo& rInfo = *pIt;
382 if (!RecoveryCore::isBrokenTempEntry(rInfo))
383 continue;
385 lRemoveArgs[1].Value <<= rInfo.ID;
386 m_xRealCore->dispatch(aRemoveURL, lRemoveArgs);
390 //===============================================
391 void RecoveryCore::setProgressHandler(const css::uno::Reference< css::task::XStatusIndicator >& xProgress)
393 m_xProgress = xProgress;
396 //===============================================
397 void RecoveryCore::setUpdateListener(IRecoveryUpdateListener* pListener)
399 m_pListener = pListener;
402 //===============================================
403 void RecoveryCore::doEmergencySavePrepare()
405 if (!m_xRealCore.is())
406 return;
408 css::util::URL aURL = impl_getParsedURL(RECOVERY_CMD_DO_PREPARE_EMERGENCY_SAVE);
410 css::uno::Sequence< css::beans::PropertyValue > lArgs(1);
411 lArgs[0].Name = PROP_DISPATCHASYNCHRON;
412 lArgs[0].Value <<= sal_False;
414 m_xRealCore->dispatch(aURL, lArgs);
417 //===============================================
418 void RecoveryCore::doEmergencySave()
420 if (!m_xRealCore.is())
421 return;
423 css::util::URL aURL = impl_getParsedURL(RECOVERY_CMD_DO_EMERGENCY_SAVE);
425 css::uno::Sequence< css::beans::PropertyValue > lArgs(2);
426 lArgs[0].Name = PROP_STATUSINDICATOR;
427 lArgs[0].Value <<= m_xProgress;
428 lArgs[1].Name = PROP_DISPATCHASYNCHRON;
429 lArgs[1].Value <<= sal_True;
431 m_xRealCore->dispatch(aURL, lArgs);
434 //===============================================
435 void RecoveryCore::doRecovery()
437 if (!m_xRealCore.is())
438 return;
440 css::util::URL aURL = impl_getParsedURL(RECOVERY_CMD_DO_RECOVERY);
442 css::uno::Sequence< css::beans::PropertyValue > lArgs(2);
443 lArgs[0].Name = PROP_STATUSINDICATOR;
444 lArgs[0].Value <<= m_xProgress;
445 lArgs[1].Name = PROP_DISPATCHASYNCHRON;
446 lArgs[1].Value <<= sal_True;
448 m_xRealCore->dispatch(aURL, lArgs);
451 //===============================================
452 ERecoveryState RecoveryCore::mapDocState2RecoverState(sal_Int32 eDocState)
454 // ???
455 ERecoveryState eRecState = E_NOT_RECOVERED_YET;
457 /* Attention:
458 Some of the following states can occure at the
459 same time. So we have to check for the "worst case" first!
461 DAMAGED -> INCOMPLETE -> HANDLED
464 // running ...
465 if (
466 ((eDocState & E_TRY_LOAD_BACKUP ) == E_TRY_LOAD_BACKUP ) ||
467 ((eDocState & E_TRY_LOAD_ORIGINAL) == E_TRY_LOAD_ORIGINAL)
469 eRecState = E_RECOVERY_IS_IN_PROGRESS;
470 // red
471 else
472 if ((eDocState & E_DAMAGED) == E_DAMAGED)
473 eRecState = E_RECOVERY_FAILED;
474 // yellow
475 else
476 if ((eDocState & E_INCOMPLETE) == E_INCOMPLETE)
477 eRecState = E_ORIGINAL_DOCUMENT_RECOVERED;
478 // green
479 else
480 if ((eDocState & E_SUCCEDED) == E_SUCCEDED)
481 eRecState = E_SUCCESSFULLY_RECOVERED;
483 return eRecState;
486 //===============================================
487 void SAL_CALL RecoveryCore::statusChanged(const css::frame::FeatureStateEvent& aEvent)
488 throw(css::uno::RuntimeException)
490 // a) special notification about start/stop async dispatch!
491 // FeatureDescriptor = "start" || "stop"
492 if (aEvent.FeatureDescriptor.equals(RECOVERY_OPERATIONSTATE_START))
494 if (m_pListener)
495 m_pListener->start();
496 return;
499 if (aEvent.FeatureDescriptor.equals(RECOVERY_OPERATIONSTATE_STOP))
501 if (m_pListener)
502 m_pListener->end();
503 return;
506 // b) normal notification about changed items
507 // FeatureDescriptor = "Update"
508 // State = Lits of informations [seq< NamedValue >]
509 if (! aEvent.FeatureDescriptor.equals(RECOVERY_OPERATIONSTATE_UPDATE))
510 return;
512 ::comphelper::SequenceAsHashMap lInfo(aEvent.State);
513 TURLInfo aNew;
515 aNew.ID = lInfo.getUnpackedValueOrDefault(STATEPROP_ID , (sal_Int32)0 );
516 aNew.DocState = lInfo.getUnpackedValueOrDefault(STATEPROP_STATE , (sal_Int32)0 );
517 aNew.OrgURL = lInfo.getUnpackedValueOrDefault(STATEPROP_ORGURL , ::rtl::OUString());
518 aNew.TempURL = lInfo.getUnpackedValueOrDefault(STATEPROP_TEMPURL , ::rtl::OUString());
519 aNew.FactoryURL = lInfo.getUnpackedValueOrDefault(STATEPROP_FACTORYURL , ::rtl::OUString());
520 aNew.TemplateURL = lInfo.getUnpackedValueOrDefault(STATEPROP_TEMPLATEURL, ::rtl::OUString());
521 aNew.DisplayName = lInfo.getUnpackedValueOrDefault(STATEPROP_TITLE , ::rtl::OUString());
522 aNew.Module = lInfo.getUnpackedValueOrDefault(STATEPROP_MODULE , ::rtl::OUString());
524 // search for already existing items and update her nState value ...
525 TURLList::iterator pIt;
526 for ( pIt = m_lURLs.begin();
527 pIt != m_lURLs.end() ;
528 ++pIt )
530 TURLInfo& aOld = *pIt;
531 if (aOld.ID == aNew.ID)
533 // change existing
534 aOld.DocState = aNew.DocState;
535 aOld.RecoveryState = RecoveryCore::mapDocState2RecoverState(aOld.DocState);
536 if (m_pListener)
538 m_pListener->updateItems();
539 m_pListener->stepNext(&aOld);
541 return;
545 // append as new one
546 // TODO think about mmatching Module name to a corresponding icon
547 String sURL = aNew.OrgURL;
548 if (!sURL.Len())
549 sURL = aNew.FactoryURL;
550 if (!sURL.Len())
551 sURL = aNew.TempURL;
552 if (!sURL.Len())
553 sURL = aNew.TemplateURL;
554 INetURLObject aURL(sURL);
555 aNew.StandardImage = SvFileInformationManager::GetFileImage(aURL, false, false);
556 aNew.HCImage = SvFileInformationManager::GetFileImage(aURL, false, true );
558 /* set the right UI state for this item to NOT_RECOVERED_YET ... because nDocState shows the state of
559 the last emergency save operation before and is interessting for the used recovery core service only ...
560 for now! But if there is a further notification for this item (see lines above!) we must
561 map the doc state to an UI state. */
562 aNew.RecoveryState = E_NOT_RECOVERED_YET;
564 // patch DisplayName! Because the document title contain more then the file name ...
565 sal_Int32 i = aNew.DisplayName.indexOf(::rtl::OUString::createFromAscii(" - "));
566 if (i > 0)
567 aNew.DisplayName = aNew.DisplayName.copy(0, i);
569 m_lURLs.push_back(aNew);
571 if (m_pListener)
572 m_pListener->updateItems();
575 //===============================================
576 void SAL_CALL RecoveryCore::disposing(const css::lang::EventObject& /*aEvent*/)
577 throw(css::uno::RuntimeException)
579 m_xRealCore.clear();
582 //===============================================
583 void RecoveryCore::impl_startListening()
585 // listening already initialized ?
586 if (m_xRealCore.is())
587 return;
588 m_xRealCore = css::uno::Reference< css::frame::XDispatch >(m_xSMGR->createInstance(SERVICENAME_RECOVERYCORE), css::uno::UNO_QUERY_THROW);
590 css::util::URL aURL;
591 if (m_bListenForSaving)
592 aURL.Complete = RECOVERY_CMD_DO_EMERGENCY_SAVE;
593 else
594 aURL.Complete = RECOVERY_CMD_DO_RECOVERY;
595 css::uno::Reference< css::util::XURLTransformer > xParser(m_xSMGR->createInstance(SERVICENAME_URLTRANSFORMER), css::uno::UNO_QUERY_THROW);
596 xParser->parseStrict(aURL);
598 /* Note: addStatusListener() call us synchronous back ... so we
599 will get the complete list of currently open documents! */
600 m_xRealCore->addStatusListener(static_cast< css::frame::XStatusListener* >(this), aURL);
603 //===============================================
604 void RecoveryCore::impl_stopListening()
606 // Ignore it, if this instance doesnt listen currently
607 if (!m_xRealCore.is())
608 return;
610 css::util::URL aURL;
611 if (m_bListenForSaving)
612 aURL.Complete = RECOVERY_CMD_DO_EMERGENCY_SAVE;
613 else
614 aURL.Complete = RECOVERY_CMD_DO_RECOVERY;
615 css::uno::Reference< css::util::XURLTransformer > xParser(m_xSMGR->createInstance(SERVICENAME_URLTRANSFORMER), css::uno::UNO_QUERY_THROW);
616 xParser->parseStrict(aURL);
618 m_xRealCore->removeStatusListener(static_cast< css::frame::XStatusListener* >(this), aURL);
619 m_xRealCore.clear();
622 //===============================================
623 css::util::URL RecoveryCore::impl_getParsedURL(const ::rtl::OUString& sURL)
625 css::util::URL aURL;
626 aURL.Complete = sURL;
628 css::uno::Reference< css::util::XURLTransformer > xParser(m_xSMGR->createInstance(SERVICENAME_URLTRANSFORMER), css::uno::UNO_QUERY_THROW);
629 xParser->parseStrict(aURL);
631 return aURL;
634 //===============================================
635 PluginProgressWindow::PluginProgressWindow( Window* pParent ,
636 const css::uno::Reference< css::lang::XComponent >& xProgress)
637 : Window (pParent )
638 , m_xProgress(xProgress)
640 Show();
641 Size aParentSize = pParent->GetSizePixel();
642 // align the progressbar to its parent
643 SetPosSizePixel( -9, 0, aParentSize.Width() + 15, aParentSize.Height() - 4 );
646 //===============================================
647 PluginProgressWindow::~PluginProgressWindow()
649 if (m_xProgress.is())
650 m_xProgress->dispose();
653 //===============================================
654 PluginProgress::PluginProgress( Window* pParent,
655 const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR )
657 m_pPlugProgressWindow = new PluginProgressWindow(pParent, static_cast< css::lang::XComponent* >(this));
658 css::uno::Reference< css::awt::XWindow > xProgressWindow = VCLUnoHelper::GetInterface(m_pPlugProgressWindow);
659 m_xProgressFactory = css::uno::Reference< css::task::XStatusIndicatorFactory >(xSMGR->createInstance(SERVICENAME_PROGRESSFACTORY), css::uno::UNO_QUERY_THROW);
660 css::uno::Reference< css::lang::XInitialization > xInit(m_xProgressFactory, css::uno::UNO_QUERY_THROW);
662 css::uno::Sequence< css::uno::Any > lArgs(2);
663 css::beans::NamedValue aProp;
664 aProp.Name = PROP_PARENTWINDOW;
665 aProp.Value <<= xProgressWindow;
666 lArgs[0] <<= aProp;
667 aProp.Name = PROP_ALLOWPARENTSHOW;
668 aProp.Value <<= sal_True;
669 lArgs[1] <<= aProp;
671 xInit->initialize(lArgs);
673 m_xProgress = m_xProgressFactory->createStatusIndicator();
676 //===============================================
677 PluginProgress::~PluginProgress()
681 //===============================================
682 Window* PluginProgress::getPlugWindow()
684 return m_pPlugProgressWindow;
687 //===============================================
688 void SAL_CALL PluginProgress::dispose()
689 throw(css::uno::RuntimeException)
691 // m_pPluginProgressWindow was deleted ...
692 // So the internal pointer of this progress
693 // weill be dead!
694 m_xProgress.clear();
697 //===============================================
698 void SAL_CALL PluginProgress::addEventListener(const css::uno::Reference< css::lang::XEventListener >& )
699 throw(css::uno::RuntimeException)
703 //===============================================
704 void SAL_CALL PluginProgress::removeEventListener( const css::uno::Reference< css::lang::XEventListener >& )
705 throw(css::uno::RuntimeException)
709 //===============================================
710 void SAL_CALL PluginProgress::start(const ::rtl::OUString&,
711 sal_Int32 nRange)
712 throw(css::uno::RuntimeException)
714 if (m_xProgress.is())
715 m_xProgress->start(::rtl::OUString(), nRange);
718 //===============================================
719 void SAL_CALL PluginProgress::end()
720 throw(css::uno::RuntimeException)
722 if (m_xProgress.is())
723 m_xProgress->end();
726 //===============================================
727 void SAL_CALL PluginProgress::setText(const ::rtl::OUString& sText)
728 throw(css::uno::RuntimeException)
730 if (m_xProgress.is())
731 m_xProgress->setText(sText);
734 //===============================================
735 void SAL_CALL PluginProgress::setValue(sal_Int32 nValue)
736 throw(css::uno::RuntimeException)
738 if (m_xProgress.is())
739 m_xProgress->setValue(nValue);
742 //===============================================
743 void SAL_CALL PluginProgress::reset()
744 throw(css::uno::RuntimeException)
746 if (m_xProgress.is())
747 m_xProgress->reset();
750 //===============================================
751 SaveDialog::SaveDialog(Window* pParent,
752 RecoveryCore* pCore )
753 : IExtendedTabPage( pParent, SVX_RES( RID_SVXPAGE_DOCRECOVERY_SAVE ) )
754 , m_aTitleWin ( this , SVX_RES ( WIN_SAVE_TITLE ) )
755 , m_aTitleFT ( this , SVX_RES ( FT_SAVE_TITLE ) )
756 , m_aTitleFL ( this , SVX_RES ( FL_SAVE_TITLE ) )
757 , m_aDescrFT ( this , SVX_RES ( FT_SAVE_DESCR ) )
758 , m_aFileListFT ( this , SVX_RES ( FT_SAVE_FILELIST ) )
759 , m_aFileListLB ( this , SVX_RES ( LB_SAVE_FILELIST ) )
760 , m_aBottomFL ( this , SVX_RES ( FL_SAVE_BOTTOM ) )
761 , m_aOkBtn ( this , SVX_RES ( BT_SAVE_OK ) )
762 , m_pCore ( pCore )
764 FreeResource();
766 // Prepare the office for the following crash save step.
767 // E.g. hide all open widows so the user cant influence our
768 // operation .-)
769 m_pCore->doEmergencySavePrepare();
771 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
772 Wallpaper aBackground(rStyleSettings.GetWindowColor());
773 m_aTitleWin.SetBackground(aBackground);
774 m_aTitleFT.SetBackground (aBackground);
776 Font aFont(m_aTitleFT.GetFont());
777 aFont.SetWeight(WEIGHT_BOLD);
778 m_aTitleFT.SetFont(aFont);
780 m_aOkBtn.SetClickHdl( LINK( this, SaveDialog, OKButtonHdl ) );
781 // m_aFileListLB.EnableInput( sal_False );
782 m_aFileListLB.SetControlBackground( rStyleSettings.GetDialogColor() );
784 // fill listbox with current open documents
785 m_aFileListLB.Clear();
787 TURLList* pURLs = m_pCore->getURLListAccess();
788 TURLList::const_iterator pIt;
790 for ( pIt = pURLs->begin();
791 pIt != pURLs->end() ;
792 ++pIt )
794 const TURLInfo& rInfo = *pIt;
795 m_aFileListLB.InsertEntry( rInfo.DisplayName, rInfo.StandardImage );
799 //===============================================
800 SaveDialog::~SaveDialog()
804 //===============================================
805 IMPL_LINK( SaveDialog, OKButtonHdl, void*, EMPTYARG )
807 m_nResult = DLG_RET_OK;
808 return 0;
811 //===============================================
812 short SaveDialog::execute()
814 ::vos::OGuard aLock(Application::GetSolarMutex());
816 // wait for user input "OK"
817 m_nResult = DLG_RET_UNKNOWN;
818 while(m_nResult == DLG_RET_UNKNOWN)
819 Application::Yield();
821 // start crash-save with progress
822 if (m_nResult == DLG_RET_OK)
824 SaveProgressDialog* pProgress = new SaveProgressDialog(this, m_pCore);
825 m_nResult = pProgress->Execute();
826 delete pProgress;
828 // if "CANCEL" => return "CANCEL"
829 // if "OK" => "AUTOLUNCH" always !
830 if (m_nResult == DLG_RET_OK)
831 m_nResult = DLG_RET_OK_AUTOLUNCH;
833 return m_nResult;
836 //===============================================
837 void SaveDialog::setDefButton()
839 m_aOkBtn.GrabFocus();
842 //===============================================
843 SaveProgressDialog::SaveProgressDialog(Window* pParent,
844 RecoveryCore* pCore )
845 : ModalDialog ( pParent , SVX_RES( RID_SVX_MDLG_DOCRECOVERY_PROGR ) )
846 , m_aHintFT ( this , SVX_RES ( FT_SAVEPROGR_HINT ) )
847 , m_aProgrFT ( this , SVX_RES ( FT_SAVEPROGR_PROGR ) )
848 , m_aProgrParent( this , SVX_RES ( WIN_SAVEPROGR_PROGR ) )
849 , m_pCore ( pCore )
851 FreeResource();
852 PluginProgress* pProgress = new PluginProgress( &m_aProgrParent, pCore->getSMGR() );
853 m_xProgress = css::uno::Reference< css::task::XStatusIndicator >(static_cast< css::task::XStatusIndicator* >(pProgress), css::uno::UNO_QUERY_THROW);
854 // m_aProgrBaseTxt = m_aProgrFT.GetText();
857 //===============================================
858 SaveProgressDialog::~SaveProgressDialog()
862 //===============================================
863 short SaveProgressDialog::Execute()
865 ::vos::OGuard aLock(Application::GetSolarMutex());
867 m_pCore->setProgressHandler(m_xProgress);
868 m_pCore->setUpdateListener(this);
869 m_pCore->doEmergencySave();
870 short nRet = ModalDialog::Execute();
871 m_pCore->setUpdateListener(0);
872 return nRet;
875 //===============================================
876 void SaveProgressDialog::updateItems()
880 //===============================================
881 void SaveProgressDialog::stepNext(TURLInfo* )
883 /* TODO
885 wenn die m_pCore noch ein Member m_nCurrentItem haette
886 koennte man dort erkennen, wer gerade drann war, wer demnaechst
887 dran ist ... Diese Info kann man dann in unserem Progress FixText anzeigen ...
891 //===============================================
892 void SaveProgressDialog::start()
896 //===============================================
897 void SaveProgressDialog::end()
899 EndDialog(DLG_RET_OK);
902 //===============================================
903 RecovDocListEntry::RecovDocListEntry( SvLBoxEntry* pEntry,
904 USHORT nFlags,
905 const String& sText )
906 : SvLBoxString( pEntry, nFlags, sText )
910 //===============================================
911 void RecovDocListEntry::Paint(const Point& aPos ,
912 SvLBox& aDevice,
913 USHORT /*nFlags */,
914 SvLBoxEntry* pEntry )
916 const Image* pImg = 0;
917 const String* pTxt = 0;
918 RecovDocList* pList = static_cast< RecovDocList* >(&aDevice);
920 Wallpaper aBackground = aDevice.GetBackground();
921 Color aColor = aBackground.GetColor();
922 BOOL bHC = aColor.IsDark();
924 TURLInfo* pInfo = (TURLInfo*)pEntry->GetUserData();
925 switch(pInfo->RecoveryState)
927 case E_SUCCESSFULLY_RECOVERED :
929 pImg = &pList->m_aGreenCheckImg;
930 if (bHC)
931 pImg = &pList->m_aGreenCheckImgHC;
932 pTxt = &pList->m_aSuccessRecovStr;
934 break;
936 case E_ORIGINAL_DOCUMENT_RECOVERED : // TODO must be renamed into ORIGINAL DOCUMENT recovered! Because its marked as yellow
938 pImg = &pList->m_aYellowCheckImg;
939 if (bHC)
940 pImg = &pList->m_aYellowCheckImgHC;
941 pTxt = &pList->m_aOrigDocRecovStr;
943 break;
945 case E_RECOVERY_FAILED :
947 pImg = &pList->m_aRedCrossImg;
948 if (bHC)
949 pImg = &pList->m_aRedCrossImgHC;
950 pTxt = &pList->m_aRecovFailedStr;
952 break;
954 case E_RECOVERY_IS_IN_PROGRESS :
956 pImg = 0;
957 pTxt = &pList->m_aRecovInProgrStr;
959 break;
961 case E_NOT_RECOVERED_YET :
963 pImg = 0;
964 pTxt = &pList->m_aNotRecovYetStr;
966 break;
969 if (pImg)
970 aDevice.DrawImage(aPos, *pImg);
972 if (pTxt)
974 ::rtl::OUString sT1(*pTxt);
976 Point aPnt(aPos);
977 aPnt.X() += pList->m_aGreenCheckImg.GetSizePixel().Width();
978 aPnt.X() += 10;
979 aDevice.DrawText(aPnt, *pTxt);
982 //===============================================
983 RecovDocList::RecovDocList( Window* pParent,
984 const ResId& rResId )
985 : SvxSimpleTable ( pParent, rResId )
986 , m_aGreenCheckImg ( ResId(IMG_GREENCHECK,*rResId.GetResMgr() ) )
987 , m_aYellowCheckImg ( ResId(IMG_YELLOWCHECK,*rResId.GetResMgr() ) )
988 , m_aRedCrossImg ( ResId(IMG_REDCROSS,*rResId.GetResMgr() ) )
989 , m_aGreenCheckImgHC ( ResId(IMG_GREENCHECK_HC,*rResId.GetResMgr() ) )
990 , m_aYellowCheckImgHC ( ResId(IMG_YELLOWCHECK_HC,*rResId.GetResMgr() ) )
991 , m_aRedCrossImgHC ( ResId(IMG_REDCROSS_HC,*rResId.GetResMgr() ) )
992 , m_aSuccessRecovStr ( ResId(STR_SUCCESSRECOV,*rResId.GetResMgr() ) )
993 , m_aOrigDocRecovStr ( ResId(STR_ORIGDOCRECOV,*rResId.GetResMgr() ) )
994 , m_aRecovFailedStr ( ResId(STR_RECOVFAILED,*rResId.GetResMgr() ) )
995 , m_aRecovInProgrStr ( ResId(STR_RECOVINPROGR,*rResId.GetResMgr() ) )
996 , m_aNotRecovYetStr ( ResId(STR_NOTRECOVYET,*rResId.GetResMgr() ) )
998 //SetEntryHeight( short( maGreenCheckImg.GetSizePixel().Height() ) );
1001 //===============================================
1002 RecovDocList::~RecovDocList()
1006 //===============================================
1007 void RecovDocList::InitEntry( SvLBoxEntry* pEntry ,
1008 const XubString& sText ,
1009 const Image& aImage1,
1010 const Image& aImage2,
1011 SvLBoxButtonKind eButtonKind)
1013 SvTabListBox::InitEntry(pEntry, sText, aImage1, aImage2, eButtonKind);
1014 DBG_ASSERT( TabCount() == 2, "*RecovDocList::InitEntry(): structure missmatch" );
1016 SvLBoxString* pCol = (SvLBoxString*)pEntry->GetItem(2);
1017 RecovDocListEntry* p = new RecovDocListEntry(pEntry, 0, pCol->GetText());
1018 pEntry->ReplaceItem(p, 2);
1021 //===============================================
1022 short impl_askUserForWizardCancel(Window* pParent, sal_Int16 nRes)
1024 QueryBox aQuery(pParent, SVX_RES(nRes));
1025 if (aQuery.Execute() == RET_YES)
1026 return DLG_RET_OK;
1027 else
1028 return DLG_RET_CANCEL;
1031 //===============================================
1032 RecoveryDialog::RecoveryDialog(Window* pParent,
1033 RecoveryCore* pCore )
1034 : IExtendedTabPage( pParent , SVX_RES( RID_SVXPAGE_DOCRECOVERY_RECOVER ) )
1035 , m_aTitleWin ( this , SVX_RES ( WIN_RECOV_TITLE ) )
1036 , m_aTitleFT ( this , SVX_RES ( FT_RECOV_TITLE ) )
1037 , m_aTitleFL ( this , SVX_RES ( FL_RECOV_TITLE ) )
1038 , m_aDescrFT ( this , SVX_RES ( FT_RECOV_DESCR ) )
1039 , m_aProgressFT ( this , SVX_RES ( FT_RECOV_PROGR ) )
1040 , m_aProgrParent ( this , SVX_RES ( WIN_RECOV_PROGR ) )
1041 , m_aFileListFT ( this , SVX_RES ( FT_RECOV_FILELIST ) )
1042 , m_aFileListLB ( this , SVX_RES ( LB_RECOV_FILELIST ) )
1043 , m_aBottomFL ( this , SVX_RES ( FL_RECOV_BOTTOM ) )
1044 , m_aNextBtn ( this , SVX_RES ( BTN_RECOV_NEXT ) )
1045 , m_aCancelBtn ( this , SVX_RES ( BTN_RECOV_CANCEL ) )
1046 , m_aNextStr ( SVX_RES ( STR_RECOVERY_NEXT ) )
1047 , m_aTitleRecoveryInProgress( SVX_RES ( STR_RECOVERY_INPROGRESS ) )
1048 , m_aTitleRecoveryReport( SVX_RES ( STR_RECOVERY_REPORT ) )
1049 , m_aRecoveryOnlyFinish ( SVX_RES ( STR_RECOVERYONLY_FINISH ) )
1050 , m_aRecoveryOnlyFinishDescr( SVX_RES ( STR_RECOVERYONLY_FINISH_DESCR ) )
1051 , m_pDefButton ( NULL )
1052 , m_pCore ( pCore )
1053 , m_eRecoveryState (RecoveryDialog::E_RECOVERY_PREPARED)
1054 , m_bWaitForUser (sal_False)
1055 , m_bWaitForCore (sal_False)
1056 , m_bUserDecideNext (sal_False)
1057 , m_bWasRecoveryStarted (sal_False)
1058 , m_bRecoveryOnly (sal_False)
1060 static long nTabs[] = { 2, 0, 40*RECOV_CONTROLWIDTH/100 };
1061 m_aFileListLB.SetTabs( &nTabs[0] );
1062 m_aFileListLB.InsertHeaderEntry( String( SVX_RES( STR_HEADERBAR ) ) );
1064 FreeResource();
1066 ::rtl::OUString CFG_PACKAGE_RECOVERY( RTL_CONSTASCII_USTRINGPARAM ( "org.openoffice.Office.Recovery/" ));
1067 ::rtl::OUString CFG_PATH_CRASHREPORTER( RTL_CONSTASCII_USTRINGPARAM( "CrashReporter" ));
1068 ::rtl::OUString CFG_ENTRY_ENABLED( RTL_CONSTASCII_USTRINGPARAM ( "Enabled" ));
1070 sal_Bool bCrashRepEnabled( sal_True );
1071 css::uno::Any aVal = ::comphelper::ConfigurationHelper::readDirectKey(
1072 pCore->getSMGR(),
1073 CFG_PACKAGE_RECOVERY,
1074 CFG_PATH_CRASHREPORTER,
1075 CFG_ENTRY_ENABLED,
1076 ::comphelper::ConfigurationHelper::E_READONLY);
1077 aVal >>= bCrashRepEnabled;
1078 m_bRecoveryOnly = !bCrashRepEnabled;
1080 PluginProgress* pProgress = new PluginProgress( &m_aProgrParent, pCore->getSMGR() );
1081 m_xProgress = css::uno::Reference< css::task::XStatusIndicator >(static_cast< css::task::XStatusIndicator* >(pProgress), css::uno::UNO_QUERY_THROW);
1083 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1084 Wallpaper aBackground( rStyleSettings.GetWindowColor() );
1085 m_aTitleWin.SetBackground(aBackground);
1086 m_aTitleFT.SetBackground (aBackground);
1088 Font aFont(m_aTitleFT.GetFont());
1089 aFont.SetWeight(WEIGHT_BOLD);
1090 m_aTitleFT.SetFont(aFont);
1092 m_aFileListLB.SetBackground( rStyleSettings.GetDialogColor() );
1094 m_aNextBtn.Enable(TRUE);
1095 m_aNextBtn.SetClickHdl( LINK( this, RecoveryDialog, NextButtonHdl ) );
1096 m_aCancelBtn.SetClickHdl( LINK( this, RecoveryDialog, CancelButtonHdl ) );
1098 // fill list box first time
1099 TURLList* pURLList = m_pCore->getURLListAccess();
1100 TURLList::const_iterator pIt;
1101 for ( pIt = pURLList->begin();
1102 pIt != pURLList->end() ;
1103 ++pIt )
1105 const TURLInfo& rInfo = *pIt;
1107 String sName( rInfo.DisplayName );
1108 sName += '\t';
1109 sName += impl_getStatusString( rInfo );
1110 SvLBoxEntry* pEntry = m_aFileListLB.InsertEntry(sName, rInfo.StandardImage, rInfo.StandardImage);
1111 pEntry->SetUserData((void*)&rInfo);
1112 m_aFileListLB.SetExpandedEntryBmp (pEntry, rInfo.HCImage, BMP_COLOR_HIGHCONTRAST);
1113 m_aFileListLB.SetCollapsedEntryBmp(pEntry, rInfo.HCImage, BMP_COLOR_HIGHCONTRAST);
1116 // mark first item
1117 SvLBoxEntry* pFirst = m_aFileListLB.First();
1118 if (pFirst)
1119 m_aFileListLB.SetCursor(pFirst, sal_True);
1122 //===============================================
1123 RecoveryDialog::~RecoveryDialog()
1127 //===============================================
1128 short RecoveryDialog::execute()
1130 ::vos::OGuard aSolarLock(Application::GetSolarMutex());
1132 switch(m_eRecoveryState)
1134 case RecoveryDialog::E_RECOVERY_PREPARED :
1136 // Dialog was started first time ...
1137 // wait for user decision ("start" or "cancel" recovery)
1138 // This decision will be made inside the NextBtn handler.
1139 m_aNextBtn.Enable(TRUE);
1140 m_aCancelBtn.Enable(TRUE);
1141 m_bWaitForUser = sal_True;
1142 while(m_bWaitForUser)
1143 Application::Yield();
1144 if (m_bUserDecideNext)
1145 m_eRecoveryState = RecoveryDialog::E_RECOVERY_IN_PROGRESS;
1146 else
1147 m_eRecoveryState = RecoveryDialog::E_RECOVERY_CANCELED;
1148 return execute();
1151 case RecoveryDialog::E_RECOVERY_IN_PROGRESS :
1153 // user decided to start recovery ...
1154 m_bWasRecoveryStarted = sal_True;
1155 // do it asynchronous (to allow repaints)
1156 // and wait for this asynchronous operation.
1157 m_aDescrFT.SetText( m_aTitleRecoveryInProgress );
1158 m_aNextBtn.Enable(FALSE);
1159 m_aCancelBtn.Enable(FALSE);
1160 m_pCore->setProgressHandler(m_xProgress);
1161 m_pCore->setUpdateListener(this);
1162 m_pCore->doRecovery();
1164 m_bWaitForCore = sal_True;
1165 while(m_bWaitForCore)
1166 Application::Yield();
1168 m_pCore->setUpdateListener(0);
1169 m_eRecoveryState = RecoveryDialog::E_RECOVERY_CORE_DONE;
1170 return execute();
1173 case RecoveryDialog::E_RECOVERY_CORE_DONE :
1175 // the core finished it's task.
1176 // let the user decide the next step.
1177 if ( m_bRecoveryOnly )
1179 m_aDescrFT.SetText(m_aRecoveryOnlyFinishDescr);
1180 m_aNextBtn.SetText(m_aRecoveryOnlyFinish);
1181 m_aNextBtn.Enable(TRUE);
1182 m_aCancelBtn.Enable(FALSE);
1184 else
1186 m_aDescrFT.SetText(m_aTitleRecoveryReport);
1187 m_aNextBtn.SetText(m_aNextStr);
1188 m_aNextBtn.Enable(TRUE);
1189 m_aCancelBtn.Enable(TRUE);
1192 m_bWaitForUser = sal_True;
1193 while(m_bWaitForUser)
1194 Application::Yield();
1196 if (m_bUserDecideNext)
1197 m_eRecoveryState = RecoveryDialog::E_RECOVERY_DONE;
1198 else
1199 m_eRecoveryState = RecoveryDialog::E_RECOVERY_CANCELED;
1200 return execute();
1203 case RecoveryDialog::E_RECOVERY_DONE :
1205 // All documents was reovered.
1206 // User decided to step to the "next" wizard page.
1207 // Do it ... but check first, if there exist some
1208 // failed recovery documents. They must be saved to
1209 // a user selected directrory.
1210 short nRet = DLG_RET_UNKNOWN;
1211 BrokenRecoveryDialog* pBrokenRecoveryDialog = new BrokenRecoveryDialog(this, m_pCore, !m_bWasRecoveryStarted);
1212 String sSaveDir = pBrokenRecoveryDialog->getSaveDirURL(); // get the default dir
1213 if (pBrokenRecoveryDialog->isExecutionNeeded())
1215 nRet = pBrokenRecoveryDialog->Execute();
1216 sSaveDir = pBrokenRecoveryDialog->getSaveDirURL();
1218 delete pBrokenRecoveryDialog;
1220 switch(nRet)
1222 // no broken temp files exists
1223 // step to the next wizard page
1224 case DLG_RET_UNKNOWN :
1226 m_eRecoveryState = RecoveryDialog::E_RECOVERY_HANDLED;
1227 return DLG_RET_OK;
1230 // user decided to save the broken temp files
1231 // do and forget it
1232 // step to the next wizard page
1233 case DLG_RET_OK :
1235 m_pCore->saveBrokenTempEntries(sSaveDir);
1236 m_pCore->forgetBrokenTempEntries();
1237 m_eRecoveryState = RecoveryDialog::E_RECOVERY_HANDLED;
1238 return DLG_RET_OK;
1241 // user decided to ignore broken temp files.
1242 // Ask it again ... may be this decision was wrong.
1243 // Results:
1244 // IGNORE => remove broken temp files
1245 // => step to the next wizard page
1246 // CANCEL => step back to the recovery page
1247 case DLG_RET_CANCEL :
1249 // TODO ask user ...
1250 m_pCore->forgetBrokenTempEntries();
1251 m_eRecoveryState = RecoveryDialog::E_RECOVERY_HANDLED;
1252 return DLG_RET_OK;
1256 m_eRecoveryState = RecoveryDialog::E_RECOVERY_HANDLED;
1257 return DLG_RET_OK;
1260 case RecoveryDialog::E_RECOVERY_CANCELED :
1262 // "YES" => break recovery
1263 // But there exist different states, where "cancel" can be called.
1264 // Handle it different.
1265 if (m_bWasRecoveryStarted)
1266 m_eRecoveryState = RecoveryDialog::E_RECOVERY_CANCELED_AFTERWARDS;
1267 else
1268 m_eRecoveryState = RecoveryDialog::E_RECOVERY_CANCELED_BEFORE;
1269 return execute();
1272 case RecoveryDialog::E_RECOVERY_CANCELED_BEFORE :
1273 case RecoveryDialog::E_RECOVERY_CANCELED_AFTERWARDS :
1275 // We have to check if there exists some temp. files.
1276 // They should be saved to a user defined location.
1277 // If no temp files exists or user decided to ignore it ...
1278 // we have to remove all recovery/session data anyway!
1279 short nRet = DLG_RET_UNKNOWN;
1280 BrokenRecoveryDialog* pBrokenRecoveryDialog = new BrokenRecoveryDialog(this, m_pCore, !m_bWasRecoveryStarted);
1281 String sSaveDir = pBrokenRecoveryDialog->getSaveDirURL(); // get the default save location
1283 // dialog itself checks if there is a need to copy files for this mode.
1284 // It uses the information m_bWasRecoveryStarted doing so.
1285 if (pBrokenRecoveryDialog->isExecutionNeeded())
1287 nRet = pBrokenRecoveryDialog->Execute();
1288 sSaveDir = pBrokenRecoveryDialog->getSaveDirURL();
1290 delete pBrokenRecoveryDialog;
1292 // Possible states:
1293 // a) nRet == DLG_RET_UNKNOWN
1294 // dialog was not shown ...
1295 // because there exists no temp file for copy.
1296 // => remove all recovery data
1297 // b) nRet == DLG_RET_OK
1298 // dialog was shown ...
1299 // user decided to save temp files
1300 // => save all OR broken temp files (depends from the time, where cancel was called)
1301 // => remove all recovery data
1302 // c) nRet == DLG_RET_CANCEL
1303 // dialog was shown ...
1304 // user decided to ignore temp files
1305 // => remove all recovery data
1306 // => a)/c) are the same ... b) has one additional operation
1308 // b)
1309 if (nRet == DLG_RET_OK)
1311 if (m_bWasRecoveryStarted)
1312 m_pCore->saveBrokenTempEntries(sSaveDir);
1313 else
1314 m_pCore->saveAllTempEntries(sSaveDir);
1317 // a,b,c)
1318 if (m_bWasRecoveryStarted)
1319 m_pCore->forgetBrokenRecoveryEntries();
1320 else
1321 m_pCore->forgetAllRecoveryEntries();
1322 m_eRecoveryState = RecoveryDialog::E_RECOVERY_HANDLED;
1324 // THERE IS NO WAY BACK. see impl_askUserForWizardCancel()!
1325 return DLG_RET_CANCEL;
1328 case RecoveryDialog::E_RECOVERY_HANDLED :
1330 m_bWaitForUser = sal_True;
1331 while(m_bWaitForUser)
1332 Application::Yield();
1334 // TODO: show BrokenRecoveryDialog again, ift he user
1335 // doesnt accepted it last time.
1337 if (m_bUserDecideNext)
1338 return DLG_RET_OK;
1339 else
1340 return DLG_RET_CANCEL;
1344 // should never be reached .-)
1345 DBG_ERROR("Should never be reached!");
1346 return DLG_RET_OK;
1349 //===============================================
1350 void RecoveryDialog::setDefButton()
1352 if ( m_aNextBtn.IsEnabled() )
1353 m_aNextBtn.GrabFocus();
1354 else
1355 m_pDefButton = &m_aNextBtn;
1358 //===============================================
1359 void RecoveryDialog::start()
1363 //===============================================
1364 void RecoveryDialog::updateItems()
1366 ULONG c = m_aFileListLB.GetEntryCount();
1367 ULONG i = 0;
1368 for ( i=0; i<c; ++i )
1370 SvLBoxEntry* pEntry = m_aFileListLB.GetEntry(i);
1371 if ( !pEntry )
1372 continue;
1374 TURLInfo* pInfo = (TURLInfo*)pEntry->GetUserData();
1375 if ( !pInfo )
1376 continue;
1378 String sStatus = impl_getStatusString( *pInfo );
1379 if ( sStatus.Len() > 0 )
1380 m_aFileListLB.SetEntryText( sStatus, pEntry, 1 );
1383 m_aFileListLB.Invalidate();
1384 m_aFileListLB.Update();
1387 //===============================================
1388 void RecoveryDialog::stepNext(TURLInfo* pItem)
1390 ULONG c = m_aFileListLB.GetEntryCount();
1391 ULONG i = 0;
1392 for (i=0; i<c; ++i)
1394 SvLBoxEntry* pEntry = m_aFileListLB.GetEntry(i);
1395 if (!pEntry)
1396 continue;
1398 TURLInfo* pInfo = (TURLInfo*)pEntry->GetUserData();
1399 if (pInfo->ID != pItem->ID)
1400 continue;
1402 m_aFileListLB.SetCursor(pEntry, sal_True);
1403 m_aFileListLB.MakeVisible(pEntry);
1404 m_aFileListLB.Invalidate();
1405 m_aFileListLB.Update();
1406 break;
1410 //===============================================
1411 void RecoveryDialog::end()
1413 if ( m_pDefButton )
1415 m_pDefButton->GrabFocus();
1416 m_pDefButton = NULL;
1418 m_bWaitForCore = sal_False;
1421 //===============================================
1422 IMPL_LINK( RecoveryDialog, NextButtonHdl, void*, EMPTYARG )
1424 m_bUserDecideNext = sal_True;
1425 m_bWaitForUser = sal_False;
1426 return 0;
1429 //===============================================
1430 IMPL_LINK( RecoveryDialog, CancelButtonHdl, void*, EMPTYARG )
1432 if (m_eRecoveryState == RecoveryDialog::E_RECOVERY_PREPARED)
1434 if (impl_askUserForWizardCancel(this, RID_SVXQB_EXIT_RECOVERY) == DLG_RET_CANCEL)
1435 return 0;
1437 m_bUserDecideNext = sal_False;
1438 m_bWaitForUser = sal_False;
1439 return 0;
1442 //===============================================
1443 void RecoveryDialog::impl_refreshDocList()
1447 //===============================================
1448 String RecoveryDialog::impl_getStatusString( const TURLInfo& rInfo ) const
1450 String sStatus;
1451 switch ( rInfo.RecoveryState )
1453 case E_SUCCESSFULLY_RECOVERED :
1454 sStatus = m_aFileListLB.m_aSuccessRecovStr;
1455 break;
1456 case E_ORIGINAL_DOCUMENT_RECOVERED :
1457 sStatus = m_aFileListLB.m_aOrigDocRecovStr;
1458 break;
1459 case E_RECOVERY_FAILED :
1460 sStatus = m_aFileListLB.m_aRecovFailedStr;
1461 break;
1462 case E_RECOVERY_IS_IN_PROGRESS :
1463 sStatus = m_aFileListLB.m_aRecovInProgrStr;
1464 break;
1465 case E_NOT_RECOVERED_YET :
1466 sStatus = m_aFileListLB.m_aNotRecovYetStr;
1467 break;
1468 default:
1469 break;
1471 return sStatus;
1474 //===============================================
1475 BrokenRecoveryDialog::BrokenRecoveryDialog(Window* pParent ,
1476 RecoveryCore* pCore ,
1477 sal_Bool bBeforeRecovery)
1478 : ModalDialog ( pParent, SVX_RES( RID_SVX_MDLG_DOCRECOVERY_BROKEN ) )
1479 , m_aDescrFT ( this , SVX_RES( FT_BROKEN_DESCR ) )
1480 , m_aFileListFT ( this , SVX_RES( FT_BROKEN_FILELIST ) )
1481 , m_aFileListLB ( this , SVX_RES( LB_BROKEN_FILELIST ) )
1482 , m_aSaveDirFT ( this , SVX_RES( FT_BROKEN_SAVEDIR ) )
1483 , m_aSaveDirED ( this , SVX_RES( ED_BROKEN_SAVEDIR ) )
1484 , m_aSaveDirBtn ( this , SVX_RES( BTN_BROKEN_SAVEDIR ) )
1485 , m_aBottomFL ( this , SVX_RES( FL_BROKEN_BOTTOM ) )
1486 , m_aOkBtn ( this , SVX_RES( BTN_BROKEN_OK ) )
1487 , m_aCancelBtn ( this , SVX_RES( BTN_BROKEN_CANCEL ) )
1488 , m_pCore ( pCore )
1489 , m_bBeforeRecovery (bBeforeRecovery)
1490 , m_bExecutionNeeded(sal_False)
1492 FreeResource();
1494 m_aSaveDirBtn.SetClickHdl( LINK( this, BrokenRecoveryDialog, SaveButtonHdl ) );
1495 m_aOkBtn.SetClickHdl( LINK( this, BrokenRecoveryDialog, OkButtonHdl ) );
1496 m_aCancelBtn.SetClickHdl( LINK( this, BrokenRecoveryDialog, CancelButtonHdl ) );
1498 m_sSavePath = SvtPathOptions().GetWorkPath();
1499 INetURLObject aObj( m_sSavePath );
1500 String sPath;
1501 ::utl::LocalFileHelper::ConvertURLToSystemPath( aObj.GetMainURL( INetURLObject::NO_DECODE ), sPath );
1502 m_aSaveDirED.SetText( sPath );
1504 impl_refresh();
1507 //===============================================
1508 BrokenRecoveryDialog::~BrokenRecoveryDialog()
1512 //===============================================
1513 void BrokenRecoveryDialog::impl_refresh()
1515 m_bExecutionNeeded = sal_False;
1516 TURLList* pURLList = m_pCore->getURLListAccess();
1517 TURLList::const_iterator pIt;
1518 for ( pIt = pURLList->begin();
1519 pIt != pURLList->end() ;
1520 ++pIt )
1522 const TURLInfo& rInfo = *pIt;
1524 if (m_bBeforeRecovery)
1526 // "Cancel" before recovery ->
1527 // search for any temp files!
1528 if (!rInfo.TempURL.getLength())
1529 continue;
1531 else
1533 // "Cancel" after recovery ->
1534 // search for broken temp files
1535 if (!RecoveryCore::isBrokenTempEntry(rInfo))
1536 continue;
1539 m_bExecutionNeeded = sal_True;
1541 USHORT nPos = m_aFileListLB.InsertEntry(rInfo.DisplayName, rInfo.StandardImage );
1542 m_aFileListLB.SetEntryData( nPos, (void*)&rInfo );
1544 m_sSavePath = ::rtl::OUString();
1545 m_aOkBtn.GrabFocus();
1548 //===============================================
1549 sal_Bool BrokenRecoveryDialog::isExecutionNeeded()
1551 return m_bExecutionNeeded;
1554 //===============================================
1555 ::rtl::OUString BrokenRecoveryDialog::getSaveDirURL()
1557 return m_sSavePath;
1560 //===============================================
1561 IMPL_LINK( BrokenRecoveryDialog, OkButtonHdl, void*, EMPTYARG )
1563 String sPhysicalPath = m_aSaveDirED.GetText().EraseLeadingChars().EraseTrailingChars();
1564 String sURL;
1565 ::utl::LocalFileHelper::ConvertPhysicalNameToURL( sPhysicalPath, sURL );
1566 m_sSavePath = sURL;
1567 while (!m_sSavePath.getLength())
1568 impl_askForSavePath();
1570 EndDialog(DLG_RET_OK);
1571 return 0;
1574 //===============================================
1575 IMPL_LINK( BrokenRecoveryDialog, CancelButtonHdl, void*, EMPTYARG )
1577 EndDialog(DLG_RET_CANCEL);
1578 return 0;
1581 //===============================================
1582 IMPL_LINK( BrokenRecoveryDialog, SaveButtonHdl, void*, EMPTYARG )
1584 impl_askForSavePath();
1585 return 0;
1588 //===============================================
1589 void BrokenRecoveryDialog::impl_askForSavePath()
1591 css::uno::Reference< css::ui::dialogs::XFolderPicker > xFolderPicker(
1592 m_pCore->getSMGR()->createInstance(SERVICENAME_FOLDERPICKER), css::uno::UNO_QUERY_THROW);
1593 // svt::SetDialogHelpId( xFolderPicker, HID_OPTIONS_PATHS_SELECTFOLDER );
1595 INetURLObject aURL(m_sSavePath, INET_PROT_FILE);
1596 xFolderPicker->setDisplayDirectory(aURL.GetMainURL(INetURLObject::NO_DECODE));
1597 short nRet = xFolderPicker->execute();
1598 if (nRet == css::ui::dialogs::ExecutableDialogResults::OK)
1600 m_sSavePath = xFolderPicker->getDirectory();
1601 String sPath;
1602 ::utl::LocalFileHelper::ConvertURLToSystemPath( m_sSavePath, sPath );
1603 m_aSaveDirED.SetText( sPath );
1607 //===============================================
1608 ///////////////////////////////////////////////////////////////////////
1609 // Error Report Welcome Dialog
1610 ///////////////////////////////////////////////////////////////////////
1612 ErrorRepWelcomeDialog::ErrorRepWelcomeDialog( Window* _pParent, sal_Bool _bAllowBack )
1613 :IExtendedTabPage ( _pParent, SVX_RES( RID_SVXPAGE_ERR_REP_WELCOME ) )
1614 ,maTitleWin ( this, SVX_RES( WIN_RECOV_TITLE ) )
1615 ,maTitleFT ( this, SVX_RES( FT_RECOV_TITLE ) )
1616 ,maTitleFL ( this, SVX_RES( FL_RECOV_TITLE ) )
1617 ,maDescrFT ( this, SVX_RES( FT_RECOV_DESCR ) )
1618 ,maBottomFL ( this, SVX_RES( FL_RECOV_BOTTOM ) )
1619 ,maPrevBtn ( this, SVX_RES( BTN_RECOV_PREV ) )
1620 ,maNextBtn ( this, SVX_RES( BTN_RECOV_NEXT ) )
1621 ,maCancelBtn ( this, SVX_RES( BTN_RECOV_CANCEL ) )
1623 FreeResource();
1625 Wallpaper aBack( GetSettings().GetStyleSettings().GetWindowColor() );
1626 maTitleWin.SetBackground( aBack );
1627 maTitleFT.SetBackground( aBack );
1629 Font aFnt( maTitleFT.GetFont() );
1630 aFnt.SetWeight( WEIGHT_BOLD );
1631 maTitleFT.SetFont( aFnt );
1633 maPrevBtn.SetClickHdl( LINK( this, ErrorRepWelcomeDialog, PrevBtnHdl ) );
1634 maPrevBtn.Enable( _bAllowBack );
1636 maNextBtn.SetClickHdl( LINK( this, ErrorRepWelcomeDialog, NextBtnHdl ) );
1637 maNextBtn.Enable( sal_True );
1639 maCancelBtn.SetClickHdl( LINK( this, ErrorRepWelcomeDialog, CancelBtnHdl ) );
1640 maCancelBtn.Enable( sal_True );
1643 ErrorRepWelcomeDialog::~ErrorRepWelcomeDialog()
1647 IMPL_LINK( ErrorRepWelcomeDialog, PrevBtnHdl, void*, EMPTYARG )
1649 m_nResult = DLG_RET_BACK;
1650 return 0;
1653 IMPL_LINK( ErrorRepWelcomeDialog, NextBtnHdl, void*, EMPTYARG )
1655 m_nResult = DLG_RET_OK;
1656 return 0;
1659 IMPL_LINK( ErrorRepWelcomeDialog, CancelBtnHdl, void*, EMPTYARG )
1661 m_nResult = DLG_RET_CANCEL;
1662 return 0;
1665 short ErrorRepWelcomeDialog::execute()
1667 ::vos::OGuard aLock(Application::GetSolarMutex());
1668 Show();
1669 m_nResult = DLG_RET_UNKNOWN;
1670 while(m_nResult == DLG_RET_UNKNOWN)
1671 Application::Yield();
1672 return m_nResult;
1675 void ErrorRepWelcomeDialog::setDefButton()
1677 maNextBtn.GrabFocus();
1680 ///////////////////////////////////////////////////////////////////////
1681 // Error Report Send Dialog and its MultiLineEdit
1682 ///////////////////////////////////////////////////////////////////////
1684 ErrorDescriptionEdit::ErrorDescriptionEdit( Window* pParent, const ResId& rResId ) :
1686 MultiLineEdit( pParent, rResId )
1689 SetModifyHdl( LINK( this, ErrorDescriptionEdit, ModifyHdl ) );
1690 if ( GetVScrollBar() )
1691 GetVScrollBar()->Hide();
1694 ErrorDescriptionEdit::~ErrorDescriptionEdit()
1698 IMPL_LINK( ErrorDescriptionEdit, ModifyHdl, void*, EMPTYARG )
1700 if ( !GetVScrollBar() )
1701 return 0;
1703 ExtTextEngine* pTextEngine = GetTextEngine();
1704 DBG_ASSERT( pTextEngine, "no text engine" );
1706 ULONG i, nParaCount = pTextEngine->GetParagraphCount();
1707 USHORT nLineCount = 0;
1709 for ( i = 0; i < nParaCount; ++i )
1710 nLineCount = nLineCount + pTextEngine->GetLineCount(i);
1712 USHORT nVisCols = 0, nVisLines = 0;
1713 GetMaxVisColumnsAndLines( nVisCols, nVisLines );
1714 GetVScrollBar()->Show( nLineCount > nVisLines );
1716 return 0;
1719 ErrorRepSendDialog::ErrorRepSendDialog( Window* _pParent )
1720 :IExtendedTabPage ( _pParent, SVX_RES( RID_SVXPAGE_ERR_REP_SEND ) )
1721 ,maTitleWin ( this, SVX_RES( WIN_RECOV_TITLE ) )
1722 ,maTitleFT ( this, SVX_RES( FT_RECOV_TITLE ) )
1723 ,maTitleFL ( this, SVX_RES( FL_RECOV_TITLE ) )
1724 ,maDescrFT ( this, SVX_RES( FT_RECOV_DESCR ) )
1726 ,maDocTypeFT ( this, SVX_RES( FT_ERRSEND_DOCTYPE ) )
1727 ,maDocTypeED ( this, SVX_RES( ED_ERRSEND_DOCTYPE ) )
1728 ,maUsingFT ( this, SVX_RES( FT_ERRSEND_USING ) )
1729 ,maUsingML ( this, SVX_RES( ML_ERRSEND_USING ) )
1730 ,maShowRepBtn ( this, SVX_RES( BTN_ERRSEND_SHOWREP ) )
1731 ,maOptBtn ( this, SVX_RES( BTN_ERRSEND_OPT ) )
1732 ,maContactCB ( this, SVX_RES( CB_ERRSEND_CONTACT ) )
1733 ,maEMailAddrFT ( this, SVX_RES( FT_ERRSEND_EMAILADDR ) )
1734 ,maEMailAddrED ( this, SVX_RES( ED_ERRSEND_EMAILADDR ) )
1736 ,maBottomFL ( this, SVX_RES( FL_RECOV_BOTTOM ) )
1737 ,maPrevBtn ( this, SVX_RES( BTN_RECOV_PREV ) )
1738 ,maNextBtn ( this, SVX_RES( BTN_RECOV_NEXT ) )
1739 ,maCancelBtn ( this, SVX_RES( BTN_RECOV_CANCEL ) )
1741 FreeResource();
1743 initControls();
1745 Wallpaper aBack( GetSettings().GetStyleSettings().GetWindowColor() );
1746 maTitleWin.SetBackground( aBack );
1747 maTitleFT.SetBackground( aBack );
1749 Font aFnt( maTitleFT.GetFont() );
1750 aFnt.SetWeight( WEIGHT_BOLD );
1751 maTitleFT.SetFont( aFnt );
1753 maShowRepBtn.SetClickHdl( LINK( this, ErrorRepSendDialog, ShowRepBtnHdl ) );
1754 maOptBtn.SetClickHdl( LINK( this, ErrorRepSendDialog, OptBtnHdl ) );
1755 maContactCB.SetClickHdl( LINK( this, ErrorRepSendDialog, ContactCBHdl ) );
1756 maPrevBtn.SetClickHdl( LINK( this, ErrorRepSendDialog, PrevBtnHdl ) );
1757 maNextBtn.SetClickHdl( LINK( this, ErrorRepSendDialog, SendBtnHdl ) );
1758 maCancelBtn.SetClickHdl( LINK( this, ErrorRepSendDialog, CancelBtnHdl ) );
1760 ReadParams();
1763 maDocTypeED.SetText( maParams.maSubject );
1764 maUsingML.SetText( maParams.maBody );
1765 maContactCB.Check( maParams.mbAllowContact );
1766 maEMailAddrED.SetText( maParams.maReturnAddress );
1768 ContactCBHdl( 0 );
1771 ErrorRepSendDialog::~ErrorRepSendDialog()
1775 short ErrorRepSendDialog::execute()
1777 ::vos::OGuard aLock(Application::GetSolarMutex());
1778 Show();
1779 m_nResult = DLG_RET_UNKNOWN;
1780 while(m_nResult == DLG_RET_UNKNOWN)
1781 Application::Yield();
1782 return m_nResult;
1785 void ErrorRepSendDialog::setDefButton()
1787 // set first focus
1788 maDocTypeED.GrabFocus();
1791 IMPL_LINK( ErrorRepSendDialog, PrevBtnHdl, void*, EMPTYARG )
1793 m_nResult = DLG_RET_BACK;
1794 return 0;
1797 IMPL_LINK( ErrorRepSendDialog, CancelBtnHdl, void*, EMPTYARG )
1799 m_nResult = DLG_RET_CANCEL;
1800 return 0;
1803 IMPL_LINK( ErrorRepSendDialog, SendBtnHdl, void*, EMPTYARG )
1806 SaveParams();
1807 SendReport();
1809 m_nResult = DLG_RET_OK;
1810 return 0;
1813 IMPL_LINK( ErrorRepSendDialog, ShowRepBtnHdl, void*, EMPTYARG )
1815 ErrorRepPreviewDialog aDlg( this );
1816 aDlg.Execute();
1817 return 0;
1820 IMPL_LINK( ErrorRepSendDialog, OptBtnHdl, void*, EMPTYARG )
1822 ErrorRepOptionsDialog aDlg( this, maParams );
1823 aDlg.Execute();
1824 return 0;
1827 IMPL_LINK( ErrorRepSendDialog, ContactCBHdl, void*, EMPTYARG )
1829 bool bCheck = maContactCB.IsChecked();
1830 maEMailAddrFT.Enable( bCheck );
1831 maEMailAddrED.Enable( bCheck );
1832 return 0;
1835 void ErrorRepSendDialog::initControls()
1837 // if the text is too short for two lines, insert a newline
1838 String sText = maDocTypeFT.GetText();
1839 if ( maDocTypeFT.GetCtrlTextWidth( sText ) <= maDocTypeFT.GetSizePixel().Width() )
1841 sText.Insert( '\n', 0 );
1842 maDocTypeFT.SetText( sText );
1845 // if the button text is too wide, then broaden the button
1846 sText = maShowRepBtn.GetText();
1847 long nTxtW = maShowRepBtn.GetCtrlTextWidth( sText );
1848 long nBtnW = maShowRepBtn.GetSizePixel().Width();
1849 if ( nTxtW >= nBtnW )
1851 const long nMinDelta = 10;
1852 long nDelta = Max( nTxtW - nBtnW, nMinDelta );
1853 sal_uInt32 i = 0;
1854 Window* pWins[] =
1856 &maShowRepBtn, &maOptBtn,
1857 &maDescrFT, &maDocTypeFT, &maDocTypeED, &maUsingFT,
1858 &maUsingML, &maContactCB, &maEMailAddrFT, &maEMailAddrED
1860 // the first two buttons need a new size (wider) and position (more left)
1861 Window** pCurrent = pWins;
1862 const sal_uInt32 nBtnCount = 2;
1863 for ( ; i < nBtnCount; ++i, ++pCurrent )
1865 Size aNewSize = (*pCurrent)->GetSizePixel();
1866 aNewSize.Width() += nDelta;
1867 (*pCurrent)->SetSizePixel( aNewSize );
1868 Point aNewPos = (*pCurrent)->GetPosPixel();
1869 aNewPos.X() -= nDelta;
1870 (*pCurrent)->SetPosPixel( aNewPos );
1873 // loop through all the other windows and adjust their size
1874 for ( ; i < sizeof( pWins ) / sizeof( pWins[ 0 ] ); ++i, ++pCurrent )
1876 Size aSize = (*pCurrent)->GetSizePixel();
1877 aSize.Width() -= nDelta;
1878 (*pCurrent)->SetSizePixel( aSize );
1883 String ErrorRepSendDialog::GetDocType( void ) const
1885 return maDocTypeED.GetText();
1888 String ErrorRepSendDialog::GetUsing( void ) const
1890 return maUsingML.GetText();
1893 bool ErrorRepSendDialog::IsContactAllowed( void ) const
1895 return maContactCB.IsChecked();
1898 String ErrorRepSendDialog::GetEMailAddress( void ) const
1900 return maEMailAddrED.GetText();
1904 ///////////////////////////////////////////////////////////////////////
1905 // Error Report Options Dialog
1906 ///////////////////////////////////////////////////////////////////////
1908 ErrorRepOptionsDialog::ErrorRepOptionsDialog( Window* _pParent, ErrorRepParams& _rParams )
1909 :ModalDialog ( _pParent, SVX_RES( RID_SVX_MDLG_ERR_REP_OPTIONS ) )
1910 ,maProxyFL( this, SVX_RES( FL_ERROPT_PROXY ) )
1911 ,maSystemBtn( this, SVX_RES( BTN_ERROPT_SYSTEM ) )
1912 ,maDirectBtn( this, SVX_RES( BTN_ERROPT_DIRECT ) )
1913 ,maManualBtn( this, SVX_RES( BTN_ERROPT_MANUAL ) )
1914 ,maProxyServerFT( this, SVX_RES( FT_ERROPT_PROXYSERVER ) )
1915 ,maProxyServerEd( this, SVX_RES( ED_ERROPT_PROXYSERVER ) )
1916 ,maProxyPortFT( this, SVX_RES( FT_ERROPT_PROXYPORT ) )
1917 ,maProxyPortEd( this, SVX_RES( ED_ERROPT_PROXYPORT ) )
1918 ,maDescriptionFT( this, SVX_RES( FT_ERROPT_DESCRIPTION ) )
1919 ,maButtonsFL( this, SVX_RES( FL_ERROPT_BUTTONS ) )
1920 ,maOKBtn( this, SVX_RES( BTN_ERROPT_OK ) )
1921 ,maCancelBtn( this, SVX_RES( BTN_ERROPT_CANCEL ) )
1922 ,mrParams( _rParams )
1924 FreeResource();
1926 maManualBtn.SetToggleHdl( LINK( this, ErrorRepOptionsDialog, ManualBtnHdl ) );
1927 maCancelBtn.SetClickHdl( LINK( this, ErrorRepOptionsDialog, CancelBtnHdl ) );
1928 maOKBtn.SetClickHdl( LINK( this, ErrorRepOptionsDialog, OKBtnHdl ) );
1930 maProxyServerEd.SetText( mrParams.maHTTPProxyServer );
1931 maProxyPortEd.SetText( mrParams.maHTTPProxyPort );
1933 #ifndef WNT
1934 // no "Use system settings" button on non windows systems
1935 // so hide this button
1936 maSystemBtn.Hide();
1937 long nDelta = maDirectBtn.GetPosPixel().Y() - maSystemBtn.GetPosPixel().Y();
1938 // and loop through all these controls and adjust their position
1939 Window* pWins[] =
1941 &maDirectBtn, &maManualBtn, &maProxyServerFT,
1942 &maProxyServerEd, &maProxyPortFT, &maProxyPortEd, &maDescriptionFT
1944 Window** pCurrent = pWins;
1945 for ( sal_uInt32 i = 0; i < sizeof( pWins ) / sizeof( pWins[ 0 ] ); ++i, ++pCurrent )
1947 Point aPos = (*pCurrent)->GetPosPixel();
1948 aPos.Y() -= nDelta;
1949 (*pCurrent)->SetPosPixel( aPos );
1951 #endif
1954 switch ( mrParams.miHTTPConnectionType )
1956 default:
1957 #ifdef WNT
1958 case 0:
1959 maSystemBtn.Check( TRUE );
1960 break;
1961 #endif
1962 case 1:
1963 maDirectBtn.Check( TRUE );
1964 break;
1965 case 2:
1966 maManualBtn.Check( TRUE );
1967 break;
1970 ManualBtnHdl( 0 );
1973 ErrorRepOptionsDialog::~ErrorRepOptionsDialog()
1977 IMPL_LINK( ErrorRepOptionsDialog, ManualBtnHdl, void*, EMPTYARG )
1979 bool bCheck = maManualBtn.IsChecked();
1980 maProxyServerFT.Enable( bCheck );
1981 maProxyServerEd.Enable( bCheck );
1982 maProxyPortFT.Enable( bCheck );
1983 maProxyPortEd.Enable( bCheck );
1984 return 0;
1987 IMPL_LINK( ErrorRepOptionsDialog, OKBtnHdl, void*, EMPTYARG )
1989 if ( maManualBtn.IsChecked() )
1990 mrParams.miHTTPConnectionType = 2;
1991 else if ( maDirectBtn.IsChecked() )
1992 mrParams.miHTTPConnectionType = 1;
1993 else if ( maSystemBtn.IsChecked() )
1994 mrParams.miHTTPConnectionType = 0;
1996 mrParams.maHTTPProxyServer = maProxyServerEd.GetText();
1997 mrParams.maHTTPProxyPort = maProxyPortEd.GetText();
1999 EndDialog(DLG_RET_OK);
2000 return 0;
2003 IMPL_LINK( ErrorRepOptionsDialog, CancelBtnHdl, void*, EMPTYARG )
2005 EndDialog(DLG_RET_CANCEL);
2006 return 0;
2009 ///////////////////////////////////////////////////////////////////////
2010 // Error Report Edit (MultiLineEdit with fixed font)
2011 ///////////////////////////////////////////////////////////////////////
2013 ErrorRepEdit::ErrorRepEdit( Window* pParent, const ResId& rResId ) :
2014 ExtMultiLineEdit( pParent, rResId )
2016 // fixed font for error report
2017 Color aColor = GetTextColor();
2019 Font aFont = OutputDevice::GetDefaultFont(
2020 DEFAULTFONT_FIXED, LANGUAGE_SYSTEM, DEFAULTFONT_FLAGS_ONLYONE );
2022 // Set font color because the default font color is transparent !!!
2023 aFont.SetColor( aColor );
2025 GetTextEngine()->SetFont( aFont );
2027 // no blinking cursor and a little left margin
2028 EnableCursor( FALSE );
2029 SetLeftMargin( 4 );
2032 ErrorRepEdit::~ErrorRepEdit()
2036 ///////////////////////////////////////////////////////////////////////
2037 // Error Report Preview Dialog
2038 ///////////////////////////////////////////////////////////////////////
2041 static ::rtl::OUString GetCrashConfigDir()
2044 #if defined(WNT) || defined(OS2)
2045 OUString ustrValue = OUString::createFromAscii("${$BRAND_BASE_DIR/program/bootstrap.ini:UserInstallation}");
2046 #elif defined( MACOSX )
2047 OUString ustrValue = OUString::createFromAscii("~");
2048 #else
2049 OUString ustrValue = OUString::createFromAscii("$SYSUSERCONFIG");
2050 #endif
2051 Bootstrap::expandMacros( ustrValue );
2053 #if defined(WNT) || defined(OS2)
2054 ustrValue += OUString::createFromAscii("/user/crashdata");
2055 #endif
2056 return ustrValue;
2059 #if defined(WNT) || defined(OS2)
2060 #define CHKFILE "crashdat.chk"
2061 #define STKFILE "crashdat.stk"
2062 #define PRVFILE "crashdat.prv"
2063 #else
2064 #define CHKFILE ".crash_report_checksum"
2065 #define STKFILE ".crash_report_frames"
2066 #define PRVFILE ".crash_report_preview"
2067 #endif
2069 // static ::rtl::OUString GetChecksumURL()
2070 // {
2071 // ::rtl::OUString aURL = GetCrashConfigDir();
2073 // aURL += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) );
2074 // aURL += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CHKFILE ) );
2076 // return aURL;
2077 // }
2079 // static ::rtl::OUString GetStackURL()
2080 // {
2081 // ::rtl::OUString aURL = GetCrashConfigDir();
2083 // aURL += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) );
2084 // aURL += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STKFILE ) );
2086 // return aURL;
2087 // }
2089 static ::rtl::OUString GetPreviewURL()
2091 ::rtl::OUString aURL = GetCrashConfigDir();
2093 aURL += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) );
2094 aURL += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( PRVFILE ) );
2096 return aURL;
2099 static String LoadCrashFile( const ::rtl::OUString &rURL )
2101 String aFileContent;
2102 ::osl::File aFile( rURL );
2104 printf( "Loading %s:", OString( rURL.getStr(), rURL.getLength(), osl_getThreadTextEncoding() ).getStr() );
2105 if ( ::osl::FileBase::E_None == aFile.open( OpenFlag_Read ) )
2107 ::rtl::OString aContent;
2108 ::osl::FileBase::RC result;
2109 sal_uInt64 aBytesRead;
2113 sal_Char aBuffer[256];
2115 result = aFile.read( aBuffer, sizeof(aBuffer), aBytesRead );
2117 if ( ::osl::FileBase::E_None == result )
2119 ::rtl::OString aTemp( aBuffer, static_cast< xub_StrLen >( aBytesRead ) );
2120 aContent += aTemp;
2122 } while ( ::osl::FileBase::E_None == result && aBytesRead );
2124 ::rtl::OUString ustrContent( aContent.getStr(), aContent.getLength(), RTL_TEXTENCODING_UTF8 );
2125 aFileContent = ustrContent;
2127 aFile.close();
2129 printf( "SUCCEEDED\n" );
2131 else
2132 printf( "FAILED\n" );
2134 return aFileContent;
2139 ErrorRepPreviewDialog::ErrorRepPreviewDialog( Window* _pParent )
2140 :ModalDialog ( _pParent, SVX_RES( RID_SVX_MDLG_ERR_REP_PREVIEW ) )
2141 ,maContentML( this, SVX_RES( ML_ERRPREVIEW_CONTENT ) )
2142 ,maOKBtn( this, SVX_RES( BTN_ERRPREVIEW_OK ) )
2145 FreeResource();
2147 mnMinHeight = ( maContentML.GetSizePixel().Height() / 2 );
2149 String aPreview = LoadCrashFile( GetPreviewURL() );
2150 ErrorRepSendDialog *pMainDlg = (ErrorRepSendDialog *)_pParent;
2152 String aSeperator = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "\r\n\r\n================\r\n\r\n" ) );
2154 String aContent = pMainDlg->GetDocType();
2155 if ( aContent.Len() > 0 )
2156 aContent += aSeperator;
2157 aContent += pMainDlg->GetUsing();
2158 if ( aContent.Len() > 0 )
2159 aContent += aSeperator;
2160 aContent += aPreview;
2162 maContentML.SetText( aContent );
2165 ErrorRepPreviewDialog::~ErrorRepPreviewDialog()
2169 void ErrorRepPreviewDialog::Resize()
2171 Size a3Sz = LogicToPixel( Size( 3, 3 ), MAP_APPFONT );
2172 Size aWinSz = GetSizePixel();
2173 Size aBtnSz = maOKBtn.GetSizePixel();
2174 Point aEditPnt = maContentML.GetPosPixel();
2176 long nNewHeight = Max( aWinSz.Height() - aEditPnt.Y() - 3 * a3Sz.Height() - aBtnSz.Height(), mnMinHeight );
2177 long nNewWidth = aWinSz.Width() - 4 * a3Sz.Width();
2179 Size aNewSize( nNewWidth, nNewHeight );
2180 maContentML.SetSizePixel( aNewSize );
2181 Point aNewPoint( Max( aEditPnt.X() + aNewSize.Width() - aBtnSz.Width(), aEditPnt.X() ),
2182 aEditPnt.Y() + aNewSize.Height() + a3Sz.Height() );
2183 maOKBtn.SetPosPixel( aNewPoint );
2185 } // namespace DocRecovery
2186 } // namespace svx