diff options
author | osnola <alonso@loria.fr> | 2015-05-18 10:21:10 +0200 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2015-05-19 08:24:59 +0200 |
commit | f9568335a653f72732f9c8ebf007cf8850021ff9 (patch) | |
tree | ad5c96cbe2636c58a46692f92a1f127e5b2c4453 /writerperfect | |
parent | fa76bbbe9869b0a009e6e05df1130fac5b4fc15a (diff) |
upload libwps 0.4.0
Change-Id: I9da61333b7c46d20cf7010553929b141ec011d84
Diffstat (limited to 'writerperfect')
-rw-r--r-- | writerperfect/Library_wpftcalc.mk | 2 | ||||
-rw-r--r-- | writerperfect/Library_wpftdraw.mk | 2 | ||||
-rw-r--r-- | writerperfect/Library_wpftimpress.mk | 2 | ||||
-rw-r--r-- | writerperfect/Library_wpftwriter.mk | 2 | ||||
-rw-r--r-- | writerperfect/Library_writerperfect.mk | 3 | ||||
-rw-r--r-- | writerperfect/Module_writerperfect.mk | 4 | ||||
-rw-r--r-- | writerperfect/UIConfig_writerperfect.mk | 26 | ||||
-rw-r--r-- | writerperfect/source/calc/MSWorksCalcImportFilter.cxx | 71 | ||||
-rw-r--r-- | writerperfect/source/common/WPFTEncodingDialog.cxx | 177 | ||||
-rw-r--r-- | writerperfect/source/writer/MSWorksImportFilter.cxx | 34 | ||||
-rw-r--r-- | writerperfect/uiconfig/ui/wpftencodingdialog.ui | 88 |
11 files changed, 404 insertions, 7 deletions
diff --git a/writerperfect/Library_wpftcalc.mk b/writerperfect/Library_wpftcalc.mk index 395d1d81a3ab..a68aa4846ffd 100644 --- a/writerperfect/Library_wpftcalc.mk +++ b/writerperfect/Library_wpftcalc.mk @@ -34,8 +34,10 @@ $(eval $(call gb_Library_use_libraries,wpftcalc,\ cppuhelper \ sal \ sot \ + svx \ tl \ utl \ + vcl \ writerperfect \ xo \ $(gb_UWINAPI) \ diff --git a/writerperfect/Library_wpftdraw.mk b/writerperfect/Library_wpftdraw.mk index 29409c135e33..1e57fcd9aa1a 100644 --- a/writerperfect/Library_wpftdraw.mk +++ b/writerperfect/Library_wpftdraw.mk @@ -34,8 +34,10 @@ $(eval $(call gb_Library_use_libraries,wpftdraw,\ cppuhelper \ sal \ sot \ + svx \ tl \ utl \ + vcl \ writerperfect \ xo \ $(gb_UWINAPI) \ diff --git a/writerperfect/Library_wpftimpress.mk b/writerperfect/Library_wpftimpress.mk index eac71cb02d31..3d35aa778151 100644 --- a/writerperfect/Library_wpftimpress.mk +++ b/writerperfect/Library_wpftimpress.mk @@ -34,9 +34,11 @@ $(eval $(call gb_Library_use_libraries,wpftimpress,\ cppuhelper \ sal \ sot \ + svx \ tl \ ucbhelper \ utl \ + vcl \ writerperfect \ xo \ $(gb_UWINAPI) \ diff --git a/writerperfect/Library_wpftwriter.mk b/writerperfect/Library_wpftwriter.mk index b47c2717f65c..8c32ea366f8f 100644 --- a/writerperfect/Library_wpftwriter.mk +++ b/writerperfect/Library_wpftwriter.mk @@ -36,9 +36,11 @@ $(eval $(call gb_Library_use_libraries,wpftwriter,\ sal \ sfx \ sot \ + svx \ tl \ ucbhelper \ utl \ + vcl \ writerperfect \ xo \ $(gb_UWINAPI) \ diff --git a/writerperfect/Library_writerperfect.mk b/writerperfect/Library_writerperfect.mk index 3089b5a0add8..1343be6625b6 100644 --- a/writerperfect/Library_writerperfect.mk +++ b/writerperfect/Library_writerperfect.mk @@ -37,9 +37,11 @@ $(eval $(call gb_Library_use_libraries,writerperfect,\ cppuhelper \ sal \ sot \ + svx \ tl \ ucbhelper \ utl \ + vcl \ xo \ $(gb_UWINAPI) \ )) @@ -47,6 +49,7 @@ $(eval $(call gb_Library_use_libraries,writerperfect,\ $(eval $(call gb_Library_add_exception_objects,writerperfect,\ writerperfect/source/common/DirectoryStream \ writerperfect/source/common/DocumentHandler \ + writerperfect/source/common/WPFTEncodingDialog \ writerperfect/source/common/WPXSvInputStream \ )) diff --git a/writerperfect/Module_writerperfect.mk b/writerperfect/Module_writerperfect.mk index 9c30697fea1c..e7870439eb05 100644 --- a/writerperfect/Module_writerperfect.mk +++ b/writerperfect/Module_writerperfect.mk @@ -27,6 +27,10 @@ $(eval $(call gb_Module_add_targets,writerperfect,\ Library_writerperfect \ )) +$(eval $(call gb_Module_add_l10n_targets,writerperfect,\ + UIConfig_writerperfect \ +)) + $(eval $(call gb_Module_add_check_targets,writerperfect,\ CppunitTest_writerperfect_stream \ )) diff --git a/writerperfect/UIConfig_writerperfect.mk b/writerperfect/UIConfig_writerperfect.mk new file mode 100644 index 000000000000..d0d8ef5030fb --- /dev/null +++ b/writerperfect/UIConfig_writerperfect.mk @@ -0,0 +1,26 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# + +$(eval $(call gb_UIConfig_UIConfig,writerperfect)) + +$(eval $(call gb_UIConfig_add_uifiles,writerperfect,\ + writerperfect/uiconfig/ui/wpftencodingdialog \ +)) + +# vim: set noet sw=4 ts=4: diff --git a/writerperfect/source/calc/MSWorksCalcImportFilter.cxx b/writerperfect/source/calc/MSWorksCalcImportFilter.cxx index d8976389ded0..f68b4a00eab6 100644 --- a/writerperfect/source/calc/MSWorksCalcImportFilter.cxx +++ b/writerperfect/source/calc/MSWorksCalcImportFilter.cxx @@ -14,6 +14,7 @@ #include <libwps/libwps.h> +#include "writerperfect/WPFTEncodingDialog.hxx" #include "MSWorksCalcImportFilter.hxx" using com::sun::star::uno::Sequence; @@ -26,18 +27,78 @@ using com::sun::star::uno::XComponentContext; bool MSWorksCalcImportFilter::doImportDocument(librevenge::RVNGInputStream &rInput, OdsGenerator &rGenerator, utl::MediaDescriptor &) { - return libwps::WPS_OK == libwps::WPSDocument::parse(&rInput, &rGenerator); + libwps::WPSKind kind = libwps::WPS_TEXT; + libwps::WPSCreator creator; + bool needEncoding; + const libwps::WPSConfidence confidence = libwps::WPSDocument::isFileFormatSupported(&rInput, kind, creator, needEncoding); + + std::string fileEncoding(""); + if ((kind == libwps::WPS_SPREADSHEET || kind == libwps::WPS_DATABASE) && (confidence == libwps::WPS_CONFIDENCE_EXCELLENT) && needEncoding) + { + OUString title, encoding; + if (creator == libwps::WPS_MSWORKS) + { + title="Import MsWorks files(libwps)"; + encoding="CP850"; + } + else if (creator == libwps::WPS_LOTUS) + { + title="Import Lotus files(libwps)"; + encoding="CP437"; + } + else if (creator == libwps::WPS_SYMPHONY) + { + title="Import Symphony files(libwps)"; + encoding="CP437"; + } + else + { + title="Import Quattro Pro files(libwps)"; + encoding="CP437"; + } + try + { + const ScopedVclPtrInstance<writerperfect::WPFTEncodingDialog> pDlg(nullptr, &title, &encoding); + if (pDlg->Execute() == RET_OK) + { + if (!pDlg->GetEncoding().isEmpty()) + fileEncoding=pDlg->GetEncoding().toUtf8().getStr(); + } + // we can fail because we are in headless mode, the user has cancelled conversion, ... + else if (pDlg->hasUserCalledCancel()) + return false; + } + catch (...) + { + } + } + return libwps::WPS_OK == libwps::WPSDocument::parse(&rInput, &rGenerator, "", fileEncoding.c_str()); } bool MSWorksCalcImportFilter::doDetectFormat(librevenge::RVNGInputStream &rInput, OUString &rTypeName) { libwps::WPSKind kind = libwps::WPS_TEXT; - const libwps::WPSConfidence confidence = libwps::WPSDocument::isFileFormatSupported(&rInput, kind); + libwps::WPSCreator creator; + bool needEncoding; + const libwps::WPSConfidence confidence = libwps::WPSDocument::isFileFormatSupported(&rInput, kind, creator, needEncoding); - if ((kind == libwps::WPS_SPREADSHEET || kind == libwps::WPS_DATABASE) && (confidence == libwps::WPS_CONFIDENCE_EXCELLENT)) + if ((kind == libwps::WPS_SPREADSHEET || kind == libwps::WPS_DATABASE) && confidence == libwps::WPS_CONFIDENCE_EXCELLENT) { - rTypeName = "calc_MS_Works_Document"; - return true; + if (creator == libwps::WPS_MSWORKS) + { + rTypeName = "calc_MS_Works_Document"; + return true; + } + if (creator == libwps::WPS_LOTUS || creator == libwps::WPS_SYMPHONY) + { + rTypeName = "calc_WPS_Lotus_Document"; + return true; + } + if (creator == libwps::WPS_QUATTRO_PRO) + { + rTypeName = "calc_WPS_QPro_Document"; + return true; + } } return false; diff --git a/writerperfect/source/common/WPFTEncodingDialog.cxx b/writerperfect/source/common/WPFTEncodingDialog.cxx new file mode 100644 index 000000000000..4e04304a5247 --- /dev/null +++ b/writerperfect/source/common/WPFTEncodingDialog.cxx @@ -0,0 +1,177 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <writerperfect/WPFTEncodingDialog.hxx> + +namespace writerperfect +{ + +namespace +{ + +struct EncodingImplementation +{ + + static OUString const(s_encodings[]); + + static int numEncodings(); + static void insertEncodings(ListBox *box); + static void selectEncoding(ListBox *box, const OUString *encoding); + static OUString getEncoding(ListBox *box); +}; + +OUString const(EncodingImplementation::s_encodings[])= +{ + "MacArabic", "Arabic (Apple Macintosh)", + "CP864", "Arabic (DOS/OS2-864)", + "CP1006", "Arabic (IBM-1006)", + "CP1256", "Arabic (Windows-1256)", + "CP775", "Baltic (DOS/OS2-775)", + "CP1257", "Baltic (Windows-1257)", + "MacCeltic", "Celtic (Apple Macintosh)", + "MacCyrillic", "Cyrillic (Apple Macintosh)", + "CP855", "Cyrillic (DOS/OS2-855)", + "CP866", "Cyrillic (DOS/OS2-866/Russian)", + "CP1251", "Cyrillic (Windows-1251)", + "MacCEurope", "Eastern Europe (Apple Macintosh)", + "MacCroatian", "Eastern Europe (Apple Macintosh/Croatian)", + "MacRomanian", "Eastern Europe (Apple Macintosh/Romanian)", + "CP852", "Eastern Europe (DOS/OS2-852)", + "CP1250", "Eastern Europe (Windows-1250/WinLatin 2)", + "MacGreek", "Greek (Apple Macintosh)", + "CP737", "Greek (DOS/OS2-737)", + "CP869", "Greek (DOS/OS2-869/Greek-2)", + "CP875", "Greek (DOS/OS2-875)", + "CP1253", "Greek (Windows-1253)", + "MacHebrew", "Hebrew (Apple Macintosh)", + "CP424", "Hebrew (DOS/OS2-424)", + "CP856", "Hebrew (DOS/OS2-856)", + "CP862", "Hebrew (DOS/OS2-862)", + "CP1255", "Hebrew (Windows-1255)", + "CP500", "International (DOS/OS2-500)", + "MacThai", "Thai (Apple Macintosh)", + "CP874", "Thai (DOS/OS2-874)", + "MacTurkish", "Turkish (Apple Macintosh)", + "CP857", "Turkish (DOS/OS2-857)", + "CP1026", "Turkish (DOS/OS2-1026)", + "CP1254", "Turkish (Windows-1254)", + "CP1258", "Vietnamese (Windows-1258)", + "MacRoman", "Western Europe (Apple Macintosh)", + "MacIceland", "Western Europe (Apple Macintosh/Icelandic)", + "CP037", "Western Europe (DOS/OS2-037/US-Canada)", + "CP437", "Western Europe (DOS/OS2-437/US)", + "CP850", "Western Europe (DOS/OS2-850)", + "CP860", "Western Europe (DOS/OS2-860/Portuguese)", + "CP861", "Western Europe (DOS/OS2-861/Icelandic)", + "CP863", "Western Europe (DOS/OS2-863/French)", + "CP865", "Western Europe (DOS/OS2-865/Nordic)", + "CP1252", "Western Europe (Windows-1252/WinLatin 1)" +}; + +int EncodingImplementation::numEncodings() +{ + return int(sizeof(s_encodings)/(2*sizeof(const OUString *))); +} + +void EncodingImplementation::insertEncodings(ListBox *box) +{ + sal_IntPtr num=sal_IntPtr(numEncodings()); + for (sal_IntPtr i=0; i<num; ++i) + { + sal_IntPtr nAt=box->InsertEntry(s_encodings[2*i+1]); + box->SetEntryData(nAt, reinterpret_cast<void *>(i)); + } +} + +void EncodingImplementation::selectEncoding(ListBox *box, const OUString *encoding) +{ + if (!encoding) + return; + sal_IntPtr num=sal_IntPtr(numEncodings()); + for (sal_IntPtr i=0; i<num; ++i) + { + if (*encoding!=s_encodings[2*i]) continue; + box->SelectEntryPos(i); + return; + } +} + +OUString EncodingImplementation::getEncoding(ListBox *box) +{ + sal_IntPtr pos=(sal_IntPtr) box->GetSelectEntryData(); + if (pos<0||pos>=numEncodings()) + return OUString(); + return s_encodings[2*pos]; +} + +} + +WPFTEncodingDialog::WPFTEncodingDialog( + vcl::Window *pParent, + const OUString *pStrTitle, + const OUString *encoding) + : ModalDialog(pParent, "WPFTEncodingDialog", "writerperfect/ui/WPFTEncodingDialog.ui"), + m_pLbCharset(), m_pBtnOk(), m_pBtnCancel(), m_userHasCancelled(false) +{ + get(m_pLbCharset, "comboboxtext"); + get(m_pBtnOk, "ok"); + get(m_pBtnCancel, "cancel"); + + m_pBtnCancel->SetClickHdl(LINK(this, WPFTEncodingDialog, CancelHdl)); + + EncodingImplementation::insertEncodings(m_pLbCharset); + m_pLbCharset->SetStyle(m_pLbCharset->GetStyle() | WB_SORT); + // m_pLbCharset->set_height_request(6 * m_pLbCharset->GetTextHeight()); + m_pLbCharset->SetDoubleClickHdl(LINK(this, WPFTEncodingDialog, DoubleClickHdl)); + if (encoding) + EncodingImplementation::selectEncoding(m_pLbCharset, encoding); + m_pLbCharset->Show(); + + if (pStrTitle) + SetText(*pStrTitle); +} + +WPFTEncodingDialog::~WPFTEncodingDialog() +{ +} + +OUString WPFTEncodingDialog::GetEncoding() const +{ + return EncodingImplementation::getEncoding(m_pLbCharset); +} + +IMPL_LINK_NOARG(WPFTEncodingDialog, CancelHdl) +{ + m_userHasCancelled=true; + Close(); + return 0; +} + +IMPL_LINK(WPFTEncodingDialog, DoubleClickHdl, ListBox *, pLb) +{ + if (pLb == m_pLbCharset) + { + m_pBtnOk->Click(); + } + return 0; +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/writer/MSWorksImportFilter.cxx b/writerperfect/source/writer/MSWorksImportFilter.cxx index 61c54f5779b4..f06a21a08ee6 100644 --- a/writerperfect/source/writer/MSWorksImportFilter.cxx +++ b/writerperfect/source/writer/MSWorksImportFilter.cxx @@ -9,11 +9,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include <boost/scoped_ptr.hpp> #include <com/sun/star/uno/Reference.h> #include <cppuhelper/supportsservice.hxx> #include <libwps/libwps.h> +#include "writerperfect/WPFTEncodingDialog.hxx" #include "MSWorksImportFilter.hxx" using com::sun::star::uno::Sequence; @@ -33,13 +35,41 @@ static bool handleEmbeddedWKSObject(const librevenge::RVNGBinaryData &data, OdfD bool MSWorksImportFilter::doImportDocument(librevenge::RVNGInputStream &rInput, OdtGenerator &rGenerator, utl::MediaDescriptor &) { - return libwps::WPS_OK == libwps::WPSDocument::parse(&rInput, &rGenerator); + libwps::WPSKind kind = libwps::WPS_TEXT; + libwps::WPSCreator creator; + bool needEncoding; + const libwps::WPSConfidence confidence = libwps::WPSDocument::isFileFormatSupported(&rInput, kind, creator, needEncoding); + + std::string fileEncoding(""); + try + { + if ((kind == libwps::WPS_TEXT) && (confidence == libwps::WPS_CONFIDENCE_EXCELLENT) && needEncoding) + { + OUString title("Import MsWorks files(libwps)"); + OUString encoding("CP850"); + const ScopedVclPtrInstance<writerperfect::WPFTEncodingDialog> pDlg(nullptr, &title, &encoding); + if (pDlg->Execute() == RET_OK) + { + if (!pDlg->GetEncoding().isEmpty()) + fileEncoding=pDlg->GetEncoding().toUtf8().getStr(); + } + // we can fail because we are in headless mode, the user has cancelled conversion, ... + else if (pDlg->hasUserCalledCancel()) + return false; + } + } + catch (...) + { + } + return libwps::WPS_OK == libwps::WPSDocument::parse(&rInput, &rGenerator, "", fileEncoding.c_str()); } bool MSWorksImportFilter::doDetectFormat(librevenge::RVNGInputStream &rInput, OUString &rTypeName) { libwps::WPSKind kind = libwps::WPS_TEXT; - const libwps::WPSConfidence confidence = libwps::WPSDocument::isFileFormatSupported(&rInput, kind); + libwps::WPSCreator creator; + bool needEncoding; + const libwps::WPSConfidence confidence = libwps::WPSDocument::isFileFormatSupported(&rInput, kind, creator, needEncoding); if ((kind == libwps::WPS_TEXT) && (confidence == libwps::WPS_CONFIDENCE_EXCELLENT)) { diff --git a/writerperfect/uiconfig/ui/wpftencodingdialog.ui b/writerperfect/uiconfig/ui/wpftencodingdialog.ui new file mode 100644 index 000000000000..bf00869466d7 --- /dev/null +++ b/writerperfect/uiconfig/ui/wpftencodingdialog.ui @@ -0,0 +1,88 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Generated with glade 3.18.3 --> +<interface> + <requires lib="gtk+" version="3.12"/> + <object class="GtkDialog" id="WPFTEncodingDialog"> + <property name="can_focus">False</property> + <property name="modal">True</property> + <property name="default_height">-1</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">2</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="ok"> + <property name="label">gtk-ok</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="has_default">True</property> + <property name="receives_default">True</property> + <property name="use_stock">True</property> + <property name="yalign">0.62000000476837158</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkButton" id="cancel"> + <property name="label">gtk-undo</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">True</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">2</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Character set:</property> + <attributes> + <attribute name="weight" value="semibold"/> + </attributes> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkComboBoxText" id="comboboxtext"> + <property name="can_focus">False</property> + </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">ok</action-widget> + <action-widget response="0">cancel</action-widget> + </action-widgets> + </object> +</interface> |