kapptemplate.cpp 2.97 KB
Newer Older
1
2
3
4
5
/*
    SPDX-FileCopyrightText: 2008 Anne-Marie Mahfouf <annma@kde.org>

    SPDX-License-Identifier: GPL-2.0-or-later
*/
6

7
#include <KLocalizedString>
Simon Wächter's avatar
Simon Wächter committed
8
#include <KHelpClient>
9

Simon Wächter's avatar
Simon Wächter committed
10
11
12
#include <QPixmap>
#include <QRegExpValidator>

13
#include "choicepage.h"
14
#include "generatepage.h"
15
16
#include "kapptemplate.h"
#include "prefs.h"
17

Simon Wächter's avatar
Simon Wächter committed
18
KAppTemplate::KAppTemplate(QWidget *parent)
19
20
21
    : QWizard()
{
    Q_UNUSED(parent);
22
    setWindowTitle(i18nc("@title:window", "KDE and Qt Template Generator"));
23
24
25
26
27
28
29
30
31
32
33
34
35
36
    setOption(HaveHelpButton, true);
    connect(this, SIGNAL(helpRequested()), this, SLOT(showHelp()));
    addPage(new IntroPage);
    addPage(new ChoicePage);
    addPage(new PropertiesPage);
    addPage(new GeneratePage);
}

KAppTemplate::~KAppTemplate()
{
}

void KAppTemplate::showHelp()
{
Simon Wächter's avatar
Simon Wächter committed
37
    KHelpClient::invokeHelp("kapptemplate-index", "kapptemplate");
38
39
40
41
42
43
}


IntroPage::IntroPage(QWidget *parent)
    : QWizardPage(parent)
{
44
    setTitle(i18nc("@title:tab", "Introduction"));
45
46
47
48
49
50
51
    ui_introduction.setupUi(this);
}

PropertiesPage::PropertiesPage(QWidget *parent) //in its own file?
    : QWizardPage(parent)
{
    setTitle(i18n("Set the project properties"));
52
    setCommitPage(true);
53
    setButtonText(QWizard::CommitButton, i18nc("@action:button", "Generate"));
54
    ui_properties.setupUi(this);
55

56
57
58
    //float version = Prefs::appVersion().toFloat();
    ui_properties.kcfg_appVersion->setText(Prefs::appVersion());//TODO appVersion+0.1 if already exists
    ui_properties.kcfg_url->setMode(KFile::Directory);
59
    ui_properties.kcfg_url->setUrl(QUrl(Prefs::url()));
60
61
62
    ui_properties.kcfg_name->setText(Prefs::name());
    ui_properties.kcfg_email->setText(Prefs::email());

63
64
65
66
67
    registerField("author",  ui_properties.kcfg_name);
    registerField("email", ui_properties.kcfg_email);
    registerField("version", ui_properties.kcfg_appVersion);
    registerField("url", ui_properties.kcfg_url->lineEdit());

68
69
70
71
72
73
    //get from emaildefaults [PROFILE_Default]
    connect(ui_properties.kcfg_appVersion, SIGNAL(textChanged(const QString &)), this, SIGNAL(completeChanged()));
    connect(ui_properties.kcfg_url, SIGNAL(textChanged(const QString &)), this, SIGNAL(completeChanged()));
    connect(ui_properties.kcfg_name, SIGNAL(textChanged(const QString &)), this, SIGNAL(completeChanged()));
    connect(ui_properties.kcfg_email, SIGNAL(textChanged(const QString &)), this, SIGNAL(completeChanged()));
    connect(this, SIGNAL(completeChanged()), this, SLOT(saveConfig()));
74
    // TODO make some fields mandatory?
75
76
77
78
}

void PropertiesPage::initializePage()
{
79
    appNameString = field("appName").toString();
80
    QString message = i18n("Your project name is: %1", appNameString);
81
82
83
84
85
86
87
88
89
    ui_properties.appNameLabel->setText(message);
}

void PropertiesPage::saveConfig()
{
    Prefs::setAppVersion(ui_properties.kcfg_appVersion->text());
    Prefs::setUrl(ui_properties.kcfg_url->url().path());
    Prefs::setName(ui_properties.kcfg_name->text());
    Prefs::setEmail(ui_properties.kcfg_email->text());
90
    Prefs::setAppName(appNameString);
91
    Prefs::self()->save();
92
}