Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/kmymoney.cpp
Context not available. | |||||
97 | #include "kmymoneyadaptor.h" | 97 | #include "kmymoneyadaptor.h" | ||
---|---|---|---|---|---|
98 | 98 | | |||
99 | #include "dialogs/settings/ksettingskmymoney.h" | 99 | #include "dialogs/settings/ksettingskmymoney.h" | ||
100 | #include "dialogs/kbackupdlg.h" | | |||
101 | #include "dialogs/kexportdlg.h" | 100 | #include "dialogs/kexportdlg.h" | ||
102 | #include "dialogs/kimportdlg.h" | 101 | #include "dialogs/kimportdlg.h" | ||
103 | #include "dialogs/mymoneyqifprofileeditor.h" | 102 | #include "dialogs/mymoneyqifprofileeditor.h" | ||
Context not available. | |||||
178 | #define RECOVER_KEY_EXPIRATION_WARNING 30 | 177 | #define RECOVER_KEY_EXPIRATION_WARNING 30 | ||
179 | #endif | 178 | #endif | ||
180 | 179 | | |||
181 | enum backupStateE { | | |||
182 | BACKUP_IDLE = 0, | | |||
183 | BACKUP_MOUNTING, | | |||
184 | BACKUP_COPYING, | | |||
185 | BACKUP_UNMOUNTING | | |||
186 | }; | | |||
187 | | ||||
188 | class KMyMoneyApp::Private | 180 | class KMyMoneyApp::Private | ||
189 | { | 181 | { | ||
190 | public: | 182 | public: | ||
Context not available. | |||||
270 | */ | 262 | */ | ||
271 | QMap<QString, KMyMoneyPlugin::OnlinePlugin*> m_onlinePlugins; | 263 | QMap<QString, KMyMoneyPlugin::OnlinePlugin*> m_onlinePlugins; | ||
272 | 264 | | |||
273 | /** | | |||
274 | * The following variable represents the state while crafting a backup. | | |||
275 | * It can have the following values | | |||
276 | * | | |||
277 | * - IDLE: the default value if not performing a backup | | |||
278 | * - MOUNTING: when a mount command has been issued | | |||
279 | * - COPYING: when a copy command has been issued | | |||
280 | * - UNMOUNTING: when an unmount command has been issued | | |||
281 | */ | | |||
282 | backupStateE m_backupState; | | |||
283 | | ||||
284 | /** | | |||
285 | * This variable keeps the result of the backup operation. | | |||
286 | */ | | |||
287 | int m_backupResult; | | |||
288 | | ||||
289 | /** | | |||
290 | * This variable is set, when the user selected to mount/unmount | | |||
291 | * the backup volume. | | |||
292 | */ | | |||
293 | bool m_backupMount; | | |||
294 | | ||||
295 | QProcess m_proc; | 265 | QProcess m_proc; | ||
296 | 266 | | |||
297 | /// A pointer to the view holding the tabs. | 267 | /// A pointer to the view holding the tabs. | ||
Context not available. | |||||
426 | 396 | | |||
427 | setCentralWidget(frame); | 397 | setCentralWidget(frame); | ||
428 | 398 | | |||
429 | connect(&d->m_proc, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(slotProcessExited())); | | |||
430 | | ||||
431 | // force to show the home page if the file is closed | 399 | // force to show the home page if the file is closed | ||
432 | connect(action("view_show_transaction_detail"), SIGNAL(toggled(bool)), d->m_myMoneyView, SLOT(slotShowTransactionDetail(bool))); | 400 | connect(action("view_show_transaction_detail"), SIGNAL(toggled(bool)), d->m_myMoneyView, SLOT(slotShowTransactionDetail(bool))); | ||
433 | 401 | | |||
434 | d->m_backupState = BACKUP_IDLE; | | |||
435 | | ||||
436 | // TODO: port kf5 | 402 | // TODO: port kf5 | ||
437 | int weekStart = 1;//KLocale::global()->workingWeekStartDay(); | 403 | int weekStart = 1;//KLocale::global()->workingWeekStartDay(); | ||
438 | int weekEnd = 7;//KLocale::global()->workingWeekEndDay(); | 404 | int weekEnd = 7;//KLocale::global()->workingWeekEndDay(); | ||
Context not available. | |||||
581 | saveas_database->setIcon(QIcon::fromTheme("svn-update")); | 547 | saveas_database->setIcon(QIcon::fromTheme("svn-update")); | ||
582 | connect(saveas_database, SIGNAL(triggered()), this, SLOT(slotSaveAsDatabase())); | 548 | connect(saveas_database, SIGNAL(triggered()), this, SLOT(slotSaveAsDatabase())); | ||
583 | 549 | | |||
584 | QAction *file_backup = actionCollection()->addAction("file_backup"); | | |||
585 | file_backup->setText(i18n("Backup...")); | | |||
586 | file_backup->setIcon(QIcon::fromTheme(QStringLiteral("utilities-file-archiver"), | | |||
587 | QIcon::fromTheme(QStringLiteral("package")))); | | |||
588 | connect(file_backup, SIGNAL(triggered()), this, SLOT(slotFileBackup())); | | |||
589 | | ||||
590 | QAction *file_import_qif = actionCollection()->addAction("file_import_qif"); | 550 | QAction *file_import_qif = actionCollection()->addAction("file_import_qif"); | ||
591 | file_import_qif->setText(i18n("QIF...")); | 551 | file_import_qif->setText(i18n("QIF...")); | ||
592 | connect(file_import_qif, SIGNAL(triggered()), this, SLOT(slotQifImport())); | 552 | connect(file_import_qif, SIGNAL(triggered()), this, SLOT(slotQifImport())); | ||
Context not available. | |||||
2607 | } | 2567 | } | ||
2608 | } | 2568 | } | ||
2609 | 2569 | | |||
2610 | /** No descriptions */ | | |||
2611 | void KMyMoneyApp::slotFileBackup() | | |||
2612 | { | | |||
2613 | // Save the file first so isLocalFile() works | | |||
2614 | if (d->m_myMoneyView && d->m_myMoneyView->dirty()) | | |||
2615 | | ||||
2616 | { | | |||
2617 | if (KMessageBox::questionYesNo(this, i18n("The file must be saved first " | | |||
2618 | "before it can be backed up. Do you want to continue?")) == KMessageBox::No) { | | |||
2619 | return; | | |||
2620 | | ||||
2621 | } | | |||
2622 | | ||||
2623 | slotFileSave(); | | |||
2624 | } | | |||
2625 | | ||||
2626 | | ||||
2627 | | ||||
2628 | if (d->m_fileName.isEmpty()) | | |||
2629 | return; | | |||
2630 | | ||||
2631 | if (!d->m_fileName.isLocalFile()) { | | |||
2632 | KMessageBox::sorry(this, | | |||
2633 | i18n("The current implementation of the backup functionality only supports local files as source files. Your current source file is '%1'.", d->m_fileName.url()), | | |||
2634 | | ||||
2635 | i18n("Local files only")); | | |||
2636 | return; | | |||
2637 | } | | |||
2638 | // TODO: port KF5 | | |||
2639 | #if 0 | | |||
2640 | QPointer<KBackupDlg> backupDlg = new KBackupDlg(this); | | |||
2641 | int returncode = backupDlg->exec(); | | |||
2642 | if (returncode == QDialog::Accepted && backupDlg != 0) { | | |||
2643 | | ||||
2644 | d->m_backupMount = backupDlg->mountCheckBox->isChecked(); | | |||
2645 | d->m_proc.clearProgram(); | | |||
2646 | d->m_backupState = BACKUP_MOUNTING; | | |||
2647 | d->m_mountpoint = backupDlg->txtMountPoint->text(); | | |||
2648 | | ||||
2649 | if (d->m_backupMount) { | | |||
2650 | progressCallback(0, 300, i18n("Mounting %1", d->m_mountpoint)); | | |||
2651 | d->m_proc.setProgram("mount"); | | |||
2652 | d->m_proc << d->m_mountpoint; | | |||
2653 | d->m_proc.start(); | | |||
2654 | | ||||
2655 | } else { | | |||
2656 | // If we don't have to mount a device, we just issue | | |||
2657 | // a dummy command to start the copy operation | | |||
2658 | progressCallback(0, 300, ""); | | |||
2659 | d->m_proc.setProgram("true"); | | |||
2660 | d->m_proc.start(); | | |||
2661 | } | | |||
2662 | | ||||
2663 | } | | |||
2664 | | ||||
2665 | delete backupDlg; | | |||
2666 | #endif | | |||
2667 | } | | |||
2668 | | ||||
2669 | | ||||
2670 | /** No descriptions */ | | |||
2671 | void KMyMoneyApp::slotProcessExited() | | |||
2672 | { | | |||
2673 | // TODO: port KF5 | | |||
2674 | #if 0 | | |||
2675 | switch (d->m_backupState) { | | |||
2676 | case BACKUP_MOUNTING: | | |||
2677 | | ||||
2678 | if (d->m_proc.exitStatus() == QProcess::NormalExit && d->m_proc.exitCode() == 0) { | | |||
2679 | d->m_proc.clearProgram(); | | |||
2680 | QString today; | | |||
2681 | today.sprintf("-%04d-%02d-%02d.kmy", | | |||
2682 | QDate::currentDate().year(), | | |||
2683 | QDate::currentDate().month(), | | |||
2684 | QDate::currentDate().day()); | | |||
2685 | QString backupfile = d->m_mountpoint + '/' + d->m_fileName.fileName(); | | |||
2686 | KMyMoneyUtils::appendCorrectFileExt(backupfile, today); | | |||
2687 | | ||||
2688 | // check if file already exists and ask what to do | | |||
2689 | d->m_backupResult = 0; | | |||
2690 | QFile f(backupfile); | | |||
2691 | if (f.exists()) { | | |||
2692 | int answer = KMessageBox::warningContinueCancel(this, i18n("Backup file for today exists on that device. Replace?"), i18n("Backup"), KGuiItem(i18n("&Replace"))); | | |||
2693 | if (answer == KMessageBox::Cancel) { | | |||
2694 | d->m_backupResult = 1; | | |||
2695 | | ||||
2696 | if (d->m_backupMount) { | | |||
2697 | progressCallback(250, 0, i18n("Unmounting %1", d->m_mountpoint)); | | |||
2698 | d->m_proc.clearProgram(); | | |||
2699 | d->m_proc.setProgram("umount"); | | |||
2700 | d->m_proc << d->m_mountpoint; | | |||
2701 | d->m_backupState = BACKUP_UNMOUNTING; | | |||
2702 | d->m_proc.start(); | | |||
2703 | } else { | | |||
2704 | d->m_backupState = BACKUP_IDLE; | | |||
2705 | progressCallback(-1, -1, QString()); | | |||
2706 | ready(); | | |||
2707 | } | | |||
2708 | } | | |||
2709 | } | | |||
2710 | | ||||
2711 | if (d->m_backupResult == 0) { | | |||
2712 | progressCallback(50, 0, i18n("Writing %1", backupfile)); | | |||
2713 | //FIXME: FIX on windows | | |||
2714 | d->m_proc << "cp" << "-f" << d->m_fileName.path() << backupfile; | | |||
2715 | d->m_backupState = BACKUP_COPYING; | | |||
2716 | d->m_proc.start(); | | |||
2717 | } | | |||
2718 | | ||||
2719 | } else { | | |||
2720 | KMessageBox::information(this, i18n("Error mounting device"), i18n("Backup")); | | |||
2721 | d->m_backupResult = 1; | | |||
2722 | if (d->m_backupMount) { | | |||
2723 | progressCallback(250, 0, i18n("Unmounting %1", d->m_mountpoint)); | | |||
2724 | d->m_proc.clearProgram(); | | |||
2725 | d->m_proc.setProgram("umount"); | | |||
2726 | d->m_proc << d->m_mountpoint; | | |||
2727 | d->m_backupState = BACKUP_UNMOUNTING; | | |||
2728 | d->m_proc.start(); | | |||
2729 | | ||||
2730 | } else { | | |||
2731 | d->m_backupState = BACKUP_IDLE; | | |||
2732 | progressCallback(-1, -1, QString()); | | |||
2733 | ready(); | | |||
2734 | } | | |||
2735 | } | | |||
2736 | break; | | |||
2737 | | ||||
2738 | case BACKUP_COPYING: | | |||
2739 | if (d->m_proc.exitStatus() == QProcess::NormalExit && d->m_proc.exitCode() == 0) { | | |||
2740 | | ||||
2741 | if (d->m_backupMount) { | | |||
2742 | progressCallback(250, 0, i18n("Unmounting %1", d->m_mountpoint)); | | |||
2743 | d->m_proc.clearProgram(); | | |||
2744 | d->m_proc.setProgram("umount"); | | |||
2745 | d->m_proc << d->m_mountpoint; | | |||
2746 | d->m_backupState = BACKUP_UNMOUNTING; | | |||
2747 | d->m_proc.start(); | | |||
2748 | } else { | | |||
2749 | progressCallback(300, 0, i18nc("Backup done", "Done")); | | |||
2750 | KMessageBox::information(this, i18n("File successfully backed up"), i18n("Backup")); | | |||
2751 | d->m_backupState = BACKUP_IDLE; | | |||
2752 | progressCallback(-1, -1, QString()); | | |||
2753 | ready(); | | |||
2754 | } | | |||
2755 | } else { | | |||
2756 | qDebug("cp exit code is %d", d->m_proc.exitCode()); | | |||
2757 | d->m_backupResult = 1; | | |||
2758 | KMessageBox::information(this, i18n("Error copying file to device"), i18n("Backup")); | | |||
2759 | | ||||
2760 | if (d->m_backupMount) { | | |||
2761 | progressCallback(250, 0, i18n("Unmounting %1", d->m_mountpoint)); | | |||
2762 | d->m_proc.clearProgram(); | | |||
2763 | d->m_proc.setProgram("umount"); | | |||
2764 | d->m_proc << d->m_mountpoint; | | |||
2765 | d->m_backupState = BACKUP_UNMOUNTING; | | |||
2766 | d->m_proc.start(); | | |||
2767 | | ||||
2768 | | ||||
2769 | } else { | | |||
2770 | d->m_backupState = BACKUP_IDLE; | | |||
2771 | progressCallback(-1, -1, QString()); | | |||
2772 | ready(); | | |||
2773 | } | | |||
2774 | } | | |||
2775 | break; | | |||
2776 | | ||||
2777 | | ||||
2778 | case BACKUP_UNMOUNTING: | | |||
2779 | if (d->m_proc.exitStatus() == QProcess::NormalExit && d->m_proc.exitCode() == 0) { | | |||
2780 | | ||||
2781 | progressCallback(300, 0, i18nc("Backup done", "Done")); | | |||
2782 | if (d->m_backupResult == 0) | | |||
2783 | KMessageBox::information(this, i18n("File successfully backed up"), i18n("Backup")); | | |||
2784 | } else { | | |||
2785 | KMessageBox::information(this, i18n("Error unmounting device"), i18n("Backup")); | | |||
2786 | } | | |||
2787 | d->m_backupState = BACKUP_IDLE; | | |||
2788 | progressCallback(-1, -1, QString()); | | |||
2789 | ready(); | | |||
2790 | break; | | |||
2791 | | ||||
2792 | default: | | |||
2793 | qWarning("Unknown state for backup operation!"); | | |||
2794 | progressCallback(-1, -1, QString()); | | |||
2795 | ready(); | | |||
2796 | break; | | |||
2797 | } | | |||
2798 | #endif | | |||
2799 | } | | |||
2800 | | ||||
2801 | void KMyMoneyApp::slotShowTipOfTheDay() | 2570 | void KMyMoneyApp::slotShowTipOfTheDay() | ||
2802 | { | 2571 | { | ||
2803 | KTipDialog::showTip(d->m_myMoneyView, "", true); | 2572 | KTipDialog::showTip(d->m_myMoneyView, "", true); | ||
Context not available. | |||||
6398 | action("file_save_as")->setEnabled(fileOpen); | 6167 | action("file_save_as")->setEnabled(fileOpen); | ||
6399 | action("file_close")->setEnabled(fileOpen); | 6168 | action("file_close")->setEnabled(fileOpen); | ||
6400 | action("view_personal_data")->setEnabled(fileOpen); | 6169 | action("view_personal_data")->setEnabled(fileOpen); | ||
6401 | action("file_backup")->setEnabled(fileOpen && !d->m_myMoneyView->isDatabase()); | | |||
6402 | action("file_print")->setEnabled(fileOpen && d->m_myMoneyView->canPrint()); | 6170 | action("file_print")->setEnabled(fileOpen && d->m_myMoneyView->canPrint()); | ||
6403 | #ifdef KMM_DEBUG | 6171 | #ifdef KMM_DEBUG | ||
6404 | action("view_file_info")->setEnabled(fileOpen); | 6172 | action("view_file_info")->setEnabled(fileOpen); | ||
Context not available. |