From 200aa11bbd25189047b388b88b3fc1f50b785d7c Mon Sep 17 00:00:00 2001 From: sje Date: Wed, 1 Nov 2006 14:37:48 +0000 Subject: git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@8 4f64403b-2f21-0410-a795-97e2b3489a10 --- metacontacts/meta_options.c | 305 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 305 insertions(+) create mode 100644 metacontacts/meta_options.c (limited to 'metacontacts/meta_options.c') diff --git a/metacontacts/meta_options.c b/metacontacts/meta_options.c new file mode 100644 index 0000000..8e0c77a --- /dev/null +++ b/metacontacts/meta_options.c @@ -0,0 +1,305 @@ +/* +MetaContacts Plugin for Miranda IM. + +Copyright © 2004 Universite Louis PASTEUR, STRASBOURG. + +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. +*/ + +/** @file meta_menu.c +* +* Functions needed to handle MetaContacts. +* Centralizes functions called when the user chooses +* an option integrated in the context-menu of the \c CList. +*/ + +#include "metacontacts.h" + +MetaOptions options; +MetaOptions options_changes; + +BOOL CALLBACK DlgProcOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + HWND hw; + char buff[512]; + + switch ( msg ) { + case WM_INITDIALOG: { + TranslateDialogDefault( hwndDlg ); + options_changes = options; + + CheckDlgButton(hwndDlg, IDC_CHK_SETDEFAULTRECV, options_changes.set_default_on_recv ? TRUE : FALSE); + hw = GetDlgItem(hwndDlg, IDC_CHK_TEMPDEFAULT); + EnableWindow(hw, options_changes.set_default_on_recv); + CheckDlgButton(hwndDlg, IDC_CHK_TEMPDEFAULT, options_changes.temp_default ? TRUE : FALSE); + + CheckDlgButton(hwndDlg, IDC_CHK_ALWAYSUSEDEFAULT, options_changes.always_use_default ? TRUE : FALSE); + CheckDlgButton(hwndDlg, IDC_CHK_SUPPRESSSTATUS, options_changes.suppress_status ? TRUE : FALSE); + CheckDlgButton(hwndDlg, IDC_CHK_SUPPRESSPROTO, options_changes.suppress_proto ? TRUE : FALSE); + + CheckDlgButton(hwndDlg, IDC_RAD_UID, options_changes.menu_contact_label == DNT_UID); + CheckDlgButton(hwndDlg, IDC_RAD_DID, options_changes.menu_contact_label == DNT_DID); + + CheckDlgButton(hwndDlg, IDC_RAD_MSG, options_changes.menu_function == FT_MSG); + CheckDlgButton(hwndDlg, IDC_RAD_MENU, options_changes.menu_function == FT_MENU); + CheckDlgButton(hwndDlg, IDC_RAD_INFO, options_changes.menu_function == FT_INFO); + + CheckDlgButton(hwndDlg, IDC_RAD_NICK, options_changes.clist_contact_name == CNNT_NICK); + CheckDlgButton(hwndDlg, IDC_RAD_NAME, options_changes.clist_contact_name == CNNT_DISPLAYNAME); + CheckDlgButton(hwndDlg, IDC_CHK_LOCKHANDLE, options_changes.lockHandle ? TRUE : FALSE); + CheckDlgButton(hwndDlg, IDC_CHK_SUBWINDOW, options_changes.subcontact_windows ? TRUE : FALSE); + + CheckDlgButton(hwndDlg, IDC_CHK_METAHISTORY, options_changes.metahistory ? TRUE : FALSE); + CheckDlgButton(hwndDlg, IDC_CHK_SUBHISTORY, options_changes.subhistory ? TRUE : FALSE); + CheckDlgButton(hwndDlg, IDC_CHK_COPYDATA, options_changes.copydata ? TRUE : FALSE); + + if(!options_changes.subcontact_windows) { + hw = GetDlgItem(hwndDlg, IDC_CHK_METAHISTORY); + EnableWindow(hw, FALSE); + } else { + hw = GetDlgItem(hwndDlg, IDC_CHK_SUBHISTORY); + EnableWindow(hw, FALSE); + } + + CheckDlgButton(hwndDlg, IDC_CHK_COPYHISTORY, options_changes.copy_subcontact_history ? TRUE : FALSE); + hw = GetDlgItem(hwndDlg, IDC_ED_DAYS); + _itoa(options_changes.days_history, buff, 10); + SetWindowText(hw, buff); + + return TRUE; + } + case WM_COMMAND: + if ( HIWORD( wParam ) == BN_CLICKED ) { + switch( LOWORD( wParam )) { + case IDC_CHK_SETDEFAULTRECV: + options_changes.set_default_on_recv = IsDlgButtonChecked(hwndDlg, IDC_CHK_SETDEFAULTRECV); + hw = GetDlgItem(hwndDlg, IDC_CHK_TEMPDEFAULT); + EnableWindow(hw, options_changes.set_default_on_recv); + SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + break; + case IDC_CHK_TEMPDEFAULT: + hw = GetDlgItem(hwndDlg, IDC_CHK_TEMPDEFAULT); + options_changes.temp_default = IsDlgButtonChecked(hwndDlg, IDC_CHK_TEMPDEFAULT); + SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + break; + case IDC_CHK_ALWAYSUSEDEFAULT: + hw = GetDlgItem(hwndDlg, IDC_CHK_ALWAYSUSEDEFAULT); + options_changes.always_use_default = IsDlgButtonChecked(hwndDlg, IDC_CHK_ALWAYSUSEDEFAULT); + SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + break; + case IDC_CHK_SUPPRESSSTATUS: + hw = GetDlgItem(hwndDlg, IDC_CHK_SUPPRESSSTATUS); + options_changes.suppress_status = IsDlgButtonChecked(hwndDlg, IDC_CHK_SUPPRESSSTATUS); + SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + break; + case IDC_CHK_SUPPRESSPROTO: + hw = GetDlgItem(hwndDlg, IDC_CHK_SUPPRESSPROTO); + options_changes.suppress_proto = IsDlgButtonChecked(hwndDlg, IDC_CHK_SUPPRESSPROTO); + SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + break; + case IDC_CHK_COPYHISTORY: + hw = GetDlgItem(hwndDlg, IDC_CHK_COPYHISTORY); + options_changes.copy_subcontact_history = IsDlgButtonChecked(hwndDlg, IDC_CHK_COPYHISTORY); + SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + break; + case IDC_CHK_METAHISTORY: + hw = GetDlgItem(hwndDlg, IDC_CHK_METAHISTORY); + options_changes.metahistory = IsDlgButtonChecked(hwndDlg, IDC_CHK_METAHISTORY); + SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + break; + case IDC_CHK_SUBHISTORY: + hw = GetDlgItem(hwndDlg, IDC_CHK_SUBHISTORY); + options_changes.subhistory = IsDlgButtonChecked(hwndDlg, IDC_CHK_SUBHISTORY); + SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + break; + case IDC_CHK_COPYDATA: + hw = GetDlgItem(hwndDlg, IDC_CHK_COPYDATA); + options_changes.copydata = IsDlgButtonChecked(hwndDlg, IDC_CHK_COPYDATA); + SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + break; + case IDC_RAD_UID: + hw = GetDlgItem(hwndDlg, IDC_RAD_UID); + if(IsDlgButtonChecked(hwndDlg, IDC_RAD_UID)) { + options_changes.menu_contact_label = DNT_UID; + CheckDlgButton(hwndDlg, IDC_RAD_DID, FALSE); + } + SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + break; + case IDC_RAD_DID: + hw = GetDlgItem(hwndDlg, IDC_RAD_DID); + if(IsDlgButtonChecked(hwndDlg, IDC_RAD_DID)) { + options_changes.menu_contact_label = DNT_DID; + CheckDlgButton(hwndDlg, IDC_RAD_UID, FALSE); + } + SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + break; + case IDC_RAD_MSG: + hw = GetDlgItem(hwndDlg, IDC_RAD_MSG); + if(IsDlgButtonChecked(hwndDlg, IDC_RAD_MSG)) { + options_changes.menu_function = FT_MSG; + CheckDlgButton(hwndDlg, IDC_RAD_MENU, FALSE); + CheckDlgButton(hwndDlg, IDC_RAD_INFO, FALSE); + } + SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + break; + case IDC_RAD_MENU: + hw = GetDlgItem(hwndDlg, IDC_RAD_MENU); + if(IsDlgButtonChecked(hwndDlg, IDC_RAD_MENU)) { + options_changes.menu_function = FT_MENU; + CheckDlgButton(hwndDlg, IDC_RAD_MSG, FALSE); + CheckDlgButton(hwndDlg, IDC_RAD_INFO, FALSE); + } + SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + break; + case IDC_RAD_INFO: + hw = GetDlgItem(hwndDlg, IDC_RAD_INFO); + if(IsDlgButtonChecked(hwndDlg, IDC_RAD_INFO)) { + options_changes.menu_function = FT_INFO; + CheckDlgButton(hwndDlg, IDC_RAD_MSG, FALSE); + CheckDlgButton(hwndDlg, IDC_RAD_MENU, FALSE); + } + SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + break; + case IDC_RAD_NICK: + hw = GetDlgItem(hwndDlg, IDC_RAD_NICK); + if(IsDlgButtonChecked(hwndDlg, IDC_RAD_NICK)) { + options_changes.clist_contact_name = CNNT_NICK; + CheckDlgButton(hwndDlg, IDC_RAD_NAME, FALSE); + } + SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + break; + case IDC_RAD_NAME: + hw = GetDlgItem(hwndDlg, IDC_RAD_NAME); + if(IsDlgButtonChecked(hwndDlg, IDC_RAD_NAME)) { + options_changes.clist_contact_name = CNNT_DISPLAYNAME; + CheckDlgButton(hwndDlg, IDC_RAD_NICK, FALSE); + } + SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + break; + case IDC_CHK_SUBWINDOW: + hw = GetDlgItem(hwndDlg, IDC_CHK_SUBWINDOW); + options_changes.subcontact_windows = IsDlgButtonChecked(hwndDlg, IDC_CHK_SUBWINDOW); + + if(options_changes.subcontact_windows) { + hw = GetDlgItem(hwndDlg, IDC_CHK_METAHISTORY); + EnableWindow(hw, TRUE); + hw = GetDlgItem(hwndDlg, IDC_CHK_SUBHISTORY); + CheckDlgButton(hwndDlg, IDC_CHK_SUBHISTORY, TRUE); + EnableWindow(hw, FALSE); + options_changes.subhistory = TRUE; + } else { + hw = GetDlgItem(hwndDlg, IDC_CHK_SUBHISTORY); + EnableWindow(hw, TRUE); + hw = GetDlgItem(hwndDlg, IDC_CHK_METAHISTORY); + CheckDlgButton(hwndDlg, IDC_CHK_METAHISTORY, TRUE); + EnableWindow(hw, FALSE); + options_changes.metahistory = TRUE; + } + SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + break; + case IDC_CHK_LOCKHANDLE: + options_changes.lockHandle = IsDlgButtonChecked(hwndDlg, IDC_CHK_LOCKHANDLE); + SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + break; + } + } else if ( HIWORD( wParam ) == EN_CHANGE && ( HWND )lParam == GetFocus()) { + SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + } + break; + + case WM_NOTIFY: + if (((LPNMHDR)lParam)->code == PSN_APPLY ) { + hw = GetDlgItem(hwndDlg, IDC_ED_DAYS); + GetWindowText(hw, buff, 512); + if(strlen(buff) > 0) + options_changes.days_history = atoi(buff); + + options = options_changes; + Meta_WriteOptions(&options); + + Meta_SuppressStatus(options.suppress_status); + Meta_SetAllNicks(); + return TRUE; + } + break; + } + + return FALSE; +} + +int Meta_WriteOptions(MetaOptions *opt) { + DBWriteContactSettingByte(NULL, META_PROTO, "SetDefaultOnRecv", (BYTE)(opt->set_default_on_recv ? 1 : 0)); + DBWriteContactSettingByte(NULL, META_PROTO, "TempDefault", (BYTE)(opt->temp_default ? 1 : 0)); + DBWriteContactSettingByte(NULL, META_PROTO, "AlwaysUseDefault", (BYTE)(opt->always_use_default ? 1 : 0)); + DBWriteContactSettingByte(NULL, META_PROTO, "SuppressStatus", (BYTE)(opt->suppress_status ? 1 : 0)); + DBWriteContactSettingWord(NULL, META_PROTO, "MenuContactLabel", (WORD)opt->menu_contact_label); + DBWriteContactSettingWord(NULL, META_PROTO, "MenuContactFunction", (WORD)opt->menu_function); + DBWriteContactSettingWord(NULL, META_PROTO, "CListContactName", (WORD)opt->clist_contact_name); + DBWriteContactSettingByte(NULL, META_PROTO, "SuppressProto", (BYTE)(opt->suppress_proto ? 1 : 0)); + DBWriteContactSettingByte(NULL, META_PROTO, "CopyHistory", (BYTE)(opt->copy_subcontact_history ? 1 : 0)); + DBWriteContactSettingDword(NULL, META_PROTO, "DaysHistory", (DWORD)(opt->days_history)); + DBWriteContactSettingDword(NULL, META_PROTO, "SetStatusFromOfflineDelay", (DWORD)(opt->set_status_from_offline_delay)); + DBWriteContactSettingByte(NULL, META_PROTO, "SubcontactWindows", (BYTE)(opt->subcontact_windows ? 1 : 0)); + DBWriteContactSettingByte(NULL, META_PROTO, "CopyData", (BYTE)(opt->copydata ? 1 : 0)); + DBWriteContactSettingByte(NULL, META_PROTO, "LockHandle", (BYTE)(opt->lockHandle ? 1 : 0)); + DBWriteContactSettingByte(NULL, META_PROTO, "MetaMessageIcon", (BYTE)(opt->flash_meta_message_icon ? 1 : 0)); + DBWriteContactSettingByte(NULL, META_PROTO, "CopyUserInfo", (BYTE)(opt->copy_userinfo ? 1 : 0)); + + if(!opt->subcontact_windows) + DBWriteContactSettingByte(NULL, META_PROTO, "MetaHistory", 1); + else + DBWriteContactSettingByte(NULL, META_PROTO, "MetaHistory", (BYTE)(opt->metahistory ? 1 : 0)); + + if(opt->subcontact_windows) + DBWriteContactSettingByte(NULL, META_PROTO, "SubcontactHistory", 1); + else + DBWriteContactSettingByte(NULL, META_PROTO, "SubcontactHistory", (BYTE)(opt->subhistory ? 1 : 0)); + return 0; + + DBWriteContactSettingByte(NULL, META_PROTO, "UseProtoRecv", (BYTE)(opt->use_proto_recv ? 1 : 0)); +} + +int Meta_ReadOptions(MetaOptions *opt) { + opt->set_default_on_recv = (DBGetContactSettingByte(NULL, META_PROTO, "SetDefaultOnRecv", 1) == 1 ? TRUE : FALSE); + opt->temp_default = (DBGetContactSettingByte(NULL, META_PROTO, "TempDefault", 0) == 1 ? TRUE : FALSE); + opt->always_use_default = (DBGetContactSettingByte(NULL, META_PROTO, "AlwaysUseDefault", 0) == 1 ? TRUE : FALSE); + opt->suppress_status = (DBGetContactSettingByte(NULL, META_PROTO, "SuppressStatus", 1) == 1 ? TRUE : FALSE); + opt->menu_contact_label = (int)DBGetContactSettingWord(NULL, META_PROTO, "MenuContactLabel", DNT_UID); + opt->menu_function = (int)DBGetContactSettingWord(NULL, META_PROTO, "MenuContactFunction", FT_MENU); + opt->clist_contact_name = (int)DBGetContactSettingWord(NULL, META_PROTO, "CListContactName", CNNT_NICK); + opt->suppress_proto = (DBGetContactSettingByte(NULL, META_PROTO, "SuppressProto", 0) == 1 ? TRUE : FALSE); + opt->copy_subcontact_history = (DBGetContactSettingByte(NULL, META_PROTO, "CopyHistory", 1) == 1 ? TRUE : FALSE); + opt->days_history = (int)DBGetContactSettingDword(NULL, META_PROTO, "DaysHistory", 14); + opt->set_status_from_offline_delay = (int)DBGetContactSettingDword(NULL, META_PROTO, "SetStatusFromOfflineDelay", DEFAULT_SET_STATUS_SLEEP_TIME); + opt->subcontact_windows = (DBGetContactSettingByte(NULL, META_PROTO, "SubcontactWindows", 0) == 1 ? TRUE : FALSE); + opt->copydata = (DBGetContactSettingByte(NULL, META_PROTO, "CopyData", 1) == 1 ? TRUE : FALSE); + opt->lockHandle = (DBGetContactSettingByte(NULL, META_PROTO, "LockHandle", 0) == 1 ? TRUE : FALSE); + opt->flash_meta_message_icon = (DBGetContactSettingByte(NULL, META_PROTO, "MetaMessageIcon", 1) == 1 ? TRUE : FALSE); + opt->copy_userinfo = (DBGetContactSettingByte(NULL, META_PROTO, "CopyUserInfo", 1) == 1 ? TRUE : FALSE); + + if(!opt->subcontact_windows) + opt->metahistory = TRUE; + else + opt->metahistory = (DBGetContactSettingByte(NULL, META_PROTO, "MetaHistory", 1) == 1 ? TRUE : FALSE); + + if(opt->subcontact_windows) + opt->subhistory = TRUE; + else + opt->subhistory = (DBGetContactSettingByte(NULL, META_PROTO, "SubcontactHistory", 1) == 1 ? TRUE : FALSE); + + opt->use_proto_recv = (DBGetContactSettingByte(NULL, META_PROTO, "UseProtoRecv", 1) == 1 ? TRUE : FALSE); + return 0; +} + -- cgit v1.2.3