1
/***************************************************************************
2
* Copyright © 2010 Jonathan Thomas <echidnaman@kubuntu.org> *
4
* This program is free software; you can redistribute it and/or *
5
* modify it under the terms of the GNU General Public License as *
6
* published by the Free Software Foundation; either version 2 of *
7
* the License or (at your option) version 3 or any later version *
8
* accepted by the membership of KDE e.V. (or its successor approved *
9
* by the membership of KDE e.V.), which shall act as a proxy *
10
* defined in Section 14 of version 3 of the license. *
12
* This program is distributed in the hope that it will be useful, *
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
* GNU General Public License for more details. *
17
* You should have received a copy of the GNU General Public License *
18
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
19
***************************************************************************/
24
#include <QtGui/QHBoxLayout>
25
#include <QtGui/QLabel>
26
#include <QtGui/QPushButton>
27
#include <QtGui/QToolButton>
28
#include <QtGui/QVBoxLayout>
38
#include <KMessageBox>
39
#include <KTextBrowser>
42
#include <LibQApt/Backend>
43
#include <LibQApt/Package>
45
MainTab::MainTab(QWidget *parent)
50
QVBoxLayout *layout = new QVBoxLayout(this);
52
layout->setSpacing(0);
54
KHBox *headerBox = new KHBox(this);
55
layout->addWidget(headerBox);
56
m_packageShortDescLabel = new QLabel(headerBox);
57
m_packageShortDescLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
60
m_packageShortDescLabel->setFont(font);
62
QWidget *buttonBox = new QWidget(headerBox);
64
QHBoxLayout *buttonBoxLayout = new QHBoxLayout(buttonBox);
65
buttonBoxLayout->setMargin(0);
66
buttonBoxLayout->setSpacing(KDialog::spacingHint());
68
QLabel *buttonLabel = new QLabel(buttonBox);
69
buttonLabel->setText(i18nc("@label", "Mark for:"));
70
buttonBoxLayout->addWidget(buttonLabel);
72
m_installButton = new QPushButton(buttonBox);
73
m_installButton->setIcon(KIcon("download"));
74
m_installButton->setText(i18nc("@action:button", "Installation"));
75
connect(m_installButton, SIGNAL(clicked()), this, SLOT(emitSetInstall()));
76
buttonBoxLayout->addWidget(m_installButton);
78
m_removeButton = new QToolButton(buttonBox);
79
m_removeButton->setPopupMode(QToolButton::MenuButtonPopup);
80
m_removeButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
81
m_removeButton->setIcon(KIcon("edit-delete"));
82
m_removeButton->setText(i18nc("@action:button", "Removal"));
83
connect(m_removeButton, SIGNAL(clicked()), this, SLOT(emitSetRemove()));
84
buttonBoxLayout->addWidget(m_removeButton);
86
m_upgradeButton = new QPushButton(buttonBox);
87
m_upgradeButton->setIcon(KIcon("system-software-update"));
88
m_upgradeButton->setText(i18nc("@action:button", "Upgrade"));
89
connect(m_upgradeButton, SIGNAL(clicked()), this, SLOT(emitSetInstall()));
90
buttonBoxLayout->addWidget(m_upgradeButton);
92
m_reinstallButton = new QPushButton(buttonBox);
93
m_reinstallButton->setIcon(KIcon("view-refresh"));
94
m_reinstallButton->setText(i18nc("@action:button", "Reinstallation"));
95
connect(m_reinstallButton, SIGNAL(clicked()), this, SLOT(emitSetReInstall()));
96
buttonBoxLayout->addWidget(m_reinstallButton);
98
m_purgeMenu = new KMenu(m_removeButton);
99
m_purgeAction = new KAction(this);
100
m_purgeAction->setIcon(KIcon("edit-delete-shred"));
101
m_purgeAction->setText(i18nc("@action:button", "Purge"));
102
connect(m_purgeAction, SIGNAL(triggered()), this, SLOT(emitSetPurge()));
103
m_purgeMenu->addAction(m_purgeAction);
104
m_removeButton->setMenu(m_purgeMenu);
106
m_purgeButton = new QPushButton(buttonBox);
107
m_purgeButton->setIcon(m_purgeAction->icon());
108
m_purgeButton->setText(m_purgeAction->text());
109
connect(m_purgeButton, SIGNAL(clicked()), this, SLOT(emitSetPurge()));
110
buttonBoxLayout->addWidget(m_purgeButton);
112
m_cancelButton = new QPushButton(buttonBox);
113
m_cancelButton->setIcon(KIcon("dialog-cancel"));
114
m_cancelButton->setText(i18nc("@action:button", "Unmark"));
115
connect(m_cancelButton, SIGNAL(clicked()), this, SLOT(emitSetKeep()));
116
buttonBoxLayout->addWidget(m_cancelButton);
118
m_descriptionBrowser = new KTextBrowser(this);
119
layout->addWidget(m_descriptionBrowser);
126
void MainTab::setBackend(QApt::Backend *backend)
131
void MainTab::setPackage(QApt::Package *package)
137
void MainTab::clear()
142
void MainTab::refresh()
145
return; // Nothing to refresh yet, so return, else we crash
147
int state = m_package->state();
148
bool upgradeable = (state & QApt::Package::Upgradeable);
150
if (state & QApt::Package::Installed) {
151
m_installButton->hide();
152
m_removeButton->show();
154
m_upgradeButton->show();
156
m_upgradeButton->hide();
158
if (state & (QApt::Package::NotDownloadable) || upgradeable) {
159
m_reinstallButton->hide();
161
m_reinstallButton->show();
163
m_cancelButton->hide();
164
m_purgeButton->hide();
165
} else if (state & QApt::Package::ResidualConfig) {
166
m_purgeButton->show();
167
m_installButton->show();
168
m_removeButton->hide();
169
m_upgradeButton->hide();
170
m_reinstallButton->hide();
171
m_cancelButton->hide();
173
m_installButton->show();
174
m_removeButton->hide();
175
m_upgradeButton->hide();
176
m_reinstallButton->hide();
177
m_purgeButton->hide();
178
m_cancelButton->hide();
182
if (state & (QApt::Package::ToInstall | QApt::Package::ToReInstall |
183
QApt::Package::ToUpgrade | QApt::Package::ToDowngrade |
184
QApt::Package::ToRemove | QApt::Package::ToPurge)) {
185
m_installButton->hide();
186
m_removeButton->hide();
187
m_upgradeButton->hide();
188
m_reinstallButton->hide();
189
m_cancelButton->show();
192
m_packageShortDescLabel->setText(m_package->shortDescription());
194
m_descriptionBrowser->setText(m_package->longDescription());
196
// Append a newline to give a bit of separation for the support string
197
m_descriptionBrowser->append(QString());
198
if (m_package->isSupported()) {
199
m_descriptionBrowser->append(i18nc("@info Tells how long Canonical, Ltd. will support a package",
200
"Canonical provides critical updates for %1 until %2.",
201
m_package->latin1Name(), m_package->supportedUntil()));
203
m_descriptionBrowser->append(i18nc("@info Tells how long Canonical, Ltd. will support a package",
204
"Canonical does not provide updates for %1. Some updates "
205
"may be provided by the Ubuntu community.", m_package->latin1Name()));
209
void MainTab::emitSetInstall()
211
emit setInstall(m_package);
214
void MainTab::emitSetRemove()
216
emit setRemove(m_package);
219
void MainTab::emitSetUpgrade()
221
emit setUpgrade(m_package);
224
void MainTab::emitSetReInstall()
226
emit setReInstall(m_package);
229
void MainTab::emitSetKeep()
231
emit setKeep(m_package);
234
void MainTab::emitSetPurge()
236
emit setPurge(m_package);
239
#include "MainTab.moc"