-rw-r--r-- | libopie2/opiepim/ui/opimmainwindow.cpp | 71 | ||||
-rw-r--r-- | libopie2/opiepim/ui/opimmainwindow.h | 79 |
2 files changed, 150 insertions, 0 deletions
diff --git a/libopie2/opiepim/ui/opimmainwindow.cpp b/libopie2/opiepim/ui/opimmainwindow.cpp new file mode 100644 index 0000000..92be2fd --- a/dev/null +++ b/libopie2/opiepim/ui/opimmainwindow.cpp | |||
@@ -0,0 +1,71 @@ | |||
1 | #include <qapplication.h> | ||
2 | #include <qcopchannel_qws.h> | ||
3 | |||
4 | #include <qpe/qcopenvelope_qws.h> | ||
5 | |||
6 | #include "opimmainwindow.h" | ||
7 | |||
8 | OPimMainWindow::OPimMainWindow( const QString& service, QWidget* parent, | ||
9 | const char* name, WFlags flag ) | ||
10 | : QMainWindow( parent, name, flag ), m_service( service ), m_fallBack(0l) { | ||
11 | |||
12 | /* | ||
13 | * let's generate our QCopChannel | ||
14 | */ | ||
15 | m_str = QString("QPE/"+m_service).local8Bit(); | ||
16 | m_channel= new QCopChannel(m_str, this ); | ||
17 | connect(m_channel, SIGNAL(received(const QCString&, const QByteArray& ) ), | ||
18 | this, SLOT( appMessage( const QCString&, const QByteArray& ) ) ); | ||
19 | |||
20 | /* connect flush and reload */ | ||
21 | connect(qApp, SIGNAL(flush() ), | ||
22 | this, SLOT(flush() ) ); | ||
23 | connect(qApp, SIGNAL(reload() ), | ||
24 | this, SLOT(reload() ) ); | ||
25 | } | ||
26 | OPimMainWindow::~OPimMainWindow() { | ||
27 | delete m_channel; | ||
28 | } | ||
29 | QCopChannel* OPimMainWindow::channel() { | ||
30 | return m_channel; | ||
31 | } | ||
32 | void OPimMainWindow::appMessage( const QCString& cmd, const QByteArray& array ) { | ||
33 | /* | ||
34 | * create demands to create | ||
35 | * a new record... | ||
36 | */ | ||
37 | QDataStream stream(array, IO_ReadOnly); | ||
38 | if ( cmd == "create()" ) { | ||
39 | int uid = create(); | ||
40 | QCopEnvelope e(m_str, "created(int)" ); | ||
41 | e << uid; | ||
42 | }else if ( cmd == "remove(int)" ) { | ||
43 | int uid; | ||
44 | stream >> uid; | ||
45 | bool rem = remove( uid ); | ||
46 | QCopEnvelope e(m_str, "removed(bool)" ); | ||
47 | e << rem; | ||
48 | }else if ( cmd == "beam(int,int)" ) { | ||
49 | int uid, trans; | ||
50 | stream >> uid; | ||
51 | stream >> trans; | ||
52 | beam( uid, trans ); | ||
53 | }else if ( cmd == "show(int)" ) { | ||
54 | int uid; | ||
55 | stream >> uid; | ||
56 | show( uid ); | ||
57 | }else if ( cmd == "edit(int)" ) { | ||
58 | int uid; | ||
59 | stream >> uid; | ||
60 | edit( uid ); | ||
61 | }else if ( cmd == "add(int,QByteArray)" ) { | ||
62 | int rtti; | ||
63 | QByteArray array; | ||
64 | stream >> rtti; | ||
65 | stream >> array; | ||
66 | m_fallBack = record(rtti, array ); | ||
67 | if (!m_fallBack) return; | ||
68 | add( *m_fallBack ); | ||
69 | delete m_fallBack; | ||
70 | } | ||
71 | } | ||
diff --git a/libopie2/opiepim/ui/opimmainwindow.h b/libopie2/opiepim/ui/opimmainwindow.h new file mode 100644 index 0000000..94100bd --- a/dev/null +++ b/libopie2/opiepim/ui/opimmainwindow.h | |||
@@ -0,0 +1,79 @@ | |||
1 | #ifndef OPIE_PIM_MAINWINDOW_H | ||
2 | #define OPIE_PIM_MAINWINDOW_H | ||
3 | |||
4 | #include <qmainwindow.h> | ||
5 | |||
6 | #include <opie/opimrecord.h> | ||
7 | |||
8 | /** | ||
9 | * This is a common Opie PIM MainWindow | ||
10 | * it takes care of the QCOP internals | ||
11 | * and implements some functions | ||
12 | * for the URL scripting schema | ||
13 | */ | ||
14 | /* | ||
15 | * due Qt and Templates with signal and slots | ||
16 | * do not work that good :( | ||
17 | * (Ok how to moc a template ;) ) | ||
18 | * We will have the mainwindow which calls a struct which | ||
19 | * is normally reimplemented as a template ;) | ||
20 | */ | ||
21 | |||
22 | class QCopChannel; | ||
23 | class OPimMainWindow : public QMainWindow { | ||
24 | Q_OBJECT | ||
25 | public: | ||
26 | enum TransPort { BlueTooth=0, | ||
27 | IrDa }; | ||
28 | |||
29 | OPimMainWindow( const QString& service, QWidget *parent = 0, const char* name = 0, | ||
30 | WFlags f = WType_TopLevel); | ||
31 | virtual ~OPimMainWindow(); | ||
32 | |||
33 | |||
34 | protected slots: | ||
35 | /* for syncing */ | ||
36 | virtual void flush() = 0; | ||
37 | virtual void reload() = 0; | ||
38 | |||
39 | /** create a new Records and return the uid */ | ||
40 | virtual int create() = 0; | ||
41 | /** remove a record with UID == uid */ | ||
42 | virtual bool remove( int uid ) = 0; | ||
43 | /** beam the record with UID = uid */ | ||
44 | virtual void beam( int uid , int transport = IrDa) = 0; | ||
45 | |||
46 | /** show the record with UID == uid */ | ||
47 | virtual void show( int uid ) = 0; | ||
48 | /** edit the record */ | ||
49 | virtual void edit( int uid ) = 0; | ||
50 | |||
51 | /** make a copy of it! */ | ||
52 | virtual void add( const OPimRecord& ) = 0; | ||
53 | |||
54 | /* I would love to do this as a template | ||
55 | * but can't think of a right way | ||
56 | * because I need signal and slots -zecke | ||
57 | */ | ||
58 | /* | ||
59 | * the only pointer in the whole PIM API :( | ||
60 | */ | ||
61 | virtual OPimRecord* record( int rtti, const QByteArray& ) = 0; | ||
62 | QCopChannel* channel(); | ||
63 | |||
64 | private slots: | ||
65 | void appMessage( const QCString&, const QByteArray& ); | ||
66 | |||
67 | |||
68 | private: | ||
69 | class Private; | ||
70 | Private* d; | ||
71 | |||
72 | QCopChannel* m_channel; | ||
73 | QString m_service; | ||
74 | QCString m_str; | ||
75 | OPimRecord* m_fallBack; | ||
76 | }; | ||
77 | |||
78 | |||
79 | #endif | ||