summaryrefslogtreecommitdiff
path: root/plugins/Weather/src/weather_update.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2015-08-27 20:49:19 +0000
committerGeorge Hazan <george.hazan@gmail.com>2015-08-27 20:49:19 +0000
commit5d7ce04b05778bdd989b6744b300c0f65ed94624 (patch)
tree088fa7be74d11d1e7aa868aa204a5740bdd4ea2e /plugins/Weather/src/weather_update.cpp
parent4161903017f66f2a91f72df5bf44f6165cbfffde (diff)
code cleaning
git-svn-id: http://svn.miranda-ng.org/main/trunk@15049 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Weather/src/weather_update.cpp')
-rw-r--r--plugins/Weather/src/weather_update.cpp102
1 files changed, 51 insertions, 51 deletions
diff --git a/plugins/Weather/src/weather_update.cpp b/plugins/Weather/src/weather_update.cpp
index 78bf4c6a10..a213106160 100644
--- a/plugins/Weather/src/weather_update.cpp
+++ b/plugins/Weather/src/weather_update.cpp
@@ -34,7 +34,7 @@ UPDATELIST *UpdateListTail;
// retrieve weather info and display / log them
// hContact = current contact
-int UpdateWeather(MCONTACT hContact)
+int UpdateWeather(MCONTACT hContact)
{
TCHAR str[256], str2[MAX_TEXT_SIZE];
DBVARIANT dbv;
@@ -152,7 +152,7 @@ int UpdateWeather(MCONTACT hContact)
db_set_b(hContact, WEATHERPROTONAME, "IsUpdated", TRUE);
// save info for default weather condition
- if ( !mir_tstrcmp(winfo.id, opt.Default) && !opt.NoProtoCondition) {
+ if (!mir_tstrcmp(winfo.id, opt.Default) && !opt.NoProtoCondition) {
// save current condition for default station to be displayed after the update
old_status = status;
status = winfo.status;
@@ -168,13 +168,13 @@ int UpdateWeather(MCONTACT hContact)
if (db_get_b(hContact, WEATHERPROTONAME, "File", 0)) {
// external log
- if ( !db_get_ts(hContact,WEATHERPROTONAME, "Log",&dbv)) {
+ if (!db_get_ts(hContact, WEATHERPROTONAME, "Log", &dbv)) {
// for the option for overwriting the file, delete old file first
- if (db_get_b(hContact,WEATHERPROTONAME, "Overwrite",0))
+ if (db_get_b(hContact, WEATHERPROTONAME, "Overwrite", 0))
DeleteFile(dbv.ptszVal);
// open the file and set point to the end of file
- FILE *file = _tfopen( dbv.ptszVal, _T("a"));
+ FILE *file = _tfopen(dbv.ptszVal, _T("a"));
db_free(&dbv);
if (file != NULL) {
// write data to the file and close
@@ -197,7 +197,7 @@ int UpdateWeather(MCONTACT hContact)
dbei.flags = DBEF_READ | DBEF_UTF;
dbei.eventType = EVENTTYPE_MESSAGE;
dbei.pBlob = szMessage;
- dbei.cbBlob = (DWORD)mir_strlen(szMessage)+1;
+ dbei.cbBlob = (DWORD)mir_strlen(szMessage) + 1;
db_event_add(hContact, &dbei);
}
@@ -223,7 +223,7 @@ int UpdateWeather(MCONTACT hContact)
// a linked list queue for updating weather station
// this function add a weather contact to the end of queue for update
// hContact = current contact
-void UpdateListAdd(MCONTACT hContact)
+void UpdateListAdd(MCONTACT hContact)
{
UPDATELIST *newItem = (UPDATELIST*)mir_alloc(sizeof(UPDATELIST));
newItem->hContact = hContact;
@@ -247,14 +247,14 @@ MCONTACT UpdateGetFirst()
WaitForSingleObject(hUpdateMutex, INFINITE);
if (UpdateListHead != NULL) {
- UPDATELIST* Item = UpdateListHead;
+ UPDATELIST* Item = UpdateListHead;
hContact = Item->hContact;
UpdateListHead = Item->next;
mir_free(Item);
if (UpdateListHead == NULL)
- UpdateListTail = NULL;
+ UpdateListTail = NULL;
}
ReleaseMutex(hUpdateMutex);
@@ -262,7 +262,7 @@ MCONTACT UpdateGetFirst()
return hContact;
}
-void DestroyUpdateList(void)
+void DestroyUpdateList(void)
{
WaitForSingleObject(hUpdateMutex, INFINITE);
@@ -284,11 +284,11 @@ void DestroyUpdateList(void)
// 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
-void UpdateAll(BOOL AutoUpdate, BOOL RemoveData)
+void UpdateAll(BOOL AutoUpdate, BOOL RemoveData)
{
// add all weather contact to the update queue list
for (MCONTACT hContact = db_find_first(WEATHERPROTONAME); hContact; hContact = db_find_next(hContact, WEATHERPROTONAME))
- if ( !db_get_b(hContact,WEATHERPROTONAME, "AutoUpdate",FALSE) || !AutoUpdate) {
+ if (!db_get_b(hContact, WEATHERPROTONAME, "AutoUpdate", FALSE) || !AutoUpdate) {
if (RemoveData)
DBDataManage((MCONTACT)hContact, WDBM_REMOVE, 0, 0);
UpdateListAdd(hContact);
@@ -296,13 +296,13 @@ void UpdateAll(BOOL AutoUpdate, BOOL RemoveData)
// 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)
+ if (!ThreadRunning)
mir_forkthread(UpdateThreadProc, NULL);
}
// update a single station
// wParam = handle for the weather station that is going to be updated
-INT_PTR UpdateSingleStation(WPARAM wParam, LPARAM)
+INT_PTR UpdateSingleStation(WPARAM wParam, LPARAM)
{
if (IsMyContact(wParam)) {
// add the station to the end of the update queue
@@ -311,7 +311,7 @@ INT_PTR UpdateSingleStation(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)
+ if (!ThreadRunning)
mir_forkthread(UpdateThreadProc, NULL);
}
@@ -320,7 +320,7 @@ INT_PTR UpdateSingleStation(WPARAM wParam, LPARAM)
// update a single station with removing the old data
// wParam = handle for the weather station that is going to be updated
-INT_PTR UpdateSingleRemove(WPARAM wParam, LPARAM)
+INT_PTR UpdateSingleRemove(WPARAM wParam, LPARAM)
{
if (IsMyContact(wParam)) {
// add the station to the end of the update queue, and also remove old data
@@ -329,7 +329,7 @@ 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)
+ if (!ThreadRunning)
mir_forkthread(UpdateThreadProc, NULL);
}
@@ -338,7 +338,7 @@ INT_PTR UpdateSingleRemove(WPARAM wParam, LPARAM)
// update all weather thread
// this thread update each weather station from the queue
-void UpdateThreadProc(LPVOID)
+void UpdateThreadProc(LPVOID)
{
WaitForSingleObject(hUpdateMutex, INFINITE);
if (ThreadRunning) {
@@ -349,7 +349,7 @@ void UpdateThreadProc(LPVOID)
ReleaseMutex(hUpdateMutex);
// update weather by getting the first station from the queue until the queue is empty
- while (UpdateListHead != NULL && !Miranda_Terminated())
+ while (UpdateListHead != NULL && !Miranda_Terminated())
UpdateWeather(UpdateGetFirst());
NetlibHttpDisconnect();
@@ -378,7 +378,7 @@ INT_PTR UpdateAllRemove(WPARAM, LPARAM)
// getting weather data and save them into the database
// hContact = the contact to get the data
-int GetWeatherData(MCONTACT hContact)
+int GetWeatherData(MCONTACT hContact)
{
// get eacnh part of the id's
TCHAR id[256];
@@ -401,14 +401,14 @@ int GetWeatherData(MCONTACT hContact)
// get the update strings (loaded to memory from ini files)
WIDATA *Data = GetWIData(Svc);
- if (Data == NULL)
+ if (Data == NULL)
return SVC_NOT_FOUND; // the ini for the station cannot be found
WORD cond = NA;
char loc[256];
- for (int i=0; i < 4; ++i) {
+ for (int i = 0; i < 4; ++i) {
// generate update URL
- switch(i) {
+ switch (i) {
case 0:
mir_snprintf(loc, _countof(loc), Data->UpdateURL, _T2A(id));
break;
@@ -439,7 +439,7 @@ int GetWeatherData(MCONTACT hContact)
mir_free(szData);
return retval;
}
- if ( _tcsstr(szData, _T("Document Not Found")) != NULL) {
+ if (_tcsstr(szData, _T("Document Not Found")) != NULL) {
mir_free(szData);
return DOC_NOT_FOUND;
}
@@ -460,11 +460,11 @@ int GetWeatherData(MCONTACT hContact)
// if it is a normal item with start= and end=, then parse through the downloaded string
// to get a data value.
GetDataValue(&Item->Item, DataValue, &szInfo);
- if ( mir_tstrcmp(Item->Item.Name, _T("Condition")) && mir_tstrcmpi(Item->Item.Unit, _T("Cond")))
+ if (mir_tstrcmp(Item->Item.Name, _T("Condition")) && mir_tstrcmpi(Item->Item.Unit, _T("Cond")))
_tcsncpy(DataValue, TranslateTS(DataValue), MAX_DATA_LEN - 1);
break;
- case WID_SET:
+ case WID_SET:
{
// for the "Set Data=" operation
DBVARIANT dbv;
@@ -480,25 +480,25 @@ int GetWeatherData(MCONTACT hContact)
// the end of the string, last item
chop = _tcsstr(str, _T(" & "));
if (chop == NULL)
- chop = _tcschr(str, '\0');
+ chop = _tcschr(str, '\0');
- stl = min(sizeof(str2)-1, (unsigned)(chop-str-2));
- _tcsncpy(str2, str+1, stl);
+ stl = min(sizeof(str2) - 1, (unsigned)(chop - str - 2));
+ _tcsncpy(str2, str + 1, stl);
str2[stl] = 0;
- switch(str[0]) {
+ switch (str[0]) {
case '[': // variable, add the value to the result string
hasvar = TRUE;
- if ( !DBGetData(hContact, _T2A(str2), &dbv)) {
+ if (!DBGetData(hContact, _T2A(str2), &dbv)) {
mir_tstrncat(DataValue, dbv.ptszVal, _countof(DataValue) - mir_tstrlen(DataValue));
- DataValue[_countof(DataValue)-1] = 0;
+ DataValue[_countof(DataValue) - 1] = 0;
db_free(&dbv);
}
break;
case'\"': // constant, add it to the result string
mir_tstrncat(DataValue, TranslateTS(str2), _countof(DataValue) - mir_tstrlen(DataValue));
- DataValue[_countof(DataValue)-1] = 0;
+ DataValue[_countof(DataValue) - 1] = 0;
break;
}
@@ -506,16 +506,16 @@ int GetWeatherData(MCONTACT hContact)
str = chop + 3;
} while (chop[0] && str[0]);
- if ( !hasvar) ConvertDataValue(&Item->Item, DataValue);
+ if (!hasvar) ConvertDataValue(&Item->Item, DataValue);
break;
}
- case WID_BREAK:
+ case WID_BREAK:
{
// for the "Break Data=" operation
DBVARIANT dbv;
- if ( !DBGetData(hContact, _T2A(Item->Item.Start), &dbv)) {
+ if (!DBGetData(hContact, _T2A(Item->Item.Start), &dbv)) {
_tcsncpy(DataValue, dbv.ptszVal, _countof(DataValue));
- DataValue[_countof(DataValue)-1] = 0;
+ DataValue[_countof(DataValue) - 1] = 0;
db_free(&dbv);
}
else {
@@ -537,23 +537,23 @@ int GetWeatherData(MCONTACT hContact)
ConvertDataValue(&Item->Item, DataValue);
// write the 2 strings created from the break operation
- if (Item->Item.End[0])
+ if (Item->Item.End[0])
db_set_ts(hContact, WEATHERCONDITION, _T2A(Item->Item.End), end);
break;
- } }
+ }
+ }
// don't store data if it is not available
- if ((DataValue[0] != 0 && mir_tstrcmp(DataValue, NODATA) &&
+ if ((DataValue[0] != 0 && mir_tstrcmp(DataValue, NODATA) &&
mir_tstrcmp(DataValue, TranslateTS(NODATA)) && mir_tstrcmp(Item->Item.Name, _T("Ignore"))) ||
- ( !mir_tstrcmp(Item->Item.Name, _T("Alert")) && i == 0))
- {
+ (!mir_tstrcmp(Item->Item.Name, _T("Alert")) && i == 0)) {
// temporary workaround for mToolTip to show feel-like temperature
- if ( !mir_tstrcmp(Item->Item.Name, _T("Feel")))
+ if (!mir_tstrcmp(Item->Item.Name, _T("Feel")))
db_set_ts(hContact, WEATHERCONDITION, "Heat Index", DataValue);
GetStationID(hContact, Svc, _countof(Svc));
- if ( !mir_tstrcmp(Svc, opt.Default))
+ if (!mir_tstrcmp(Svc, opt.Default))
db_set_ts(NULL, DEFCURRENTWEATHER, _T2A(Item->Item.Name), DataValue);
- if ( !mir_tstrcmp(Item->Item.Name, _T("Condition"))) {
+ if (!mir_tstrcmp(Item->Item.Name, _T("Condition"))) {
TCHAR buf[128], *cbuf;
mir_sntprintf(buf, _T("#%s Weather"), DataValue);
cbuf = TranslateTS(buf);
@@ -563,7 +563,7 @@ int GetWeatherData(MCONTACT hContact)
CharLowerBuff(DataValue, (DWORD)mir_tstrlen(DataValue));
cond = GetIcon(DataValue, Data);
}
- else if ( mir_tstrcmpi(Item->Item.Unit, _T("Cond")) == 0) {
+ else if (mir_tstrcmpi(Item->Item.Unit, _T("Cond")) == 0) {
TCHAR buf[128], *cbuf;
mir_sntprintf(buf, _T("#%s Weather"), DataValue);
cbuf = TranslateTS(buf);
@@ -587,24 +587,24 @@ int GetWeatherData(MCONTACT hContact)
//============ UPDATE TIMERS ============
// main auto-update timer
-void CALLBACK timerProc(HWND, UINT, UINT_PTR, DWORD)
+void CALLBACK timerProc(HWND, UINT, UINT_PTR, DWORD)
{
// only run if it is not current updating and the auto update option is enabled
- if ( !ThreadRunning && opt.CAutoUpdate && !Miranda_Terminated() && (opt.NoProtoCondition || status == ID_STATUS_ONLINE))
+ if (!ThreadRunning && opt.CAutoUpdate && !Miranda_Terminated() && (opt.NoProtoCondition || status == ID_STATUS_ONLINE))
UpdateAll(TRUE, FALSE);
}
// temporary timer for first run
// when this is run, it kill the old startup timer and create the permenant one above
-void CALLBACK timerProc2(HWND, UINT, UINT_PTR, DWORD)
+void CALLBACK timerProc2(HWND, UINT, UINT_PTR, DWORD)
{
KillTimer(NULL, timerId);
ThreadRunning = FALSE;
- if ( Miranda_Terminated())
+ if (Miranda_Terminated())
return;
if (opt.StartupUpdate && opt.NoProtoCondition)
UpdateAll(FALSE, FALSE);
- timerId = SetTimer(NULL, 0, ((int)opt.UpdateTime)*60000, (TIMERPROC)timerProc);
+ timerId = SetTimer(NULL, 0, ((int)opt.UpdateTime) * 60000, (TIMERPROC)timerProc);
}