/* * callback function for tab 3 options page */ INT_PTR CALLBACK DlgProcOpts_Tab3(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch ( msg ) { case WM_INITDIALOG: { //executed once during init of each tab, on each enter to miranda options mirfoxMiranda.getMirfoxData().setTab3OptionsState(MFENUM_OPTIONS_INIT); TranslateDialogDefault(hwndDlg); //protocol list initialization HWND hAccountsList = GetDlgItem(hwndDlg, IDC3_PROTOCOLS_LIST); ListView_SetExtendedListViewStyleEx(hAccountsList, LVS_EX_FULLROWSELECT|LVS_EX_CHECKBOXES, LVS_EX_FULLROWSELECT|LVS_EX_CHECKBOXES); LVCOLUMN lvCol = {0}; lvCol.mask = LVCF_WIDTH|LVCF_TEXT; lvCol.pszText=TranslateT("Protocol"); lvCol.cx = 260; //column width ListView_InsertColumn(hAccountsList, 0, &lvCol); LVITEM lvItem = {0}; lvItem.mask=LVIF_TEXT|LVIF_PARAM; lvItem.iItem=0; lvItem.iSubItem=0; //get accounts data from mirfoxData boost::ptr_list<MirandaAccount> * mirandaAccountsPtr = mirfoxMiranda.getMirfoxData().getMirandaAccounts(); boost::ptr_list<MirandaAccount>::iterator mirandaAccountsIter; for (mirandaAccountsIter = mirandaAccountsPtr->begin(); mirandaAccountsIter != mirandaAccountsPtr->end(); mirandaAccountsIter++){ lvItem.pszText = mirandaAccountsIter->tszAccountName; //http://www.experts-exchange.com/Programming/Languages/CPP/Q_20175412.html - must duplicate string lvItem.lParam = (LPARAM)_strdup(mirandaAccountsIter->szModuleName); ListView_InsertItem(hAccountsList,&lvItem);//winapi function MFENUM_MIRANDAACCOUNT_STATE accountState = mirandaAccountsIter->accountState; if (accountState == MFENUM_MIRANDAACCOUNT_STATE_ON){ ListView_SetCheckState(hAccountsList, lvItem.iItem, 1 ); } else { ListView_SetCheckState(hAccountsList, lvItem.iItem, 0 ); } lvItem.iItem++; } //protocol list initialization - end mirfoxMiranda.getMirfoxData().setTab3OptionsState(MFENUM_OPTIONS_WORK); return FALSE; } case WM_COMMAND: { if (mirfoxMiranda.getMirfoxData().getTab3OptionsState() != MFENUM_OPTIONS_WORK){ break; //options not inited yet } break; } case WM_NOTIFY: { //executed on each change tab at options or after [OK] if (mirfoxMiranda.getMirfoxData().getTab3OptionsState() != MFENUM_OPTIONS_WORK){ break; //options not inited yet } if (((NMHDR*)lParam)->idFrom == IDC3_PROTOCOLS_LIST) { if (((NMHDR*)lParam)->code== LVN_ITEMCHANGED) { NMLISTVIEW *nmlv = (NMLISTVIEW *)lParam; if (/*IsWindowVisible(GetDlgItem(hwndDlg,IDC_PROTOCOLLIST)) && */ ((nmlv->uNewState ^ nmlv->uOldState) & LVIS_STATEIMAGEMASK)) { SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); } } } if (((LPNMHDR)lParam)->idFrom == 0 && ((LPNMHDR)lParam)->code == PSN_APPLY ){ //SaveOptions from tab3 mirfoxData to miranda database HWND hList = GetDlgItem(hwndDlg, IDC3_PROTOCOLS_LIST); LVITEM lvItem = {0}; lvItem.mask = LVIF_PARAM; for (int i=0; i<ListView_GetItemCount(hList); i++) { lvItem.iItem = i; lvItem.iSubItem = 0; ListView_GetItem(hList, &lvItem); char * accountId ((char *)lvItem.lParam); BYTE accountStateB = (BYTE)ListView_GetCheckState(hList, lvItem.iItem); MFENUM_MIRANDAACCOUNT_STATE accountState; if (accountStateB == 0){ accountState = MFENUM_MIRANDAACCOUNT_STATE_OFF; } else if (accountStateB == 1){ accountState = MFENUM_MIRANDAACCOUNT_STATE_ON; } else { //todo errors handling accountState = MFENUM_MIRANDAACCOUNT_STATE_ON; } //save to mirfoxData int result = mirfoxMiranda.getMirfoxData().updateMirandaAccountState(accountId, accountState); if (result != 0){ //todo errors handling } //save to db 1 - on, 2 - off std::string mirandaAccountDBKey("ACCOUNTSTATE_"); mirandaAccountDBKey += accountId; if (accountState == MFENUM_MIRANDAACCOUNT_STATE_OFF){ db_set_b(0, PLUGIN_DB_ID, mirandaAccountDBKey.c_str(), 2); } else { db_set_b(0, PLUGIN_DB_ID, mirandaAccountDBKey.c_str(), 1); } } //end for } break; } case WM_DESTROY: break; } return 0; }
/** * function changes db module name from "MirfoxMiranda" (used before 0.3.0.0) to "Mirfox" */ void MirandaUtils::translateOldDBNames() { //settings "clientsProfilesFilterCheckbox", "clientsProfilesFilterString" int opt1KeyValue = db_get_b(0, OLD_PLUGIN_DB_ID, "clientsProfilesFilterCheckbox", 0); if (opt1KeyValue != 0){ db_set_b(0, PLUGIN_DB_ID, "clientsProfilesFilterCheckbox", opt1KeyValue); db_unset(0, OLD_PLUGIN_DB_ID, "clientsProfilesFilterCheckbox"); logger->log(L"TranslateOldDBNames: 'clientsProfilesFilterCheckbox' db entry found and moved"); } else { logger->log(L"TranslateOldDBNames: no old settings found. returning."); return; } DBVARIANT opt2Dbv = {0}; INT_PTR opt2Result = db_get_s(0, OLD_PLUGIN_DB_ID, "clientsProfilesFilterString", &opt2Dbv, DBVT_TCHAR); if (opt2Result == 0){ //success std::wstring clientsProfilesFilterString = opt2Dbv.pwszVal; db_set_ts(0, PLUGIN_DB_ID, "clientsProfilesFilterString", clientsProfilesFilterString.c_str()); db_unset(0, OLD_PLUGIN_DB_ID, "clientsProfilesFilterString"); logger->log(L"TranslateOldDBNames: 'clientsProfilesFilterString' db entry found and moved"); } db_free(&opt2Dbv); //account's settings "ACCOUNTSTATE_" int accountsTmpCount = 0; PROTOACCOUNT **accountsTmp; CallService(MS_PROTO_ENUMACCOUNTS, (WPARAM)&accountsTmpCount, (LPARAM)&accountsTmp); for(int i=0; i<accountsTmpCount; i++) { logger->log_p(L"TranslateOldDBNames: found ACCOUNT: [%s] protocol: [%S]", accountsTmp[i]->tszAccountName, accountsTmp[i]->szProtoName); std::string mirandaAccountDBKey("ACCOUNTSTATE_"); mirandaAccountDBKey += accountsTmp[i]->szModuleName; int keyValue = db_get_b(0, OLD_PLUGIN_DB_ID, mirandaAccountDBKey.c_str(), 0); if (keyValue != 0){ db_set_b(0, PLUGIN_DB_ID, mirandaAccountDBKey.c_str(), keyValue); db_unset(0, OLD_PLUGIN_DB_ID, mirandaAccountDBKey.c_str()); logger->log(L"TranslateOldDBNames: ACCOUNT db entry found and moved"); } } //contacts "state" for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)){ logger->log_p(L"TranslateOldDBNames: found CONTACT: [" SCNuPTR L"]", hContact); int keyValue = db_get_b(hContact, OLD_PLUGIN_DB_ID, "state", 0); if (keyValue != 0){ db_set_b(hContact, PLUGIN_DB_ID, "state", keyValue); db_unset(hContact, OLD_PLUGIN_DB_ID, "state"); logger->log(L"TranslateOldDBNames: CONTACT db entry found and moved"); } } //delete db module CallService(MS_DB_MODULE_DELETE, 0, (LPARAM)OLD_PLUGIN_DB_ID); }
void MirfoxData::initializeMirandaAccounts() { clearMirandaAccounts(); int accountsCount = 0; PROTOACCOUNT **accounts; //get accounts from Miranda by CallService MS_PROTO_ENUMACCOUNTS CallService(MS_PROTO_ENUMACCOUNTS, (WPARAM)&accountsCount, (LPARAM)&accounts); uint64_t protocolId = 1; for(int i=0; i<accountsCount; i++) { //checking account if(accounts[i]->bIsEnabled == 0){ continue; } if(accounts[i]->bDynDisabled != 0){ continue; } //add to list MirandaAccount* mirandaAccountItemPtr = new MirandaAccount( protocolId, accounts[i]->szModuleName, accounts[i]->tszAccountName, accounts[i]->szProtoName, accounts[i]->iOrder ); MFLogger* logger = MFLogger::getInstance(); logger->log_p(L"initializeMirandaAccounts: tszAccountName: [%s] protocol: [%S]", accounts[i]->tszAccountName, accounts[i]->szProtoName ); protocolId++; std::string mirandaAccountDBKey("ACCOUNTSTATE_"); mirandaAccountDBKey += accounts[i]->szModuleName; int keyValue = db_get_b(0, PLUGIN_DB_ID, mirandaAccountDBKey.c_str(), 0); if (keyValue == 1 || keyValue == 2){ //setting exist if (keyValue == 1){ mirandaAccountItemPtr->accountState = MFENUM_MIRANDAACCOUNT_STATE_ON; //1 } else { mirandaAccountItemPtr->accountState = MFENUM_MIRANDAACCOUNT_STATE_OFF; //2 } } else { //setting does not exist, or is invalid -> save default setting (1 - ON) if (MirfoxData::getAccountDefaultState(mirandaAccountItemPtr) == 1){ //on = 1 mirandaAccountItemPtr->accountState = MFENUM_MIRANDAACCOUNT_STATE_ON; //1 db_set_b(0, PLUGIN_DB_ID, mirandaAccountDBKey.c_str(), 1); } else { //off = 2 mirandaAccountItemPtr->accountState = MFENUM_MIRANDAACCOUNT_STATE_OFF; //2 db_set_b(0, PLUGIN_DB_ID, mirandaAccountDBKey.c_str(), 2); } } addMirandaAccount(mirandaAccountItemPtr); } //TODO - sort by mirandaAccount.displayOrder }