sfx2: let .uno:SignPDF result in a warning before editing the doc

Editing such a document is most probably not what you want, help the
user to avoid the trouble.

Change-Id: I87d52d89e12658675b580b7dc21fb38fe41dd777
Reviewed-on: https://gerrit.libreoffice.org/30955
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
This commit is contained in:
Miklos Vajna
2016-11-18 11:28:45 +01:00
parent 5fb9418096
commit d4460b7000
3 changed files with 130 additions and 7 deletions

View File

@@ -20,6 +20,7 @@ $(eval $(call gb_UIConfig_add_uifiles,sfx,\
sfx2/uiconfig/ui/documentfontspage \
sfx2/uiconfig/ui/documentinfopage \
sfx2/uiconfig/ui/documentpropertiesdialog \
sfx2/uiconfig/ui/editdocumentdialog \
sfx2/uiconfig/ui/editdurationdialog \
sfx2/uiconfig/ui/emojicontrol \
sfx2/uiconfig/ui/errorfindemaildialog \

View File

@@ -154,6 +154,55 @@ void SfxViewFrame::InitInterface_Impl()
#endif
}
/// Asks the user if editing a read-only document is really wanted.
class SfxEditDocumentDialog : public MessageDialog
{
private:
VclPtr<PushButton> m_pEditDocument;
VclPtr<PushButton> m_pCancel;
public:
SfxEditDocumentDialog(vcl::Window* pParent);
~SfxEditDocumentDialog() override;
void dispose() override;
};
SfxEditDocumentDialog::SfxEditDocumentDialog(vcl::Window* pParent)
: MessageDialog(pParent, "EditDocumentDialog", "sfx/ui/editdocumentdialog.ui")
{
get(m_pEditDocument, "edit");
get(m_pCancel, "cancel");
}
SfxEditDocumentDialog::~SfxEditDocumentDialog()
{
disposeOnce();
}
void SfxEditDocumentDialog::dispose()
{
m_pEditDocument.clear();
m_pCancel.clear();
MessageDialog::dispose();
}
/// Is this read-only object shell opened via .uno:SignPDF?
static bool IsSignPDF(SfxObjectShellRef xObjSh)
{
if (!xObjSh.Is())
return false;
SfxMedium* pMedium = xObjSh->GetMedium();
if (pMedium && !pMedium->IsOriginallyReadOnly())
{
std::shared_ptr<const SfxFilter> pFilter = pMedium->GetFilter();
if (pFilter && pFilter->GetName() == "draw_pdf_import")
return true;
}
return false;
}
static bool AskPasswordToModify_Impl( const uno::Reference< task::XInteractionHandler >& xHandler, const OUString& aPath, const std::shared_ptr<const SfxFilter>& pFilter, sal_uInt32 nPasswordHash, const uno::Sequence< beans::PropertyValue >& aInfo )
{
// TODO/LATER: In future the info should replace the direct hash completely
@@ -1149,13 +1198,7 @@ void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
}
else
{
bool bSignPDF = false;
SfxMedium* pMedium = m_xObjSh->GetMedium();
if (pMedium && !pMedium->IsOriginallyReadOnly())
{
std::shared_ptr<const SfxFilter> pFilter = pMedium->GetFilter();
bSignPDF = pFilter && pFilter->GetName() == "draw_pdf_import";
}
bool bSignPDF = IsSignPDF(m_xObjSh);
SfxInfoBarWindow* pInfoBar = AppendInfoBar("readonly", SfxResId(bSignPDF ? STR_READONLY_PDF : STR_READONLY_DOCUMENT));
if (pInfoBar)
@@ -1267,6 +1310,12 @@ void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
IMPL_LINK_NOARG(SfxViewFrame, SwitchReadOnlyHandler, Button*, void)
{
if (m_xObjSh.Is() && IsSignPDF(m_xObjSh))
{
ScopedVclPtrInstance<SfxEditDocumentDialog> pDialog(nullptr);
if (pDialog->Execute() != RET_OK)
return;
}
GetDispatcher()->Execute(SID_EDITDOC);
}

View File

@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 -->
<interface>
<requires lib="gtk+" version="3.0"/>
<object class="GtkMessageDialog" id="EditDocumentDialog">
<property name="can_focus">False</property>
<property name="border_width">6</property>
<property name="title" translatable="yes">Confirm editing of document</property>
<property name="resizable">False</property>
<property name="modal">True</property>
<property name="type_hint">dialog</property>
<property name="skip_taskbar_hint">True</property>
<property name="message_type">question</property>
<property name="text" translatable="yes">Are you sure you want to edit the document?</property>
<property name="secondary_text" translatable="yes">The original file can be signed without editing the document. Existing signatures on the document will be lost in case of saving an edited version.</property>
<child internal-child="vbox">
<object class="GtkBox" id="messagedialog-vbox">
<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="messagedialog-action_area">
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="edit">
<property name="label" translatable="yes">Edit Document</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="has_default">True</property>
<property name="receives_default">True</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
<property name="non_homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkButton" id="cancel">
<property name="label" translatable="yes">Cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_underline">True</property>
<property name="image_position">bottom</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
<property name="non_homogeneous">True</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>
</object>
</child>
<action-widgets>
<action-widget response="1">edit</action-widget>
<action-widget response="0">cancel</action-widget>
</action-widgets>
</object>
</interface>