Remove KActionCollection::setComponentData: this does not work on a KActionCollection...
[kdepim.git] / kmailcvt / kmailcvt.cpp
blobb2b45b2e41adac9d0e2c1cbd8dd8dea332e7a5df
1 /***************************************************************************
2 kmailcvt.cpp - description
3 -------------------
4 copyright : (C) 2003 by Laurence Anderson
5 email : l.d.anderson@warwick.ac.uk
6 ***************************************************************************/
8 /***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
17 // Local includes
18 #include "kmailcvt.h"
19 #include "kimportpage.h"
20 #include "kselfilterpage.h"
21 #include "filters.hxx"
23 // KDE includes
24 #include <kaboutapplicationdialog.h>
25 #include <kglobal.h>
26 #include <klocale.h>
27 #include <kdebug.h>
28 #include <ktoolinvocation.h>
30 // Qt includes
31 #include <QPushButton>
33 #include <akonadi/control.h>
36 KMailCVT::KMailCVT(QWidget *parent)
37 : KAssistantDialog(parent) {
38 setModal(true);
39 setWindowTitle( i18n( "KMailCVT Import Tool" ) );
42 selfilterpage = new KSelFilterPage;
43 page1 = new KPageWidgetItem( selfilterpage, i18n( "Step 1: Select Filter" ) );
45 addPage( page1);
47 importpage = new KImportPage;
48 page2 = new KPageWidgetItem( importpage, i18n( "Step 2: Importing..." ) );
49 addPage( page2 );
50 connect(this,SIGNAL(helpClicked()),this,SLOT(help()));
52 // Disable the 'next button to begin with.
53 setValid( currentPage(), false );
55 connect( selfilterpage->mCollectionRequestor, SIGNAL( collectionChanged(Akonadi::Collection) ),
56 this, SLOT( collectionChanged(Akonadi::Collection) ) );
57 Akonadi::Control::widgetNeedsAkonadi(this);
60 KMailCVT::~KMailCVT()
64 void KMailCVT::next()
66 if( currentPage() == page1 ){
67 // Save selected filter
68 Filter *selectedFilter = selfilterpage->getSelectedFilter();
69 Akonadi::Collection selectedCollection = selfilterpage->mCollectionRequestor->collection();
70 // without filter don't go next
71 if ( !selectedFilter )
72 return;
73 // Ensure we have a valid collection.
74 if( !selectedCollection.isValid() )
75 return;
76 if ( !selectedFilter->needsSecondPage() ) {
77 FilterInfo *info = new FilterInfo( importpage, this, selfilterpage->removeDupMsg_checked() );
78 info->setRootCollection( selectedCollection );
79 selectedFilter->import( info );
80 accept();
81 delete info;
83 else {
84 // Goto next page
85 KAssistantDialog::next();
86 // Disable back & finish
87 setValid( currentPage(), false );
88 // Start import
89 FilterInfo *info = new FilterInfo(importpage, this, selfilterpage->removeDupMsg_checked());
90 info->setStatusMsg(i18n("Import in progress"));
91 info->clear(); // Clear info from last time
92 info->setRootCollection( selectedCollection );
93 selectedFilter->import(info);
94 info->setStatusMsg(i18n("Import finished"));
95 // Cleanup
96 delete info;
97 // Enable finish & back buttons
98 setValid( currentPage(), true );
100 } else KAssistantDialog::next();
103 void KMailCVT::reject() {
104 if ( currentPage() == page2 )
105 FilterInfo::terminateASAP(); // ie. import in progress
106 KAssistantDialog::reject();
109 void KMailCVT::collectionChanged( const Akonadi::Collection& selectedCollection )
111 if( selectedCollection.isValid() ){
112 setValid( currentPage(), true );
113 } else {
114 setValid( currentPage(), false );
118 void KMailCVT::help()
120 KAboutApplicationDialog a( KGlobal::mainComponent().aboutData(), this );
121 a.exec();
124 #include "kmailcvt.moc"