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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
|
#include <tqvbox.h>
#include <tqlabel.h>
#include <tqpopupmenu.h>
#include <tqsplitter.h>
#include <tqtimer.h>
#include <tqwidgetstack.h>
#include <kpushbutton.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <tdeaction.h>
#include <tdeactionclasses.h>
#include <tdeapplication.h>
#include <kdebug.h>
#include <tdeparts/part.h>
#include <ktrader.h>
#include <klibloader.h>
#include <kstatusbar.h>
#include <kstandarddirs.h>
#include <kprocess.h>
#include <kmenubar.h>
#include <apt-pkg/packagemanager.h>
#include <apt-front/manager.h>
#include <apt-front/init.h>
#include <apt-front/cache/entity/package.h>
#include <apt-front/cache/component/state.h>
#include <apt-front/cache/component/desktop.h>
#include <apt-front/cache/component/history.h>
#include <apt-front/predicate/factory.h>
#include <adept/acqprogresswidget.h>
#include <adept/desktoplist.h>
#include <adept/utils.h>
#include "app.h"
#include <adept/dpkgpm-gui.h> // EVIL
using namespace aptFront;
using namespace cache;
using namespace utils;
using namespace adept;
std::string GroupPolicy::groupForCategories( Range< std::string > r ) {
/* std::cerr << "groupForCategories: ";
for ( Range< std::string > i = r; i != i.end(); ++i ) {
std::cerr << *i << " ";
}
std::cerr << std::endl; */
for ( Range< std::string > i = r; i != i.end(); ++i ) {
if ( i->find( "X-TDE-settings" ) != std::string::npos )
return "Settings";
if ( i->find( "X-TDE-information" ) != std::string::npos )
return "Settings";
}
if ( r.contains( "Development" ) ) return "Development";
if ( !r.contains( "Education" ) ) {
if ( r.contains( "Astronomy" ) || r.contains( "Biology" )
|| r.contains( "Chemistry" ) || r.contains( "Geology" )
|| r.contains( "MedicalSoftware" ) || r.contains( "Physics" )
|| r.contains( "Math" ) || r.contains( "Science" ) )
return "Science";
} else {
return "Edutainment";
}
if ( r.contains( "Game" ) ) return "Games";
if ( r.contains( "Graphics" ) ) return "Graphics";
if ( r.contains( "Network" ) ) return "Internet";
if ( r.contains( "AudioVideo" ) ) return "Multimedia";
if ( r.contains( "Office" ) ) return "Office";
if ( r.contains( "Settings" ) ) return "Settings";
if ( r.contains( "System" ) ) return "System";
if ( r.contains( "Utility" ) ) {
if ( r.contains( "Accessibility" ) )
return "Accessibility";
return "Utilities";
}
return "Others";
}
TQString IconPolicy::iconForGroup( TQString g ) {
if ( g == u8( "Office" ) ) return u8( "package_wordprocessing" );
if ( g == u8( "Internet" ) ) return u8( "package_network" );
if ( g == u8( "Science" ) ) return u8( "edu_science" );
if ( g == u8( "Accessibility" ) ) return u8( "access" );
if ( g == u8( "Others" ) ) return u8( "package" );
return TQString( "package_" ) + g.lower();
}
void WaitForLister::waiting()
{
kdDebug() << "WaitForLister::waiting()" << endl;
/* if (app->m_list->lister()->busy())
TQTimer::singleShot( 100, this, TQT_SLOT( waiting() ) );
else */ {
TQTimer::singleShot( 0, app, slot );
deleteLater();
}
}
App::App() {
m_all = new TQVBox( this );
m_stack = new TQWidgetStack( m_all );
m_stack->addWidget( m_loading = new TQLabel( i18n( "Loading, please wait..." ), m_stack ) );
m_loading->setAlignment( TQt::AlignHCenter | TQt::AlignVCenter );
m_buttons = new TQHBox( m_all );
m_editSources = new KPushButton( i18n( "Edit Software Sources" ), m_buttons );
m_reviewChanges = new KPushButton( i18n( "Review Changes" ), m_buttons );
TQLabel *space = new TQLabel( m_buttons ); // spacing
m_next = new KPushButton( i18n( "Next" ), m_buttons );
m_quit = new KPushButton( i18n( "Quit" ), m_buttons );
m_editSources->setEnabled( false );
m_reviewChanges->setEnabled( false );
m_next->setEnabled( false );
m_quit->setEnabled( false );
m_buttons->setSpacing( 2 );
m_buttons->setMargin( 2 );
TQSizePolicy buttons( TQSizePolicy::Preferred, TQSizePolicy::Fixed, false );
m_buttons->setSizePolicy( buttons );
m_next->setSizePolicy( buttons );
m_quit->setSizePolicy( buttons );
space->setSizePolicy( TQSizePolicy(
TQSizePolicy::Expanding,
TQSizePolicy::Fixed, false ) );
setStandardToolBarMenuEnabled( false );
createStandardStatusBarAction();
setupActions();
setupGUI( Keys|StatusBar|Save|Create );
delete toolBar();
menuBar()->hide();
Application::setStatusBar( statusBar() );
TQTimer::singleShot(
0, this,
TQT_SLOT( delayed() ) );
setCentralWidget( m_all );
setMinimumSize( 400, 300 );
}
void App::delayed() {
initialize();
cache().addComponent( new component::Desktop() );
TDEGlobal::dirs()->addResourceDir(
"desktopicon",
u8( INSTALLER_DATA "/icons/" ) );
cache().component< component::Desktop >().setPolicy( new GroupPolicy() );
cache().component< component::Desktop >().loadDirectory(
INSTALLER_DATA "/desktop/" );
TQFile file(TQString("/usr/bin/software-properties-kde"));
if (file.exists()) {
connect( m_editSources, TQT_SIGNAL( clicked() ), this, TQT_SLOT( editSources() ) );
m_editSources->setEnabled( true );
}
connect( m_reviewChanges, TQT_SIGNAL( clicked() ), this, TQT_SLOT( togglePreview() ) );
m_reviewChanges->setEnabled( true );
connect( m_quit, TQT_SIGNAL( clicked() ), this, TQT_SLOT( close() ) );
m_quit->setEnabled( true );
m_stack->addWidget( m_view = new InstallerView( m_stack ) );
connect( m_view->selector(), TQT_SIGNAL( request( cache::entity::Package,
cache::component::State::Action ) ),
this, TQT_SLOT( request( cache::entity::Package,
cache::component::State::Action ) ) );
m_stack->addWidget( m_preview = new Browser( m_stack ) );
m_preview->searchView()->setPreviewMode();
m_view->selector()->setPolicy( new IconPolicy() );
m_stack->addWidget(
m_bye = new TQLabel( i18n( "Installation Complete!" ), m_stack ) );
m_bye->setAlignment( TQt::AlignHCenter | TQt::AlignVCenter );
m_stack->addWidget( m_progress = new adept::AcqProgressWidget( m_stack ) );
m_stack->addWidget( m_commitProgress = new CommitProgress( m_stack ) );
m_stack->raiseWidget( m_view );
statusBar()->clear();
m_view->rebuild();
start();
}
bool App::confirmRequest( entity::Package p, component::State::Action a )
{
component::Desktop &d = cache::Global::get().component< component::Desktop >();
typedef predicate::AttributeAdaptor< entity::Desktop,
predicate::match::Exact< entity::Package > > Adaptor;
TQString t;
if ( a == component::State::ARemove )
t = i18n( "You selected to remove a program. Following applications "
"are part of the same package, and they will be removed."
" Are you sure you want to remove? " );
else
return true;
// create modal dialog for the question
KDialogBase *db = new KDialogBase( KDialogBase::Plain, i18n( "Confirm action" ),
KDialogBase::Ok | KDialogBase::Cancel,
KDialogBase::Ok, this );
TQVBoxLayout *layout = new TQVBoxLayout( db->plainPage() );
layout->setSpacing( 4 );
// db->plainPage()->setLayout( layout = new TQVBoxLayout( db->plainPage() ) );
// TQVBox *vb = new TQVBox( db );
TQLabel *txt = new TQLabel( db->plainPage() );
txt->setAlignment( TQt::AlignLeft | TQt::AlignTop | TQt::WordBreak );
txt->setMinimumWidth( 500 );
txt->setText( t );
txt->setFixedHeight( txt->heightForWidth( 320 ) );
txt->setSizePolicy( TQSizePolicy(
TQSizePolicy::Expanding, TQSizePolicy::Fixed, false ) );
DesktopList *l = new DesktopList( db->plainPage() );
l->setMinimumHeight( 220 );
l->setMinimumWidth( 320 );
l->setDisplayCheckboxes( false );
layout->addWidget( txt );
layout->addWidget( l );
l->insertRange( filteredRange( d.entries(),
Adaptor( &entity::Desktop::package, p ) ) );
db->adjustSize();
connect( db, TQT_SIGNAL( okClicked() ), this, TQT_SLOT( requestOk() ) );
m_currentRequestOk = false;
db->exec();
return m_currentRequestOk;
}
void App::request( entity::Package p, component::State::Action a ) {
if ( !confirmRequest( p, a ) ) return;
RequestList::iterator rm = m_requests.end(), i;
for ( i = m_requests.begin(); i != m_requests.end(); ++i ) {
if ( i->first == p ) {
rm = i;
break;
}
}
if ( rm != m_requests.end() )
m_requests.erase( rm );
if ( a != component::State::AKeep )
m_requests.push_back( std::make_pair( p, a ) );
cache::Global::get().state().revert();
cache::Global::get().state().replay( range( m_requests.begin(),
m_requests.end() ) );
}
bool App::consistent() {
int remove = 0;
RequestList::iterator i;
for ( i = m_requests.begin(); i != m_requests.end(); ++i ) {
if ( i->second == component::State::ARemove ) {
++remove;
}
}
if ( remove >= cache::Global::get().state().removeCount() )
return true;
return false;
}
void App::setupActions()
{
KStdAction::quit( TQT_TQOBJECT(kapp), TQT_SLOT( quit() ), actionCollection() );
m_undo = KStdAction::undo( TQT_TQOBJECT(this), TQT_SLOT( undo() ), actionCollection() );
m_redo = KStdAction::redo( TQT_TQOBJECT(this), TQT_SLOT( redo() ), actionCollection() );
m_previewAction = new TDEToggleAction(
i18n( "Review Changes" ), u8( "adept_preview" ),
0, TQT_TQOBJECT(this), TQT_SLOT( togglePreview() ), actionCollection(),
"review" );
setHistoryEnabled( false );
createStandardStatusBarAction();
}
void App::togglePreview()
{
if ( m_state == Preview ) {
m_previewAction->setChecked( false );
setState( Select );
m_stack->raiseWidget( m_view );
notifyPostChange( 0 );
m_reviewChanges->setEnabled(true);
} else {
setState( Preview );
m_stack->raiseWidget( m_preview );
setNext( i18n( "Back to Program Selection" ), TQT_SLOT( togglePreview() ) );
m_previewAction->setChecked( true );
m_preview->searchView()->lister()->scheduleRebuild();
m_reviewChanges->setEnabled(false);
}
}
void App::inspect()
{
m_state = Inspect;
m_stack->raiseWidget( m_preview );
setNext( i18n( "Changes are OK, proceed" ), TQT_SLOT( commit() ) );
m_preview->searchView()->lister()->scheduleRebuild();
}
void App::setHistoryEnabled( bool e ) {
if ( e && history() ) {
m_undo->setEnabled( history()->canUndo() );
m_redo->setEnabled( history()->canRedo() );
} else {
m_undo->setEnabled( false );
m_redo->setEnabled( false );
}
}
void App::notifyPreRebuild( component::Base *b )
{
m_requests.clear();
}
void App::notifyPreChange( component::Base *b )
{
Application::notifyPreChange( b );
checkpoint();
}
void App::notifyPostChange( component::Base *b )
{
Application::notifyPostChange( b );
if ( m_state == Select ) {
if ( cache().state().changed() )
if ( consistent() )
setNext( i18n( "Apply Changes" ), TQT_SLOT( commit() ) );
else
setNext( i18n( "Inspect Changes" ), TQT_SLOT( inspect() ) );
else
disableNext();
}
}
void App::setNext( TQString s, const char *slot ) {
m_next->setText( s );
m_next->setEnabled( true );
m_next->disconnect( this );
connect( m_next, TQT_SIGNAL( clicked() ),
this, slot );
m_quit->setEnabled( true );
}
void App::disableNext() {
m_next->setText( i18n( "Next" ) );
m_next->setEnabled( false );
disconnect( m_next, TQT_SIGNAL( clicked() ), 0, 0 );
}
void App::disableButtons() {
disableNext();
m_quit->setEnabled( false );
}
void App::editSources() {
TDEProcess* softwarePropertiesProcess = new TDEProcess(TQT_TQOBJECT(this));
*softwarePropertiesProcess << "/usr/bin/software-properties-kde";
softwarePropertiesProcess->start();
}
void App::start() {
m_stack->raiseWidget( m_view );
m_quit->setText( i18n( "Forget Changes and Quit" ) );
disableNext();
setState( Select );
notifyPostChange( 0 );
}
void App::commit() {
kdDebug() << "App::commit" << endl;
setState( Commit );
disableButtons();
setHistoryEnabled( false );
aptFront::Manager m;
m.setProgressCallback( m_progress->callback() );
m.setUpdateInterval( 100000 );
try {
m_stack->raiseWidget( m_progress );
m.download();
m_stack->raiseWidget( m_commitProgress );
m.commit();
} catch ( exception::OperationCancelled ) {
return start();
} catch ( ... ) {
KMessageBox::sorry(
this, i18n( "There was an error commiting changes. "
"Possibly there was a problem downloading some "
"packages or the commit would break packages. " ),
i18n( "Could not commit changes" ) );
}
cache().addComponent( new component::Desktop() );
cache().component< component::Desktop >().setPolicy( new GroupPolicy() );
cache().component< component::Desktop >().loadDirectory(
INSTALLER_DATA "/desktop/" );
TQTimer::singleShot( 500, m_view, TQT_SLOT( rebuild() ) );
m_stack->raiseWidget( m_bye );
m_quit->setText( i18n( "Quit" ) );
setNext( i18n( "Back to Program Selection" ), TQT_SLOT( start() ) );
// setNext( i18n( "Done: Quit" ), TQT_SLOT( close() ) );
}
#include "app.moc"
|