summaryrefslogtreecommitdiff
path: root/plugins/TabSRMM/src/sendlater.h
blob: c928789ce715321550792df39f0100eb32507c0d (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
/*
 * astyle --force-indent=tab=4 --brackets=linux --indent-switches
 *		  --pad=oper --one-line=keep-blocks  --unpad=paren
 *
 * Miranda NG: the free IM client for Microsoft* Windows*
 *
 * Copyright 2000-2009 Miranda ICQ/IM project,
 * all portions of this codebase are copyrighted to the people
 * listed in contributors.txt.
 *
 * 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.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * you should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * part of tabSRMM messaging plugin for Miranda.
 *
 * (C) 2005-2010 by silvercircle _at_ gmail _dot_ com and contributors
 *
 * the sendlater class
 */

#ifndef __SENDLATER_H
#define __SENDLATER_H

#define TIMERID_SENDLATER 12000
#define TIMERID_SENDLATER_TICK 13000

#define TIMEOUT_SENDLATER 10000
#define TIMEOUT_SENDLATER_TICK 200

class CSendLaterJob {

public:
	/*
	 * job status/error codes
	 */
	enum {
		INVALID_CONTACT = 'I',
		JOB_DEFERRED = 'D',
		JOB_AGE = 'O',
		JOB_MYSTATUS = 'M',
		JOB_STATUS = 'S',
		JOB_WAITACK = 'A',
		JOB_REMOVABLE = 'R',
		JOB_HOLD = 'H',
	};
	/*
	 * internal flags
	 */
	enum {
		SLF_SUSPEND = 1,
		SLF_INVALID = 2
	};
	void	readFlags();
	void	writeFlags();
	void	cleanDB();
	bool	isPersistentJob();
	bool	mustDelete();
	CSendLaterJob();
	~CSendLaterJob();
	char	szId[20];									// database key name (time stamp of original send)
	HANDLE	hContact;									// original contact where the message has been assigned
	HANDLE  hTargetContact;								// *real* contact (can be different for metacontacts, e.g).
	HANDLE	hProcess;									// returned from the protocols sending service. needed to find it in the ACK handler
	time_t	created;									// job was created at this time (important to kill jobs, that are too old)
	time_t	lastSent;									// time at which the delivery was initiated. used to handle timeouts
	char	*sendBuffer;								// utf-8 send buffer
	PBYTE	pBuf;										// conventional send buffer (for non-utf8 protocols)
	DWORD	dwFlags;
	int		iSendCount;									// # of times we tried to send it...
	bool	fSuccess, fFailed;
	BYTE	bCode;										// error/progress code (for the UI)
};

class CSendLater {
	
public:
	enum {
		SENDLATER_AGE_THRESHOLD = (86400 * 3),				// 3 days, older messages will be removed from the db.
		SENDLATER_RESEND_THRESHOLD = 180,					// timeouted messages should be resent after that many seconds
		SENDLATER_PROCESS_INTERVAL = 50						// process the list of waiting job every this many seconds
	};

	CSendLater();
   ~CSendLater();
   bool   isAvail() const { return(m_fAvail); }
   bool   isInteractive() const { return(m_fIsInteractive); }
   bool   isJobListEmpty() const { return(m_sendLaterJobList.getCount() == 0); }
   bool   haveErrorPopups() const { return(m_fErrorPopups); }
   bool   haveSuccessPopups() const { return(m_fSuccessPopups); }
   void   startJobListProcess();
   time_t lastProcessed() const { return(m_last_sendlater_processed); }
   void   setLastProcessed(const time_t _t) { m_last_sendlater_processed = _t; }
   void   flushQueue() { m_last_sendlater_processed = 0; }
   bool   haveJobs() const { return (m_sendLaterJobList.getCount() != 0 && m_currJob != -1); }

   static int _cdecl addStub(const char *szSetting, LPARAM lParam);

	bool   processCurrentJob();
   void   processContacts();
   int    addJob(const char *szSetting, LPARAM lParam);
   void   addContact(const HANDLE hContact);
   HANDLE processAck(const ACKDATA *ack);

   void   invokeQueueMgrDlg();
   void   qMgrUpdate(bool fReEnable = false);
   static INT_PTR svcQMgr(WPARAM wParam, LPARAM lParam);

private:
   void    processSingleContact(const HANDLE hContact);
   int     sendIt(CSendLaterJob *job);

   INT_PTR CALLBACK DlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
   static INT_PTR CALLBACK DlgProcStub(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

	void    qMgrFillList(bool fClear = true);
   void    qMgrSetupColumns();
   void    qMgrSaveColumns();
   LRESULT qMgrAddFilter(const HANDLE hContact, const TCHAR* tszNick);

   LIST<void> m_sendLaterContactList;
   LIST<CSendLaterJob> m_sendLaterJobList;

	bool    m_fAvail;
   bool    m_fIsInteractive;
   bool    m_fErrorPopups;
   bool    m_fSuccessPopups;
   time_t  m_last_sendlater_processed;
   int     m_currJob;

   HWND    m_hwndDlg;
   HWND    m_hwndList, m_hwndFilter;
   HANDLE  m_hFilter;      // contact handle to filter the qmgr list (0 = no filter, show all)
   LRESULT m_sel;         // index of the combo box entry corresponding to the contact filter;
};

extern CSendLater* sendLater;

#endif /* __SENDLATER_H */