diff --git a/src/pimcommon/autocorrection/import/importlibreofficeautocorrection.cpp b/src/pimcommon/autocorrection/import/importlibreofficeautocorrection.cpp index 4d7b912..08a5728 100644 --- a/src/pimcommon/autocorrection/import/importlibreofficeautocorrection.cpp +++ b/src/pimcommon/autocorrection/import/importlibreofficeautocorrection.cpp @@ -1,160 +1,159 @@ /* Copyright (c) 2012-2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "importlibreofficeautocorrection.h" #include #include #include #include #include #include "pimcommon_debug.h" #include -#include using namespace PimCommon; ImportLibreOfficeAutocorrection::ImportLibreOfficeAutocorrection(QWidget *parent) : ImportAbstractAutocorrection(parent) { } ImportLibreOfficeAutocorrection::~ImportLibreOfficeAutocorrection() { closeArchive(); } void ImportLibreOfficeAutocorrection::closeArchive() { if (mArchive) { if (mArchive->isOpen()) { mArchive->close(); } delete mArchive; mArchive = nullptr; } delete mTempDir; mTempDir = nullptr; } bool ImportLibreOfficeAutocorrection::import(const QString &fileName, LoadAttribute loadAttribute) { //We Don't have it in LibreOffice if (loadAttribute == SuperScript) { return false; } closeArchive(); mArchive = new KZip(fileName); const bool result = mArchive->open(QIODevice::ReadOnly); if (result) { importAutoCorrectionFile(); return true; } else { KMessageBox::error(mParent, i18n("Archive cannot be opened in read mode."), i18n("Import LibreOffice Autocorrection File")); return false; } } void ImportLibreOfficeAutocorrection::importAutoCorrectionFile() { mTempDir = new QTemporaryDir(); const KArchiveDirectory *archiveDirectory = mArchive->directory(); //Replace word importFile(DOCUMENT, archiveDirectory); //No tread as end of line importFile(SENTENCE, archiveDirectory); //Two upper letter importFile(WORD, archiveDirectory); } bool ImportLibreOfficeAutocorrection::importFile(Type type, const KArchiveDirectory *archiveDirectory) { const KArchiveEntry *documentList = nullptr; QString archiveFileName; switch (type) { case DOCUMENT: archiveFileName = QStringLiteral("DocumentList.xml"); break; case SENTENCE: archiveFileName = QStringLiteral("SentenceExceptList.xml"); break; case WORD: archiveFileName = QStringLiteral("WordExceptList.xml"); break; default: return false; } documentList = archiveDirectory->entry(archiveFileName); if (documentList && documentList->isFile()) { const KArchiveFile *archiveFile = static_cast(documentList); archiveFile->copyTo(mTempDir->path()); QFile file(mTempDir->path() + QLatin1Char('/') + archiveFileName); QDomDocument doc; if (loadDomElement(doc, &file)) { QDomElement list = doc.documentElement(); if (list.isNull()) { qCDebug(PIMCOMMON_LOG) << "No list defined in " << type; } else { for (QDomElement e = list.firstChildElement(); !e.isNull(); e = e.nextSiblingElement()) { const QString tag = e.tagName(); if (tag == QLatin1String("block-list:block")) { switch (type) { case DOCUMENT: if (e.hasAttribute(QStringLiteral("block-list:abbreviated-name")) && e.hasAttribute(QStringLiteral("block-list:name"))) { mAutocorrectEntries.insert(e.attribute(QStringLiteral("block-list:abbreviated-name")), e.attribute(QStringLiteral("block-list:name"))); } break; case SENTENCE: if (e.hasAttribute(QStringLiteral("block-list:abbreviated-name"))) { mTwoUpperLetterExceptions.insert(e.attribute(QStringLiteral("block-list:abbreviated-name"))); } break; case WORD: if (e.hasAttribute(QStringLiteral("block-list:abbreviated-name"))) { mUpperCaseExceptions.insert(e.attribute(QStringLiteral("block-list:abbreviated-name"))); } break; } } else { qCDebug(PIMCOMMON_LOG) << " unknown tag " << tag; } } } } } else { return false; } return true; } bool ImportLibreOfficeAutocorrection::loadDomElement(QDomDocument &doc, QFile *file) { QString errorMsg; int errorRow; int errorCol; if (!doc.setContent(file, &errorMsg, &errorRow, &errorCol)) { qCDebug(PIMCOMMON_LOG) << "Unable to load document.Parse error in line " << errorRow << ", col " << errorCol << ": " << errorMsg; return false; } return true; } diff --git a/src/pimcommon/migration/migrateapplicationfiles.h b/src/pimcommon/migration/migrateapplicationfiles.h index 9ffcd1c..bbc24f7 100644 --- a/src/pimcommon/migration/migrateapplicationfiles.h +++ b/src/pimcommon/migration/migrateapplicationfiles.h @@ -1,68 +1,67 @@ /* Copyright (c) 2015-2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef MIGRATEAPPLICATIONFILE_H #define MIGRATEAPPLICATIONFILE_H #include -#include #include "migratefileinfo.h" #include "pimcommon_export.h" namespace PimCommon { class MigrateApplicationFilesPrivate; /** * @brief The MigrateApplicationFiles class * @author Laurent Montel */ class PIMCOMMON_EXPORT MigrateApplicationFiles : public QObject { Q_OBJECT public: explicit MigrateApplicationFiles(QObject *parent = nullptr); ~MigrateApplicationFiles(); Q_REQUIRED_RESULT bool start(); Q_REQUIRED_RESULT bool checkIfNecessary(); void insertMigrateInfo(const MigrateFileInfo &info); Q_REQUIRED_RESULT int version() const; void setVersion(int version); Q_REQUIRED_RESULT QString configFileName() const; void setConfigFileName(const QString &configFileName); Q_REQUIRED_RESULT int currentConfigVersion() const; void setCurrentConfigVersion(int currentConfigVersion); Q_REQUIRED_RESULT QString applicationName() const; void setApplicationName(const QString &applicationName); Q_SIGNALS: void migrateDone(); private: bool copyRecursively(const QString &srcFilePath, const QString &tgtFilePath); void finished(); void writeConfig(); void migrateFolder(const MigrateFileInfo &info); void migrateFile(const MigrateFileInfo &info); bool migrateConfig(); MigrateApplicationFilesPrivate *const d; }; } #endif // MIGRATEAPPLICATIONFILE_H diff --git a/src/pimcommon/widgets/spellchecklineedit.cpp b/src/pimcommon/widgets/spellchecklineedit.cpp index ae987da..49388ff 100644 --- a/src/pimcommon/widgets/spellchecklineedit.cpp +++ b/src/pimcommon/widgets/spellchecklineedit.cpp @@ -1,138 +1,137 @@ /* * Copyright (c) 2011-2020 Laurent Montel * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * In addition, as a special exception, the copyright holders give * permission to link the code of this program with any edition of * the Qt library by Trolltech AS, Norway (or with modified versions * of Qt that use the same license as Qt), and distribute linked * combinations including the two. You must obey the GNU General * Public License in all respects for all of the code used other than * Qt. If you modify this file, you may extend this exception to * your version of the file, but you are not obligated to do so. If * you do not wish to do so, delete this exception statement from * your version. */ #include "spellchecklineedit.h" #include #include #include -#include #include using namespace PimCommon; SpellCheckLineEdit::SpellCheckLineEdit(QWidget *parent, const QString &configFile) : KPIMTextEdit::RichTextEditor(parent) { setSpellCheckingConfigFileName(configFile); setSearchSupport(false); setAllowTabSupport(false); setAcceptRichText(false); setTabChangesFocus(true); // widget may not be resized vertically setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed)); setLineWrapMode(NoWrap); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setCheckSpellingEnabled(true); document()->adjustSize(); document()->setDocumentMargin(2); } SpellCheckLineEdit::~SpellCheckLineEdit() { } void SpellCheckLineEdit::keyPressEvent(QKeyEvent *e) { if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return || e->key() == Qt::Key_Down) { Q_EMIT focusDown(); return; } else if (e->key() == Qt::Key_Up) { Q_EMIT focusUp(); return; } RichTextEditor::keyPressEvent(e); } QSize SpellCheckLineEdit::sizeHint() const { QFontMetrics fm(font()); const int h = document()->size().toSize().height() - fm.descent() + 2 * frameWidth(); QStyleOptionFrame opt; opt.initFrom(this); opt.rect = QRect(0, 0, 100, h); opt.lineWidth = lineWidth(); opt.midLineWidth = 0; opt.state |= QStyle::State_Sunken; QSize s = style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(100, h), this); return s; } QSize SpellCheckLineEdit::minimumSizeHint() const { return sizeHint(); } void SpellCheckLineEdit::insertFromMimeData(const QMimeData *source) { if (!source) { return; } setFocus(); // Copy text from the clipboard (paste) QString pasteText = source->text(); // is there any text in the clipboard? if (!pasteText.isEmpty()) { // replace \r with \n to make xterm pastes happy pasteText.replace(QLatin1Char('\r'), QLatin1Char('\n')); // remove blank lines while (pasteText.contains(QLatin1String("\n\n"))) { pasteText.replace(QLatin1String("\n\n"), QLatin1String("\n")); } QRegExp reTopSpace(QStringLiteral("^ *\n")); while (pasteText.contains(reTopSpace)) { pasteText.remove(reTopSpace); } QRegExp reBottomSpace(QStringLiteral("\n *$")); while (pasteText.contains(reBottomSpace)) { pasteText.remove(reBottomSpace); } // does the text contain at least one newline character? pasteText.replace(QLatin1Char('\n'), QLatin1Char(' ')); insertPlainText(pasteText); ensureCursorVisible(); return; } else { RichTextEditor::insertFromMimeData(source); } }