summaryrefslogtreecommitdiff
path: root/plugins/Weather/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-04-09 21:40:22 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-04-09 21:40:22 +0000
commit3dc0d9b0b7c30ea2f77d74c4ce5b6ccd67bd525c (patch)
treeefee912ee654baafeb98efcd117921db6b7489bc /plugins/Weather/src
parentbcb27264ba737778e5d3edad36088bacf74f0236 (diff)
- the kernel filters out contacts by proto names much faster than a plugin;
- database cycles simplified git-svn-id: http://svn.miranda-ng.org/main/trunk@4404 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Weather/src')
-rw-r--r--plugins/Weather/src/weather_contacts.cpp32
-rw-r--r--plugins/Weather/src/weather_data.cpp83
-rw-r--r--plugins/Weather/src/weather_mwin.cpp22
-rw-r--r--plugins/Weather/src/weather_update.cpp10
4 files changed, 67 insertions, 80 deletions
diff --git a/plugins/Weather/src/weather_contacts.cpp b/plugins/Weather/src/weather_contacts.cpp
index a52727f002..2cc4187bf1 100644
--- a/plugins/Weather/src/weather_contacts.cpp
+++ b/plugins/Weather/src/weather_contacts.cpp
@@ -448,26 +448,24 @@ int ContactDeleted(WPARAM wParam, LPARAM lParam)
// now the default station is deleted, try to get a new one
// start looking for other weather stations
- for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
- if (IsMyContact(hContact)) {
- if ( !db_get_ts(hContact, WEATHERPROTONAME, "ID", &dbv)) {
- // if the station is not a default station, set it as the new default station
- // this is the first weather station encountered from the search
- if ( _tcscmp(opt.Default, dbv.ptszVal)) {
- _tcscpy(opt.Default, dbv.ptszVal);
- opt.DefStn = hContact;
+ for (HANDLE hContact = db_find_first(WEATHERPROTONAME); hContact; hContact = db_find_next(hContact, WEATHERPROTONAME)) {
+ if ( !db_get_ts(hContact, WEATHERPROTONAME, "ID", &dbv)) {
+ // if the station is not a default station, set it as the new default station
+ // this is the first weather station encountered from the search
+ if ( _tcscmp(opt.Default, dbv.ptszVal)) {
+ _tcscpy(opt.Default, dbv.ptszVal);
+ opt.DefStn = hContact;
+ db_free(&dbv);
+ if ( !db_get_ts(hContact, WEATHERPROTONAME, "Nick", &dbv)) {
+ TCHAR str[255];
+ mir_sntprintf(str, SIZEOF(str), TranslateT("%s is now the default weather station"), dbv.ptszVal);
db_free(&dbv);
- if ( !db_get_ts(hContact, WEATHERPROTONAME, "Nick", &dbv)) {
- TCHAR str[255];
- mir_sntprintf(str, SIZEOF(str), TranslateT("%s is now the default weather station"), dbv.ptszVal);
- db_free(&dbv);
- MessageBox(NULL, str, TranslateT("Weather Protocol"), MB_OK | MB_ICONINFORMATION);
- }
- db_set_ts(NULL, WEATHERPROTONAME, "Default", opt.Default);
- return 0; // exit this function quickly
+ MessageBox(NULL, str, TranslateT("Weather Protocol"), MB_OK | MB_ICONINFORMATION);
}
- db_free(&dbv);
+ db_set_ts(NULL, WEATHERPROTONAME, "Default", opt.Default);
+ return 0; // exit this function quickly
}
+ db_free(&dbv);
}
}
// got here if no more weather station left
diff --git a/plugins/Weather/src/weather_data.cpp b/plugins/Weather/src/weather_data.cpp
index 3f6ce3b0f2..bcf0e22139 100644
--- a/plugins/Weather/src/weather_data.cpp
+++ b/plugins/Weather/src/weather_data.cpp
@@ -124,54 +124,51 @@ void EraseAllInfo()
HANDLE LastContact = NULL;
DBVARIANT dbv;
// loop through all contacts
- for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
- // see if the contact is a weather contact
- if ( IsMyContact(hContact)) {
- db_set_w(hContact,WEATHERPROTONAME, "Status",ID_STATUS_OFFLINE);
- db_set_w(hContact,WEATHERPROTONAME, "StatusIcon",ID_STATUS_OFFLINE);
- db_unset(hContact, "CList", "MyHandle");
- // clear all data
- if ( db_get_ts(hContact, WEATHERPROTONAME, "Nick", &dbv)) {
- db_set_ts(hContact, WEATHERPROTONAME, "Nick", TranslateT("<Enter city name here>"));
- db_set_s(hContact, WEATHERPROTONAME, "LastLog", "never");
- db_set_s(hContact, WEATHERPROTONAME, "LastCondition", "None");
- db_set_s(hContact, WEATHERPROTONAME, "LastTemperature", "None");
- }
- else db_free(&dbv);
-
- DBDataManage(hContact, WDBM_REMOVE, 0, 0);
- db_set_s(hContact, "UserInfo", "MyNotes", "");
- // reset update tag
- db_set_b(hContact,WEATHERPROTONAME, "IsUpdated",FALSE);
- // reset logging settings
- if ( !db_get_ts(hContact,WEATHERPROTONAME, "Log", &dbv)) {
- db_set_b(hContact,WEATHERPROTONAME, "File",(BYTE)(dbv.ptszVal[0] != 0));
- db_free(&dbv);
- }
- else db_set_b(hContact,WEATHERPROTONAME, "File",FALSE);
+ for (HANDLE hContact = db_find_first(WEATHERPROTONAME); hContact; hContact = db_find_next(hContact, WEATHERPROTONAME)) {
+ db_set_w(hContact,WEATHERPROTONAME, "Status",ID_STATUS_OFFLINE);
+ db_set_w(hContact,WEATHERPROTONAME, "StatusIcon",ID_STATUS_OFFLINE);
+ db_unset(hContact, "CList", "MyHandle");
+ // clear all data
+ if ( db_get_ts(hContact, WEATHERPROTONAME, "Nick", &dbv)) {
+ db_set_ts(hContact, WEATHERPROTONAME, "Nick", TranslateT("<Enter city name here>"));
+ db_set_s(hContact, WEATHERPROTONAME, "LastLog", "never");
+ db_set_s(hContact, WEATHERPROTONAME, "LastCondition", "None");
+ db_set_s(hContact, WEATHERPROTONAME, "LastTemperature", "None");
+ }
+ else db_free(&dbv);
+
+ DBDataManage(hContact, WDBM_REMOVE, 0, 0);
+ db_set_s(hContact, "UserInfo", "MyNotes", "");
+ // reset update tag
+ db_set_b(hContact,WEATHERPROTONAME, "IsUpdated",FALSE);
+ // reset logging settings
+ if ( !db_get_ts(hContact,WEATHERPROTONAME, "Log", &dbv)) {
+ db_set_b(hContact,WEATHERPROTONAME, "File",(BYTE)(dbv.ptszVal[0] != 0));
+ db_free(&dbv);
+ }
+ else db_set_b(hContact,WEATHERPROTONAME, "File",FALSE);
- // if no default station find, assign a new one
- if (opt.Default[0] == 0) {
- GetStationID(hContact, opt.Default, SIZEOF(opt.Default));
+ // if no default station find, assign a new one
+ if (opt.Default[0] == 0) {
+ GetStationID(hContact, opt.Default, SIZEOF(opt.Default));
- opt.DefStn = hContact;
- if ( !db_get_ts(hContact,WEATHERPROTONAME, "Nick",&dbv)) {
- wsprintf(str, TranslateT("%s is now the default weather station"), dbv.ptszVal);
- db_free(&dbv);
- MessageBox(NULL, str, TranslateT("Weather Protocol"), MB_OK|MB_ICONINFORMATION);
- }
+ opt.DefStn = hContact;
+ if ( !db_get_ts(hContact,WEATHERPROTONAME, "Nick",&dbv)) {
+ wsprintf(str, TranslateT("%s is now the default weather station"), dbv.ptszVal);
+ db_free(&dbv);
+ MessageBox(NULL, str, TranslateT("Weather Protocol"), MB_OK|MB_ICONINFORMATION);
}
- // get the handle of the default station
- if (opt.DefStn == NULL) {
- if ( !db_get_ts(hContact,WEATHERPROTONAME, "ID",&dbv)) {
- if ( !_tcscmp(dbv.ptszVal, opt.Default))
- opt.DefStn = hContact;
- db_free(&dbv);
- }
+ }
+ // get the handle of the default station
+ if (opt.DefStn == NULL) {
+ if ( !db_get_ts(hContact,WEATHERPROTONAME, "ID",&dbv)) {
+ if ( !_tcscmp(dbv.ptszVal, opt.Default))
+ opt.DefStn = hContact;
+ db_free(&dbv);
}
- ContactCount++; // increment counter
- LastContact = hContact;
}
+ ContactCount++; // increment counter
+ LastContact = hContact;
}
// if weather contact exists, set the status to online so it is ready for update
diff --git a/plugins/Weather/src/weather_mwin.cpp b/plugins/Weather/src/weather_mwin.cpp
index 7f70b659d0..c127214999 100644
--- a/plugins/Weather/src/weather_mwin.cpp
+++ b/plugins/Weather/src/weather_mwin.cpp
@@ -384,25 +384,19 @@ void InitMwin(void)
FontRegisterT(&fontid);
}
- for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
- // see if the contact is a weather contact
- if (IsMyContact(hContact)) {
- if (db_get_dw(hContact, WEATHERPROTONAME, "mwin", 0))
- addWindow(hContact);
- }
- }
+ for (HANDLE hContact = db_find_first(WEATHERPROTONAME); hContact; hContact = db_find_next(hContact, WEATHERPROTONAME))
+ if (db_get_dw(hContact, WEATHERPROTONAME, "mwin", 0))
+ addWindow(hContact);
+
hFontHook = HookEvent(ME_FONT_RELOAD, RedrawFrame);
}
void DestroyMwin(void)
{
- for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
- // see if the contact is a weather contact
- if (IsMyContact(hContact)) {
- DWORD frameId = db_get_dw(hContact, WEATHERPROTONAME, "mwin", 0);
- if (frameId)
- CallService(MS_CLIST_FRAMES_REMOVEFRAME, frameId, 0);
- }
+ for (HANDLE hContact = db_find_first(WEATHERPROTONAME); hContact; hContact = db_find_next(hContact, WEATHERPROTONAME)) {
+ DWORD frameId = db_get_dw(hContact, WEATHERPROTONAME, "mwin", 0);
+ if (frameId)
+ CallService(MS_CLIST_FRAMES_REMOVEFRAME, frameId, 0);
}
UnregisterClass( _T("WeatherFrame"), hInst);
UnhookEvent(hFontHook);
diff --git a/plugins/Weather/src/weather_update.cpp b/plugins/Weather/src/weather_update.cpp
index 4c7f819b1f..a6cee642ff 100644
--- a/plugins/Weather/src/weather_update.cpp
+++ b/plugins/Weather/src/weather_update.cpp
@@ -282,12 +282,10 @@ void DestroyUpdateList(void)
void UpdateAll(BOOL AutoUpdate, BOOL RemoveData)
{
// add all weather contact to the update queue list
- for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
- if (IsMyContact(hContact)) {
- if ( !db_get_b(hContact,WEATHERPROTONAME, "AutoUpdate",FALSE) || !AutoUpdate) {
- if (RemoveData) DBDataManage((HANDLE)hContact, WDBM_REMOVE, 0, 0);
- UpdateListAdd(hContact);
- }
+ for (HANDLE hContact = db_find_first(WEATHERPROTONAME); hContact; hContact = db_find_next(hContact, WEATHERPROTONAME)) {
+ if ( !db_get_b(hContact,WEATHERPROTONAME, "AutoUpdate",FALSE) || !AutoUpdate) {
+ if (RemoveData) DBDataManage((HANDLE)hContact, WDBM_REMOVE, 0, 0);
+ UpdateListAdd(hContact);
}
}