summaryrefslogtreecommitdiff
path: root/plugins/Weather
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Weather')
-rw-r--r--plugins/Weather/src/stdafx.h34
-rw-r--r--plugins/Weather/src/weather_addstn.cpp2
-rw-r--r--plugins/Weather/src/weather_contacts.cpp6
-rw-r--r--plugins/Weather/src/weather_conv.cpp17
-rw-r--r--plugins/Weather/src/weather_data.cpp68
-rw-r--r--plugins/Weather/src/weather_http.cpp33
-rw-r--r--plugins/Weather/src/weather_info.cpp4
-rw-r--r--plugins/Weather/src/weather_ini.cpp267
-rw-r--r--plugins/Weather/src/weather_opt.cpp6
-rw-r--r--plugins/Weather/src/weather_update.cpp68
-rw-r--r--plugins/Weather/src/weather_userinfo.cpp245
11 files changed, 358 insertions, 392 deletions
diff --git a/plugins/Weather/src/stdafx.h b/plugins/Weather/src/stdafx.h
index 43a6d19eed..658894e12a 100644
--- a/plugins/Weather/src/stdafx.h
+++ b/plugins/Weather/src/stdafx.h
@@ -236,7 +236,6 @@ struct MYOPTIONS
void DestroyOptions(void);
//============ STRUCT USED TO MAKE AN UPDATE LIST ============
-
struct WCONTACTLIST {
MCONTACT hContact;
struct WCONTACTLIST *next;
@@ -244,8 +243,7 @@ struct WCONTACTLIST {
typedef struct WCONTACTLIST UPDATELIST;
-extern UPDATELIST *UpdateListHead;
-extern UPDATELIST *UpdateListTail;
+extern UPDATELIST *UpdateListHead, *UpdateListTail;
void DestroyUpdateList(void);
@@ -349,27 +347,19 @@ typedef struct DATALIST WIDATALIST;
//============ GLOBAL VARIABLES ============
-extern WIDATALIST *WIHead;
-extern WIDATALIST *WITail;
+extern WIDATALIST *WIHead, *WITail;
extern HINSTANCE hInst;
-extern HWND hPopupWindow;
-extern HWND hWndSetup;
+extern HWND hPopupWindow, hWndSetup;
extern MYOPTIONS opt;
-extern unsigned status;
-extern unsigned old_status;
+extern unsigned status, old_status;
-extern MWindowList hDataWindowList;
-extern MWindowList hWindowList;
+extern MWindowList hDataWindowList, hWindowList;
-extern HANDLE hNetlibUser, hNetlibHttp;
-extern HANDLE hHookWeatherUpdated;
-extern HANDLE hHookWeatherError;
-extern HANDLE hTBButton;
+extern HANDLE hNetlibUser, hNetlibHttp, hHookWeatherUpdated, hHookWeatherError, hTBButton, hUpdateMutex;
extern UINT_PTR timerId;
-extern HANDLE hUpdateMutex;
extern HGENMENU hMwinMenu;
@@ -395,7 +385,6 @@ int WeatherAdd(WPARAM wParam, LPARAM lParam);
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);
@@ -425,14 +414,12 @@ void GetID(TCHAR *pszID);
TCHAR *GetError(int code);
// functions in weather_data.c
-void GetStationID(MCONTACT hContact, TCHAR* id, size_t idlen);
+void GetStationID(MCONTACT hContact, TCHAR* id, int idlen);
WEATHERINFO LoadWeatherInfo(MCONTACT Change);
int DBGetData(MCONTACT hContact, char *setting, DBVARIANT *dbv);
-int DBGetStaticString(MCONTACT hContact, const char *szModule, const char *valueName, TCHAR *dest, size_t dest_len);
void EraseAllInfo(void);
-void LoadStationData(TCHAR *pszFile, TCHAR *pszShortFile, WIDATA *Data);
void GetDataValue(WIDATAITEM *UpdateData, TCHAR *Data, TCHAR** szInfo);
void ConvertDataValue(WIDATAITEM *UpdateData, TCHAR *Data);
void wSetData(char **Data, const char *Value);
@@ -449,16 +436,13 @@ void NetlibInit();
void NetlibHttpDisconnect(void);
// functions in weather_ini.c
-void WIListAdd(WIDATA Data);
WIDATA* GetWIData(TCHAR *pszServ);
bool IsContainedInCondList(const TCHAR *pszStr, WICONDLIST *List);
void DestroyWIList();
bool LoadWIData(bool dial);
-void FreeWIData(WIDATA *Data);
-INT_PTR CALLBACK DlgProcSetup(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK DlgPopupOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
// functions in weather_info.c
@@ -499,7 +483,6 @@ void AvatarDownloaded(MCONTACT hContact);
int UpdateWeather(MCONTACT hContact);
void UpdateAll(BOOL AutoUpdate, BOOL RemoveOld);
-void UpdateThreadProc(LPVOID hWnd);
INT_PTR UpdateSingleStation(WPARAM wParam,LPARAM lParam);
INT_PTR UpdateAllInfo(WPARAM wParam,LPARAM lParam);
INT_PTR UpdateSingleRemove(WPARAM wParam,LPARAM lParam);
@@ -520,15 +503,12 @@ void removeWindow(MCONTACT hContact);
// functions in weather_userinfo.c
int UserInfoInit(WPARAM wParam, LPARAM lParam);
-INT_PTR CALLBACK DlgProcUIPage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
-INT_PTR CALLBACK DlgProcMoreData(HWND hwndDlg, UINT msg, 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 LoadBriefInfoText(HWND hwndDlg, MCONTACT hContact);
void InitIcons(void);
HICON LoadIconEx(const char* name, bool big);
diff --git a/plugins/Weather/src/weather_addstn.cpp b/plugins/Weather/src/weather_addstn.cpp
index 2e2eeca1a7..5ab2d661a5 100644
--- a/plugins/Weather/src/weather_addstn.cpp
+++ b/plugins/Weather/src/weather_addstn.cpp
@@ -165,7 +165,7 @@ INT_PTR WeatherBasicSearch(WPARAM, LPARAM lParam)
}
// ============ NAME SEARCH ============
-
+//
// name search timer process (threaded)
static void __cdecl NameSearchTimerProc(LPVOID)
{
diff --git a/plugins/Weather/src/weather_contacts.cpp b/plugins/Weather/src/weather_contacts.cpp
index 355fd7b25c..60919e5b43 100644
--- a/plugins/Weather/src/weather_contacts.cpp
+++ b/plugins/Weather/src/weather_contacts.cpp
@@ -60,7 +60,7 @@ INT_PTR LoadForecast(WPARAM wParam, LPARAM)
GetStationID(wParam, id, _countof(id));
if (id[0] != 0) {
// check if the complte forecast URL is set. If it is not, display warning and quit
- if (DBGetStaticString(wParam, WEATHERPROTONAME, "InfoURL", loc2, _countof(loc2)) || loc2[0] == 0) {
+ if (db_get_tstatic(wParam, WEATHERPROTONAME, "InfoURL", loc2, _countof(loc2)) || loc2[0] == 0) {
MessageBox(NULL, NO_FORECAST_URL, TranslateT("Weather Protocol"), MB_ICONINFORMATION);
return 1;
}
@@ -78,7 +78,7 @@ INT_PTR WeatherMap(WPARAM wParam, LPARAM)
GetStationID(wParam, id, _countof(id));
if (id[0] != 0) {
// check if the weather map URL is set. If it is not, display warning and quit
- if (DBGetStaticString(wParam, WEATHERPROTONAME, "MapURL", loc2, _countof(loc2)) || loc2[0] == 0) {
+ if (db_get_tstatic(wParam, WEATHERPROTONAME, "MapURL", loc2, _countof(loc2)) || loc2[0] == 0) {
MessageBox(NULL, NO_MAP_URL, TranslateT("Weather Protocol"), MB_ICONINFORMATION);
return 1;
}
@@ -425,7 +425,7 @@ INT_PTR EditSettings(WPARAM wParam, LPARAM)
}
//============ CONTACT DELETION ============
-
+//
// when a contact is deleted, make sure some other contact take over the default station
// wParam = deleted contact
int ContactDeleted(WPARAM wParam, LPARAM)
diff --git a/plugins/Weather/src/weather_conv.cpp b/plugins/Weather/src/weather_conv.cpp
index e889d63e2d..bc3f523d8c 100644
--- a/plugins/Weather/src/weather_conv.cpp
+++ b/plugins/Weather/src/weather_conv.cpp
@@ -403,19 +403,18 @@ WORD GetIcon(const TCHAR* cond, WIDATA *Data)
}
//============ STRING CONVERSIONS ============
-
+//
// this function convert the string to the format with 1 upper case followed by lower case char
void CaseConv(TCHAR *str)
{
- TCHAR *pstr;
BOOL nextUp = TRUE;
CharLowerBuff(str, (DWORD)mir_tstrlen(str));
- for (pstr = str; *pstr; pstr++) {
+ for (TCHAR *pstr = str; *pstr; pstr++) {
if (*pstr == ' ' || *pstr == '-')
nextUp = TRUE;
else {
- TCHAR ch = *(TCHAR*)pstr;
+ TCHAR ch = *pstr;
if (nextUp)
*pstr = (TCHAR)CharUpper((LPTSTR)ch);
nextUp = FALSE;
@@ -425,7 +424,7 @@ void CaseConv(TCHAR *str)
// the next 2 functions are copied from miranda source
// str = the string to modify
-
+//
void TrimString(char *str)
{
size_t len, start;
@@ -481,7 +480,7 @@ char *GetSearchStr(char *dis)
}
//============ ICON ASSIGNMENT ============
-
+//
// make display and history strings
// w = WEATHERINFO data to be parsed
// dis = the string to parse
@@ -575,7 +574,7 @@ INT_PTR GetDisplaySvcFunc(WPARAM wParam, LPARAM lParam)
}
//============ ID MANAGEMENT ============
-
+//
// get service data module internal name
// mod/id <- the mod part
// pszID = original 2-part id, return the service internal name
@@ -597,11 +596,11 @@ void GetID(TCHAR *pszID)
}
//============ WEATHER ERROR CODE ============
-
+//
// Get the text when an error code is specified
// code = the error code obtained when updating weather
// str = the string for the error
-
+//
TCHAR *GetError(int code)
{
TCHAR *str, str2[100];
diff --git a/plugins/Weather/src/weather_data.cpp b/plugins/Weather/src/weather_data.cpp
index c9303092ad..24554f2f4f 100644
--- a/plugins/Weather/src/weather_data.cpp
+++ b/plugins/Weather/src/weather_data.cpp
@@ -29,11 +29,11 @@ saving individual weather data for a weather contact.
// get station ID from DB
// hContact = the current contact handle
// return value = the string for station ID
-
-void GetStationID(MCONTACT hContact, TCHAR* id, size_t idlen)
+//
+void GetStationID(MCONTACT hContact, TCHAR* id, int idlen)
{
// accessing the database
- if (DBGetStaticString(hContact, WEATHERPROTONAME, "ID", id, idlen))
+ if (db_get_tstatic(hContact, WEATHERPROTONAME, "ID", id, idlen))
id[0] = 0;
}
@@ -49,35 +49,35 @@ WEATHERINFO LoadWeatherInfo(MCONTACT hContact)
winfo.hContact = hContact;
GetStationID(hContact, winfo.id, _countof(winfo.id));
- if (DBGetStaticString(hContact, WEATHERPROTONAME, "Nick", winfo.city, _countof(winfo.city)))
+ if (db_get_tstatic(hContact, WEATHERPROTONAME, "Nick", winfo.city, _countof(winfo.city)))
_tcsncpy(winfo.city, NODATA, _countof(winfo.city) - 1);
- if (DBGetStaticString(hContact, WEATHERCONDITION, "Update", winfo.update, _countof(winfo.update)))
+ if (db_get_tstatic(hContact, WEATHERCONDITION, "Update", winfo.update, _countof(winfo.update)))
_tcsncpy(winfo.update, NODATA, _countof(winfo.update) - 1);
- if (DBGetStaticString(hContact, WEATHERCONDITION, "Condition", winfo.cond, _countof(winfo.cond)))
+ if (db_get_tstatic(hContact, WEATHERCONDITION, "Condition", winfo.cond, _countof(winfo.cond)))
_tcsncpy(winfo.cond, NODATA, _countof(winfo.cond) - 1);
- if (DBGetStaticString(hContact, WEATHERCONDITION, "Temperature", winfo.temp, _countof(winfo.temp)))
+ if (db_get_tstatic(hContact, WEATHERCONDITION, "Temperature", winfo.temp, _countof(winfo.temp)))
_tcsncpy(winfo.temp, NODATA, _countof(winfo.temp) - 1);
- if (DBGetStaticString(hContact, WEATHERCONDITION, "High", winfo.high, _countof(winfo.high)))
+ if (db_get_tstatic(hContact, WEATHERCONDITION, "High", winfo.high, _countof(winfo.high)))
_tcsncpy(winfo.high, NODATA, _countof(winfo.high) - 1);
- if (DBGetStaticString(hContact, WEATHERCONDITION, "Low", winfo.low, _countof(winfo.low)))
+ if (db_get_tstatic(hContact, WEATHERCONDITION, "Low", winfo.low, _countof(winfo.low)))
_tcsncpy(winfo.low, NODATA, _countof(winfo.low) - 1);
- if (DBGetStaticString(hContact, WEATHERCONDITION, "Sunset", winfo.sunset, _countof(winfo.sunset)))
+ if (db_get_tstatic(hContact, WEATHERCONDITION, "Sunset", winfo.sunset, _countof(winfo.sunset)))
_tcsncpy(winfo.sunset, NODATA, _countof(winfo.sunset) - 1);
- if (DBGetStaticString(hContact, WEATHERCONDITION, "Sunrise", winfo.sunrise, _countof(winfo.sunrise)))
+ if (db_get_tstatic(hContact, WEATHERCONDITION, "Sunrise", winfo.sunrise, _countof(winfo.sunrise)))
_tcsncpy(winfo.sunrise, NODATA, _countof(winfo.sunrise) - 1);
- if (DBGetStaticString(hContact, WEATHERCONDITION, "Wind Speed", winfo.wind, _countof(winfo.wind)))
+ if (db_get_tstatic(hContact, WEATHERCONDITION, "Wind Speed", winfo.wind, _countof(winfo.wind)))
_tcsncpy(winfo.wind, NODATA, _countof(winfo.wind) - 1);
- if (DBGetStaticString(hContact, WEATHERCONDITION, "Wind Direction", winfo.winddir, _countof(winfo.winddir)))
+ if (db_get_tstatic(hContact, WEATHERCONDITION, "Wind Direction", winfo.winddir, _countof(winfo.winddir)))
_tcsncpy(winfo.winddir, NODATA, _countof(winfo.winddir) - 1);
- if (DBGetStaticString(hContact, WEATHERCONDITION, "Dewpoint", winfo.dewpoint, _countof(winfo.dewpoint)))
+ if (db_get_tstatic(hContact, WEATHERCONDITION, "Dewpoint", winfo.dewpoint, _countof(winfo.dewpoint)))
_tcsncpy(winfo.dewpoint, NODATA, _countof(winfo.dewpoint) - 1);
- if (DBGetStaticString(hContact, WEATHERCONDITION, "Pressure", winfo.pressure, _countof(winfo.pressure)))
+ if (db_get_tstatic(hContact, WEATHERCONDITION, "Pressure", winfo.pressure, _countof(winfo.pressure)))
_tcsncpy(winfo.pressure, NODATA, _countof(winfo.pressure) - 1);
- if (DBGetStaticString(hContact, WEATHERCONDITION, "Visibility", winfo.vis, _countof(winfo.vis)))
+ if (db_get_tstatic(hContact, WEATHERCONDITION, "Visibility", winfo.vis, _countof(winfo.vis)))
_tcsncpy(winfo.vis, NODATA, _countof(winfo.vis) - 1);
- if (DBGetStaticString(hContact, WEATHERCONDITION, "Humidity", winfo.humid, _countof(winfo.humid)))
+ if (db_get_tstatic(hContact, WEATHERCONDITION, "Humidity", winfo.humid, _countof(winfo.humid)))
_tcsncpy(winfo.humid, NODATA, _countof(winfo.humid) - 1);
- if (DBGetStaticString(hContact, WEATHERCONDITION, "Feel", winfo.feel, _countof(winfo.feel)))
+ if (db_get_tstatic(hContact, WEATHERCONDITION, "Feel", winfo.feel, _countof(winfo.feel)))
_tcsncpy(winfo.feel, NODATA, _countof(winfo.feel) - 1);
winfo.status = (WORD)db_get_w(hContact, WEATHERPROTONAME, "StatusIcon", ID_STATUS_OFFLINE);
@@ -100,21 +100,9 @@ int DBGetData(MCONTACT hContact, char *setting, DBVARIANT *dbv)
return 0;
}
-int DBGetStaticString(MCONTACT hContact, const char *szModule, const char *valueName, TCHAR *dest, size_t dest_len)
-{
- DBVARIANT dbv;
- if (db_get_ts(hContact, szModule, valueName, &dbv))
- return 1;
-
- _tcsncpy(dest, dbv.ptszVal, dest_len);
- dest[dest_len - 1] = 0;
- db_free(&dbv);
- return 0;
-}
-
//============ ERASE OLD SETTINGS ============
-
+//
// erase all current weather information from database
// lastver = the last used version number in dword (using PLUGIN_MAKE_VERSION)
void EraseAllInfo()
@@ -251,12 +239,12 @@ void ConvertDataValue(WIDATAITEM *UpdateData, TCHAR *Data)
}
//============ GET THE VALUE OF A DATAITEM ============
-
+//
// get the value of the data using the start, end strings
// UpdateData = the WIDATAITEM struct containing start, end, unit
// Data = the string containing weather data obtained from UpdateData
// global var. used: szInfo = the downloaded string
-
+//
void GetDataValue(WIDATAITEM *UpdateData, TCHAR *Data, TCHAR** szData)
{
TCHAR last = 0, current, *start, *end;
@@ -355,18 +343,16 @@ void GetDataValue(WIDATAITEM *UpdateData, TCHAR *Data, TCHAR** szData)
}
//============ ALLOCATE SPACE AND COPY STRING ============
-
+//
// copy a string into a new memory location
// Data = the field the data is copied to
// Value = the original string, the string where data is copied from
void wSetData(char **Data, const char *Value)
{
- if (Value[0] != 0) {
- char *newData = (char*)mir_alloc(mir_strlen(Value) + 3);
- mir_strcpy(newData, Value);
- *Data = newData;
- }
- else *Data = "";
+ if (Value[0] != 0)
+ *Data = mir_strdup(Value);
+ else
+ *Data = "";
}
void wSetData(WCHAR **Data, const char *Value)
@@ -414,7 +400,7 @@ int GetWeatherDataFromDB(const char *szSetting, LPARAM lparam)
// remove or display the weather information for a contact
// hContact - the contact in which the info is going to be removed
-
+//
void DBDataManage(MCONTACT hContact, WORD Mode, WPARAM wParam, LPARAM)
{
LIST<char> arSettings(10);
diff --git a/plugins/Weather/src/weather_http.cpp b/plugins/Weather/src/weather_http.cpp
index 7d63c1ad6c..4171440bc9 100644
--- a/plugins/Weather/src/weather_http.cpp
+++ b/plugins/Weather/src/weather_http.cpp
@@ -27,25 +27,23 @@ from the web using netlib
HANDLE hNetlibUser, hNetlibHttp;
-int findHeader(NETLIBHTTPREQUEST *nlhrReply, char *hdr)
+static int findHeader(const NETLIBHTTPREQUEST *nlhrReply, const char *hdr)
{
- int res = -1, i;
- for (i = 0; i < nlhrReply->headersCount; i++) {
+ for (int i = 0; i < nlhrReply->headersCount; i++) {
if (_stricmp(nlhrReply->headers[i].szName, hdr) == 0) {
- res = i;
- break;
+ return i;
}
}
- return res;
+ return -1;
}
//============ DOWNLOAD NEW WEATHER ============
-
+//
// function to download webpage from the internet
// szUrl = URL of the webpage to be retrieved
// return value = 0 for success, 1 or HTTP error code for failure
// global var used: szData, szInfo = containing the retrieved data
-
+//
int InternetDownloadFile(char *szUrl, char *cookie, char *userAgent, TCHAR **szData)
{
if (userAgent == NULL || userAgent[0] == 0)
@@ -95,14 +93,17 @@ int InternetDownloadFile(char *szUrl, char *cookie, char *userAgent, TCHAR **szD
// allocate memory and save the retrieved data
int i = findHeader(nlhrReply, "Content-Type");
- if (i != -1 && strstr(_strlwr((char*)nlhrReply->headers[i].szValue), "utf-8"))
+ // look for Content-Type=utf-8 in header
+ if (i != -1 && strstr(_strlwr(nlhrReply->headers[i].szValue), "utf-8"))
bIsUtf = true;
else {
- char* end = nlhrReply->pData;
- for (;;) {
+ char *end = nlhrReply->pData;
+ while (end) {
+ // look for
+ // <meta http-equiv="Content-Type" content="utf-8" />
char* beg = strstr(end, "<meta");
- if (beg == NULL) break;
- else {
+ if (beg)
+ {
end = strchr(beg, '>');
if (end)
{
@@ -118,6 +119,8 @@ int InternetDownloadFile(char *szUrl, char *cookie, char *userAgent, TCHAR **szD
else *end = tmp;
}
}
+ else
+ break;
}
}
@@ -135,7 +138,7 @@ int InternetDownloadFile(char *szUrl, char *cookie, char *userAgent, TCHAR **szD
*szData = (TCHAR*)mir_alloc(512);
// store the error code in szData
mir_sntprintf(*szData, 512, _T("Error occured! HTTP Error: %i\n"), nlhrReply->resultCode);
- result = (int)nlhrReply->resultCode;
+ result = nlhrReply->resultCode;
}
hNetlibHttp = nlhrReply->nlc;
@@ -145,7 +148,7 @@ int InternetDownloadFile(char *szUrl, char *cookie, char *userAgent, TCHAR **szD
}
//============ NETLIB INITIALIZATION ============
-
+//
// initialize netlib support for weather protocol
void NetlibInit(void)
{
diff --git a/plugins/Weather/src/weather_info.cpp b/plugins/Weather/src/weather_info.cpp
index b1eba54fea..1e5e982c9d 100644
--- a/plugins/Weather/src/weather_info.cpp
+++ b/plugins/Weather/src/weather_info.cpp
@@ -30,7 +30,7 @@ regrading the loading of ini contents
//============ INI INFORMATION ============
// List INI Information for all loaded INI files
-void INIInfo(HWND hwndDlg)
+static void INIInfo(HWND hwndDlg)
{
TCHAR str[16];
size_t memused = 0;
@@ -202,7 +202,7 @@ void GetINIInfo(TCHAR *pszSvc)
}
//============ DISPLAY A LIST FOR CUSTOM VARIABLES ============
-
+//
// a message box for displaying the list of custom variables
// can be found when click on "More" in text option dialog
void MoreVarList(void)
diff --git a/plugins/Weather/src/weather_ini.cpp b/plugins/Weather/src/weather_ini.cpp
index 3d6e94b216..31d3f28b6f 100644
--- a/plugins/Weather/src/weather_ini.cpp
+++ b/plugins/Weather/src/weather_ini.cpp
@@ -30,10 +30,10 @@ code for unloading and getting weather data from the ini settings.
HWND hWndSetup;
//============ DATA LIST (LINKED LIST) ============
-
+//
// add an item into weather service data list
// Data = the service data to be added to the list
-void WIListAdd(WIDATA Data)
+static void WIListAdd(WIDATA Data)
{
// create a new datalist item and point to the data
WIDATALIST *newItem = (WIDATALIST*)mir_alloc(sizeof(WIDATALIST));
@@ -60,23 +60,8 @@ WIDATA* GetWIData(TCHAR *pszServ)
return NULL;
}
-// remove all service data from memory
-void DestroyWIList(void)
-{
- // free the list one by one
- while (WIHead != NULL) {
- WIDATALIST *wi = WIHead;
- WIHead = wi->next;
- FreeWIData(&wi->Data); // free the data struct
- mir_free(wi);
- }
-
- // make sure the entire list is clear
- WITail = NULL;
-}
-
//============ DATA ITEM LIST (LINKED LIST) ============
-
+//
// add a new update item into the current list
void WIItemListAdd(WIDATAITEM *DataItem, WIDATA *Data)
{
@@ -115,7 +100,7 @@ void FreeDataItem(WIDATAITEM *Item)
}
//============ Condition Icon List ============
-
+//
// initiate icon assignmet list
void WICondListInit(WICONDLIST *List)
{
@@ -163,64 +148,83 @@ void DestroyCondList(WICONDLIST *List)
}
-//============ LOADING INI FILES ============
-
-// load the weather update data form INI files
-bool LoadWIData(bool dial)
+//============ WEATHER INI SETUP DIALOG ============
+//
+static INT_PTR CALLBACK DlgProcSetup(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
- // make sure that the current service data list is empty
- WITail = NULL;
- WIHead = WITail;
+ switch (msg) {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hwndDlg);
- // find all *.ini file in the plugin\weather directory
- TCHAR szSearchPath[MAX_PATH], FileName[MAX_PATH];
- GetModuleFileName(GetModuleHandle(NULL), szSearchPath, _countof(szSearchPath));
- TCHAR *chop = _tcsrchr(szSearchPath, '\\');
- if (chop == NULL)
- return false;
- *chop = '\0';
- mir_tstrncat(szSearchPath, _T("\\Plugins\\Weather\\*.ini"), _countof(szSearchPath) - mir_tstrlen(szSearchPath));
- _tcsncpy(FileName, szSearchPath, MAX_PATH - 1);
+ // make the buttons flat
+ SendDlgItemMessage(hwndDlg, IDC_STEP1, BUTTONSETASFLATBTN, TRUE, 0);
+ SendDlgItemMessage(hwndDlg, IDC_STEP2, BUTTONSETASFLATBTN, TRUE, 0);
+ SendDlgItemMessage(hwndDlg, IDC_STEP3, BUTTONSETASFLATBTN, TRUE, 0);
+ SendDlgItemMessage(hwndDlg, IDC_STEP4, BUTTONSETASFLATBTN, TRUE, 0);
- WIN32_FIND_DATA fd;
- HANDLE hFind = FindFirstFile(szSearchPath, &fd);
+ // set icons
+ SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIconEx("main", TRUE));
+ SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadIconEx("main", FALSE));
+ WindowList_Add(hWindowList, hwndDlg, NULL);
+ ShowWindow(hwndDlg, SW_SHOW);
+ break;
- // load the content of the ini file into memory
- if (hFind != INVALID_HANDLE_VALUE) {
- do {
- chop = _tcsrchr(FileName, '\\');
- chop[1] = '\0';
- mir_tstrncat(FileName, fd.cFileName, _countof(FileName) - mir_tstrlen(FileName));
- if (mir_tstrcmpi(fd.cFileName, _T("SAMPLE_INI.INI"))) {
- WIDATA Data;
- LoadStationData(FileName, fd.cFileName, &Data);
- if (Data.Enabled)
- WIListAdd(Data);
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDC_STEP1:
+ // update current data
+ Utils_OpenUrl("http://miranda-ng.org/");
+ break;
+
+ case IDC_STEP2:
+ {
+ TCHAR szPath[1024];
+ GetModuleFileName(GetModuleHandle(NULL), szPath, _countof(szPath));
+ TCHAR *chop = _tcsrchr(szPath, '\\');
+ if (chop) {
+ *chop = '\0';
+ mir_tstrncat(szPath, _T("\\Plugins\\weather\\"), _countof(szPath) - mir_tstrlen(szPath));
+ if (_tmkdir(szPath) == 0)
+ ShellExecute((HWND)lParam, _T("open"), szPath, _T(""), _T(""), SW_SHOW);
}
- // look through the entire "plugins\weather" directory
- } while (FindNextFile(hFind, &fd));
- FindClose(hFind);
- }
+ break;
+ }
- if (WIHead == NULL) {
- // no ini found, display an error message box.
- if (dial)
- hWndSetup = CreateDialog(hInst, MAKEINTRESOURCE(IDD_SETUP), NULL, DlgProcSetup);
- else
- MessageBox(NULL,
- TranslateT("No update data file is found. Please check your Plugins\\Weather directory."),
- TranslateT("Weather Protocol"), MB_OK | MB_ICONERROR);
- return false;
+ case IDC_STEP3:
+ if (LoadWIData(false))
+ MessageBox(NULL,
+ TranslateT("All update data has been reloaded."),
+ TranslateT("Weather Protocol"), MB_OK | MB_ICONINFORMATION);
+ break;
+
+ case IDC_STEP4:
+ WeatherAdd(0, 0);
+ // fall through
+ case IDCANCEL:
+ // close the info window
+ DestroyWindow(hwndDlg);
+ break;
+ }
+ break;
+
+ case WM_CLOSE:
+ DestroyWindow(hwndDlg);
+ break;
+
+ case WM_DESTROY:
+ ReleaseIconEx((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0));
+ ReleaseIconEx((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, 0));
+ break;
}
- return true;
+ return FALSE;
}
// load the station data from a file
// pszFile = the file name + path for the ini file to be loaded
// pszShortFile = the file name of the ini file, but not including the path
// Data = the struct to load the ini content to, and return to previous function
-void LoadStationData(TCHAR *pszFile, TCHAR *pszShortFile, WIDATA *Data)
+static void LoadStationData(TCHAR *pszFile, TCHAR *pszShortFile, WIDATA *Data)
{
WIDATAITEM DataItem;
char *Group, *Temp;
@@ -473,11 +477,64 @@ void LoadStationData(TCHAR *pszFile, TCHAR *pszShortFile, WIDATA *Data)
}
}
-//============ FREE WIDATA ITEM FROM MEMORY ============
+//============ LOADING INI FILES ============
+//
+// load the weather update data form INI files
+bool LoadWIData(bool dial)
+{
+ // make sure that the current service data list is empty
+ WITail = NULL;
+ WIHead = WITail;
+
+ // find all *.ini file in the plugin\weather directory
+ TCHAR szSearchPath[MAX_PATH], FileName[MAX_PATH];
+ GetModuleFileName(GetModuleHandle(NULL), szSearchPath, _countof(szSearchPath));
+ TCHAR *chop = _tcsrchr(szSearchPath, '\\');
+ if (chop == NULL)
+ return false;
+ *chop = '\0';
+ mir_tstrncat(szSearchPath, _T("\\Plugins\\Weather\\*.ini"), _countof(szSearchPath) - mir_tstrlen(szSearchPath));
+ _tcsncpy(FileName, szSearchPath, MAX_PATH - 1);
+
+ WIN32_FIND_DATA fd;
+ HANDLE hFind = FindFirstFile(szSearchPath, &fd);
+
+ // load the content of the ini file into memory
+ if (hFind != INVALID_HANDLE_VALUE) {
+ do {
+ chop = _tcsrchr(FileName, '\\');
+ chop[1] = '\0';
+ mir_tstrncat(FileName, fd.cFileName, _countof(FileName) - mir_tstrlen(FileName));
+ if (mir_tstrcmpi(fd.cFileName, _T("SAMPLE_INI.INI"))) {
+ WIDATA Data;
+ LoadStationData(FileName, fd.cFileName, &Data);
+ if (Data.Enabled)
+ WIListAdd(Data);
+ }
+ // look through the entire "plugins\weather" directory
+ } while (FindNextFile(hFind, &fd));
+ FindClose(hFind);
+ }
+
+ if (WIHead == NULL) {
+ // no ini found, display an error message box.
+ if (dial)
+ hWndSetup = CreateDialog(hInst, MAKEINTRESOURCE(IDD_SETUP), NULL, DlgProcSetup);
+ else
+ MessageBox(NULL,
+ TranslateT("No update data file is found. Please check your Plugins\\Weather directory."),
+ TranslateT("Weather Protocol"), MB_OK | MB_ICONERROR);
+ return false;
+ }
+ return true;
+}
+
+//============ FREE WIDATA ITEM FROM MEMORY ============
+//
// free the WIDATA struct from memory
// Data = the struct to be freed
-void FreeWIData(WIDATA *Data)
+static void FreeWIData(WIDATA *Data)
{
// free update items linked list first
WIDATAITEMLIST *WItem = Data->UpdateData;
@@ -520,75 +577,17 @@ void FreeWIData(WIDATA *Data)
DestroyCondList(&Data->CondList[i]);
}
-//============ WEATHER INI SETUP DIALOG ============
-
-INT_PTR CALLBACK DlgProcSetup(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+// remove all service data from memory
+void DestroyWIList(void)
{
- switch (msg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hwndDlg);
-
- // make the buttons flat
- SendDlgItemMessage(hwndDlg, IDC_STEP1, BUTTONSETASFLATBTN, TRUE, 0);
- SendDlgItemMessage(hwndDlg, IDC_STEP2, BUTTONSETASFLATBTN, TRUE, 0);
- SendDlgItemMessage(hwndDlg, IDC_STEP3, BUTTONSETASFLATBTN, TRUE, 0);
- SendDlgItemMessage(hwndDlg, IDC_STEP4, BUTTONSETASFLATBTN, TRUE, 0);
-
- // set icons
- SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIconEx("main", TRUE));
- SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadIconEx("main", FALSE));
-
- WindowList_Add(hWindowList, hwndDlg, NULL);
- ShowWindow(hwndDlg, SW_SHOW);
- break;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDC_STEP1:
- // update current data
- Utils_OpenUrl("http://miranda-ng.org/");
- break;
-
- case IDC_STEP2:
- {
- TCHAR szPath[1024];
- GetModuleFileName(GetModuleHandle(NULL), szPath, _countof(szPath));
- TCHAR *chop = _tcsrchr(szPath, '\\');
- if (chop) {
- *chop = '\0';
- mir_tstrncat(szPath, _T("\\Plugins\\weather\\"), _countof(szPath) - mir_tstrlen(szPath));
- if (_tmkdir(szPath) == 0)
- ShellExecute((HWND)lParam, _T("open"), szPath, _T(""), _T(""), SW_SHOW);
- }
- break;
- }
-
- case IDC_STEP3:
- if (LoadWIData(false))
- MessageBox(NULL,
- TranslateT("All update data has been reloaded."),
- TranslateT("Weather Protocol"), MB_OK | MB_ICONINFORMATION);
- break;
-
- case IDC_STEP4:
- WeatherAdd(0, 0);
- // fall through
- case IDCANCEL:
- // close the info window
- DestroyWindow(hwndDlg);
- break;
- }
- break;
-
- case WM_CLOSE:
- DestroyWindow(hwndDlg);
- break;
-
- case WM_DESTROY:
- ReleaseIconEx((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0));
- ReleaseIconEx((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, 0));
- break;
+ // free the list one by one
+ while (WIHead != NULL) {
+ WIDATALIST *wi = WIHead;
+ WIHead = wi->next;
+ FreeWIData(&wi->Data); // free the data struct
+ mir_free(wi);
}
- return FALSE;
-}
+ // make sure the entire list is clear
+ WITail = NULL;
+}
diff --git a/plugins/Weather/src/weather_opt.cpp b/plugins/Weather/src/weather_opt.cpp
index fd36410b99..9377bf7339 100644
--- a/plugins/Weather/src/weather_opt.cpp
+++ b/plugins/Weather/src/weather_opt.cpp
@@ -28,7 +28,7 @@ static BOOL opt_startup;
int RedrawFrame(WPARAM wParam, LPARAM lParam);
//============ LOADING AND SAVING OPTIONS ===========
-
+//
// set a string to default
// in = string to determine which field to set default "CBNEHXPp"
void SetTextDefault(const char* in)
@@ -387,7 +387,7 @@ static INT_PTR CALLBACK OptionsProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM l
//============ TEXT OPTION DIALOG ============
-void LoadTextSettings(HWND hdlg)
+static void LoadTextSettings(HWND hdlg)
{
// load text option settings from memory
SetDlgItemText(hdlg, IDC_CTEXT, opt.cText);
@@ -401,7 +401,7 @@ void LoadTextSettings(HWND hdlg)
}
// free the display text settings from memory
-void FreeTextVar(void)
+static void FreeTextVar(void)
{
wfree(&opt.cText);
wfree(&opt.bText);
diff --git a/plugins/Weather/src/weather_update.cpp b/plugins/Weather/src/weather_update.cpp
index b2d2928896..be95d9e56e 100644
--- a/plugins/Weather/src/weather_update.cpp
+++ b/plugins/Weather/src/weather_update.cpp
@@ -26,12 +26,10 @@ menu items).
#include "stdafx.h"
-UPDATELIST *UpdateListHead;
-UPDATELIST *UpdateListTail;
-
+UPDATELIST *UpdateListHead, *UpdateListTail;
//============ RETRIEVE NEW WEATHER ============
-
+//
// retrieve weather info and display / log them
// hContact = current contact
int UpdateWeather(MCONTACT hContact)
@@ -219,7 +217,7 @@ int UpdateWeather(MCONTACT hContact)
}
//============ UPDATE LIST ============
-
+//
// a linked list queue for updating weather station
// this function add a weather contact to the end of queue for update
// hContact = current contact
@@ -279,8 +277,30 @@ void DestroyUpdateList(void)
ReleaseMutex(hUpdateMutex);
}
-//============ UPDATE WEATHER ============
+// update all weather thread
+// this thread update each weather station from the queue
+static void UpdateThreadProc(void *)
+{
+ WaitForSingleObject(hUpdateMutex, INFINITE);
+ if (ThreadRunning) {
+ ReleaseMutex(hUpdateMutex);
+ return;
+ }
+ ThreadRunning = TRUE; // prevent 2 instance of this thread running
+ ReleaseMutex(hUpdateMutex);
+
+ // update weather by getting the first station from the queue until the queue is empty
+ while (UpdateListHead != NULL && !Miranda_Terminated())
+ UpdateWeather(UpdateGetFirst());
+
+ NetlibHttpDisconnect();
+
+ // exit the update thread
+ ThreadRunning = FALSE;
+}
+//============ UPDATE WEATHER ============
+//
// update all weather station
// AutoUpdate = true if it is from automatic update using timer
// false if it is from update by clicking the main menu
@@ -290,14 +310,14 @@ void UpdateAll(BOOL AutoUpdate, BOOL RemoveData)
for (MCONTACT hContact = db_find_first(WEATHERPROTONAME); hContact; hContact = db_find_next(hContact, WEATHERPROTONAME))
if (!db_get_b(hContact, WEATHERPROTONAME, "AutoUpdate", FALSE) || !AutoUpdate) {
if (RemoveData)
- DBDataManage((MCONTACT)hContact, WDBM_REMOVE, 0, 0);
+ DBDataManage(hContact, WDBM_REMOVE, 0, 0);
UpdateListAdd(hContact);
}
// if it is not updating, then start the update thread process
// if it is updating, the stations just added to the queue will get updated by the already-running process
if (!ThreadRunning)
- mir_forkthread(UpdateThreadProc, NULL);
+ mir_forkthread(UpdateThreadProc);
}
// update a single station
@@ -312,7 +332,7 @@ INT_PTR UpdateSingleStation(WPARAM wParam, LPARAM)
// if it is updating, the stations just added to the queue will get
// updated by the already-running process
if (!ThreadRunning)
- mir_forkthread(UpdateThreadProc, NULL);
+ mir_forkthread(UpdateThreadProc);
}
return 0;
@@ -330,34 +350,12 @@ INT_PTR UpdateSingleRemove(WPARAM wParam, LPARAM)
// if it is not updating, then start the update thread process
// if it is updating, the stations just added to the queue will get updated by the already-running process
if (!ThreadRunning)
- mir_forkthread(UpdateThreadProc, NULL);
+ mir_forkthread(UpdateThreadProc);
}
return 0;
}
-// update all weather thread
-// this thread update each weather station from the queue
-void UpdateThreadProc(LPVOID)
-{
- WaitForSingleObject(hUpdateMutex, INFINITE);
- if (ThreadRunning) {
- ReleaseMutex(hUpdateMutex);
- return;
- }
- ThreadRunning = TRUE; // prevent 2 instance of this thread running
- ReleaseMutex(hUpdateMutex);
-
- // update weather by getting the first station from the queue until the queue is empty
- while (UpdateListHead != NULL && !Miranda_Terminated())
- UpdateWeather(UpdateGetFirst());
-
- NetlibHttpDisconnect();
-
- // exit the update thread
- ThreadRunning = FALSE;
-}
-
// the "Update All" menu item in main menu
INT_PTR UpdateAllInfo(WPARAM, LPARAM)
{
@@ -375,12 +373,12 @@ INT_PTR UpdateAllRemove(WPARAM, LPARAM)
}
//============ GETTING WEATHER DATA ============
-
+//
// getting weather data and save them into the database
// hContact = the contact to get the data
int GetWeatherData(MCONTACT hContact)
{
- // get eacnh part of the id's
+ // get each part of the id's
TCHAR id[256];
GetStationID(hContact, id, _countof(id));
@@ -585,7 +583,7 @@ int GetWeatherData(MCONTACT hContact)
}
//============ UPDATE TIMERS ============
-
+//
// main auto-update timer
void CALLBACK timerProc(HWND, UINT, UINT_PTR, DWORD)
{
diff --git a/plugins/Weather/src/weather_userinfo.cpp b/plugins/Weather/src/weather_userinfo.cpp
index 96abec033a..cc99987a51 100644
--- a/plugins/Weather/src/weather_userinfo.cpp
+++ b/plugins/Weather/src/weather_userinfo.cpp
@@ -27,111 +27,8 @@ information
#include "stdafx.h"
-//============ CONTACT INFORMATION ============
-
-// initialize user info
-// lParam = current contact
-int UserInfoInit(WPARAM wParam, LPARAM lParam)
-{
- OPTIONSDIALOGPAGE odp = { 0 };
- odp.hInstance = hInst;
- odp.position = 100000000;
- odp.ptszTitle = _T(WEATHERPROTONAME);
-
- if (lParam == 0) {
- odp.pszTemplate = MAKEINTRESOURCEA(IDD_INFO);
- odp.pfnDlgProc = DlgProcINIPage;
- odp.flags = ODPF_TCHAR;
- UserInfo_AddPage(wParam, &odp);
- }
- else {
- // check if it is a weather contact
- if (IsMyContact(lParam)) {
- // register the contact info page
- odp.pszTemplate = MAKEINTRESOURCEA(IDD_USERINFO);
- odp.pfnDlgProc = DlgProcUIPage;
- odp.flags = ODPF_BOLDGROUPS | ODPF_TCHAR;
- UserInfo_AddPage(wParam, &odp);
- }
- }
- return 0;
-}
-
-// dialog process for the weather tab under user info
-// lParam = current contact
-INT_PTR CALLBACK DlgProcUIPage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- WEATHERINFO w;
- TCHAR str[MAX_TEXT_SIZE];
-
- MCONTACT hContact = (MCONTACT)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
- switch (msg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hwndDlg);
- SendDlgItemMessage(hwndDlg, IDC_MOREDETAIL, BUTTONSETASFLATBTN, TRUE, 0);
- // save the contact handle for later use
- hContact = lParam;
- SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)hContact);
- // load weather info for the contact
- w = LoadWeatherInfo(lParam);
- SetDlgItemText(hwndDlg, IDC_INFO1, GetDisplay(&w, TranslateT("Current condition for %n"), str));
-
- SendDlgItemMessage(hwndDlg, IDC_INFOICON, STM_SETICON,
- (WPARAM)Skin_LoadProtoIcon(WEATHERPROTONAME,
- db_get_w(hContact, WEATHERPROTONAME, "StatusIcon", 0)), 0);
-
- { // bold and enlarge the current condition
- LOGFONT lf;
- HFONT hNormalFont = (HFONT)SendDlgItemMessage(hwndDlg, IDC_INFO2, WM_GETFONT, 0, 0);
- GetObject(hNormalFont, sizeof(lf), &lf);
- lf.lfWeight = FW_BOLD;
- lf.lfWidth = 7;
- lf.lfHeight = 15;
- SendDlgItemMessage(hwndDlg, IDC_INFO2, WM_SETFONT, (WPARAM)CreateFontIndirect(&lf), 0);
- }
- // set the text for displaying other current weather conditions data
- GetDisplay(&w, _T("%c %t"), str);
- SetDlgItemText(hwndDlg, IDC_INFO2, str);
- SetDlgItemText(hwndDlg, IDC_INFO3, w.feel);
- SetDlgItemText(hwndDlg, IDC_INFO4, w.pressure);
- GetDisplay(&w, _T("%i %w"), str);
- SetDlgItemText(hwndDlg, IDC_INFO5, str);
- SetDlgItemText(hwndDlg, IDC_INFO6, w.dewpoint);
- SetDlgItemText(hwndDlg, IDC_INFO7, w.sunrise);
- SetDlgItemText(hwndDlg, IDC_INFO8, w.sunset);
- SetDlgItemText(hwndDlg, IDC_INFO9, w.high);
- SetDlgItemText(hwndDlg, IDC_INFO10, w.low);
- GetDisplay(&w, TranslateT("Last update on: %u"), str);
- SetDlgItemText(hwndDlg, IDC_INFO11, str);
- SetDlgItemText(hwndDlg, IDC_INFO12, w.humid);
- SetDlgItemText(hwndDlg, IDC_INFO13, w.vis);
- break;
-
- case WM_DESTROY:
- IcoLib_ReleaseIcon((HICON)SendDlgItemMessage(hwndDlg, IDC_INFOICON, STM_SETICON, 0, 0));
- DeleteObject((HFONT)SendDlgItemMessage(hwndDlg, IDC_INFO2, WM_GETFONT, 0, 0));
- break;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDC_MOREDETAIL:
- HWND hMoreDataDlg = WindowList_Find(hDataWindowList, hContact);
- if (hMoreDataDlg == NULL)
- hMoreDataDlg = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_BRIEF), NULL, DlgProcMoreData, hContact);
- else {
- SetForegroundWindow(hMoreDataDlg);
- SetFocus(hMoreDataDlg);
- }
- ShowWindow(GetDlgItem(hMoreDataDlg, IDC_MTEXT), 0);
- ShowWindow(GetDlgItem(hMoreDataDlg, IDC_DATALIST), 1);
- }
- break;
- }
- return 0;
-}
-
//============ BRIEF INFORMATION ============
-
+//
static int BriefDlgResizer(HWND, LPARAM, UTILRESIZECONTROL *urc)
{
switch (urc->wId) {
@@ -153,9 +50,31 @@ static int BriefDlgResizer(HWND, LPARAM, UTILRESIZECONTROL *urc)
return RD_ANCHORX_LEFT | RD_ANCHORY_TOP;
}
+// set the title of the dialog and on the which rectangle
+// also load brief info into message box
+static void LoadBriefInfoText(HWND hwndDlg, MCONTACT hContact)
+{
+ WEATHERINFO winfo;
+ TCHAR str[4096];
+
+ // load weather information from the contact into the WEATHERINFO struct
+ winfo = LoadWeatherInfo(hContact);
+ // check if data exist. If not, display error message box
+ if (!(BOOL)db_get_b(hContact, WEATHERPROTONAME, "IsUpdated", FALSE))
+ _tcsncpy(str, WEATHER_NO_INFO, _countof(str) - 1);
+ else
+ // set the display text and show the message box
+ GetDisplay(&winfo, opt.bText, str);
+ SetDlgItemText(hwndDlg, IDC_MTEXT, str);
+
+ GetDisplay(&winfo, _T("%c, %t"), str);
+ SetWindowText(hwndDlg, winfo.city);
+ SetDlgItemText(hwndDlg, IDC_HEADERBAR, str);
+}
+
// dialog process for more data in the user info window
// lParam = contact handle
-INT_PTR CALLBACK DlgProcMoreData(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+static INT_PTR CALLBACK DlgProcMoreData(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
static const unsigned tabstops = 48;
MCONTACT hContact = (MCONTACT)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
@@ -319,28 +238,110 @@ INT_PTR CALLBACK DlgProcMoreData(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l
return FALSE;
}
-// set the title of the dialog and on the which rectangle
-// also load brief info into message box
-void LoadBriefInfoText(HWND hwndDlg, MCONTACT hContact)
+// dialog process for the weather tab under user info
+// lParam = current contact
+static INT_PTR CALLBACK DlgProcUIPage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
- WEATHERINFO winfo;
- TCHAR str[4096];
+ WEATHERINFO w;
+ TCHAR str[MAX_TEXT_SIZE];
- // load weather information from the contact into the WEATHERINFO struct
- winfo = LoadWeatherInfo(hContact);
- // check if data exist. If not, display error message box
- if (!(BOOL)db_get_b(hContact, WEATHERPROTONAME, "IsUpdated", FALSE))
- _tcsncpy(str, WEATHER_NO_INFO, _countof(str) - 1);
- else
- // set the display text and show the message box
- GetDisplay(&winfo, opt.bText, str);
- SetDlgItemText(hwndDlg, IDC_MTEXT, str);
+ MCONTACT hContact = (MCONTACT)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
+ switch (msg) {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hwndDlg);
+ SendDlgItemMessage(hwndDlg, IDC_MOREDETAIL, BUTTONSETASFLATBTN, TRUE, 0);
+ // save the contact handle for later use
+ hContact = lParam;
+ SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)hContact);
+ // load weather info for the contact
+ w = LoadWeatherInfo(lParam);
+ SetDlgItemText(hwndDlg, IDC_INFO1, GetDisplay(&w, TranslateT("Current condition for %n"), str));
- GetDisplay(&winfo, _T("%c, %t"), str);
- SetWindowText(hwndDlg, winfo.city);
- SetDlgItemText(hwndDlg, IDC_HEADERBAR, str);
+ SendDlgItemMessage(hwndDlg, IDC_INFOICON, STM_SETICON,
+ (WPARAM)Skin_LoadProtoIcon(WEATHERPROTONAME,
+ db_get_w(hContact, WEATHERPROTONAME, "StatusIcon", 0)), 0);
+
+ { // bold and enlarge the current condition
+ LOGFONT lf;
+ HFONT hNormalFont = (HFONT)SendDlgItemMessage(hwndDlg, IDC_INFO2, WM_GETFONT, 0, 0);
+ GetObject(hNormalFont, sizeof(lf), &lf);
+ lf.lfWeight = FW_BOLD;
+ lf.lfWidth = 7;
+ lf.lfHeight = 15;
+ SendDlgItemMessage(hwndDlg, IDC_INFO2, WM_SETFONT, (WPARAM)CreateFontIndirect(&lf), 0);
+ }
+ // set the text for displaying other current weather conditions data
+ GetDisplay(&w, _T("%c %t"), str);
+ SetDlgItemText(hwndDlg, IDC_INFO2, str);
+ SetDlgItemText(hwndDlg, IDC_INFO3, w.feel);
+ SetDlgItemText(hwndDlg, IDC_INFO4, w.pressure);
+ GetDisplay(&w, _T("%i %w"), str);
+ SetDlgItemText(hwndDlg, IDC_INFO5, str);
+ SetDlgItemText(hwndDlg, IDC_INFO6, w.dewpoint);
+ SetDlgItemText(hwndDlg, IDC_INFO7, w.sunrise);
+ SetDlgItemText(hwndDlg, IDC_INFO8, w.sunset);
+ SetDlgItemText(hwndDlg, IDC_INFO9, w.high);
+ SetDlgItemText(hwndDlg, IDC_INFO10, w.low);
+ GetDisplay(&w, TranslateT("Last update on: %u"), str);
+ SetDlgItemText(hwndDlg, IDC_INFO11, str);
+ SetDlgItemText(hwndDlg, IDC_INFO12, w.humid);
+ SetDlgItemText(hwndDlg, IDC_INFO13, w.vis);
+ break;
+
+ case WM_DESTROY:
+ IcoLib_ReleaseIcon((HICON)SendDlgItemMessage(hwndDlg, IDC_INFOICON, STM_SETICON, 0, 0));
+ DeleteObject((HFONT)SendDlgItemMessage(hwndDlg, IDC_INFO2, WM_GETFONT, 0, 0));
+ break;
+
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDC_MOREDETAIL:
+ HWND hMoreDataDlg = WindowList_Find(hDataWindowList, hContact);
+ if (hMoreDataDlg == NULL)
+ hMoreDataDlg = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_BRIEF), NULL, DlgProcMoreData, hContact);
+ else {
+ SetForegroundWindow(hMoreDataDlg);
+ SetFocus(hMoreDataDlg);
+ }
+ ShowWindow(GetDlgItem(hMoreDataDlg, IDC_MTEXT), 0);
+ ShowWindow(GetDlgItem(hMoreDataDlg, IDC_DATALIST), 1);
+ }
+ break;
+ }
+ return 0;
}
+//============ CONTACT INFORMATION ============
+//
+// initialize user info
+// lParam = current contact
+int UserInfoInit(WPARAM wParam, LPARAM lParam)
+{
+ OPTIONSDIALOGPAGE odp = { 0 };
+ odp.hInstance = hInst;
+ odp.position = 100000000;
+ odp.ptszTitle = _T(WEATHERPROTONAME);
+
+ if (lParam == 0) {
+ odp.pszTemplate = MAKEINTRESOURCEA(IDD_INFO);
+ odp.pfnDlgProc = DlgProcINIPage;
+ odp.flags = ODPF_TCHAR;
+ UserInfo_AddPage(wParam, &odp);
+ }
+ else {
+ // check if it is a weather contact
+ if (IsMyContact(lParam)) {
+ // register the contact info page
+ odp.pszTemplate = MAKEINTRESOURCEA(IDD_USERINFO);
+ odp.pfnDlgProc = DlgProcUIPage;
+ odp.flags = ODPF_BOLDGROUPS | ODPF_TCHAR;
+ UserInfo_AddPage(wParam, &odp);
+ }
+ }
+ return 0;
+}
+
+
// show brief information dialog
// wParam = current contact
int BriefInfo(WPARAM wParam, LPARAM)