importwizard.cpp 16.9 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"
29

30 31 32 33
#include "autodetect/thunderbird/thunderbirdimportdata.h"
#include "autodetect/icedove/icedoveimportdata.h"
#include "autodetect/oe/oeimportdata.h"
#include "autodetect/thebat/thebatimportdata.h"
Laurent Montel's avatar
Laurent Montel committed
34

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

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

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

Laurent Montel's avatar
Laurent Montel committed
52 53 54
ImportWizard::ImportWizard(WizardMode mode, QWidget *parent)
    : KAssistantDialog(parent),
      mMode(mode),
Laurent Montel's avatar
Laurent Montel committed
55
      mSelectedPim(nullptr)
56
{
57
    setModal(true);
Laurent Montel's avatar
Laurent Montel committed
58 59
    setWindowTitle(i18n("PIM Import Tool"));
    setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Help);
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

84 85 86 87
    if (mode == AutoDetect) {
        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 == 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 210
void ImportWizard::initializeImportModule()
{
    //Import module
211 212 213 214 215 216 217 218
    AbstractImporter *importer = new ThunderbirdImportData(this);
    importer->setImportWizard(this);
    addImportModule(importer);

    importer = new IcedoveImportData(this);
    importer->setImportWizard(this);
    addImportModule(importer);

219 220 221
//    importer = new SylpheedImportData(this);
//    importer->setImportWizard(this);
//    addImportModule(importer);
222

Laurent Montel's avatar
Laurent Montel committed
223 224 225
//    importer = new Evolutionv3ImportData(this);
//    importer->setImportWizard(this);
//    addImportModule(importer);
226

Laurent Montel's avatar
Laurent Montel committed
227 228 229
//    importer = new Evolutionv2ImportData(this);
//    importer->setImportWizard(this);
//    addImportModule(importer);
230

Laurent Montel's avatar
Laurent Montel committed
231 232 233
//    importer = new Evolutionv1ImportData(this);
//    importer->setImportWizard(this);
//    addImportModule(importer);
234

235 236 237
//    importer = new OperaImportData(this);
//    importer->setImportWizard(this);
//    addImportModule(importer);
Laurent Montel's avatar
Laurent Montel committed
238
#ifdef Q_OS_WIN
239 240 241
    importer = new OeImportData(this);
    importer->setImportWizard(this);
    addImportModule(importer);
Laurent Montel's avatar
Laurent Montel committed
242 243
#endif
#ifdef Q_OS_MAC
244 245 246
    importer = new OeImportData(this);
    importer->setImportWizard(this);
    addImportModule(importer);
Laurent Montel's avatar
Laurent Montel committed
247 248 249
#endif

#ifdef Q_OS_WIN
Laurent Montel's avatar
Laurent Montel committed
250 251 252
//    importer = new PMailImportData(this);
//    importer->setImportWizard(this);
//    addImportModule(importer);
253 254 255 256

    importer = new TheBatImportData(this);
    importer->setImportWizard(this);
    addImportModule(importer);
Laurent Montel's avatar
Laurent Montel committed
257 258
#endif

Laurent Montel's avatar
Laurent Montel committed
259 260 261
//    importer = new BalsaImportData(this);
//    importer->setImportWizard(this);
//    addImportModule(importer);
262

263 264 265
//    importer = new ClawsMailImportData(this);
//    importer->setImportWizard(this);
//    addImportModule(importer);
266

Laurent Montel's avatar
Laurent Montel committed
267 268 269
//    importer = new TrojitaImportData(this);
//    importer->setImportWizard(this);
//    addImportModule(importer);
Laurent Montel's avatar
Laurent Montel committed
270 271
}

272 273
void ImportWizard::slotProgramDoubleClicked()
{
274
    next();
275 276
}

Laurent Montel's avatar
Laurent Montel committed
277 278
void ImportWizard::slotImportAddressbookClicked()
{
Laurent Montel's avatar
Laurent Montel committed
279
    addFinishInfo(i18n("Import addressbook from %1...", mSelectedPim->name()));
280 281
    mImportAddressbookPage->setImportButtonEnabled(false);
    const bool result = mSelectedPim->importAddressBook();
Laurent Montel's avatar
Laurent Montel committed
282
    setValid(mImportAddressbookPageItem, result);
Laurent Montel's avatar
Laurent Montel committed
283 284
}

Laurent Montel's avatar
Laurent Montel committed
285 286
void ImportWizard::slotImportFiltersClicked()
{
Laurent Montel's avatar
Laurent Montel committed
287
    addFinishInfo(i18n("Import filters from %1...", mSelectedPim->name()));
288 289
    mImportFilterPage->setImportButtonEnabled(false);
    const bool result = mSelectedPim->importFilters();
Laurent Montel's avatar
Laurent Montel committed
290
    setValid(mImportFilterPageItem, result);
Laurent Montel's avatar
Laurent Montel committed
291 292
}

Laurent Montel's avatar
Laurent Montel committed
293 294
void ImportWizard::slotImportMailsClicked()
{
Laurent Montel's avatar
Laurent Montel committed
295
    addFinishInfo(i18n("Import mails from %1...", mSelectedPim->name()));
296 297
    mImportMailPage->setImportButtonEnabled(false);
    const bool result = mSelectedPim->importMails();
Laurent Montel's avatar
Laurent Montel committed
298
    setValid(mImportMailPageItem, result);
Laurent Montel's avatar
Laurent Montel committed
299 300
}

Laurent Montel's avatar
Laurent Montel committed
301 302
void ImportWizard::slotImportSettingsClicked()
{
Laurent Montel's avatar
Laurent Montel committed
303
    addFinishInfo(i18n("Import settings from %1...", mSelectedPim->name()));
304 305
    mImportSettingPage->setImportButtonEnabled(false);
    const bool result = mSelectedPim->importSettings();
Laurent Montel's avatar
Laurent Montel committed
306
    setValid(mImportSettingPageItem, result);
Laurent Montel's avatar
Laurent Montel committed
307 308
}

Laurent Montel's avatar
Laurent Montel committed
309 310
void ImportWizard::slotImportCalendarClicked()
{
Laurent Montel's avatar
Laurent Montel committed
311
    addFinishInfo(i18n("Import calendar from %1...", mSelectedPim->name()));
312 313
    mImportCalendarPage->setImportButtonEnabled(false);
    const bool result = mSelectedPim->importCalendar();
Laurent Montel's avatar
Laurent Montel committed
314
    setValid(mImportCalendarPageItem, result);
Laurent Montel's avatar
Laurent Montel committed
315 316
}

Laurent Montel's avatar
Laurent Montel committed
317
void ImportWizard::slotProgramSelected(const QString &program)
Laurent Montel's avatar
Laurent Montel committed
318
{
Laurent Montel's avatar
Laurent Montel committed
319 320 321
    AbstractImporter *importer = mlistImport.value(program);
    if (importer) {
        mSelectedPim = importer;
Laurent Montel's avatar
Laurent Montel committed
322
        setValid(currentPage(), true);
323
    }
Laurent Montel's avatar
Laurent Montel committed
324
}
Laurent Montel's avatar
Laurent Montel committed
325 326 327

void ImportWizard::checkModules()
{
328
    mSelectProgramPage->setFoundProgram(mlistImport.keys());
329 330
}

Laurent Montel's avatar
Laurent Montel committed
331
void ImportWizard::addImportModule(AbstractImporter *import)
Laurent Montel's avatar
Laurent Montel committed
332
{
Laurent Montel's avatar
Laurent Montel committed
333 334 335
    if (import->foundMailer()) {
        mlistImport.insert(import->name(), import);
    } else {
336
        delete import;
Laurent Montel's avatar
Laurent Montel committed
337
    }
Laurent Montel's avatar
Laurent Montel committed
338 339
}

Laurent Montel's avatar
Laurent Montel committed
340
void ImportWizard::slotAtLeastOneComponentSelected(bool result)
341
{
Laurent Montel's avatar
Laurent Montel committed
342
    setValid(mSelectComponentPageItem, result);
343 344
}

Laurent Montel's avatar
Laurent Montel committed
345
void ImportWizard::setAppropriatePage(AbstractImporter::TypeSupportedOptions options)
Laurent Montel's avatar
Laurent Montel committed
346
{
Laurent Montel's avatar
Laurent Montel committed
347 348 349 350 351
    setAppropriate(mImportMailPageItem, (options & AbstractImporter::Mails));
    setAppropriate(mImportFilterPageItem, (options & AbstractImporter::Filters));
    setAppropriate(mImportSettingPageItem, (options & AbstractImporter::Settings));
    setAppropriate(mImportAddressbookPageItem, (options & AbstractImporter::AddressBooks));
    setAppropriate(mImportCalendarPageItem, (options & AbstractImporter::Calendars));
Laurent Montel's avatar
Laurent Montel committed
352 353
}

Laurent Montel's avatar
Laurent Montel committed
354 355
void ImportWizard::next()
{
Laurent Montel's avatar
Laurent Montel committed
356
    if (currentPage() == mSelectProgramPageItem) {
357 358 359
        KAssistantDialog::next();
        mSelectProgramPage->disableSelectProgram();
        mSelectComponentPage->setEnabledComponent(mSelectedPim->supportedOption());
Laurent Montel's avatar
Laurent Montel committed
360
    } else if (currentPage() == mSelectComponentPageItem) {
361 362
        setAppropriatePage(mSelectComponentPage->selectedComponents());
        KAssistantDialog::next();
Laurent Montel's avatar
Laurent Montel committed
363 364
        setValid(mImportMailPageItem, false);
    } else if (currentPage() == mImportMailPageItem) {
365
        KAssistantDialog::next();
Laurent Montel's avatar
Laurent Montel committed
366 367
        setValid(mImportFilterPageItem, false);
    } else if (currentPage() == mImportFilterPageItem) {
368
        KAssistantDialog::next();
Laurent Montel's avatar
Laurent Montel committed
369 370
        setValid(mImportSettingPageItem, false);
    } else if (currentPage() == mImportSettingPageItem) {
371
        KAssistantDialog::next();
Laurent Montel's avatar
Laurent Montel committed
372 373
        setValid(mImportAddressbookPageItem, false);
    } else if (currentPage() == mImportAddressbookPageItem) {
374
        KAssistantDialog::next();
Laurent Montel's avatar
Laurent Montel committed
375 376
        setValid(mImportCalendarPageItem, false);
    } else if (currentPage() == mImportCalendarPageItem) {
377
        KAssistantDialog::next();
Laurent Montel's avatar
Laurent Montel committed
378
        setValid(mImportFinishPageItem, true);
Laurent Montel's avatar
Laurent Montel committed
379 380 381 382 383
    } 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
384
        if (!selectedFilter) {
Laurent Montel's avatar
Laurent Montel committed
385
            return;
Laurent Montel's avatar
Laurent Montel committed
386
        }
Laurent Montel's avatar
Laurent Montel committed
387
        // Ensure we have a valid collection.
Laurent Montel's avatar
Laurent Montel committed
388
        if (!selectedCollection.isValid()) {
Laurent Montel's avatar
Laurent Montel committed
389
            return;
Laurent Montel's avatar
Laurent Montel committed
390
        }
Laurent Montel's avatar
Laurent Montel committed
391 392 393
        // Goto next page
        KAssistantDialog::next();
        // Disable back & finish
Laurent Montel's avatar
Laurent Montel committed
394
        setValid(currentPage(), false);
Laurent Montel's avatar
Laurent Montel committed
395 396 397

        finishButton()->setEnabled(false);

Laurent Montel's avatar
Laurent Montel committed
398
        MailImporter::FilterInfo *info = new MailImporter::FilterInfo();
Laurent Montel's avatar
Laurent Montel committed
399
        MailImporter::FilterImporterAkonadi *filterImporter = new MailImporter::FilterImporterAkonadi(info);
Laurent Montel's avatar
Laurent Montel committed
400
        ImportWizardFilterInfoGui *infoGui = new ImportWizardFilterInfoGui(mImportpage, this);
Laurent Montel's avatar
Laurent Montel committed
401 402
        info->setFilterInfoGui(infoGui);
        info->setStatusMessage(i18n("Import in progress"));
Laurent Montel's avatar
Laurent Montel committed
403
        info->setRemoveDupMessage(mSelfilterpage->removeDupMsg_checked());
Laurent Montel's avatar
Laurent Montel committed
404
        info->clear(); // Clear info from last time
Laurent Montel's avatar
Laurent Montel committed
405 406
        filterImporter->setRootCollection(selectedCollection);
        selectedFilter->setFilterImporter(filterImporter);
Laurent Montel's avatar
Laurent Montel committed
407
        selectedFilter->setFilterInfo(info);
Laurent Montel's avatar
Laurent Montel committed
408 409 410
        selectedFilter->import();
        info->setStatusMessage(i18n("Import finished"));
        // Cleanup
Laurent Montel's avatar
Laurent Montel committed
411
        delete filterImporter;
Laurent Montel's avatar
Laurent Montel committed
412 413
        delete info;
        // Enable finish & back buttons
Laurent Montel's avatar
Laurent Montel committed
414
        setValid(currentPage(), true);
Laurent Montel's avatar
Laurent Montel committed
415
        finishButton()->setEnabled(true);
416 417 418
    } else {
        KAssistantDialog::next();
    }
Laurent Montel's avatar
Laurent Montel committed
419 420
}

421 422
void ImportWizard::enableAllImportButton()
{
423 424 425 426 427
    mImportMailPage->setImportButtonEnabled(true);
    mImportFilterPage->setImportButtonEnabled(true);
    mImportSettingPage->setImportButtonEnabled(true);
    mImportAddressbookPage->setImportButtonEnabled(true);
    mImportCalendarPage->setImportButtonEnabled(true);
428 429
}

Laurent Montel's avatar
Laurent Montel committed
430 431
void ImportWizard::back()
{
Laurent Montel's avatar
Laurent Montel committed
432
    if (currentPage() == mSelectProgramPageItem) {
433
        return;
Laurent Montel's avatar
Laurent Montel committed
434 435 436 437
    } else if (currentPage() == mImportFilterPageItem ||
               currentPage() == mImportSettingPageItem ||
               currentPage() == mImportAddressbookPageItem ||
               currentPage() == mImportCalendarPageItem ||
Laurent Montel's avatar
Laurent Montel committed
438
               currentPage() == mImportFinishPageItem) {
439 440 441
        enableAllImportButton();
    }
    KAssistantDialog::back();
Laurent Montel's avatar
Laurent Montel committed
442 443
}

Laurent Montel's avatar
Laurent Montel committed
444
ImportMailPage *ImportWizard::importMailPage() const
445
{
446
    return mImportMailPage;
447 448
}

Laurent Montel's avatar
Laurent Montel committed
449
ImportFilterPage *ImportWizard::importFilterPage() const
Laurent Montel's avatar
Laurent Montel committed
450
{
451
    return mImportFilterPage;
Laurent Montel's avatar
Laurent Montel committed
452 453
}

454
ImportAddressbookPage *ImportWizard::importAddressBookPage() const
Laurent Montel's avatar
Laurent Montel committed
455
{
456
    return mImportAddressbookPage;
Laurent Montel's avatar
Laurent Montel committed
457 458
}

459
ImportSettingPage *ImportWizard::importSettingPage() const
Laurent Montel's avatar
Laurent Montel committed
460
{
461
    return mImportSettingPage;
Laurent Montel's avatar
Laurent Montel committed
462
}
463

464
ImportFinishPage *ImportWizard::importFinishPage() const
Laurent Montel's avatar
Laurent Montel committed
465
{
466
    return mImportFinishPage;
Laurent Montel's avatar
Laurent Montel committed
467
}
468

Laurent Montel's avatar
Laurent Montel committed
469 470
ImportCalendarPage *ImportWizard::importCalendarPage() const
{
471
    return mImportCalendarPage;
Laurent Montel's avatar
Laurent Montel committed
472 473
}

Laurent Montel's avatar
Laurent Montel committed
474
void ImportWizard::addFinishInfo(const QString &log)
475
{
Laurent Montel's avatar
Laurent Montel committed
476
    mImportFinishPage->addImportInfo(log);
477 478
}

Laurent Montel's avatar
Laurent Montel committed
479
void ImportWizard::addFinishError(const QString &log)
480
{
Laurent Montel's avatar
Laurent Montel committed
481
    mImportFinishPage->addImportError(log);
482 483
}

Laurent Montel's avatar
Laurent Montel committed
484 485 486 487 488
void ImportWizard::slotSelectManualSelectionChanged(bool b)
{
    mMode = b ? Manual : AutoDetect;
    updatePagesFromMode();
}