importwizard.cpp 10.7 KB
Newer Older
1
/*
Laurent Montel's avatar
Laurent Montel committed
2
  Copyright (c) 2012-2013 Montel Laurent <montel@kde.org>
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

  This program is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License, version 2, as
  published by the Free Software Foundation.

  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.

  You should have received a copy of the GNU General Public License along
  with this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include "importwizard.h"
19
#include "importwizardkernel.h"
Laurent Montel's avatar
Laurent Montel committed
20
#include "selectprogrampage.h"
Laurent Montel's avatar
Laurent Montel committed
21 22 23 24 25
#include "selectcomponentpage.h"
#include "importmailpage.h"
#include "importfilterpage.h"
#include "importsettingpage.h"
#include "importaddressbookpage.h"
Laurent Montel's avatar
Laurent Montel committed
26
#include "importcalendarpage.h"
Laurent Montel's avatar
Laurent Montel committed
27
#include "importfinishpage.h"
28

Torgny Nyblom's avatar
Torgny Nyblom committed
29
#include "thunderbird/thunderbirdimportdata.h"
30
#include "sylpheed/sylpheedimportdata.h"
Laurent Montel's avatar
Laurent Montel committed
31
#include "evolutionv3/evolutionv3importdata.h"
32 33
#include "evolutionv2/evolutionv2importdata.h"
#include "evolutionv1/evolutionv1importdata.h"
Laurent Montel's avatar
Laurent Montel committed
34
#include "opera/operaimportdata.h"
Laurent Montel's avatar
Laurent Montel committed
35
#include "oe/oeimportdata.h"
Laurent Montel's avatar
Laurent Montel committed
36
#include "mailapp/mailappimportdata.h"
Laurent Montel's avatar
Laurent Montel committed
37
#include "pmail/pmailimportdata.h"
Laurent Montel's avatar
Laurent Montel committed
38
#include "thebat/thebatimportdata.h"
Laurent Montel's avatar
Laurent Montel committed
39
#include "balsa/balsaimportdata.h"
Laurent Montel's avatar
Typo  
Laurent Montel committed
40
#include "claws-mail/clawsmailimportdata.h"
41
#include "trojita/trojitaimportdata.h"
Laurent Montel's avatar
Laurent Montel committed
42
#include "kmail1/kmail1importdata.h"
Laurent Montel's avatar
Laurent Montel committed
43

44 45 46
#include <kaboutapplicationdialog.h>
#include <kglobal.h>
#include <klocale.h>
Laurent Montel's avatar
Laurent Montel committed
47
#include <qdebug.h>
Laurent Montel's avatar
Laurent Montel committed
48
#include <KMessageBox>
Laurent Montel's avatar
Laurent Montel committed
49
#include <KHelpMenu>
Laurent Montel's avatar
Port++  
Laurent Montel committed
50
#include <QMenu>
Laurent Montel's avatar
Laurent Montel committed
51
#include <AkonadiCore/control.h>
Laurent Montel's avatar
Laurent Montel committed
52
#include <mailcommon/kernel/mailkernel.h>
53 54

ImportWizard::ImportWizard(QWidget *parent)
55
    : KAssistantDialog(parent), mSelectedPim( 0 )
56
{
57 58
    setModal(true);
    setWindowTitle( i18n( "PIM Import Tool" ) );
59 60 61
    KGlobal::locale()->insertCatalog( QLatin1String("libmailimporter") );
    KGlobal::locale()->insertCatalog( QLatin1String("libmailcommon") );
    KGlobal::locale()->insertCatalog( QLatin1String("libpimcommon") );
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107

    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

    mSelectProgramPage = new SelectProgramPage(this);
    mPage1 = new KPageWidgetItem( mSelectProgramPage, i18n( "Detect program" ) );
    addPage( mPage1);

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

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

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

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

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

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


    mImportFinishPage = new ImportFinishPage(this);
    mPage8 = new KPageWidgetItem( mImportFinishPage, i18n( "Finish" ) );
    addPage( mPage8 );


    //Import module
    addImportModule(new ThunderbirdImportData(this));
    addImportModule(new SylpheedImportData(this));
    addImportModule(new Evolutionv3ImportData(this));
    addImportModule(new Evolutionv2ImportData(this));
    addImportModule(new Evolutionv1ImportData(this));
    addImportModule(new OperaImportData(this));
108
#ifdef Q_OS_WIN
109
    addImportModule(new OeImportData(this));
110 111
#endif
#ifdef Q_OS_MAC
112
    addImportModule(new MailAppImportData(this));
113
#endif
Laurent Montel's avatar
Laurent Montel committed
114

Laurent Montel's avatar
Laurent Montel committed
115
#ifdef Q_OS_WIN
116 117
    addImportModule(new PMailImportData(this));
    addImportModule(new TheBatImportData(this));
Laurent Montel's avatar
Laurent Montel committed
118
#endif
Laurent Montel's avatar
Laurent Montel committed
119

120 121 122
    addImportModule(new BalsaImportData(this));
    addImportModule(new ClawsMailImportData(this));
    addImportModule(new TrojitaImportData(this));
Laurent Montel's avatar
Laurent Montel committed
123
    addImportModule(new KMail1ImportData(this));
124 125 126

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

128 129 130 131 132 133 134
    connect(mSelectProgramPage,SIGNAL(programSelected(QString)),this,SLOT(slotProgramSelected(QString)));
    connect(mSelectProgramPage, SIGNAL(doubleClicked()), this, SLOT(slotProgramDoubleClicked()) );
    connect(mImportMailPage,SIGNAL(importMailsClicked()),this,SLOT(slotImportMailsClicked()));
    connect(mImportFilterPage, SIGNAL(importFiltersClicked()), this, SLOT(slotImportFiltersClicked()) );
    connect(mImportSettingPage, SIGNAL(importSettingsClicked()), this, SLOT(slotImportSettingsClicked()) );
    connect(mImportAddressbookPage, SIGNAL(importAddressbookClicked()), this, SLOT(slotImportAddressbookClicked()) );
    connect(mImportCalendarPage, SIGNAL(importCalendarClicked()), this, SLOT(slotImportCalendarClicked()) );
Laurent Montel's avatar
Laurent Montel committed
135

Laurent Montel's avatar
Laurent Montel committed
136

137
    connect(mSelectComponentPage, SIGNAL(atLeastOneComponentSelected(bool)), this, SLOT(slotAtLeastOneComponentSelected(bool)) );
138

139 140
    resize( 640, 480 );
    Akonadi::Control::widgetNeedsAkonadi(this);
Laurent Montel's avatar
Laurent Montel committed
141

142 143
    checkModules();
    KMessageBox::information(this,i18n("Close KMail before importing data. Some plugins will modify KMail config file."));
Laurent Montel's avatar
Laurent Montel committed
144 145
    //QT5 KHelpMenu *helpMenu = new KHelpMenu(this, KGlobal::mainComponent().aboutData(), true);
    //setButtonMenu( Help, helpMenu->menu() );
146 147 148 149
}

ImportWizard::~ImportWizard()
{
150
    qDeleteAll(mlistImport);
Laurent Montel's avatar
Laurent Montel committed
151 152
}

153 154
void ImportWizard::slotProgramDoubleClicked()
{
155
    next();
156 157
}

Laurent Montel's avatar
Laurent Montel committed
158 159
void ImportWizard::slotImportAddressbookClicked()
{
160 161 162 163
    addFinishInfo( i18n( "Import addressbook from %1...", mSelectedPim->name() ) );
    mImportAddressbookPage->setImportButtonEnabled(false);
    const bool result = mSelectedPim->importAddressBook();
    setValid(mPage6,result);
Laurent Montel's avatar
Laurent Montel committed
164 165
}

Laurent Montel's avatar
Laurent Montel committed
166 167
void ImportWizard::slotImportFiltersClicked()
{
168 169 170 171
    addFinishInfo( i18n( "Import filters from %1...", mSelectedPim->name() ) );
    mImportFilterPage->setImportButtonEnabled(false);
    const bool result = mSelectedPim->importFilters();
    setValid(mPage4,result);
Laurent Montel's avatar
Laurent Montel committed
172 173
}

Laurent Montel's avatar
Laurent Montel committed
174 175
void ImportWizard::slotImportMailsClicked()
{
176 177 178 179
    addFinishInfo( i18n( "Import mails from %1...", mSelectedPim->name() ) );
    mImportMailPage->setImportButtonEnabled(false);
    const bool result = mSelectedPim->importMails();
    setValid(mPage3,result);
Laurent Montel's avatar
Laurent Montel committed
180 181
}

Laurent Montel's avatar
Laurent Montel committed
182 183
void ImportWizard::slotImportSettingsClicked()
{
184 185 186 187
    addFinishInfo( i18n( "Import settings from %1...", mSelectedPim->name() ) );
    mImportSettingPage->setImportButtonEnabled(false);
    const bool result = mSelectedPim->importSettings();
    setValid(mPage5,result);
Laurent Montel's avatar
Laurent Montel committed
188 189
}

Laurent Montel's avatar
Laurent Montel committed
190 191
void ImportWizard::slotImportCalendarClicked()
{
192 193 194 195
    addFinishInfo( i18n( "Import calendar from %1...", mSelectedPim->name() ) );
    mImportCalendarPage->setImportButtonEnabled(false);
    const bool result = mSelectedPim->importCalendar();
    setValid(mPage7,result);
Laurent Montel's avatar
Laurent Montel committed
196 197
}

Laurent Montel's avatar
Laurent Montel committed
198 199
void ImportWizard::slotProgramSelected(const QString& program)
{
200
    if (mlistImport.contains(program)) {
201 202 203
        mSelectedPim = mlistImport.value( program );
        setValid( currentPage(), true );
    }
Laurent Montel's avatar
Laurent Montel committed
204
}
Laurent Montel's avatar
Laurent Montel committed
205 206 207

void ImportWizard::checkModules()
{
208
    mSelectProgramPage->setFoundProgram(mlistImport.keys());
209 210
}

Laurent Montel's avatar
Laurent Montel committed
211
void ImportWizard::addImportModule(AbstractImporter *import)
Laurent Montel's avatar
Laurent Montel committed
212
{
213 214 215 216
    if ( import->foundMailer() )
        mlistImport.insert(import->name(),import);
    else
        delete import;
Laurent Montel's avatar
Laurent Montel committed
217 218
}

219 220
void ImportWizard::slotAtLeastOneComponentSelected( bool result )
{
221
    setValid(mPage2,result);
222 223
}

Laurent Montel's avatar
Laurent Montel committed
224
void ImportWizard::setAppropriatePage(AbstractImporter::TypeSupportedOptions options)
Laurent Montel's avatar
Laurent Montel committed
225
{
226 227 228 229 230
    setAppropriate(mPage3,(options & AbstractImporter::Mails));
    setAppropriate(mPage4,(options & AbstractImporter::Filters));
    setAppropriate(mPage5,(options & AbstractImporter::Settings));
    setAppropriate(mPage6,(options & AbstractImporter::AddressBooks));
    setAppropriate(mPage7,(options & AbstractImporter::Calendars));
Laurent Montel's avatar
Laurent Montel committed
231 232 233

}

Laurent Montel's avatar
Laurent Montel committed
234 235
void ImportWizard::next()
{
236
    if ( currentPage() == mPage1 ) {
237 238 239
        KAssistantDialog::next();
        mSelectProgramPage->disableSelectProgram();
        mSelectComponentPage->setEnabledComponent(mSelectedPim->supportedOption());
240
    } else if ( currentPage() == mPage2 ) {
241 242 243
        setAppropriatePage(mSelectComponentPage->selectedComponents());
        KAssistantDialog::next();
        setValid(mPage3,false);
244
    } else if ( currentPage() == mPage3 ) {
245 246
        KAssistantDialog::next();
        setValid(mPage4,false);
247
    } else if ( currentPage() == mPage4 ) {
248 249
        KAssistantDialog::next();
        setValid(mPage5,false);
250
    } else if ( currentPage() == mPage5 ) {
251 252
        KAssistantDialog::next();
        setValid(mPage6,false);
253
    } else if ( currentPage() == mPage6 ) {
254 255
        KAssistantDialog::next();
        setValid(mPage7,false);
256
    } else if ( currentPage() == mPage7 ) {
257 258 259 260 261
        KAssistantDialog::next();
        setValid(mPage8,true);
    } else {
        KAssistantDialog::next();
    }
Laurent Montel's avatar
Laurent Montel committed
262 263
}

264 265
void ImportWizard::enableAllImportButton()
{
266 267 268 269 270
    mImportMailPage->setImportButtonEnabled(true);
    mImportFilterPage->setImportButtonEnabled(true);
    mImportSettingPage->setImportButtonEnabled(true);
    mImportAddressbookPage->setImportButtonEnabled(true);
    mImportCalendarPage->setImportButtonEnabled(true);
271 272
}

Laurent Montel's avatar
Laurent Montel committed
273 274
void ImportWizard::back()
{
275
    if ( currentPage() == mPage1 ) {
276
        return;
277
    } else if ( currentPage() == mPage4 ||
278 279 280 281 282 283 284
               currentPage() == mPage5 ||
               currentPage() == mPage6 ||
               currentPage() == mPage7 ||
               currentPage() == mPage8 ) {
        enableAllImportButton();
    }
    KAssistantDialog::back();
Laurent Montel's avatar
Laurent Montel committed
285 286
}

Laurent Montel's avatar
Laurent Montel committed
287 288
void ImportWizard::reject()
{
289
    KAssistantDialog::reject();
Laurent Montel's avatar
Laurent Montel committed
290 291
}

292
ImportMailPage* ImportWizard::importMailPage() const
293
{
294
    return mImportMailPage;
295 296
}

297
ImportFilterPage* ImportWizard::importFilterPage() const
Laurent Montel's avatar
Laurent Montel committed
298
{
299
    return mImportFilterPage;
Laurent Montel's avatar
Laurent Montel committed
300 301
}

302
ImportAddressbookPage *ImportWizard::importAddressBookPage() const
Laurent Montel's avatar
Laurent Montel committed
303
{
304
    return mImportAddressbookPage;
Laurent Montel's avatar
Laurent Montel committed
305 306
}

307
ImportSettingPage *ImportWizard::importSettingPage() const
Laurent Montel's avatar
Laurent Montel committed
308
{
309
    return mImportSettingPage;
Laurent Montel's avatar
Laurent Montel committed
310
}
311
ImportFinishPage *ImportWizard::importFinishPage() const
Laurent Montel's avatar
Laurent Montel committed
312
{
313
    return mImportFinishPage;
Laurent Montel's avatar
Laurent Montel committed
314
}
315

Laurent Montel's avatar
Laurent Montel committed
316 317
ImportCalendarPage *ImportWizard::importCalendarPage() const
{
318
    return mImportCalendarPage;
Laurent Montel's avatar
Laurent Montel committed
319 320
}

321 322
void ImportWizard::addFinishInfo( const QString& log )
{
323
    mImportFinishPage->addImportInfo( log );
324 325 326 327
}

void ImportWizard::addFinishError( const QString& log )
{
328
    mImportFinishPage->addImportError( log );
329 330
}