summaryrefslogtreecommitdiff
path: root/src/core/stdclist
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2015-10-30 17:13:48 +0000
committerGeorge Hazan <george.hazan@gmail.com>2015-10-30 17:13:48 +0000
commitc0bf2d57a2b9ed3bb11eb6a4c499629b7ce8ba98 (patch)
treeab12fbe3d3bbc0c0321a8af75102a50997786e16 /src/core/stdclist
parent211967c3ae7d510f2e63aac7fe912d040ad1ebc3 (diff)
missing file added
git-svn-id: http://svn.miranda-ng.org/main/trunk@15653 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src/core/stdclist')
-rw-r--r--src/core/stdclist/src/contact.cpp97
1 files changed, 97 insertions, 0 deletions
diff --git a/src/core/stdclist/src/contact.cpp b/src/core/stdclist/src/contact.cpp
new file mode 100644
index 0000000000..ae6d772529
--- /dev/null
+++ b/src/core/stdclist/src/contact.cpp
@@ -0,0 +1,97 @@
+/*
+
+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 } };
+
+int GetStatusModeOrdering(int statusMode)
+{
+ int i;
+ for (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;
+ TCHAR namea[128], *nameb;
+ int statusa, statusb;
+ int rc;
+
+ statusa = db_get_w(a, c1->proto, "Status", ID_STATUS_OFFLINE);
+ 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) {
+ 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;
+ }
+
+ 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);
+}