summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/sms/services/gsmlib.h
blob: 5f7b9257a3e0559f661ea105b357790d0f11463d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*  *************************************************************************
    *   copyright: (C) 2005 Justin Huff <jjhuff@mspin.net>                  *
    *************************************************************************
*/

/*  *************************************************************************
    *                                                                       *
    * This program is free software; you can redistribute it and/or modify  *
    * it under the terms of the GNU General Public License as published by  *
    * the Free Software Foundation; either version 2 of the License, or     *
    * (at your option) any later version.                                   *
    *                                                                       *
    *************************************************************************
*/

#ifndef GSMLIB_H_039562406
#define GSMLIB_H_039562406

#include "config.h"
#ifdef INCLUDE_SMSGSM

#include <unistd.h>

#include <gsmlib/gsm_unix_serial.h>
#include <gsmlib/gsm_sms.h>
#include <gsmlib/gsm_me_ta.h>
#include <gsmlib/gsm_util.h>
#include <gsmlib/gsm_event.h>

#include "smsservice.h"
#include "kopetemessage.h"

#include <tqobject.h>
#include <tqevent.h>
#include <tqthread.h>
#include <tqmutex.h>
#include <tqvaluelist.h>
#include <tqstringlist.h>

class GSMLibPrefsUI;
class SMSContact;
class TQListViewItem;
class TDEProcess;
class GSMLibThread;

class GSMLib : public SMSService
{
    Q_OBJECT
  
public:
    GSMLib(Kopete::Account* account);
    ~GSMLib();

    void send(const Kopete::Message& msg);
    void setWidgetContainer(TQWidget* parent, TQGridLayout* container);

    int maxSize();
    const TQString& description();

public slots:
    void savePreferences();
	virtual void connect();
	virtual void disconnect();

//signals:
//	void messageSent(const Kopete::Message &);
protected:
	virtual void customEvent(TQCustomEvent* e);
	
    TQWidget* configureWidget(TQWidget* parent);
	void saveConfig(); 
	void loadConfig(); 

    GSMLibPrefsUI* prefWidget;
    TQStringList output;

	TQString m_device;
	
    TQString m_description;

	GSMLibThread* m_thread;
	
} ;


/// Custom event for async-events
class GSMLibEvent : public TQCustomEvent
{
public:
	enum SubType { CONNECTED, DISCONNECTED, NEW_MESSAGE, MSG_SENT, MSG_NOT_SENT };
	
	GSMLibEvent(SubType t);

	SubType subType();
	void setSubType(SubType t);

	TQString Text;
	TQString Number;
	
	TQString Reason;
	
	Kopete::Message Message;
protected:
	SubType m_subType;
};

/// Thread to deal with GsmLib's blocking 
class GSMLibThread : public TQThread, gsmlib::GsmEvent
{
public:
	GSMLibThread(TQString dev, GSMLib* parent);
	virtual ~GSMLibThread();
	
	virtual void run();
	void stop();
	void send(const Kopete::Message& msg);
protected:
	bool doConnect();
	void pollForMessages();
	void sendMessageQueue();
	void sendMessage(const Kopete::Message& msg);
    void SMSReception(gsmlib::SMSMessageRef newMessage, SMSMessageType messageType);
    void SMSReceptionIndication(std::string storeName, unsigned int index, SMSMessageType messageType);
	
	GSMLib* m_parent;
	TQString m_device;
	
    gsmlib::MeTa* m_MeTa;
	
	bool m_run;
	
    struct IncomingMessage
    {
        int Index;
        TQString StoreName;
        gsmlib::SMSMessageRef Message;
        GsmEvent::SMSMessageType Type; 

        IncomingMessage() :   Index(-1)
        {}
    };

    typedef TQValueList<IncomingMessage> MessageList;
    MessageList m_newMessages;

	typedef TQValueList<Kopete::Message> KopeteMessageList;
	KopeteMessageList m_outMessages;
	TQMutex m_outMessagesMutex;
};

#endif
#endif //GSMLIB_H_039562406