Kaydet (Commit) bc998e5e authored tarafından Jan-Marek Glogowski's avatar Jan-Marek Glogowski Kaydeden (comit) Björn Michaelsen

MM: readd CreateMonitor handling

The mail merge wizard uses a different progress dialog
(CreateDialog) then the UNO functions (PrintDialog).

This restores the previously unused code and unifies some of the
dialog handling.

This reverts the dbmgr / mail merge unused code parts of
    commit d49d0139 and
    commit c16f45db

Change-Id: I06088140f604893a33f3ee37507e551b043a193d
Reviewed-on: https://gerrit.libreoffice.org/10985Reviewed-by: 's avatarBjörn Michaelsen <bjoern.michaelsen@canonical.com>
Tested-by: 's avatarBjörn Michaelsen <bjoern.michaelsen@canonical.com>
üst 36ac7749
...@@ -168,6 +168,31 @@ const sal_Char cActiveConnection[] = "ActiveConnection"; ...@@ -168,6 +168,31 @@ const sal_Char cActiveConnection[] = "ActiveConnection";
namespace namespace
{ {
bool lcl_getCountFromResultSet( sal_Int32& rCount, const uno::Reference<XResultSet>& xResultSet )
{
uno::Reference<XPropertySet> xPrSet(xResultSet, UNO_QUERY);
if(xPrSet.is())
{
try
{
bool bFinal = false;
Any aFinal = xPrSet->getPropertyValue("IsRowCountFinal");
aFinal >>= bFinal;
if(!bFinal)
{
xResultSet->last();
xResultSet->first();
}
Any aCount = xPrSet->getPropertyValue("RowCount");
if( aCount >>= rCount )
return true;
}
catch(const Exception&)
{
}
}
return false;
}
// copy compatibility options // copy compatibility options
void lcl_CopyCompatibilityOptions( SwWrtShell& rSourceShell, SwWrtShell& rTargetShell) void lcl_CopyCompatibilityOptions( SwWrtShell& rSourceShell, SwWrtShell& rTargetShell)
{ {
...@@ -829,9 +854,9 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, ...@@ -829,9 +854,9 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
//check if the doc is synchronized and contains at least one linked section //check if the doc is synchronized and contains at least one linked section
bool bSynchronizedDoc = pSourceShell->IsLabelDoc() && pSourceShell->GetSectionFmtCount() > 1; bool bSynchronizedDoc = pSourceShell->IsLabelDoc() && pSourceShell->GetSectionFmtCount() > 1;
bool bNoError = true; bool bNoError = true;
bool bEMail = rMergeDescriptor.nMergeType == DBMGR_MERGE_MAILING; const bool bEMail = rMergeDescriptor.nMergeType == DBMGR_MERGE_MAILING;
const bool bAsSingleFile = rMergeDescriptor.nMergeType == DBMGR_MERGE_SINGLE_FILE; const bool bAsSingleFile = rMergeDescriptor.nMergeType == DBMGR_MERGE_SINGLE_FILE;
bool bMergeOnly = rMergeDescriptor.nMergeType == DBMGR_MERGE_ONLY; const bool bMergeOnly = rMergeDescriptor.nMergeType == DBMGR_MERGE_ONLY;
::rtl::Reference< MailDispatcher > xMailDispatcher; ::rtl::Reference< MailDispatcher > xMailDispatcher;
OUString sBodyMimeType; OUString sBodyMimeType;
...@@ -910,6 +935,24 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, ...@@ -910,6 +935,24 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
sal_uInt16 nStartingPageNo = 0; sal_uInt16 nStartingPageNo = 0;
bool bPageStylesWithHeaderFooter = false; bool bPageStylesWithHeaderFooter = false;
vcl::Window *pSourceWindow = 0;
CancelableModelessDialog *pProgressDlg = 0;
if (!IsMergeSilent()) {
pSourceWindow = &pSourceShell->GetView().GetEditWin();
if( bMergeOnly )
pProgressDlg = new CreateMonitor( pSourceWindow );
else {
pProgressDlg = new PrintMonitor( pSourceWindow, PrintMonitor::MONITOR_TYPE_PRINT );
static_cast<PrintMonitor*>( pProgressDlg )->SetText(pSourceShell->GetView().GetDocShell()->GetTitle(22));
}
pProgressDlg->SetCancelHdl( LINK(this, SwDBManager, PrtCancelHdl) );
pProgressDlg->Show();
for( sal_uInt16 i = 0; i < 25; i++)
Application::Reschedule();
}
if(bAsSingleFile || rMergeDescriptor.bCreateSingleFile) if(bAsSingleFile || rMergeDescriptor.bCreateSingleFile)
{ {
// create a target docshell to put the merged document into // create a target docshell to put the merged document into
...@@ -919,6 +962,11 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, ...@@ -919,6 +962,11 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
lcl_SaveDoc( xTargetDocShell, "MergeDoc" ); lcl_SaveDoc( xTargetDocShell, "MergeDoc" );
#endif #endif
SfxViewFrame* pTargetFrame = SfxViewFrame::LoadHiddenDocument( *xTargetDocShell, 0 ); SfxViewFrame* pTargetFrame = SfxViewFrame::LoadHiddenDocument( *xTargetDocShell, 0 );
if (bMergeOnly) {
//the created window has to be located at the same position as the source window
vcl::Window& rTargetWindow = pTargetFrame->GetFrame().GetWindow();
rTargetWindow.SetPosPixel(pSourceWindow->GetPosPixel());
}
pTargetView = static_cast<SwView*>( pTargetFrame->GetViewShell() ); pTargetView = static_cast<SwView*>( pTargetFrame->GetViewShell() );
...@@ -948,13 +996,6 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, ...@@ -948,13 +996,6 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
lcl_CopyDynamicDefaults( *pSourceShell->GetDoc(), *pTargetShell->GetDoc() ); lcl_CopyDynamicDefaults( *pSourceShell->GetDoc(), *pTargetShell->GetDoc() );
} }
PrintMonitor aPrtMonDlg(&pSourceShell->GetView().GetEditWin(), PrintMonitor::MONITOR_TYPE_PRINT);
aPrtMonDlg.m_pDocName->SetText(pSourceShell->GetView().GetDocShell()->GetTitle(22));
aPrtMonDlg.SetCancelHdl(LINK(this, SwDBManager, PrtCancelHdl));
if (!IsMergeSilent())
aPrtMonDlg.Show();
// Progress, to prohibit KeyInputs // Progress, to prohibit KeyInputs
SfxProgress aProgress(pSourceDocSh, ::aEmptyOUStr, 1); SfxProgress aProgress(pSourceDocSh, ::aEmptyOUStr, 1);
...@@ -965,7 +1006,12 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, ...@@ -965,7 +1006,12 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
pViewFrm->GetDispatcher()->Lock(true); pViewFrm->GetDispatcher()->Lock(true);
pViewFrm = SfxViewFrame::GetNext(*pViewFrm, pSourceDocSh); pViewFrm = SfxViewFrame::GetNext(*pViewFrm, pSourceDocSh);
} }
sal_uLong nDocNo = 1; sal_uLong nDocNo = 1;
sal_Int32 nDocCount = 0;
if( !IsMergeSilent() && bMergeOnly &&
lcl_getCountFromResultSet( nDocCount, pImpl->pMergeData->xResultSet ) )
static_cast<CreateMonitor*>( pProgressDlg )->SetTotalCount( nDocCount );
long nStartRow, nEndRow; long nStartRow, nEndRow;
bool bFreezedLayouts = false; bool bFreezedLayouts = false;
...@@ -1017,14 +1063,22 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, ...@@ -1017,14 +1063,22 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
else else
{ {
INetURLObject aTempFileURL(aTempFile->GetURL()); INetURLObject aTempFileURL(aTempFile->GetURL());
aPrtMonDlg.m_pPrinter->SetText( aTempFileURL.GetBase() ); if (!IsMergeSilent()) {
OUString sStat(SW_RES(STR_STATSTR_LETTER)); // Brief if( bMergeOnly )
sStat += " "; static_cast<CreateMonitor*>( pProgressDlg )->SetCurrentPosition( nDocNo );
sStat += OUString::number( nDocNo ); else {
aPrtMonDlg.m_pPrintInfo->SetText(sStat); PrintMonitor *pPrintMonDlg = static_cast<PrintMonitor*>( pProgressDlg );
pPrintMonDlg->m_pPrinter->SetText( aTempFileURL.GetBase() );
// computation time for Save-Monitor: OUString sStat(SW_RES(STR_STATSTR_LETTER)); // Brief
for (sal_uInt16 i = 0; i < 25; i++) sStat += " ";
sStat += OUString::number( nDocNo );
pPrintMonDlg->m_pPrintInfo->SetText( sStat );
}
pProgressDlg->Update();
}
// Computation time for the GUI
for( sal_uInt16 i = 0; i < 25; i++ )
Application::Reschedule(); Application::Reschedule();
// The SfxObjectShell will be closed explicitly later but it is more safe to use SfxObjectShellLock here // The SfxObjectShell will be closed explicitly later but it is more safe to use SfxObjectShellLock here
...@@ -1250,6 +1304,9 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, ...@@ -1250,6 +1304,9 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
} while( !bCancel && } while( !bCancel &&
(bSynchronizedDoc && (nStartRow != nEndRow)? ExistsNextRecord() : ToNextMergeRecord())); (bSynchronizedDoc && (nStartRow != nEndRow)? ExistsNextRecord() : ToNextMergeRecord()));
for( sal_uInt16 i = 0; i < 25; i++)
Application::Reschedule();
// Unfreeze target document layouts and correct all PageDescs. // Unfreeze target document layouts and correct all PageDescs.
if(rMergeDescriptor.bCreateSingleFile || bAsSingleFile) if(rMergeDescriptor.bCreateSingleFile || bAsSingleFile)
{ {
...@@ -1259,7 +1316,7 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, ...@@ -1259,7 +1316,7 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
std::for_each( aAllLayouts.begin(), aAllLayouts.end(),std::mem_fun(&SwRootFrm::AllCheckPageDescs)); std::for_each( aAllLayouts.begin(), aAllLayouts.end(),std::mem_fun(&SwRootFrm::AllCheckPageDescs));
} }
aPrtMonDlg.Show( false ); DELETEZ( pProgressDlg );
// save the single output document // save the single output document
if (bMergeOnly) if (bMergeOnly)
......
...@@ -42,6 +42,41 @@ PrintMonitor::PrintMonitor(vcl::Window *pParent, PrintMonitorType eType ) ...@@ -42,6 +42,41 @@ PrintMonitor::PrintMonitor(vcl::Window *pParent, PrintMonitorType eType )
m_pPrinting->Show(); m_pPrinting->Show();
} }
// Progress Indicator for Creation of personalized Mail Merge documents:
CreateMonitor::CreateMonitor( vcl::Window *pParent )
: CancelableModelessDialog(pParent, "MMCreatingDialog",
"modules/swriter/ui/mmcreatingdialog.ui")
, m_sCountingPattern()
, m_sVariable_Total("%Y")
, m_sVariable_Position("%X")
, m_nTotalCount(0)
, m_nCurrentPosition(0)
{
get(m_pCounting, "progress");
m_sCountingPattern = m_pCounting->GetText();
m_pCounting->SetText("...");
}
void CreateMonitor::UpdateCountingText()
{
OUString sText(m_sCountingPattern);
sText = sText.replaceAll( m_sVariable_Total, OUString::number( m_nTotalCount ) );
sText = sText.replaceAll( m_sVariable_Position, OUString::number( m_nCurrentPosition ) );
m_pCounting->SetText(sText);
}
void CreateMonitor::SetTotalCount( sal_Int32 nTotal )
{
m_nTotalCount = nTotal;
UpdateCountingText();
}
void CreateMonitor::SetCurrentPosition( sal_Int32 nCurrent )
{
m_nCurrentPosition = nCurrent;
UpdateCountingText();
}
CancelableModelessDialog::CancelableModelessDialog( vcl::Window *pParent, CancelableModelessDialog::CancelableModelessDialog( vcl::Window *pParent,
const OString& rID, const OUString& rUIXMLDescription ) const OString& rID, const OUString& rUIXMLDescription )
: ModelessDialog( pParent , rID, rUIXMLDescription ) : ModelessDialog( pParent , rID, rUIXMLDescription )
......
...@@ -53,6 +53,27 @@ public: ...@@ -53,6 +53,27 @@ public:
PrintMonitor( vcl::Window *pParent, PrintMonitorType eType ); PrintMonitor( vcl::Window *pParent, PrintMonitorType eType );
}; };
class CreateMonitor : public CancelableModelessDialog
{
public:
CreateMonitor( vcl::Window *pParent );
void SetTotalCount( sal_Int32 nTotal );
void SetCurrentPosition( sal_Int32 nCurrent );
private:
void UpdateCountingText();
private:
FixedText* m_pCounting;
OUString m_sCountingPattern;
OUString m_sVariable_Total;
OUString m_sVariable_Position;
sal_Int32 m_nTotalCount;
sal_Int32 m_nCurrentPosition;
};
#endif #endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkDialog" id="MMCreatingDialog">
<property name="can_focus">False</property>
<property name="border_width">6</property>
<property name="title" translatable="yes">Mail Merge</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox1">
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog-action_area1">
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="cancel">
<property name="label">gtk-cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkGrid" id="grid1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="row_spacing">6</property>
<property name="column_spacing">12</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">1</property>
<property name="label" translatable="yes">Status:</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">1</property>
<property name="label" translatable="yes">Progress:</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Creating documents...</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="progress">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">%X of %Y</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="0">cancel</action-widget>
</action-widgets>
</object>
</interface>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment