Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/main.cpp
Show All 20 Lines | |||||
21 | // ---------------------------------------------------------------------------- | 21 | // ---------------------------------------------------------------------------- | ||
22 | // QT Includes | 22 | // QT Includes | ||
23 | 23 | | |||
24 | #include <QWidget> | 24 | #include <QWidget> | ||
25 | #include <QStringList> | 25 | #include <QStringList> | ||
26 | #include <QApplication> | 26 | #include <QApplication> | ||
27 | #include <QCommandLineParser> | 27 | #include <QCommandLineParser> | ||
28 | #include <QSplashScreen> | 28 | #include <QSplashScreen> | ||
29 | #include <QStandardPaths> | ||||
29 | #ifdef KMM_DBUS | 30 | #ifdef KMM_DBUS | ||
30 | #include <QDBusConnection> | 31 | #include <QDBusConnection> | ||
31 | #include <QDBusConnectionInterface> | 32 | #include <QDBusConnectionInterface> | ||
32 | #include <QDBusInterface> | 33 | #include <QDBusInterface> | ||
33 | #endif | 34 | #endif | ||
34 | // ---------------------------------------------------------------------------- | 35 | // ---------------------------------------------------------------------------- | ||
35 | // KDE Includes | 36 | // KDE Includes | ||
36 | 37 | | |||
37 | #include <KTipDialog> | 38 | #include <KTipDialog> | ||
38 | #include <KLocalizedString> | 39 | #include <KLocalizedString> | ||
39 | #include <KMessageBox> | 40 | #include <KMessageBox> | ||
40 | #include <Kdelibs4ConfigMigrator> | 41 | #include <Kdelibs4ConfigMigrator> | ||
42 | #include <KConfig> | ||||
43 | #include <KSharedConfig> | ||||
41 | 44 | | |||
42 | // ---------------------------------------------------------------------------- | 45 | // ---------------------------------------------------------------------------- | ||
43 | // Project Includes | 46 | // Project Includes | ||
44 | 47 | | |||
45 | #include "mymoney/mymoneyfile.h" | 48 | #include "mymoney/mymoneyfile.h" | ||
46 | #include "kmymoney.h" | 49 | #include "kmymoney.h" | ||
47 | #include "kstartuplogo.h" | 50 | #include "kstartuplogo.h" | ||
48 | #include "kcreditswindow.h" | 51 | #include "kcreditswindow.h" | ||
49 | #include "kmymoneyutils.h" | 52 | #include "kmymoneyutils.h" | ||
50 | #include "kmymoneyglobalsettings.h" | 53 | #include "kmymoneyglobalsettings.h" | ||
51 | #include "misc/webconnect.h" | 54 | #include "misc/webconnect.h" | ||
52 | 55 | | |||
53 | #ifdef KMM_DEBUG | 56 | #ifdef KMM_DEBUG | ||
54 | #include "mymoneyutils.h" | 57 | #include "mymoneyutils.h" | ||
55 | #include "mymoneytracer.h" | 58 | #include "mymoneytracer.h" | ||
56 | #endif | 59 | #endif | ||
57 | 60 | | |||
58 | bool timersOn = false; | 61 | bool timersOn = false; | ||
59 | 62 | | |||
60 | KMyMoneyApp* kmymoney; | 63 | KMyMoneyApp* kmymoney; | ||
61 | 64 | | |||
62 | static int runKMyMoney(QApplication *a, std::unique_ptr<QSplashScreen> splash, const QUrl & file, bool noFile); | 65 | static int runKMyMoney(QApplication *a, std::unique_ptr<QSplashScreen> splash, const QUrl & file, bool noFile); | ||
66 | static void migrateConfigFiles(); | ||||
63 | 67 | | |||
64 | int main(int argc, char *argv[]) | 68 | int main(int argc, char *argv[]) | ||
65 | { | 69 | { | ||
66 | { | | |||
67 | // Copy KDE 4 config files to the KF5 location | | |||
68 | Kdelibs4ConfigMigrator migrator(QStringLiteral("kmymoney")); | | |||
69 | migrator.setConfigFiles(QStringList{"kmymoneyrc"}); | | |||
70 | migrator.setUiFiles(QStringList{"kmymoneyui.rc"}); | | |||
71 | migrator.migrate(); | | |||
72 | } | | |||
73 | | ||||
74 | /** | 70 | /** | ||
75 | * Create application first | 71 | * Create application first | ||
76 | */ | 72 | */ | ||
77 | QApplication app(argc, argv); | 73 | QApplication app(argc, argv); | ||
78 | KLocalizedString::setApplicationDomain("kmymoney"); | 74 | KLocalizedString::setApplicationDomain("kmymoney"); | ||
79 | 75 | | |||
76 | migrateConfigFiles(); | ||||
80 | 77 | | |||
81 | /** | 78 | /** | ||
82 | * construct and register about data | 79 | * construct and register about data | ||
83 | */ | 80 | */ | ||
84 | KAboutData aboutData(QStringLiteral("kmymoney"), i18n("KMyMoney"), QStringLiteral(VERSION)); | 81 | KAboutData aboutData(QStringLiteral("kmymoney"), i18n("KMyMoney"), QStringLiteral(VERSION)); | ||
85 | aboutData.setOrganizationDomain("kde.org"); | 82 | aboutData.setOrganizationDomain("kde.org"); | ||
86 | KAboutData::setApplicationData(aboutData); | 83 | KAboutData::setApplicationData(aboutData); | ||
87 | 84 | | |||
▲ Show 20 Lines • Show All 226 Lines • ▼ Show 20 Line(s) | 247 | { | |||
314 | kmymoney->updateCaption(); | 311 | kmymoney->updateCaption(); | ||
315 | kmymoney->centralWidget()->setEnabled(true); | 312 | kmymoney->centralWidget()->setEnabled(true); | ||
316 | kmymoney->show(); | 313 | kmymoney->show(); | ||
317 | splash.reset(); | 314 | splash.reset(); | ||
318 | 315 | | |||
319 | const int rc = a->exec(); | 316 | const int rc = a->exec(); | ||
320 | return rc; | 317 | return rc; | ||
321 | } | 318 | } | ||
319 | | ||||
320 | static void migrateConfigFiles() | ||||
321 | { | ||||
322 | const QString sMainConfigName(QStringLiteral("kmymoneyrc")); | ||||
323 | const QString sMainConfigSubdirectory(QStringLiteral("kmymoney/")); // all KMM config files should be in ~/.config/kmymoney/ | ||||
324 | const QString sMainConfigPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + | ||||
325 | QLatin1Char('/') + | ||||
326 | sMainConfigSubdirectory; | ||||
327 | | ||||
328 | if (!QFile::exists(sMainConfigPath + sMainConfigName)) { // if main config file doesn't exist, then it's first run | ||||
329 | | ||||
330 | // it could be migration from KDE4 to KF5 so prepare list of configuration files to migrate | ||||
331 | QStringList sConfigNames | ||||
332 | { | ||||
333 | sMainConfigName, | ||||
334 | QStringLiteral("csvimporterrc"), | ||||
335 | QStringLiteral("printcheckpluginrc"), | ||||
336 | QStringLiteral("icalendarexportpluginrc"), | ||||
337 | QStringLiteral("kbankingrc"), | ||||
338 | }; | ||||
339 | | ||||
340 | // Copy KDE 4 config files to the KF5 location | ||||
341 | Kdelibs4ConfigMigrator migrator(QStringLiteral("kmymoney")); | ||||
342 | migrator.setConfigFiles(sConfigNames); | ||||
343 | migrator.setUiFiles(QStringList{QStringLiteral("kmymoneyui.rc")}); | ||||
344 | migrator.migrate(); | ||||
345 | | ||||
346 | QFileInfo fileInfo(sMainConfigPath + sMainConfigName); | ||||
347 | QDir().mkpath(fileInfo.absolutePath()); | ||||
348 | const QString sOldMainConfigPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + | ||||
349 | QLatin1Char('/'); | ||||
350 | | ||||
351 | // some files have changed their names during switch to KF5, so prepare map for name replacements | ||||
352 | QMap<QString, QString> configNamesChange { | ||||
353 | {QStringLiteral("printcheckpluginrc"), QStringLiteral("checkprintingrc")}, | ||||
354 | {QStringLiteral("icalendarexportpluginrc"), QStringLiteral("icalendarexporterrc")} | ||||
355 | }; | ||||
356 | | ||||
357 | for (const auto& sConfigName : sConfigNames) { | ||||
358 | const auto sOldConfigFilename = sOldMainConfigPath + sConfigName; | ||||
359 | const auto sNewConfigFilename = sMainConfigPath + configNamesChange.value(sConfigName, sConfigName); | ||||
360 | if (QFile::exists(sOldConfigFilename)) { | ||||
361 | if (QFile::copy(sOldConfigFilename, sNewConfigFilename)) | ||||
362 | QFile::remove(sOldConfigFilename); | ||||
363 | } | ||||
364 | } | ||||
365 | } | ||||
366 | KConfig::setMainConfigName(sMainConfigSubdirectory + sMainConfigName); // otherwise it would be ~/.config/kmymoneyrc and not ~/.config/kmymoney/kmymoneyrc | ||||
367 | KMyMoneySettings::instance(KSharedConfig::openConfig().data()->name()); // kcfg settings file should be kmymoneyrc, so define it here in one place instead in kmymoney.kcfg | ||||
tbaumgart: It still fails. **KMyMoneySettings::instance() **requires a **const QString&** to the filename… | |||||
It seems so. Please look at wojnilowicz: It seems so. Please look at
https://api.kde.org/frameworks/kconfig/html/classKConfigSkeleton. | |||||
368 | } |
It still fails. KMyMoneySettings::instance() requires a const QString& to the filename and KSharedConfig::openConfig() returns a pointer to a KSharedConfig object. That somehow does not look right to me. Are you using a different version of KSharedConfig than I do.