From 09d94267629233582f3d56fa4dbea69c95dfea3c Mon Sep 17 00:00:00 2001 From: Dioksin Date: Wed, 2 Apr 2014 14:18:49 +0000 Subject: Quotes plugin reworked accordingly to Miranda NG requirements git-svn-id: http://svn.miranda-ng.org/main/trunk@8826 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Quotes/src/Forex.cpp | 179 ++++++++++++++++++++---------- plugins/Quotes/src/IconLib.cpp | 1 + plugins/Quotes/src/IconLib.h | 1 + plugins/Quotes/src/QuotesProviderBase.cpp | 4 +- plugins/Quotes/src/resource.h | 4 +- plugins/Quotes/src/stdafx.h | 1 + plugins/Quotes/src/version.h | 2 +- 7 files changed, 131 insertions(+), 61 deletions(-) (limited to 'plugins/Quotes/src') diff --git a/plugins/Quotes/src/Forex.cpp b/plugins/Quotes/src/Forex.cpp index e148794ee1..c4ac039c8c 100644 --- a/plugins/Quotes/src/Forex.cpp +++ b/plugins/Quotes/src/Forex.cpp @@ -6,7 +6,8 @@ int hLangpack; HINSTANCE g_hInstance = NULL; HANDLE g_hEventWorkThreadStop; -int g_nStatus = ID_STATUS_OFFLINE; +//int g_nStatus = ID_STATUS_OFFLINE; +bool g_bAutoUpdate = true; HGENMENU g_hMenuEditSettings = NULL; HGENMENU g_hMenuOpenLogFile = NULL; #ifdef CHART_IMPLEMENT @@ -14,6 +15,8 @@ HGENMENU g_hMenuChart = NULL; #endif HGENMENU g_hMenuRefresh = NULL; +#define DB_STR_AUTO_UPDATE "AutoUpdate" + namespace { typedef std::vector THandles; @@ -21,6 +24,11 @@ namespace THandles g_ahServices; THandles g_ahThreads; std::vector g_ahMenus; + HGENMENU g_hEnableDisableMenu; + HANDLE g_hTBButton; + + LPSTR g_pszAutoUpdateCmd = "Quotes/Enable-Disable Auto Update"; + LPSTR g_pszCurrencyConverter = "Quotes/CurrencyConverter"; PLUGININFOEX Global_pluginInfo = { @@ -37,6 +45,66 @@ namespace {0xe882056d, 0xd1d, 0x4131, {0x9a, 0x98, 0x40, 0x4c, 0xba, 0xea, 0x6a, 0x9c}} }; + void UpdateMenu(bool bAutoUpdate) + { + CLISTMENUITEM mi = { sizeof(mi) }; + + if (bAutoUpdate) { // to enable auto-update + mi.pszName = LPGEN("Auto Update Enabled"); + mi.icolibItem = Quotes_GetIconHandle(IDI_ICON_MAIN); + //opt.AutoUpdate = 1; + } + else { // to disable auto-update + mi.pszName = LPGEN("Auto Update Disabled"); + mi.icolibItem = Quotes_GetIconHandle(IDI_ICON_DISABLED); + //opt.AutoUpdate = 0; + } + + mi.flags = CMIM_ICON | CMIM_NAME; + Menu_ModifyItem(g_hEnableDisableMenu, &mi); + CallService(MS_TTB_SETBUTTONSTATE, reinterpret_cast(g_hTBButton), !bAutoUpdate ? TTBST_PUSHED : TTBST_RELEASED); + } + + + INT_PTR QuoteProtoFunc_SetStatus(WPARAM wp,LPARAM /*lp*/) + { + if ((ID_STATUS_ONLINE == wp) || (ID_STATUS_OFFLINE == wp)) + { + bool bAutoUpdate = (ID_STATUS_ONLINE == wp); + bool bOldFlag = g_bAutoUpdate; + + if(bAutoUpdate != g_bAutoUpdate) + { + g_bAutoUpdate = bAutoUpdate; + db_set_b(NULL,QUOTES_MODULE_NAME,DB_STR_AUTO_UPDATE,g_bAutoUpdate); + if (bOldFlag && !g_bAutoUpdate) + { + BOOL b = ::SetEvent(g_hEventWorkThreadStop); + assert(b); + } + else if (g_bAutoUpdate && !bOldFlag) + { + BOOL b = ::ResetEvent(g_hEventWorkThreadStop); + assert(b && "Failed to reset event"); + + const CModuleInfo::TQuotesProvidersPtr& pProviders = CModuleInfo::GetQuoteProvidersPtr(); + const CQuotesProviders::TQuotesProviders& rapProviders = pProviders->GetProviders(); + for(CQuotesProviders::TQuotesProviders::const_iterator i = rapProviders.begin();i != rapProviders.end();++i) + { + const CQuotesProviders::TQuotesProviderPtr& pProvider = *i; + g_ahThreads.push_back( mir_forkthread(WorkingThread, pProvider.get())); + } + } + + UpdateMenu(g_bAutoUpdate); + //ProtoBroadcastAck(QUOTES_PROTOCOL_NAME,NULL,ACKTYPE_STATUS,ACKRESULT_SUCCESS,reinterpret_cast(nOldStatus),g_nStatus); + } + + } + + return 0; + } + INT_PTR QuotesMenu_RefreshAll(WPARAM wp,LPARAM lp) { const CQuotesProviders::TQuotesProviders& apProviders = CModuleInfo::GetQuoteProvidersPtr()->GetProviders(); @@ -44,6 +112,12 @@ namespace return 0; } + INT_PTR QuotesMenu_EnableDisable(WPARAM wp,LPARAM lp) + { + QuoteProtoFunc_SetStatus(g_bAutoUpdate ? ID_STATUS_OFFLINE : ID_STATUS_ONLINE,0L); + return 0; + } + void InitMenu() { CLISTMENUITEM mi = { sizeof(mi) }; @@ -53,22 +127,34 @@ namespace HGENMENU hMenuRoot = Menu_AddMainMenuItem(&mi); g_ahMenus.push_back(hMenuRoot); + mi.ptszName = LPGENT("Enable/Disable Auto Update"); + mi.flags = CMIF_TCHAR | CMIF_ROOTHANDLE; + mi.position = 10100001; + mi.icolibItem = Quotes_GetIconHandle(IDI_ICON_MAIN); + mi.pszService = g_pszAutoUpdateCmd; + mi.hParentMenu = hMenuRoot; + g_hEnableDisableMenu = Menu_AddMainMenuItem(&mi); + g_ahMenus.push_back(g_hEnableDisableMenu); + HANDLE h = CreateServiceFunction(mi.pszService, QuotesMenu_EnableDisable); + g_ahServices.push_back(h); + UpdateMenu(g_bAutoUpdate); + mi.ptszName = LPGENT("Refresh All Quotes\\Rates"); mi.flags = CMIF_TCHAR | CMIF_ROOTHANDLE; - //mi.position = 0x0FFFFFFF; + mi.position = 20100001; mi.icolibItem = Quotes_GetIconHandle(IDI_ICON_MAIN); mi.pszService = "Quotes/RefreshAll"; mi.hParentMenu = hMenuRoot; - HGENMENU hMenu = Menu_AddMainMenuItem(&mi); + auto hMenu = Menu_AddMainMenuItem(&mi); g_ahMenus.push_back(hMenu); - HANDLE h = CreateServiceFunction(mi.pszService, QuotesMenu_RefreshAll); + h = CreateServiceFunction(mi.pszService, QuotesMenu_RefreshAll); g_ahServices.push_back(h); mi.ptszName = LPGENT("Currency Converter..."); //mi.flags = CMIF_TCHAR|CMIF_ICONFROMICOLIB|CMIF_ROOTHANDLE; - //mi.position = 0x0FFFFFFF; + mi.position = 20100002; mi.icolibItem = Quotes_GetIconHandle(IDI_ICON_CURRENCY_CONVERTER); - mi.pszService = "Quotes/CurrencyConverter"; + mi.pszService = g_pszCurrencyConverter; hMenu = Menu_AddMainMenuItem(&mi); g_ahMenus.push_back(hMenu); h = CreateServiceFunction(mi.pszService, QuotesMenu_CurrencyConverter); @@ -79,6 +165,7 @@ namespace //mi.flags = CMIF_TCHAR|CMIF_ICONFROMICOLIB|CMIF_ROOTHANDLE; mi.icolibItem = Quotes_GetIconHandle(IDI_ICON_EXPORT); mi.pszService = "Quotes/ExportAll"; + mi.position = 20100003; hMenu = Menu_AddMainMenuItem(&mi); g_ahMenus.push_back(hMenu); h = CreateServiceFunction(mi.pszService, QuotesMenu_ExportAll); @@ -88,6 +175,7 @@ namespace //mi.flags = CMIF_TCHAR|CMIF_ICONFROMICOLIB|CMIF_ROOTHANDLE; mi.icolibItem = Quotes_GetIconHandle(IDI_ICON_IMPORT); mi.pszService = "Quotes/ImportAll"; + mi.position = 20100004; hMenu = Menu_AddMainMenuItem(&mi); g_ahMenus.push_back(hMenu); h = CreateServiceFunction(mi.pszService, QuotesMenu_ImportAll); @@ -169,6 +257,29 @@ namespace g_ahServices.push_back(h); } + int Quotes_OnToolbarLoaded(WPARAM wParam, LPARAM lParam) + { + TTBButton ttb = { sizeof(ttb) }; + ttb.name = LPGEN("Enable/Diable Quotes Auto Update"); + ttb.pszService = g_pszAutoUpdateCmd; + ttb.pszTooltipUp = LPGEN("Quotes Auto Update Enabled"); + ttb.pszTooltipDn = LPGEN("Quotes Auto Update Disabled"); + ttb.hIconHandleUp = Quotes_GetIconHandle(IDI_ICON_MAIN); + ttb.hIconHandleDn = Quotes_GetIconHandle(IDI_ICON_DISABLED); + ttb.dwFlags = ((g_bAutoUpdate) ? 0 : TTBBF_PUSHED) | TTBBF_ASPUSHBUTTON | TTBBF_VISIBLE; + g_hTBButton = TopToolbar_AddButton(&ttb); + + ttb.name = LPGEN("Currency Converter"); + ttb.pszService = g_pszCurrencyConverter; + ttb.pszTooltipUp = LPGEN("Currency Converter"); + ttb.pszTooltipDn = LPGEN("Currency Converter"); + ttb.hIconHandleUp = Quotes_GetIconHandle(IDI_ICON_CURRENCY_CONVERTER); + ttb.hIconHandleDn = Quotes_GetIconHandle(IDI_ICON_CURRENCY_CONVERTER); + ttb.dwFlags = TTBBF_VISIBLE; + TopToolbar_AddButton(&ttb); + + return 0; + } int QuotesEventFunc_OnModulesLoaded(WPARAM, LPARAM) { @@ -184,6 +295,9 @@ namespace h = HookEvent(ME_CLIST_DOUBLECLICKED,Quotes_OnContactDoubleClick); g_ahEvents.push_back(h); + h = HookEvent(ME_TTB_MODULELOADED, Quotes_OnToolbarLoaded); + g_ahEvents.push_back(h); + InitMenu(); return 0; @@ -205,7 +319,7 @@ namespace INT_PTR QuoteProtoFunc_GetStatus(WPARAM/* wp*/,LPARAM/* lp*/) { - return g_nStatus; + return g_bAutoUpdate ? ID_STATUS_ONLINE : ID_STATUS_OFFLINE; } void WaitForWorkingThreads() @@ -218,46 +332,10 @@ namespace } } - INT_PTR QuoteProtoFunc_SetStatus(WPARAM wp,LPARAM /*lp*/) - { - int nStatus = wp; - if ((ID_STATUS_ONLINE == nStatus) || (ID_STATUS_OFFLINE == nStatus)) - { - int nOldStatus = g_nStatus; - if(nStatus != g_nStatus) - { - g_nStatus = nStatus; - if ((ID_STATUS_ONLINE == nOldStatus) && (ID_STATUS_OFFLINE == g_nStatus)) - { - BOOL b = ::SetEvent(g_hEventWorkThreadStop); - assert(b); - } - else if ((ID_STATUS_ONLINE == g_nStatus) && (ID_STATUS_OFFLINE == nOldStatus)) - { - BOOL b = ::ResetEvent(g_hEventWorkThreadStop); - assert(b && "Failed to reset event"); - - const CModuleInfo::TQuotesProvidersPtr& pProviders = CModuleInfo::GetQuoteProvidersPtr(); - const CQuotesProviders::TQuotesProviders& rapProviders = pProviders->GetProviders(); - for(CQuotesProviders::TQuotesProviders::const_iterator i = rapProviders.begin();i != rapProviders.end();++i) - { - const CQuotesProviders::TQuotesProviderPtr& pProvider = *i; - g_ahThreads.push_back( mir_forkthread(WorkingThread, pProvider.get())); - } - } - - ProtoBroadcastAck(QUOTES_PROTOCOL_NAME,NULL,ACKTYPE_STATUS,ACKRESULT_SUCCESS,reinterpret_cast(nOldStatus),g_nStatus); - } - - } - - return 0; - } int QuotesEventFunc_PreShutdown(WPARAM wParam, LPARAM lParam) { QuoteProtoFunc_SetStatus(ID_STATUS_OFFLINE,0); - //WindowList_Broadcast(g_hWindowListEditSettings,WM_CLOSE,0,0); CModuleInfo::GetInstance().OnMirandaShutdown(); return 0; } @@ -338,19 +416,6 @@ namespace return CallService(MS_CLIST_REMOVECONTACTMENUITEM,reinterpret_cast(h),0); } -// PROTO_INTERFACE* protoInit(const char* pszProtoName, const TCHAR* tszUserName) -// { -// CAimProto *ppro = new CAimProto(pszProtoName, tszUserName); -// g_Instances.insert(ppro); -// return ppro; -// } -// -// int protoUninit(PROTO_INTERFACE* ppro) -// { -// g_Instances.remove((CAimProto*)ppro); -// return 0; -// } - } BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) @@ -368,7 +433,6 @@ extern "C" int __declspec(dllexport) Load(void) { - mir_getLP(&Global_pluginInfo); if(false == CModuleInfo::Verify()) @@ -408,6 +472,7 @@ extern "C" h = CreateServiceFunction(MS_QUOTES_IMPORT, Quotes_Import); g_ahServices.push_back(h); + g_bAutoUpdate = 1 == db_get_b(NULL,QUOTES_MODULE_NAME,DB_STR_AUTO_UPDATE,1); return 0; } diff --git a/plugins/Quotes/src/IconLib.cpp b/plugins/Quotes/src/IconLib.cpp index 2ea239fb6c..bc328f2f82 100644 --- a/plugins/Quotes/src/IconLib.cpp +++ b/plugins/Quotes/src/IconLib.cpp @@ -3,6 +3,7 @@ static IconItem iconList[] = { { LPGEN("Protocol icon"), ICON_STR_MAIN, IDI_ICON_MAIN }, + { LPGEN("Auto Update Disabled"), ICON_STR_AUTO_UPDATE_DISABLED, IDI_ICON_DISABLED }, { LPGEN("Quote/Rate up"), ICON_STR_QUOTE_UP, IDI_ICON_UP }, { LPGEN("Quote/Rate down"), ICON_STR_QUOTE_DOWN, IDI_ICON_DOWN }, { LPGEN("Quote/Rate not changed"), ICON_STR_QUOTE_NOT_CHANGED, IDI_ICON_NOTCHANGED }, diff --git a/plugins/Quotes/src/IconLib.h b/plugins/Quotes/src/IconLib.h index 29b0326622..a1ea6ea078 100644 --- a/plugins/Quotes/src/IconLib.h +++ b/plugins/Quotes/src/IconLib.h @@ -2,6 +2,7 @@ #define __8821d334_afac_439e_9a81_76318e1ac4ef_IconLib_h__ #define ICON_STR_MAIN "main" +#define ICON_STR_AUTO_UPDATE_DISABLED "auto_update_disabled" #define ICON_STR_QUOTE_UP "quote_up" #define ICON_STR_QUOTE_DOWN "quote_down" #define ICON_STR_QUOTE_NOT_CHANGED "quote_not_changed" diff --git a/plugins/Quotes/src/QuotesProviderBase.cpp b/plugins/Quotes/src/QuotesProviderBase.cpp index 92b5099f70..3751454b58 100644 --- a/plugins/Quotes/src/QuotesProviderBase.cpp +++ b/plugins/Quotes/src/QuotesProviderBase.cpp @@ -1,6 +1,6 @@ #include "StdAfx.h" -extern int g_nStatus; +extern bool g_bAutoUpdate; extern HANDLE g_hEventWorkThreadStop; @@ -235,7 +235,7 @@ const tstring& CQuotesProviderBase::GetURL()const bool CQuotesProviderBase::IsOnline() { - return ID_STATUS_ONLINE == g_nStatus; + return g_bAutoUpdate; } void CQuotesProviderBase::AddContact(MCONTACT hContact) diff --git a/plugins/Quotes/src/resource.h b/plugins/Quotes/src/resource.h index 50ee0a637b..883d45b747 100644 --- a/plugins/Quotes/src/resource.h +++ b/plugins/Quotes/src/resource.h @@ -1,6 +1,6 @@ //{{NO_DEPENDENCIES}} // Microsoft Visual C++ generated include file. -// Used by Forex.rc +// Used by C:\Code\My code\Miranda NG\plugins\Quotes\res\Forex.rc // #define IDD_DIALOG_ECONOMIC_RATES 101 #define IDI_ICON_MAIN 102 @@ -24,6 +24,8 @@ #define IDD_PROVIDER_ADV_SETTINGS 120 #define IDI_ICON_SWAP 121 #define IDD_DIALOG_POPUP 121 +#define IDI_ICON_MAIN1 122 +#define IDI_ICON_DISABLED 122 #define IDD_DIALOG_VARIABLE_LIST 123 #define IDC_TREE_ECONOMIC_RATES 1001 #define IDC_EDIT_REFRESH_RATE 1002 diff --git a/plugins/Quotes/src/stdafx.h b/plugins/Quotes/src/stdafx.h index 57ef426d99..59b2a17047 100644 --- a/plugins/Quotes/src/stdafx.h +++ b/plugins/Quotes/src/stdafx.h @@ -36,6 +36,7 @@ #include #include +#include #include #include diff --git a/plugins/Quotes/src/version.h b/plugins/Quotes/src/version.h index 389689b1fd..4ec361f96a 100644 --- a/plugins/Quotes/src/version.h +++ b/plugins/Quotes/src/version.h @@ -1,6 +1,6 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 0 -#define __RELEASE_NUM 24 +#define __RELEASE_NUM 25 #define __BUILD_NUM 0 #include -- cgit v1.2.3