diff options
author | George Hazan <ghazan@miranda.im> | 2017-07-30 17:30:39 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-07-30 17:30:39 +0300 |
commit | 6fad3235de6bec045fec19a7265e19e880ac84e2 (patch) | |
tree | ea375f721c2cc7e586142ccd0298b096a7a5b31f /plugins/ListeningTo | |
parent | 4aab3b6bc3d66ade09b25649d389b8aef358bfbd (diff) |
Hotkeys: code cleaning
Diffstat (limited to 'plugins/ListeningTo')
-rw-r--r-- | plugins/ListeningTo/src/listeningto.cpp | 143 |
1 files changed, 71 insertions, 72 deletions
diff --git a/plugins/ListeningTo/src/listeningto.cpp b/plugins/ListeningTo/src/listeningto.cpp index ebda2b1ef2..b8daa9b2f1 100644 --- a/plugins/ListeningTo/src/listeningto.cpp +++ b/plugins/ListeningTo/src/listeningto.cpp @@ -293,23 +293,22 @@ int ModulesLoaded(WPARAM, LPARAM) }
// Hotkeys support
- HOTKEYDESC hkd = { 0 };
- hkd.cbSize = sizeof(hkd);
- hkd.pszSection = LPGEN("Listening to");
+ HOTKEYDESC hkd = {};
+ hkd.szSection.a = LPGEN("Listening to");
hkd.pszService = MS_LISTENINGTO_HOTKEYS_ENABLE;
hkd.pszName = "ListeningTo/EnableAll";
- hkd.pszDescription = LPGEN("Send to all protocols");
+ hkd.szDescription.a = LPGEN("Send to all protocols");
Hotkey_Register(&hkd);
hkd.pszService = MS_LISTENINGTO_HOTKEYS_DISABLE;
hkd.pszName = "ListeningTo/DisableAll";
- hkd.pszDescription = LPGEN("Don't send to any protocols");
+ hkd.szDescription.a = LPGEN("Don't send to any protocols");
Hotkey_Register(&hkd);
hkd.pszService = MS_LISTENINGTO_HOTKEYS_TOGGLE;
hkd.pszName = "ListeningTo/ToggleAll";
- hkd.pszDescription = LPGEN("Toggle send to all protocols");
+ hkd.szDescription.a = LPGEN("Toggle send to all protocols");
Hotkey_Register(&hkd);
//
@@ -412,72 +411,72 @@ ProtocolInfo* GetProtoInfo(char *proto) return NULL;
}
-static void ReplaceVars(Buffer<wchar_t> *buffer, MCONTACT hContact, wchar_t **variables, int numVariables) -{ - if (buffer->len < 3) - return; - - if (numVariables < 0) - return; - - for (size_t i = buffer->len - 1; i > 0; i--) { - if (buffer->str[i] == '%') { - // Find previous - size_t j; - for (j = i - 1; j > 0 && ((buffer->str[j] >= 'a' && buffer->str[j] <= 'z') - || (buffer->str[j] >= 'A' && buffer->str[j] <= 'Z') - || buffer->str[j] == '-' - || buffer->str[j] == '_'); j--); - - if (buffer->str[j] == '%') { - size_t foundLen = i - j + 1; - if (foundLen == 9 && wcsncmp(&buffer->str[j], L"%contact%", 9) == 0) { - buffer->replace(j, i + 1, pcli->pfnGetContactDisplayName(hContact, 0)); - } - else if (foundLen == 6 && wcsncmp(&buffer->str[j], L"%date%", 6) == 0) { - wchar_t tmp[128]; - TimeZone_ToStringT(time(NULL), L"d s", tmp, _countof(tmp)); - buffer->replace(j, i + 1, tmp); - } - else { - for (int k = 0; k < numVariables; k += 2) { - size_t len = mir_wstrlen(variables[k]); - if (foundLen == len + 2 && wcsncmp(&buffer->str[j] + 1, variables[k], len) == 0) { - buffer->replace(j, i + 1, variables[k + 1]); - break; - } - } - } - } - - i = j; - if (i == 0) - break; - } - else if (buffer->str[i] == '\\' && i + 1 <= buffer->len - 1 && buffer->str[i + 1] == 'n') { - buffer->str[i] = '\r'; - buffer->str[i + 1] = '\n'; - } - } -} -
-void ReplaceTemplate(Buffer<wchar_t> *out, MCONTACT hContact, wchar_t *templ, wchar_t **vars, int numVars) -{ - - if (ServiceExists(MS_VARS_FORMATSTRING)) { - wchar_t *tmp = variables_parse_ex(templ, NULL, hContact, vars, numVars); - if (tmp != NULL) { - out->append(tmp); - mir_free(tmp); - out->pack(); - return; - } - } - - out->append(templ); - ReplaceVars(out, hContact, vars, numVars); - out->pack(); -} +static void ReplaceVars(Buffer<wchar_t> *buffer, MCONTACT hContact, wchar_t **variables, int numVariables)
+{
+ if (buffer->len < 3)
+ return;
+
+ if (numVariables < 0)
+ return;
+
+ for (size_t i = buffer->len - 1; i > 0; i--) {
+ if (buffer->str[i] == '%') {
+ // Find previous
+ size_t j;
+ for (j = i - 1; j > 0 && ((buffer->str[j] >= 'a' && buffer->str[j] <= 'z')
+ || (buffer->str[j] >= 'A' && buffer->str[j] <= 'Z')
+ || buffer->str[j] == '-'
+ || buffer->str[j] == '_'); j--);
+
+ if (buffer->str[j] == '%') {
+ size_t foundLen = i - j + 1;
+ if (foundLen == 9 && wcsncmp(&buffer->str[j], L"%contact%", 9) == 0) {
+ buffer->replace(j, i + 1, pcli->pfnGetContactDisplayName(hContact, 0));
+ }
+ else if (foundLen == 6 && wcsncmp(&buffer->str[j], L"%date%", 6) == 0) {
+ wchar_t tmp[128];
+ TimeZone_ToStringT(time(NULL), L"d s", tmp, _countof(tmp));
+ buffer->replace(j, i + 1, tmp);
+ }
+ else {
+ for (int k = 0; k < numVariables; k += 2) {
+ size_t len = mir_wstrlen(variables[k]);
+ if (foundLen == len + 2 && wcsncmp(&buffer->str[j] + 1, variables[k], len) == 0) {
+ buffer->replace(j, i + 1, variables[k + 1]);
+ break;
+ }
+ }
+ }
+ }
+
+ i = j;
+ if (i == 0)
+ break;
+ }
+ else if (buffer->str[i] == '\\' && i + 1 <= buffer->len - 1 && buffer->str[i + 1] == 'n') {
+ buffer->str[i] = '\r';
+ buffer->str[i + 1] = '\n';
+ }
+ }
+}
+
+void ReplaceTemplate(Buffer<wchar_t> *out, MCONTACT hContact, wchar_t *templ, wchar_t **vars, int numVars)
+{
+
+ if (ServiceExists(MS_VARS_FORMATSTRING)) {
+ wchar_t *tmp = variables_parse_ex(templ, NULL, hContact, vars, numVars);
+ if (tmp != NULL) {
+ out->append(tmp);
+ mir_free(tmp);
+ out->pack();
+ return;
+ }
+ }
+
+ out->append(templ);
+ ReplaceVars(out, hContact, vars, numVars);
+ out->pack();
+}
void SetListeningInfo(char *proto, LISTENINGTOINFO *lti = NULL)
{
|