1/*
2 Copyright (c) 2009 Volker Krause <vkrause@kde.org>
3 Copyright (c) 2010 Tom Albers <toma@kde.org>
4
5 This library is free software; you can redistribute it and/or modify it
6 under the terms of the GNU Library General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or (at your
8 option) any later version.
9
10 This library is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 02110-1301, USA.
19*/
20
21#include "dialog.h"
22#include "personaldatapage.h"
23#ifndef ACCOUNTWIZARD_NO_GHNS
24#include "providerpage.h"
25#endif
26#include "typepage.h"
27#include "loadpage.h"
28#include "global.h"
29#include "dynamicpage.h"
30#include "setupmanager.h"
31#include "servertest.h"
32#include "setuppage.h"
33
34#include <KMime/Message>
35
36#include <klocalizedstring.h>
37#include <kross/core/action.h>
38#include <kdebug.h>
39#include <kmessagebox.h>
40
41#include <qplatformdefs.h>
42
43Dialog::Dialog(QWidget* parent, Qt::WindowFlags flags ) :
44 KAssistantDialog( parent, flags )
45{
46#if defined (Q_WS_MAEMO_5) || defined (MEEGO_EDITION_HARMATTAN)
47 setWindowState( Qt::WindowFullScreen );
48#endif
49
50 showButton( Help, false ); // we don't have help for the account wizard atm
51
52 mSetupManager = new SetupManager( this );
53 const bool showPersonalDataPage = Global::typeFilter().size() == 1 && Global::typeFilter().first() == KMime::Message::mimeType();
54
55 if ( showPersonalDataPage ) {
56 // todo: dont ask these details based on a setting of the desktop file.
57 PersonalDataPage *pdpage = new PersonalDataPage( this );
58 addPage( pdpage, i18n( "Provide personal data" ) );
59 connect( pdpage, SIGNAL(manualWanted(bool)), SLOT(slotManualConfigWanted(bool)) );
60 if ( !Global::assistant().isEmpty() ) {
61 pdpage->setHideOptionInternetSearch( true );
62 }
63 }
64
65 if ( Global::assistant().isEmpty() ) {
66 TypePage* typePage = new TypePage( this );
67 connect( typePage->treeview(), SIGNAL(doubleClicked(QModelIndex)), SLOT(slotNextPage()) );
68#ifndef ACCOUNTWIZARD_NO_GHNS
69 connect( typePage, SIGNAL(ghnsWanted()), SLOT(slotGhnsWanted()) );
70#endif
71 mTypePage = addPage( typePage, i18n( "Select Account Type" ) );
72 setAppropriate( mTypePage, false );
73
74#ifndef ACCOUNTWIZARD_NO_GHNS
75 ProviderPage *ppage = new ProviderPage( this );
76 connect( typePage, SIGNAL(ghnsWanted()), ppage, SLOT(startFetchingData()) );
77 connect( ppage->treeview(), SIGNAL(doubleClicked(QModelIndex)), SLOT(slotNextPage()) );
78 connect( ppage, SIGNAL(ghnsNotWanted()), SLOT(slotGhnsNotWanted()) );
79 mProviderPage = addPage( ppage, i18n( "Select Provider" ) );
80 setAppropriate( mProviderPage, false );
81#endif
82 }
83
84 LoadPage *loadPage = new LoadPage( this );
85 mLoadPage = addPage( loadPage, i18n( "Loading Assistant" ) );
86 setAppropriate( mLoadPage, false );
87 loadPage->exportObject( this, QLatin1String( "Dialog" ) );
88 loadPage->exportObject( mSetupManager, QLatin1String( "SetupManager" ) );
89 loadPage->exportObject( new ServerTest( this ), QLatin1String( "ServerTest" ) );
90 connect( loadPage, SIGNAL(aboutToStart()), SLOT(clearDynamicPages()) );
91
92 SetupPage *setupPage = new SetupPage( this );
93 mLastPage = addPage( setupPage, i18n( "Setting up Account" ) );
94 mSetupManager->setSetupPage( setupPage );
95
96 slotManualConfigWanted( !showPersonalDataPage );
97
98 Page *page = qobject_cast<Page*>( currentPage()->widget() );
99 page->enterPageNext();
100 emit page->pageEnteredNext();
101 enableButton( KDialog::Help, false );
102}
103
104KPageWidgetItem* Dialog::addPage(Page* page, const QString &title)
105{
106 KPageWidgetItem *item = KAssistantDialog::addPage( page, title );
107 connect( page, SIGNAL(leavePageNextOk()), SLOT(slotNextOk()) );
108 connect( page, SIGNAL(leavePageBackOk()), SLOT(slotBackOk()) );
109 page->setPageWidgetItem( item );
110 return item;
111}
112
113
114void Dialog::slotNextPage()
115{
116 next();
117}
118
119void Dialog::next()
120{
121 Page *page = qobject_cast<Page*>( currentPage()->widget() );
122 page->leavePageNext();
123 page->leavePageNextRequested();
124}
125
126void Dialog::slotNextOk()
127{
128 Page *page = qobject_cast<Page*>( currentPage()->widget() );
129 emit page->pageLeftNext();
130 KAssistantDialog::next();
131 page = qobject_cast<Page*>( currentPage()->widget() );
132 page->enterPageNext();
133 emit page->pageEnteredNext();
134}
135
136
137void Dialog::back()
138{
139 Page *page = qobject_cast<Page*>( currentPage()->widget() );
140 page->leavePageBack();
141 page->leavePageBackRequested();
142}
143
144void Dialog::slotBackOk()
145{
146 Page *page = qobject_cast<Page*>( currentPage()->widget() );
147 emit page->pageLeftBack();
148 KAssistantDialog::back();
149 page = qobject_cast<Page*>( currentPage()->widget() );
150 page->enterPageBack();
151 emit page->pageEnteredBack();
152}
153
154QObject* Dialog::addPage(const QString& uiFile, const QString &title )
155{
156 kDebug() << uiFile;
157 DynamicPage *page = new DynamicPage( Global::assistantBasePath() + uiFile, this );
158 connect( page, SIGNAL(leavePageNextOk()), SLOT(slotNextOk()) );
159 connect( page, SIGNAL(leavePageBackOk()), SLOT(slotBackOk()) );
160 KPageWidgetItem* item = insertPage( mLastPage, page, title );
161 page->setPageWidgetItem( item );
162 mDynamicPages.push_back( item );
163 return page;
164}
165
166void Dialog::slotManualConfigWanted( bool show )
167{
168 Q_ASSERT( mTypePage );
169 setAppropriate( mTypePage, show );
170 setAppropriate( mLoadPage, show );
171}
172
173#ifndef ACCOUNTWIZARD_NO_GHNS
174void Dialog::slotGhnsWanted()
175{
176 Q_ASSERT( mProviderPage );
177 setAppropriate( mProviderPage, true );
178 setCurrentPage( mProviderPage );
179}
180
181void Dialog::slotGhnsNotWanted()
182{
183 Q_ASSERT( mProviderPage );
184 setAppropriate( mProviderPage, false );
185}
186#endif
187
188SetupManager* Dialog::setupManager()
189{
190 return mSetupManager;
191}
192
193void Dialog::clearDynamicPages()
194{
195 foreach ( KPageWidgetItem *item, mDynamicPages )
196 removePage( item );
197 mDynamicPages.clear();
198}
199
200void Dialog::reject()
201{
202 connect( mSetupManager, SIGNAL(rollbackComplete()), SLOT(close()) );
203 mSetupManager->requestRollback();
204}
205
206
207