⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainwindow.cpp

📁 YakaPhone, 著名的VOIP客户端, 需要使用iax库和QT库.界面很漂亮
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	
	this->preferences->setOutputDevice(this->settingsDialog->comboBox_AudioOutput->currentIndex());
	this->preferences->setInputDevice(this->settingsDialog->comboBox_AudioInput->currentIndex());
	this->preferences->setRingDevice(this->settingsDialog->comboBox_AudioRing->currentIndex());
	this->preferences->setBuzzerRing(this->settingsDialog->checkBox_RingBuzzer->isChecked());
	
	int aFilterFlag = 0;
	if (this->settingsDialog->checkBox_NoiseRecuction->isChecked()) aFilterFlag |= IAXC_FILTER_DENOISE;
	if (this->settingsDialog->checkBox_AnalogAutomaticGainControl->isChecked()) aFilterFlag |= IAXC_FILTER_AAGC;
	if (this->settingsDialog->checkBox_AutomaticGainControl->isChecked()) aFilterFlag |= IAXC_FILTER_AGC;
	if (this->settingsDialog->checkBox_EchoCancellation->isChecked()) aFilterFlag |= IAXC_FILTER_ECHO;
	if (this->settingsDialog->checkBox_ComfortNoise->isChecked()) aFilterFlag |= IAXC_FILTER_CN;
	this->preferences->setFilterFlag(aFilterFlag);
	if (this->settingsDialog->checkBox_SilenceSuppression->isChecked())
	{
		this->preferences->setSilenceThreshold(1);//auto
	}
	else
	{
		this->preferences->setSilenceThreshold(-99);
	}
  	
	this->defaultAccount->save();
	this->preferences->saveSettings();
	
	this->preferences->updateDevices();
	
this->startTheMusic(true, true); // Start the music each time u change settings	

}

void MainWindow::settingsRejected()
{
	
}

void MainWindow::createDefaultAccount()
{
	QString accountName = QString::fromUtf8("Default_Account");
	int accPos = this->preferences->createNewAccount(accountName);
	this->defaultAccount = this->preferences->getAccount(accPos);
	
	//Important to make this default and save it !!!!
	this->preferences->setDefaultAccountId(this->defaultAccount->accId);
	this->preferences->saveAccount(accPos);
	
	this->preferences->saveSettings();
	
	//this->statusbar->showMessage(this->defaultAccount->accId);
}

void MainWindow::initIAX(IaxWrapper* wrp)
{
	this->wrapper = wrp;
	
    connect(this->wrapper , SIGNAL( signalFree() ), this, SLOT( handleIaxWrapperEventFree() ) );
    connect(this->wrapper , SIGNAL( signalBusy(int) ), this, SLOT( handleIaxWrapperEventBusy(int) ) );
    connect(this->wrapper , SIGNAL( signalTransfer(int) ), this, SLOT( handleIaxWrapperEventTransfer(int) ) );	
    connect(this->wrapper , SIGNAL( signalCalling(int, QString) ), this, SLOT( handleIaxWrapperEventCalling(int, QString) ) );
    connect(this->wrapper , SIGNAL( signalAnsweredCall(int) ), this, SLOT( handleIaxWrapperEventAnsweredCall(int) ) );
    connect(this->wrapper , SIGNAL( signalHoldCall(int) ), this, SLOT( handleIaxWrapperEventHoldCall(int) ) );
    connect(this->wrapper , SIGNAL( signalResumedCall(int) ), this, SLOT( handleIaxWrapperEventResumedCall(int) ) );
    connect(this->wrapper , SIGNAL( signalOutgoingRinging(int) ), this, SLOT( handleIaxWrapperEventOutgoingRinging(int) ) );
    connect(this->wrapper , SIGNAL( signalIncomingRinging(int) ), this, SLOT( handleIaxWrapperEventIncomingRinging(int) ) );
    connect(this->wrapper , SIGNAL( signalComplete(int) ), this, SLOT( handleIaxWrapperEventComplete(int) ) );
    connect(this->wrapper , SIGNAL( signalInactive(int) ), this, SLOT( handleIaxWrapperEventInactive(int) ) );
    connect(this->wrapper , SIGNAL( signalRegistered() ), this, SLOT( handleIaxWrapperEventRegistered() ) );
    connect(this->wrapper , SIGNAL( signalUnregistered() ), this, SLOT( handleIaxWrapperEventUnregistered() ) );
    connect(this->wrapper , SIGNAL( signalLevels(int, int, int)), this, SLOT( handleIaxWrapperEventLevels(int,int, int) ) );
    connect(this->wrapper , SIGNAL( signalRegistrationRequested(Account*) ), this, SLOT( handleIaxWrapperEventRegistrationRequested(Account*) ) );
    connect(this->wrapper , SIGNAL( fatalError(QString) ), this, SLOT( fatalError(QString) ));
    //connect(this->wrapper , SIGNAL( signalDebug(const char*) ), this, SLOT( slotLogWindow(const char*) ));
    connect(this->wrapper , SIGNAL(callTime(int, int, int, int ) ), this, SLOT(updateCallDuration(int, int, int, int )) );
   
   	this->preferences = this->wrapper->getSettings();
   	this->preferences->loadSettings(); // Very Important to get everything on and going !!!
   	
   	QString defaultAcctID = this->preferences->getDefaultAccountId();  	
   	this->defaultAccount = this->preferences->findAccountById(defaultAcctID);
   	if(this->defaultAccount == NULL)
   	{
   		this->createDefaultAccount();
   	}
 
    connect(this->defaultAccount , SIGNAL( signalRegistrationInactive(Account*) ), this, SLOT( handleIaxWrapperEventRegistrationInactive(Account*) ) );
    connect(this->defaultAccount , SIGNAL( signalRegistrationConnecting(Account*) ), this, SLOT( handleIaxWrapperEventRegistrationConnecting(Account*) ) );    	
    connect(this->defaultAccount , SIGNAL( signalRegistrationAccepted(Account*) ), this, SLOT( handleIaxWrapperEventRegistrationAccepted(Account*) ) );
    connect(this->defaultAccount , SIGNAL( signalRegistrationRejected(Account*) ), this, SLOT( handleIaxWrapperEventRegistrationRejected(Account*) ) );
    connect(this->defaultAccount , SIGNAL( signalRegistrationTimeout(Account*) ), this, SLOT( handleIaxWrapperEventRegistrationTimeout(Account*) ) );
       	
   	bool initOK = this->wrapper->init_iax_client();
   	
   	this->startTheMusic(initOK, false);
}

void MainWindow::startTheMusic(bool initOK, bool changedSettings)
{   	  	
   	// Just in case no user is set ask for the settings...
   	// This applies especially for the first start!
   	if(this->defaultAccount->username == QString::fromUtf8(""))
   	{
   		this->settings();
   	}
   	
   	if(initOK)
   	{  		
   		this->wrapper->registerWithServer();	
    	//QMessageBox::information(this, "Account:", this->defaultAccount->username ); 		
   	}
   	else
   	{
   		//this->statusbar->showMessage(QString::fromUtf8("init NOT OK"));
   	}	
}

void MainWindow::stopTheMusic()
{
	if(this->wrapper != NULL)
	{
		this->wrapper->unregisterFromServer();
	}
	else
	{
		
	}
}
void MainWindow::fatalError(QString errorMsg)
{
	QString fatalMsg = QString::fromUtf8("Error message:") + errorMsg + QString::fromUtf8("\nApplication will exit!\n");
	QMessageBox::information(this, QString::fromUtf8("Yakaphone"), fatalMsg);
    qFatal(fatalMsg.toAscii());
    close();
    QApplication::exit();
}
  
void MainWindow::handleIaxWrapperEventRegistered()
{
	this->label_StatusText->setText(QString::fromUtf8("Registered"));
	this->updateUIControlsEnabled(true, false, true, true);
	this->updateUIControlsIcons(QString::fromUtf8(":/controlPad/Dial_a.png"), 	QString::fromUtf8(":/controlPad/Hold_a.png"));			
}

void MainWindow::handleIaxWrapperEventUnregistered()
{
	this->label_StatusText->setText(QString::fromUtf8("Unregistered"));
	this->updateUIControlsEnabled(false, false, false, true);
	this->updateUIControlsIcons(QString::fromUtf8(":/controlPad/Dial_a.png"), 	QString::fromUtf8(":/controlPad/Hold_a.png"));		
}

void MainWindow::handleIaxWrapperEventCalling(int callNo, QString status)
{
	this->label_StatusText->setText(QString::fromUtf8("Calling [") + QString::number(callNo) + QString::fromUtf8("]..."));
	//this->label_StatusText->setText(tr("Calling [") + QString::number(callNo) + "]: " + status);
	//this->label_StatusText->setText(tr("Calling..."));
	this->updateUIControlsEnabled(true, false, false, false);
	this->updateUIControlsIcons(QString::fromUtf8(":/controlPad/HangUp_a.png"), QString::fromUtf8(":/controlPad/Hold_a.png"));	
}

void MainWindow::handleIaxWrapperEventAnsweredCall(int callNo)
{
	this->label_StatusText->setText(QString::fromUtf8("AnsweredCall [") + QString::number(callNo) + QString::fromUtf8("]"));
	this->updateUIControlsEnabled(true, true, false, false);
	this->updateUIControlsIcons(QString::fromUtf8(":/controlPad/Drop_a.png"), QString::fromUtf8(":/controlPad/Hold_a.png"));	
}

void MainWindow::handleIaxWrapperEventHoldCall(int callNo)
{
	this->label_StatusText->setText(QString::fromUtf8("HoldCall [") + QString::number(callNo) + QString::fromUtf8("]"));
	this->updateUIControlsEnabled(true, true, false, false);
	this->updateUIControlsIcons(QString::fromUtf8(":/controlPad/HangUp_a.png"), 	QString::fromUtf8(":/controlPad/Resume_a.png"));		
}

void MainWindow::handleIaxWrapperEventResumedCall(int callNo)
{
	this->label_StatusText->setText(QString::fromUtf8("ResumedCall [") + QString::number(callNo) + QString::fromUtf8("]"));
	this->updateUIControlsEnabled(true, true, false, false);
	this->updateUIControlsIcons(QString::fromUtf8(":/controlPad/HangUp_a.png"), 	QString::fromUtf8(":/controlPad/Hold_a.png"));		
}

void MainWindow::handleIaxWrapperEventLevels(int inValue, int outValue, int threshold)
{
	int norm_inValue_100 = inValue > 100 ? 0 : inValue;
	int norm_outValue_100 = outValue > 100 ? 0 : outValue;
	
	this->progressBar_Mocrophone->setValue(norm_inValue_100);
	this->progressBar_Loudspeaker->setValue(norm_outValue_100);
}
void MainWindow::handleIaxWrapperEventFree()
{
	this->label_StatusText->setText(QString::fromUtf8("Free"));
	this->updateUIControlsEnabled(true, true, false, true);
	this->updateUIControlsIcons(QString::fromUtf8(":/controlPad/HangUp_a.png"), QString::fromUtf8(":/controlPad/Hold_a.png"));		
}

void MainWindow::handleIaxWrapperEventBusy(int callNo)
{
	this->label_StatusText->setText(QString::fromUtf8("Busy..."));
	this->updateUIControlsEnabled(true, false, false, false);
	this->updateUIControlsIcons(QString::fromUtf8(":/controlPad/HangUp_a.png"),  QString::fromUtf8(":/controlPad/Hold_a.png"));		
}

void MainWindow::handleIaxWrapperEventTransfer(int callNo)
{
	this->label_StatusText->setText(QString::fromUtf8("Transfer"));
//	this->updateUIControlsEnabled(true, false, false, false, false);
//	this->updateUIControlsIcons(":/controlPad/HangUp_a.png", 	":/controlPad/Hold_a.png");		
}
void MainWindow::handleIaxWrapperEventOutgoingRinging(int callNo)
{
	this->label_StatusText->setText(QString::fromUtf8("Ringing [OUT]"));
	this->updateUIControlsEnabled(true, false, false, false);
	this->updateUIControlsIcons(QString::fromUtf8(":/controlPad/HangUp_a.png"), 	QString::fromUtf8(":/controlPad/Hold_a.png"));		
}

void MainWindow::handleIaxWrapperEventIncomingRinging(int callNo)
{
	this->label_StatusText->setText(QString::fromUtf8("Ringing [IN]"));
	this->label_TelNumber->setText(QString::number(callNo));
	
	this->updateUIControlsEnabled(true, false, false, false);
	this->updateUIControlsIcons(QString::fromUtf8(":/controlPad/Answer_a.png"), QString::fromUtf8(":/controlPad/Hold_a.png"));		
}

void MainWindow::handleIaxWrapperEventComplete(int callNo)
{
	this->label_StatusText->setText(QString::fromUtf8("Connected..."));
	this->updateUIControlsEnabled(true, true, false, false);
	this->updateUIControlsIcons(QString::fromUtf8(":/controlPad/HangUp_a.png"), QString::fromUtf8(":/controlPad/Hold_a.png"));	
}

void MainWindow::handleIaxWrapperEventInactive(int callNo)
{
	this->justDroppedForEdit = true;
	
	this->callRecordCounter = -1;
	this->preferences->loadCallRecords();
	this->pushButton_CallRecord_Backward->setEnabled(true);
	this->pushButton_CallRecord_Forward->setEnabled(true);	
	
	this->label_StatusText->setText(QString::fromUtf8("Dropped [") + QString::number(callNo) + QString::fromUtf8("]"));
	this->updateUIControlsEnabled(true, false, true, true);
	this->updateUIControlsIcons(QString::fromUtf8(":/controlPad/Dial_a.png"), 	QString::fromUtf8(":/controlPad/Hold_a.png"));
}

void MainWindow::handleIaxWrapperEventRegistrationInactive(Account* account)
{
	this->label_StatusText->setText(QString::fromUtf8("Reg. Inactive [") + account->username + QString::fromUtf8("]"));
	this->updateUIControlsEnabled(false, false, false, true);
}

void MainWindow::handleIaxWrapperEventRegistrationConnecting(Account* account)
{
	this->label_StatusText->setText(QString::fromUtf8("Connecting..."));
	this->updateUIControlsEnabled(false, false, false, false);
}
void MainWindow::handleIaxWrapperEventRegistrationRequested(Account* account)
{
	this->label_StatusText->setText(QString::fromUtf8("Logging in..."));
	this->updateUIControlsEnabled(false, false, false, false);
}

void MainWindow::handleIaxWrapperEventRegistrationAccepted(Account* account)
{
    if ((this->wrapper->callSession.count()>0) && 
    	(  (this->wrapper->callSession[this->wrapper->getSelectedCall()].isOutgoing()) || (this->wrapper->callSession[this->wrapper->getSelectedCall()].isIncoming()) )&&
    	(this->wrapper->callSession[this->wrapper->getSelectedCall()].isActive()) 
    	)
    {
    	// You are currently acti
    }
    else
    {
		this->label_StatusText->setText(QString::fromUtf8("Logged In [ ") + account->username + QString::fromUtf8(" ]"));	
		this->updateUIControlsEnabled(true, false, true, true);
		this->updateUIControlsIcons(QString::fromUtf8(":/controlPad/Dial_a.png"), QString::fromUtf8(":/controlPad/Hold_a.png"));	
    }	

}
void MainWindow::handleIaxWrapperEventRegistrationRejected(Account* account)
{
	this->label_StatusText->setText(QString::fromUtf8("Reg. Rejected [") + account->username + QString::fromUtf8("]"));
	this->updateUIControlsEnabled(false, false, false, true);
	this->updateUIControlsIcons(QString::fromUtf8(":/controlPad/Dial_a.png"), QString::fromUtf8(":/controlPad/Hold_a.png"));
}
void MainWindow::handleIaxWrapperEventRegistrationTimeout(Account* account)
{
	this->label_StatusText->setText(QString::fromUtf8("Reg. Timeout [") + account->username + QString::fromUtf8("]"));
	this->updateUIControlsEnabled(false, false, false, true);
	this->updateUIControlsIcons(QString::fromUtf8(":/controlPad/Dial_a.png"), 	QString::fromUtf8(":/controlPad/Hold_a.png"));
}
 
void MainWindow::updateCallDuration(int callNo, int hours, int minutes, int seconds)
{
    QString hoursStr = QString::number(hours);
    if (hours<10)
        hoursStr = QString::fromUtf8("0") + hoursStr;
    QString minutesStr = QString::number(minutes);
    if (minutes<10)
        minutesStr = QString::fromUtf8("0") + minutesStr;
    QString secondsStr = QString::number(seconds);
    if (seconds<10)
        secondsStr = QString::fromUtf8("0") + secondsStr;

    this->label_TimerText->setText(hoursStr + QString::fromUtf8(":") + minutesStr + QString::fromUtf8(":") + secondsStr);
}

void MainWindow::updateUIControlsEnabled(bool dialAnsDrop, bool holdResume, bool credit, bool settings)
{
	this->pushButton_DialAnsDrop->setEnabled(dialAnsDrop);
	this->pushButton_HoldResume->setEnabled(holdResume);
	this->pushButton_Credit->setEnabled(credit);
	this->pushButton_Settings->setEnabled(settings);
}

void MainWindow::updateUIControlsIcons(QString dialAnsDrop, QString holdResume)
{
	QIcon dialAnswerDropIcon(dialAnsDrop);
	QIcon holdResumeIcon(holdResume);
	this->pushButton_DialAnsDrop->setIcon(dialAnswerDropIcon);
	this->pushButton_HoldResume->setIcon(holdResumeIcon);

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -