-rw-r--r-- | noncore/apps/opie-console/mainwindow.cpp | 100 |
1 files changed, 1 insertions, 99 deletions
diff --git a/noncore/apps/opie-console/mainwindow.cpp b/noncore/apps/opie-console/mainwindow.cpp index 01468ca..abcdb84 100644 --- a/noncore/apps/opie-console/mainwindow.cpp +++ b/noncore/apps/opie-console/mainwindow.cpp | |||
@@ -1,577 +1,479 @@ | |||
1 | #include <assert.h> | 1 | #include <assert.h> |
2 | 2 | ||
3 | #include <qaction.h> | 3 | #include <qaction.h> |
4 | #include <qmenubar.h> | 4 | #include <qmenubar.h> |
5 | #include <qlabel.h> | 5 | #include <qlabel.h> |
6 | #include <qpopupmenu.h> | 6 | #include <qpopupmenu.h> |
7 | #include <qtoolbar.h> | 7 | #include <qtoolbar.h> |
8 | #include <qmessagebox.h> | 8 | #include <qmessagebox.h> |
9 | #include <qpushbutton.h> | 9 | #include <qpushbutton.h> |
10 | #include <qwhatsthis.h> | 10 | #include <qwhatsthis.h> |
11 | #include <qfileinfo.h> | 11 | #include <qfileinfo.h> |
12 | #include <qtextstream.h> | 12 | #include <qtextstream.h> |
13 | 13 | ||
14 | #include <qpe/resource.h> | 14 | #include <qpe/resource.h> |
15 | #include <qpe/qpeapplication.h> | 15 | #include <qpe/qpeapplication.h> |
16 | #include <qpe/filemanager.h> | 16 | #include <qpe/filemanager.h> |
17 | #include <qpe/mimetype.h> | 17 | #include <qpe/mimetype.h> |
18 | 18 | ||
19 | #include <opie/ofiledialog.h> | 19 | #include <opie/ofiledialog.h> |
20 | 20 | ||
21 | #include "TEmulation.h" | 21 | #include "TEmulation.h" |
22 | #include "keytrans.h" | 22 | #include "keytrans.h" |
23 | #include "profileeditordialog.h" | 23 | #include "profileeditordialog.h" |
24 | #include "configdialog.h" | 24 | #include "configdialog.h" |
25 | #include "default.h" | 25 | #include "default.h" |
26 | #include "metafactory.h" | 26 | #include "metafactory.h" |
27 | #include "profile.h" | 27 | #include "profile.h" |
28 | #include "profilemanager.h" | 28 | #include "profilemanager.h" |
29 | #include "mainwindow.h" | 29 | #include "mainwindow.h" |
30 | #include "tabwidget.h" | 30 | #include "tabwidget.h" |
31 | #include "transferdialog.h" | 31 | #include "transferdialog.h" |
32 | #include "function_keyboard.h" | 32 | #include "function_keyboard.h" |
33 | #include "emulation_handler.h" | 33 | #include "emulation_handler.h" |
34 | #include "script.h" | 34 | #include "script.h" |
35 | 35 | ||
36 | static char * filesave_xpm[] = { | ||
37 | "16 16 78 1", | ||
38 | " c None", | ||
39 | ". c #343434", | ||
40 | "+ c #A0A0A0", | ||
41 | "@ c #565656", | ||
42 | "# c #9E9E9E", | ||
43 | "$ c #525252", | ||
44 | "% c #929292", | ||
45 | "& c #676767", | ||
46 | "* c #848484", | ||
47 | "= c #666666", | ||
48 | "- c #D8D8D8", | ||
49 | "; c #FFFFFF", | ||
50 | "> c #DBDBDB", | ||
51 | ", c #636363", | ||
52 | "' c #989898", | ||
53 | ") c #2D2D2D", | ||
54 | "! c #909090", | ||
55 | "~ c #AEAEAE", | ||
56 | "{ c #EAEAEA", | ||
57 | "] c #575757", | ||
58 | "^ c #585858", | ||
59 | "/ c #8A8A8A", | ||
60 | "( c #828282", | ||
61 | "_ c #6F6F6F", | ||
62 | ": c #C9C9C9", | ||
63 | "< c #050505", | ||
64 | "[ c #292929", | ||
65 | "} c #777777", | ||
66 | "| c #616161", | ||
67 | "1 c #3A3A3A", | ||
68 | "2 c #BEBEBE", | ||
69 | "3 c #2C2C2C", | ||
70 | "4 c #7C7C7C", | ||
71 | "5 c #F6F6F6", | ||
72 | "6 c #FCFCFC", | ||
73 | "7 c #6B6B6B", | ||
74 | "8 c #959595", | ||
75 | "9 c #4F4F4F", | ||
76 | "0 c #808080", | ||
77 | "a c #767676", | ||
78 | "b c #818181", | ||
79 | "c c #B8B8B8", | ||
80 | "d c #FBFBFB", | ||
81 | "e c #F9F9F9", | ||
82 | "f c #CCCCCC", | ||
83 | "g c #030303", | ||
84 | "h c #737373", | ||
85 | "i c #7A7A7A", | ||
86 | "j c #7E7E7E", | ||
87 | "k c #6A6A6A", | ||
88 | "l c #FAFAFA", | ||
89 | "m c #505050", | ||
90 | "n c #9D9D9D", | ||
91 | "o c #333333", | ||
92 | "p c #7B7B7B", | ||
93 | "q c #787878", | ||
94 | "r c #696969", | ||
95 | "s c #494949", | ||
96 | "t c #555555", | ||
97 | "u c #949494", | ||
98 | "v c #E6E6E6", | ||
99 | "w c #424242", | ||
100 | "x c #515151", | ||
101 | "y c #535353", | ||
102 | "z c #3E3E3E", | ||
103 | "A c #D4D4D4", | ||
104 | "B c #0C0C0C", | ||
105 | "C c #353535", | ||
106 | "D c #474747", | ||
107 | "E c #ECECEC", | ||
108 | "F c #919191", | ||
109 | "G c #7D7D7D", | ||
110 | "H c #000000", | ||
111 | "I c #404040", | ||
112 | "J c #858585", | ||
113 | "K c #323232", | ||
114 | "L c #D0D0D0", | ||
115 | "M c #1C1C1C", | ||
116 | " ...+ ", | ||
117 | " @#$%&..+ ", | ||
118 | " .*=-;;>,..+ ", | ||
119 | " ')!~;;;;;;{]..", | ||
120 | " ^/(-;;;;;;;_:<", | ||
121 | " [}|;;;;;;;{12$", | ||
122 | " #34-55;;;;678$+", | ||
123 | " 90ab=c;dd;e1fg ", | ||
124 | " [ahij((kbl0mn$ ", | ||
125 | " op^q^^7r&]s/$+ ", | ||
126 | "@btu;vbwxy]zAB ", | ||
127 | "CzDEvEv;;DssF$ ", | ||
128 | "G.H{E{E{IxsJ$+ ", | ||
129 | " +...vEKxzLM ", | ||
130 | " +...z]n$ ", | ||
131 | " +... "}; | ||
132 | |||
133 | |||
134 | 36 | ||
135 | MainWindow::MainWindow(QWidget *parent, const char *name, WFlags) : QMainWindow(parent, name, WStyle_ContextHelp) { | 37 | MainWindow::MainWindow(QWidget *parent, const char *name, WFlags) : QMainWindow(parent, name, WStyle_ContextHelp) { |
136 | KeyTrans::loadAll(); | 38 | KeyTrans::loadAll(); |
137 | for (int i = 0; i < KeyTrans::count(); i++ ) { | 39 | for (int i = 0; i < KeyTrans::count(); i++ ) { |
138 | KeyTrans* s = KeyTrans::find(i ); | 40 | KeyTrans* s = KeyTrans::find(i ); |
139 | assert( s ); | 41 | assert( s ); |
140 | } | 42 | } |
141 | m_factory = new MetaFactory(); | 43 | m_factory = new MetaFactory(); |
142 | Default def(m_factory); | 44 | Default def(m_factory); |
143 | m_sessions.setAutoDelete( TRUE ); | 45 | m_sessions.setAutoDelete( TRUE ); |
144 | m_curSession = 0; | 46 | m_curSession = 0; |
145 | m_manager = new ProfileManager( m_factory ); | 47 | m_manager = new ProfileManager( m_factory ); |
146 | m_manager->load(); | 48 | m_manager->load(); |
147 | m_scriptsData.setAutoDelete(TRUE); | 49 | m_scriptsData.setAutoDelete(TRUE); |
148 | 50 | ||
149 | initUI(); | 51 | initUI(); |
150 | populateProfiles(); | 52 | populateProfiles(); |
151 | populateScripts(); | 53 | populateScripts(); |
152 | } | 54 | } |
153 | void MainWindow::initUI() { | 55 | void MainWindow::initUI() { |
154 | setToolBarsMovable( FALSE ); | 56 | setToolBarsMovable( FALSE ); |
155 | 57 | ||
156 | /* tool bar for the menu */ | 58 | /* tool bar for the menu */ |
157 | m_tool = new QToolBar( this ); | 59 | m_tool = new QToolBar( this ); |
158 | m_tool->setHorizontalStretchable( TRUE ); | 60 | m_tool->setHorizontalStretchable( TRUE ); |
159 | 61 | ||
160 | m_bar = new QMenuBar( m_tool ); | 62 | m_bar = new QMenuBar( m_tool ); |
161 | m_console = new QPopupMenu( this ); | 63 | m_console = new QPopupMenu( this ); |
162 | m_scripts = new QPopupMenu( this ); | 64 | m_scripts = new QPopupMenu( this ); |
163 | m_sessionsPop= new QPopupMenu( this ); | 65 | m_sessionsPop= new QPopupMenu( this ); |
164 | m_scriptsPop = new QPopupMenu( this ); | 66 | m_scriptsPop = new QPopupMenu( this ); |
165 | 67 | ||
166 | /* add a toolbar for icons */ | 68 | /* add a toolbar for icons */ |
167 | m_icons = new QToolBar(this); | 69 | m_icons = new QToolBar(this); |
168 | 70 | ||
169 | /* | 71 | /* |
170 | * the settings action | 72 | * the settings action |
171 | */ | 73 | */ |
172 | m_setProfiles = new QAction(tr("Configure Profiles"), | 74 | m_setProfiles = new QAction(tr("Configure Profiles"), |
173 | Resource::loadPixmap( "SettingsIcon" ), | 75 | Resource::loadPixmap( "SettingsIcon" ), |
174 | QString::null, 0, this, 0); | 76 | QString::null, 0, this, 0); |
175 | m_setProfiles->addTo( m_console ); | 77 | m_setProfiles->addTo( m_console ); |
176 | connect( m_setProfiles, SIGNAL(activated() ), | 78 | connect( m_setProfiles, SIGNAL(activated() ), |
177 | this, SLOT(slotConfigure() ) ); | 79 | this, SLOT(slotConfigure() ) ); |
178 | 80 | ||
179 | m_console->insertSeparator(); | 81 | m_console->insertSeparator(); |
180 | /* | 82 | /* |
181 | * new Action for new sessions | 83 | * new Action for new sessions |
182 | */ | 84 | */ |
183 | QAction* newCon = new QAction(tr("New Connection"), | 85 | QAction* newCon = new QAction(tr("New Connection"), |
184 | Resource::loadPixmap( "new" ), | 86 | Resource::loadPixmap( "new" ), |
185 | QString::null, 0, this, 0); | 87 | QString::null, 0, this, 0); |
186 | newCon->addTo( m_console ); | 88 | newCon->addTo( m_console ); |
187 | connect( newCon, SIGNAL(activated() ), | 89 | connect( newCon, SIGNAL(activated() ), |
188 | this, SLOT(slotNew() ) ); | 90 | this, SLOT(slotNew() ) ); |
189 | 91 | ||
190 | m_console->insertSeparator(); | 92 | m_console->insertSeparator(); |
191 | 93 | ||
192 | QAction *saveCon = new QAction(tr("Save Connection"), | 94 | QAction *saveCon = new QAction(tr("Save Connection"), |
193 | QPixmap( ( const char** ) filesave_xpm ) , QString::null, | 95 | Resource::loadPixmap( "save" ), QString::null, |
194 | 0, this, 0 ); | 96 | 0, this, 0 ); |
195 | saveCon->addTo( m_console ); | 97 | saveCon->addTo( m_console ); |
196 | connect( saveCon, SIGNAL(activated() ), | 98 | connect( saveCon, SIGNAL(activated() ), |
197 | this, SLOT(slotSaveSession() ) ); | 99 | this, SLOT(slotSaveSession() ) ); |
198 | m_console->insertSeparator(); | 100 | m_console->insertSeparator(); |
199 | 101 | ||
200 | /* | 102 | /* |
201 | * connect action | 103 | * connect action |
202 | */ | 104 | */ |
203 | m_connect = new QAction( tr("Connect"), Resource::loadPixmap("console/connected"), | 105 | m_connect = new QAction( tr("Connect"), Resource::loadPixmap("console/connected"), |
204 | QString::null, 0, this, 0 ); | 106 | QString::null, 0, this, 0 ); |
205 | m_connect->addTo( m_console ); | 107 | m_connect->addTo( m_console ); |
206 | connect(m_connect, SIGNAL(activated() ), | 108 | connect(m_connect, SIGNAL(activated() ), |
207 | this, SLOT(slotConnect() ) ); | 109 | this, SLOT(slotConnect() ) ); |
208 | 110 | ||
209 | /* | 111 | /* |
210 | * disconnect action | 112 | * disconnect action |
211 | */ | 113 | */ |
212 | m_disconnect = new QAction( tr("Disconnect"), Resource::loadPixmap("console/notconnected"), | 114 | m_disconnect = new QAction( tr("Disconnect"), Resource::loadPixmap("console/notconnected"), |
213 | QString::null, 0, this, 0 ); | 115 | QString::null, 0, this, 0 ); |
214 | m_disconnect->addTo( m_console ); | 116 | m_disconnect->addTo( m_console ); |
215 | connect(m_disconnect, SIGNAL(activated() ), | 117 | connect(m_disconnect, SIGNAL(activated() ), |
216 | this, SLOT(slotDisconnect() ) ); | 118 | this, SLOT(slotDisconnect() ) ); |
217 | 119 | ||
218 | m_console->insertSeparator(); | 120 | m_console->insertSeparator(); |
219 | 121 | ||
220 | m_transfer = new QAction( tr("Transfer file..."), Resource::loadPixmap("pass") , QString::null, | 122 | m_transfer = new QAction( tr("Transfer file..."), Resource::loadPixmap("pass") , QString::null, |
221 | 0, this, 0 ); | 123 | 0, this, 0 ); |
222 | m_transfer->addTo( m_console ); | 124 | m_transfer->addTo( m_console ); |
223 | connect(m_transfer, SIGNAL(activated() ), | 125 | connect(m_transfer, SIGNAL(activated() ), |
224 | this, SLOT(slotTransfer() ) ); | 126 | this, SLOT(slotTransfer() ) ); |
225 | 127 | ||
226 | /* | 128 | /* |
227 | * immediate change of line wrap policy | 129 | * immediate change of line wrap policy |
228 | */ | 130 | */ |
229 | m_isWrapped = false; | 131 | m_isWrapped = false; |
230 | m_wrap = new QAction( tr("Line wrap"), Resource::loadPixmap( "linewrap" ), QString::null, 0, this, 0 ); | 132 | m_wrap = new QAction( tr("Line wrap"), Resource::loadPixmap( "linewrap" ), QString::null, 0, this, 0 ); |
231 | m_wrap->addTo( m_console ); | 133 | m_wrap->addTo( m_console ); |
232 | connect( m_wrap, SIGNAL( activated() ), SLOT( slotWrap() ) ); | 134 | connect( m_wrap, SIGNAL( activated() ), SLOT( slotWrap() ) ); |
233 | 135 | ||
234 | /* | 136 | /* |
235 | * fullscreen | 137 | * fullscreen |
236 | */ | 138 | */ |
237 | m_isFullscreen = false; | 139 | m_isFullscreen = false; |
238 | 140 | ||
239 | m_fullscreen = new QAction( tr("Full screen"), Resource::loadPixmap( "fullscreen" ) | 141 | m_fullscreen = new QAction( tr("Full screen"), Resource::loadPixmap( "fullscreen" ) |
240 | , QString::null, 0, this, 0); | 142 | , QString::null, 0, this, 0); |
241 | m_fullscreen->addTo( m_console ); | 143 | m_fullscreen->addTo( m_console ); |
242 | connect( m_fullscreen, SIGNAL( activated() ), | 144 | connect( m_fullscreen, SIGNAL( activated() ), |
243 | this, SLOT( slotFullscreen() ) ); | 145 | this, SLOT( slotFullscreen() ) ); |
244 | 146 | ||
245 | m_console->insertSeparator(); | 147 | m_console->insertSeparator(); |
246 | 148 | ||
247 | QAction *a = new QAction(); | 149 | QAction *a = new QAction(); |
248 | a->setText( tr("Save history") ); | 150 | a->setText( tr("Save history") ); |
249 | a->addTo( m_console ); | 151 | a->addTo( m_console ); |
250 | connect(a, SIGNAL(activated() ), | 152 | connect(a, SIGNAL(activated() ), |
251 | this, SLOT(slotSaveHistory() ) ); | 153 | this, SLOT(slotSaveHistory() ) ); |
252 | /* | 154 | /* |
253 | * terminate action | 155 | * terminate action |
254 | */ | 156 | */ |
255 | m_terminate = new QAction(); | 157 | m_terminate = new QAction(); |
256 | m_terminate->setText( tr("Terminate") ); | 158 | m_terminate->setText( tr("Terminate") ); |
257 | m_terminate->addTo( m_console ); | 159 | m_terminate->addTo( m_console ); |
258 | connect(m_terminate, SIGNAL(activated() ), | 160 | connect(m_terminate, SIGNAL(activated() ), |
259 | this, SLOT(slotTerminate() ) ); | 161 | this, SLOT(slotTerminate() ) ); |
260 | 162 | ||
261 | m_closewindow = new QAction(); | 163 | m_closewindow = new QAction(); |
262 | m_closewindow->setText( tr("Close Window") ); | 164 | m_closewindow->setText( tr("Close Window") ); |
263 | m_closewindow->addTo( m_console ); | 165 | m_closewindow->addTo( m_console ); |
264 | connect( m_closewindow, SIGNAL(activated() ), | 166 | connect( m_closewindow, SIGNAL(activated() ), |
265 | this, SLOT(slotClose() ) ); | 167 | this, SLOT(slotClose() ) ); |
266 | 168 | ||
267 | 169 | ||
268 | /* | 170 | /* |
269 | * script actions | 171 | * script actions |
270 | */ | 172 | */ |
271 | m_runScript_id = m_scripts->insertItem(tr("Run Script"), m_scriptsPop, -1, 0); | 173 | m_runScript_id = m_scripts->insertItem(tr("Run Script"), m_scriptsPop, -1, 0); |
272 | connect(m_scriptsPop, SIGNAL(activated(int)), this, SLOT(slotRunScript(int))); | 174 | connect(m_scriptsPop, SIGNAL(activated(int)), this, SLOT(slotRunScript(int))); |
273 | 175 | ||
274 | m_recordScript = new QAction(tr("Record Script"), QString::null, 0, this, 0); | 176 | m_recordScript = new QAction(tr("Record Script"), QString::null, 0, this, 0); |
275 | m_recordScript->addTo(m_scripts); | 177 | m_recordScript->addTo(m_scripts); |
276 | connect(m_recordScript, SIGNAL(activated()), this, SLOT(slotRecordScript())); | 178 | connect(m_recordScript, SIGNAL(activated()), this, SLOT(slotRecordScript())); |
277 | 179 | ||
278 | m_saveScript = new QAction(tr("Save Script"), QString::null, 0, this, 0); | 180 | m_saveScript = new QAction(tr("Save Script"), QString::null, 0, this, 0); |
279 | m_saveScript->addTo(m_scripts); | 181 | m_saveScript->addTo(m_scripts); |
280 | connect(m_saveScript, SIGNAL(activated()), this, SLOT(slotSaveScript())); | 182 | connect(m_saveScript, SIGNAL(activated()), this, SLOT(slotSaveScript())); |
281 | 183 | ||
282 | 184 | ||
283 | /* | 185 | /* |
284 | * action that open/closes the keyboard | 186 | * action that open/closes the keyboard |
285 | */ | 187 | */ |
286 | m_openKeys = new QAction (tr("Open Keyboard..."), | 188 | m_openKeys = new QAction (tr("Open Keyboard..."), |
287 | Resource::loadPixmap( "console/keys/keyboard_icon" ), | 189 | Resource::loadPixmap( "console/keys/keyboard_icon" ), |
288 | QString::null, 0, this, 0); | 190 | QString::null, 0, this, 0); |
289 | m_openKeys->setToggleAction(true); | 191 | m_openKeys->setToggleAction(true); |
290 | connect (m_openKeys, SIGNAL(toggled(bool)), this, SLOT(slotOpenKeb(bool))); | 192 | connect (m_openKeys, SIGNAL(toggled(bool)), this, SLOT(slotOpenKeb(bool))); |
291 | 193 | ||
292 | /* insert the submenu */ | 194 | /* insert the submenu */ |
293 | m_console->insertItem(tr("New from Profile"), m_sessionsPop, | 195 | m_console->insertItem(tr("New from Profile"), m_sessionsPop, |
294 | -1, 0); | 196 | -1, 0); |
295 | 197 | ||
296 | /* insert the connection menu */ | 198 | /* insert the connection menu */ |
297 | m_bar->insertItem( tr("Connection"), m_console ); | 199 | m_bar->insertItem( tr("Connection"), m_console ); |
298 | 200 | ||
299 | /* the scripts menu */ | 201 | /* the scripts menu */ |
300 | m_bar->insertItem( tr("Scripts"), m_scripts ); | 202 | m_bar->insertItem( tr("Scripts"), m_scripts ); |
301 | 203 | ||
302 | /* and the keyboard */ | 204 | /* and the keyboard */ |
303 | m_keyBar = new QToolBar(this); | 205 | m_keyBar = new QToolBar(this); |
304 | addToolBar( m_keyBar, "Keyboard", QMainWindow::Top, TRUE ); | 206 | addToolBar( m_keyBar, "Keyboard", QMainWindow::Top, TRUE ); |
305 | m_keyBar->setHorizontalStretchable( TRUE ); | 207 | m_keyBar->setHorizontalStretchable( TRUE ); |
306 | m_keyBar->hide(); | 208 | m_keyBar->hide(); |
307 | 209 | ||
308 | m_kb = new FunctionKeyboard(m_keyBar); | 210 | m_kb = new FunctionKeyboard(m_keyBar); |
309 | connect(m_kb, SIGNAL(keyPressed(FKey, ushort, ushort, bool)), | 211 | connect(m_kb, SIGNAL(keyPressed(FKey, ushort, ushort, bool)), |
310 | this, SLOT(slotKeyReceived(FKey, ushort, ushort, bool))); | 212 | this, SLOT(slotKeyReceived(FKey, ushort, ushort, bool))); |
311 | 213 | ||
312 | 214 | ||
313 | a = new QAction(tr("Copy"), | 215 | a = new QAction(tr("Copy"), |
314 | Resource::loadPixmap("copy"), QString::null, | 216 | Resource::loadPixmap("copy"), QString::null, |
315 | 0, this, 0 ); | 217 | 0, this, 0 ); |
316 | //a->addTo( m_icons ); | 218 | //a->addTo( m_icons ); |
317 | connect( a, SIGNAL(activated() ), | 219 | connect( a, SIGNAL(activated() ), |
318 | this, SLOT(slotCopy() ) ); | 220 | this, SLOT(slotCopy() ) ); |
319 | 221 | ||
320 | QAction *paste = new QAction(tr("Paste"), | 222 | QAction *paste = new QAction(tr("Paste"), |
321 | Resource::loadPixmap("paste"), QString::null, | 223 | Resource::loadPixmap("paste"), QString::null, |
322 | 0, this, 0 ); | 224 | 0, this, 0 ); |
323 | connect( paste, SIGNAL(activated() ), | 225 | connect( paste, SIGNAL(activated() ), |
324 | this, SLOT(slotPaste() ) ); | 226 | this, SLOT(slotPaste() ) ); |
325 | 227 | ||
326 | 228 | ||
327 | newCon->addTo( m_icons ); | 229 | newCon->addTo( m_icons ); |
328 | m_setProfiles->addTo( m_icons ); | 230 | m_setProfiles->addTo( m_icons ); |
329 | paste->addTo( m_icons ); | 231 | paste->addTo( m_icons ); |
330 | m_openKeys->addTo(m_icons); | 232 | m_openKeys->addTo(m_icons); |
331 | m_fullscreen->addTo( m_icons ); | 233 | m_fullscreen->addTo( m_icons ); |
332 | 234 | ||
333 | m_connect->setEnabled( false ); | 235 | m_connect->setEnabled( false ); |
334 | m_disconnect->setEnabled( false ); | 236 | m_disconnect->setEnabled( false ); |
335 | m_terminate->setEnabled( false ); | 237 | m_terminate->setEnabled( false ); |
336 | m_transfer->setEnabled( false ); | 238 | m_transfer->setEnabled( false ); |
337 | m_scripts->setItemEnabled(m_runScript_id, false); | 239 | m_scripts->setItemEnabled(m_runScript_id, false); |
338 | m_recordScript->setEnabled( false ); | 240 | m_recordScript->setEnabled( false ); |
339 | m_saveScript->setEnabled( false ); | 241 | m_saveScript->setEnabled( false ); |
340 | m_fullscreen->setEnabled( false ); | 242 | m_fullscreen->setEnabled( false ); |
341 | m_closewindow->setEnabled( false ); | 243 | m_closewindow->setEnabled( false ); |
342 | m_wrap->setEnabled( false ); | 244 | m_wrap->setEnabled( false ); |
343 | 245 | ||
344 | /* | 246 | /* |
345 | * connect to the menu activation | 247 | * connect to the menu activation |
346 | */ | 248 | */ |
347 | connect( m_sessionsPop, SIGNAL(activated( int ) ), | 249 | connect( m_sessionsPop, SIGNAL(activated( int ) ), |
348 | this, SLOT(slotProfile( int ) ) ); | 250 | this, SLOT(slotProfile( int ) ) ); |
349 | 251 | ||
350 | m_consoleWindow = new TabWidget( this, "blah"); | 252 | m_consoleWindow = new TabWidget( this, "blah"); |
351 | connect(m_consoleWindow, SIGNAL(activated(Session*) ), | 253 | connect(m_consoleWindow, SIGNAL(activated(Session*) ), |
352 | this, SLOT(slotSessionChanged(Session*) ) ); | 254 | this, SLOT(slotSessionChanged(Session*) ) ); |
353 | setCentralWidget( m_consoleWindow ); | 255 | setCentralWidget( m_consoleWindow ); |
354 | 256 | ||
355 | } | 257 | } |
356 | 258 | ||
357 | ProfileManager* MainWindow::manager() { | 259 | ProfileManager* MainWindow::manager() { |
358 | return m_manager; | 260 | return m_manager; |
359 | } | 261 | } |
360 | TabWidget* MainWindow::tabWidget() { | 262 | TabWidget* MainWindow::tabWidget() { |
361 | return m_consoleWindow; | 263 | return m_consoleWindow; |
362 | } | 264 | } |
363 | void MainWindow::populateProfiles() { | 265 | void MainWindow::populateProfiles() { |
364 | m_sessionsPop->clear(); | 266 | m_sessionsPop->clear(); |
365 | Profile::ValueList list = manager()->all(); | 267 | Profile::ValueList list = manager()->all(); |
366 | for (Profile::ValueList::Iterator it = list.begin(); it != list.end(); ++it ) { | 268 | for (Profile::ValueList::Iterator it = list.begin(); it != list.end(); ++it ) { |
367 | m_sessionsPop->insertItem( (*it).name() ); | 269 | m_sessionsPop->insertItem( (*it).name() ); |
368 | } | 270 | } |
369 | 271 | ||
370 | } | 272 | } |
371 | 273 | ||
372 | void MainWindow::populateScripts() { | 274 | void MainWindow::populateScripts() { |
373 | m_scriptsPop->clear(); | 275 | m_scriptsPop->clear(); |
374 | m_scriptsData.clear(); | 276 | m_scriptsData.clear(); |
375 | DocLnkSet files(QPEApplication::documentDir(), "text/plain"); | 277 | DocLnkSet files(QPEApplication::documentDir(), "text/plain"); |
376 | QListIterator<DocLnk> dit(files.children()); | 278 | QListIterator<DocLnk> dit(files.children()); |
377 | for (; dit.current(); ++dit) { | 279 | for (; dit.current(); ++dit) { |
378 | if (*dit && (*dit)->name().length()>0) { | 280 | if (*dit && (*dit)->name().length()>0) { |
379 | QFileInfo info((*dit)->file()); | 281 | QFileInfo info((*dit)->file()); |
380 | if (info.extension(false) == "script") { | 282 | if (info.extension(false) == "script") { |
381 | m_scriptsData.append(new DocLnk(**dit)); | 283 | m_scriptsData.append(new DocLnk(**dit)); |
382 | m_scriptsPop->insertItem((*dit)->name()); | 284 | m_scriptsPop->insertItem((*dit)->name()); |
383 | } | 285 | } |
384 | } | 286 | } |
385 | } | 287 | } |
386 | 288 | ||
387 | } | 289 | } |
388 | 290 | ||
389 | MainWindow::~MainWindow() { | 291 | MainWindow::~MainWindow() { |
390 | delete m_factory; | 292 | delete m_factory; |
391 | manager()->save(); | 293 | manager()->save(); |
392 | } | 294 | } |
393 | 295 | ||
394 | MetaFactory* MainWindow::factory() { | 296 | MetaFactory* MainWindow::factory() { |
395 | return m_factory; | 297 | return m_factory; |
396 | } | 298 | } |
397 | 299 | ||
398 | Session* MainWindow::currentSession() { | 300 | Session* MainWindow::currentSession() { |
399 | return m_curSession; | 301 | return m_curSession; |
400 | } | 302 | } |
401 | 303 | ||
402 | QList<Session> MainWindow::sessions() { | 304 | QList<Session> MainWindow::sessions() { |
403 | return m_sessions; | 305 | return m_sessions; |
404 | } | 306 | } |
405 | 307 | ||
406 | void MainWindow::slotNew() { | 308 | void MainWindow::slotNew() { |
407 | ProfileEditorDialog dlg(factory() ); | 309 | ProfileEditorDialog dlg(factory() ); |
408 | dlg.showMaximized(); | 310 | dlg.showMaximized(); |
409 | dlg.setCaption( tr("New Connection") ); | 311 | dlg.setCaption( tr("New Connection") ); |
410 | int ret = dlg.exec(); | 312 | int ret = dlg.exec(); |
411 | 313 | ||
412 | if ( ret == QDialog::Accepted ) { | 314 | if ( ret == QDialog::Accepted ) { |
413 | create( dlg.profile() ); | 315 | create( dlg.profile() ); |
414 | } | 316 | } |
415 | } | 317 | } |
416 | 318 | ||
417 | void MainWindow::slotRecordScript() { | 319 | void MainWindow::slotRecordScript() { |
418 | if (currentSession()) { | 320 | if (currentSession()) { |
419 | currentSession()->emulationHandler()->startRecording(); | 321 | currentSession()->emulationHandler()->startRecording(); |
420 | m_saveScript->setEnabled(true); | 322 | m_saveScript->setEnabled(true); |
421 | m_recordScript->setEnabled(false); | 323 | m_recordScript->setEnabled(false); |
422 | } | 324 | } |
423 | } | 325 | } |
424 | 326 | ||
425 | void MainWindow::slotSaveScript() { | 327 | void MainWindow::slotSaveScript() { |
426 | if (currentSession() && currentSession()->emulationHandler()->isRecording()) { | 328 | if (currentSession() && currentSession()->emulationHandler()->isRecording()) { |
427 | QMap<QString, QStringList> map; | 329 | QMap<QString, QStringList> map; |
428 | QStringList text; | 330 | QStringList text; |
429 | text << "text/plain"; | 331 | text << "text/plain"; |
430 | map.insert(tr("Script"), text ); | 332 | map.insert(tr("Script"), text ); |
431 | QString filename = OFileDialog::getSaveFileName(2, QPEApplication::documentDir(), QString::null, map); | 333 | QString filename = OFileDialog::getSaveFileName(2, QPEApplication::documentDir(), QString::null, map); |
432 | if (!filename.isEmpty()) { | 334 | if (!filename.isEmpty()) { |
433 | QFileInfo info(filename); | 335 | QFileInfo info(filename); |
434 | if (info.extension(FALSE) != "script") | 336 | if (info.extension(FALSE) != "script") |
435 | filename += ".script"; | 337 | filename += ".script"; |
436 | DocLnk nf; | 338 | DocLnk nf; |
437 | nf.setType("text/plain"); | 339 | nf.setType("text/plain"); |
438 | nf.setFile(filename); | 340 | nf.setFile(filename); |
439 | nf.setName(info.fileName()); | 341 | nf.setName(info.fileName()); |
440 | FileManager fm; | 342 | FileManager fm; |
441 | fm.saveFile(nf, currentSession()->emulationHandler()->script()->script()); | 343 | fm.saveFile(nf, currentSession()->emulationHandler()->script()->script()); |
442 | currentSession()->emulationHandler()->clearScript(); | 344 | currentSession()->emulationHandler()->clearScript(); |
443 | m_saveScript->setEnabled(false); | 345 | m_saveScript->setEnabled(false); |
444 | m_recordScript->setEnabled(true); | 346 | m_recordScript->setEnabled(true); |
445 | populateScripts(); | 347 | populateScripts(); |
446 | } | 348 | } |
447 | } | 349 | } |
448 | } | 350 | } |
449 | 351 | ||
450 | void MainWindow::slotRunScript(int id) { | 352 | void MainWindow::slotRunScript(int id) { |
451 | if (currentSession()) { | 353 | if (currentSession()) { |
452 | int index = m_scriptsPop->indexOf(id); | 354 | int index = m_scriptsPop->indexOf(id); |
453 | DocLnk *lnk = m_scriptsData.at(index); | 355 | DocLnk *lnk = m_scriptsData.at(index); |
454 | QString filePath = lnk->file(); | 356 | QString filePath = lnk->file(); |
455 | Script script(filePath); | 357 | Script script(filePath); |
456 | currentSession()->emulationHandler()->runScript(&script); | 358 | currentSession()->emulationHandler()->runScript(&script); |
457 | } | 359 | } |
458 | } | 360 | } |
459 | 361 | ||
460 | void MainWindow::slotConnect() { | 362 | void MainWindow::slotConnect() { |
461 | if ( currentSession() ) { | 363 | if ( currentSession() ) { |
462 | bool ret = currentSession()->layer()->open(); | 364 | bool ret = currentSession()->layer()->open(); |
463 | if(!ret) QMessageBox::warning(currentSession()->widgetStack(), | 365 | if(!ret) QMessageBox::warning(currentSession()->widgetStack(), |
464 | QObject::tr("Failed"), | 366 | QObject::tr("Failed"), |
465 | QObject::tr("Connecting failed for this session.")); | 367 | QObject::tr("Connecting failed for this session.")); |
466 | else { | 368 | else { |
467 | m_connect->setEnabled( false ); | 369 | m_connect->setEnabled( false ); |
468 | m_disconnect->setEnabled( true ); | 370 | m_disconnect->setEnabled( true ); |
469 | 371 | ||
470 | // if it does not support file transfer, disable the menu entry | 372 | // if it does not support file transfer, disable the menu entry |
471 | if ( ( m_curSession->layer() )->supports()[1] == 0 ) { | 373 | if ( ( m_curSession->layer() )->supports()[1] == 0 ) { |
472 | m_transfer->setEnabled( false ); | 374 | m_transfer->setEnabled( false ); |
473 | } else { | 375 | } else { |
474 | m_transfer->setEnabled( true ); | 376 | m_transfer->setEnabled( true ); |
475 | } | 377 | } |
476 | 378 | ||
477 | m_recordScript->setEnabled( true ); | 379 | m_recordScript->setEnabled( true ); |
478 | m_scripts->setItemEnabled(m_runScript_id, true); | 380 | m_scripts->setItemEnabled(m_runScript_id, true); |
479 | } | 381 | } |
480 | } | 382 | } |
481 | } | 383 | } |
482 | 384 | ||
483 | void MainWindow::slotDisconnect() { | 385 | void MainWindow::slotDisconnect() { |
484 | if ( currentSession() ) { | 386 | if ( currentSession() ) { |
485 | currentSession()->layer()->close(); | 387 | currentSession()->layer()->close(); |
486 | m_connect->setEnabled( true ); | 388 | m_connect->setEnabled( true ); |
487 | m_disconnect->setEnabled( false ); | 389 | m_disconnect->setEnabled( false ); |
488 | m_transfer->setEnabled( false ); | 390 | m_transfer->setEnabled( false ); |
489 | m_recordScript->setEnabled( false); | 391 | m_recordScript->setEnabled( false); |
490 | m_saveScript->setEnabled( false ); | 392 | m_saveScript->setEnabled( false ); |
491 | m_scripts->setItemEnabled(m_runScript_id, false); | 393 | m_scripts->setItemEnabled(m_runScript_id, false); |
492 | } | 394 | } |
493 | } | 395 | } |
494 | 396 | ||
495 | void MainWindow::slotTerminate() { | 397 | void MainWindow::slotTerminate() { |
496 | if ( currentSession() ) | 398 | if ( currentSession() ) |
497 | currentSession()->layer()->close(); | 399 | currentSession()->layer()->close(); |
498 | 400 | ||
499 | slotClose(); | 401 | slotClose(); |
500 | /* FIXME move to the next session */ | 402 | /* FIXME move to the next session */ |
501 | } | 403 | } |
502 | 404 | ||
503 | void MainWindow::slotConfigure() { | 405 | void MainWindow::slotConfigure() { |
504 | ConfigDialog conf( manager()->all(), factory() ); | 406 | ConfigDialog conf( manager()->all(), factory() ); |
505 | conf.showMaximized(); | 407 | conf.showMaximized(); |
506 | 408 | ||
507 | int ret = conf.exec(); | 409 | int ret = conf.exec(); |
508 | 410 | ||
509 | if ( QDialog::Accepted == ret ) { | 411 | if ( QDialog::Accepted == ret ) { |
510 | manager()->setProfiles( conf.list() ); | 412 | manager()->setProfiles( conf.list() ); |
511 | manager()->save(); | 413 | manager()->save(); |
512 | populateProfiles(); | 414 | populateProfiles(); |
513 | } | 415 | } |
514 | } | 416 | } |
515 | /* | 417 | /* |
516 | * we will remove | 418 | * we will remove |
517 | * this window from the tabwidget | 419 | * this window from the tabwidget |
518 | * remove it from the list | 420 | * remove it from the list |
519 | * delete it | 421 | * delete it |
520 | * and set the currentSession() | 422 | * and set the currentSession() |
521 | */ | 423 | */ |
522 | void MainWindow::slotClose() { | 424 | void MainWindow::slotClose() { |
523 | if (!currentSession() ) | 425 | if (!currentSession() ) |
524 | return; | 426 | return; |
525 | 427 | ||
526 | Session* ses = currentSession(); | 428 | Session* ses = currentSession(); |
527 | qWarning("removing! currentSession %s", currentSession()->name().latin1() ); | 429 | qWarning("removing! currentSession %s", currentSession()->name().latin1() ); |
528 | /* set to NULL to be safe, if its needed slotSessionChanged resets it automatically */ | 430 | /* set to NULL to be safe, if its needed slotSessionChanged resets it automatically */ |
529 | m_curSession = NULL; | 431 | m_curSession = NULL; |
530 | tabWidget()->remove( /*currentSession()*/ses ); | 432 | tabWidget()->remove( /*currentSession()*/ses ); |
531 | /*it's autodelete */ | 433 | /*it's autodelete */ |
532 | m_sessions.remove( ses ); | 434 | m_sessions.remove( ses ); |
533 | qWarning("after remove!!"); | 435 | qWarning("after remove!!"); |
534 | 436 | ||
535 | if (!currentSession() ) { | 437 | if (!currentSession() ) { |
536 | m_connect->setEnabled( false ); | 438 | m_connect->setEnabled( false ); |
537 | m_disconnect->setEnabled( false ); | 439 | m_disconnect->setEnabled( false ); |
538 | m_terminate->setEnabled( false ); | 440 | m_terminate->setEnabled( false ); |
539 | m_transfer->setEnabled( false ); | 441 | m_transfer->setEnabled( false ); |
540 | m_recordScript->setEnabled( false ); | 442 | m_recordScript->setEnabled( false ); |
541 | m_saveScript->setEnabled( false ); | 443 | m_saveScript->setEnabled( false ); |
542 | m_scripts->setItemEnabled(m_runScript_id, false); | 444 | m_scripts->setItemEnabled(m_runScript_id, false); |
543 | m_fullscreen->setEnabled( false ); | 445 | m_fullscreen->setEnabled( false ); |
544 | m_wrap->setEnabled( false ); | 446 | m_wrap->setEnabled( false ); |
545 | m_closewindow->setEnabled( false ); | 447 | m_closewindow->setEnabled( false ); |
546 | } | 448 | } |
547 | 449 | ||
548 | m_kb->loadDefaults(); | 450 | m_kb->loadDefaults(); |
549 | } | 451 | } |
550 | 452 | ||
551 | /* | 453 | /* |
552 | * We will get the name | 454 | * We will get the name |
553 | * Then the profile | 455 | * Then the profile |
554 | * and then we will make a profile | 456 | * and then we will make a profile |
555 | */ | 457 | */ |
556 | void MainWindow::slotProfile( int id) { | 458 | void MainWindow::slotProfile( int id) { |
557 | Profile prof = manager()->profile( m_sessionsPop->text( id) ); | 459 | Profile prof = manager()->profile( m_sessionsPop->text( id) ); |
558 | create( prof ); | 460 | create( prof ); |
559 | } | 461 | } |
560 | void MainWindow::create( const Profile& prof ) { | 462 | void MainWindow::create( const Profile& prof ) { |
561 | if(m_curSession) | 463 | if(m_curSession) |
562 | if(m_curSession->transferDialog()) m_curSession->transferDialog()->hide(); | 464 | if(m_curSession->transferDialog()) m_curSession->transferDialog()->hide(); |
563 | 465 | ||
564 | Session *ses = manager()->fromProfile( prof, tabWidget() ); | 466 | Session *ses = manager()->fromProfile( prof, tabWidget() ); |
565 | 467 | ||
566 | if((!ses) || (!ses->layer()) || (!ses->widgetStack())) | 468 | if((!ses) || (!ses->layer()) || (!ses->widgetStack())) |
567 | { | 469 | { |
568 | QMessageBox::warning(this, | 470 | QMessageBox::warning(this, |
569 | QObject::tr("Session failed"), | 471 | QObject::tr("Session failed"), |
570 | QObject::tr("<qt>Cannot open session: Not all components were found.</qt>")); | 472 | QObject::tr("<qt>Cannot open session: Not all components were found.</qt>")); |
571 | //if(ses) delete ses; | 473 | //if(ses) delete ses; |
572 | return; | 474 | return; |
573 | } | 475 | } |
574 | 476 | ||
575 | m_sessions.append( ses ); | 477 | m_sessions.append( ses ); |
576 | tabWidget()->add( ses ); | 478 | tabWidget()->add( ses ); |
577 | tabWidget()->repaint(); | 479 | tabWidget()->repaint(); |