From 5552d1c8922afbcf4d8b60eea6cda27de6b6d08d Mon Sep 17 00:00:00 2001 From: slotwin Date: Sat, 31 May 2014 14:44:46 +0000 Subject: MyDetails: code cleanup git-svn-id: http://svn.miranda-ng.org/main/trunk@9378 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MyDetails/src/data.cpp | 92 ++++++++++++++++++++-------------------- plugins/MyDetails/src/data.h | 14 +++--- plugins/MyDetails/src/frame.cpp | 45 ++++++++------------ plugins/MyDetails/src/frame.h | 8 ++-- plugins/MyDetails/src/stdafx.cpp | 2 +- 5 files changed, 76 insertions(+), 85 deletions(-) (limited to 'plugins/MyDetails') diff --git a/plugins/MyDetails/src/data.cpp b/plugins/MyDetails/src/data.cpp index 585c403a81..c6afc471e8 100644 --- a/plugins/MyDetails/src/data.cpp +++ b/plugins/MyDetails/src/data.cpp @@ -20,7 +20,7 @@ Boston, MA 02111-1307, USA. #include "commons.h" -static char *StatusModeToDbSetting(int status,const char *suffix); +static char *StatusModeToDbSetting(int status, const char *suffix); ProtocolArray *protocols = NULL; @@ -33,7 +33,7 @@ void InitProtocolData() protocols = new ProtocolArray(count); for (int i = 0; i < count; i++) { - PROTOACCOUNT* acc = protos[i]; + PROTOACCOUNT *acc = protos[i]; if (acc->szModuleName == NULL || acc->szModuleName[0] == '\0' || acc->bIsVirtual) continue; @@ -53,7 +53,7 @@ void DeInitProtocolData() // Protocol Class /////////////////////////////////////////////////////////////////////////////////////////// -Protocol::Protocol(const char *aName, const TCHAR* descr) +Protocol::Protocol(const char *aName, const TCHAR *descr) { lstrcpynA(name, aName, SIZEOF(name)); lstrcpyn(description, descr, SIZEOF(description)); @@ -121,14 +121,15 @@ int Protocol::GetStatus() if (CallProtoService(name, PS_GETCUSTOMSTATUSEX, 0, (LPARAM)&css) != 0) tszXStatusMessage[0] = tszXStatusName[0] = 0, custom_status = 0; } - else custom_status = 0; + else + custom_status = 0; // if protocol supports custom status, but it is not set (custom_status will be -1), show normal status if (custom_status < 0) custom_status = 0; if (custom_status == 0) { - TCHAR *tmp = (TCHAR*)CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, status, GSMDF_TCHAR); + TCHAR *tmp = (TCHAR *)CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, status, GSMDF_TCHAR); lcopystr(status_name, tmp, SIZEOF(status_name)); } else { @@ -197,8 +198,7 @@ bool Protocol::CanGetStatusMsg() bool Protocol::CanGetStatusMsg(int aStatus) { - return (CallProtoService(name, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_MODEMSGSEND) != 0 - && (PF3 & Proto_Status2Flag(aStatus)); + return (CallProtoService(name, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_MODEMSGSEND) != 0 && (PF3 & Proto_Status2Flag(aStatus)); } bool Protocol::CanSetStatusMsg() @@ -216,7 +216,7 @@ void Protocol::GetStatusMsg(int aStatus, TCHAR *msg, size_t msg_size) if (!CanGetStatusMsg()) lcopystr(msg, _T(""), msg_size); else if (aStatus == status && ProtoServiceExists(name, PS_GETMYAWAYMSG)) { - ptrT tmp((TCHAR*)CallProtoService(name, PS_GETMYAWAYMSG, 0, SGMA_TCHAR)); + ptrT tmp((TCHAR *)CallProtoService(name, PS_GETMYAWAYMSG, 0, SGMA_TCHAR)); lcopystr(msg, tmp == NULL ? _T("") : tmp, msg_size); } else if (ServiceExists(MS_AWAYMSG_GETSTATUSMSGT)) { @@ -297,7 +297,7 @@ int Protocol::GetNickMaxLength() return ret; } -TCHAR* Protocol::GetNick() +TCHAR *Protocol::GetNick() { // See if can get one if (!CanGetNick()) @@ -319,7 +319,8 @@ TCHAR* Protocol::GetNick() lcopystr(nickname, ci.pszVal, SIZEOF(nickname)); mir_free(ci.pszVal); } - else lcopystr(nickname, _T(""), SIZEOF(nickname)); + else + lcopystr(nickname, _T(""), SIZEOF(nickname)); return nickname; } @@ -371,7 +372,7 @@ bool Protocol::ListeningToEnabled() return CanSetListeningTo() && CallService(MS_LISTENINGTO_ENABLED, (WPARAM)name, 0) != 0; } -TCHAR * Protocol::GetListeningTo() +TCHAR *Protocol::GetListeningTo() { if (!CanGetListeningTo()) { lcopystr(listening_to, _T(""), SIZEOF(listening_to)); @@ -393,7 +394,7 @@ TCHAR * Protocol::GetListeningTo() ProtocolArray::ProtocolArray(int max_size) { - buffer = (Protocol **) malloc(max_size * sizeof(Protocol*)); + buffer = (Protocol **)malloc(max_size * sizeof(Protocol *)); buffer_len = 0; GetDefaultNick(); @@ -404,7 +405,7 @@ ProtocolArray::ProtocolArray(int max_size) ProtocolArray::~ProtocolArray() { if (buffer != NULL) { - for ( int i = 0 ; i < buffer_len ; i++ ) + for (int i = 0; i < buffer_len; i++) delete buffer[i]; free(buffer); } @@ -424,18 +425,18 @@ void ProtocolArray::Add(Protocol *p) } -Protocol* ProtocolArray::Get(int i) +Protocol *ProtocolArray::Get(int i) { return (i >= buffer_len) ? NULL : buffer[i]; } -Protocol* ProtocolArray::Get(const char *name) +Protocol *ProtocolArray::Get(const char *name) { if (name == NULL) return NULL; - for ( int i = 0 ; i < buffer_len ; i++ ) + for (int i = 0; i < buffer_len; i++) if (strcmp(name, buffer[i]->name) == 0) return buffer[i]; @@ -451,21 +452,19 @@ bool ProtocolArray::CanSetStatusMsgPerProtocol() void ProtocolArray::GetAvatars() { - for ( int i = 0 ; i < buffer_len ; i++ ) - { + for (int i = 0; i < buffer_len; i++) buffer[i]->GetAvatar(); - } } void ProtocolArray::GetStatusMsgs() { - for ( int i = 0 ; i < buffer_len ; i++ ) + for (int i = 0; i < buffer_len; i++) buffer[i]->GetStatusMsg(); } void ProtocolArray::GetStatuses() { - for ( int i = 0 ; i < buffer_len ; i++ ) + for (int i = 0; i < buffer_len; i++) buffer[i]->GetStatus(); } @@ -485,10 +484,10 @@ bool ProtocolArray::CanSetAvatars() void ProtocolArray::SetAvatars(const TCHAR *file_name) { - if ( !CanSetAvatars()) + if (!CanSetAvatars()) return; - CallService(MS_AV_SETMYAVATART, NULL, (WPARAM) file_name); + CallService(MS_AV_SETMYAVATART, NULL, (WPARAM)file_name); } void ProtocolArray::SetNicks(const TCHAR *nick) @@ -500,7 +499,7 @@ void ProtocolArray::SetNicks(const TCHAR *nick) db_set_ts(0, MODULE_NAME, SETTING_DEFAULT_NICK, nick); - for ( int i = 0 ; i < buffer_len ; i++ ) + for (int i = 0; i < buffer_len; i++) buffer[i]->SetNick(default_nick); } @@ -512,19 +511,19 @@ void ProtocolArray::SetStatus(int aStatus) void ProtocolArray::SetStatusMsgs(const TCHAR *message) { - for (int i = ID_STATUS_OFFLINE ; i <= ID_STATUS_IDLE; i++) + for (int i = ID_STATUS_OFFLINE; i <= ID_STATUS_IDLE; i++) SetStatusMsgs(i, message); } void ProtocolArray::SetStatusMsgs(int status, const TCHAR *message) { - db_set_ts(NULL,"SRAway",StatusModeToDbSetting(status,"Msg"),message); + db_set_ts(NULL, "SRAway", StatusModeToDbSetting(status, "Msg"), message); // Save default also - if ( !db_get_b(NULL,"SRAway",StatusModeToDbSetting(status,"UsePrev"),0)) - db_set_ts(NULL,"SRAway",StatusModeToDbSetting(status,"Default"),message); + if (!db_get_b(NULL, "SRAway", StatusModeToDbSetting(status, "UsePrev"), 0)) + db_set_ts(NULL, "SRAway", StatusModeToDbSetting(status, "Default"), message); - for ( int i = 0 ; i < buffer_len ; i++ ) + for (int i = 0; i < buffer_len; i++) if (buffer[i]->status == status) buffer[i]->SetStatusMsg(status, message); } @@ -547,19 +546,19 @@ void ProtocolArray::GetDefaultAvatar() default_avatar_file[0] = '\0'; } -TCHAR* ProtocolArray::GetDefaultStatusMsg() +TCHAR *ProtocolArray::GetDefaultStatusMsg() { return GetDefaultStatusMsg(CallService(MS_CLIST_GETSTATUSMODE, 0, 0)); } -TCHAR* ProtocolArray::GetDefaultStatusMsg(int status) +TCHAR *ProtocolArray::GetDefaultStatusMsg(int status) { default_status_message[0] = '\0'; if (status == ID_STATUS_CONNECTING) status = ID_STATUS_OFFLINE; - TCHAR *tmp = (TCHAR*) CallService(MS_AWAYMSG_GETSTATUSMSGT, (WPARAM)status, 0); + TCHAR *tmp = (TCHAR *)CallService(MS_AWAYMSG_GETSTATUSMSGT, (WPARAM)status, 0); if (tmp != NULL) { lstrcpyn(default_status_message, tmp, SIZEOF(default_status_message)); mir_free(tmp); @@ -582,25 +581,26 @@ bool ProtocolArray::ListeningToEnabled() ////////////////////////////////////////////////////////////////////////////////////////////////////// // Helper functions -static char *StatusModeToDbSetting(int status,const char *suffix) +static char *StatusModeToDbSetting(int status, const char *suffix) { char *prefix; static char str[64]; - switch(status) { - case ID_STATUS_AWAY: prefix="Away"; break; - case ID_STATUS_NA: prefix="Na"; break; - case ID_STATUS_DND: prefix="Dnd"; break; - case ID_STATUS_OCCUPIED: prefix="Occupied"; break; - case ID_STATUS_FREECHAT: prefix="FreeChat"; break; - case ID_STATUS_ONLINE: prefix="On"; break; - case ID_STATUS_OFFLINE: prefix="Off"; break; - case ID_STATUS_INVISIBLE: prefix="Inv"; break; - case ID_STATUS_ONTHEPHONE: prefix="Otp"; break; - case ID_STATUS_OUTTOLUNCH: prefix="Otl"; break; - case ID_STATUS_IDLE: prefix="Idl"; break; + switch (status) { + case ID_STATUS_AWAY: prefix = "Away"; break; + case ID_STATUS_NA: prefix = "Na"; break; + case ID_STATUS_DND: prefix = "Dnd"; break; + case ID_STATUS_OCCUPIED: prefix = "Occupied"; break; + case ID_STATUS_FREECHAT: prefix = "FreeChat"; break; + case ID_STATUS_ONLINE: prefix = "On"; break; + case ID_STATUS_OFFLINE: prefix = "Off"; break; + case ID_STATUS_INVISIBLE: prefix = "Inv"; break; + case ID_STATUS_ONTHEPHONE: prefix = "Otp"; break; + case ID_STATUS_OUTTOLUNCH: prefix = "Otl"; break; + case ID_STATUS_IDLE: prefix = "Idl"; break; default: return NULL; } - lstrcpyA(str,prefix); lstrcatA(str,suffix); + lstrcpyA(str, prefix); + lstrcatA(str, suffix); return str; } diff --git a/plugins/MyDetails/src/data.h b/plugins/MyDetails/src/data.h index f2ab3e555a..53bc6ade9d 100644 --- a/plugins/MyDetails/src/data.h +++ b/plugins/MyDetails/src/data.h @@ -74,7 +74,7 @@ public: //void SetAvatar(const char *file_name, HBITMAP hBmp); bool CanGetNick(); - TCHAR * GetNick(); // Copy to cache and return a copy + TCHAR *GetNick(); // Copy to cache and return a copy int GetNickMaxLength(); bool CanSetNick(); void SetNick(const TCHAR *nick); @@ -82,11 +82,11 @@ public: bool CanGetListeningTo(); bool CanSetListeningTo(); bool ListeningToEnabled(); - TCHAR * GetListeningTo(); // Copy to cache and return a copy + TCHAR *GetListeningTo(); // Copy to cache and return a copy bool CanGetStatusMsg(); bool CanGetStatusMsg(int aStatus); - TCHAR * GetStatusMsg(); // Copy to cache and return a copy + TCHAR *GetStatusMsg(); // Copy to cache and return a copy void GetStatusMsg(int aStatus, TCHAR *msg, size_t msg_size); bool CanSetStatusMsg(); bool CanSetStatusMsg(int aStatus); @@ -116,8 +116,8 @@ public: int GetSize(); void Add(Protocol *p); - Protocol* Get(int i); - Protocol* Get(const char *name); + Protocol *Get(int i); + Protocol *Get(const char *name); void GetAvatars(); bool CanSetAvatars(); @@ -138,8 +138,8 @@ public: void GetDefaultNick(); // Copy to cache void GetDefaultAvatar(); // Copy to cache - TCHAR* GetDefaultStatusMsg(); // Copy to cache - TCHAR* GetDefaultStatusMsg(int status); + TCHAR *GetDefaultStatusMsg(); // Copy to cache + TCHAR *GetDefaultStatusMsg(int status); bool CanSetListeningTo(); bool ListeningToEnabled(); diff --git a/plugins/MyDetails/src/frame.cpp b/plugins/MyDetails/src/frame.cpp index 383ea5bb31..2469e22728 100644 --- a/plugins/MyDetails/src/frame.cpp +++ b/plugins/MyDetails/src/frame.cpp @@ -100,8 +100,8 @@ void SetStatusMessageRefreshTime(HWND hwnd); int SettingsChangedHook(WPARAM wParam, LPARAM lParam); int AvatarChangedHook(WPARAM wParam, LPARAM lParam); int ProtoAckHook(WPARAM wParam, LPARAM lParam); -int SmileyAddOptionsChangedHook(WPARAM wParam,LPARAM lParam); -int ListeningtoEnableStateChangedHook(WPARAM wParam,LPARAM lParam); +int SmileyAddOptionsChangedHook(WPARAM wParam, LPARAM lParam); +int ListeningtoEnableStateChangedHook(WPARAM wParam, LPARAM lParam); #define OUTSIDE_BORDER 6 @@ -181,7 +181,7 @@ void DeInitFrames() if (g_bFramesExist && frame_id != -1) CallService(MS_CLIST_FRAMES_REMOVEFRAME, (WPARAM)frame_id, 0); - for (int i = 0 ; i < NUM_FONTS ; i++) + for (int i = 0; i < NUM_FONTS; i++) if (hFont[i] != 0) DeleteObject(hFont[i]); @@ -193,7 +193,7 @@ void DeInitFrames() int ReloadFont(WPARAM wParam, LPARAM lParam) { - for (int i = 0 ; i < NUM_FONTS ; i++) { + for (int i = 0; i < NUM_FONTS; i++) { if (hFont[i] != 0) DeleteObject(hFont[i]); @@ -230,7 +230,7 @@ int CreateFrame() ReloadColour(0, 0); HookEvent(ME_COLOUR_RELOAD, ReloadColour); - for (int i = 0 ; i < NUM_FONTS ; i++) { + for (int i = 0; i < NUM_FONTS; i++) { ZeroMemory(&font_id[i], sizeof(font_id[i])); font_id[i].cbSize = sizeof(FontIDT); @@ -359,7 +359,7 @@ bool FrameIsFloating() LRESULT CALLBACK FrameContainerWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { - switch(msg) { + switch (msg) { case WM_SHOWWINDOW: if ((BOOL)wParam) Utils_RestoreWindowPosition(hwnd, 0, MODULE_NAME, WINDOW_NAME_PREFIX); @@ -524,19 +524,8 @@ HWND CreateTooltip(HWND hwnd, RECT &rect) return NULL; /* CREATE A TOOLTIP WINDOW */ - HWND hwndTT = CreateWindowEx(WS_EX_TOPMOST, - TOOLTIPS_CLASS, - NULL, - WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, - CW_USEDEFAULT, - CW_USEDEFAULT, - CW_USEDEFAULT, - CW_USEDEFAULT, - hwnd, - NULL, - hInst, - NULL - ); // handle to the ToolTip control + HWND hwndTT = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, + CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwnd, NULL, hInst, NULL); // handle to the ToolTip control /* INITIALIZE MEMBERS OF THE TOOLINFO STRUCTURE */ TOOLINFO ti; @@ -1041,9 +1030,11 @@ void DrawTextWithRect(HDC hdc, const TCHAR *text, const TCHAR *def_text, RECT rc // Only first line TCHAR *tmp2 = _tcsdup(tmp); TCHAR *pos = _tcsrchr(tmp2, '\r'); - if (pos != NULL) pos[0] = '\0'; + if (pos != NULL) + pos[0] = '\0'; pos = _tcschr(tmp2, '\n'); - if (pos != NULL) pos[0] = '\0'; + if (pos != NULL) + pos[0] = '\0'; RECT r = rc; @@ -1395,7 +1386,7 @@ void MakeHover(HWND hwnd, bool draw, bool *hover, POINT *p, RECT *r) void ShowGlobalStatusMenu(HWND hwnd, MyDetailsFrameData *data, Protocol *proto, POINT &p) { - HMENU submenu = (HMENU) CallService(MS_CLIST_MENUGETSTATUS,0,0); + HMENU submenu = (HMENU)CallService(MS_CLIST_MENUGETSTATUS, 0, 0); p.x = (opts.draw_text_align_right ? data->status_rect.right : data->status_rect.left); p.y = data->status_rect.bottom + 1; @@ -1520,7 +1511,7 @@ void ShowListeningToMenu(HWND hwnd, MyDetailsFrameData *data, Protocol *proto, P | (opts.draw_text_align_right ? TPM_RIGHTALIGN : TPM_LEFTALIGN), p.x, p.y, 0, hwnd, NULL); DestroyMenu(menu); - switch(ret) { + switch (ret) { case 1: CallService(MS_LISTENINGTO_ENABLE, (LPARAM)proto->name, !proto->ListeningToEnabled()); break; @@ -1536,7 +1527,7 @@ LRESULT CALLBACK FrameWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar MyDetailsFrameData *data = (MyDetailsFrameData *)GetWindowLongPtr(hwnd, GWLP_USERDATA); Protocol *proto; - switch(msg) { + switch (msg) { case WM_CREATE: { data = new MyDetailsFrameData(); @@ -1751,7 +1742,7 @@ LRESULT CALLBACK FrameWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar int ret = TrackPopupMenu(submenu, TPM_TOPALIGN | TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD, p.x, p.y, 0, hwnd, NULL); DestroyMenu(menu); - switch(ret) { + switch (ret) { case 1: CallService(MS_MYDETAILS_SETMYAVATARUI, 0, (LPARAM)proto->name); break; @@ -1791,7 +1782,7 @@ LRESULT CALLBACK FrameWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar int ret = TrackPopupMenu(submenu, TPM_TOPALIGN | TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD, p.x, p.y, 0, hwnd, NULL); DestroyMenu(menu); - switch(ret) { + switch (ret) { case 1: CallService(MS_MYDETAILS_SETMYNICKNAMEUI, 0, (LPARAM)proto->name); break; @@ -1859,7 +1850,7 @@ LRESULT CALLBACK FrameWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar int ret = TrackPopupMenu(submenu, TPM_TOPALIGN | TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD, p.x, p.y, 0, hwnd, NULL); DestroyMenu(menu); - switch(ret) { + switch (ret) { case 1: CallService(MS_MYDETAILS_SETMYSTATUSMESSAGEUI, 0, (LPARAM)proto->name); break; diff --git a/plugins/MyDetails/src/frame.h b/plugins/MyDetails/src/frame.h index 5382d3ed46..4ed686571f 100644 --- a/plugins/MyDetails/src/frame.h +++ b/plugins/MyDetails/src/frame.h @@ -30,9 +30,9 @@ void RefreshFrameAndCalcRects(); void SetCycleTime(); -INT_PTR PluginCommand_ShowNextProtocol(WPARAM wParam,LPARAM lParam); -INT_PTR PluginCommand_ShowPreviousProtocol(WPARAM wParam,LPARAM lParam); -INT_PTR PluginCommand_ShowProtocol(WPARAM wParam,LPARAM lParam); +INT_PTR PluginCommand_ShowNextProtocol(WPARAM wParam, LPARAM lParam); +INT_PTR PluginCommand_ShowPreviousProtocol(WPARAM wParam, LPARAM lParam); +INT_PTR PluginCommand_ShowProtocol(WPARAM wParam, LPARAM lParam); -#endif // __FRAME_H__ \ No newline at end of file +#endif // __FRAME_H__ diff --git a/plugins/MyDetails/src/stdafx.cpp b/plugins/MyDetails/src/stdafx.cpp index 3e55ac0306..b15006d187 100644 --- a/plugins/MyDetails/src/stdafx.cpp +++ b/plugins/MyDetails/src/stdafx.cpp @@ -15,4 +15,4 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include "commons.h" \ No newline at end of file +#include "commons.h" -- cgit v1.2.3