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
|
#include <qvbox.h>
#include <qlabel.h>
#include <qsplitter.h>
#include <qtimer.h>
#include <qwidgetstack.h>
#include <kpushbutton.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kaction.h>
#include <kactionclasses.h>
#include <kapplication.h>
#include <kdebug.h>
#include <kparts/part.h>
#include <ktrader.h>
#include <klibloader.h>
#include <kstatusbar.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/history.h>
#include <apt-front/predicate/factory.h>
#include <adept/acqprogresswidget.h>
#include <adept/progress.h>
#include <adept/utils.h>
#include "app.h"
using namespace aptFront;
using namespace aptFront::cache;
using namespace adept;
void WaitForLister::waiting()
{
kdDebug() << "WaitForLister::waiting()" << endl;
if (app->m_list->searchView()->lister()->busy())
QTimer::singleShot( 100, this, SLOT( waiting() ) );
else {
QTimer::singleShot( 0, app, slot );
deleteLater();
}
}
TestApp::TestApp()
{
m_all = new QVBox( this );
m_stack = new QWidgetStack( m_all );
m_stack->addWidget( m_loading = new QLabel( i18n( "Loading, please wait..." ), m_stack ) );
m_loading->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
m_buttons = new QHBox( m_all );
QLabel *space = new QLabel( m_buttons ); // spacing
m_next = new KPushButton( i18n( "Next" ), m_buttons );
m_quit = new KPushButton( i18n( "Quit" ), m_buttons );
m_next->setEnabled( false );
m_quit->setEnabled( false );
m_buttons->setSpacing( 2 );
m_buttons->setMargin( 2 );
QSizePolicy buttons( QSizePolicy::Preferred, QSizePolicy::Fixed, false );
m_buttons->setSizePolicy( buttons );
m_next->setSizePolicy( buttons );
m_quit->setSizePolicy( buttons );
space->setSizePolicy( QSizePolicy(
QSizePolicy::Expanding,
QSizePolicy::Fixed, false ) );
setStandardToolBarMenuEnabled( false );
createStandardStatusBarAction();
setupActions();
setupGUI( Keys|StatusBar|Save|Create );
delete toolBar();
Application::setStatusBar( statusBar() );
QTimer::singleShot(
0, this,
SLOT( delayed() ) );
setCentralWidget( m_all );
setMinimumSize( 400, 300 );
}
void TestApp::delayed()
{
initialize();
observeComponent< component::State >();
m_stack->addWidget( m_list = new adept::Browser( m_stack ) );
m_stack->addWidget( m_bye = new QLabel( i18n( "Update Complete" ),
m_stack ) );
m_stack->addWidget( m_start = new QLabel( i18n( "Welcome to Adept Updater" ),
m_stack ) );
m_bye->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
m_start->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
m_list->searchView()->setUpgradeMode();
m_stack->addWidget( m_progress = new adept::AcqProgressWidget( m_stack ) );
m_stack->addWidget( m_commitProgress = new CommitProgress( m_stack ) );
m_stack->raiseWidget( m_start );
statusBar()->clear();
notifyPostChange(0);
start();
}
void TestApp::setupActions()
{
KStdAction::quit( kapp, SLOT( quit() ), actionCollection() );
m_undo = KStdAction::undo( this, SLOT( undo() ), actionCollection() );
m_redo = KStdAction::redo( this, SLOT( redo() ), actionCollection() );
setHistoryEnabled( false );
createStandardStatusBarAction();
}
void TestApp::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 TestApp::notifyPreChange( component::Base *b )
{
Application::notifyPreChange( b );
checkpoint();
}
void TestApp::notifyPostChange( component::Base *b )
{
Application::notifyPostChange( b );
m_list->searchView()->lister()->scheduleRebuild(); // rebuild on change...
}
void TestApp::setNext( QString s, const char *slot, QString q, const char *quits ) {
disconnect( m_next, SIGNAL( clicked() ), 0, 0 );
m_next->setText( s );
m_next->setEnabled( slot );
if ( slot )
connect( m_next, SIGNAL( clicked() ), this, slot );
disconnect( m_quit, SIGNAL( clicked() ), 0, 0 );
m_quit->setEnabled( quits );
m_quit->setText( q );
if ( quits )
connect( m_quit, SIGNAL( clicked() ), this, quits );
}
void TestApp::disableNext() {
setNext( i18n( "Next" ), 0 );
}
void TestApp::disableButtons() {
disableNext();
m_quit->setEnabled( false );
}
void TestApp::start() {
disableNext();
setNext( i18n( "Fetch List of Updates" ), SLOT( update() ),
i18n( "Skip Fetching List" ), SLOT( postUpdate() ) );
}
void TestApp::update() {
kdDebug() << "TestApp::update" << endl;
disableButtons();
aptFront::Manager m;
m.setProgressCallback( m_progress->callback() );
m.setUpdateInterval( 100000 );
kdDebug() << "manager set up" << endl;
try {
m_stack->raiseWidget( m_progress );
m.update();
} catch ( exception::OperationCancelled ) {
} catch ( ... ) {
KMessageBox::sorry(
this, i18n( "There was an error downloading updates. " ),
i18n( "Could not fetch updates" ) );
}
postUpdate();
}
void TestApp::postUpdate() {
cache::Global::get().state().distUpgrade();
if ( cache::Global::get().state().upgradableCount() > 0 ) {
m_list->searchView()->lister()->scheduleRebuild();
m_stack->raiseWidget( m_list );
setHistoryEnabled( true );
setNext( i18n( "Apply Updates" ), SLOT( commit() ) );
} else {
m_bye->setText( i18n( "Nothing to Update" ) );
m_stack->raiseWidget( m_bye );
disableNext();
// setNext( i18n( "Nothing to do, Quit" ), SLOT( close() ) );
m_quit->setText( i18n( "Quit" ) );
m_quit->setEnabled( true );
}
}
void TestApp::commit() {
kdDebug() << "TestApp::commit" << endl;
disableButtons();
setHistoryEnabled( false );
if (m_list->searchView()->lister()->busy()) {
new WaitForLister( this, SLOT( commit() ) );
return;
}
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 ) {
} 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" ) );
}
m_stack->raiseWidget( m_bye );
disableNext();
m_quit->setText( i18n( "Quit" ) );
m_quit->setEnabled( true );
notifyPostChange( 0 );
}
#include "app.moc"
|