summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/io_serial.cpp3
-rw-r--r--noncore/apps/opie-console/mainwindow.cpp7
2 files changed, 7 insertions, 3 deletions
diff --git a/noncore/apps/opie-console/io_serial.cpp b/noncore/apps/opie-console/io_serial.cpp
index b495f39..77ced85 100644
--- a/noncore/apps/opie-console/io_serial.cpp
+++ b/noncore/apps/opie-console/io_serial.cpp
@@ -1,55 +1,57 @@
1#include <fcntl.h> 1#include <fcntl.h>
2#include <termios.h> 2#include <termios.h>
3#include <errno.h> 3#include <errno.h>
4#include <unistd.h> 4#include <unistd.h>
5#include "io_serial.h" 5#include "io_serial.h"
6 6
7IOSerial::IOSerial(const Profile &config) : IOLayer(config) { 7IOSerial::IOSerial(const Profile &config) : IOLayer(config) {
8 m_read = 0l;
9 m_error = 0l;
8 m_fd = 0; 10 m_fd = 0;
9 reload(config); 11 reload(config);
10} 12}
11 13
12 14
13IOSerial::~IOSerial() { 15IOSerial::~IOSerial() {
14 if (m_fd) { 16 if (m_fd) {
15 close(); 17 close();
16 } 18 }
17} 19}
18 20
19void IOSerial::send(const QByteArray &data) { 21void IOSerial::send(const QByteArray &data) {
20 if (m_fd) { 22 if (m_fd) {
21 write(m_fd, data.data(), data.size()); 23 write(m_fd, data.data(), data.size());
22 } else { 24 } else {
23 emit error(Refuse, tr("Not connected")); 25 emit error(Refuse, tr("Not connected"));
24 } 26 }
25} 27}
26 28
27void IOSerial::close() { 29void IOSerial::close() {
28 if (m_fd) { 30 if (m_fd) {
29 delete m_read; 31 delete m_read;
30 delete m_error; 32 delete m_error;
31 ::close(m_fd); 33 ::close(m_fd);
32 m_fd = 0; 34 m_fd = 0;
33 } else { 35 } else {
34 emit error(Refuse, tr("Not connected")); 36 emit error(Refuse, tr("Not connected"));
35 } 37 }
36} 38}
37 39
38bool IOSerial::open() { 40bool IOSerial::open() {
39 if (!m_fd) { 41 if (!m_fd) {
40 struct termios tty; 42 struct termios tty;
41 m_fd = ::open(m_device, O_RDWR | O_NOCTTY | O_NONBLOCK); 43 m_fd = ::open(m_device, O_RDWR | O_NOCTTY | O_NONBLOCK);
42 if (m_fd < 0) { 44 if (m_fd < 0) {
43 emit error(CouldNotOpen, strerror(errno)); 45 emit error(CouldNotOpen, strerror(errno));
44 return FALSE; 46 return FALSE;
45 } 47 }
46 tcgetattr(m_fd, &tty); 48 tcgetattr(m_fd, &tty);
47 49
48 /* Baud rate */ 50 /* Baud rate */
49 int speed = baud(m_baud); 51 int speed = baud(m_baud);
50 if (speed == -1) { 52 if (speed == -1) {
51 emit error(Refuse, tr("Invalid baud rate")); 53 emit error(Refuse, tr("Invalid baud rate"));
52 } 54 }
53 cfsetospeed(&tty, speed); 55 cfsetospeed(&tty, speed);
54 cfsetispeed(&tty, speed); 56 cfsetispeed(&tty, speed);
55 57
@@ -67,96 +69,97 @@ bool IOSerial::open() {
67 default: break; 69 default: break;
68 } 70 }
69 71
70 /* Raw, no echo mode */ 72 /* Raw, no echo mode */
71 tty.c_iflag = IGNBRK; 73 tty.c_iflag = IGNBRK;
72 tty.c_lflag = 0; 74 tty.c_lflag = 0;
73 tty.c_oflag = 0; 75 tty.c_oflag = 0;
74 tty.c_cflag |= CLOCAL | CREAD; 76 tty.c_cflag |= CLOCAL | CREAD;
75 77
76 /* Stop bits */ 78 /* Stop bits */
77 if (m_sbits == 2) { 79 if (m_sbits == 2) {
78 tty.c_cflag |= CSTOPB; 80 tty.c_cflag |= CSTOPB;
79 } else { 81 } else {
80 tty.c_cflag &= ~CSTOPB; 82 tty.c_cflag &= ~CSTOPB;
81 } 83 }
82 84
83 tty.c_cc[VMIN] = 1; 85 tty.c_cc[VMIN] = 1;
84 tty.c_cc[VTIME] = 5; 86 tty.c_cc[VTIME] = 5;
85 87
86 /* Flow control */ 88 /* Flow control */
87 if (m_flow & FlowSW) 89 if (m_flow & FlowSW)
88 tty.c_iflag |= IXON | IXOFF; 90 tty.c_iflag |= IXON | IXOFF;
89 else 91 else
90 tty.c_iflag &= ~(IXON|IXOFF|IXANY); 92 tty.c_iflag &= ~(IXON|IXOFF|IXANY);
91 93
92 if (m_flow & FlowHW) 94 if (m_flow & FlowHW)
93 tty.c_cflag |= CRTSCTS; 95 tty.c_cflag |= CRTSCTS;
94 else 96 else
95 tty.c_cflag &= ~CRTSCTS; 97 tty.c_cflag &= ~CRTSCTS;
96 98
97 /* Parity */ 99 /* Parity */
98 tty.c_cflag &= ~(PARENB | PARODD); 100 tty.c_cflag &= ~(PARENB | PARODD);
99 if (m_parity & ParityEven) 101 if (m_parity & ParityEven)
100 tty.c_cflag |= PARENB; 102 tty.c_cflag |= PARENB;
101 else if (m_parity & ParityOdd) 103 else if (m_parity & ParityOdd)
102 tty.c_cflag |= (PARENB | PARODD); 104 tty.c_cflag |= (PARENB | PARODD);
103 105
104 /* Set the changes */ 106 /* Set the changes */
105 tcsetattr(m_fd, TCSANOW, &tty); 107 tcsetattr(m_fd, TCSANOW, &tty);
106 108
107 /* Notifications on read & errors */ 109 /* Notifications on read & errors */
108 m_read = new QSocketNotifier(m_fd, QSocketNotifier::Read, this); 110 m_read = new QSocketNotifier(m_fd, QSocketNotifier::Read, this);
109 m_error = new QSocketNotifier(m_fd, QSocketNotifier::Exception, this); 111 m_error = new QSocketNotifier(m_fd, QSocketNotifier::Exception, this);
110 connect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived())); 112 connect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived()));
111 connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured())); 113 connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured()));
112 return TRUE; 114 return TRUE;
113 } else { 115 } else {
114 emit error(Refuse, tr("Device is already connected")); 116 emit error(Refuse, tr("Device is already connected"));
117 m_fd = 0;
115 return FALSE; 118 return FALSE;
116 } 119 }
117} 120}
118 121
119void IOSerial::reload(const Profile &config) { 122void IOSerial::reload(const Profile &config) {
120 m_device = config.readEntry("Device", SERIAL_DEFAULT_DEVICE); 123 m_device = config.readEntry("Device", SERIAL_DEFAULT_DEVICE);
121 m_baud = config.readNumEntry("Baud", SERIAL_DEFAULT_BAUD); 124 m_baud = config.readNumEntry("Baud", SERIAL_DEFAULT_BAUD);
122 m_parity = config.readNumEntry("Parity", SERIAL_DEFAULT_PARITY); 125 m_parity = config.readNumEntry("Parity", SERIAL_DEFAULT_PARITY);
123 m_dbits = config.readNumEntry("DataBits", SERIAL_DEFAULT_DBITS); 126 m_dbits = config.readNumEntry("DataBits", SERIAL_DEFAULT_DBITS);
124 m_sbits = config.readNumEntry("StopBits", SERIAL_DEFAULT_SBITS); 127 m_sbits = config.readNumEntry("StopBits", SERIAL_DEFAULT_SBITS);
125 m_flow = config.readNumEntry("Flow", SERIAL_DEFAULT_FLOW); 128 m_flow = config.readNumEntry("Flow", SERIAL_DEFAULT_FLOW);
126} 129}
127 130
128int IOSerial::baud(int baud) const { 131int IOSerial::baud(int baud) const {
129 switch (baud) { 132 switch (baud) {
130 case 300: return B300; break; 133 case 300: return B300; break;
131 case 600: return B600; break; 134 case 600: return B600; break;
132 case 1200: return B1200; break; 135 case 1200: return B1200; break;
133 case 2400: return B2400; break; 136 case 2400: return B2400; break;
134 case 4800: return B4800; break; 137 case 4800: return B4800; break;
135 case 9600: return B9600; break; 138 case 9600: return B9600; break;
136 case 19200: return B19200; break; 139 case 19200: return B19200; break;
137 case 38400: return B38400; break; 140 case 38400: return B38400; break;
138 case 57600: return B57600; break; 141 case 57600: return B57600; break;
139 case 115200: return B115200; break; 142 case 115200: return B115200; break;
140 } 143 }
141 return -1; 144 return -1;
142} 145}
143 146
144void IOSerial::errorOccured() { 147void IOSerial::errorOccured() {
145 emit error(ClosedUnexpected, strerror(errno)); 148 emit error(ClosedUnexpected, strerror(errno));
146 close(); 149 close();
147} 150}
148 151
149void IOSerial::dataArrived() { 152void IOSerial::dataArrived() {
150 QByteArray array; 153 QByteArray array;
151 char buf[4096]; 154 char buf[4096];
152 155
153 int len = read(m_fd, buf, 4096); 156 int len = read(m_fd, buf, 4096);
154 if (len == 0) 157 if (len == 0)
155 close(); 158 close();
156 if (len < 0) 159 if (len < 0)
157 return; 160 return;
158 array.setRawData(buf, len); 161 array.setRawData(buf, len);
159 emit received(array); 162 emit received(array);
160} 163}
161 164
162QString IOSerial::identifier() const { 165QString IOSerial::identifier() const {
diff --git a/noncore/apps/opie-console/mainwindow.cpp b/noncore/apps/opie-console/mainwindow.cpp
index aeb3742..0bd6a13 100644
--- a/noncore/apps/opie-console/mainwindow.cpp
+++ b/noncore/apps/opie-console/mainwindow.cpp
@@ -24,97 +24,97 @@ MainWindow::MainWindow() {
24 24
25 initUI(); 25 initUI();
26 populateProfiles(); 26 populateProfiles();
27} 27}
28void MainWindow::initUI() { 28void MainWindow::initUI() {
29 setToolBarsMovable( FALSE ); 29 setToolBarsMovable( FALSE );
30 30
31 m_tool = new QToolBar( this ); 31 m_tool = new QToolBar( this );
32 m_tool->setHorizontalStretchable( TRUE ); 32 m_tool->setHorizontalStretchable( TRUE );
33 33
34 m_bar = new QMenuBar( m_tool ); 34 m_bar = new QMenuBar( m_tool );
35 m_console = new QPopupMenu( this ); 35 m_console = new QPopupMenu( this );
36 m_sessionsPop= new QPopupMenu( this ); 36 m_sessionsPop= new QPopupMenu( this );
37 m_settings = new QPopupMenu( this ); 37 m_settings = new QPopupMenu( this );
38 38
39 /* 39 /*
40 * new Action for new sessions 40 * new Action for new sessions
41 */ 41 */
42 QAction* a = new QAction(); 42 QAction* a = new QAction();
43 a->setText( tr("New Connection") ); 43 a->setText( tr("New Connection") );
44 a->addTo( m_console ); 44 a->addTo( m_console );
45 connect(a, SIGNAL(activated() ), 45 connect(a, SIGNAL(activated() ),
46 this, SLOT(slotNew() ) ); 46 this, SLOT(slotNew() ) );
47 47
48 /* 48 /*
49 * connect action 49 * connect action
50 */ 50 */
51 m_connect = new QAction(); 51 m_connect = new QAction();
52 m_connect->setText( tr("Connect") ); 52 m_connect->setText( tr("Connect") );
53 m_connect->addTo( m_console ); 53 m_connect->addTo( m_console );
54 connect(m_connect, SIGNAL(activated() ), 54 connect(m_connect, SIGNAL(activated() ),
55 this, SLOT(slotConnect() ) ); 55 this, SLOT(slotConnect() ) );
56 56
57 /* 57 /*
58 * disconnect action 58 * disconnect action
59 */ 59 */
60 m_disconnect = new QAction(); 60 m_disconnect = new QAction();
61 m_disconnect->setText( tr("Disconnect") ); 61 m_disconnect->setText( tr("Disconnect") );
62 m_disconnect->addTo( m_console ); 62 m_disconnect->addTo( m_console );
63 connect(m_disconnect, SIGNAL(activated() ), 63 connect(m_disconnect, SIGNAL(activated() ),
64 this, SLOT(slotDisconnect() ) ); 64 this, SLOT(slotDisconnect() ) );
65 65
66 /* 66 /*
67 * terminate action 67 * terminate action
68 */ 68 */
69 m_terminate = new QAction(); 69 m_terminate = new QAction();
70 m_terminate->setText( tr("Terminate") ); 70 m_terminate->setText( tr("Terminate") );
71 m_terminate->addTo( m_console ); 71 m_terminate->addTo( m_console );
72 connect(m_disconnect, SIGNAL(activated() ), 72 connect(m_terminate, SIGNAL(activated() ),
73 this, SLOT(slotTerminate() ) ); 73 this, SLOT(slotTerminate() ) );
74 74
75 a = new QAction(); 75 a = new QAction();
76 a->setText( tr("Close Window") ); 76 a->setText( tr("Close Window") );
77 a->addTo( m_console ); 77 a->addTo( m_console );
78 connect(a, SIGNAL(activated() ), 78 connect(a, SIGNAL(activated() ),
79 this, SLOT(slotClose() ) ); 79 this, SLOT(slotClose() ) );
80 80
81 /* 81 /*
82 * the settings action 82 * the settings action
83 */ 83 */
84 m_setProfiles = new QAction(); 84 m_setProfiles = new QAction();
85 m_setProfiles->setText( tr("Configure Profiles") ); 85 m_setProfiles->setText( tr("Configure Profiles") );
86 m_setProfiles->addTo( m_settings ); 86 m_setProfiles->addTo( m_settings );
87 connect( m_setProfiles, SIGNAL(activated() ), 87 connect( m_setProfiles, SIGNAL(activated() ),
88 this, SLOT(slotConfigure() ) ); 88 this, SLOT(slotConfigure() ) );
89 89
90 /* insert the submenu */ 90 /* insert the submenu */
91 m_console->insertItem(tr("New from Profile"), m_sessionsPop, 91 m_console->insertItem(tr("New from Profile"), m_sessionsPop,
92 -1, 0); 92 -1, 0);
93 93
94 /* insert the connection menu */ 94 /* insert the connection menu */
95 m_bar->insertItem( tr("Connection"), m_console ); 95 m_bar->insertItem( tr("Connection"), m_console );
96 96
97 /* the settings menu */ 97 /* the settings menu */
98 m_bar->insertItem( tr("Settings"), m_settings ); 98 m_bar->insertItem( tr("Settings"), m_settings );
99 99
100 /* 100 /*
101 * connect to the menu activation 101 * connect to the menu activation
102 */ 102 */
103 connect( m_sessionsPop, SIGNAL(activated( int ) ), 103 connect( m_sessionsPop, SIGNAL(activated( int ) ),
104 this, SLOT(slotProfile( int ) ) ); 104 this, SLOT(slotProfile( int ) ) );
105 105
106 m_consoleWindow = new TabWidget( this, "blah"); 106 m_consoleWindow = new TabWidget( this, "blah");
107 setCentralWidget( m_consoleWindow ); 107 setCentralWidget( m_consoleWindow );
108 108
109} 109}
110 110
111ProfileManager* MainWindow::manager() { 111ProfileManager* MainWindow::manager() {
112 return m_manager; 112 return m_manager;
113} 113}
114TabWidget* MainWindow::tabWidget() { 114TabWidget* MainWindow::tabWidget() {
115 return m_consoleWindow; 115 return m_consoleWindow;
116} 116}
117void MainWindow::populateProfiles() { 117void MainWindow::populateProfiles() {
118 m_sessionsPop->clear(); 118 m_sessionsPop->clear();
119 Profile::ValueList list = manager()->all(); 119 Profile::ValueList list = manager()->all();
120 for (Profile::ValueList::Iterator it = list.begin(); it != list.end(); ++it ) { 120 for (Profile::ValueList::Iterator it = list.begin(); it != list.end(); ++it ) {
@@ -143,74 +143,75 @@ void MainWindow::slotNew() {
143 qWarning("New Connection"); 143 qWarning("New Connection");
144 ProfileEditorDialog dlg(factory() ); 144 ProfileEditorDialog dlg(factory() );
145 int ret = dlg.exec(); 145 int ret = dlg.exec();
146 146
147 if ( ret == QDialog::Accepted ) { 147 if ( ret == QDialog::Accepted ) {
148 create( dlg.profile() ); 148 create( dlg.profile() );
149 } 149 }
150} 150}
151 151
152void MainWindow::slotConnect() { 152void MainWindow::slotConnect() {
153 if ( currentSession() ) 153 if ( currentSession() )
154 currentSession()->layer()->open(); 154 currentSession()->layer()->open();
155} 155}
156 156
157void MainWindow::slotDisconnect() { 157void MainWindow::slotDisconnect() {
158 if ( currentSession() ) 158 if ( currentSession() )
159 currentSession()->layer()->close(); 159 currentSession()->layer()->close();
160} 160}
161 161
162void MainWindow::slotTerminate() { 162void MainWindow::slotTerminate() {
163 if ( currentSession() ) 163 if ( currentSession() )
164 currentSession()->layer()->close(); 164 currentSession()->layer()->close();
165 165
166 slotClose(); 166 slotClose();
167 /* FIXME move to the next session */ 167 /* FIXME move to the next session */
168} 168}
169 169
170void MainWindow::slotConfigure() { 170void MainWindow::slotConfigure() {
171 qWarning("configure"); 171 qWarning("configure");
172 ConfigDialog conf( manager()->all(), factory() ); 172 ConfigDialog conf( manager()->all(), factory() );
173 conf.showMaximized(); 173 conf.showMaximized();
174 174
175 int ret = conf.exec(); 175 int ret = conf.exec();
176 176
177 if ( QDialog::Accepted == ret ) { 177 if ( QDialog::Accepted == ret ) {
178 qWarning("conf %d", conf.list().count() ); 178 qWarning("conf %d", conf.list().count() );
179 manager()->setProfiles( conf.list() ); 179 manager()->setProfiles( conf.list() );
180 populateProfiles(); 180 populateProfiles();
181 } 181 }
182} 182}
183/* 183/*
184 * we will remove 184 * we will remove
185 * this window from the tabwidget 185 * this window from the tabwidget
186 * remove it from the list 186 * remove it from the list
187 * delete it 187 * delete it
188 * and set the currentSession() 188 * and set the currentSession()
189 */ 189 */
190void MainWindow::slotClose() { 190void MainWindow::slotClose() {
191 qWarning("close");
191 if (!currentSession() ) 192 if (!currentSession() )
192 return; 193 return;
193 194
194 tabWidget()->remove( currentSession() ); 195 tabWidget()->remove( currentSession() );
195 tabWidget()->setCurrent( m_sessions.first() ); 196 /*it's autodelete */
196 m_sessions.remove( m_curSession ); 197 m_sessions.remove( m_curSession );
197 delete m_curSession;
198 m_curSession = m_sessions.first(); 198 m_curSession = m_sessions.first();
199 tabWidget()->setCurrent( m_curSession );
199} 200}
200 201
201/* 202/*
202 * We will get the name 203 * We will get the name
203 * Then the profile 204 * Then the profile
204 * and then we will make a profile 205 * and then we will make a profile
205 */ 206 */
206void MainWindow::slotProfile( int id) { 207void MainWindow::slotProfile( int id) {
207 Profile prof = manager()->profile( m_sessionsPop->text( id) ); 208 Profile prof = manager()->profile( m_sessionsPop->text( id) );
208 create( prof ); 209 create( prof );
209} 210}
210void MainWindow::create( const Profile& prof ) { 211void MainWindow::create( const Profile& prof ) {
211 Session *ses = manager()->fromProfile( prof, tabWidget() ); 212 Session *ses = manager()->fromProfile( prof, tabWidget() );
212 213
213 m_sessions.append( ses ); 214 m_sessions.append( ses );
214 tabWidget()->add( ses ); 215 tabWidget()->add( ses );
215 m_curSession = ses; 216 m_curSession = ses;
216} 217}