gloox  1.0
lastactivity.h
1 /*
2  Copyright (c) 2005-2009 by Jakob Schroeter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 
14 #ifndef LASTACTIVITY_H__
15 #define LASTACTIVITY_H__
16 
17 #include "iqhandler.h"
18 
19 #include <ctime>
20 
21 namespace gloox
22 {
23 
24  class JID;
25  class ClientBase;
26  class LastActivityHandler;
27 
39  class GLOOX_API LastActivity : public IqHandler
40  {
41  public:
52  class GLOOX_API Query : public StanzaExtension
53  {
54  public:
59  Query( const Tag* tag = 0 );
60 
66  Query( const std::string& status, long seconds );
67 
71  virtual ~Query();
72 
78  long seconds() const { return m_seconds; }
79 
85  const std::string& status() const { return m_status; }
86 
87  // reimplemented from StanzaExtension
88  virtual const std::string& filterString() const;
89 
90  // reimplemented from StanzaExtension
91  virtual StanzaExtension* newInstance( const Tag* tag ) const
92  {
93  return new Query( tag );
94  }
95 
96  // reimplemented from StanzaExtension
97  virtual Tag* tag() const;
98 
99  // reimplemented from StanzaExtension
100  virtual StanzaExtension* clone() const
101  {
102  return new Query( *this );
103  }
104 
105  private:
106  long m_seconds;
107  std::string m_status;
108 
109  };
110 
115  LastActivity( ClientBase* parent );
116 
120  virtual ~LastActivity();
121 
127  void query( const JID& jid );
128 
134  void registerLastActivityHandler( LastActivityHandler* lah ) { m_lastActivityHandler = lah; }
135 
139  void removeLastActivityHandler() { m_lastActivityHandler = 0; }
140 
145  void resetIdleTimer();
146 
147  // reimplemented from IqHandler
148  virtual bool handleIq( const IQ& iq );
149 
150  // reimplemented from IqHandler
151  virtual void handleIqID( const IQ& iq, int context );
152 
153  private:
154 #ifdef LASTACTIVITY_TEST
155  public:
156 #endif
157  LastActivityHandler* m_lastActivityHandler;
158  ClientBase* m_parent;
159 
160  time_t m_active;
161 
162  };
163 
164 }
165 
166 #endif // LASTACTIVITY_H__