diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -40,7 +40,6 @@ kjotslinkdialog.cpp localresourcecreator.cpp kjotsbookshelfentryvalidator.cpp - knowitimporter.cpp ${kjots_config_SRCS} ) diff --git a/src/kjotswidget.h b/src/kjotswidget.h --- a/src/kjotswidget.h +++ b/src/kjotswidget.h @@ -119,8 +119,6 @@ void selectNext(int role, int step); int search(bool); - void migrateNoteData(const QString &migrator, const QString &type = QString()); - protected Q_SLOTS: void renderSelection(); void changeTheme(); diff --git a/src/kjotswidget.cpp b/src/kjotswidget.cpp --- a/src/kjotswidget.cpp +++ b/src/kjotswidget.cpp @@ -116,10 +116,10 @@ { Akonadi::ControlGui::widgetNeedsAkonadi(this); - KConfigGroup migrationCfg(KSharedConfig::openConfig(), "General"); - const bool autoCreate = migrationCfg.readEntry("AutoCreateResourceOnStart", true); - migrationCfg.writeEntry("AutoCreateResourceOnStart", autoCreate); - migrationCfg.sync(); + KConfigGroup config(KSharedConfig::openConfig(), "General"); + const bool autoCreate = config.readEntry("AutoCreateResourceOnStart", true); + config.writeEntry("AutoCreateResourceOnStart", autoCreate); + config.sync(); if (autoCreate) { LocalResourceCreator *creator = new LocalResourceCreator(this); creator->createIfMissing(); @@ -444,10 +444,6 @@ void KJotsWidget::delayedInitialization() { - migrateNoteData(QLatin1String("kjotsmigrator")); - // Disable nigration of data from KNotes as that app still exists in 4.5. -// migrateNoteData( "kres-migrator", "notes" ); - //TODO: Save previous searches in settings file? searchDialog = new KFindDialog(this, 0, QStringList(), false); QGridLayout *layout = new QGridLayout(searchDialog->findExtension()); @@ -559,46 +555,6 @@ } } -void KJotsWidget::migrateNoteData(const QString &migrator, const QString &type) -{ - // Akonadi migration - KConfig config(migrator + QLatin1String("rc")); - KConfigGroup migrationCfg(&config, "Migration"); - const bool enabled = migrationCfg.readEntry("Enabled", true); - const bool completed = migrationCfg.readEntry("Completed", false); - const int currentVersion = migrationCfg.readEntry("Version", 0); - const int targetVersion = migrationCfg.readEntry("TargetVersion", 1); - if (enabled && !completed && currentVersion < targetVersion) { - qDebug() << "Performing Akonadi migration. Good luck!"; - KProcess proc; - QStringList args = QStringList() << QLatin1String("--interactive-on-change"); - if (!type.isEmpty()) { - args << QLatin1String("--type") << type; - } - - const QString path = QStandardPaths::findExecutable(migrator); - proc.setProgram(path, args); - proc.start(); - bool result = proc.waitForStarted(); - if (result) { - result = proc.waitForFinished(); - } - if (result && proc.exitCode() == 0) { - qDebug() << "Akonadi migration has been successful"; - } else { - // exit code 1 means it is already running, so we are probably called by a migrator instance - qCritical() << "Akonadi migration failed!"; - qCritical() << "command was: " << proc.program(); - qCritical() << "exit code: " << proc.exitCode(); - qCritical() << "stdout: " << proc.readAllStandardOutput(); - qCritical() << "stderr: " << proc.readAllStandardError(); - } - migrationCfg.writeEntry("Version", targetVersion); - migrationCfg.writeEntry("Completed", true); - migrationCfg.sync(); - } -} - inline QTextEdit *KJotsWidget::activeEditor() { if (browser->isVisible()) { diff --git a/src/knowitimporter.h b/src/knowitimporter.h deleted file mode 100644 --- a/src/knowitimporter.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * This file is part of KJots - * - * Copyright 2008 Stephen Kelly - * - * 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 library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -#ifndef KNOWITIMPORTER_H -#define KNOWITIMPORTER_H - -class QDomElement; -class QUrl; - -#include -#include - - -struct KnowItNote { - QString title; - int depth; - QString content; - int id; // Only used to determine parent /child relationships. This is not the KJots Page or Book id. - int parent; - - QList< QPair< QString, QString > > links; - -}; - -/** -Class for importing KNowIt notes. KNowIt is not longer maintained. -@since 4.2 -*/ -class KnowItImporter -{ -public: - KnowItImporter(); - - /** - Create a KJotsBook from the knowit file at @p url. - */ - void importFromUrl(const QUrl &url); - -private: - /** - Builds several trees with roots at m_notes. - @param url The url of the knowit file. - */ - void buildNoteTree(const QUrl &url); - - /** - Add a representation of note @p n to m_domDoc. If @p n has child notes, it will create a book, otherwise a page. - */ - QDomElement addNote(const KnowItNote &n); - - /** - Build a domDocument from the notes rooted at m_notes. - */ - void buildDomDocument(); - - QList m_notes; // Top level notes. - QList m_lastNoteAtLevel; - QDomDocument m_domDoc; - QHash m_noteHash; - QHash > m_childNotes; -}; - -#endif diff --git a/src/knowitimporter.cpp b/src/knowitimporter.cpp deleted file mode 100644 --- a/src/knowitimporter.cpp +++ /dev/null @@ -1,256 +0,0 @@ -/* - * This file is part of KJots - * - * Copyright 2008 Stephen Kelly - * - * 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 library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -#include "knowitimporter.h" - -#include -#include -#include -#include -#include - -#include - -#include - -KnowItImporter::KnowItImporter() -{ -} - -void KnowItImporter::importFromUrl(const QUrl &url) -{ -// TODO PORT -#if 0 - KJotsBook *book = new KJotsBook(); - buildNoteTree(url); - -// foreach () -// qDebug(); - buildDomDocument(); - - QTemporaryFile file; -//code was file.setPrefix( QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + "kjots/" ) ; -//Add to constructor and adapt if necessay: QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + "kjots/" QLatin1String("/myapp_XXXXXX.txt") -//code was file.setSuffix( ".book" ); -//Add to constructor and adapt if necessay: QDir::tempPath() + QLatin1String("/myapp_XXXXXX") + QLatin1String( ".book" ) - file.setAutoRemove(false); - - if (file.open()) { - file.write("\n\n\n"); - file.write(m_domDoc.toByteArray()); - file.write("\n"); - qDebug() << file.fileName(); - QString newFileName = file.fileName(); - file.close(); - book->openBook(newFileName); - } - - return book; -#endif -} - -QDomElement KnowItImporter::addNote(const KnowItNote ¬e) -{ - QDomElement newElement; - int childNotesCount = m_childNotes[ note.id ].size(); -// int childNotesCount = note.childNotes.size(); - qDebug() << note.title << childNotesCount; - if (childNotesCount > 0) { - newElement = m_domDoc.createElement(QLatin1String("KJotsBook")); - - } else { - newElement = m_domDoc.createElement(QLatin1String("KJotsPage")); - } - - QDomElement titleTag = m_domDoc.createElement(QLatin1String("Title")); - titleTag.appendChild(m_domDoc.createTextNode(note.title)); - newElement.appendChild(titleTag); - QDomElement idTag = m_domDoc.createElement(QLatin1String("ID")); - idTag.appendChild(m_domDoc.createTextNode(QLatin1String("0"))); // Gets a valid id later. - newElement.appendChild(idTag); - - if (childNotesCount > 0) { - QDomElement openTag = m_domDoc.createElement(QLatin1String("Open")); - openTag.appendChild(m_domDoc.createTextNode(QLatin1String("1"))); - newElement.appendChild(openTag); - - QDomElement titlePage = m_domDoc.createElement(QLatin1String("KJotsPage")); - QDomElement titlePageTitleTag = m_domDoc.createElement(QLatin1String("Title")); - titlePageTitleTag.appendChild(m_domDoc.createTextNode(note.title)); - titlePage.appendChild(titlePageTitleTag); - QDomElement titlePageIdTag = m_domDoc.createElement(QLatin1String("ID")); - titlePageIdTag.appendChild(m_domDoc.createTextNode(QLatin1String("0"))); // Gets a valid id later. - titlePage.appendChild(titlePageIdTag); - QDomElement titlePageTextTag = m_domDoc.createElement(QLatin1String("Text")); - titlePageTextTag.appendChild(m_domDoc.createCDATASection(note.content)); - titlePage.appendChild(titlePageTextTag); - newElement.appendChild(titlePage); - - const QList ids = m_childNotes[ note.id ]; - for (int id : ids) { - QDomElement e = addNote(m_noteHash.value(id)); - newElement.appendChild(e); - } - } else { - QString contents = note.content; - if (note.links.size() > 0) { - if (contents.endsWith(QLatin1String(""))) { - contents.chop(14); - } - contents.append(QLatin1String("

Links:

\n
    \n")); - for (int i = 0; i < note.links.size(); ++i) { - qDebug() << "link" << note.links[i].first << note.links[i].second; - contents.append(QString::fromLatin1("
  • %2
  • \n") - .arg(note.links[i].first) - .arg(note.links[i].second)); - } - contents.append(QLatin1String("
")); - } - - QDomElement textTag = m_domDoc.createElement(QLatin1String("Text")); - textTag.appendChild(m_domDoc.createCDATASection(contents)); - newElement.appendChild(textTag); - } - - return newElement; - -} - -void KnowItImporter::buildDomDocument() -{ - QDomElement parent = m_domDoc.createElement(QLatin1String("KJotsBook")); - QDomElement titleTag = m_domDoc.createElement(QLatin1String("Title")); - titleTag.appendChild(m_domDoc.createTextNode(i18nc("Name for the top level book created to hold the imported data.", "KNowIt Import"))); - parent.appendChild(titleTag); - QDomElement idTag = m_domDoc.createElement(QLatin1String("ID")); - idTag.appendChild(m_domDoc.createTextNode(QLatin1String("0"))); // Gets a valid id later. - parent.appendChild(idTag); - QDomElement openTag = m_domDoc.createElement(QLatin1String("Open")); - openTag.appendChild(m_domDoc.createTextNode(QLatin1String("1"))); - parent.appendChild(openTag); - m_domDoc.appendChild(parent); - - for (const KnowItNote &n : qAsConst(m_notes)) { - QDomElement e = addNote(n); - parent.appendChild(e); - qDebug() << n.title; - } - qDebug() << m_domDoc.toString(); -} - -void KnowItImporter::buildNoteTree(const QUrl &url) -{ - - QFile knowItFile(url.toLocalFile()); - if (knowItFile.open(QIODevice::ReadOnly | QIODevice::Text)) { - QSet entryHeaders; - entryHeaders << "\\NewEntry" << "\\CurrentEntry"; - - int id = 1; - - QTextStream in(&knowItFile); - while (!in.atEnd()) { - QString line = in.readLine(); - - qDebug() << "got line: " << line; - - if (line.trimmed().isEmpty()) { - continue; - } - - for (const QByteArray &header : qAsConst(entryHeaders)) { - if (line.startsWith(QLatin1String(header))) { - qDebug() << "init" << line << header; - line = line.right(line.size() - header.size()).trimmed(); - qDebug() << "header tag removed: " << line; - - QStringList list = line.split(QLatin1Char(' ')); - int startOfTitle = line.indexOf(QLatin1Char(' ')); - bool ok = false; - - qDebug() << "depth" << list.at(0).trimmed(); - - int depth = list.at(0).trimmed().toInt(&ok); - qDebug() << ok << "valid depth"; - if (ok) { - QString title = line.right(line.size() - startOfTitle).trimmed(); - KnowItNote n; - n.title = title; - n.depth = depth; - n.id = id; - if (depth == 0) { - n.parent = 0; - } else { - n.parent = m_lastNoteAtLevel[depth - 1].id; - } - - QString contentLine = in.readLine(); - //QList< QPair > links; - QString contents; - QString url; - QString target; - while ((!in.atEnd()) && (!contentLine.trimmed().isEmpty())) { - qDebug() << contentLine; - if (contentLine.startsWith(QLatin1String("\\Link"))) { - url = contentLine.right(contentLine.size() - 5).trimmed(); - contentLine = in.readLine(); - continue; - } - if (contentLine.startsWith(QLatin1String("\\Descr"))) { - target = contentLine.right(contentLine.size() - 6).trimmed(); - contentLine = in.readLine(); - continue; - } - if (!url.isEmpty() && !target.isEmpty()) { - QPair< QString, QString > link; - link.first = url; - link.second = target; - n.links << link; - url.clear(); - target.clear(); - } - contents.append(contentLine); - contentLine = in.readLine(); - } - - n.content = contents; - - m_noteHash.insert(id, n); - m_childNotes[n.parent].append(id); - id++; - - if (m_lastNoteAtLevel.size() == depth) { - m_lastNoteAtLevel.append(n); - } else { - m_lastNoteAtLevel[depth] = n; - } - - if (depth == 0) { - m_notes.append(n); - } - } - break; // If found first header, don't check for second one. - } - } // Foreach header. - } // At end of stream - } // File open. -} - diff --git a/src/main.cpp b/src/main.cpp --- a/src/main.cpp +++ b/src/main.cpp @@ -54,25 +54,6 @@ exit(0); } - // backwards compatibility code to convert "old" user font settings - // to the new config settings - KConfigGroup config(KSharedConfig::openConfig(), "kjots"); - if (config.hasKey("EFontFamily")) { - // read old font and create it - QFont font(config.readEntry("EFontFamily"), - config.readEntry("EFontSize", 12), - config.readEntry("EFontWeight", 0), - config.readEntry("EFontItalic", 0)); - // delete old entries - config.deleteEntry("EFontFamily"); - config.deleteEntry("EFontSize"); - config.deleteEntry("EFontWeight"); - config.deleteEntry("EFontItalic"); - config.deleteEntry("EFontCharset"); - // write new "converted" entry - config.writeEntry("Font", font); - } - KJotsMain *jots = new KJotsMain; if (app.isSessionRestored()) { if (KJotsMain::canBeRestored(1)) {