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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
|
/*
Weather Protocol plugin for Miranda NG
Copyright (C) 2012-21 Miranda NG team
Copyright (c) 2005-2011 Boris Krasnovskiy All Rights Reserved
Copyright (c) 2002-2005 Calvin Che
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; version 2
of the License.
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, see <http://www.gnu.org/licenses/>.
*/
/* This file contains the includes, weather constants/declarations,
the structs, and the primitives for some of the functions.
*/
#pragma once
//============ THE INCLUDES ===========
#include <share.h>
#include <time.h>
#include <windows.h>
#include <commctrl.h>
#include <richedit.h>
#include <malloc.h>
#include <newpluginapi.h>
#include <m_contacts.h>
#include <m_icolib.h>
#include <m_options.h>
#include <m_langpack.h>
#include <m_skin.h>
#include <m_database.h>
#include <m_history.h>
#include <m_protosvc.h>
#include <m_userinfo.h>
#include <m_netlib.h>
#include <m_ignore.h>
#include <m_findadd.h>
#include <m_button.h>
#include <m_avatars.h>
#include <m_clc.h>
#include <m_fontservice.h>
#include <m_skin_eng.h>
#include <m_cluiframes.h>
#include <m_popup.h>
#include <win2k.h>
#include <m_acc.h>
#include <m_weather.h>
#include <m_toptoolbar.h>
#include "resource.h"
#include "version.h"
//============ CONSTANTS ============
// name
#define MODULENAME "Weather"
#define WEATHERPROTOTEXT "Weather"
#define DEFCURRENTWEATHER "WeatherCondition"
#define WEATHERCONDITION "Current"
// weather conditions
#define SUNNY ID_STATUS_ONLINE
#define NA ID_STATUS_OFFLINE
#define PCLOUDY ID_STATUS_AWAY
#define CLOUDY ID_STATUS_NA
#define RAIN ID_STATUS_OCCUPIED
#define FOG ID_STATUS_DND
#define SNOW ID_STATUS_FREECHAT
#define LIGHT ID_STATUS_INVISIBLE
#define THUNDER ID_STATUS_INVISIBLE
#define UNAVAIL 40081
// status
#define NOSTATUSDATA 1
// limits
#define MAX_TEXT_SIZE 4096
#define MAX_DATA_LEN 1024
// db info mangement mode
#define WDBM_REMOVE 1
#define WDBM_DETAILDISPLAY 2
// more info list column width
#define LIST_COLUMN 150
// others
#define NODATA TranslateT("N/A")
#define UM_SETCONTACT 40000
// weather update error codes
#define INVALID_ID_FORMAT 10
#define INVALID_SVC 11
#define INVALID_ID 12
#define SVC_NOT_FOUND 20
#define NETLIB_ERROR 30
#define DATA_EMPTY 40
#define DOC_NOT_FOUND 42
#define DOC_TOO_SHORT 43
#define UNKNOWN_ERROR 99
// weather update error text
#define E10 TranslateT("Invalid ID format, missing \"/\" (10)")
#define E11 TranslateT("Invalid service (11)")
#define E12 TranslateT("Invalid station (12)")
#define E20 TranslateT("Weather service ini for this station is not found (20)")
#define E30 TranslateT("Netlib error - check your internet connection (30)")
#define E40 TranslateT("Empty data is retrieved (40)")
#define E42 TranslateT("Document not found (42)")
#define E43 TranslateT("Document too short to contain any weather data (43)")
#define E99 TranslateT("Unknown error (99)")
// HTTP error... not all translated
// 100 Continue
// 101 Switching Protocols
// 200 OK
// 201 Created
// 202 Accepted
// 203 Non-Authoritative Information
#define E204 TranslateT("HTTP Error: No content (204)")
// 205 Reset Content
// 206 Partial Content
// 300 Multiple Choices
#define E301 TranslateT("HTTP Error: Data moved (301)")
// 302 Found
// 303 See Other
// 304 Not Modified
#define E305 TranslateT("HTTP Error: Use proxy (305)")
// 306 (Unused)
#define E307 TranslateT("HTTP Error: Temporary redirect (307)")
#define E400 TranslateT("HTTP Error: Bad request (400)")
#define E401 TranslateT("HTTP Error: Unauthorized (401)")
#define E402 TranslateT("HTTP Error: Payment required (402)")
#define E403 TranslateT("HTTP Error: Forbidden (403)")
#define E404 TranslateT("HTTP Error: Not found (404)")
#define E405 TranslateT("HTTP Error: Method not allowed (405)")
// 406 Not Acceptable
#define E407 TranslateT("HTTP Error: Proxy authentication required (407)")
// 408 Request Timeout
// 409 Conflict
#define E410 TranslateT("HTTP Error: Gone (410)")
// 411 Length Required
// 412 Precondition Failed
// 413 Request Entity Too Large
// 414 Request-URI Too Long
// 415 Unsupported Media Type
// 416 Requested Range Not Satisfiable
// 417 Expectation Failed
#define E500 TranslateT("HTTP Error: Internal server error (500)")
// 501 Not Implemented
#define E502 TranslateT("HTTP Error: Bad gateway (502)")
#define E503 TranslateT("HTTP Error: Service unavailable (503)")
#define E504 TranslateT("HTTP Error: Gateway timeout (504)")
// 505 HTTP Version Not Supported
// defaults constants
#define C_DEFAULT L"%n [%t, %c]"
#define N_DEFAULT TranslateT("%c\\nTemperature: %t\\nFeel-Like: %f\\nPressure: %p\\nWind: %i %w\\nHumidity: %m\\nDew Point: %e\\nVisibility: %v\\n\\nSun Rise: %r\\nSun Set: %y\\n\\n5 Days Forecast:\\n%[Forecast Day 1]\\n%[Forecast Day 2]\\n%[Forecast Day 3]\\n%[Forecast Day 4]\\n%[Forecast Day 5]")
#define B_DEFAULT TranslateT("Feel-Like: %f\\nPressure: %p\\nWind: %i %w\\nHumidity: %m\\nDew Point: %e\\nVisibility: %v\\n\\nSun Rise: %r\\nSun Set: %y\\n\\n5 Days Forecast:\\n%[Forecast Day 1]\\n%[Forecast Day 2]\\n%[Forecast Day 3]\\n%[Forecast Day 4]\\n%[Forecast Day 5]")
#define b_DEFAULT TranslateT("Weather Condition for %n as of %u")
#define X_DEFAULT N_DEFAULT
#define H_DEFAULT TranslateT("%c, %t (feel-like %f) Wind: %i %w Humidity: %m")
#define E_DEFAULT TranslateT("%n at %u: %c, %t (feel-like %f) Wind: %i %w Humidity: %m")
#define P_DEFAULT TranslateT("%n (%u)")
#define p_DEFAULT TranslateT("%c, %t\\nToday: High %h, Low %l")
#define s_DEFAULT TranslateT("Temperature: %[Temperature]")
#define VAR_LIST_POPUP TranslateT("%c\tcurrent condition\n%d\tcurrent date\n%e\tdewpoint\n%f\tfeel-like temperature\n%h\ttoday's high\n%i\twind direction\n%l\ttoday's low\n%m\thumidity\n%n\tstation name\n%p\tpressure\n%r\tsunrise time\n%s\tstation ID\n%t\ttemperature\n%u\tupdate time\n%v\tvisibility\n%w\twind speed\n%y\tsun set")
#define VAR_LIST_OPT TranslateT("%c\tcurrent condition\n%d\tcurrent date\n%e\tdewpoint\n%f\tfeel-like temp\n%h\ttoday's high\n%i\twind direction\n%l\ttoday's low\n%m\thumidity\n%n\tstation name\n%p\tpressure\n%r\tsunrise time\n%s\tstation ID\n%t\ttemperature\n%u\tupdate time\n%v\tvisibility\n%w\twind speed\n%y\tsun set\n----------\n\\n\tnew line")
#define WEATHER_NO_INFO TranslateT("No information available.\r\nPlease update weather condition first.")
#define CUSTOM_VARS TranslateT("%[..]\tcustom variables")
#define VARS_LIST TranslateT("Here is a list of custom variables that are currently available")
#define NO_FORECAST_URL TranslateT("The URL for complete forecast has not been set. You can set it from the Edit Settings dialog.")
#define NO_MAP_URL TranslateT("The URL for weather map has not been set. You can set it from the Edit Settings dialog.")
//============ OPTION STRUCT ============
// option struct
struct MYOPTIONS
{
// main options
BYTE AutoUpdate;
BYTE CAutoUpdate;
BYTE StartupUpdate;
BYTE NoProtoCondition;
BYTE UpdateOnlyConditionChanged;
BYTE RemoveOldData;
BYTE MakeItalic;
WORD UpdateTime;
WORD AvatarSize;
// units
WORD tUnit;
WORD wUnit;
WORD vUnit;
WORD pUnit;
WORD dUnit;
WORD eUnit;
wchar_t DegreeSign[4];
BYTE DoNotAppendUnit;
BYTE NoFrac;
// texts
wchar_t *cText;
wchar_t *bTitle;
wchar_t *bText;
wchar_t *nText;
wchar_t *eText;
wchar_t *hText;
wchar_t *xText;
wchar_t *sText;
// advanced
BYTE DisCondIcon;
// popup options
BYTE UsePopup;
BYTE UpdatePopup;
BYTE AlertPopup;
BYTE PopupOnChange;
BYTE ShowWarnings;
// popup colors
BYTE UseWinColors;
COLORREF BGColour;
COLORREF TextColour;
// popup actions
DWORD LeftClickAction;
DWORD RightClickAction;
// popup delay
DWORD pDelay;
// popup texts
wchar_t *pTitle;
wchar_t *pText;
// other misc stuff
wchar_t Default[64];
MCONTACT DefStn;
};
void DestroyOptions(void);
//============ STRUCT USED TO MAKE AN UPDATE LIST ============
struct WCONTACTLIST {
MCONTACT hContact;
struct WCONTACTLIST *next;
};
typedef struct WCONTACTLIST UPDATELIST;
extern UPDATELIST *UpdateListHead, *UpdateListTail;
void DestroyUpdateList(void);
//============ DATA FORMAT STRUCT ============
#define WID_NORMAL 0
#define WID_SET 1
#define WID_BREAK 2
typedef struct {
wchar_t *Name;
wchar_t *Start;
wchar_t *End;
wchar_t *Unit;
char *Url;
wchar_t *Break;
int Type;
} WIDATAITEM;
struct WITEMLIST {
WIDATAITEM Item;
struct WITEMLIST *Next;
};
typedef struct WITEMLIST WIDATAITEMLIST;
typedef struct {
BOOL Available;
char *SearchURL;
wchar_t *NotFoundStr;
WIDATAITEM Name;
} WIIDSEARCH;
typedef struct {
BOOL Available;
wchar_t *First;
WIDATAITEM Name;
WIDATAITEM ID;
} WINAMESEARCHTYPE;
typedef struct {
char *SearchURL;
wchar_t *NotFoundStr;
wchar_t *SingleStr;
WINAMESEARCHTYPE Single;
WINAMESEARCHTYPE Multiple;
} WINAMESEARCH;
struct STRLIST {
wchar_t *Item;
struct STRLIST *Next;
};
typedef struct STRLIST WICONDITEM;
typedef struct {
WICONDITEM *Head;
WICONDITEM *Tail;
} WICONDLIST;
typedef struct {
wchar_t *FileName;
wchar_t *ShortFileName;
BOOL Enabled;
// header
wchar_t *DisplayName;
wchar_t *InternalName;
wchar_t *Description;
wchar_t *Author;
wchar_t *Version;
int InternalVer;
size_t MemUsed;
// default
char *DefaultURL;
wchar_t *DefaultMap;
char *UpdateURL;
char *UpdateURL2;
char *UpdateURL3;
char *UpdateURL4;
char *Cookie;
char *UserAgent;
// items
int UpdateDataCount;
WIDATAITEMLIST *UpdateData;
WIDATAITEMLIST *UpdateDataTail;
WIIDSEARCH IDSearch;
WINAMESEARCH NameSearch;
WICONDLIST CondList[10];
} WIDATA;
//============ DATA LIST (LINKED LIST) ============
struct DATALIST {
WIDATA Data;
struct DATALIST *next;
};
typedef struct DATALIST WIDATALIST;
//============ GLOBAL VARIABLES ============
extern WIDATALIST *WIHead, *WITail;
extern HWND hPopupWindow, hWndSetup;
extern MYOPTIONS opt;
extern unsigned status, old_status;
extern MWindowList hDataWindowList, hWindowList;
extern HNETLIBUSER hNetlibUser;
extern HANDLE hHookWeatherUpdated, hHookWeatherError, hTBButton, hUpdateMutex;
extern UINT_PTR timerId;
extern HGENMENU hMwinMenu;
// check if weather is currently updating
extern BOOL ThreadRunning;
//============ FUNCTION PRIMITIVES ============
// functions in weather_addstn.c
INT_PTR WeatherAddToList(WPARAM wParam,LPARAM lParam);
BOOL CheckSearch();
int IDSearch(wchar_t *id, const int searchId);
int NameSearch(wchar_t *name, const int searchId);
INT_PTR WeatherBasicSearch(WPARAM wParam,LPARAM lParam);
INT_PTR WeatherCreateAdvancedSearchUI(WPARAM wParam, LPARAM lParam);
INT_PTR WeatherAdvancedSearch(WPARAM wParam, LPARAM lParam);
int WeatherAdd(WPARAM wParam, LPARAM lParam);
// functions used in weather_contacts.c
INT_PTR ViewLog(WPARAM wParam,LPARAM lParam);
INT_PTR LoadForecast(WPARAM wParam,LPARAM lParam);
INT_PTR WeatherMap(WPARAM wParam,LPARAM lParam);
INT_PTR EditSettings(WPARAM wParam,LPARAM lParam);
int ContactDeleted(WPARAM wParam,LPARAM lParam);
BOOL IsMyContact(MCONTACT hContact);
// functions in weather_conv.c
void GetTemp(wchar_t *tempchar, wchar_t *unit, wchar_t *str);
void GetSpeed(wchar_t *tempchar, wchar_t *unit, wchar_t *str);
void GetPressure(wchar_t *tempchar, wchar_t *unit, wchar_t *str);
void GetDist(wchar_t *tempchar, wchar_t *unit, wchar_t *str);
void GetElev(wchar_t *tempchar, wchar_t *unit, wchar_t *str);
WORD GetIcon(const wchar_t* cond, WIDATA *Data);
void CaseConv(wchar_t *str);
void TrimString(char *str);
void TrimString(WCHAR *str);
void ConvertBackslashes(char *str);
char *GetSearchStr(char *dis);
wchar_t *GetDisplay(WEATHERINFO *w, const wchar_t *dis, wchar_t* str);
INT_PTR GetDisplaySvcFunc(WPARAM wParam, LPARAM lParam);
void GetSvc(wchar_t *pszID);
void GetID(wchar_t *pszID);
wchar_t *GetError(int code);
// functions in weather_data.c
void GetStationID(MCONTACT hContact, wchar_t* id, int idlen);
WEATHERINFO LoadWeatherInfo(MCONTACT Change);
int DBGetData(MCONTACT hContact, char *setting, DBVARIANT *dbv);
void EraseAllInfo(void);
void GetDataValue(WIDATAITEM *UpdateData, wchar_t *Data, wchar_t** szInfo);
void ConvertDataValue(WIDATAITEM *UpdateData, wchar_t *Data);
void wSetData(char **Data, const char *Value);
void wSetData(WCHAR **Data, const char *Value);
void wSetData(WCHAR **Data, const WCHAR *Value);
void wfree(char **Data);
void wfree(WCHAR **Data);
void DBDataManage(MCONTACT hContact, WORD Mode, WPARAM wParam, LPARAM lParam);
// functions in weather_http.c
int InternetDownloadFile (char *szUrl, char *cookie, char *userAgent, wchar_t** szData);
void NetlibInit();
// functions in weather_ini.c
WIDATA* GetWIData(wchar_t *pszServ);
bool IsContainedInCondList(const wchar_t *pszStr, WICONDLIST *List);
void DestroyWIList();
bool LoadWIData(bool dial);
INT_PTR CALLBACK DlgPopupOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
// functions in weather_info.c
void GetINIInfo(wchar_t *pszSvc);
void MoreVarList();
// functions in weather_opt.c
void SetTextDefault(const char* in);
void LoadOptions();
void SaveOptions();
int OptInit(WPARAM wParam,LPARAM lParam);
// functions in weather_popup.c
int WeatherPopup(WPARAM wParam, LPARAM lParam);
int WeatherError(WPARAM wParam, LPARAM lParam);
int WPShowMessage(wchar_t* lpzText, WORD kind);
LRESULT CALLBACK PopupWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
// functions in weather_svcs.c
void InitServices(void);
INT_PTR WeatherSetStatus(WPARAM new_status, LPARAM lParam);
INT_PTR WeatherGetCaps(WPARAM wParam, LPARAM lParam);
INT_PTR WeatherGetName(WPARAM wParam, LPARAM lParam);
INT_PTR WeatherGetStatus(WPARAM wParam, LPARAM lParam);
INT_PTR WeatherLoadIcon(WPARAM wParam, LPARAM lParam);
void UpdateMenu(BOOL State);
void UpdatePopupMenu(BOOL State);
void AddMenuItems();
void AvatarDownloaded(MCONTACT hContact);
// functions in weather_update.c
int UpdateWeather(MCONTACT hContact);
void UpdateAll(BOOL AutoUpdate, BOOL RemoveOld);
INT_PTR UpdateSingleStation(WPARAM wParam,LPARAM lParam);
INT_PTR UpdateAllInfo(WPARAM wParam,LPARAM lParam);
INT_PTR UpdateSingleRemove(WPARAM wParam,LPARAM lParam);
INT_PTR UpdateAllRemove(WPARAM wParam,LPARAM lParam);
int GetWeatherData(MCONTACT hContact);
void CALLBACK timerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime);
void CALLBACK timerProc2(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime);
// function from multiwin module
void InitMwin(void);
void DestroyMwin(void);
INT_PTR Mwin_MenuClicked(WPARAM wParam, LPARAM lParam);
int BuildContactMenu(WPARAM wparam, LPARAM lparam);
void UpdateMwinData(MCONTACT hContact);
void removeWindow(MCONTACT hContact);
// functions in weather_userinfo.c
int UserInfoInit(WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK DlgProcINIPage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
#define WM_UPDATEDATA WM_USER + 2687
int BriefInfo(WPARAM wParam, LPARAM lParam);
INT_PTR BriefInfoSvc(WPARAM wParam, LPARAM lParam);
void InitIcons(void);
//============ Plugin Class ============
struct CMPlugin : public PLUGIN<CMPlugin>
{
CMPlugin();
int Load() override;
int Unload() override;
};
|