1/*
2 Copyright (c) 2009 Volker Krause <vkrause@kde.org>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
20#include "loadpage.h"
21#include "global.h"
22#include <kassistantdialog.h>
23#include <kconfig.h>
24#include <kconfiggroup.h>
25#include <kross/core/action.h>
26#include <QtCore/qfile.h>
27
28LoadPage::LoadPage(KAssistantDialog* parent) :
29 Page( parent ),
30 m_action( 0 )
31{
32 ui.setupUi( this );
33 setValid( false );
34}
35
36void LoadPage::enterPageNext()
37{
38 setValid( false );
39 // FIXME: deletion seems to delete the exported objects as well, killing the entire wizard...
40 //delete m_action;
41 m_action = 0;
42 emit aboutToStart();
43
44 const KConfig f( Global::assistant() );
45 KConfigGroup grp( &f, "Wizard" );
46 const QString scriptFile = grp.readEntry( "Script", QString() );
47 if ( scriptFile.isEmpty() ) {
48 ui.statusLabel->setText( i18n( "No script specified in '%1'.", Global::assistant() ) );
49 return;
50 }
51 if ( !QFile::exists( Global::assistantBasePath() + scriptFile ) ) {
52 ui.statusLabel->setText( i18n( "Unable to load assistant: File '%1' does not exist.", Global::assistantBasePath() + scriptFile ) );
53 return;
54 }
55 ui.statusLabel->setText( i18n( "Loading script '%1'...", Global::assistantBasePath() + scriptFile ) );
56
57 m_action = new Kross::Action( this, QLatin1String("AccountWizard") );
58 typedef QPair<QObject*, QString> ObjectStringPair;
59 foreach ( const ObjectStringPair &exportedObject, m_exportedObjects )
60 m_action->addQObject( exportedObject.first, exportedObject.second );
61
62 if ( !m_action->setFile( Global::assistantBasePath() + scriptFile ) ) {
63 ui.statusLabel->setText( i18n( "Failed to load script: '%1'.", m_action->errorMessage() ) );
64 return;
65 }
66
67 KConfigGroup grpTranslate( &f, "Translate" );
68 const QString poFileName = grpTranslate.readEntry( "Filename" );
69 if ( !poFileName.isEmpty() )
70 KGlobal::locale()->insertCatalog( poFileName );
71
72 m_action->trigger();
73
74 m_parent->next();
75}
76
77void LoadPage::enterPageBack()
78{
79 // TODO: if we are the first page, call enterPageNext(), hm, can we get here then at all?
80 m_parent->back();
81}
82
83void LoadPage::exportObject(QObject* object, const QString& name)
84{
85 m_exportedObjects.push_back( qMakePair( object, name ) );
86}
87
88
89