From 068a19fb0f4c2f8efa79977a3e3c8dd239ca8a33 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 20 Mar 2020 17:37:57 +0300 Subject: IEView: - SRMM button added to insert "Code" instruction into the edit window; - ieviewModuleName renamed as it should be: MODULENAME; - code cleaning & reordering; - version bump. --- plugins/IEView/res/code.ico | Bin 0 -> 1150 bytes plugins/IEView/res/ieview.rc | 3 + plugins/IEView/src/Options.cpp | 247 ++++++++++++++++++------------------- plugins/IEView/src/Options.h | 2 + plugins/IEView/src/Template.h | 25 ++-- plugins/IEView/src/Utils.cpp | 2 +- plugins/IEView/src/Utils.h | 31 ++--- plugins/IEView/src/ieview_main.cpp | 31 ++++- plugins/IEView/src/resource.h | 1 + plugins/IEView/src/stdafx.h | 23 ++-- plugins/IEView/src/version.h | 2 +- 11 files changed, 194 insertions(+), 173 deletions(-) create mode 100644 plugins/IEView/res/code.ico (limited to 'plugins') diff --git a/plugins/IEView/res/code.ico b/plugins/IEView/res/code.ico new file mode 100644 index 0000000000..f128f86651 Binary files /dev/null and b/plugins/IEView/res/code.ico differ diff --git a/plugins/IEView/res/ieview.rc b/plugins/IEView/res/ieview.rc index a92ce0bee4..55499349bf 100644 --- a/plugins/IEView/res/ieview.rc +++ b/plugins/IEView/res/ieview.rc @@ -48,6 +48,9 @@ END // Icon with lowest ID value placed first to ensure application icon // remains consistent on all systems. + +IDI_CODE ICON "code.ico" + IDI_RTL_ON ICON "rtl_on.ico" IDI_RTL_OFF ICON "rtl_off.ico" diff --git a/plugins/IEView/src/Options.cpp b/plugins/IEView/src/Options.cpp index e5bcbb89f8..26f2d1a7d0 100644 --- a/plugins/IEView/src/Options.cpp +++ b/plugins/IEView/src/Options.cpp @@ -962,6 +962,119 @@ ProtocolSettings::~ProtocolSettings() ///////////////////////////////////////////////////////////////////////////////////////// +void ProtocolSettings::readFromDb() +{ + /* SRMM settings */ + const char *szProto = protocolName; + if (szProto == nullptr) + szProto = "_default_"; + + char dbsName[256]; + mir_snprintf(dbsName, "%s.%s", szProto, DBS_SRMM_ENABLE); + setSRMMEnable(protocolName == nullptr ? true : 0 != g_plugin.getByte(dbsName, FALSE)); + + mir_snprintf(dbsName, "%s.%s", szProto, DBS_SRMM_MODE); + setSRMMMode(g_plugin.getByte(dbsName, FALSE)); + + mir_snprintf(dbsName, "%s.%s", szProto, DBS_SRMM_FLAGS); + setSRMMFlags(g_plugin.getDword(dbsName, 16128)); + + DBVARIANT dbv; + char tmpPath[MAX_PATH]; + mir_snprintf(dbsName, "%s.%s", szProto, DBS_SRMM_BACKGROUND); + if (!g_plugin.getString(dbsName, &dbv)) { + PathToAbsolute(dbv.pszVal, tmpPath); + setSRMMBackgroundFilename(tmpPath); + db_free(&dbv); + } + + mir_snprintf(dbsName, "%s.%s", szProto, DBS_SRMM_CSS); + if (!g_plugin.getString(dbsName, &dbv)) { + PathToAbsolute(dbv.pszVal, tmpPath); + setSRMMCssFilename(tmpPath); + db_free(&dbv); + } + + mir_snprintf(dbsName, "%s.%s", szProto, DBS_SRMM_TEMPLATE); + if (!g_plugin.getString(dbsName, &dbv)) { + PathToAbsolute(dbv.pszVal, tmpPath); + setSRMMTemplateFilename(tmpPath); + db_free(&dbv); + } + + /* Group chat settings */ + mir_snprintf(dbsName, "%s.%s", szProto, DBS_CHAT_ENABLE); + setChatEnable(protocolName == nullptr ? true : 0 != g_plugin.getByte(dbsName, FALSE)); + + mir_snprintf(dbsName, "%s.%s", szProto, DBS_CHAT_MODE); + setChatMode(g_plugin.getByte(dbsName, FALSE)); + + mir_snprintf(dbsName, "%s.%s", szProto, DBS_CHAT_FLAGS); + setChatFlags(g_plugin.getDword(dbsName, 16128)); + + mir_snprintf(dbsName, "%s.%s", szProto, DBS_CHAT_BACKGROUND); + if (!g_plugin.getString(dbsName, &dbv)) { + if (strncmp(tmpPath, "http://", 7)) + PathToAbsolute(dbv.pszVal, tmpPath); + + setChatBackgroundFilename(tmpPath); + db_free(&dbv); + } + + mir_snprintf(dbsName, "%s.%s", szProto, DBS_CHAT_CSS); + if (!g_plugin.getString(dbsName, &dbv)) { + if (strncmp(tmpPath, "http://", 7)) + PathToAbsolute(dbv.pszVal, tmpPath); + + setChatCssFilename(tmpPath); + db_free(&dbv); + } + + mir_snprintf(dbsName, "%s.%s", szProto, DBS_CHAT_TEMPLATE); + if (!g_plugin.getString(dbsName, &dbv)) { + PathToAbsolute(dbv.pszVal, tmpPath); + setChatTemplateFilename(tmpPath); + db_free(&dbv); + } + + /* History settings */ + mir_snprintf(dbsName, "%s.%s", szProto, DBS_HISTORY_ENABLE); + setHistoryEnable(protocolName == nullptr ? true : 0 != g_plugin.getByte(dbsName, FALSE)); + + mir_snprintf(dbsName, "%s.%s", szProto, DBS_HISTORY_MODE); + setHistoryMode(g_plugin.getByte(dbsName, FALSE)); + + mir_snprintf(dbsName, "%s.%s", szProto, DBS_HISTORY_FLAGS); + setHistoryFlags(g_plugin.getDword(dbsName, 16128)); + + mir_snprintf(dbsName, "%s.%s", szProto, DBS_HISTORY_BACKGROUND); + if (!g_plugin.getString(dbsName, &dbv)) { + if (strncmp(tmpPath, "http://", 7)) + PathToAbsolute(dbv.pszVal, tmpPath); + + setHistoryBackgroundFilename(tmpPath); + db_free(&dbv); + } + + mir_snprintf(dbsName, "%s.%s", szProto, DBS_HISTORY_CSS); + if (!g_plugin.getString(dbsName, &dbv)) { + if (strncmp(tmpPath, "http://", 7)) + PathToAbsolute(dbv.pszVal, tmpPath); + + setHistoryCssFilename(tmpPath); + db_free(&dbv); + } + + mir_snprintf(dbsName, "%s.%s", szProto, DBS_HISTORY_TEMPLATE); + if (!g_plugin.getString(dbsName, &dbv)) { + PathToAbsolute(dbv.pszVal, tmpPath); + setHistoryTemplateFilename(tmpPath); + db_free(&dbv); + } +} + +///////////////////////////////////////////////////////////////////////////////////////// + void ProtocolSettings::setSRMMTemplateFilename(const char *filename) { srmmTemplateFilename = filename; @@ -986,136 +1099,22 @@ void Options::init() { if (isInited) return; isInited = true; - DBVARIANT dbv; generalFlags = g_plugin.getDword(DBS_BASICFLAGS, 13); - /* TODO: move to buildProtocolList method */ - int protoCount; - PROTOACCOUNT **pProtos; - Proto_EnumAccounts(&protoCount, &pProtos); - - for (int i = 0; i < protoCount + 1; i++) { - ProtocolSettings *proto; - char tmpPath[MAX_PATH]; - char dbsName[256]; - if (i == 0) { - proto = new ProtocolSettings(nullptr); - proto->setSRMMEnable(true); - } - else if (mir_strcmp(pProtos[i - 1]->szModuleName, META_PROTO)) { - if ((CallProtoService(pProtos[i - 1]->szModuleName, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_IM) == 0) - continue; - - proto = new ProtocolSettings(pProtos[i - 1]->szModuleName); - } - else continue; - - /* SRMM settings */ - const char *szProto = proto->getProtocolName(); - if (szProto == nullptr) - szProto = "_default_"; - - mir_snprintf(dbsName, "%s.%s", szProto, DBS_SRMM_ENABLE); - proto->setSRMMEnable(i == 0 ? true : 0 != g_plugin.getByte(dbsName, FALSE)); - - mir_snprintf(dbsName, "%s.%s", szProto, DBS_SRMM_MODE); - proto->setSRMMMode(g_plugin.getByte(dbsName, FALSE)); - - mir_snprintf(dbsName, "%s.%s", szProto, DBS_SRMM_FLAGS); - proto->setSRMMFlags(g_plugin.getDword(dbsName, 16128)); - - mir_snprintf(dbsName, "%s.%s", szProto, DBS_SRMM_BACKGROUND); - if (!g_plugin.getString(dbsName, &dbv)) { - PathToAbsolute(dbv.pszVal, tmpPath); - proto->setSRMMBackgroundFilename(tmpPath); - db_free(&dbv); - } - - mir_snprintf(dbsName, "%s.%s", szProto, DBS_SRMM_CSS); - if (!g_plugin.getString(dbsName, &dbv)) { - PathToAbsolute(dbv.pszVal, tmpPath); - proto->setSRMMCssFilename(tmpPath); - db_free(&dbv); - } - - mir_snprintf(dbsName, "%s.%s", szProto, DBS_SRMM_TEMPLATE); - if (!g_plugin.getString(dbsName, &dbv)) { - PathToAbsolute(dbv.pszVal, tmpPath); - proto->setSRMMTemplateFilename(tmpPath); - db_free(&dbv); - } - - /* Group chat settings */ - mir_snprintf(dbsName, "%s.%s", szProto, DBS_CHAT_ENABLE); - proto->setChatEnable(i == 0 ? true : 0 != g_plugin.getByte(dbsName, FALSE)); - - mir_snprintf(dbsName, "%s.%s", szProto, DBS_CHAT_MODE); - proto->setChatMode(g_plugin.getByte(dbsName, FALSE)); - - mir_snprintf(dbsName, "%s.%s", szProto, DBS_CHAT_FLAGS); - proto->setChatFlags(g_plugin.getDword(dbsName, 16128)); - - mir_snprintf(dbsName, "%s.%s", szProto, DBS_CHAT_BACKGROUND); - if (!g_plugin.getString(dbsName, &dbv)) { - if (strncmp(tmpPath, "http://", 7)) - PathToAbsolute(dbv.pszVal, tmpPath); + auto *proto = new ProtocolSettings(nullptr); + proto->readFromDb(); + arProtos.insert(proto); - proto->setChatBackgroundFilename(tmpPath); - db_free(&dbv); - } - - mir_snprintf(dbsName, "%s.%s", szProto, DBS_CHAT_CSS); - if (!g_plugin.getString(dbsName, &dbv)) { - if (strncmp(tmpPath, "http://", 7)) - PathToAbsolute(dbv.pszVal, tmpPath); - - proto->setChatCssFilename(tmpPath); - db_free(&dbv); - } - - mir_snprintf(dbsName, "%s.%s", szProto, DBS_CHAT_TEMPLATE); - if (!g_plugin.getString(dbsName, &dbv)) { - PathToAbsolute(dbv.pszVal, tmpPath); - proto->setChatTemplateFilename(tmpPath); - db_free(&dbv); - } + for (auto &it : Accounts()) { - /* History settings */ - mir_snprintf(dbsName, "%s.%s", szProto, DBS_HISTORY_ENABLE); - proto->setHistoryEnable(i == 0 ? true : 0 != g_plugin.getByte(dbsName, FALSE)); - - mir_snprintf(dbsName, "%s.%s", szProto, DBS_HISTORY_MODE); - proto->setHistoryMode(g_plugin.getByte(dbsName, FALSE)); - - mir_snprintf(dbsName, "%s.%s", szProto, DBS_HISTORY_FLAGS); - proto->setHistoryFlags(g_plugin.getDword(dbsName, 16128)); - - mir_snprintf(dbsName, "%s.%s", szProto, DBS_HISTORY_BACKGROUND); - if (!g_plugin.getString(dbsName, &dbv)) { - if (strncmp(tmpPath, "http://", 7)) - PathToAbsolute(dbv.pszVal, tmpPath); - - proto->setHistoryBackgroundFilename(tmpPath); - db_free(&dbv); - } - - mir_snprintf(dbsName, "%s.%s", szProto, DBS_HISTORY_CSS); - if (!g_plugin.getString(dbsName, &dbv)) { - if (strncmp(tmpPath, "http://", 7)) - PathToAbsolute(dbv.pszVal, tmpPath); - - proto->setHistoryCssFilename(tmpPath); - db_free(&dbv); - } - - mir_snprintf(dbsName, "%s.%s", szProto, DBS_HISTORY_TEMPLATE); - if (!g_plugin.getString(dbsName, &dbv)) { - PathToAbsolute(dbv.pszVal, tmpPath); - proto->setHistoryTemplateFilename(tmpPath); - db_free(&dbv); - } + if (!mir_strcmp(it->szModuleName, META_PROTO)) + continue; + if ((CallProtoService(it->szModuleName, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_IM) == 0) + continue; + proto = new ProtocolSettings(it->szModuleName); + proto->readFromDb(); arProtos.insert(proto); } diff --git a/plugins/IEView/src/Options.h b/plugins/IEView/src/Options.h index fb5a534453..c0a565043c 100644 --- a/plugins/IEView/src/Options.h +++ b/plugins/IEView/src/Options.h @@ -77,6 +77,8 @@ public: ProtocolSettings(const char *protocolName); ~ProtocolSettings(); + void readFromDb(); + __forceinline const char* getProtocolName() { return protocolName; } __forceinline void setSRMMEnable(bool enable) { this->srmmEnable = enable; } diff --git a/plugins/IEView/src/Template.h b/plugins/IEView/src/Template.h index 87117c0a45..a42c4c92af 100644 --- a/plugins/IEView/src/Template.h +++ b/plugins/IEView/src/Template.h @@ -18,29 +18,26 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -class TemplateMap; -class Template; + #ifndef TEMPLATE_INCLUDED #define TEMPLATE_INCLUDED -#include "stdafx.h" - -class TokenDef { -public: +struct TokenDef +{ const char *tokenString; - int token; - int tokenLen; - int escape; + int token, tokenLen, escape; + TokenDef(const char *tokenString); TokenDef(const char *tokenString, int token, int escape); }; -class Token { -private: +class Token +{ int escape; int type; char *text; Token *next; + public: enum TOKENS { END = 0, @@ -65,6 +62,7 @@ public: NICKOUT, FILEDESC, }; + Token(int, const char *, int); ~Token(); int getType(); @@ -91,10 +89,10 @@ protected: public: ~Template(); + __forceinline Token *getTokens() const { return m_tokens; } __forceinline Template* getNext() { return m_next; } __forceinline const char* getText() const { return m_text; } __forceinline const char* getName() const { return m_name; } - __forceinline Token* getTokens() const { return m_tokens; } }; class TemplateMap @@ -111,8 +109,8 @@ class TemplateMap void addTemplate(const char *name, const char *text); void setFilename(const char *filename); void clear(); + static TemplateMap* add(const char *id, const char *filename); - static void appendText(char **str, int *sizeAlloced, const char *fmt, ...); static TemplateMap* loadTemplateFile(const char *proto, const char *filename, bool onlyInfo); public: @@ -129,5 +127,4 @@ public: __forceinline bool isRTL() const { return m_rtl; } }; - #endif diff --git a/plugins/IEView/src/Utils.cpp b/plugins/IEView/src/Utils.cpp index f195c9638e..50da2b3a8b 100644 --- a/plugins/IEView/src/Utils.cpp +++ b/plugins/IEView/src/Utils.cpp @@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" -wchar_t Utils::base_dir[MAX_PATH]; +static wchar_t base_dir[MAX_PATH]; const wchar_t *Utils::getBaseDir() { diff --git a/plugins/IEView/src/Utils.h b/plugins/IEView/src/Utils.h index a5d9400244..031e400bf4 100644 --- a/plugins/IEView/src/Utils.h +++ b/plugins/IEView/src/Utils.h @@ -18,30 +18,21 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -class Utils; #ifndef UTILS_INCLUDED #define UTILS_INCLUDED -#include "stdafx.h" - -class Utils { -private: - static unsigned hookNum; - static unsigned serviceNum; - static HANDLE* hHooks; - static HANDLE* hServices; - static wchar_t base_dir[MAX_PATH]; -public: - static const wchar_t *getBaseDir(); - static wchar_t* toAbsolute(wchar_t* relative); - static void appendIcon(CMStringA &str, const char *iconFile); - static void convertPath(char *path); - static void convertPath(wchar_t *path); - static char *escapeString(const char *a); - static int detectURL(const wchar_t *text); - static bool DbEventIsForMsgWindow(DBEVENTINFO *dbei); - static bool DbEventIsForHistory(DBEVENTINFO *dbei); +namespace Utils +{ + const wchar_t *getBaseDir(); + wchar_t* toAbsolute(wchar_t* relative); + void appendIcon(CMStringA &str, const char *iconFile); + void convertPath(char *path); + void convertPath(wchar_t *path); + char *escapeString(const char *a); + int detectURL(const wchar_t *text); + bool DbEventIsForMsgWindow(DBEVENTINFO *dbei); + bool DbEventIsForHistory(DBEVENTINFO *dbei); }; #endif diff --git a/plugins/IEView/src/ieview_main.cpp b/plugins/IEView/src/ieview_main.cpp index e8d59998bc..09042a5bca 100644 --- a/plugins/IEView/src/ieview_main.cpp +++ b/plugins/IEView/src/ieview_main.cpp @@ -25,6 +25,7 @@ CMPlugin g_plugin; IconItem iconList[] = { + { LPGEN("Code"), "CODE", IDI_CODE }, { LPGEN("RTL On"), "RTL_ON", IDI_RTL_ON }, { LPGEN("RTL Off"), "RTL_OFF", IDI_RTL_OFF }, { LPGEN("Group On"), "GROUP_ON", IDI_GROUP_ON }, @@ -47,13 +48,39 @@ PLUGININFOEX pluginInfoEx = { }; CMPlugin::CMPlugin() : - PLUGIN(ieviewModuleName, pluginInfoEx) + PLUGIN(MODULENAME, pluginInfoEx) {} ///////////////////////////////////////////////////////////////////////////////////////// +static int CustomButtonPressed(WPARAM, LPARAM lParam) +{ + CustomButtonClickData *cbcd = (CustomButtonClickData *)lParam; + if (mir_strcmp(cbcd->pszModule, MODULENAME)) + return 0; + + if (cbcd->dwButtonId != 1) + return 1; + + HWND hEdit = GetDlgItem(cbcd->hwndFrom, IDC_SRMM_MESSAGE); + SendMessage(hEdit, EM_REPLACESEL, TRUE, (LPARAM)L"[code][/code]"); + return 0; +} + static int ModulesLoaded(WPARAM, LPARAM) { + BBButton bbd = {}; + bbd.pszModuleName = MODULENAME; + bbd.dwButtonID = 1; + bbd.bbbFlags = BBBF_ISCHATBUTTON | BBBF_ISIMBUTTON; + bbd.dwDefPos = 40; + bbd.hIcon = g_plugin.getIconHandle(IDI_CODE); + bbd.pwszText = L"[Code]"; + bbd.pwszTooltip = LPGENW("Format text as code"); + Srmm_AddButton(&bbd, &g_plugin); + + HookEvent(ME_MSG_BUTTONPRESSED, CustomButtonPressed); + Options::init(); return 0; } @@ -77,7 +104,7 @@ int CMPlugin::Load() CreateServiceFunction(MS_IEVIEW_NAVIGATE, HandleIENavigate); CreateServiceFunction("IEView/ReloadOptions", ReloadOptions); hHookOptionsChanged = CreateHookableEvent(ME_IEVIEW_OPTIONSCHANGED); - g_plugin.registerIcon("IEView", iconList, ieviewModuleName); + g_plugin.registerIcon("IEView", iconList, MODULENAME); return 0; } diff --git a/plugins/IEView/src/resource.h b/plugins/IEView/src/resource.h index f3c6a430b6..10a782b67e 100644 --- a/plugins/IEView/src/resource.h +++ b/plugins/IEView/src/resource.h @@ -9,6 +9,7 @@ #define IDI_RTL_OFF 101 #define IDI_GROUP_ON 102 #define IDI_GROUP_OFF 103 +#define IDI_CODE 104 #define IDD_SRMM_OPTIONS 153 #define IDD_GENERAL_OPTIONS 155 #define IDR_CONTEXTMENU 200 diff --git a/plugins/IEView/src/stdafx.h b/plugins/IEView/src/stdafx.h index a91545c28f..40881602f2 100644 --- a/plugins/IEView/src/stdafx.h +++ b/plugins/IEView/src/stdafx.h @@ -37,23 +37,24 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include +#include #include #include -#include -#include -#include -#include -#include #include -#include -#include +#include #include +#include +#include +#include +#include #include +#include +#include +#include +#include #include #include -#include -#include -#include +#include #include "IEView.h" #include "Utils.h" @@ -70,7 +71,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "TextToken.h" #include "external_funcs.h" -#define ieviewModuleName "IEVIEW" +#define MODULENAME "IEVIEW" struct CMPlugin : public PLUGIN { diff --git a/plugins/IEView/src/version.h b/plugins/IEView/src/version.h index a50cad8dad..5f706e58ca 100644 --- a/plugins/IEView/src/version.h +++ b/plugins/IEView/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 1 #define __MINOR_VERSION 6 #define __RELEASE_NUM 0 -#define __BUILD_NUM 2 +#define __BUILD_NUM 3 #include -- cgit v1.2.3