📄 prefs.cpp
字号:
/*************************************************************************** * Copyright (C) 2004 by Emil Stoyanov * * emosto@users.sourceforge.net * * * * 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 "prefs.h"Prefs::Prefs(QObject *parent, const char *name) : QObject(parent){ this->setObjectName(name); setInputDevice(0); setOutputDevice(0); setRingDevice(0); setFilterFlag(IAXC_FILTER_AAGC|IAXC_FILTER_ECHO|IAXC_FILTER_DENOISE|IAXC_FILTER_CN); silenceThreshold = -99; // default}Prefs::~Prefs(){}void Prefs::loadSettings(){ // Load CallRecords although not settings per se! loadCallRecords(); loadAccounts(); // load device settings loadDeviceSettings(); // load filter settings loadFilterSettings(); // load miscellaneous settings loadMiscSettings(); // load session settings loadSessionSettings();}void Prefs::loadAccounts(){ QSettings * accSettings = getSettings(); // read stored account names accSettings->beginGroup(QString::fromUtf8("accounts")); QStringList accs = accSettings->childGroups(); defaultAccountId = accSettings->value(QString::fromUtf8("defaultAccountId"),QString::fromUtf8("0")).toString(); delete accSettings; // prepare the accounts vector //accounts.setAutoDelete(true); accounts.clear(); for (QStringList::Iterator it = accs.begin();it!=accs.end(); ++it) { // get the name of the next acount QString nextAcc = *it; // create an instance with that name Account *account = new Account(nextAcc); // set the values account->load(); // and append the account to the list of accounts accounts.append(account); }}void Prefs::loadCallRecords(){ QSettings * callRecordSettings = getSettings(); // read stored account names callRecordSettings->beginGroup(QString::fromUtf8("callregister/calls")); QStringList callRecordsFromSettings = callRecordSettings->childGroups(); delete callRecordSettings; // prepare the accounts vector //accounts.setAutoDelete(true); this->callrecords.clear(); int callRecordCounter = 0; int maxCallRecords = 20; // This is a fixed value that should actually be configurable! //Do reverse recursion such that you remove the oldest records!! for (int i = callRecordsFromSettings.size()-1; i >= 0; --i) { //QMessageBox::information(NULL, QString::fromUtf8("Yakaphone"), QString::number(i)); // create an instance with that name CallRecord *callRecord = new CallRecord(); // set the values callRecord->load(callRecordsFromSettings.at(i)); if (callRecord->getCallerIdNumber() == CallRecord::mailBoxCallerIdNumber) { // Remove calls to mailbox from list!!! callRecord->remove(); } else { if(callRecordCounter < maxCallRecords) { // and append the call record to the list of call records! this->callrecords.append(callRecord); } else { callRecord->remove(); } callRecordCounter++; } } /* for (QStringList::Iterator it = callRecords.begin();it!=callRecords.end(); ++it) { // get the name of the next acount QString nextCallRecord = *it; // create an instance with that name CallRecord *callRecord = new CallRecord(); // set the values callRecord->load(nextCallRecord); if(callRecordCounter < maxCallRecords) { // and append the call record to the list of call records! callrecords.append(callRecord); } else { callRecord->remove(); } callRecordCounter++; } */}void Prefs::saveSettings(){ // save all accounts for (int i=0;i<accounts.count();i++) saveAccount(i); // save the defaultAccountId QSettings * accSettings = getSettings(); accSettings->setValue(QString::fromUtf8("/accounts/defaultAccountId"), defaultAccountId); delete accSettings; // save device settings saveDeviceSettings(); // save filter settings saveFilterSettings(); // save miscellaneous settings saveMiscSettings();}Account* Prefs::getAccount(int i){ return accounts.at(i);}QList<Account*> Prefs:: getAccounts(){ return accounts;}CallRecord* Prefs::getCallRecord(int i){ return callrecords.at(i);}QList<CallRecord*> Prefs:: getCallRecords(){ return callrecords;}int Prefs::createNewAccount(QString accName){ Account* newAcc = new Account(accName); addAccount(newAcc); return accounts.count()-1;}void Prefs::addAccount(Account* acc){ accounts.append(acc);}void Prefs::removeAccount(int accNumber){ Account* acc = accounts.at(accNumber); acc->remove(); accounts.removeAt(accNumber);}void Prefs::saveAccount(int accNumber){ Account* acc = accounts.at(accNumber); acc->save();}QString Prefs::getDefaultAccountId(){ return defaultAccountId;}void Prefs::setDefaultAccountId(QString df){ defaultAccountId = df;}void Prefs::detectDevices(){ struct iaxc_audio_device *devices; int devNumber,input,output,ring; long devCapabilities; QString devName; int result = iaxc_audio_devices_get(&devices, &devNumber, &input, &output, &ring); //fprintf(stderr, "iaxc_aduio_devices_get = %d\n", result); inputDeviceNames.clear(); outputDeviceNames.clear(); ringDeviceNames.clear(); for(int i=0; i<devNumber; i++) { devCapabilities = devices->capabilities; devName = QString::fromAscii(devices->name); if(devCapabilities & IAXC_AD_INPUT) inputDeviceNames.append(devName); if(devCapabilities & IAXC_AD_OUTPUT) outputDeviceNames.append(devName); if(devCapabilities & IAXC_AD_RING) ringDeviceNames.append(devName); devices++; }}void Prefs::updateDevices(){ iaxc_audio_devices_set(inputDevice,outputDevice,ringDevice);}void Prefs::loadDeviceSettings(){ QSettings * settings = getSettings(); inputDevice = settings->value(QString::fromUtf8("/devices/inputDevice"),0).toInt(); outputDevice = settings->value(QString::fromUtf8("/devices/outputDevice"),0).toInt(); ringDevice = settings->value(QString::fromUtf8("/devices/ringDevice"),0).toInt(); buzzerRing = settings->value(QString::fromUtf8("/devices/buzzerRing"),false).toBool(); delete settings;}void Prefs::saveDeviceSettings(){ QSettings * settings = getSettings(); settings->setValue(QString::fromUtf8("/devices/inputDevice"), inputDevice); settings->setValue(QString::fromUtf8("/devices/outputDevice"), outputDevice); settings->setValue(QString::fromUtf8("/devices/ringDevice"), ringDevice); settings->setValue(QString::fromUtf8("/devices/buzzerRing"), buzzerRing); delete settings;}void Prefs::saveMiscSettings(){ QSettings * settings = getSettings(); settings->setValue(QString::fromUtf8("/misc/docked"), docked); settings->setValue(QString::fromUtf8("/misc/hiddenOnStartup"), hiddenOnStartup); settings->setValue(QString::fromUtf8("/misc/connectedOnStartup"), connectedOnStartup); settings->setValue(QString::fromUtf8("/misc/raiseWindow"), raiseWindow); settings->setValue(QString::fromUtf8("/misc/maxCalls"), maxCallsNumber); settings->setValue(QString::fromUtf8("/misc/ExecuteCommandOnRing"), execCommandOnRing); settings->setValue(QString::fromUtf8("/misc/CommandOnRing"), commandOnRing); delete settings;}void Prefs::loadMiscSettings(){ QSettings * settings = getSettings(); setDocked(settings->value(QString::fromUtf8("/misc/docked"),false).toBool()); setHiddenOnStartup(settings->value(QString::fromUtf8("/misc/hiddenOnStartup"),false).toBool()); setConnectedOnStartup(settings->value(QString::fromUtf8("/misc/connectedOnStartup"),true).toBool()); setRaiseWindow(settings->value(QString::fromUtf8("/misc/raiseWindow"),true).toBool()); setMaxCalls(settings->value(QString::fromUtf8("/misc/maxCalls"),1).toInt()); setExecCommandOnRing(settings->value(QString::fromUtf8("/misc/ExecuteCommandOnRing"), false).toBool()); setCommandOnRing(settings->value(QString::fromUtf8("/misc/CommandOnRing"), QString::fromUtf8("")).toString()); delete settings;}void Prefs::loadFilterSettings(){ QSettings * settings = getSettings(); filterFlag = 0; if (settings->value(QString::fromUtf8("/filters/NoiseReduction"),true).toBool()) filterFlag |= IAXC_FILTER_DENOISE; if (settings->value(QString::fromUtf8("/filters/AGC"),true).toBool()) filterFlag |= IAXC_FILTER_AGC; if (settings->value(QString::fromUtf8("/filters/EchoCancelation"),false).toBool()) filterFlag |= IAXC_FILTER_ECHO;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -