summaryrefslogtreecommitdiff
path: root/plugins/Weather/src/weather_ini.cpp
diff options
context:
space:
mode:
authorTobias Weimer <wishmaster51@googlemail.com>2016-04-05 18:55:38 +0000
committerTobias Weimer <wishmaster51@googlemail.com>2016-04-05 18:55:38 +0000
commitab2852015641c9aa9aa2588fb21617e31b7da546 (patch)
treed364084fadc2ef4b3787b61695c8323ecf0a0214 /plugins/Weather/src/weather_ini.cpp
parentce08c537a294e306a01981f3f02c4757cd130c92 (diff)
Weather: - cleanup
git-svn-id: http://svn.miranda-ng.org/main/trunk@16589 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Weather/src/weather_ini.cpp')
-rw-r--r--plugins/Weather/src/weather_ini.cpp267
1 files changed, 133 insertions, 134 deletions
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;
+}