source: qutecom-2.2/wengophone/src/model/history/HistoryMemento.h @ 608:91ffb4958dcf

Last change on this file since 608:91ffb4958dcf was 608:91ffb4958dcf, checked in by laurent@…, 3 years ago

store in history chat sip alias contact + use alias on chat window

File size: 5.9 KB
Line 
1/*
2 * WengoPhone, a voice over Internet phone
3 * Copyright (C) 2004-2006  Wengo
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 */
19
20#ifndef OWHISTORYMEMENTO_H
21#define OWHISTORYMEMENTO_H
22
23#include <sipwrapper/EnumPhoneCallState.h>
24
25#include <util/Date.h>
26#include <util/Time.h>
27#include <serializer/DateXMLSerializer.h>
28#include <serializer/TimeXMLSerializer.h>
29
30#include <string>
31
32#include <boost/archive/xml_iarchive.hpp>
33#include <boost/archive/xml_oarchive.hpp>
34#include <boost/archive/archive_exception.hpp>
35
36/**
37 * History Memento (Memento in the Memento pattern)
38 *
39 * @author Mathieu Stute
40 */
41class HistoryMemento {
42        friend class HistoryMementoCollection;
43        friend class History;
44public:
45
46        static const unsigned int SERIALIZATION_VERSION = 1;
47
48        /**
49         * State of a memento.
50         */
51        enum State {
52                IncomingCall,
53                OutgoingCall,
54                MissedCall,
55                RejectedCall,
56                OutgoingSmsOk,
57                OutgoingSmsNok,
58                ChatSession,
59                FileTransferUploaded,
60                FileTransferDownloaded,
61                FileTransferInProgress,
62                FileTransferCancelled,
63                FileTransferPaused,
64                None,
65                Any,
66        };
67
68        /**
69         * Default constructor.
70         */
71        HistoryMemento();
72
73        /**
74         * Complete constructor.
75         */
76        HistoryMemento(State state, const std::string & peer, int callId = -1, const std::string & data = "",const std::string & alias = "" );
77
78        /**
79         * a more complete constructor
80         */
81        HistoryMemento(State state, Date date, Time time, const std::string & peer, int callId = -1, const std::string & data = "");
82
83        /**
84         * Default destructor.
85         */
86        ~HistoryMemento();
87
88        /**
89         * Returns the state.
90         *
91         * @return the state
92         */
93        HistoryMemento::State getState() const;
94
95        /**
96         * Returns the peer.
97         *
98         * @return the peer
99         */
100        std::string getPeer() const;
101
102        /**
103         * Returns the duration.
104         *
105         * @return the duration
106         */
107        int getDuration() const;
108
109        /**
110         * Returns the date.
111         *
112         * @return the date
113         */
114        Date getDate() const;
115
116        /**
117         * Returns the time.
118         *
119         * @return the time
120         */
121        Time getTime() const;
122
123        /**
124         * Returns data.
125         *
126         * @return data
127         */
128        std::string getData() const;
129
130       
131        /**
132         * Returns alias.
133         *
134         * @return alias
135         */
136        std::string getAlias() const;
137
138        /**
139         * Returns true if the Memento can be replayed.
140         *
141         * @return true if the Memento can be replayed
142         */
143        bool canReplay() const;
144
145        /**
146         * update the duration.
147         *
148         * @param duration the duration of the call
149         */
150        void updateDuration(int duration);
151
152        /**
153         * Returns a string representing the memento.
154         *
155         * @return return a string representing the memento
156         */
157        std::string toString() const;
158
159private:
160
161        /**
162         * Returns true if the memento is for a call.
163         *
164         * @return true if the memento is for a call
165         */
166        bool isCallMemento() const;
167
168        /**
169         * Returns true if the memento is for a SMS.
170         *
171         * @return true if the memento is for a SMS
172         */
173        bool isSMSMemento() const;
174
175        /**
176         * Returns true if the memento is for a chat session.
177         *
178         * @return true if the memento is for a chat session
179         */
180        bool isChatSessionMemento() const;
181
182        /**
183         * Updates state.
184         *
185         * @param state new state
186         */
187        void updateState(State state);
188
189        /**
190         * Returns the callId associated to the memento.
191         *
192         * @return return the callId associated to the memento
193         */
194        int getCallId() const;
195
196        /**
197         * Returns a string representing a memento state.
198         *
199         * @return return a string representing a memento state
200         */
201        static std::string stateToString(State state);
202
203        /**
204         * the peer.
205         * TODO: replace by a set of peers (multi SMS, audio conf)
206         */
207        std::string _peer;
208
209        /** State of the Memento. */
210        State _state;
211
212        /** Date associated to the memento. */
213        Date _date;
214
215        /** Time associated to the memento. */
216        Time _time;
217
218        /**
219         * meaning:
220         * - text for SMS
221         * - filename for file transfer
222         */
223        std::string _data;
224
225        /** data: meaningfull only for calls. */
226        int _duration;
227
228        /** data: meaningfull only for calls from this instance of the application. */
229        int _callId;
230
231        /**display name used for sip message */
232        std::string _alias;
233
234        friend class boost::serialization::access;
235
236        /** Serialialization load method. */
237        template < class Archive >
238        void load(Archive & ar, const unsigned int version) {
239                if (version == SERIALIZATION_VERSION) {
240                        ar >> BOOST_SERIALIZATION_NVP(_peer);
241                        DateXMLSerializer d(_date);
242                        std::string date;
243                        ar >> BOOST_SERIALIZATION_NVP(date);
244                        d.unserialize(date);
245                        TimeXMLSerializer t(_time);
246                        std::string time;
247                        ar >> BOOST_SERIALIZATION_NVP(time);
248                        t.unserialize(time);
249                        ar >> BOOST_SERIALIZATION_NVP(_duration);
250                        ar >> BOOST_SERIALIZATION_NVP(_state);
251                        ar >> BOOST_SERIALIZATION_NVP(_data);
252                        ar >> BOOST_SERIALIZATION_NVP(_alias);
253                } else {
254                        //LOG_DEBUG("Bad Serialization Version");
255                }
256        }
257
258        /** Serialialization save method. */
259        template < class Archive >
260        void save(Archive & ar, const unsigned int version) const {
261                ar << BOOST_SERIALIZATION_NVP(_peer);
262                DateXMLSerializer d((Date &)_date);
263                std::string date = d.serialize();
264                ar << BOOST_SERIALIZATION_NVP(date);
265                TimeXMLSerializer t((Time &)_time);
266                std::string time = t.serialize();
267                ar << BOOST_SERIALIZATION_NVP(time);
268                ar << BOOST_SERIALIZATION_NVP(_duration);
269                ar << BOOST_SERIALIZATION_NVP(_state);
270                ar << BOOST_SERIALIZATION_NVP(_data);
271                ar << BOOST_SERIALIZATION_NVP(_alias);
272        }
273
274        BOOST_SERIALIZATION_SPLIT_MEMBER()
275};
276
277BOOST_CLASS_VERSION(HistoryMemento, HistoryMemento::SERIALIZATION_VERSION)
278
279#endif  //OWHISTORYMEMENTO_H
280
Note: See TracBrowser for help on using the repository browser.