summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/io_layer.cpp2
-rw-r--r--noncore/apps/opie-console/io_layer.h5
-rw-r--r--noncore/apps/opie-console/io_serial.cpp21
-rw-r--r--noncore/apps/opie-console/io_serial.h10
-rw-r--r--noncore/apps/opie-console/mainwindow.cpp67
-rw-r--r--noncore/apps/opie-console/mainwindow.h11
-rw-r--r--noncore/apps/opie-console/metafactory.cpp16
-rw-r--r--noncore/apps/opie-console/metafactory.h8
-rw-r--r--noncore/apps/opie-console/opie-console.pro13
-rw-r--r--noncore/apps/opie-console/profile.cpp59
-rw-r--r--noncore/apps/opie-console/profile.h66
-rw-r--r--noncore/apps/opie-console/profileconfig.cpp35
-rw-r--r--noncore/apps/opie-console/profileconfig.h17
-rw-r--r--noncore/apps/opie-console/profilemanager.cpp62
-rw-r--r--noncore/apps/opie-console/profilemanager.h30
-rw-r--r--noncore/apps/opie-console/session.cpp16
-rw-r--r--noncore/apps/opie-console/session.h11
-rw-r--r--noncore/apps/opie-console/tabwidget.cpp28
-rw-r--r--noncore/apps/opie-console/tabwidget.h28
19 files changed, 472 insertions, 33 deletions
diff --git a/noncore/apps/opie-console/io_layer.cpp b/noncore/apps/opie-console/io_layer.cpp
index ca1deb8..563a252 100644
--- a/noncore/apps/opie-console/io_layer.cpp
+++ b/noncore/apps/opie-console/io_layer.cpp
@@ -1,14 +1,14 @@
1#include "io_layer.h" 1#include "io_layer.h"
2 2
3IOLayer::IOLayer() 3IOLayer::IOLayer()
4 : QObject() 4 : QObject()
5{ 5{
6} 6}
7 7
8IOLayer::IOLayer(const Config &) 8IOLayer::IOLayer(const Profile &)
9 : QObject() 9 : QObject()
10{ 10{
11} 11}
12 12
13IOLayer::~IOLayer() { 13IOLayer::~IOLayer() {
14} 14}
diff --git a/noncore/apps/opie-console/io_layer.h b/noncore/apps/opie-console/io_layer.h
index 537c851..2f1ceef 100644
--- a/noncore/apps/opie-console/io_layer.h
+++ b/noncore/apps/opie-console/io_layer.h
@@ -1,47 +1,48 @@
1#ifndef OPIE_IO_LAYER_H 1#ifndef OPIE_IO_LAYER_H
2#define OPIE_IO_LAYER_H 2#define OPIE_IO_LAYER_H
3 3
4#include <qobject.h> 4#include <qobject.h>
5#include <qpe/config.h> 5#include <qpe/config.h>
6 6
7#include "profile.h"
8
7/** 9/**
8 * This is the base class for IO Layers 10 * This is the base class for IO Layers
9 * It will used to sent and recv data( QByteArray ) 11 * It will used to sent and recv data( QByteArray )
10 * it 12 * it
11 */ 13 */
12class Config;
13class IOLayer : public QObject { 14class IOLayer : public QObject {
14 Q_OBJECT 15 Q_OBJECT
15public: 16public:
16 enum Error { 17 enum Error {
17 NoError = -1, 18 NoError = -1,
18 Refuse = 0, 19 Refuse = 0,
19 CouldNotOpen =1, 20 CouldNotOpen =1,
20 ClosedUnexpected =2, 21 ClosedUnexpected =2,
21 ClosedError =3, 22 ClosedError =3,
22 Terminate = 4 23 Terminate = 4
23 /* add more errors here */ 24 /* add more errors here */
24 }; 25 };
25 /** 26 /**
26 * a small c'tor 27 * a small c'tor
27 */ 28 */
28 IOLayer(); 29 IOLayer();
29 30
30 /** 31 /**
31 * create an IOLayer instance from a config file 32 * create an IOLayer instance from a config file
32 * the currently set group stores the profile/session 33 * the currently set group stores the profile/session
33 * information 34 * information
34 */ 35 */
35 IOLayer( const Config& ); 36 IOLayer( const Profile& );
36 37
37 /** 38 /**
38 * destructor 39 * destructor
39 */ 40 */
40 virtual ~IOLayer(); 41 virtual ~IOLayer();
41 42
42 /** 43 /**
43 * a small internal identifier 44 * a small internal identifier
44 */ 45 */
45 virtual QString identifier() const = 0; 46 virtual QString identifier() const = 0;
46 47
47 /** 48 /**
diff --git a/noncore/apps/opie-console/io_serial.cpp b/noncore/apps/opie-console/io_serial.cpp
index c9155d1..b495f39 100644
--- a/noncore/apps/opie-console/io_serial.cpp
+++ b/noncore/apps/opie-console/io_serial.cpp
@@ -1,19 +1,19 @@
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 Config &config) : IOLayer(config) { 7IOSerial::IOSerial(const Profile &config) : IOLayer(config) {
8 m_fd = 0; 8 m_fd = 0;
9 reload(config); 9 reload(config);
10} 10}
11 11
12 12
13IOSerial::~IOSerial() { 13IOSerial::~IOSerial() {
14 if (m_fd) { 14 if (m_fd) {
15 close(); 15 close();
16 } 16 }
17} 17}
18 18
19void IOSerial::send(const QByteArray &data) { 19void IOSerial::send(const QByteArray &data) {
@@ -37,103 +37,104 @@ void IOSerial::close() {
37 37
38bool IOSerial::open() { 38bool IOSerial::open() {
39 if (!m_fd) { 39 if (!m_fd) {
40 struct termios tty; 40 struct termios tty;
41 m_fd = ::open(m_device, O_RDWR | O_NOCTTY | O_NONBLOCK); 41 m_fd = ::open(m_device, O_RDWR | O_NOCTTY | O_NONBLOCK);
42 if (m_fd < 0) { 42 if (m_fd < 0) {
43 emit error(CouldNotOpen, strerror(errno)); 43 emit error(CouldNotOpen, strerror(errno));
44 return FALSE; 44 return FALSE;
45 } 45 }
46 tcgetattr(m_fd, &tty); 46 tcgetattr(m_fd, &tty);
47 47
48 /* Baud rate */ 48 /* Baud rate */
49 int speed = getBaud(m_baud); 49 int speed = baud(m_baud);
50 if (speed == -1) { 50 if (speed == -1) {
51 emit error(Refuse, tr("Invalid baud rate")); 51 emit error(Refuse, tr("Invalid baud rate"));
52 } 52 }
53 cfsetospeed(&tty, speed); 53 cfsetospeed(&tty, speed);
54 cfsetispeed(&tty, speed); 54 cfsetispeed(&tty, speed);
55 55
56 /* Take care of Space / Mark parity */ 56 /* Take care of Space / Mark parity */
57 if (m_dbits == 7 && (m_parity == ParitySpace || m_parity == ParityMark)) { 57 if (m_dbits == 7 && (m_parity == ParitySpace || m_parity == ParityMark)) {
58 m_dbits = 8; 58 m_dbits = 8;
59 } 59 }
60 60
61 /* Data bits */ 61 /* Data bits */
62 switch (m_dbits) { 62 switch (m_dbits) {
63 case 5: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS5; break; 63 case 5: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS5; break;
64 case 6: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS6; break; 64 case 6: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS6; break;
65 case 7: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS7; break; 65 case 7: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS7; break;
66 case 8: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; break; 66 case 8: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; break;
67 default: break;
67 } 68 }
68 69
69 /* Raw, no echo mode */ 70 /* Raw, no echo mode */
70 tty.c_iflag = IGNBRK; 71 tty.c_iflag = IGNBRK;
71 tty.c_lflag = 0; 72 tty.c_lflag = 0;
72 tty.c_oflag = 0; 73 tty.c_oflag = 0;
73 tty.c_cflag |= CLOCAL | CREAD; 74 tty.c_cflag |= CLOCAL | CREAD;
74 75
75 /* Stop bits */ 76 /* Stop bits */
76 if (m_sbits == 2) { 77 if (m_sbits == 2) {
77 tty.c_cflag |= CSTOPB; 78 tty.c_cflag |= CSTOPB;
78 } else { 79 } else {
79 tty.c_cflag &= ~CSTOPB; 80 tty.c_cflag &= ~CSTOPB;
80 } 81 }
81 82
82 tty.c_cc[VMIN] = 1; 83 tty.c_cc[VMIN] = 1;
83 tty.c_cc[VTIME] = 5; 84 tty.c_cc[VTIME] = 5;
84 85
85 /* Flow control */ 86 /* Flow control */
86 if (m_flow & FlowSW) 87 if (m_flow & FlowSW)
87 tty.c_iflag |= IXON | IXOFF; 88 tty.c_iflag |= IXON | IXOFF;
88 else 89 else
89 tty.c_iflag &= ~(IXON|IXOFF|IXANY); 90 tty.c_iflag &= ~(IXON|IXOFF|IXANY);
90 91
91 if (m_flow & FlowHW) 92 if (m_flow & FlowHW)
92 tty.c_cflag |= CRTSCTS; 93 tty.c_cflag |= CRTSCTS;
93 else 94 else
94 tty.c_cflag &= ~CRTSCTS; 95 tty.c_cflag &= ~CRTSCTS;
95 96
96 /* Parity */ 97 /* Parity */
97 tty.c_cflag &= ~(PARENB | PARODD); 98 tty.c_cflag &= ~(PARENB | PARODD);
98 if (m_parity & ParityEven) 99 if (m_parity & ParityEven)
99 tty.c_cflag |= PARENB; 100 tty.c_cflag |= PARENB;
100 else if (m_parity & ParityOdd) 101 else if (m_parity & ParityOdd)
101 tty.c_cflag |= (PARENB | PARODD); 102 tty.c_cflag |= (PARENB | PARODD);
102 103
103 /* Set the changes */ 104 /* Set the changes */
104 tcsetattr(m_fd, TCSANOW, &tty); 105 tcsetattr(m_fd, TCSANOW, &tty);
105 106
106 /* Notifications on read & errors */ 107 /* Notifications on read & errors */
107 m_read = new QSocketNotifier(m_fd, QSocketNotifier::Read, this); 108 m_read = new QSocketNotifier(m_fd, QSocketNotifier::Read, this);
108 m_error = new QSocketNotifier(m_fd, QSocketNotifier::Exception, this); 109 m_error = new QSocketNotifier(m_fd, QSocketNotifier::Exception, this);
109 connect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived())); 110 connect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived()));
110 connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured())); 111 connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured()));
111 return TRUE; 112 return TRUE;
112 } else { 113 } else {
113 emit error(Refuse, tr("Device is already connected")); 114 emit error(Refuse, tr("Device is already connected"));
114 return FALSE; 115 return FALSE;
115 } 116 }
116} 117}
117 118
118void IOSerial::reload(const Config &config) { 119void IOSerial::reload(const Profile &config) {
119 m_device = config.readEntry("Device", SERIAL_DEFAULT_DEVICE); 120 m_device = config.readEntry("Device", SERIAL_DEFAULT_DEVICE);
120 m_baud = config.readNumEntry("Baud", SERIAL_DEFAULT_BAUD); 121 m_baud = config.readNumEntry("Baud", SERIAL_DEFAULT_BAUD);
121 m_parity = config.readNumEntry("Parity", SERIAL_DEFAULT_PARITY); 122 m_parity = config.readNumEntry("Parity", SERIAL_DEFAULT_PARITY);
122 m_dbits = config.readNumEntry("DataBits", SERIAL_DEFAULT_DBITS); 123 m_dbits = config.readNumEntry("DataBits", SERIAL_DEFAULT_DBITS);
123 m_sbits = config.readNumEntry("StopBits", SERIAL_DEFAULT_SBITS); 124 m_sbits = config.readNumEntry("StopBits", SERIAL_DEFAULT_SBITS);
124 m_flow = config.readNumEntry("Flow", SERIAL_DEFAULT_FLOW); 125 m_flow = config.readNumEntry("Flow", SERIAL_DEFAULT_FLOW);
125} 126}
126 127
127int IOSerial::getBaud(int baud) const { 128int IOSerial::baud(int baud) const {
128 switch (baud) { 129 switch (baud) {
129 case 300: return B300; break; 130 case 300: return B300; break;
130 case 600: return B600; break; 131 case 600: return B600; break;
131 case 1200: return B1200; break; 132 case 1200: return B1200; break;
132 case 2400: return B2400; break; 133 case 2400: return B2400; break;
133 case 4800: return B4800; break; 134 case 4800: return B4800; break;
134 case 9600: return B9600; break; 135 case 9600: return B9600; break;
135 case 19200: return B19200; break; 136 case 19200: return B19200; break;
136 case 38400: return B38400; break; 137 case 38400: return B38400; break;
137 case 57600: return B57600; break; 138 case 57600: return B57600; break;
138 case 115200: return B115200; break; 139 case 115200: return B115200; break;
139 } 140 }
diff --git a/noncore/apps/opie-console/io_serial.h b/noncore/apps/opie-console/io_serial.h
index 1d34411..521dac6 100644
--- a/noncore/apps/opie-console/io_serial.h
+++ b/noncore/apps/opie-console/io_serial.h
@@ -20,40 +20,40 @@ public:
20 enum Parity { 20 enum Parity {
21 ParityNone = 0, 21 ParityNone = 0,
22 ParityEven, 22 ParityEven,
23 ParityOdd, 23 ParityOdd,
24 ParitySpace, 24 ParitySpace,
25 ParityMark 25 ParityMark
26 }; 26 };
27 27
28 enum Flow { 28 enum Flow {
29 FlowHW = 0x01, 29 FlowHW = 0x01,
30 FlowSW = 0x02 30 FlowSW = 0x02
31 }; 31 };
32 32
33 IOSerial(const Config &); 33 IOSerial(const Profile &);
34 ~IOSerial(); 34 ~IOSerial();
35 35
36 QString identifier() const; 36 QString identifier() const;
37 QString name() const; 37 QString name() const;
38signals: 38signals:
39 void received(const QByteArray &); 39 void received(const QByteArray &);
40 void error(int, const QString &); 40 void error(int, const QString &);
41public slots: 41public slots:
42 void send(const QByteArray &); 42 void send(const QByteArray &);
43 bool open(); 43 bool open();
44 void close(); 44 void close();
45 void reload(const Config &); 45 void reload(const Profile &);
46protected: 46protected:
47 int getBaud(int baud) const; 47 int baud(int baud) const;
48protected slots: 48protected slots:
49 void dataArrived(); 49 void dataArrived();
50 void errorOccured(); 50 void errorOccured();
51protected: 51protected:
52 QSocketNotifier *m_read; 52 QSocketNotifier *m_read;
53 QSocketNotifier *m_error; 53 QSocketNotifier *m_error;
54 QString m_device; 54 QString m_device;
55 int m_baud; 55 int m_baud;
56 int m_parity; 56 int m_parity;
57 int m_dbits; 57 int m_dbits;
58 int m_sbits; 58 int m_sbits;
59 int m_flow; 59 int m_flow;
diff --git a/noncore/apps/opie-console/mainwindow.cpp b/noncore/apps/opie-console/mainwindow.cpp
index e9b5eda..1ae4a20 100644
--- a/noncore/apps/opie-console/mainwindow.cpp
+++ b/noncore/apps/opie-console/mainwindow.cpp
@@ -2,61 +2,122 @@
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 "metafactory.h" 8#include "metafactory.h"
9#include "mainwindow.h" 9#include "mainwindow.h"
10 10
11MainWindow::MainWindow() { 11MainWindow::MainWindow() {
12 m_factory = new MetaFactory(); 12 m_factory = new MetaFactory();
13 m_sessions.setAutoDelete( TRUE ); 13 m_sessions.setAutoDelete( TRUE );
14 m_curSession = -1; 14 m_curSession = 0;
15 15
16 initUI(); 16 initUI();
17} 17}
18void MainWindow::initUI() { 18void MainWindow::initUI() {
19 setToolBarsMovable( FALSE ); 19 setToolBarsMovable( FALSE );
20 20
21 m_tool = new QToolBar( this ); 21 m_tool = new QToolBar( this );
22 m_tool->setHorizontalStretchable( TRUE ); 22 m_tool->setHorizontalStretchable( TRUE );
23 23
24 m_bar = new QMenuBar( m_tool ); 24 m_bar = new QMenuBar( m_tool );
25 m_console = new QPopupMenu( this ); 25 m_console = new QPopupMenu( this );
26 m_sessionsPop= new QPopupMenu( this );
27 m_settings = new QPopupMenu( this );
26 28
27 /* 29 /*
28 * new Action for new sessions 30 * new Action for new sessions
29 */ 31 */
30 QAction* a = new QAction(); 32 QAction* a = new QAction();
31 a->setText( tr("New Connection") ); 33 a->setText( tr("New Connection") );
32 a->addTo( m_console ); 34 a->addTo( m_console );
33 connect(a, SIGNAL(activated() ), 35 connect(a, SIGNAL(activated() ),
34 this, SLOT(slotNew() ) ); 36 this, SLOT(slotNew() ) );
35 37
36 a = new QAction();
37 a->setText( tr("New from Session") );
38 38
39
40 /*
41 * connect action
42 */
39 m_connect = new QAction(); 43 m_connect = new QAction();
40 m_connect->setText( tr("Connect") ); 44 m_connect->setText( tr("Connect") );
41 m_connect->addTo( m_console ); 45 m_connect->addTo( m_console );
42 connect(m_connect, SIGNAL(activated() ), 46 connect(m_connect, SIGNAL(activated() ),
43 this, SLOT(slotConnect() ) ); 47 this, SLOT(slotConnect() ) );
44 48
49
50 /*
51 * disconnect action
52 */
53 m_disconnect = new QAction();
54 m_disconnect->setText( tr("Disconnect") );
55 m_disconnect->addTo( m_console );
56 connect(m_disconnect, SIGNAL(activated() ),
57 this, SLOT(slotDisconnect() ) );
58
59 /*
60 * terminate action
61 */
62 m_terminate = new QAction();
63 m_terminate->setText( tr("Terminate") );
64 m_terminate->addTo( m_console );
65 connect(m_disconnect, SIGNAL(activated() ),
66 this, SLOT(slotTerminate() ) );
67
68 /*
69 * the settings action
70 */
71 m_setProfiles = new QAction();
72 m_setProfiles->setText( tr("Configure Profiles") );
73 m_setProfiles->addTo( m_settings );
74 connect( m_setProfiles, SIGNAL(activated() ),
75 this, SLOT(slotConfigure() ) );
76
77 /* insert the submenu */
78 m_console->insertItem(tr("New from Profile"), m_sessionsPop,
79 -1, 0);
80
81 /* insert the connection menu */
45 m_bar->insertItem( tr("Connection"), m_console ); 82 m_bar->insertItem( tr("Connection"), m_console );
46 83
84 /* the settings menu */
85 m_bar->insertItem( tr("Settings"), m_settings );
86
47} 87}
48MainWindow::~MainWindow() { 88MainWindow::~MainWindow() {
49 delete m_factory; 89 delete m_factory;
50} 90}
51 91
52MetaFactory* MainWindow::factory() { 92MetaFactory* MainWindow::factory() {
53 return m_factory; 93 return m_factory;
54} 94}
55 95
56Session* MainWindow::currentSession() { 96Session* MainWindow::currentSession() {
57 return m_curSession; 97 return m_curSession;
58} 98}
59 99
60QList<Session> MainWindow::sessions() { 100QList<Session> MainWindow::sessions() {
61 return m_sessions; 101 return m_sessions;
62} 102}
103void MainWindow::slotNew() {
104 qWarning("New Connection");
105}
106void MainWindow::slotConnect() {
107 if ( currentSession() )
108 currentSession()->layer()->open();
109}
110void MainWindow::slotDisconnect() {
111 if ( currentSession() )
112 currentSession()->layer()->close();
113}
114void MainWindow::slotTerminate() {
115 if ( currentSession() )
116 currentSession()->layer()->close();
117 delete m_curSession;
118 m_curSession = 0l;
119 /* FIXME move to the next session */
120}
121void MainWindow::slotConfigure() {
122 qWarning("configure");
123}
diff --git a/noncore/apps/opie-console/mainwindow.h b/noncore/apps/opie-console/mainwindow.h
index db3a653..b6a8419 100644
--- a/noncore/apps/opie-console/mainwindow.h
+++ b/noncore/apps/opie-console/mainwindow.h
@@ -29,46 +29,51 @@ public:
29 MetaFactory* factory(); 29 MetaFactory* factory();
30 30
31 /** 31 /**
32 * A session contains a QWidget*, 32 * A session contains a QWidget*,
33 * an IOLayer* and some infos for us 33 * an IOLayer* and some infos for us
34 */ 34 */
35 Session* currentSession(); 35 Session* currentSession();
36 36
37 /** 37 /**
38 * the session list 38 * the session list
39 */ 39 */
40 QList<Session> sessions(); 40 QList<Session> sessions();
41protected slots: 41
42private slots:
42 void slotNew(); 43 void slotNew();
43 void slotConnect(); 44 void slotConnect();
45 void slotDisconnect();
46 void slotTerminate();
47 void slotConfigure();
48
44private: 49private:
45 void initUI(); 50 void initUI();
46 /** 51 /**
47 * the current session 52 * the current session
48 */ 53 */
49 Session* m_curSession; 54 Session* m_curSession;
50 55
51 /** 56 /**
52 * the session list 57 * the session list
53 */ 58 */
54 QList<Session> m_sessions; 59 QList<Session> m_sessions;
55 60
56 /** 61 /**
57 * the metafactory 62 * the metafactory
58 */ 63 */
59 MetaFactory* m_factory; 64 MetaFactory* m_factory;
60 65
61 QToolBar* m_tool; 66 QToolBar* m_tool;
62 QMenuBar* m_bar; 67 QMenuBar* m_bar;
63 QPopupMenu* m_console; 68 QPopupMenu* m_console;
64 QPopupMenu* m_settings; 69 QPopupMenu* m_settings;
65 QPopupMenu* m_newsession; 70 QPopupMenu* m_sessionsPop;
66 QAction* m_connect; 71 QAction* m_connect;
67 QAction* m_disconnect; 72 QAction* m_disconnect;
68 QAction* m_terminate; 73 QAction* m_terminate;
69 QAction* m_set; 74 QAction* m_setProfiles;
70 75
71}; 76};
72 77
73 78
74#endif 79#endif
diff --git a/noncore/apps/opie-console/metafactory.cpp b/noncore/apps/opie-console/metafactory.cpp
index bef6ec7..754f34c 100644
--- a/noncore/apps/opie-console/metafactory.cpp
+++ b/noncore/apps/opie-console/metafactory.cpp
@@ -1,13 +1,13 @@
1 1#include <qpe/config.h>
2#include "metafactory.h" 2#include "metafactory.h"
3 3
4MetaFactory::MetaFactory() { 4MetaFactory::MetaFactory() {
5} 5}
6MetaFactory::~MetaFactory() { 6MetaFactory::~MetaFactory() {
7 7
8} 8}
9void MetaFactory::addConfigWidgetFactory( const QString& str, 9void MetaFactory::addConfigWidgetFactory( const QString& str,
10 configWidget wid) { 10 configWidget wid) {
11 m_confFact.insert( str, wid ); 11 m_confFact.insert( str, wid );
12} 12}
13void MetaFactory::addIOLayerFactory( const QString& str, 13void MetaFactory::addIOLayerFactory( const QString& str,
@@ -33,12 +33,26 @@ QStringList MetaFactory::configWidgets()const {
33 list << it.key(); 33 list << it.key();
34 } 34 }
35 return list; 35 return list;
36} 36}
37QStringList MetaFactory::fileTransferLayers()const { 37QStringList MetaFactory::fileTransferLayers()const {
38 QStringList list; 38 QStringList list;
39 QMap<QString, filelayer>::ConstIterator it; 39 QMap<QString, filelayer>::ConstIterator it;
40 for ( it = m_fileFact.begin(); it != m_fileFact.end(); ++it ) { 40 for ( it = m_fileFact.begin(); it != m_fileFact.end(); ++it ) {
41 list << it.key(); 41 list << it.key();
42 } 42 }
43 return list; 43 return list;
44} 44}
45IOLayer* MetaFactory::newIOLayer( const QString& str,const Profile& prof ) {
46 IOLayer* lay = 0l;
47
48 QMap<QString, iolayer>::Iterator it;
49 it = m_layerFact.find( str );
50 if ( it != m_layerFact.end() ) {
51 lay = (*(it.data()))(prof);
52 /*
53 iolayer laye = it.data();
54 lay = (*laye )(conf);*/
55 }
56
57 return lay;
58}
diff --git a/noncore/apps/opie-console/metafactory.h b/noncore/apps/opie-console/metafactory.h
index aae9391..bdd2ad2 100644
--- a/noncore/apps/opie-console/metafactory.h
+++ b/noncore/apps/opie-console/metafactory.h
@@ -4,40 +4,42 @@
4/** 4/**
5 * The MetaFactory is used to keep track of all IOLayers, FileTransferLayers and ConfigWidgets 5 * The MetaFactory is used to keep track of all IOLayers, FileTransferLayers and ConfigWidgets
6 * and to instantiate these implementations on demand 6 * and to instantiate these implementations on demand
7 */ 7 */
8 8
9#include <qwidget.h> 9#include <qwidget.h>
10#include <qmap.h> 10#include <qmap.h>
11 11
12#include <qpe/config.h> 12#include <qpe/config.h>
13 13
14#include "io_layer.h" 14#include "io_layer.h"
15#include "file_layer.h" 15#include "file_layer.h"
16 16#include "profile.h"
17 17
18class MetaFactory { 18class MetaFactory {
19public: 19public:
20 typedef QWidget* (*configWidget)(QWidget* parent); 20 typedef QWidget* (*configWidget)(QWidget* parent);
21 typedef IOLayer* (*iolayer)(const Config& ); 21 typedef IOLayer* (*iolayer)(const Profile& );
22 typedef FileTransferLayer* (*filelayer)(IOLayer*); 22 typedef FileTransferLayer* (*filelayer)(IOLayer*);
23 23
24 MetaFactory(); 24 MetaFactory();
25 ~MetaFactory(); 25 ~MetaFactory();
26 26
27 void addConfigWidgetFactory( const QString&, 27 void addConfigWidgetFactory( const QString&,
28 configWidget ); 28 configWidget );
29 void addIOLayerFactory(const QString&, 29 void addIOLayerFactory(const QString&,
30 iolayer ); 30 iolayer );
31 void addFileTransferLayer( const QString&, 31 void addFileTransferLayer( const QString&,
32 filelayer ); 32 filelayer );
33 QStringList ioLayers()const; 33 QStringList ioLayers()const;
34 QStringList configWidgets()const; 34 QStringList configWidgets()const;
35 QStringList fileTransferLayers()const; 35 QStringList fileTransferLayers()const;
36 IOLayer* newIOLayer( const QString&,const Profile& );
37
36private: 38private:
37 QMap<QString, configWidget> m_confFact; 39 QMap<QString, configWidget> m_confFact;
38 QMap<QString, iolayer> m_layerFact; 40 QMap<QString, iolayer> m_layerFact;
39 QMap<QString, filelayer> m_fileFact; 41 QMap<QString, filelayer> m_fileFact;
40}; 42};
41 43
42 44
43#endif 45#endif
diff --git a/noncore/apps/opie-console/opie-console.pro b/noncore/apps/opie-console/opie-console.pro
index 4a1180f..e045a48 100644
--- a/noncore/apps/opie-console/opie-console.pro
+++ b/noncore/apps/opie-console/opie-console.pro
@@ -1,19 +1,28 @@
1TEMPLATE = app 1TEMPLATE = app
2CONFIG = qt warn_on release 2CONFIG = qt warn_on release
3DESTDIR = $(OPIEDIR)/bin 3DESTDIR = $(OPIEDIR)/bin
4HEADERS = io_layer.h io_serial.h \ 4HEADERS = io_layer.h io_serial.h \
5 file_layer.h \ 5 file_layer.h \
6 metafactory.h \ 6 metafactory.h \
7 session.h \ 7 session.h \
8 mainwindow.h 8 mainwindow.h \
9 profile.h \
10 profileconfig.h \
11 profilemanager.h \
12 configwidget.h \
13 tabwidget.h
9SOURCES = io_layer.cpp io_serial.cpp \ 14SOURCES = io_layer.cpp io_serial.cpp \
10 file_layer.cpp main.cpp \ 15 file_layer.cpp main.cpp \
11 metafactory.cpp \ 16 metafactory.cpp \
12 session.cpp \ 17 session.cpp \
13 mainwindow.cpp 18 mainwindow.cpp \
19 profile.cpp \
20 profileconfig.cpp \
21 profilemanager.cpp \
22 tabwidget.cpp
14INTERFACES = 23INTERFACES =
15INCLUDEPATH += $(OPIEDIR)/include 24INCLUDEPATH += $(OPIEDIR)/include
16DEPENDPATH += $(OPIEDIR)/include 25DEPENDPATH += $(OPIEDIR)/include
17LIBS += -lqpe -lopie 26LIBS += -lqpe -lopie
18TARGET = opie-console 27TARGET = opie-console
19 28
diff --git a/noncore/apps/opie-console/profile.cpp b/noncore/apps/opie-console/profile.cpp
new file mode 100644
index 0000000..b730218
--- a/dev/null
+++ b/noncore/apps/opie-console/profile.cpp
@@ -0,0 +1,59 @@
1#include "profile.h"
2
3Profile::Profile() {
4
5}
6Profile::Profile( const QString& name,
7 const QString& iolayerName,
8 int background,
9 int foreground,
10 int terminal )
11 : m_name( name ), m_ioLayer( iolayerName ), m_back( background ),
12 m_fore( foreground ), m_terminal( terminal )
13{
14}
15Profile::Profile( const Profile& prof )
16{
17 (*this) = prof;
18}
19Profile &Profile::operator=( const Profile& prof ) {
20 m_name = prof.m_name;
21 m_ioLayer = prof.m_ioLayer;
22 m_back = prof.m_back;
23 m_fore = prof.m_fore;
24 m_terminal = prof.m_terminal;
25
26 return *this;
27}
28Profile::~Profile() {
29}
30QString Profile::name()const {
31 return m_name;
32}
33QString Profile::ioLayerName()const {
34 return m_ioLayer;
35}
36int Profile::foreground()const {
37 return m_fore;
38}
39int Profile::background()const {
40 return m_back;
41}
42int Profile::terminal()const {
43 return m_terminal;
44}
45void Profile::setName( const QString& str ) {
46 m_name = str;
47}
48void Profile::setIOLayer( const QString& name ) {
49 m_ioLayer = name;
50}
51void Profile::setBackground( int back ) {
52 m_back = back;
53}
54void Profile::setForeground( int fore ) {
55 m_fore = fore;
56}
57void Profile::setTerminal( int term ) {
58 m_terminal = term;
59}
diff --git a/noncore/apps/opie-console/profile.h b/noncore/apps/opie-console/profile.h
new file mode 100644
index 0000000..8adc0bd
--- a/dev/null
+++ b/noncore/apps/opie-console/profile.h
@@ -0,0 +1,66 @@
1#ifndef OPIE_PROFILE_H
2#define OPIE_PROFILE_H
3
4#include <qmap.h>
5#include <qstring.h>
6#include <qstringlist.h>
7#include <qvaluelist.h>
8/**
9 * A session will be generated from a saved
10 * profile. A profile contains the iolayername
11 * a name.
12 * We can generate a Session from a Profile
13 * No configuration is contained here....
14 */
15class Profile {
16public:
17 typedef QValueList<Profile> ValueList;
18 enum Color { Black = 0,
19 White,
20 Gray };
21 enum Terminal {VT102 = 0 };
22 enum Font { Micro = 0, Small, Medium };
23 Profile();
24 Profile( const QString& name,
25 const QString& iolayerName,
26 int background,
27 int foreground,
28 int terminal);
29 Profile( const Profile& );
30 Profile &operator=( const Profile& );
31
32 ~Profile();
33 QString name()const;
34 QString ioLayerName()const;
35 int foreground()const;
36 int background()const;
37 int terminal()const;
38
39 /*
40 * config stuff
41 */
42 QMap<QString, QString> conf();
43 void clearConf();
44 void writeEntry( const QString& key, const QString& value );
45 void writeEntry( const QString& key, int num );
46 void writeEntry( const QString& key, bool b );
47 void writeEntry( const QString& key, const QStringList&, const QChar& );
48 QString readEntry( const QString& key, const QString& deflt = QString::null)const;
49 int readNumEntry( const QString& key, int = -1 )const;
50 bool readBoolEntry( const QString& key, bool = FALSE )const;
51
52 void setName( const QString& );
53 void setIOLayer( const QString& );
54 void setBackground( int back );
55 void setForeground( int fore );
56 void setTerminal( int term );
57private:
58 QMap<QString, QString> m_conf;
59 QString m_name;
60 QString m_ioLayer;
61 int m_back;
62 int m_fore;
63 int m_terminal;
64};
65
66#endif
diff --git a/noncore/apps/opie-console/profileconfig.cpp b/noncore/apps/opie-console/profileconfig.cpp
new file mode 100644
index 0000000..8b16920
--- a/dev/null
+++ b/noncore/apps/opie-console/profileconfig.cpp
@@ -0,0 +1,35 @@
1
2#include "profileconfig.h"
3
4ProfileConfig::ProfileConfig( const QString& prof )
5 : Config( prof )
6{
7}
8ProfileConfig::~ProfileConfig() {
9
10}
11QStringList ProfileConfig::groups()const {
12 QStringList list;
13 QMap<QString, ConfigGroup>::ConstIterator it;
14 it= Config::groups.begin();
15
16 for (; it != Config::groups.end(); ++it )
17 list << it.key();
18
19
20 return list;
21
22}
23void ProfileConfig::clearAll() {
24 QMap<QString, ConfigGroup>::ConstIterator it;
25 it = Config::groups.begin();
26
27 for ( ; it != Config::groups.end(); ++it )
28 clearGroup( it.key() );
29}
30void ProfileConfig::clearGroup( const QString& str ) {
31 QString cur =git.key();
32 setGroup( str );
33 Config::clearGroup();
34 setGroup( cur );
35}
diff --git a/noncore/apps/opie-console/profileconfig.h b/noncore/apps/opie-console/profileconfig.h
new file mode 100644
index 0000000..e2e149c
--- a/dev/null
+++ b/noncore/apps/opie-console/profileconfig.h
@@ -0,0 +1,17 @@
1
2#ifndef OPIE_PROFILE_CONFIG_H
3#define OPIE_PROFILE_CONFIG_H
4
5#include <qpe/config.h>
6#include <qstringlist.h>
7
8class ProfileConfig : public Config {
9public:
10 ProfileConfig( const QString& prof );
11 ~ProfileConfig();
12 QStringList groups()const;
13 void clearGroup( const QString& );
14 void clearAll();
15
16};
17#endif
diff --git a/noncore/apps/opie-console/profilemanager.cpp b/noncore/apps/opie-console/profilemanager.cpp
new file mode 100644
index 0000000..db36686
--- a/dev/null
+++ b/noncore/apps/opie-console/profilemanager.cpp
@@ -0,0 +1,62 @@
1
2#include <qpe/config.h>
3
4#include "metafactory.h"
5#include "profileconfig.h"
6#include "profilemanager.h"
7
8ProfileManager::ProfileManager( MetaFactory* fact )
9 : m_fact( fact )
10{
11
12}
13ProfileManager::~ProfileManager() {
14
15}
16void ProfileManager::load() {
17 m_list.clear();
18 ProfileConfig conf("opie-console-profiles");
19 QStringList groups = conf.groups();
20 QStringList::Iterator it;
21
22 /*
23 * for each profile
24 */
25 /*
26 * QAsciiDict Parsing FIXME
27 */
28 for ( it = groups.begin(); it != groups.end(); ++it ) {
29 conf.setGroup( (*it) );
30 Profile prof;
31 prof.setName( conf.readEntry("name") );
32 prof.setIOLayer( conf.readEntry("iolayer") );
33 prof.setBackground( conf.readNumEntry("back") );
34 prof.setForeground( conf.readNumEntry("fore") );
35 prof.setTerminal( conf.readNumEntry("terminal") );
36
37 m_list.append( prof );
38 }
39
40}
41Profile::ValueList ProfileManager::all()const {
42 return m_list;
43}
44Session* ProfileManager::fromProfile( const Profile& prof) {
45 Session* session = new Session();
46 session->setName( prof.name() );
47 session->setIOLayer(m_fact->newIOLayer(prof.ioLayerName(),
48 prof) );
49 /*
50 * FIXME
51 * load emulation
52 * load widget
53 * set colors + fonts
54 */
55 return session;
56}
57void ProfileManager::save( ) {
58 m_list.clear();
59 ProfileConfig conf("opie-console-profiles");
60 Session* se= 0l;
61 // FIXME save
62}
diff --git a/noncore/apps/opie-console/profilemanager.h b/noncore/apps/opie-console/profilemanager.h
new file mode 100644
index 0000000..d4d0fd0
--- a/dev/null
+++ b/noncore/apps/opie-console/profilemanager.h
@@ -0,0 +1,30 @@
1#ifndef OPIE_PROFILE_MANAGER_H
2#define OPIE_PROFILE_MANAGER_H
3
4#include <qlist.h>
5
6#include "session.h"
7#include "profile.h"
8
9class MetaFactory;
10class ConfigWidget;
11class ProfileManager {
12public:
13 ProfileManager(MetaFactory*);
14 ~ProfileManager();
15
16 void load();
17 Profile::ValueList all()const;
18 void clear();
19 /**
20 * also replaces the item
21 */
22 void add( const Profile& prof );
23 void remove( const Profile& prof );
24 Session* fromProfile( const Profile& );
25 void save();
26private:
27 MetaFactory* m_fact;
28 Profile::ValueList m_list;
29};
30#endif
diff --git a/noncore/apps/opie-console/session.cpp b/noncore/apps/opie-console/session.cpp
index 4198fdc..d32b340 100644
--- a/noncore/apps/opie-console/session.cpp
+++ b/noncore/apps/opie-console/session.cpp
@@ -1,26 +1,38 @@
1 1
2 2
3#include "io_layer.h" 3#include "io_layer.h"
4#include "file_layer.h" 4#include "file_layer.h"
5#include "session.h" 5#include "session.h"
6 6
7Session::Session( QWidget* widget, IOLayer* lay) 7Session::Session() {
8 : m_widget( widget ), m_layer( lay ) 8 m_widget = 0l;
9 m_layer = 0l;
10}
11Session::Session( const QString& na, QWidget* widget, IOLayer* lay)
12 : m_name( na ), m_widget( widget ), m_layer( lay )
9{ 13{
10} 14}
11Session::~Session() { 15Session::~Session() {
12 delete m_layer; 16 delete m_layer;
13 delete m_widget; 17 delete m_widget;
14} 18}
19QString Session::name()const {
20 return m_name;
21}
15QWidget* Session::widget() { 22QWidget* Session::widget() {
16 return m_widget; 23 return m_widget;
17} 24}
18IOLayer* Session::layer() { 25IOLayer* Session::layer() {
19 return m_layer; 26 return m_layer;
20} 27}
28void Session::setName( const QString& na){
29 m_name = na;
30}
21void Session::setWidget( QWidget* wid ) { 31void Session::setWidget( QWidget* wid ) {
32 delete m_widget;
22 m_widget = wid; 33 m_widget = wid;
23} 34}
24void Session::setIOLayer( IOLayer* lay ) { 35void Session::setIOLayer( IOLayer* lay ) {
36 delete m_layer;
25 m_layer = lay; 37 m_layer = lay;
26} 38}
diff --git a/noncore/apps/opie-console/session.h b/noncore/apps/opie-console/session.h
index 3978e1b..44b5fc8 100644
--- a/noncore/apps/opie-console/session.h
+++ b/noncore/apps/opie-console/session.h
@@ -7,33 +7,42 @@ class IOLayer;
7/** 7/**
8 * This is a Session. A session contains 8 * This is a Session. A session contains
9 * a QWidget pointer and a IOLayer 9 * a QWidget pointer and a IOLayer
10 * Imagine a session like a collection of what 10 * Imagine a session like a collection of what
11 * is needed to show your widget in a tab ;) 11 * is needed to show your widget in a tab ;)
12 */ 12 */
13class Session { 13class Session {
14public: 14public:
15 /** 15 /**
16 * c'tor with widget and layer 16 * c'tor with widget and layer
17 * ownership get's transfered 17 * ownership get's transfered
18 */ 18 */
19 Session( QWidget* widget, IOLayer* ); 19 Session();
20 Session( const QString&, QWidget* widget, IOLayer* );
20 ~Session(); 21 ~Session();
21 22
22 /** 23 /**
24 * return the name of the session
25 */
26 QString name()const;
27
28 /**
23 * return the widget 29 * return the widget
24 */ 30 */
25 QWidget* widget(); 31 QWidget* widget();
26 32
27 /** 33 /**
28 * return the layer 34 * return the layer
29 */ 35 */
30 IOLayer* layer(); 36 IOLayer* layer();
31 void setWidget( QWidget* widget ); 37 void setWidget( QWidget* widget );
32 void setIOLayer( IOLayer* ); 38 void setIOLayer( IOLayer* );
39 void setName( const QString& );
33 40
34private: 41private:
42 QString m_name;
35 QWidget* m_widget; 43 QWidget* m_widget;
36 IOLayer* m_layer; 44 IOLayer* m_layer;
45
37}; 46};
38 47
39#endif 48#endif
diff --git a/noncore/apps/opie-console/tabwidget.cpp b/noncore/apps/opie-console/tabwidget.cpp
new file mode 100644
index 0000000..6091aa2
--- a/dev/null
+++ b/noncore/apps/opie-console/tabwidget.cpp
@@ -0,0 +1,28 @@
1
2#include "tabwidget.h"
3
4TabWidget::TabWidget( QWidget* parent, const char* name )
5 : QTabWidget( parent, name )
6{
7 connect(this, SIGNAL(currentChanged(QWidget*) ),
8 this, SLOT(slotCurChanged(QWidget*) ) );
9}
10TabWidget::~TabWidget() {
11}
12void TabWidget::add( Session* ses ) {
13 if ( !ses->widget() ) return;
14 addTab( ses->widget(), ses->name() );
15 m_map.insert( ses->widget(), ses );
16}
17void TabWidget::remove( Session* ses ) {
18 m_map.remove( ses->widget() );
19 removePage( ses->widget() );
20}
21void TabWidget::slotCurChanged( QWidget* wid ) {
22 QMap<QWidget*, Session*>::Iterator it;
23 it = m_map.find(wid );
24 if (it == m_map.end() )
25 return;
26
27 emit activated( it.data() );
28}
diff --git a/noncore/apps/opie-console/tabwidget.h b/noncore/apps/opie-console/tabwidget.h
new file mode 100644
index 0000000..d5d4be3
--- a/dev/null
+++ b/noncore/apps/opie-console/tabwidget.h
@@ -0,0 +1,28 @@
1#ifndef OPIE_TAB_WIDGET_H
2#define OPIE_TAB_WIDGET_H
3
4#include <qmap.h>
5#include <qtabwidget.h>
6
7#include "session.h"
8/**
9 * This is our central tab widget
10 * we can add sessions here
11 */
12class TabWidget : QTabWidget{
13 Q_OBJECT
14public:
15 TabWidget(QWidget *parent, const char* name );
16 ~TabWidget();
17 void add( Session* );
18 void remove( Session* );
19
20signals:
21 void activated(Session* ses );
22private slots:
23 void slotCurChanged( QWidget* wid );
24private:
25 QMap<QWidget*, Session*> m_map;
26};
27
28#endif