-
Notifications
You must be signed in to change notification settings - Fork 0
/
startpage.cpp
144 lines (119 loc) · 4.6 KB
/
startpage.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
Copyright (c) 2009 Riccardo Iaconelli <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
*/
#include <QLabel>
#include <QComboBox>
#include <QListWidget>
#include <QListWidgetItem>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QModelIndex>
#include <QAbstractItemModel>
#include <KUser>
// #include <KLocalizedString>
#include <KDebug>
#include <KLineEdit>
#include <KPushButton>
#include <KSeparator>
#include <KUrlRequester>
#include <KStandardDirs>
#include "packagemodel.h"
#include "startpage.h"
#include "mainwindow.h"
#include "ui_startpage.h"
StartPage::StartPage(MainWindow *parent) // TODO set a palette so it will look identical with any color scheme.
: QWidget(parent),
m_parent(parent)
{
setupWidgets();
refreshRecentProjectsList();
}
StartPage::~StartPage()
{
delete ui;
}
void StartPage::setupWidgets()
{
ui = new Ui::StartPage;
ui->setupUi(this);
// Enforce the security restriction from package.cpp in the input field
QRegExpValidator *pluginname_validator = new QRegExpValidator(ui->projectName);
QRegExp validatePluginName("^[\\w-\\.]+$"); // Only allow letters, numbers, underscore and period. FIXME doesn't work
pluginname_validator->setRegExp(validatePluginName);
connect(ui->recentProjects, SIGNAL(clicked(const QModelIndex)),
this, SLOT(emitProjectSelected(const QModelIndex)));
connect(ui->contentTypes, SIGNAL(clicked(const QModelIndex)),
this, SLOT(changeStackedWidgetPage()));
connect(ui->newProjectButton, SIGNAL(clicked()),
this, SLOT(createNewProject()));
new QListWidgetItem(KIcon("application-x-plasma"), i18n("Plasmoid"), ui->contentTypes);
new QListWidgetItem(KIcon("kexi"), i18n("Data Engine"), ui->contentTypes);
new QListWidgetItem(KIcon("system-run"), i18n("Runner"), ui->contentTypes);
new QListWidgetItem(KIcon("inkscape"), i18n("Theme"), ui->contentTypes);
// connect(ui->newProjectButton, SIGNAL(clicked()), this, SLOT(launchNewProjectWizard()));
}
void StartPage::changeStackedWidgetPage()
{
ui->layoutHackStackedWidget->setCurrentIndex(1);
}
void StartPage::resetStatus()
{
kDebug() << "Reset status!";
ui->layoutHackStackedWidget->setCurrentIndex(0);
refreshRecentProjectsList();
}
void StartPage::refreshRecentProjectsList()
{
ui->recentProjects->clear();
QStringList recentFiles = m_parent->recentProjects();
for (int i = 0; i < recentFiles.size(); i++) {
Plasma::PackageMetadata metadata(KStandardDirs::locateLocal("appdata", recentFiles.at(i) + '/'));
QString projectName = metadata.name();
// if (projectName.isEmpty()) {
// continue;
// }
kDebug() << "adding" << projectName << "to the list of recent projects...";
QListWidgetItem *item = new QListWidgetItem(projectName); // TODO make me the user "nice" name
item->setData(FullPathRole, projectName);
QString serviceType = metadata.serviceType();
if ( serviceType == QString("Plasma/Applet") ) {
item->setIcon(KIcon("application-x-plasma"));
} else if ( serviceType == QString("Plasma/DataEngine") ) {
item->setIcon(KIcon("kexi"));
} else if ( serviceType == QString("Plasma/Theme") ) {
item->setIcon(KIcon("inkscape"));
} else if ( serviceType == QString("Plasma/Runner") ) {
item->setIcon(KIcon("system-run"));
} else {
kWarning() << "Unknown service type" << serviceType;
}
ui->recentProjects->addItem(item);
}
}
void StartPage::createNewProject()
{
// TODO
// metadata->setPluginName( view->pluginname_edit->text() );
QString type;
if (ui->contentTypes->currentRow() == 0) {
type = "Plasma/Applet";
} else if (ui->contentTypes->currentRow() == 1) {
type = "Plasma/DataEngine";
} else if (ui->contentTypes->currentRow() == 2) {
type = "Plasma/Theme";
} else if (ui->contentTypes->currentRow() == 3) {
type = "Plasma/Runner";
}
emit projectSelected(ui->projectName->text().toLower(), type);
}
void StartPage::emitProjectSelected(const QModelIndex &index)
{
QAbstractItemModel *m = ui->recentProjects->model();
QString url = m->data(index, FullPathRole).value<QString>();
kDebug() << "Loading project file:" << m->data(index, FullPathRole);
emit projectSelected(url, QString());
}