summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorTobias Weimer <wishmaster51@googlemail.com>2015-11-01 13:30:52 +0000
committerTobias Weimer <wishmaster51@googlemail.com>2015-11-01 13:30:52 +0000
commit7a03b9fcca5ad759a6c71b2a0dceebd77533107e (patch)
tree4cd6bff30f64babb39e9ee955794cfa86afeb022 /plugins
parentef7af9e52247e0b13de8f7acc78508a1d3b9fe00 (diff)
CList blind:
- crash fix (fixes #1079) git-svn-id: http://svn.miranda-ng.org/main/trunk@15662 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Clist_blind/src/clistopts.cpp4
-rw-r--r--plugins/Clist_blind/src/contact.cpp94
-rw-r--r--plugins/Clist_blind/src/init.cpp3
-rw-r--r--plugins/Clist_blind/src/stdafx.h4
4 files changed, 103 insertions, 2 deletions
diff --git a/plugins/Clist_blind/src/clistopts.cpp b/plugins/Clist_blind/src/clistopts.cpp
index 913097d9d6..fe3af86452 100644
--- a/plugins/Clist_blind/src/clistopts.cpp
+++ b/plugins/Clist_blind/src/clistopts.cpp
@@ -184,8 +184,8 @@ static INT_PTR CALLBACK DlgProcGenOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP
(WORD)SendDlgItemMessage(hwndDlg, IDC_HIDETIMESPIN, UDM_GETPOS, 0, 0));
}
}
- db_set_b(NULL, "CList", "SortByStatus", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_SORTBYSTATUS));
- db_set_b(NULL, "CList", "SortByProto", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_SORTBYPROTO));
+ db_set_b(NULL, "CList", "SortByStatus", (BYTE) (g_bSortByStatus = IsDlgButtonChecked(hwndDlg, IDC_SORTBYSTATUS)));
+ db_set_b(NULL, "CList", "SortByProto", (BYTE) (g_bSortByProto = IsDlgButtonChecked(hwndDlg, IDC_SORTBYPROTO)));
db_set_b(NULL, "CList", "ConfirmDelete", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_CONFIRMDELETE));
db_set_b(NULL, "CList", "Tray1Click", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_ONECLK));
db_set_b(NULL, "CList", "AlwaysStatus", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_ALWAYSSTATUS));
diff --git a/plugins/Clist_blind/src/contact.cpp b/plugins/Clist_blind/src/contact.cpp
new file mode 100644
index 0000000000..7fb23a2d3c
--- /dev/null
+++ b/plugins/Clist_blind/src/contact.cpp
@@ -0,0 +1,94 @@
+/*
+
+Miranda NG: the free IM client for Microsoft* Windows*
+
+Copyright (ñ) 2012-15 Miranda NG project (http://miranda-ng.org),
+Copyright (c) 2000-12 Miranda IM project,
+all portions of this codebase are copyrighted to the people
+listed in contributors.txt.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include "stdafx.h"
+
+int g_bSortByStatus, g_bSortByProto;
+
+const struct
+{
+ int status, order;
+}
+static statusModeOrder[] = {
+ { ID_STATUS_OFFLINE, 500 },
+ { ID_STATUS_ONLINE, 10 },
+ { ID_STATUS_AWAY, 200 },
+ { ID_STATUS_DND, 110 },
+ { ID_STATUS_NA, 450 },
+ { ID_STATUS_OCCUPIED, 100 },
+ { ID_STATUS_FREECHAT, 0 },
+ { ID_STATUS_INVISIBLE, 20 },
+ { ID_STATUS_ONTHEPHONE, 150 },
+ { ID_STATUS_OUTTOLUNCH, 425 } };
+
+static int GetStatusModeOrdering(int statusMode)
+{
+ for (int i = 0; i < _countof(statusModeOrder); i++)
+ if (statusModeOrder[i].status == statusMode)
+ return statusModeOrder[i].order;
+ return 1000;
+}
+
+int CompareContacts(const ClcContact* c1, const ClcContact* c2)
+{
+ MCONTACT a = c1->hContact, b = c2->hContact;
+
+ int statusa = db_get_w(a, c1->proto, "Status", ID_STATUS_OFFLINE);
+ int statusb = db_get_w(b, c2->proto, "Status", ID_STATUS_OFFLINE);
+
+ if (g_bSortByProto) {
+ /* deal with statuses, online contacts have to go above offline */
+ if ((statusa == ID_STATUS_OFFLINE) != (statusb == ID_STATUS_OFFLINE)) {
+ return 2 * (statusa == ID_STATUS_OFFLINE) - 1;
+ }
+ /* both are online, now check protocols */
+ if (c1->proto != NULL && c2->proto != NULL) {
+ int rc = mir_strcmp(c1->proto, c2->proto);
+ if (rc != 0)
+ return rc;
+ }
+ /* protocols are the same, order by display name */
+ }
+
+ if (g_bSortByStatus) {
+ int ordera = GetStatusModeOrdering(statusa);
+ int orderb = GetStatusModeOrdering(statusb);
+ if (ordera != orderb)
+ return ordera - orderb;
+ }
+ else {
+ //one is offline: offline goes below online
+ if ((statusa == ID_STATUS_OFFLINE) != (statusb == ID_STATUS_OFFLINE))
+ return 2 * (statusa == ID_STATUS_OFFLINE) - 1;
+ }
+
+ TCHAR namea[128];
+ TCHAR *nameb = pcli->pfnGetContactDisplayName(a, 0);
+ _tcsncpy_s(namea, nameb, _TRUNCATE);
+ namea[ _countof(namea)-1 ] = 0;
+ nameb = pcli->pfnGetContactDisplayName(b, 0);
+
+ //otherwise just compare names
+ return mir_tstrcmpi(namea, nameb);
+}
diff --git a/plugins/Clist_blind/src/init.cpp b/plugins/Clist_blind/src/init.cpp
index 5c31dc61e6..f4b90ba86f 100644
--- a/plugins/Clist_blind/src/init.cpp
+++ b/plugins/Clist_blind/src/init.cpp
@@ -130,6 +130,8 @@ static INT_PTR GetStatusMode(WPARAM, LPARAM)
extern "C" int __declspec(dllexport) CListInitialise()
{
mir_getCLI();
+ g_bSortByStatus = db_get_b(NULL, "CList", "SortByStatus", SETTING_SORTBYSTATUS_DEFAULT);
+ g_bSortByProto = db_get_b(NULL, "CList", "SortByProto", SETTING_SORTBYPROTO_DEFAULT);
coreCli = *pcli;
@@ -144,6 +146,7 @@ extern "C" int __declspec(dllexport) CListInitialise()
pcli->pfnLoadClcOptions = LoadClcOptions;
pcli->pfnGetRowHeight = GetRowHeight;
pcli->pfnSortCLC = SortCLC;
+ pcli->pfnCompareContacts = CompareContacts;
CreateServiceFunction(MS_CLIST_GETSTATUSMODE, GetStatusMode);
diff --git a/plugins/Clist_blind/src/stdafx.h b/plugins/Clist_blind/src/stdafx.h
index dc20fb1eb9..ff97b904c7 100644
--- a/plugins/Clist_blind/src/stdafx.h
+++ b/plugins/Clist_blind/src/stdafx.h
@@ -49,6 +49,10 @@ struct ClcData : public ClcDataBase
// shared vars
extern HINSTANCE g_hInst;
extern CLIST_INTERFACE coreCli;
+extern int g_bSortByStatus, g_bSortByProto;
+
+
+int CompareContacts(const ClcContact *contact1, const ClcContact *contact2);
/* most free()'s are invalid when the code is executed from a dll, so this changes
all the bad free()'s to good ones, however it's still incorrect code. The reasons for not