summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-console/mainwindow.cpp
blob: 31f11384744fb8316482002c0a69d3724a1984bc (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
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

#include <qaction.h>
#include <qmenubar.h>
#include <qlabel.h>
#include <qpopupmenu.h>
#include <qtoolbar.h>

#include "configdialog.h"
#include "metafactory.h"
#include "profilemanager.h"
#include "mainwindow.h"
#include "tabwidget.h"

MainWindow::MainWindow() {
    m_factory = new MetaFactory();
    m_sessions.setAutoDelete( TRUE );
    m_curSession = 0;
    m_manager = new ProfileManager( m_factory );
    m_manager->load();

    initUI();
    populateProfiles();
}
void MainWindow::initUI() {
    setToolBarsMovable( FALSE  );

    m_tool = new QToolBar( this );
    m_tool->setHorizontalStretchable( TRUE );

    m_bar = new QMenuBar( m_tool );
    m_console = new QPopupMenu( this );
    m_sessionsPop= new QPopupMenu( this );
    m_settings = new QPopupMenu( this );

    /*
     * new Action for new sessions
     */
    QAction* a = new QAction();
    a->setText( tr("New Connection") );
    a->addTo( m_console );
    connect(a, SIGNAL(activated() ),
            this, SLOT(slotNew() ) );

    /*
     * connect action
     */
    m_connect = new QAction();
    m_connect->setText( tr("Connect") );
    m_connect->addTo( m_console );
    connect(m_connect, SIGNAL(activated() ),
            this, SLOT(slotConnect() ) );

    /*
     * disconnect action
     */
    m_disconnect = new QAction();
    m_disconnect->setText( tr("Disconnect") );
    m_disconnect->addTo( m_console );
    connect(m_disconnect, SIGNAL(activated() ),
            this, SLOT(slotDisconnect() ) );

    /*
     * terminate action
     */
    m_terminate = new QAction();
    m_terminate->setText( tr("Terminate") );
    m_terminate->addTo( m_console );
    connect(m_disconnect, SIGNAL(activated() ),
            this, SLOT(slotTerminate() ) );

    a = new QAction();
    a->setText( tr("Close Window") );
    a->addTo( m_console );
    connect(a, SIGNAL(activated() ),
            this, SLOT(slotClose() ) );

    /*
     * the settings action
     */
    m_setProfiles = new QAction();
    m_setProfiles->setText( tr("Configure Profiles") );
    m_setProfiles->addTo( m_settings );
    connect( m_setProfiles, SIGNAL(activated() ),
             this, SLOT(slotConfigure() ) );

    /* insert the submenu */
    m_console->insertItem(tr("New from Profile"), m_sessionsPop,
                          -1, 0);

    /* insert the connection menu */
    m_bar->insertItem( tr("Connection"), m_console );

    /* the settings menu */
    m_bar->insertItem( tr("Settings"), m_settings );

    /*
     * connect to the menu activation
     */
    connect( m_sessionsPop, SIGNAL(activated( int ) ),
             this, SLOT(slotProfile( int ) ) );

    m_consoleWindow = new TabWidget( this, "blah");
    setCentralWidget( m_consoleWindow );

}

ProfileManager* MainWindow::manager() {
    return m_manager;
}

void MainWindow::populateProfiles() {
    m_sessionsPop->clear();
    Profile::ValueList list = manager()->all();
    for (Profile::ValueList::Iterator it = list.begin(); it != list.end(); ++it ) {
        m_sessionsPop->insertItem( (*it).name() );
    }

}
MainWindow::~MainWindow() {
    delete m_factory;
}

MetaFactory* MainWindow::factory() {
    return m_factory;
}

Session* MainWindow::currentSession() {
    return m_curSession;
}

QList<Session> MainWindow::sessions() {
    return m_sessions;
}

void MainWindow::slotNew() {
    qWarning("New Connection");
}

void MainWindow::slotConnect() {
    if ( currentSession() )
        currentSession()->layer()->open();
}

void MainWindow::slotDisconnect() {
    if ( currentSession() )
        currentSession()->layer()->close();
}

void MainWindow::slotTerminate() {
    if ( currentSession() )
        currentSession()->layer()->close();
    delete m_curSession;
    m_curSession = 0l;
    /* FIXME move to the next session */
}

void MainWindow::slotConfigure() {
    qWarning("configure");
    ConfigDialog conf( manager()->all() );
    conf.showMaximized();

    int ret = conf.exec();

    if ( QDialog::Accepted == ret ) {
        manager()->setProfiles( conf.list() );
        populateProfiles();
    }
}

void MainWindow::slotClose() {
}

void MainWindow::slotProfile( int ) {


}