Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/kmymoney.cpp
Show First 20 Lines • Show All 61 Lines • ▼ Show 20 Line(s) | |||||
62 | #include <KTipDialog> | 62 | #include <KTipDialog> | ||
63 | #include <KRun> | 63 | #include <KRun> | ||
64 | #include <KConfigDialog> | 64 | #include <KConfigDialog> | ||
65 | #include <KXMLGUIFactory> | 65 | #include <KXMLGUIFactory> | ||
66 | #include <KRecentFilesAction> | 66 | #include <KRecentFilesAction> | ||
67 | #include <KRecentDirs> | 67 | #include <KRecentDirs> | ||
68 | #include <KProcess> | 68 | #include <KProcess> | ||
69 | #include <KAboutApplicationDialog> | 69 | #include <KAboutApplicationDialog> | ||
70 | #include <KIO/StoredTransferJob> | | |||
71 | #include <KJobWidgets> | | |||
72 | #include <KCompressionDevice> | | |||
73 | #include <KBackup> | 70 | #include <KBackup> | ||
74 | #ifdef KF5Holidays_FOUND | 71 | #ifdef ENABLE_HOLIDAYS | ||
75 | #include <KHolidays/Holiday> | 72 | #include <KHolidays/Holiday> | ||
76 | #include <KHolidays/HolidayRegion> | 73 | #include <KHolidays/HolidayRegion> | ||
77 | #endif | 74 | #endif | ||
78 | #ifdef KF5Activities_FOUND | 75 | #ifdef ENABLE_ACTIVITIES | ||
79 | #include <KActivities/ResourceInstance> | 76 | #include <KActivities/ResourceInstance> | ||
80 | #endif | 77 | #endif | ||
81 | 78 | | |||
82 | // ---------------------------------------------------------------------------- | 79 | // ---------------------------------------------------------------------------- | ||
83 | // Project Includes | 80 | // Project Includes | ||
84 | 81 | | |||
85 | #include "kmymoneysettings.h" | 82 | #include "kmymoneysettings.h" | ||
86 | #include "kmymoneyadaptor.h" | 83 | #include "kmymoneyadaptor.h" | ||
▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Line(s) | 204 | Private(KMyMoneyApp *app) : | |||
215 | m_progressBar(nullptr), | 212 | m_progressBar(nullptr), | ||
216 | m_statusLabel(nullptr), | 213 | m_statusLabel(nullptr), | ||
217 | m_autoSaveEnabled(true), | 214 | m_autoSaveEnabled(true), | ||
218 | m_autoSaveTimer(nullptr), | 215 | m_autoSaveTimer(nullptr), | ||
219 | m_progressTimer(nullptr), | 216 | m_progressTimer(nullptr), | ||
220 | m_autoSavePeriod(0), | 217 | m_autoSavePeriod(0), | ||
221 | m_inAutoSaving(false), | 218 | m_inAutoSaving(false), | ||
222 | m_recentFiles(nullptr), | 219 | m_recentFiles(nullptr), | ||
223 | #ifdef KF5Holidays_FOUND | 220 | #ifdef ENABLE_HOLIDAYS | ||
224 | m_holidayRegion(nullptr), | 221 | m_holidayRegion(nullptr), | ||
225 | #endif | 222 | #endif | ||
226 | #ifdef KF5Activities_FOUND | 223 | #ifdef ENABLE_ACTIVITIES | ||
227 | m_activityResourceInstance(nullptr), | 224 | m_activityResourceInstance(nullptr), | ||
228 | #endif | 225 | #endif | ||
229 | m_applicationIsReady(true), | 226 | m_applicationIsReady(true), | ||
230 | m_webConnect(new WebConnect(app)) { | 227 | m_webConnect(new WebConnect(app)) { | ||
231 | // since the days of the week are from 1 to 7, | 228 | // since the days of the week are from 1 to 7, | ||
232 | // and a day of the week is used to index this bit array, | 229 | // and a day of the week is used to index this bit array, | ||
233 | // resize the array to 8 elements (element 0 is left unused) | 230 | // resize the array to 8 elements (element 0 is left unused) | ||
234 | m_processingDays.resize(8); | 231 | m_processingDays.resize(8); | ||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Line(s) | |||||
307 | int m_autoSavePeriod; | 304 | int m_autoSavePeriod; | ||
308 | bool m_inAutoSaving; | 305 | bool m_inAutoSaving; | ||
309 | 306 | | |||
310 | // id's that need to be remembered | 307 | // id's that need to be remembered | ||
311 | QString m_accountGoto, m_payeeGoto; | 308 | QString m_accountGoto, m_payeeGoto; | ||
312 | 309 | | |||
313 | KRecentFilesAction* m_recentFiles; | 310 | KRecentFilesAction* m_recentFiles; | ||
314 | 311 | | |||
315 | #ifdef KF5Holidays_FOUND | 312 | #ifdef ENABLE_HOLIDAYS | ||
316 | // used by the calendar interface for schedules | 313 | // used by the calendar interface for schedules | ||
317 | KHolidays::HolidayRegion* m_holidayRegion; | 314 | KHolidays::HolidayRegion* m_holidayRegion; | ||
318 | #endif | 315 | #endif | ||
319 | 316 | | |||
320 | #ifdef KF5Activities_FOUND | 317 | #ifdef ENABLE_ACTIVITIES | ||
321 | KActivities::ResourceInstance * m_activityResourceInstance; | 318 | KActivities::ResourceInstance * m_activityResourceInstance; | ||
322 | #endif | 319 | #endif | ||
323 | 320 | | |||
324 | QBitArray m_processingDays; | 321 | QBitArray m_processingDays; | ||
325 | QMap<QDate, bool> m_holidayMap; | 322 | QMap<QDate, bool> m_holidayMap; | ||
326 | QStringList m_consistencyCheckResult; | 323 | QStringList m_consistencyCheckResult; | ||
327 | bool m_applicationIsReady; | 324 | bool m_applicationIsReady; | ||
328 | 325 | | |||
▲ Show 20 Lines • Show All 867 Lines • ▼ Show 20 Line(s) | 1145 | #endif | |||
1196 | 1193 | | |||
1197 | d->m_myMoneyView = new KMyMoneyView; | 1194 | d->m_myMoneyView = new KMyMoneyView; | ||
1198 | layout->addWidget(d->m_myMoneyView, 10); | 1195 | layout->addWidget(d->m_myMoneyView, 10); | ||
1199 | connect(d->m_myMoneyView, &KMyMoneyView::viewActivated, this, &KMyMoneyApp::slotViewSelected); | 1196 | connect(d->m_myMoneyView, &KMyMoneyView::viewActivated, this, &KMyMoneyApp::slotViewSelected); | ||
1200 | connect(d->m_myMoneyView, &KMyMoneyView::statusMsg, this, &KMyMoneyApp::slotStatusMsg); | 1197 | connect(d->m_myMoneyView, &KMyMoneyView::statusMsg, this, &KMyMoneyApp::slotStatusMsg); | ||
1201 | connect(d->m_myMoneyView, &KMyMoneyView::statusProgress, this, &KMyMoneyApp::slotStatusProgressBar); | 1198 | connect(d->m_myMoneyView, &KMyMoneyView::statusProgress, this, &KMyMoneyApp::slotStatusProgressBar); | ||
1202 | 1199 | | |||
1203 | // Initialize kactivities resource instance | 1200 | // Initialize kactivities resource instance | ||
1204 | #ifdef KF5Activities_FOUND | 1201 | #ifdef ENABLE_ACTIVITIES | ||
1205 | d->m_activityResourceInstance = new KActivities::ResourceInstance(window()->winId(), this); | 1202 | d->m_activityResourceInstance = new KActivities::ResourceInstance(window()->winId(), this); | ||
1206 | #endif | 1203 | #endif | ||
1207 | 1204 | | |||
1208 | const auto viewActions = d->m_myMoneyView->actionsToBeConnected(); | 1205 | const auto viewActions = d->m_myMoneyView->actionsToBeConnected(); | ||
1209 | actionCollection()->addActions(viewActions.values()); | 1206 | actionCollection()->addActions(viewActions.values()); | ||
1210 | for (auto it = viewActions.cbegin(); it != viewActions.cend(); ++it) | 1207 | for (auto it = viewActions.cbegin(); it != viewActions.cend(); ++it) | ||
1211 | pActions.insert(it.key(), it.value()); | 1208 | pActions.insert(it.key(), it.value()); | ||
1212 | 1209 | | |||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | 1252 | { | |||
1259 | // delete cached objects since they are in the way | 1256 | // delete cached objects since they are in the way | ||
1260 | // when unloading the plugins | 1257 | // when unloading the plugins | ||
1261 | onlineJobAdministration::instance()->clearCaches(); | 1258 | onlineJobAdministration::instance()->clearCaches(); | ||
1262 | 1259 | | |||
1263 | // we need to unload all plugins before we destroy anything else | 1260 | // we need to unload all plugins before we destroy anything else | ||
1264 | KMyMoneyPlugin::pluginHandling(KMyMoneyPlugin::Action::Unload, pPlugins, this, guiFactory()); | 1261 | KMyMoneyPlugin::pluginHandling(KMyMoneyPlugin::Action::Unload, pPlugins, this, guiFactory()); | ||
1265 | d->removeStorage(); | 1262 | d->removeStorage(); | ||
1266 | 1263 | | |||
1267 | #ifdef KF5Holidays_FOUND | 1264 | #ifdef ENABLE_HOLIDAYS | ||
1268 | delete d->m_holidayRegion; | 1265 | delete d->m_holidayRegion; | ||
1269 | #endif | 1266 | #endif | ||
1270 | 1267 | | |||
1271 | #ifdef KF5Activities_FOUND | 1268 | #ifdef ENABLE_ACTIVITIES | ||
1272 | delete d->m_activityResourceInstance; | 1269 | delete d->m_activityResourceInstance; | ||
1273 | #endif | 1270 | #endif | ||
1274 | 1271 | | |||
1275 | // make sure all settings are written to disk | 1272 | // make sure all settings are written to disk | ||
1276 | KMyMoneySettings::self()->save(); | 1273 | KMyMoneySettings::self()->save(); | ||
1277 | delete d; | 1274 | delete d; | ||
1278 | } | 1275 | } | ||
1279 | 1276 | | |||
▲ Show 20 Lines • Show All 1975 Lines • ▼ Show 20 Line(s) | 3248 | { | |||
3255 | // +1 is to make sure that we're already in the next day when the | 3252 | // +1 is to make sure that we're already in the next day when the | ||
3256 | // signal is sent (this way we also avoid setting the timer to 0) | 3253 | // signal is sent (this way we also avoid setting the timer to 0) | ||
3257 | QTimer::singleShot((static_cast<int>(dt.secsTo(nextDay)) + 1)*1000, this, SLOT(slotDateChanged())); | 3254 | QTimer::singleShot((static_cast<int>(dt.secsTo(nextDay)) + 1)*1000, this, SLOT(slotDateChanged())); | ||
3258 | d->m_myMoneyView->slotRefreshViews(); | 3255 | d->m_myMoneyView->slotRefreshViews(); | ||
3259 | } | 3256 | } | ||
3260 | 3257 | | |||
3261 | void KMyMoneyApp::setHolidayRegion(const QString& holidayRegion) | 3258 | void KMyMoneyApp::setHolidayRegion(const QString& holidayRegion) | ||
3262 | { | 3259 | { | ||
3263 | #ifdef KF5Holidays_FOUND | 3260 | #ifdef ENABLE_HOLIDAYS | ||
3264 | //since the cost of updating the cache is now not negligible | 3261 | //since the cost of updating the cache is now not negligible | ||
3265 | //check whether the region has been modified | 3262 | //check whether the region has been modified | ||
3266 | if (!d->m_holidayRegion || d->m_holidayRegion->regionCode() != holidayRegion) { | 3263 | if (!d->m_holidayRegion || d->m_holidayRegion->regionCode() != holidayRegion) { | ||
3267 | // Delete the previous holidayRegion before creating a new one. | 3264 | // Delete the previous holidayRegion before creating a new one. | ||
3268 | delete d->m_holidayRegion; | 3265 | delete d->m_holidayRegion; | ||
3269 | // Create a new holidayRegion. | 3266 | // Create a new holidayRegion. | ||
3270 | d->m_holidayRegion = new KHolidays::HolidayRegion(holidayRegion); | 3267 | d->m_holidayRegion = new KHolidays::HolidayRegion(holidayRegion); | ||
3271 | 3268 | | |||
3272 | //clear and update the holiday cache | 3269 | //clear and update the holiday cache | ||
3273 | preloadHolidays(); | 3270 | preloadHolidays(); | ||
3274 | } | 3271 | } | ||
3275 | #else | 3272 | #else | ||
3276 | Q_UNUSED(holidayRegion); | 3273 | Q_UNUSED(holidayRegion); | ||
3277 | #endif | 3274 | #endif | ||
3278 | } | 3275 | } | ||
3279 | 3276 | | |||
3280 | bool KMyMoneyApp::isProcessingDate(const QDate& date) const | 3277 | bool KMyMoneyApp::isProcessingDate(const QDate& date) const | ||
3281 | { | 3278 | { | ||
3282 | if (!d->m_processingDays.testBit(date.dayOfWeek())) | 3279 | if (!d->m_processingDays.testBit(date.dayOfWeek())) | ||
3283 | return false; | 3280 | return false; | ||
3284 | #ifdef KF5Holidays_FOUND | 3281 | #ifdef ENABLE_HOLIDAYS | ||
3285 | if (!d->m_holidayRegion || !d->m_holidayRegion->isValid()) | 3282 | if (!d->m_holidayRegion || !d->m_holidayRegion->isValid()) | ||
3286 | return true; | 3283 | return true; | ||
3287 | 3284 | | |||
3288 | //check first whether it's already in cache | 3285 | //check first whether it's already in cache | ||
3289 | if (d->m_holidayMap.contains(date)) { | 3286 | if (d->m_holidayMap.contains(date)) { | ||
3290 | return d->m_holidayMap.value(date, true); | 3287 | return d->m_holidayMap.value(date, true); | ||
3291 | } else { | 3288 | } else { | ||
3292 | bool processingDay = !d->m_holidayRegion->isHoliday(date); | 3289 | bool processingDay = !d->m_holidayRegion->isHoliday(date); | ||
3293 | d->m_holidayMap.insert(date, processingDay); | 3290 | d->m_holidayMap.insert(date, processingDay); | ||
3294 | return processingDay; | 3291 | return processingDay; | ||
3295 | } | 3292 | } | ||
3296 | #else | 3293 | #else | ||
3297 | return true; | 3294 | return true; | ||
3298 | #endif | 3295 | #endif | ||
3299 | } | 3296 | } | ||
3300 | 3297 | | |||
3301 | void KMyMoneyApp::preloadHolidays() | 3298 | void KMyMoneyApp::preloadHolidays() | ||
3302 | { | 3299 | { | ||
3303 | #ifdef KF5Holidays_FOUND | 3300 | #ifdef ENABLE_HOLIDAYS | ||
3304 | //clear the cache before loading | 3301 | //clear the cache before loading | ||
3305 | d->m_holidayMap.clear(); | 3302 | d->m_holidayMap.clear(); | ||
3306 | //only do this if it is a valid region | 3303 | //only do this if it is a valid region | ||
3307 | if (d->m_holidayRegion && d->m_holidayRegion->isValid()) { | 3304 | if (d->m_holidayRegion && d->m_holidayRegion->isValid()) { | ||
3308 | //load holidays for the forecast days plus 1 cycle, to be on the safe side | 3305 | //load holidays for the forecast days plus 1 cycle, to be on the safe side | ||
3309 | auto forecastDays = KMyMoneySettings::forecastDays() + KMyMoneySettings::forecastAccountCycle(); | 3306 | auto forecastDays = KMyMoneySettings::forecastDays() + KMyMoneySettings::forecastAccountCycle(); | ||
3310 | QDate endDate = QDate::currentDate().addDays(forecastDays); | 3307 | QDate endDate = QDate::currentDate().addDays(forecastDays); | ||
3311 | 3308 | | |||
▲ Show 20 Lines • Show All 320 Lines • ▼ Show 20 Line(s) | 3614 | case eKMyMoney::FileAction::Opened: | |||
3632 | updateActions(); | 3629 | updateActions(); | ||
3633 | m_myMoneyView->slotFileOpened(); | 3630 | m_myMoneyView->slotFileOpened(); | ||
3634 | onlineJobAdministration::instance()->updateActions(); | 3631 | onlineJobAdministration::instance()->updateActions(); | ||
3635 | m_myMoneyView->enableViewsIfFileOpen(m_storageInfo.isOpened); | 3632 | m_myMoneyView->enableViewsIfFileOpen(m_storageInfo.isOpened); | ||
3636 | m_myMoneyView->slotRefreshViews(); | 3633 | m_myMoneyView->slotRefreshViews(); | ||
3637 | onlineJobAdministration::instance()->updateOnlineTaskProperties(); | 3634 | onlineJobAdministration::instance()->updateOnlineTaskProperties(); | ||
3638 | q->connect(MyMoneyFile::instance(), &MyMoneyFile::dataChanged, q, &KMyMoneyApp::slotDataChanged); | 3635 | q->connect(MyMoneyFile::instance(), &MyMoneyFile::dataChanged, q, &KMyMoneyApp::slotDataChanged); | ||
3639 | 3636 | | |||
3640 | #ifdef KF5Activities_FOUND | 3637 | #ifdef ENABLE_ACTIVITIES | ||
3641 | m_activityResourceInstance->setUri(m_storageInfo.url); | 3638 | m_activityResourceInstance->setUri(m_storageInfo.url); | ||
3642 | #endif | 3639 | #endif | ||
3643 | break; | 3640 | break; | ||
3644 | 3641 | | |||
3645 | case eKMyMoney::FileAction::Saved: | 3642 | case eKMyMoney::FileAction::Saved: | ||
3646 | q->connect(MyMoneyFile::instance(), &MyMoneyFile::dataChanged, q, &KMyMoneyApp::slotDataChanged); | 3643 | q->connect(MyMoneyFile::instance(), &MyMoneyFile::dataChanged, q, &KMyMoneyApp::slotDataChanged); | ||
3647 | q->actionCollection()->action(QString::fromLatin1(KStandardAction::name(KStandardAction::Save)))->setEnabled(false); | 3644 | q->actionCollection()->action(QString::fromLatin1(KStandardAction::name(KStandardAction::Save)))->setEnabled(false); | ||
3648 | m_autoSaveTimer->stop(); | 3645 | m_autoSaveTimer->stop(); | ||
▲ Show 20 Lines • Show All 54 Lines • Show Last 20 Lines |