1 /***************************************************************************
2 kmailcvt.cpp - description
4 copyright : (C) 2003 by Laurence Anderson
5 email : l.d.anderson@warwick.ac.uk
6 ***************************************************************************/
8 /***************************************************************************
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. *
15 ***************************************************************************/
19 #include "kimportpage.h"
20 #include "kselfilterpage.h"
21 #include "filters.hxx"
24 #include <kaboutapplicationdialog.h>
28 #include <ktoolinvocation.h>
31 #include <QPushButton>
33 #include <akonadi/control.h>
36 KMailCVT::KMailCVT(QWidget
*parent
)
37 : KAssistantDialog(parent
) {
39 setWindowTitle( i18n( "KMailCVT Import Tool" ) );
42 selfilterpage
= new KSelFilterPage
;
43 page1
= new KPageWidgetItem( selfilterpage
, i18n( "Step 1: Select Filter" ) );
47 importpage
= new KImportPage
;
48 page2
= new KPageWidgetItem( importpage
, i18n( "Step 2: Importing..." ) );
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);
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
)
73 // Ensure we have a valid collection.
74 if( !selectedCollection
.isValid() )
76 if ( !selectedFilter
->needsSecondPage() ) {
77 FilterInfo
*info
= new FilterInfo( importpage
, this, selfilterpage
->removeDupMsg_checked() );
78 info
->setRootCollection( selectedCollection
);
79 selectedFilter
->import( info
);
85 KAssistantDialog::next();
86 // Disable back & finish
87 setValid( currentPage(), false );
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"));
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 );
114 setValid( currentPage(), false );
118 void KMailCVT::help()
120 KAboutApplicationDialog
a( KGlobal::mainComponent().aboutData(), this );
124 #include "kmailcvt.moc"