summaryrefslogtreecommitdiffstats
path: root/adept/manager/app.h
blob: a3d5efa76ca53cb1113a1f092be13449a76bd324 (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
143
144
/* -*- C++ -*- */
#ifndef TESTUI_APP_H
#define TESTUI_APP_H

#include <tdemainwindow.h>
#include <tdeparts/part.h>
#include <tdeactionclasses.h>
#include <apt-front/cache/observer.h>
#include <apt-front/cache/component/state.h>
#include <apt-front/cache/component/history.h>
#include <adept/view.h>
#include <adept/commitprogress.h>
#include <adept/sourceseditor.h>
#include <adept/application.h>

class TQVBox;
class TQWidgetStack;
class TQSplitter;
class TDEAction;
namespace adept {
class AcqProgressWidget;
}

using namespace aptFront;
using namespace adept;

class TestApp : public TDEMainWindow, Application {
    Q_OBJECT
  
public:
    enum Mode { Default, Sources, Preview, Download, Commit };
    void setupActions();
    ExtTerminalInterface *terminal();
	TestApp();
protected slots:
    void delayed(); // initialisation

    void setActionsEnabled( bool );
    void setHistoryEnabled( bool );

    void update(); // actions
    void upgrade();
    void distUpgrade();
    void commit();

    void reload(); // debugging

    void undo() { Application::undo(); }
    void redo() { Application::redo(); }
    void checkpoint() { Application::checkpoint(); }

    void foregroundClosed();

    void togglePreview();
    void toggleSources();
    void toggleDownload();
    void toggleCommit();

    void closePreview();
    void closeSources();

    void openPreview();
    void openSources();

    bool modeActive( Mode m ) {
        // return modeAction( m )->isChecked();
        return modeWidget( m ) == m_stack->visibleWidget();
    }

    void closeModes() {
        closePreview();
        closeSources();
        closeMode( Download );
        closeMode( Commit );
        m_modesClosed->setChecked( true );
    }

    void rebuildStarted() {
        if ( !m_rebuilds ) setActionsEnabled( false );
        m_rebuilds ++;
    }

    void rebuildFinished() {
        m_rebuilds --;
        if ( !m_rebuilds ) setActionsEnabled( true );
    }

protected:
    void updateActionState();
    void guardLister( adept::Lister * );
    void addMode( Mode m, TDEToggleAction *a, TQWidget *w ) {
        m_modeActionMap[ m ] = a;
        m_modeWidgetMap[ m ] = w;
        a->setChecked( false );
    }

    TDEToggleAction *modeAction( Mode m ) {
        return m_modeActionMap[ m ];
    }

    TQWidget *modeWidget( Mode m ) {
        return m_modeWidgetMap[ m ];
    }

    bool openMode( Mode );
    bool closeMode( Mode );
    void toggleMode( Mode );

    friend class WaitForLister;
    virtual void closeEvent( TQCloseEvent * );
    virtual void notifyPostChange( cache::component::Base * );
    virtual void notifyPostRebuild( cache::component::Base * );
    virtual void notifyPreChange( cache::component::Base * );

    TQWidgetStack *m_stack;
    TQLabel *m_loading;

    // stacked widgets
    adept::AcqProgressWidget *m_progress;
    adept::Browser *m_list, *m_preview;
    adept::SourcesEditor *m_sources;
    adept::CommitProgress *m_commitProgress;

    // other stuff
    std::vector<TDEAction *> m_actions;
    TQMap< TQString, TQString > m_icons;
    TDEAction *m_undo, *m_redo;

    int m_rebuilds;
    bool m_actionsEnabled;

    TDEAction *m_commit, *m_upgrade, *m_distUpgrade;
    TDEToggleAction *m_sourcesAction, *m_commitProgressAction, *m_listAction,
        *m_previewAction, *m_progressAction;
    std::map< Mode, TDEToggleAction * > m_modeActionMap;
    std::map< Mode, TQWidget * > m_modeWidgetMap;
    TDEToggleAction *m_modesClosed;
private:
    template<typename T> void plugAptActions();
    // template<typename T, typename In> void updateAptActions( In b, In e );
    template<typename T, typename In> void aptAction( In b, In e );
};

#endif