summaryrefslogtreecommitdiffstats
path: root/adept/batch/app.cpp
blob: 2577b9cd0617304b17437323507bc20d75636560 (plain)
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
#include <tqvbox.h>
#include <tqlabel.h>
#include <tqsplitter.h>
#include <tqtimer.h>
#include <tqwidgetstack.h>

#include <kpushbutton.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kaction.h>
#include <kactionclasses.h>
#include <kapplication.h>
#include <kdebug.h>
#include <tdeparts/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 <iostream>

#include "app.h"

using namespace aptFront;
using namespace aptFront::cache;
using namespace adept;

App::App( TDECmdLineArgs *args ) {
    setMainWidget( this );
    initialize();
    TQString qs_pkgname;

    updating = false;
    enum { None, Remove, Install } m = None;
    for(int i = 0; i < args->count(); i++) {
        TQCString a = args->arg( i );

        if (m == None ||
            cache().packages().packageByName( std::string( a ) ).valid()) {
          if ( m == Install ) {
            kdDebug() << "installing " << a << endl;
            cache().packages().packageByName( std::string( a ) ).markInstall();
          } else if ( m == Remove ) {
            kdDebug() << "removing " << a << endl;
            cache().packages().packageByName( std::string( a ) ).markRemove();
          }

          if ( m == None && a == "install" ) {
            m = Install;
          } if ( m == None && a == "remove" ) {
            m = Remove;
          } if ( m == None && a == "update" ) {
            updating = true;
          }
        } else {
          qs_pkgname = a;
          kdDebug() << "The package '"<<a<<"' could not be found." << endl;
          KMessageBox::sorry(
                             this, i18n( "The package '%1' could not be found." ).arg(u8(qs_pkgname)),
                             i18n( "Could not commit changes" ) );
          exit(1);
        }
    }

    if (!updating && m == 0) {
      exit( 1 );
    }

    observeComponent< component::State >();

    m_all = new TQVBox( this );
    m_stack = new TQWidgetStack( m_all );

    m_stack->addWidget( m_progress = new adept::AcqProgressWidget( m_stack ) );
    m_stack->addWidget( m_commitProgress = new CommitProgress( m_stack ) );

    connect(this, TQT_SIGNAL( imDone() ),
            this, TQT_SLOT( handleDone() ));

    setStandardToolBarMenuEnabled( false );
    createStandardStatusBarAction();
    setupGUI( Keys|StatusBar|Save|Create );
    delete toolBar();

    Application::setStatusBar( statusBar() );

    TQTimer::singleShot(
        0, this,
        TQT_SLOT( delayed() ) );

    m_stack->raiseWidget( m_progress );
    setCentralWidget( m_all );
}

void App::delayed() {
    statusBar()->clear();

    kdDebug() << "App::delayed starting commit" << endl;

    aptFront::Manager m;
    m.setProgressCallback( m_progress->callback() );
    m.setUpdateInterval( 100000 );
    try {
      if (updating) {
        m_stack->raiseWidget( m_progress );
        m.update();
      } else {
        m_stack->raiseWidget( m_progress );
        m.download();
        m_stack->raiseWidget( m_commitProgress );
        m.commit();
      }
      emit imDone();
    } catch ( exception::OperationCancelled ) {
        emit imDone();
    } 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" ) );
        emit imDone();
    }
}

void App::handleDone() {
  kdDebug() << "I'm done here" << endl;
  close();
}

#include "app.moc"