• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

knotes

  • sources
  • kde-4.14
  • kdepim
  • knotes
  • utils
knoteutils.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2013-2015 Montel Laurent <montel@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License, version 2, as
6  published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful, but
9  WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "knoteutils.h"
19 #include "noteshared/attributes/notedisplayattribute.h"
20 #include "knotesglobalconfig.h"
21 
22 #include <KStandardDirs>
23 #include <KMessageBox>
24 #include <KLocalizedString>
25 #include <KProcess>
26 #include <KDebug>
27 #include <KConfigGroup>
28 #include <QDBusInterface>
29 #include <QFileInfo>
30 
31 void KNoteUtils::updateConfiguration()
32 {
33  QDBusInterface interface( QLatin1String("org.freedesktop.Akonadi.Agent.akonadi_notes_agent"), QLatin1String("/NotesAgent") );
34  if (interface.isValid()) {
35  interface.call(QLatin1String("configurationChanged"));
36  } else {
37  qDebug()<<" Agent not launched";
38  }
39 }
40 
41 void KNoteUtils::setDefaultValue(Akonadi::Item &item)
42 {
43  NoteShared::NoteDisplayAttribute *attribute = item.attribute<NoteShared::NoteDisplayAttribute>(Akonadi::Entity::AddIfMissing);
44  attribute->setBackgroundColor(KNotesGlobalConfig::self()->bgColor());
45  attribute->setForegroundColor(KNotesGlobalConfig::self()->fgColor());
46  attribute->setSize(QSize(KNotesGlobalConfig::self()->width(), KNotesGlobalConfig::self()->height()));
47  attribute->setRememberDesktop(KNotesGlobalConfig::self()->rememberDesktop());
48  attribute->setTabSize(KNotesGlobalConfig::self()->tabSize());
49  attribute->setFont(KNotesGlobalConfig::self()->font());
50  attribute->setTitleFont(KNotesGlobalConfig::self()->titleFont());
51  attribute->setDesktop(KNotesGlobalConfig::self()->desktop());
52  attribute->setIsHidden(KNotesGlobalConfig::self()->hideNote());
53  attribute->setPosition(KNotesGlobalConfig::self()->position());
54  attribute->setShowInTaskbar(KNotesGlobalConfig::self()->showInTaskbar());
55  attribute->setKeepAbove(KNotesGlobalConfig::self()->keepAbove());
56  attribute->setKeepBelow(KNotesGlobalConfig::self()->keepBelow());
57  attribute->setAutoIndent(KNotesGlobalConfig::self()->autoIndent());
58 }
59 
60 void KNoteUtils::migrateToAkonadi()
61 {
62  bool needMigration = true;
63 
64  const QFileInfo oldDataDirFileInfo( KStandardDirs::locateLocal( "data", QLatin1String("knotes") ) );
65  if ( !oldDataDirFileInfo.exists() || !oldDataDirFileInfo.isDir() ) {
66  // neither config or data, the migrator cannot do anything useful anyways
67  needMigration = false;
68  }
69 
70  KConfig config( QLatin1String("knotes-migratorrc") );
71  KConfigGroup migrationCfg( &config, "Migration" );
72  if ( needMigration ) {
73  const bool enabled = migrationCfg.readEntry( "Enabled", true );
74  const int currentVersion = migrationCfg.readEntry( "Version", 0 );
75  const int targetVersion = migrationCfg.readEntry( "TargetVersion", 2 );
76  if ( enabled && currentVersion < targetVersion ) {
77  const int choice = KMessageBox::questionYesNoCancel( 0, i18n(
78  "<b>Thanks for using KNotes!</b>"
79  "<p>KNotes uses a new storage technology that requires migration of your current KNotes data and configuration.</p>\n"
80  "<p>The conversion process can take a lot of time (depending on the amount of notes you have) and it <em>must not be interrupted</em>.</p>\n"
81  "<p>You can:</p><ul>"
82  "<li>Migrate now (be prepared to wait)</li>"
83  "<li>Skip the migration and start with fresh data and configuration</li>"
84  "<li>Cancel and exit KNotes.</li>"
85  "</ul>"
86  "<p><a href=\"http://userbase.kde.org/Akonadi\">More Information...</a></p>"
87  ), i18n( "KNotes Migration" ), KGuiItem(i18n( "Migrate Now" )), KGuiItem(i18n( "Skip Migration" )), KStandardGuiItem::cancel(),
88  QString(), KMessageBox::Notify | KMessageBox::Dangerous | KMessageBox::AllowLink );
89  if ( choice == KMessageBox::Cancel )
90  exit( 1 );
91 
92  if ( choice != KMessageBox::Yes ) { // user skipped migration
93  // we only will make one attempt at this
94  migrationCfg.writeEntry( "Version", targetVersion );
95  migrationCfg.sync();
96 
97  return;
98  }
99 
100  kDebug() << "Performing Akonadi migration. Good luck!";
101  KProcess proc;
102  QStringList args = QStringList() << QLatin1String("--interactive-on-change");
103  const QString path = KStandardDirs::findExe( QLatin1String("knotes-migrator" ) );
104  proc.setProgram( path, args );
105  proc.start();
106  bool result = proc.waitForStarted();
107  if ( result ) {
108  result = proc.waitForFinished( -1 );
109  }
110  if ( result && proc.exitCode() == 0 ) {
111  kDebug() << "Akonadi migration has been successful";
112  } else {
113  // exit code 1 means it is already running, so we are probably called by a migrator instance
114  kError() << "Akonadi migration failed!";
115  kError() << "command was: " << proc.program();
116  kError() << "exit code: " << proc.exitCode();
117  kError() << "stdout: " << proc.readAllStandardOutput();
118  kError() << "stderr: " << proc.readAllStandardError();
119 
120  KMessageBox::error( 0, i18n("Migration to KNotes failed. In case you want to try again, run 'knotes-migrator --interactive' manually."),
121  i18n( "Migration Failed" ) );
122  return;
123  }
124  migrationCfg.writeEntry( "Version", targetVersion );
125  migrationCfg.sync();
126  }
127  } else {
128  if (migrationCfg.hasKey("Enabled") && (migrationCfg.readEntry("Enabled", false) == false)) {
129  return;
130  }
131  migrationCfg.writeEntry( "Enabled", false );
132  migrationCfg.sync();
133  }
134 }
QDBusAbstractInterface::isValid
bool isValid() const
QDBusAbstractInterface::call
QDBusMessage call(const QString &method, const QVariant &arg1, const QVariant &arg2, const QVariant &arg3, const QVariant &arg4, const QVariant &arg5, const QVariant &arg6, const QVariant &arg7, const QVariant &arg8)
QFileInfo::isDir
bool isDir() const
knoteutils.h
QString
QStringList
QDBusInterface
KNoteUtils::migrateToAkonadi
KNOTES_EXPORT void migrateToAkonadi()
Definition: knoteutils.cpp:60
QFileInfo
QFileInfo::exists
bool exists() const
QSize
KNoteUtils::setDefaultValue
KNOTES_EXPORT void setDefaultValue(Akonadi::Item &item)
Definition: knoteutils.cpp:41
QLatin1String
KNoteUtils::updateConfiguration
KNOTES_EXPORT void updateConfiguration()
Definition: knoteutils.cpp:31
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:28 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

knotes

Skip menu "knotes"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal