importwizard.cpp 15.8 KB
Newer Older
1
/*
2
   Copyright (C) 2012-2017 Montel Laurent <montel@kde.org>
3

Laurent Montel's avatar
Laurent Montel committed
4 5 6 7
   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.
8

Laurent Montel's avatar
Laurent Montel committed
9 10 11 12
   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.
13

Laurent Montel's avatar
Laurent Montel committed
14 15 16 17
   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
18 19
*/
#include "importwizard.h"
20
#include "importwizardkernel.h"
Laurent Montel's avatar
Laurent Montel committed
21
#include "selectprogrampage.h"
Laurent Montel's avatar
Laurent Montel committed
22 23 24 25 26
#include "selectcomponentpage.h"
#include "importmailpage.h"
#include "importfilterpage.h"
#include "importsettingpage.h"
#include "importaddressbookpage.h"
Laurent Montel's avatar
Laurent Montel committed
27
#include "importcalendarpage.h"
Laurent Montel's avatar
Laurent Montel committed
28
#include "importfinishpage.h"
Laurent Montel's avatar
Laurent Montel committed
29
#include "importmailpluginmanager.h"
30 31
#include "importwizarddisplayinfo.h"

Laurent Montel's avatar
Laurent Montel committed
32
#include "helper_p.h"
33

Laurent Montel's avatar
Laurent Montel committed
34 35
#include "manual/manualimportmailpage.h"
#include "manual/manualselectfilterpage.h"
Laurent Montel's avatar
Laurent Montel committed
36
#include "manual/importwizardfilterinfogui.h"
Laurent Montel's avatar
Laurent Montel committed
37 38

#include "mailimporter/filterinfo.h"
Laurent Montel's avatar
Laurent Montel committed
39
#include <MailImporterAkonadi/FilterImporterAkonadi>
Laurent Montel's avatar
Laurent Montel committed
40

Laurent Montel's avatar
Laurent Montel committed
41 42 43
#include <QAction>
#include <KAboutData>
#include <KLocalizedString>
Laurent Montel's avatar
Laurent Montel committed
44
#include "importwizard_debug.h"
Laurent Montel's avatar
Laurent Montel committed
45
#include <KMessageBox>
Laurent Montel's avatar
Laurent Montel committed
46
#include <KHelpMenu>
Laurent Montel's avatar
Laurent Montel committed
47
#include <AkonadiWidgets/controlgui.h>
Laurent Montel's avatar
Laurent Montel committed
48
#include <MailCommon/MailKernel>
Laurent Montel's avatar
Laurent Montel committed
49
#include <QPushButton>
50

Laurent Montel's avatar
Laurent Montel committed
51 52 53
ImportWizard::ImportWizard(WizardMode mode, QWidget *parent)
    : KAssistantDialog(parent),
      mMode(mode),
Laurent Montel's avatar
Laurent Montel committed
54
      mSelectedPim(nullptr)
55
{
56
    setModal(true);
Laurent Montel's avatar
Laurent Montel committed
57 58
    setWindowTitle(i18n("PIM Import Tool"));
    setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Help);
59
    mAbstractDisplayInfo = new ImportWizardDisplayInfo(this);
60

Laurent Montel's avatar
Laurent Montel committed
61 62 63
    ImportWizardKernel *kernel = new ImportWizardKernel(this);
    CommonKernel->registerKernelIf(kernel);   //register KernelIf early, it is used by the Filter classes
    CommonKernel->registerSettingsIf(kernel);   //SettingsIf is used in FolderTreeWidget
Laurent Montel's avatar
Laurent Montel committed
64
    createAutomaticModePage();
Laurent Montel's avatar
Laurent Montel committed
65
    createManualModePage();
Laurent Montel's avatar
Laurent Montel committed
66
    initializeImportModule();
67 68

    // Disable the 'next button to begin with.
Laurent Montel's avatar
Laurent Montel committed
69
    setValid(currentPage(), false);
Laurent Montel's avatar
Laurent Montel committed
70

Laurent Montel's avatar
Laurent Montel committed
71 72 73 74 75 76 77
    connect(mSelectProgramPage, &SelectProgramPage::programSelected, this, &ImportWizard::slotProgramSelected);
    connect(mSelectProgramPage, &SelectProgramPage::doubleClicked, this, &ImportWizard::slotProgramDoubleClicked);
    connect(mImportMailPage, &ImportMailPage::importMailsClicked, this, &ImportWizard::slotImportMailsClicked);
    connect(mImportFilterPage, &ImportFilterPage::importFiltersClicked, this, &ImportWizard::slotImportFiltersClicked);
    connect(mImportSettingPage, &ImportSettingPage::importSettingsClicked, this, &ImportWizard::slotImportSettingsClicked);
    connect(mImportAddressbookPage, &ImportAddressbookPage::importAddressbookClicked, this, &ImportWizard::slotImportAddressbookClicked);
    connect(mImportCalendarPage, &ImportCalendarPage::importCalendarClicked, this, &ImportWizard::slotImportCalendarClicked);
Laurent Montel's avatar
Laurent Montel committed
78

Laurent Montel's avatar
Laurent Montel committed
79
    connect(mSelectComponentPage, &SelectComponentPage::atLeastOneComponentSelected, this, &ImportWizard::slotAtLeastOneComponentSelected);
80

Laurent Montel's avatar
Laurent Montel committed
81
    resize(640, 480);
Laurent Montel's avatar
Laurent Montel committed
82
    Akonadi::ControlGui::widgetNeedsAkonadi(this);
Laurent Montel's avatar
Laurent Montel committed
83

Laurent Montel's avatar
Laurent Montel committed
84
    if (mode == WizardMode::AutoDetect) {
85 86 87
        checkModules();
        KMessageBox::information(this, i18n("Close KMail before importing data. Some plugins will modify KMail config file."));
    }
Laurent Montel's avatar
Laurent Montel committed
88 89 90
    KHelpMenu *helpMenu = new KHelpMenu(this, KAboutData::applicationData(), true);
    //Initialize menu
    QMenu *menu = helpMenu->menu();
Laurent Montel's avatar
Laurent Montel committed
91
    helpMenu->action(KHelpMenu::menuAboutApp)->setIcon(QIcon::fromTheme(QStringLiteral("kmail")));
Laurent Montel's avatar
Laurent Montel committed
92
    button(QDialogButtonBox::Help)->setMenu(menu);
Laurent Montel's avatar
Laurent Montel committed
93
    updatePagesFromMode();
Laurent Montel's avatar
Laurent Montel committed
94
    readConfig();
95 96 97 98
}

ImportWizard::~ImportWizard()
{
Laurent Montel's avatar
Laurent Montel committed
99
    writeConfig();
Laurent Montel's avatar
Laurent Montel committed
100 101
}

Laurent Montel's avatar
Laurent Montel committed
102 103
void ImportWizard::readConfig()
{
Laurent Montel's avatar
Laurent Montel committed
104 105 106
    KConfigGroup group(KSharedConfig::openConfig(), "FolderSelectionDialog");
    if (group.hasKey("LastSelectedFolder")) {
        mSelfilterpage->widget()->mCollectionRequestor->setCollection(CommonKernel->collectionFromId(group.readEntry("LastSelectedFolder", -1)));
Laurent Montel's avatar
Laurent Montel committed
107 108 109 110 111
    }
}

void ImportWizard::writeConfig()
{
Laurent Montel's avatar
Laurent Montel committed
112 113
    KConfigGroup group(KSharedConfig::openConfig(), "FolderSelectionDialog");
    group.writeEntry("LastSelectedFolder", mSelfilterpage->widget()->mCollectionRequestor->collection().id());
Laurent Montel's avatar
Laurent Montel committed
114 115 116
    group.sync();
}

Laurent Montel's avatar
Laurent Montel committed
117 118
void ImportWizard::updatePagesFromMode()
{
Laurent Montel's avatar
Laurent Montel committed
119
    const bool autodetectMode = (mMode == WizardMode::AutoDetect);
Laurent Montel's avatar
Laurent Montel committed
120 121 122 123 124 125 126 127 128 129 130
    setAppropriate(mSelectProgramPageItem, autodetectMode);
    setAppropriate(mSelectComponentPageItem, autodetectMode);
    setAppropriate(mImportMailPageItem, autodetectMode);
    setAppropriate(mImportFilterPageItem, autodetectMode);
    setAppropriate(mImportSettingPageItem, autodetectMode);
    setAppropriate(mImportAddressbookPageItem, autodetectMode);
    setAppropriate(mImportCalendarPageItem, autodetectMode);
    setAppropriate(mImportFinishPageItem, autodetectMode);

    setAppropriate(mSelfilterpageItem, !autodetectMode);
    setAppropriate(mImportpageItem, !autodetectMode);
Laurent Montel's avatar
Laurent Montel committed
131 132 133 134 135
    if (autodetectMode) {
        setCurrentPage(mSelectProgramPageItem);
    } else {
        setCurrentPage(mSelfilterpageItem);
    }
Laurent Montel's avatar
Laurent Montel committed
136 137
}

Laurent Montel's avatar
Laurent Montel committed
138 139
void ImportWizard::createManualModePage()
{
Laurent Montel's avatar
Laurent Montel committed
140
    mSelfilterpage = new ManualSelectFilterPage(this);
Laurent Montel's avatar
Laurent Montel committed
141
    mSelfilterpageItem = new KPageWidgetItem(mSelfilterpage, i18n("Step 1: Select Filter"));
Laurent Montel's avatar
Laurent Montel committed
142

Laurent Montel's avatar
Laurent Montel committed
143
    addPage(mSelfilterpageItem);
Laurent Montel's avatar
Laurent Montel committed
144

Laurent Montel's avatar
Laurent Montel committed
145
    mImportpage = new ManualImportMailPage(this);
Laurent Montel's avatar
Laurent Montel committed
146 147
    mImportpageItem = new KPageWidgetItem(mImportpage, i18n("Step 2: Importing..."));
    addPage(mImportpageItem);
Laurent Montel's avatar
Laurent Montel committed
148 149

    // Disable the 'next button to begin with.
Laurent Montel's avatar
Laurent Montel committed
150
    setValid(mSelfilterpageItem, false);
Laurent Montel's avatar
Laurent Montel committed
151

152
    connect(mSelfilterpage->widget()->mCollectionRequestor, &MailCommon::FolderRequester::folderChanged, this, &ImportWizard::slotCollectionChanged);
Laurent Montel's avatar
Laurent Montel committed
153 154
}

Laurent Montel's avatar
Laurent Montel committed
155
void ImportWizard::slotCollectionChanged(const Akonadi::Collection &selectedCollection)
Laurent Montel's avatar
Laurent Montel committed
156
{
Laurent Montel's avatar
Laurent Montel committed
157 158
    if (selectedCollection.isValid()) {
        setValid(mSelfilterpageItem, true);
Laurent Montel's avatar
Laurent Montel committed
159
    } else {
Laurent Montel's avatar
Laurent Montel committed
160
        setValid(mSelfilterpageItem, false);
Laurent Montel's avatar
Laurent Montel committed
161 162 163 164 165
    }
}

void ImportWizard::reject()
{
Laurent Montel's avatar
Laurent Montel committed
166 167 168
    if (currentPage() == mImportpageItem) {
        MailImporter::FilterInfo::terminateASAP();    // ie. import in progress
    }
Laurent Montel's avatar
Laurent Montel committed
169
    KAssistantDialog::reject();
Laurent Montel's avatar
Laurent Montel committed
170 171
}

Laurent Montel's avatar
Laurent Montel committed
172 173 174 175
void ImportWizard::createAutomaticModePage()
{
    mSelectProgramPage = new SelectProgramPage(this);
    mSelectProgramPageItem = new KPageWidgetItem(mSelectProgramPage, i18n("Detect program"));
Laurent Montel's avatar
Laurent Montel committed
176
    connect(mSelectProgramPage, &SelectProgramPage::selectManualSelectionChanged, this, &ImportWizard::slotSelectManualSelectionChanged);
Laurent Montel's avatar
Laurent Montel committed
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
    addPage(mSelectProgramPageItem);

    mSelectComponentPage = new SelectComponentPage(this);
    mSelectComponentPageItem = new KPageWidgetItem(mSelectComponentPage, i18n("Select material to import"));
    addPage(mSelectComponentPageItem);

    mImportMailPage = new ImportMailPage(this);
    mImportMailPageItem = new KPageWidgetItem(mImportMailPage, i18n("Import mail messages"));
    addPage(mImportMailPageItem);

    mImportFilterPage = new ImportFilterPage(this);
    mImportFilterPageItem = new KPageWidgetItem(mImportFilterPage, i18n("Import mail filters"));
    addPage(mImportFilterPageItem);

    mImportSettingPage = new ImportSettingPage(this);
    mImportSettingPageItem = new KPageWidgetItem(mImportSettingPage, i18n("Import settings"));
    addPage(mImportSettingPageItem);

    mImportAddressbookPage = new ImportAddressbookPage(this);
    mImportAddressbookPageItem = new KPageWidgetItem(mImportAddressbookPage, i18n("Import addressbooks"));
    addPage(mImportAddressbookPageItem);

    mImportCalendarPage = new ImportCalendarPage(this);
    mImportCalendarPageItem = new KPageWidgetItem(mImportCalendarPage, i18n("Import calendars"));
    addPage(mImportCalendarPageItem);

    mImportFinishPage = new ImportFinishPage(this);
Laurent Montel's avatar
Laurent Montel committed
204 205
    mImportFinishPageItem = new KPageWidgetItem(mImportFinishPage, i18n("Finish"));
    addPage(mImportFinishPageItem);
Laurent Montel's avatar
Laurent Montel committed
206 207
}

Laurent Montel's avatar
Laurent Montel committed
208 209
void ImportWizard::initializeImportModule()
{
Laurent Montel's avatar
Laurent Montel committed
210 211
    const QVector<LibImportWizard::AbstractImporter *> lstPlugins = ImportMailPluginManager::self()->pluginsList();
    for (LibImportWizard::AbstractImporter *abstractPlugin : qAsConst(lstPlugins)) {
Laurent Montel's avatar
Laurent Montel committed
212
        if (abstractPlugin->foundMailer()) {
213
            abstractPlugin->setParentWidget(this);
214
            abstractPlugin->setAbstractDisplayInfo(mAbstractDisplayInfo);
Laurent Montel's avatar
Laurent Montel committed
215 216 217
            mlistImport.insert(abstractPlugin->name(), abstractPlugin);
        }
    }
Laurent Montel's avatar
Laurent Montel committed
218 219
}

220 221
void ImportWizard::slotProgramDoubleClicked()
{
222
    next();
223 224
}

Laurent Montel's avatar
Laurent Montel committed
225 226
void ImportWizard::slotImportAddressbookClicked()
{
Laurent Montel's avatar
Laurent Montel committed
227
    addFinishInfo(i18n("Import addressbook from %1...", mSelectedPim->name()));
228 229
    mImportAddressbookPage->setImportButtonEnabled(false);
    const bool result = mSelectedPim->importAddressBook();
Laurent Montel's avatar
Laurent Montel committed
230
    setValid(mImportAddressbookPageItem, result);
Laurent Montel's avatar
Laurent Montel committed
231 232
}

Laurent Montel's avatar
Laurent Montel committed
233 234
void ImportWizard::slotImportFiltersClicked()
{
Laurent Montel's avatar
Laurent Montel committed
235
    addFinishInfo(i18n("Import filters from %1...", mSelectedPim->name()));
236 237
    mImportFilterPage->setImportButtonEnabled(false);
    const bool result = mSelectedPim->importFilters();
Laurent Montel's avatar
Laurent Montel committed
238
    setValid(mImportFilterPageItem, result);
Laurent Montel's avatar
Laurent Montel committed
239 240
}

Laurent Montel's avatar
Laurent Montel committed
241 242
void ImportWizard::slotImportMailsClicked()
{
Laurent Montel's avatar
Laurent Montel committed
243
    addFinishInfo(i18n("Import mails from %1...", mSelectedPim->name()));
244 245
    mImportMailPage->setImportButtonEnabled(false);
    const bool result = mSelectedPim->importMails();
Laurent Montel's avatar
Laurent Montel committed
246
    setValid(mImportMailPageItem, result);
Laurent Montel's avatar
Laurent Montel committed
247 248
}

Laurent Montel's avatar
Laurent Montel committed
249 250
void ImportWizard::slotImportSettingsClicked()
{
Laurent Montel's avatar
Laurent Montel committed
251
    addFinishInfo(i18n("Import settings from %1...", mSelectedPim->name()));
252 253
    mImportSettingPage->setImportButtonEnabled(false);
    const bool result = mSelectedPim->importSettings();
Laurent Montel's avatar
Laurent Montel committed
254
    setValid(mImportSettingPageItem, result);
Laurent Montel's avatar
Laurent Montel committed
255 256
}

Laurent Montel's avatar
Laurent Montel committed
257 258
void ImportWizard::slotImportCalendarClicked()
{
Laurent Montel's avatar
Laurent Montel committed
259
    addFinishInfo(i18n("Import calendar from %1...", mSelectedPim->name()));
260 261
    mImportCalendarPage->setImportButtonEnabled(false);
    const bool result = mSelectedPim->importCalendar();
Laurent Montel's avatar
Laurent Montel committed
262
    setValid(mImportCalendarPageItem, result);
Laurent Montel's avatar
Laurent Montel committed
263 264
}

Laurent Montel's avatar
Laurent Montel committed
265
void ImportWizard::slotProgramSelected(const QString &program)
Laurent Montel's avatar
Laurent Montel committed
266
{
Laurent Montel's avatar
Laurent Montel committed
267
    LibImportWizard::AbstractImporter *importer = mlistImport.value(program);
Laurent Montel's avatar
Laurent Montel committed
268 269
    if (importer) {
        mSelectedPim = importer;
Laurent Montel's avatar
Laurent Montel committed
270
        setValid(currentPage(), true);
271
    }
Laurent Montel's avatar
Laurent Montel committed
272
}
Laurent Montel's avatar
Laurent Montel committed
273 274 275

void ImportWizard::checkModules()
{
276
    mSelectProgramPage->setFoundProgram(mlistImport.keys());
277 278
}

Laurent Montel's avatar
Laurent Montel committed
279
void ImportWizard::addImportModule(LibImportWizard::AbstractImporter *import)
Laurent Montel's avatar
Laurent Montel committed
280
{
Laurent Montel's avatar
Laurent Montel committed
281 282 283
    if (import->foundMailer()) {
        mlistImport.insert(import->name(), import);
    } else {
284
        delete import;
Laurent Montel's avatar
Laurent Montel committed
285
    }
Laurent Montel's avatar
Laurent Montel committed
286 287
}

Laurent Montel's avatar
Laurent Montel committed
288
void ImportWizard::slotAtLeastOneComponentSelected(bool result)
289
{
Laurent Montel's avatar
Laurent Montel committed
290
    setValid(mSelectComponentPageItem, result);
291 292
}

Laurent Montel's avatar
Laurent Montel committed
293
void ImportWizard::setAppropriatePage(LibImportWizard::AbstractImporter::TypeSupportedOptions options)
Laurent Montel's avatar
Laurent Montel committed
294
{
Laurent Montel's avatar
Laurent Montel committed
295 296 297 298 299
    setAppropriate(mImportMailPageItem, (options & LibImportWizard::AbstractImporter::Mails));
    setAppropriate(mImportFilterPageItem, (options & LibImportWizard::AbstractImporter::Filters));
    setAppropriate(mImportSettingPageItem, (options & LibImportWizard::AbstractImporter::Settings));
    setAppropriate(mImportAddressbookPageItem, (options & LibImportWizard::AbstractImporter::AddressBooks));
    setAppropriate(mImportCalendarPageItem, (options & LibImportWizard::AbstractImporter::Calendars));
Laurent Montel's avatar
Laurent Montel committed
300 301
}

Laurent Montel's avatar
Laurent Montel committed
302 303
void ImportWizard::next()
{
Laurent Montel's avatar
Laurent Montel committed
304
    if (currentPage() == mSelectProgramPageItem) {
305 306 307
        KAssistantDialog::next();
        mSelectProgramPage->disableSelectProgram();
        mSelectComponentPage->setEnabledComponent(mSelectedPim->supportedOption());
Laurent Montel's avatar
Laurent Montel committed
308
    } else if (currentPage() == mSelectComponentPageItem) {
309 310
        setAppropriatePage(mSelectComponentPage->selectedComponents());
        KAssistantDialog::next();
Laurent Montel's avatar
Laurent Montel committed
311 312
        setValid(mImportMailPageItem, false);
    } else if (currentPage() == mImportMailPageItem) {
313
        KAssistantDialog::next();
Laurent Montel's avatar
Laurent Montel committed
314 315
        setValid(mImportFilterPageItem, false);
    } else if (currentPage() == mImportFilterPageItem) {
316
        KAssistantDialog::next();
Laurent Montel's avatar
Laurent Montel committed
317 318
        setValid(mImportSettingPageItem, false);
    } else if (currentPage() == mImportSettingPageItem) {
319
        KAssistantDialog::next();
Laurent Montel's avatar
Laurent Montel committed
320 321
        setValid(mImportAddressbookPageItem, false);
    } else if (currentPage() == mImportAddressbookPageItem) {
322
        KAssistantDialog::next();
Laurent Montel's avatar
Laurent Montel committed
323 324
        setValid(mImportCalendarPageItem, false);
    } else if (currentPage() == mImportCalendarPageItem) {
325
        KAssistantDialog::next();
Laurent Montel's avatar
Laurent Montel committed
326
        setValid(mImportFinishPageItem, true);
Laurent Montel's avatar
Laurent Montel committed
327 328 329 330 331
    } else if (currentPage() == mSelfilterpageItem) {
        // Save selected filter
        MailImporter::Filter *selectedFilter = mSelfilterpage->getSelectedFilter();
        Akonadi::Collection selectedCollection = mSelfilterpage->widget()->mCollectionRequestor->collection();
        // without filter don't go next
Laurent Montel's avatar
Laurent Montel committed
332
        if (!selectedFilter) {
Laurent Montel's avatar
Laurent Montel committed
333
            return;
Laurent Montel's avatar
Laurent Montel committed
334
        }
Laurent Montel's avatar
Laurent Montel committed
335
        // Ensure we have a valid collection.
Laurent Montel's avatar
Laurent Montel committed
336
        if (!selectedCollection.isValid()) {
Laurent Montel's avatar
Laurent Montel committed
337
            return;
Laurent Montel's avatar
Laurent Montel committed
338
        }
Laurent Montel's avatar
Laurent Montel committed
339 340 341
        // Goto next page
        KAssistantDialog::next();
        // Disable back & finish
Laurent Montel's avatar
Laurent Montel committed
342
        setValid(currentPage(), false);
Laurent Montel's avatar
Laurent Montel committed
343 344 345

        finishButton()->setEnabled(false);

Laurent Montel's avatar
Laurent Montel committed
346
        MailImporter::FilterInfo *info = new MailImporter::FilterInfo();
Laurent Montel's avatar
Laurent Montel committed
347
        MailImporter::FilterImporterAkonadi *filterImporter = new MailImporter::FilterImporterAkonadi(info);
Laurent Montel's avatar
Laurent Montel committed
348
        ImportWizardFilterInfoGui *infoGui = new ImportWizardFilterInfoGui(mImportpage, this);
Laurent Montel's avatar
Laurent Montel committed
349 350
        info->setFilterInfoGui(infoGui);
        info->setStatusMessage(i18n("Import in progress"));
Laurent Montel's avatar
Laurent Montel committed
351
        info->setRemoveDupMessage(mSelfilterpage->removeDupMsg_checked());
Laurent Montel's avatar
Laurent Montel committed
352
        info->clear(); // Clear info from last time
Laurent Montel's avatar
Laurent Montel committed
353 354
        filterImporter->setRootCollection(selectedCollection);
        selectedFilter->setFilterImporter(filterImporter);
Laurent Montel's avatar
Laurent Montel committed
355
        selectedFilter->setFilterInfo(info);
Laurent Montel's avatar
Laurent Montel committed
356 357 358
        selectedFilter->import();
        info->setStatusMessage(i18n("Import finished"));
        // Cleanup
Laurent Montel's avatar
Laurent Montel committed
359
        delete filterImporter;
Laurent Montel's avatar
Laurent Montel committed
360 361
        delete info;
        // Enable finish & back buttons
Laurent Montel's avatar
Laurent Montel committed
362
        setValid(currentPage(), true);
Laurent Montel's avatar
Laurent Montel committed
363
        finishButton()->setEnabled(true);
364 365 366
    } else {
        KAssistantDialog::next();
    }
Laurent Montel's avatar
Laurent Montel committed
367 368
}

369 370
void ImportWizard::enableAllImportButton()
{
371 372 373 374 375
    mImportMailPage->setImportButtonEnabled(true);
    mImportFilterPage->setImportButtonEnabled(true);
    mImportSettingPage->setImportButtonEnabled(true);
    mImportAddressbookPage->setImportButtonEnabled(true);
    mImportCalendarPage->setImportButtonEnabled(true);
376 377
}

Laurent Montel's avatar
Laurent Montel committed
378 379
void ImportWizard::back()
{
Laurent Montel's avatar
Laurent Montel committed
380
    if (currentPage() == mSelectProgramPageItem) {
381
        return;
Laurent Montel's avatar
Laurent Montel committed
382 383 384 385
    } else if (currentPage() == mImportFilterPageItem ||
               currentPage() == mImportSettingPageItem ||
               currentPage() == mImportAddressbookPageItem ||
               currentPage() == mImportCalendarPageItem ||
Laurent Montel's avatar
Laurent Montel committed
386
               currentPage() == mImportFinishPageItem) {
387 388 389
        enableAllImportButton();
    }
    KAssistantDialog::back();
Laurent Montel's avatar
Laurent Montel committed
390 391
}

Laurent Montel's avatar
Laurent Montel committed
392
ImportMailPage *ImportWizard::importMailPage() const
393
{
394
    return mImportMailPage;
395 396
}

Laurent Montel's avatar
Laurent Montel committed
397
ImportFilterPage *ImportWizard::importFilterPage() const
Laurent Montel's avatar
Laurent Montel committed
398
{
399
    return mImportFilterPage;
Laurent Montel's avatar
Laurent Montel committed
400 401
}

402
ImportAddressbookPage *ImportWizard::importAddressBookPage() const
Laurent Montel's avatar
Laurent Montel committed
403
{
404
    return mImportAddressbookPage;
Laurent Montel's avatar
Laurent Montel committed
405 406
}

407
ImportSettingPage *ImportWizard::importSettingPage() const
Laurent Montel's avatar
Laurent Montel committed
408
{
409
    return mImportSettingPage;
Laurent Montel's avatar
Laurent Montel committed
410
}
411

412
ImportFinishPage *ImportWizard::importFinishPage() const
Laurent Montel's avatar
Laurent Montel committed
413
{
414
    return mImportFinishPage;
Laurent Montel's avatar
Laurent Montel committed
415
}
416

Laurent Montel's avatar
Laurent Montel committed
417 418
ImportCalendarPage *ImportWizard::importCalendarPage() const
{
419
    return mImportCalendarPage;
Laurent Montel's avatar
Laurent Montel committed
420 421
}

Laurent Montel's avatar
Laurent Montel committed
422
void ImportWizard::addFinishInfo(const QString &log)
423
{
Laurent Montel's avatar
Laurent Montel committed
424
    mImportFinishPage->addImportInfo(log);
425 426
}

Laurent Montel's avatar
Laurent Montel committed
427
void ImportWizard::addFinishError(const QString &log)
428
{
Laurent Montel's avatar
Laurent Montel committed
429
    mImportFinishPage->addImportError(log);
430 431
}

Laurent Montel's avatar
Laurent Montel committed
432 433
void ImportWizard::slotSelectManualSelectionChanged(bool b)
{
Laurent Montel's avatar
Laurent Montel committed
434
    mMode = b ? WizardMode::Manual : WizardMode::AutoDetect;
Laurent Montel's avatar
Laurent Montel committed
435 436
    updatePagesFromMode();
}