// read complete forecast
// wParam = current contact
INT_PTR LoadForecast(WPARAM wParam, LPARAM lParam) 
{
	TCHAR id[256], loc2[256];
	GetStationID(wParam, id, SIZEOF(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, SIZEOF(loc2)) || loc2[0] == 0) {
			MessageBox(NULL, TranslateT("The URL for complete forecast have not been set. You can set it from the Edit Settings dialog."), 
				TranslateT("Weather Protocol"), MB_ICONINFORMATION);
			return 1;
		}
		// set the url and open the webpage
		OpenUrl(loc2, id );
	}
	return 0;
}
Exemple #2
0
// initialize weather info by loading values from database
// Change = current contact handle
// return value = the current weather information in WEATHERINFO struct
WEATHERINFO LoadWeatherInfo(HANDLE Change) 
{
	WEATHERINFO winfo;

	winfo.hContact = Change;
	// obtaining values from the DB
	// assuming station ID must exist at all time, but others does not have to
	// if the string is not found in database, a value of "N/A" is stored in the field
	GetStationID(Change, winfo.id, sizeof(winfo.id));

	if (DBGetStaticString(Change, WEATHERPROTONAME, "Nick", winfo.city, sizeof(winfo.city)))
		strcpy(winfo.city, NODATA);
	if (DBGetStaticString(Change, WEATHERCONDITION, "Update", winfo.update, sizeof(winfo.update)))
		strcpy(winfo.update, NODATA);
	if (DBGetStaticString(Change, WEATHERCONDITION, "Condition", winfo.cond, sizeof(winfo.cond)))
		strcpy(winfo.cond, NODATA);
	if (DBGetStaticString(Change, WEATHERCONDITION, "Temperature", winfo.temp, sizeof(winfo.temp)))
		strcpy(winfo.temp, NODATA);
	if (DBGetStaticString(Change, WEATHERCONDITION, "High", winfo.high, sizeof(winfo.high)))
		strcpy(winfo.high, NODATA);
	if (DBGetStaticString(Change, WEATHERCONDITION, "Low", winfo.low, sizeof(winfo.low)))
		strcpy(winfo.low, NODATA);
	if (DBGetStaticString(Change, WEATHERCONDITION, "Sunset", winfo.sunset, sizeof(winfo.sunset)))
		strcpy(winfo.sunset, NODATA);
	if (DBGetStaticString(Change, WEATHERCONDITION, "Sunrise", winfo.sunrise, sizeof(winfo.sunrise)))
		strcpy(winfo.sunrise, NODATA);
	if (DBGetStaticString(Change, WEATHERCONDITION, "Wind Speed", winfo.wind, sizeof(winfo.wind)))
		strcpy(winfo.wind, NODATA);
	if (DBGetStaticString(Change, WEATHERCONDITION, "Wind Direction", winfo.winddir, sizeof(winfo.winddir)))
		strcpy(winfo.winddir, NODATA);
	if (DBGetStaticString(Change, WEATHERCONDITION, "Dewpoint", winfo.dewpoint, sizeof(winfo.dewpoint)))
		strcpy(winfo.dewpoint, NODATA);
	if (DBGetStaticString(Change, WEATHERCONDITION, "Pressure", winfo.pressure, sizeof(winfo.pressure)))
		strcpy(winfo.pressure, NODATA);
	if (DBGetStaticString(Change, WEATHERCONDITION, "Visibility", winfo.vis, sizeof(winfo.vis)))
		strcpy(winfo.vis, NODATA);
	if (DBGetStaticString(Change, WEATHERCONDITION, "Humidity", winfo.humid, sizeof(winfo.humid)))
		strcpy(winfo.humid, NODATA);
	if (DBGetStaticString(Change, WEATHERCONDITION, "Feel", winfo.feel, sizeof(winfo.feel)))
		strcpy(winfo.feel, NODATA);

	winfo.status = (WORD)DBGetContactSettingWord(Change, WEATHERPROTONAME, "StatusIcon", ID_STATUS_OFFLINE);
	return winfo;
}
Exemple #3
0
// initialize weather info by loading values from database
// hContact = current contact handle
// return value = the current weather information in WEATHERINFO struct
WEATHERINFO LoadWeatherInfo(MCONTACT hContact)
{
	// obtaining values from the DB
	// assuming station ID must exist at all time, but others does not have to
	// if the string is not found in database, a value of "N/A" is stored in the field
	WEATHERINFO winfo;
	winfo.hContact = hContact;
	GetStationID(hContact, winfo.id, _countof(winfo.id));

	if (DBGetStaticString(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)))
		_tcsncpy(winfo.update, NODATA, _countof(winfo.update) - 1);
	if (DBGetStaticString(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)))
		_tcsncpy(winfo.temp, NODATA, _countof(winfo.temp) - 1);
	if (DBGetStaticString(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)))
		_tcsncpy(winfo.low, NODATA, _countof(winfo.low) - 1);
	if (DBGetStaticString(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)))
		_tcsncpy(winfo.sunrise, NODATA, _countof(winfo.sunrise) - 1);
	if (DBGetStaticString(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)))
		_tcsncpy(winfo.winddir, NODATA, _countof(winfo.winddir) - 1);
	if (DBGetStaticString(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)))
		_tcsncpy(winfo.pressure, NODATA, _countof(winfo.pressure) - 1);
	if (DBGetStaticString(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)))
		_tcsncpy(winfo.humid, NODATA, _countof(winfo.humid) - 1);
	if (DBGetStaticString(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);
	return winfo;
}
Exemple #4
0
// protocol service function for adding a new contact onto contact list
// lParam = PROTOSEARCHRESULT
INT_PTR WeatherAddToList(WPARAM wParam, LPARAM lParam) 
{
	PROTOSEARCHRESULT *psr = (PROTOSEARCHRESULT*)lParam;

	if(!psr || !psr->email)
		return 0;

	// search for existing contact
	for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
		// check if it is a weather contact
		if ( IsMyContact(hContact)) {
			DBVARIANT dbv;
			// check ID to see if the contact already exist in the database
			if ( !db_get_ts(hContact, WEATHERPROTONAME, "ID", &dbv)) {
				if ( !_tcsicmp(psr->email, dbv.ptszVal)) {
					// remove the flag for not on list and hidden, thus make the contact visible
					// and add them on the list
					if (db_get_b(hContact, "CList", "NotOnList", 1)) {
						db_unset(hContact, "CList", "NotOnList");
						db_unset(hContact, "CList", "Hidden");						
					}
					db_free(&dbv);
					// contact is added, function quitting
					return (INT_PTR)hContact;
				}
				db_free(&dbv);
			}
		}
	}

	// if contact with the same ID was not found, add it
	if (psr->cbSize < sizeof(PROTOSEARCHRESULT)) return 0;
	MCONTACT hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0);
	CallService(MS_PROTO_ADDTOCONTACT, hContact, (LPARAM)WEATHERPROTONAME);
	// suppress online notification for the new contact
	CallService(MS_IGNORE_IGNORE, hContact, IGNOREEVENT_USERONLINE);

	// set contact info and settings
	TCHAR svc[256];
	_tcsncpy(svc, psr->email, SIZEOF(svc)); svc[SIZEOF(svc)-1] = 0;
	GetSvc(svc);
	// set settings by obtaining the default for the service 
	if (psr->lastName[0] != 0) {
		WIDATA *sData = GetWIData(svc);
		db_set_ts(hContact, WEATHERPROTONAME, "MapURL", sData->DefaultMap);
		db_set_s(hContact, WEATHERPROTONAME, "InfoURL", sData->DefaultURL);
	}
	else { // if no valid service is found, create empty strings for MapURL and InfoURL
		db_set_s(hContact, WEATHERPROTONAME, "MapURL", "");
		db_set_s(hContact, WEATHERPROTONAME, "InfoURL", "");
	}
	// write the other info and settings to the database
	db_set_ts(hContact, WEATHERPROTONAME, "ID", psr->email);
	db_set_ts(hContact, WEATHERPROTONAME, "Nick", psr->nick);
	db_set_w(hContact, WEATHERPROTONAME, "Status", ID_STATUS_OFFLINE);

	AvatarDownloaded(hContact);

	TCHAR str[256];
	mir_sntprintf(str, SIZEOF(str), TranslateT("Current weather information for %s."), psr->nick);
	db_set_ts(hContact, WEATHERPROTONAME, "About", str);

	// make the last update tags to something invalid
	db_set_s(hContact, WEATHERPROTONAME, "LastLog", "never");
	db_set_s(hContact, WEATHERPROTONAME, "LastCondition", "None");
	db_set_s(hContact, WEATHERPROTONAME, "LastTemperature", "None");

	// ignore status change
	db_set_dw(hContact, "Ignore", "Mask", 8);

	// if no default station is found, set the new contact as default station
	if (opt.Default[0] == 0) {
		DBVARIANT dbv;
		GetStationID(hContact, opt.Default, SIZEOF(opt.Default));

		opt.DefStn = hContact;
		if ( !db_get_ts(hContact, WEATHERPROTONAME, "Nick", &dbv)) {
			// notification message box
			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);
	}
	// display the Edit Settings dialog box
	EditSettings(hContact, 0);
	return (INT_PTR)hContact;
}
const char* CSrCobjRecord::GetStation        (void) { return m_pParent ? m_pParent->GetEditorID(GetStationID())    : NULL; }
//This function was added to CGrandDataFile to recursively retrieve a list of *.BID files in
//a directory.  It reads the file header to populate the CList of tFileRecords that is converted to
//a safe array used by ImportManager.  This was flagrantly stolen from Kelly Michel and modified to
//search for and read in *.BID files. hn 6/8/2005
// 5-Jul-2005 SFK Removed dead code for readability
// 11-Jul-2005 SFK	Copied from GRAND Import and modified for binary
void CBinaryDataFile::GetCompleteFileList(short FacilityID, CList<tFileRecord, tFileRecord> *pFileList, 
									   const CString& Directory,  bool IncludeSubdirs)
{
	//USES_CONVERSION;

	CFileFind Finder;
	BOOL bWorking;
	CString  FileName;
	tFileRecord FileRecord;

	CString DirWithFileMask;
	DirWithFileMask.Format("%s\\*.*", Directory);
	bWorking = Finder.FindFile(DirWithFileMask);

	
	//If this is an "archive" directory, then skip it completely, and everything that may be underneath it.
	int StartSubDirName = Directory.ReverseFind('\\');
	if(StartSubDirName != -1)
	{
		CString SubDirName = Directory.Mid(StartSubDirName + 1);
		if(SubDirName.CompareNoCase("Archive")) //If SubDirName is not Archive...
		{
			do
			{
				bWorking = Finder.FindNextFile();
				
				if(!Finder.IsDots())
				{
					if(Finder.IsDirectory() && IncludeSubdirs)
					{
						//Recurse.
						GetCompleteFileList(FacilityID, pFileList, Finder.GetFilePath(), IncludeSubdirs);
					}
					else //if(Finder.IsNormal())
					{
 						FileName = Finder.GetFileName(); 
						CString Ext = FileName.Mid(FileName.GetLength() - 3, 3);
						if(!Ext.CompareNoCase("BNY"))
						{
							FileRecord.File.bstrVal = (Finder.GetFilePath()).AllocSysString();

							//****************************************************************
							//Open the file and get info on the data in the file.  Load that
							//file data into the FileRecord structure.
							//****************************************************************
							CString err;
							//If we are not able to read the *.BNY header, we fail
							CString cs(FileRecord.File.bstrVal);
							if (!ReadHeader (cs,&err))
							//if (!ReadHeader (W2T(FileRecord.File.bstrVal),&err))
							{
								if (mpFile) CloseDataFile();
							}
							else
							//Otherwise, save the file date and station ID read.
							{
								SYSTEMTIME sysTime;
								COleDateTime fileDate = GetFileDate ();
								fileDate.GetAsSystemTime (sysTime);
								SystemTimeToVariantTime (&sysTime,&FileRecord.Date.date);
								FileRecord.StationID.lVal = (long) GetStationID ();
								pFileList->AddTail (FileRecord);
								CloseDataFile ();
							}
						}
					}
				}		
			}
			while(bWorking != 0);
		}
	}

}
Exemple #7
0
// erase all current weather information from database
// lastver = the last used version number in dword (using PLUGIN_MAKE_VERSION)
void EraseAllInfo(DWORD lastver) 
{
	char str[255];
	int ContactCount = 0;
	HANDLE hContact, LastContact = NULL;
	DBVARIANT dbv;
	// loop through all contacts
	hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0);
	while(hContact) 
	{
		// see if the contact is a weather contact
		if(IsMyContact(hContact)) 
		{
			// check for upgrade
			if (lastver < __VERSION_DWORD)	UpgradeContact(lastver, hContact);
			DBWriteContactSettingWord(hContact,WEATHERPROTONAME,"Status",ID_STATUS_OFFLINE);
			DBWriteContactSettingWord(hContact,WEATHERPROTONAME,"StatusIcon",ID_STATUS_OFFLINE);
			DBDeleteContactSetting(hContact,"CList","MyHandle");
			// clear all data
			if (DBGetContactSettingString(hContact, WEATHERPROTONAME, "Nick", &dbv)) {
				DBWriteContactSettingString(hContact, WEATHERPROTONAME, "Nick", Translate("<Enter city name here>"));
				DBWriteContactSettingString(hContact, WEATHERPROTONAME, "LastLog", "never");
				DBWriteContactSettingString(hContact, WEATHERPROTONAME, "LastCondition", "None");
				DBWriteContactSettingString(hContact, WEATHERPROTONAME, "LastTemperature", "None");
			}
			else
				DBFreeVariant(&dbv);
/*
			DBWriteContactSettingString(hContact,WEATHERCONDITION,"Update", NODATA);
			DBWriteContactSettingString(hContact,WEATHERCONDITION,"Condition", NODATA);
			DBWriteContactSettingString(hContact,WEATHERCONDITION,"Temperature", NODATA);
			DBWriteContactSettingString(hContact,WEATHERCONDITION,"High", NODATA);
			DBWriteContactSettingString(hContact,WEATHERCONDITION,"Low", NODATA);
			DBWriteContactSettingString(hContact,WEATHERCONDITION,"Humidity", NODATA);
			DBWriteContactSettingString(hContact,WEATHERCONDITION,"Wind Speed", NODATA);
			DBWriteContactSettingString(hContact,WEATHERCONDITION,"Wind Direction", NODATA);
			DBWriteContactSettingString(hContact,WEATHERCONDITION,"Pressure", NODATA);
			DBWriteContactSettingString(hContact,WEATHERCONDITION,"Visibility", NODATA);
			DBWriteContactSettingString(hContact,WEATHERCONDITION,"Dewpoint", NODATA);
			DBWriteContactSettingString(hContact,WEATHERCONDITION,"Feel", NODATA);
			DBWriteContactSettingString(hContact,WEATHERCONDITION,"Heat Index", NODATA);
			DBWriteContactSettingString(hContact,WEATHERCONDITION,"Sunrise", NODATA);
			DBWriteContactSettingString(hContact,WEATHERCONDITION,"Sunset", NODATA);
*/
			DBDataManage(hContact, WDBM_REMOVE, 0, 0);
			DBWriteContactSettingString(hContact, "UserInfo", "MyNotes", "");
			// reset update tag
			DBWriteContactSettingByte(hContact,WEATHERPROTONAME,"IsUpdated",FALSE);
			// reset logging settings
			if (!DBGetContactSettingString(hContact,WEATHERPROTONAME,"Log",&dbv))
			{
				DBWriteContactSettingByte(hContact,WEATHERPROTONAME,"File",(BYTE)(dbv.pszVal[0] != 0));
				DBFreeVariant(&dbv);
			}
			else
				DBWriteContactSettingByte(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));

				opt.DefStn = hContact;
				if (!DBGetContactSettingString(hContact,WEATHERPROTONAME,"Nick",&dbv))
				{
					wsprintf(str, Translate("%s is now the default weather station"), dbv.pszVal);
					DBFreeVariant(&dbv);
					MessageBox(NULL, str, Translate("Weather Protocol"), MB_OK|MB_ICONINFORMATION);
				}
			}
			// get the handle of the default station
			if (opt.DefStn == NULL) {
				if (!DBGetContactSettingString(hContact,WEATHERPROTONAME,"ID",&dbv))
				{
					if (!strcmp(dbv.pszVal, opt.Default))	opt.DefStn = hContact;
					DBFreeVariant(&dbv);
				}
			}
			ContactCount++;		// increment counter
			LastContact = hContact;
		}
		hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0);
	}
	// if weather contact exists, set the status to online so it is ready for update
	// if (ContactCount != 0) status = ONLINE;
	// in case where the default station is missing
	if (opt.DefStn == NULL && ContactCount != 0) 
	{
		if (!DBGetContactSettingString(LastContact,WEATHERPROTONAME,"ID",&dbv))
		{
			strcpy(opt.Default, dbv.pszVal);
			DBFreeVariant(&dbv);
		}
		opt.DefStn = LastContact;
		if (!DBGetContactSettingString(LastContact,WEATHERPROTONAME,"Nick",&dbv))
		{
			wsprintf(str, Translate("%s is now the default weather station"), dbv.pszVal);
			DBFreeVariant(&dbv);
			MessageBox(NULL, str, Translate("Weather Protocol"), MB_OK|MB_ICONINFORMATION);
		}
	}
	// save option in case of default station changed
	DBWriteContactSettingString(NULL, WEATHERPROTONAME, "Default", opt.Default);
}
Exemple #8
0
// erase all current weather information from database
// lastver = the last used version number in dword (using PLUGIN_MAKE_VERSION)
void EraseAllInfo()
{
	TCHAR str[255];
	int ContactCount = 0;
	MCONTACT LastContact = NULL;
	DBVARIANT dbv;
	// loop through all contacts
	for (MCONTACT 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, _countof(opt.Default));

			opt.DefStn = hContact;
			if (!db_get_ts(hContact, WEATHERPROTONAME, "Nick", &dbv)) {
				mir_sntprintf(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 (!mir_tstrcmp(dbv.ptszVal, opt.Default))
					opt.DefStn = hContact;
				db_free(&dbv);
			}
		}
		ContactCount++;		// increment counter
		LastContact = hContact;
	}

	// if weather contact exists, set the status to online so it is ready for update
	// if (ContactCount != 0) status = ONLINE;
	// in case where the default station is missing
	if (opt.DefStn == NULL && ContactCount != 0) {
		if (!db_get_ts(LastContact, WEATHERPROTONAME, "ID", &dbv)) {
			_tcsncpy(opt.Default, dbv.ptszVal, _countof(opt.Default) - 1);
			db_free(&dbv);
		}
		opt.DefStn = LastContact;
		if (!db_get_ts(LastContact, WEATHERPROTONAME, "Nick", &dbv)) {
			mir_sntprintf(str, TranslateT("%s is now the default weather station"), dbv.ptszVal);
			db_free(&dbv);
			MessageBox(NULL, str, TranslateT("Weather Protocol"), MB_OK | MB_ICONINFORMATION);
		}
	}
	// save option in case of default station changed
	db_set_ts(NULL, WEATHERPROTONAME, "Default", opt.Default);
}