[Previous] [Next] [Contents]

CHAPTER 6. PHONE INTERFACE

 

6.8 PhoneTest, a full sample example

PhoneTest has following functions.

  • It shows current phone state. All phone states are dealt in this code.
  • It shows how to send and release call. Refer the comment in the code.
  • It shows how to send SMS. Refer the comment in the code.

 

  • phonetest.h

  • #if !defined (__PHONETEST_H__)
    #define __PHONETEST_H__
    
    #include <mzmainwindow.h>
    #include <qlabel.h>
    #include <qlineedit.h>
    #include <qcombobox.h>
    #include <qmultilineedit.h>
    #include <qpushbutton.h>
    #include <qtimer.h>
    
    class PhoneTest : public MzMainWindow 
    {
           	Q_OBJECT 
    		
    public:
           	PhoneTest ();
    	
    protected:
    
    protected slots:
    	void 	slotChangedPhoneState(int state);
    	void	slotOriginateCall();
    	void	slotReleaseCall();
    	void	slotSendSMS();
    	void	timerDone();
    
    private:
    	QLabel		*lblCurrentStatus;
    	QLabel		*currentStatus;
    
    	QLabel		*lblOriginateCall;
    	QLineEdit	*leditOriginateCall;
    	QPushButton	*btnOriginateCall;
    	QPushButton	*btnReleaseCall;
    
    	QLabel		*lblSendSMS;
    	QLineEdit	*leditSendSMS;
    	QComboBox	*cmbSendSMS;
    	QMultiLineEdit	*meditSendSMS;
    	QPushButton	*btnSendSMS;
    	QLabel		*lblSendingStatus;
    
    	QTimer		*timer;
    };
    
    #endif	/* __PHONETEST_H__ */
    
    

     

  • phonetest.cpp


  • #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <qvbox.h>
    #include <qlayout.h>
    #include <qvalidator.h>
    #include <qfile.h>
    #include <qtextstream.h>
    #include <phoneprotocol.h>
    #include <mzphone.h>
    #include <mzconfig.h>
    #include "phonetest.h"
    
    #define RESULT_FILE 	"/tmp/.result"
    
    #define DEBUG_PHONETEST
    
    #if defined (DEBUG_PHONETEST)
    #define dprintf(a...)   printf(a)
    #else
    #define dprintf(a...)   
    #endif
    
    const char *ENCODING_LABEL[] = {
           	"7BIT_ASCII",
           	"UNICODE",
           	"KSC5601_KOREAN",
    };
    
    
    PhoneTest::PhoneTest()
         : MzMainWindow(0)
    {
    	setName("Phone Test");
    
    	QVBox *vbox = new QVBox(this);
           	vbox->setFocusPolicy(StrongFocus);
    	
           	setFocusPolicy(QWidget::StrongFocus);
           	setFocus();
    
    	QWidget *panel = new QWidget(vbox);
    
    	QGridLayout *layout = new QGridLayout(panel, 8, 3); 
    	layout->setMargin(10);
    	layout->setSpacing(5);
    
    
    	lblCurrentStatus = new QLabel( tr("Phone state :"), panel);
    
    	currentStatus = new QLabel(panel, "currentStatus");
    	
    
    	lblOriginateCall = new QLabel( tr("Originate call :"), panel);
    
    	leditOriginateCall = new QLineEdit( panel );
    	leditOriginateCall->setMaxLength(32);
    	leditOriginateCall->setValidator(new QIntValidator(this));
    
    	btnOriginateCall = new QPushButton( tr("Originate"), panel);
    	btnReleaseCall = new QPushButton( tr("Release"), panel);
    
    	connect(btnOriginateCall, SIGNAL(clicked()), this, SLOT(slotOriginateCall()));
    	connect(btnReleaseCall, SIGNAL(clicked()), this, SLOT(slotReleaseCall()));
    
    	lblSendSMS = new QLabel( tr("Send SMS :"), panel);
    
    	leditSendSMS = new QLineEdit( panel );
    	leditSendSMS->setMaxLength(32);
    	leditSendSMS->setValidator(new QIntValidator(this));
    
    	cmbSendSMS = new QComboBox(panel);
    	cmbSendSMS->insertItem("Ascii", 0);
    	cmbSendSMS->insertItem("Chinese", 1);
    	cmbSendSMS->insertItem("Korean", 2);
    	cmbSendSMS->setCurrentItem(2);
    
    	meditSendSMS = new QMultiLineEdit( panel );
    
    	btnSendSMS = new QPushButton( tr("Send"), panel );
    
    	connect(btnSendSMS, SIGNAL(clicked()), this, SLOT(slotSendSMS()));
    
    	lblSendingStatus = new QLabel(panel);
    	lblSendingStatus->setFrameStyle( QFrame::Panel | QFrame::Sunken );
    
    	layout->addWidget(lblCurrentStatus, 0, 0);
    	layout->addMultiCellWidget(currentStatus, 0, 0, 1, 2);
    	layout->addMultiCellWidget(lblOriginateCall, 1, 1, 0, 2);
    	layout->addMultiCellWidget(leditOriginateCall, 2, 3, 0, 1);
    	layout->addWidget(btnOriginateCall, 2, 2);
    	layout->addWidget(btnReleaseCall, 3, 2);
    	layout->addMultiCellWidget(lblSendSMS, 4, 4, 0, 2);
    	layout->addMultiCellWidget(leditSendSMS, 5, 5, 0, 1);
    	layout->addWidget(cmbSendSMS, 5, 2);
    	layout->addMultiCellWidget(meditSendSMS, 6, 6, 0, 1);
    	layout->addWidget(btnSendSMS, 6, 2, AlignTop);
    	layout->addMultiCellWidget(lblSendingStatus, 7, 7, 0, 2);
    
    	setCentralWidget(vbox);
    
    	connect (MzPhoneNotifier::instance(), SIGNAL(changedState (int)), 
    						SLOT(slotChangedPhoneState (int)));
    
    	timer = new QTimer(this);
    	connect (timer, SIGNAL(timeout()), this, SLOT(timerDone()));
    }
    
    void PhoneTest::slotChangedPhoneState (int state)
    {
    	dprintf("[PhoneTest] slotChangedPhoneState(%d)\n", state);
    
    	QString strState;
    
    	switch((LXT_PHONE_STATE)state) {
    		case LXT_STATE_OFF: 
    			strState = "PHONE_OFF"; break;
    		case LXT_STATE_ON:
    		       	strState = "PHONE_ON"; break;
    		case LXT_STATE_UIM_EMPTY:
    		       	strState = "UIM_EMPTY"; break;
    		case LXT_STATE_UIM_LOCK:
    		       	strState = "UIM_LOCK"; break;
    		case LXT_STATE_UIM_LOCK_FROZEN:
    		       	strState = "UIM_LOCK_FROZEN"; break;
    		case LXT_STATE_UIM_MECHANICAL_PROBLEM:
    		       	strState = "UIM_MECHANICAL_PROBLEM"; break;
    		case LXT_STATE_UIM_NEED_AUTH:
    		       	strState = "UIM_NEED_AUTH"; break;
    		case LXT_STATE_UIM_READY:
    		       	strState = "UIM_READY"; break;
    		case LXT_STATE_NO_SERVICE:
    		       	strState = "NO_SERVICE"; break;
    		case LXT_STATE_STANDBY:
    		       	strState = "STANDBY"; break;
    		case LXT_STATE_WAITING_OUTGOING_CALL:
    		       	strState = "WAITING_OUTGOING_CALL"; break;
    		case LXT_STATE_WAITING_INCOMING_CALL:
    		       	strState = "WAITING_INCOMING_CALL"; break;
    		case LXT_STATE_WAITING_DATA_SERVICE:
    		       	strState = "WAITING_DATA_SERVICE"; break;
    		case LXT_STATE_CONVERSATION:
    		       	strState = "CONVERSATION"; break;
    		case LXT_STATE_DATA_SERVICED:
    		       	strState = "DATA_SERVICED"; break;
    		case LXT_STATE_DIAL_UP_DATA_SERVICED:
    		       	strState = "DIAL_UP_DATA_SERVICEd"; break;
    		case LXT_STATE_RELEASED:
    		       	strState = "CALL_RELEASED"; break;
    		case LXT_STATE_RESERVED:
    		default:
    		       	strState = "RESERVED"; break;
    	}
    
    	currentStatus->setText(strState);
    }
    
    /* There are three ways to originate call.
     *
     * 1. Name: anywhereCall
     *    args: Phone Number + Address ID + Address Type (separator is semicolon(:));
     * 2. Name: anywhereCallWithNumber
     *    args: Only Phone Number
     * 3. Name: anywhereCallWithLastNumber 
     *    args: None (originate with last dialed number)
     * 
     * There is one way to end call.
     *  
     * 1. Name: anywhereEndCall 
     *    args: None
     * */
    
    void PhoneTest::slotOriginateCall ()
    {
    	dprintf("[PhoneTest] slotOriginateCall()\n");
    
    	QString number = leditOriginateCall->text().stripWhiteSpace();
    
    	MzAction *pAction = new MzAction(number, actionCollection(), "anywhereCallWithNumber");
    
           	MzAction::activate("phoneclient", pAction);
    
    	delete pAction;
    }
    
    void PhoneTest::slotReleaseCall ()
    {
    	dprintf("[PhoneTest] slotReleaseCall()\n");
    
    	MzAction *pAction = new MzAction("", actionCollection(), "anywhereEndCall");
    
           	MzAction::activate("phoneclient", pAction);
    
    	delete pAction;
    }
    
    /* It is to send SMS in SCH-i519. 
     * 
     * # sendsms --help
     * Command Line Based SMS Tool 
     * Usage: sendsms [destination, [callback, [content, [encoding=OCTET]]]]
     * 	  If callback number is null, callback number is default phone number.
     *
     * - Encoding -
     * OCTET                    
     * IS_91_EXTENDED_PROTOCOL  
     * 7BIT_ASCII               (Ascii) 
     * IA5                      
     * UNICODE                  (Chinese)
     * SHIFT_JIS                
     * KSC5601                  
     * ISO_8859_8               
     * ISO_8859_1               
     * KSC5601_KOREAN           (Hangul) 
     * */
    
    void PhoneTest::slotSendSMS ()
    {
    	dprintf("[PhoneTest] slotSendSMS()\n");
    
    	lblSendingStatus->setText("Waiting...");
    
    	QString number = leditSendSMS->text().stripWhiteSpace();
    	QString text = meditSendSMS->text();
    
    	MzConfig config("phoneinfo");
    
           	QString cbNumber = config.read("Phone Info", "MDN", QString()).stripWhiteSpace() ;
    
           	if(cbNumber.isEmpty())
    	       	cbNumber = config.read("Phone Info", "Phonenumber", QString()).stripWhiteSpace() ;
    
    	QString saveFileName = "/tmp/.result";
    
    	QString command = "sendsms " + 
    		          number + " " + 
    			  cbNumber + " " + 
    			  text + " " + 
    		          ENCODING_LABEL[cmbSendSMS->currentItem()] + 
    			  "> /dev/null 2> " + RESULT_FILE;
    
    	dprintf("command: %s\n", command.latin1());
    
    	timer->start(2000, false);
    
    	system(command);
    }
    
    void PhoneTest::timerDone()
    {
    	dprintf("[PhoneTest] timerDone()\n");
    
    	QFile file(RESULT_FILE); 
    
    	if (!file.exists()) return;
    	else timer->stop();
    
    	if( file.open( IO_ReadOnly )  ) {
    	       
    		QTextStream ts( &file );
    	       	QString result;
    	       	result = ts.readLine(); 
    
    		dprintf("result: %s\n", result.latin1());
    
    		lblSendingStatus->setText(result.stripWhiteSpace());
    	}
    
    	QString command	= QString("rm -rf ") + RESULT_FILE;
    
    	system(command);
    }
    
        

     

  • main.cpp

  • #include <mzapplication.h>
    #include "phonetest.h"
    
    int main(int argc, char **argv)
    {
           	MzApplication a(argc, argv); 
    	
    	PhoneTest *calltest = new PhoneTest(); 
    	
    	calltest->show(); 
    	
    	return a.exec();
    }
        
        

     


    [Previous] [Next] [Contents] MIZI Prizm 2.0.0