Diffstat (limited to 'noncore/apps/opie-console/mainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-console/mainwindow.cpp | 48 |
1 files changed, 42 insertions, 6 deletions
diff --git a/noncore/apps/opie-console/mainwindow.cpp b/noncore/apps/opie-console/mainwindow.cpp index 3531478..aeb3742 100644 --- a/noncore/apps/opie-console/mainwindow.cpp +++ b/noncore/apps/opie-console/mainwindow.cpp | |||
@@ -1,34 +1,36 @@ | |||
1 | 1 | ||
2 | #include <qaction.h> | 2 | #include <qaction.h> |
3 | #include <qmenubar.h> | 3 | #include <qmenubar.h> |
4 | #include <qlabel.h> | 4 | #include <qlabel.h> |
5 | #include <qpopupmenu.h> | 5 | #include <qpopupmenu.h> |
6 | #include <qtoolbar.h> | 6 | #include <qtoolbar.h> |
7 | 7 | ||
8 | #include "profileeditordialog.h" | ||
8 | #include "configdialog.h" | 9 | #include "configdialog.h" |
9 | #include "default.h" | 10 | #include "default.h" |
10 | #include "metafactory.h" | 11 | #include "metafactory.h" |
12 | #include "profile.h" | ||
11 | #include "profilemanager.h" | 13 | #include "profilemanager.h" |
12 | #include "mainwindow.h" | 14 | #include "mainwindow.h" |
13 | #include "tabwidget.h" | 15 | #include "tabwidget.h" |
14 | 16 | ||
15 | MainWindow::MainWindow() { | 17 | MainWindow::MainWindow() { |
16 | m_factory = new MetaFactory(); | 18 | m_factory = new MetaFactory(); |
17 | Default def(m_factory); | 19 | Default def(m_factory); |
18 | m_sessions.setAutoDelete( TRUE ); | 20 | m_sessions.setAutoDelete( TRUE ); |
19 | m_curSession = 0; | 21 | m_curSession = 0; |
20 | m_manager = new ProfileManager( m_factory ); | 22 | m_manager = new ProfileManager( m_factory ); |
21 | m_manager->load(); | 23 | m_manager->load(); |
22 | 24 | ||
23 | initUI(); | 25 | initUI(); |
24 | populateProfiles(); | 26 | populateProfiles(); |
25 | } | 27 | } |
26 | void MainWindow::initUI() { | 28 | void MainWindow::initUI() { |
27 | setToolBarsMovable( FALSE ); | 29 | setToolBarsMovable( FALSE ); |
28 | 30 | ||
29 | m_tool = new QToolBar( this ); | 31 | m_tool = new QToolBar( this ); |
30 | m_tool->setHorizontalStretchable( TRUE ); | 32 | m_tool->setHorizontalStretchable( TRUE ); |
31 | 33 | ||
32 | m_bar = new QMenuBar( m_tool ); | 34 | m_bar = new QMenuBar( m_tool ); |
33 | m_console = new QPopupMenu( this ); | 35 | m_console = new QPopupMenu( this ); |
34 | m_sessionsPop= new QPopupMenu( this ); | 36 | m_sessionsPop= new QPopupMenu( this ); |
@@ -88,93 +90,127 @@ void MainWindow::initUI() { | |||
88 | /* insert the submenu */ | 90 | /* insert the submenu */ |
89 | m_console->insertItem(tr("New from Profile"), m_sessionsPop, | 91 | m_console->insertItem(tr("New from Profile"), m_sessionsPop, |
90 | -1, 0); | 92 | -1, 0); |
91 | 93 | ||
92 | /* insert the connection menu */ | 94 | /* insert the connection menu */ |
93 | m_bar->insertItem( tr("Connection"), m_console ); | 95 | m_bar->insertItem( tr("Connection"), m_console ); |
94 | 96 | ||
95 | /* the settings menu */ | 97 | /* the settings menu */ |
96 | m_bar->insertItem( tr("Settings"), m_settings ); | 98 | m_bar->insertItem( tr("Settings"), m_settings ); |
97 | 99 | ||
98 | /* | 100 | /* |
99 | * connect to the menu activation | 101 | * connect to the menu activation |
100 | */ | 102 | */ |
101 | connect( m_sessionsPop, SIGNAL(activated( int ) ), | 103 | connect( m_sessionsPop, SIGNAL(activated( int ) ), |
102 | this, SLOT(slotProfile( int ) ) ); | 104 | this, SLOT(slotProfile( int ) ) ); |
103 | 105 | ||
104 | m_consoleWindow = new TabWidget( this, "blah"); | 106 | m_consoleWindow = new TabWidget( this, "blah"); |
105 | setCentralWidget( m_consoleWindow ); | 107 | setCentralWidget( m_consoleWindow ); |
106 | 108 | ||
107 | } | 109 | } |
108 | 110 | ||
109 | ProfileManager* MainWindow::manager() { | 111 | ProfileManager* MainWindow::manager() { |
110 | return m_manager; | 112 | return m_manager; |
111 | } | 113 | } |
112 | 114 | TabWidget* MainWindow::tabWidget() { | |
115 | return m_consoleWindow; | ||
116 | } | ||
113 | void MainWindow::populateProfiles() { | 117 | void MainWindow::populateProfiles() { |
114 | m_sessionsPop->clear(); | 118 | m_sessionsPop->clear(); |
115 | Profile::ValueList list = manager()->all(); | 119 | Profile::ValueList list = manager()->all(); |
116 | for (Profile::ValueList::Iterator it = list.begin(); it != list.end(); ++it ) { | 120 | for (Profile::ValueList::Iterator it = list.begin(); it != list.end(); ++it ) { |
117 | m_sessionsPop->insertItem( (*it).name() ); | 121 | m_sessionsPop->insertItem( (*it).name() ); |
118 | } | 122 | } |
119 | 123 | ||
120 | } | 124 | } |
121 | MainWindow::~MainWindow() { | 125 | MainWindow::~MainWindow() { |
122 | delete m_factory; | 126 | delete m_factory; |
123 | manager()->save(); | 127 | manager()->save(); |
124 | } | 128 | } |
125 | 129 | ||
126 | MetaFactory* MainWindow::factory() { | 130 | MetaFactory* MainWindow::factory() { |
127 | return m_factory; | 131 | return m_factory; |
128 | } | 132 | } |
129 | 133 | ||
130 | Session* MainWindow::currentSession() { | 134 | Session* MainWindow::currentSession() { |
131 | return m_curSession; | 135 | return m_curSession; |
132 | } | 136 | } |
133 | 137 | ||
134 | QList<Session> MainWindow::sessions() { | 138 | QList<Session> MainWindow::sessions() { |
135 | return m_sessions; | 139 | return m_sessions; |
136 | } | 140 | } |
137 | 141 | ||
138 | void MainWindow::slotNew() { | 142 | void MainWindow::slotNew() { |
139 | qWarning("New Connection"); | 143 | qWarning("New Connection"); |
144 | ProfileEditorDialog dlg(factory() ); | ||
145 | int ret = dlg.exec(); | ||
146 | |||
147 | if ( ret == QDialog::Accepted ) { | ||
148 | create( dlg.profile() ); | ||
149 | } | ||
140 | } | 150 | } |
141 | 151 | ||
142 | void MainWindow::slotConnect() { | 152 | void MainWindow::slotConnect() { |
143 | if ( currentSession() ) | 153 | if ( currentSession() ) |
144 | currentSession()->layer()->open(); | 154 | currentSession()->layer()->open(); |
145 | } | 155 | } |
146 | 156 | ||
147 | void MainWindow::slotDisconnect() { | 157 | void MainWindow::slotDisconnect() { |
148 | if ( currentSession() ) | 158 | if ( currentSession() ) |
149 | currentSession()->layer()->close(); | 159 | currentSession()->layer()->close(); |
150 | } | 160 | } |
151 | 161 | ||
152 | void MainWindow::slotTerminate() { | 162 | void MainWindow::slotTerminate() { |
153 | if ( currentSession() ) | 163 | if ( currentSession() ) |
154 | currentSession()->layer()->close(); | 164 | currentSession()->layer()->close(); |
155 | delete m_curSession; | 165 | |
156 | m_curSession = 0l; | 166 | slotClose(); |
157 | /* FIXME move to the next session */ | 167 | /* FIXME move to the next session */ |
158 | } | 168 | } |
159 | 169 | ||
160 | void MainWindow::slotConfigure() { | 170 | void MainWindow::slotConfigure() { |
161 | qWarning("configure"); | 171 | qWarning("configure"); |
162 | ConfigDialog conf( manager()->all(), factory() ); | 172 | ConfigDialog conf( manager()->all(), factory() ); |
163 | conf.showMaximized(); | 173 | conf.showMaximized(); |
164 | 174 | ||
165 | int ret = conf.exec(); | 175 | int ret = conf.exec(); |
166 | 176 | ||
167 | if ( QDialog::Accepted == ret ) { | 177 | if ( QDialog::Accepted == ret ) { |
168 | qWarning("conf %d", conf.list().count() ); | 178 | qWarning("conf %d", conf.list().count() ); |
169 | manager()->setProfiles( conf.list() ); | 179 | manager()->setProfiles( conf.list() ); |
170 | populateProfiles(); | 180 | populateProfiles(); |
171 | } | 181 | } |
172 | } | 182 | } |
173 | 183 | /* | |
184 | * we will remove | ||
185 | * this window from the tabwidget | ||
186 | * remove it from the list | ||
187 | * delete it | ||
188 | * and set the currentSession() | ||
189 | */ | ||
174 | void MainWindow::slotClose() { | 190 | void MainWindow::slotClose() { |
175 | } | 191 | if (!currentSession() ) |
192 | return; | ||
176 | 193 | ||
177 | void MainWindow::slotProfile( int ) { | 194 | tabWidget()->remove( currentSession() ); |
195 | tabWidget()->setCurrent( m_sessions.first() ); | ||
196 | m_sessions.remove( m_curSession ); | ||
197 | delete m_curSession; | ||
198 | m_curSession = m_sessions.first(); | ||
199 | } | ||
178 | 200 | ||
201 | /* | ||
202 | * We will get the name | ||
203 | * Then the profile | ||
204 | * and then we will make a profile | ||
205 | */ | ||
206 | void MainWindow::slotProfile( int id) { | ||
207 | Profile prof = manager()->profile( m_sessionsPop->text( id) ); | ||
208 | create( prof ); | ||
209 | } | ||
210 | void MainWindow::create( const Profile& prof ) { | ||
211 | Session *ses = manager()->fromProfile( prof, tabWidget() ); | ||
179 | 212 | ||
213 | m_sessions.append( ses ); | ||
214 | tabWidget()->add( ses ); | ||
215 | m_curSession = ses; | ||
180 | } | 216 | } |