📄 mobilesearch.cpp
字号:
#include "mobilesearch.h"#include <qpe/global.h>#include <qpushbutton.h>#include <qmessagebox.h>#include <qlineedit.h> #include <zte/cmessagebox.h>#include <qradiobutton.h>#include <qtopia/contextbar.h>#include <qevent.h>#include <qtopia/resource.h> #include <qtopia/image.h>#include <qstringlist.h>#include <qstring.h>#include <zte/headerpixmapid.h>#include <qtopia/qcopenvelope_qws.h>#include <math.h>#include <qwhatsthis.h>#include <qvariant.h>#include <qlabel.h>#include <qlayout.h>#include <qtooltip.h>#include <sqlite/sqlite3.h>#include <qtextcodec.h>#include <stdio.h>#include <qtextstream.h>#include <stdlib.h>#include <qtextcodec.h>#include <qfile.h>#define ELEMENT_NUM(_array) ( sizeof(_array)/sizeof(_array[0]) )#ifndef resultset_structtypedef struct resultset_struct { int rows; int cols; char ***recordset; } resultset;#endif/*char *m_fgets(char *line, int n, FILE *fd){ int c = 0; char *cstring; int count = 0; cstring = line; while(--n>0 && ( c = getc(fd) ) != EOF) { if (c == '\n') break; *cstring++ = c; } *cstring++ = '\0'; if (c == EOF && cstring == line)//ie nothing in file! line = NULL; if (c == EOF) line = NULL; return line;}*/MobileSearch::MobileSearch( QWidget* parent, const char* name, WFlags fl) :QWidget (parent ,name,fl){ if ( !name ) setName( "Mobilesearch" ); setBackgroundPixmap(Resource::loadPixmap("P980/Contacts/contacts_edit_BG.png")); Result_Label = new QLabel( this, "Result_Label" ); Result_Label->setGeometry( QRect( 5, 84, 90, 16 ) ); City_Label = new QLabel( this, "City_Label" ); City_Label->setGeometry( QRect( 5, 128, 90, 30 ) ); InputNumber_Label = new QLabel( this, "InputNumber_Label" ); InputNumber_Label->setGeometry( QRect( 1, 13, 220, 16 ) ); PhoneNumber_Edit = new QLineEdit( this, "PhoneNumber_Edit" ); PhoneNumber_Edit->setGeometry( QRect( 5, 42, 167, 24 ) ); Query_PushButton = new QPushButton( this, "Query_PushButton" ); Query_PushButton->setGeometry( QRect( 175, 39, 63, 32 ) ); CityResult_Label = new QLabel( this, "CityResult_Label" ); CityResult_Label->setGeometry( QRect( 100, 128, 120, 30 ) ); SIMcardResult_Label = new QLabel( this, "SIMcardResult_Label" ); SIMcardResult_Label->setGeometry( QRect( 100, 185, 120, 30 ) ); SIMcard_Label = new QLabel( this, "SIMcard_Label" ); SIMcard_Label->setGeometry( QRect( 5, 185, 90, 30 ) ); Result_Label->setBackgroundMode (TransparentBack); City_Label->setBackgroundMode (TransparentBack); CityResult_Label->setBackgroundMode (TransparentBack); InputNumber_Label->setBackgroundMode (TransparentBack); PhoneNumber_Edit->setBackgroundMode (TransparentBack); SIMcardResult_Label->setBackgroundMode (TransparentBack); SIMcard_Label->setBackgroundMode (TransparentBack); //QCopChannel *numberChannel = new QCopChannel("QPE/Application/mobilesearch", this); languageChange(); resize( QSize(211, 254).expandedTo(minimumSizeHint()) ); Initial(); QPEApplication::setInputMethodHint(PhoneNumber_Edit, QPEApplication:: Number); PhoneNumber_Edit->setAlignment(Qt::AlignHCenter); ContextBar::setLabel(this, Qt::Key_Context1, "", tr("Query")); ContextBar::setLabel(this, Qt::Key_Back, "", tr("Back")); connect(Query_PushButton,SIGNAL(pressed()), this ,SLOT( Query_PushButtonPressed())); connect(Query_PushButton,SIGNAL(released()), this ,SLOT( Query_PushButtonReleased())); connect ( Query_PushButton ,SIGNAL(clicked()),this,SLOT(ExecuteSearch()));// connect(numberChannel, SIGNAL(received(const QCString &, const QByteArray &)), this, SLOT(executeParameter( ))); }MobileSearch::~MobileSearch() {}/*void MobileSearch::parseString(QString *pStr){ QString str2 = "+EMSC: "; int len2 = str2.length(); if ( pStr->contains("+EM", false) > 0 ) (*pStr) = pStr->right(pStr->length()- len2 );}QString MobileSearch::formatString (QString *pStr_a){ int len = pStr_a->length(); const char * pHead = pStr_a -> latin1(); for (int i=0 ; i < len ; i++) if ( pHead[i] == ',' ) { QString man=pStr_a->left( i ); (*pStr_a) = pStr_a->right(pStr_a->length()- i -1 ); return man; } }*/void MobileSearch::Query_PushButtonPressed(){ Query_PushButton->setPixmap(Resource::loadPixmap("P980/Component/search_on.png"));}void MobileSearch::Query_PushButtonReleased(){ Query_PushButton->setPixmap(Resource::loadPixmap("P980/Component/search.png")); }void MobileSearch::executeParameter( ){ int m=1385269; QuerySqlite(m);}void MobileSearch::keyPressEvent (QKeyEvent *e){ if (e->key() == Qt::Key_Context1) { ExecuteSearch(); } else if (e->key() == Qt::Key_Back) { close(); delete this; } else { QWidget::keyPressEvent(e); }}bool MobileSearch::event(QEvent *ev){ if (ev->type() == QEvent::WindowActivate) { QCopEnvelope e( "QPE/System", "setHeaderBgPixmap(int)" ); e << (int)(HeaderPixmapId::Depth3_Setting); } QWidget::event(ev);}void MobileSearch::ExecuteSearch(){ QString Inputnumber=PhoneNumber_Edit->text(); Inputnumber=Inputnumber.left(7); int Transfer_parameter=Inputnumber.toInt(); if (Transfer_parameter<1000000) { PhoneNumber_Edit->setText(""); CityResult_Label->setText(""); SIMcardResult_Label->setText(""); msg=new CMessageBox(this,1,Static_Input_Wrong, QFile::decodeName("请输入至少前7位手机号码!"),TRUE); msg->exec(); } else MobileSearch::QuerySqlite(Transfer_parameter);}void MobileSearch::Initial(){ PhoneNumber_Edit->setText(""); CityResult_Label->setText(""); SIMcardResult_Label->setText(""); PhoneNumber_Edit->setMaxLength(11); msg=0; Query_PushButton->setPixmap(Resource::loadPixmap("zte/component/search.png"));}void MobileSearch::QuerySqlite(int phonenumber){ sqlite3 *db; int rc; char * errMsg = NULL; char * P_errMsg = NULL; rc = sqlite3_open("/tmp/mobiledatabase.db", &db); if( rc ) { sqlite3_close(db); PhoneNumber_Edit->setText(""); CityResult_Label->setText(""); SIMcardResult_Label->setText(""); msg=new CMessageBox(this,1,Static_Input_Wrong, QFile::decodeName("数据库文件损坏或丢失!"),TRUE); msg->exec(); return; }else { QString valued; char ** result; char ***recordset; int nrow=0,ncol=0,count=0,i=0,j=0; resultset resultset_table; resultset_table.rows=0; resultset_table.cols=0; resultset_table.recordset=NULL; QTextOStream(&valued)<<"SELECT LOCATION FROM MobileData WHERE PHONENUM="<<phonenumber; rc=sqlite3_get_table(db,valued,&result,&nrow,&ncol,&errMsg); if ( (rc==SQLITE_OK)&&( nrow!=0&&ncol!=0 ) ) { recordset= ( char *** ) malloc (nrow * sizeof ( char ** ) ); for ( count=ncol; count< ( ( nrow + 1) * ncol ); count++) { recordset[i]= ( char ** ) malloc (ncol * sizeof ( char *) ); for ( j=0; j<ncol; j++ ) { recordset[i][j]= (char *) malloc ( ( strlen ( result[count] ) +1 ) ); strcpy ( recordset[i][j] , result[count]); if (j!=(ncol -1)) count ++; } i++; } sqlite3_free_table(result); resultset_table.rows=nrow; resultset_table.cols=ncol; resultset_table.recordset=recordset; QString P_valued; char ** P_result; char ***P_recordset; int P_nrow=0,P_ncol=0,P_count=0,P_i=0,P_j=0; resultset P_resultset_table; P_resultset_table.rows=0; P_resultset_table.cols=0; P_resultset_table.recordset=NULL; QTextOStream(&P_valued)<<"SELECT CARD FROM MobileData WHERE PHONENUM="<<phonenumber; rc= sqlite3_get_table(db,P_valued,&P_result,&P_nrow,&P_ncol,&P_errMsg); P_recordset= ( char *** ) malloc (P_nrow * sizeof ( char ** ) ); for ( P_count=P_ncol; P_count< ( ( P_nrow + 1) * P_ncol ); P_count++) { P_recordset[P_i]= ( char ** ) malloc (P_ncol * sizeof ( char *) ); for ( P_j=0; P_j<P_ncol; P_j++ ) { P_recordset[P_i][P_j]= (char *) malloc ( ( strlen ( P_result[P_count] ) +1 ) ); strcpy ( P_recordset[P_i][P_j] , P_result[P_count]); if (P_j!=(P_ncol -1)) P_count ++; } P_i++; } sqlite3_free_table(P_result); P_resultset_table.rows=P_nrow; P_resultset_table.cols=P_ncol; P_resultset_table.recordset=P_recordset; CityResult_Label->setText( QString::fromUtf8(**(resultset_table.recordset)) ); SIMcardResult_Label->setText( QString::fromUtf8( **(P_resultset_table.recordset) ) ); } else { PhoneNumber_Edit->setText(""); CityResult_Label->setText(""); SIMcardResult_Label->setText(""); msg=new CMessageBox(this,1,Static_Input_Wrong, QFile::decodeName("请输入正确手机号码!"),TRUE); msg->exec(); }/* char sql_string[102400]; FILE *read_fd=(FILE *)0; read_fd=fopen("/home/Trolltech/SDK-Qtopia-pc/src/applications/mobilesearch/mobiledatabase.sql","r"); if ( read_fd != NULL ) { rewind(read_fd); while( !feof (read_fd) ) { m_fgets(sql_string ,102400, read_fd); if ( strcmp (sql_string , "")!=0 ) { rc=sqlite3_exec ( db , sql_string ,0,0, &errMsg); if (rc ==SQLITE_OK) City_Edit->setText("ALL"); else { qWarning(errMsg); sqlite3_close(db); City_Edit->setText("at lease run"); return; } } } fclose(read_fd); } else City_Edit->setText("not run"); //end of else */ } sqlite3_close(db);}void MobileSearch::languageChange(){ setCaption( tr( "MobileSearch" ) ); Result_Label->setText( tr( "Result" ) ); City_Label->setText( tr( "City:" ) ); InputNumber_Label->setText( tr( "Input your phone number:" ) ); Query_PushButton->setText( tr( " " ) ); CityResult_Label->setText( tr( "City:" ) ); SIMcardResult_Label->setText( tr( "SIM card:" ) ); SIMcard_Label->setText( tr( "SIM card:" ) );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -