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

   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.

   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; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
Laurent Montel's avatar
Laurent Montel committed
18 19 20
*/

#include "mboxmainwindow.h"
Laurent Montel's avatar
Laurent Montel committed
21 22
#include "mboximportwidget.h"
#include "mboximportkernel.h"
Laurent Montel's avatar
Laurent Montel committed
23 24
#include "mboximporterinfogui.h"

25
#include <mailimporter/filtermbox.h>
Laurent Montel's avatar
Laurent Montel committed
26
#include <mailimporter/importmailswidget.h>
Laurent Montel's avatar
Laurent Montel committed
27

Laurent Montel's avatar
Laurent Montel committed
28
#include <MailCommon/MailKernel>
Laurent Montel's avatar
Laurent Montel committed
29

Laurent Montel's avatar
Laurent Montel committed
30
#include <KLocalizedString>
Laurent Montel's avatar
Laurent Montel committed
31 32 33
#include <QDialogButtonBox>
#include <QPushButton>
#include <QVBoxLayout>
Laurent Montel's avatar
Laurent Montel committed
34

Laurent Montel's avatar
Laurent Montel committed
35
MBoxMainWindow::MBoxMainWindow(const QString &filename, QWidget *parent)
Laurent Montel's avatar
Laurent Montel committed
36
    : QDialog(parent),
Laurent Montel's avatar
Laurent Montel committed
37
      mFileName(filename)
Laurent Montel's avatar
Laurent Montel committed
38
{
Laurent Montel's avatar
Laurent Montel committed
39
    setWindowTitle(i18n("Import mbox file"));
Laurent Montel's avatar
Laurent Montel committed
40 41 42
    QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
    QVBoxLayout *mainLayout = new QVBoxLayout;
    setLayout(mainLayout);
Laurent Montel's avatar
Laurent Montel committed
43
    connect(buttonBox, &QDialogButtonBox::rejected, this, &MBoxMainWindow::reject);
Laurent Montel's avatar
Laurent Montel committed
44

Laurent Montel's avatar
Laurent Montel committed
45
    buttonBox->button(QDialogButtonBox::Close)->setDefault(true);
Laurent Montel's avatar
Laurent Montel committed
46

Laurent Montel's avatar
Laurent Montel committed
47 48 49
    MBoxImporterKernel *kernel = new MBoxImporterKernel(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
50 51

    mImportWidget = new MBoxImportWidget;
Laurent Montel's avatar
Laurent Montel committed
52 53 54
    mainLayout->addWidget(mImportWidget);
    mainLayout->addWidget(buttonBox);

Laurent Montel's avatar
Laurent Montel committed
55
    connect(mImportWidget, &MBoxImportWidget::importMailsClicked, this, &MBoxMainWindow::slotImportMBox);
Laurent Montel's avatar
Laurent Montel committed
56
    resize(800, 600);
Laurent Montel's avatar
Laurent Montel committed
57 58 59 60 61 62
}

MBoxMainWindow::~MBoxMainWindow()
{
}

Laurent Montel's avatar
Laurent Montel committed
63 64
void MBoxMainWindow::slotImportMBox()
{
Laurent Montel's avatar
Laurent Montel committed
65 66 67
    MailImporter::FilterInfo *info = new MailImporter::FilterInfo();
    MBoxImporterInfoGui *infoGui = new MBoxImporterInfoGui(mImportWidget);
    info->setFilterInfoGui(infoGui);
Laurent Montel's avatar
Laurent Montel committed
68
    info->setRootCollection(mImportWidget->selectedCollection());
Laurent Montel's avatar
Laurent Montel committed
69 70 71 72
    info->clear(); // Clear info from last time

    info->setStatusMessage(i18n("Import in progress"));
    MailImporter::FilterMBox mbox;
Laurent Montel's avatar
Laurent Montel committed
73
    mbox.setFilterInfo(info);
Laurent Montel's avatar
Laurent Montel committed
74
    info->clear();
Laurent Montel's avatar
Laurent Montel committed
75
    mbox.importMails(QStringList() << mFileName);
Laurent Montel's avatar
Laurent Montel committed
76 77
    info->setStatusMessage(i18n("Import finished"));
    delete info;
Laurent Montel's avatar
Laurent Montel committed
78 79
}