~blue-shell/blue-shell/muon-firefox-apps

« back to all changes in this revision

Viewing changes to libmuon/DetailsTabs/MainTab.cpp

  • Committer: Jonathan Thomas
  • Date: 2011-11-06 02:19:48 UTC
  • Revision ID: git-v1:498a98a05157c758a93f50092851c3ede98812f8
These classes are all now only used by MPM due to the new Updater GUI,
so move them out of libmuon and back to the muon folder.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *   Copyright © 2010 Jonathan Thomas <echidnaman@kubuntu.org>             *
3
 
 *                                                                         *
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.                    *
11
 
 *                                                                         *
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.                          *
16
 
 *                                                                         *
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
 
 ***************************************************************************/
20
 
 
21
 
#include "MainTab.h"
22
 
 
23
 
// Qt includes
24
 
#include <QtGui/QHBoxLayout>
25
 
#include <QtGui/QLabel>
26
 
#include <QtGui/QPushButton>
27
 
#include <QtGui/QToolButton>
28
 
#include <QtGui/QVBoxLayout>
29
 
 
30
 
// KDE includes
31
 
#include <KAction>
32
 
#include <KDebug>
33
 
#include <KDialog>
34
 
#include <KHBox>
35
 
#include <KIcon>
36
 
#include <KLocale>
37
 
#include <KMenu>
38
 
#include <KMessageBox>
39
 
#include <KTextBrowser>
40
 
 
41
 
// LibQApt includes
42
 
#include <LibQApt/Backend>
43
 
#include <LibQApt/Package>
44
 
 
45
 
MainTab::MainTab(QWidget *parent)
46
 
    : QWidget(parent)
47
 
    , m_backend(0)
48
 
    , m_package(0)
49
 
{
50
 
    QVBoxLayout *layout = new QVBoxLayout(this);
51
 
    layout->setMargin(0);
52
 
    layout->setSpacing(0);
53
 
    setLayout(layout);
54
 
    KHBox *headerBox = new KHBox(this);
55
 
    layout->addWidget(headerBox);
56
 
    m_packageShortDescLabel = new QLabel(headerBox);
57
 
    m_packageShortDescLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
58
 
    QFont font;
59
 
    font.setBold(true);
60
 
    m_packageShortDescLabel->setFont(font);
61
 
 
62
 
    QWidget *buttonBox = new QWidget(headerBox);
63
 
 
64
 
    QHBoxLayout *buttonBoxLayout = new QHBoxLayout(buttonBox);
65
 
    buttonBoxLayout->setMargin(0);
66
 
    buttonBoxLayout->setSpacing(KDialog::spacingHint());
67
 
 
68
 
    QLabel *buttonLabel = new QLabel(buttonBox);
69
 
    buttonLabel->setText(i18nc("@label", "Mark for:"));
70
 
    buttonBoxLayout->addWidget(buttonLabel);
71
 
 
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);
77
 
 
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);
85
 
 
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);
91
 
 
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);
97
 
 
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);
105
 
 
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);
111
 
 
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);
117
 
 
118
 
    m_descriptionBrowser = new KTextBrowser(this);
119
 
    layout->addWidget(m_descriptionBrowser);
120
 
}
121
 
 
122
 
MainTab::~MainTab()
123
 
{
124
 
}
125
 
 
126
 
void MainTab::setBackend(QApt::Backend *backend)
127
 
{
128
 
    m_backend = backend;
129
 
}
130
 
 
131
 
void MainTab::setPackage(QApt::Package *package)
132
 
{
133
 
    m_package = package;
134
 
    refresh();
135
 
}
136
 
 
137
 
void MainTab::clear()
138
 
{
139
 
    m_package = 0;
140
 
}
141
 
 
142
 
void MainTab::refresh()
143
 
{
144
 
    if (!m_package) {
145
 
        return; // Nothing to refresh yet, so return, else we crash
146
 
    }
147
 
    int state = m_package->state();
148
 
    bool upgradeable = (state & QApt::Package::Upgradeable);
149
 
 
150
 
    if (state & QApt::Package::Installed) {
151
 
        m_installButton->hide();
152
 
        m_removeButton->show();
153
 
        if (upgradeable) {
154
 
            m_upgradeButton->show();
155
 
        } else {
156
 
            m_upgradeButton->hide();
157
 
        }
158
 
        if (state & (QApt::Package::NotDownloadable) || upgradeable) {
159
 
            m_reinstallButton->hide();
160
 
        } else {
161
 
            m_reinstallButton->show();
162
 
        }
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();
172
 
    } else {
173
 
        m_installButton->show();
174
 
        m_removeButton->hide();
175
 
        m_upgradeButton->hide();
176
 
        m_reinstallButton->hide();
177
 
        m_purgeButton->hide();
178
 
        m_cancelButton->hide();
179
 
    }
180
 
 
181
 
    // If status changed
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();
190
 
    }
191
 
 
192
 
    m_packageShortDescLabel->setText(m_package->shortDescription());
193
 
 
194
 
    m_descriptionBrowser->setText(m_package->longDescription());
195
 
 
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()));
202
 
    } else {
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()));
206
 
    }
207
 
}
208
 
 
209
 
void MainTab::emitSetInstall()
210
 
{
211
 
    emit setInstall(m_package);
212
 
}
213
 
 
214
 
void MainTab::emitSetRemove()
215
 
{
216
 
    emit setRemove(m_package);
217
 
}
218
 
 
219
 
void MainTab::emitSetUpgrade()
220
 
{
221
 
    emit setUpgrade(m_package);
222
 
}
223
 
 
224
 
void MainTab::emitSetReInstall()
225
 
{
226
 
    emit setReInstall(m_package);
227
 
}
228
 
 
229
 
void MainTab::emitSetKeep()
230
 
{
231
 
    emit setKeep(m_package);
232
 
}
233
 
 
234
 
void MainTab::emitSetPurge()
235
 
{
236
 
    emit setPurge(m_package);
237
 
}
238
 
 
239
 
#include "MainTab.moc"