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