diff options
Diffstat (limited to 'plugins/Non-IM Contact/src/timer.cpp')
-rw-r--r-- | plugins/Non-IM Contact/src/timer.cpp | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/plugins/Non-IM Contact/src/timer.cpp b/plugins/Non-IM Contact/src/timer.cpp new file mode 100644 index 0000000000..42e2b47df1 --- /dev/null +++ b/plugins/Non-IM Contact/src/timer.cpp @@ -0,0 +1,84 @@ +#include "commonheaders.h"
+
+UINT_PTR timerId;
+
+//=====================================================
+// Name : timerProc
+// Parameters: none
+// Returns : void
+// Description : called when the timer interval occurs
+//=====================================================
+
+void timerFunc(LPVOID di)
+{
+ char text[512], fn[16], szFileName[MAX_PATH], temp[MAX_PATH];
+
+ int timerCount = db_get_w(NULL, MODNAME, "timerCount",1)+1;
+
+ if (LCStatus == ID_STATUS_OFFLINE) {
+ killTimer();
+ return;
+ }
+ db_set_w(NULL, MODNAME, "timerCount", (WORD)timerCount);
+
+ /* update the web pages*/
+ for (int i=0; ;i++) {
+ sprintf(fn, "fn%d", i);
+ if (!db_get_static(NULL, MODNAME, fn, text))
+ break;
+
+ if (!strncmp("http://", text, strlen("http://"))) {
+ strcat(fn, "_timer");
+ int timer = db_get_w(NULL, MODNAME, fn, 60);
+ if (timer && !(timerCount % timer)) {
+ if (!InternetDownloadFile(text)) {
+ mir_snprintf(szFileName, SIZEOF(szFileName), "%s\\plugins\\fn%d.html", getMimDir(temp), i);
+ savehtml(szFileName);
+ }
+ }
+ }
+ }
+
+ /* update all the contacts */
+ for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
+ if (!strcmp(MODNAME, GetContactProto(hContact))) {
+ int timer = db_get_w(hContact, MODNAME, "Timer", 15);
+ if (timer && !(timerCount % timer))
+ if (db_get_static(hContact, MODNAME, "Name", text))
+ replaceAllStrings(hContact);
+ }
+ }
+}
+
+void CALLBACK timerProc(HWND, UINT, UINT_PTR, DWORD)
+{
+ // new thread for the timer...
+ forkthread(timerFunc, 0, 0);
+}
+
+//=====================================================
+// Name : startTimer
+// Parameters: int interval
+// Returns : int
+// Description : starts the timer
+//=====================================================
+
+int startTimer(int interval)
+{
+ timerId = SetTimer(NULL, 0, interval, timerProc);
+ return 0;
+}
+
+//=====================================================
+// Name : killTimer
+// Parameters: none
+// Returns : int
+// Description : stops the timer
+//=====================================================
+
+int killTimer()
+{
+ db_set_w(NULL, MODNAME, "timerCount",0);
+ KillTimer(NULL,timerId);
+ return 0;
+}
|