-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpkginstallOptions.cpp
194 lines (154 loc) · 4.54 KB
/
pkginstallOptions.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/////////////////////////////////////////////////////////////////////////////////
// $Id: pkginstallOptions.cpp 21211 1999-05-11 09:16:28Z bieker $
//
// File : pkginstallOptions.cpp
// Author: Damyan Pepper
// Author: Toivo Pedaste
//
#include "config.h"
// qt headers
#include <qlabel.h>
// ksetup headers
#include "pkginstallOptions.h"
#include "managementWidget.h"
#include "debInterface.h"
#include "kpackage.h"
#include <klocale.h>
// Constructor -- set the frame style, and setup the sub widgets
pkginstallOptionsWidget::pkginstallOptionsWidget(param *pars, QWidget *parent,
const char *name)
: QFrame(parent,name)
{
setFrameStyle(QFrame::Raised | QFrame::Panel);
setupWidgets(pars);
package = 0;
}
// Destructor
pkginstallOptionsWidget::~pkginstallOptionsWidget()
{
int i;
for (i = 0; i < bnumber; i++) {
delete(Boxs[i]);
}
delete []Boxs;
}
// Set up the sub-widgets
void pkginstallOptionsWidget::setupWidgets(param *pars)
{
int i;
// Create widgets
title = new QLabel(i18n("Install Package"), this);
title->setFont(QFont("Helvetica",18, QFont::Bold));
title->setAutoResize(TRUE);
title->update();
installButton = new QPushButton(i18n("Install"),this);
cancelButton = new QPushButton(i18n("Cancel"),this);
// count number of buttons
for (bnumber = 0; pars[bnumber].name != 0; bnumber++);
Boxs = new QCheckBox *[bnumber];
for (i = 0; i < bnumber ; i++) {
Boxs[i] = new QCheckBox(pars[i].name, this);
Boxs[i]->setChecked(pars[i].init);
}
// Connections
connect(installButton,SIGNAL(clicked()),SLOT(pkginstallButtonClicked()));
connect(cancelButton,SIGNAL(clicked()),SLOT(cancelButtonClicked()));
// Do the layout
layout = new QBoxLayout(this,QBoxLayout::TopToBottom,bnumber);
QBoxLayout *buttons = new QBoxLayout(QBoxLayout::LeftToRight);
layout->addWidget(title,1);
layout->addStretch(1);
for (i = 0; i < bnumber; i++) {
layout->addWidget(Boxs[i],1);
}
layout->addStretch(2);
layout->addLayout(buttons);
#if QT_VERSION < 200
buttons->addStrut(20);
#endif
buttons->addWidget(installButton,2);
buttons->addStretch(1);
buttons->addWidget(cancelButton,2);
layout->activate();
}
// Set the current package that is being worked with
void pkginstallOptionsWidget::setPackage(packageInfo *p)
{
package = p;
}
// install button has been clicked....so install the package
void pkginstallOptionsWidget::pkginstallButtonClicked()
{
// Disable the buttons
int i, r;
installButton->setEnabled(FALSE);
cancelButton->setEnabled(FALSE);
for (i = 0; i < bnumber; i++) {
Boxs[i]->setEnabled(FALSE);
}
// Collect data from check boxes
int installFlags = 0;
for (i = 0; i < bnumber; i++) {
installFlags |= (Boxs[i]->isChecked()) << i;
}
// interfaceFlags|=INSTALL_PERCENT;
r = package->interface->install(installFlags, package);
// enable the buttons
installButton->setEnabled(TRUE);
cancelButton->setEnabled(TRUE);
for (i = 0; i < bnumber; i++) {
Boxs[i]->setEnabled(TRUE);
}
// Emit the finished signal to indicate that installation is complete
if (!r) {
kpkg->kp->management->updatePackage(package,TRUE);
emit finished(0);
}
}
// Cancel button has been clicked -- finish without doing anything
void pkginstallOptionsWidget::cancelButtonClicked()
{
kpkg->kp->management->updatePackage(package,TRUE);
emit finished(0);
}
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
pkginstallOptionsWidgetMult::pkginstallOptionsWidgetMult
(param *pars, QWidget *parent, const char *name)
: pkginstallOptionsWidget(pars, parent, name)
{
notModified = TRUE;
}
pkginstallOptionsWidgetMult::~pkginstallOptionsWidgetMult()
{
}
void pkginstallOptionsWidgetMult::setup(QList<packageInfo> *pl, QString type)
{
QString s;
packList = pl;
s.sprintf(i18n("Install: %d %s Packages"),packList->count(),type.data());
title->setText(s.data());
}
void pkginstallOptionsWidgetMult::pkginstallButtonClicked()
{
int i, r;
notModified = FALSE;
// Collect data from check boxes
int installFlags = 0;
for (i = 0; i < bnumber; i++) {
installFlags |= (Boxs[i]->isChecked()) << i;
}
// interfaceFlags|=INSTALL_PERCENT;
r = packList->first()->interface->install(installFlags, packList);
// Emit the finished signal to indicate that installation is complete
if (!r) {
emit finished(1);
}
}
void pkginstallOptionsWidgetMult::cancelButtonClicked()
{
if (notModified)
emit finished(0);
else
emit finished(1);
}