📄 javadomain.cpp~
字号:
/* * Hello World demo program for EZX * Copyright (C) 2005 Sam Revitch <samr7@cs.washington.edu> * * 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.1 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. * * Further, this software is distributed without any warranty that it is * free of the rightful claim of any third person regarding infringement * or the like. Any license provided herein, whether implied or * otherwise, applies only to this software file. Patent licenses, if * any, provided herein do not apply to combinations of this program with * other software, or any other product whatsoever. * * 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 *///#define QT_NO_TEXTCODEC#define QT_NO_DRAGANDDROP#define QT_NO_PROPERTIES#include <E2_EZX_ZApplication.h>#include <E2_EZX_ZKbMainWidget.h>#include <E2_EZX_ZMessageDlg.h>#include <E2_EZX_ZLabel.h>#include <E2_EZX_ZScrollPanel.h>#include <E2_EZX_ZSoftKey.h>#include <E2_EZX_ZOptionsMenu.h>#include <E2_EZX_ZComboBox.h>#include <stdio.h>#include <unistd.h>#include <stdlib.h>#include <qfile.h>#include <qtextcodec.h>#include <qlayout.h>#include <qdir.h>#include <pthread.h>
QTextCodec* gbk_codec = QTextCodec::codecForName("UTF-8");
QString ChineseAndEnglish(const char*ChineseString)
{
return gbk_codec->toUnicode(ChineseString);
} typedef struct JavaProgram{ char name[64]; char showName[24]; char path[64]; int isCard;};int initJavaProgram(JavaProgram** pplist ){ QDir dir("/mmc/mmca1/.system/java/DownloadApps"); int count = (int)dir.count() ; dir.setPath("/ezxlocal/.system/java/DownloadApps"); count += (int)dir.count(); dir.setPath("/ezxlocal/.system/java/SystemApps"); count += (int)dir.count(); *pplist = new JavaProgram[count]; int index = 0; if(*pplist != NULL ) { QFile file("/mmc/mmca1/.system/java/CardRegistry"); char tmp[256]; int isMpkg = 1; if( file.open(IO_ReadWrite) ) { while( file.readLine( tmp, 256 ) != -1 && index < count ) { if( tmp[0] == '[' ) { if( !isMpkg ) { index++; } (*pplist)[index].isCard = 1; isMpkg = 0; } else if( strstr( tmp , "Directory" ) == tmp ) { strcpy( (*pplist)[index].path , tmp + 12 ); (*pplist)[index].path[strlen((*pplist)[index].path) - 1 ] = 0; } else if( strstr( tmp , "Name" ) == tmp ) { strcpy( (*pplist)[index].name , tmp + 7 ); (*pplist)[index].name[strlen((*pplist)[index].name) - 1 ] = 0; if( strlen((*pplist)[index].name) > 20 ) { memset((*pplist)[index].showName , 0 , 24 ); strncpy( (*pplist)[index].showName , (*pplist)[index].name , 16 ); strcat( (*pplist)[index].showName , "..." ); } else { strcpy( (*pplist)[index].showName , (*pplist)[index].name ); } } else if( strstr( tmp , "MpkgFile" ) == tmp ) { if( strchr( tmp , '/' ) != NULL ) { isMpkg = 1; } } } file.close(); } if( !isMpkg ) { index++; } isMpkg = 1; QFile filephone("/ezx_user/download/appwrite/am/InstalledDB"); if( filephone.open(IO_ReadWrite) ) { while( filephone.readLine( tmp, 256 ) != -1 && index < count ) { if( tmp[0] == '[' ) { if( !isMpkg ) { index++; } (*pplist)[index].isCard = 0; isMpkg = 0; } else if( strstr( tmp , "Directory" ) == tmp ) { strcpy( (*pplist)[index].path , tmp + 12 ); (*pplist)[index].path[strlen((*pplist)[index].path) - 1 ] = 0; } else if( strstr( tmp , "Name" ) == tmp ) { strcpy( (*pplist)[index].name , tmp + 7 ); (*pplist)[index].name[strlen((*pplist)[index].name) - 1 ] = 0; if( strlen((*pplist)[index].name) > 20 ) { memset((*pplist)[index].showName , 0 , 24 ); strncpy( (*pplist)[index].showName , (*pplist)[index].name , 16 ); strcat( (*pplist)[index].showName , "..." ); } else { strcpy( (*pplist)[index].showName , (*pplist)[index].name ); } } else if( strstr( tmp , "MpkgFile" ) == tmp ) { if( strchr( tmp , '/' ) != NULL ) { isMpkg = 1; } } } filephone.close(); } if( !isMpkg ) { index++; } } if( index == 0 ) { system("showQ \"\" 没有安装任何java程序! 2"); exit(0); } return index;}int getDomain(char* path){ char tmp[256]; sprintf(tmp ,"%s/registry.txt" , path); QFile file(tmp); int ret = 0; if( file.open(IO_ReadWrite) ) { char* buff = new char[file.size()]; file.readBlock(buff , file.size()); if( strstr(buff , "\nDomain: Untrusted\n") != NULL ) { ret = 0; } else if( strstr(buff , "\nDomain: Operator\n") != NULL ) { ret = 1; } else if( strstr(buff , "\nDomain: Manufacturer\n") != NULL ) { ret = 2; } file.close(); delete[] buff; } return ret;} void setDomain(char* path , int domain){ char tmp[256]; sprintf(tmp ,"%s/registry.txt" , path); QFile file(tmp); if( file.open(IO_ReadWrite) ) { int size = file.size(); char* buff = new char[size]; file.readBlock(buff , size); file.close(); file.remove(); if( file.open(IO_ReadWrite) ) { char* pre = strstr(buff , "\nDomain: "); file.writeBlock(buff , pre - buff + 9 ); switch( domain ) { case 1: file.writeBlock("Operator" , 8 ); break; case 2: file.writeBlock("Manufacturer" , 12 ); break; case 0: default: file.writeBlock("Untrusted" , 9 ); break; } pre = strchr( pre + 1, '\n' ); file.writeBlock(pre , size - ( pre - buff ) ); } file.close(); delete[] buff; }}
class MyDialog : public ZKbMainWidget{
Q_OBJECT ZComboBox* nameBox; ZComboBox* domainBox; ZLabel* infoLabel; JavaProgram* pJavaList; public: MyDialog( ):ZKbMainWidget((ZHeader::HEADER_TYPE)3,NULL , "ZMainWidget" , 0) { setMainWidgetTitle(ChineseAndEnglish("Java软件授权")); ZSoftKey* softKey = new ZSoftKey(NULL , this , this); QRect rect; ZOptionsMenu* menu = new ZOptionsMenu(rect, softKey, NULL , 0 ,(ZSkinService::WidgetClsID)2 ); menu->insertItem(ChineseAndEnglish("退出") , NULL , NULL , true , 0 , 0 ); softKey->setOptMenu(ZSoftKey::LEFT, menu); softKey->setText(ZSoftKey::LEFT, ChineseAndEnglish("选项"), (ZSoftKey::TEXT_PRIORITY)0); softKey->setText(ZSoftKey::RIGHT, ChineseAndEnglish("关于"), (ZSoftKey::TEXT_PRIORITY)0);
softKey->setClickedSlot(ZSoftKey::RIGHT, this, SLOT(about()));
menu->connectItem(0, qApp, SLOT(quit())); nameBox = new ZComboBox(this,"name",true); domainBox = new ZComboBox(this,"domainBox",true); infoLabel = new ZLabel(ChineseAndEnglish("") , this, "ZLabel", 0, (ZSkinService::WidgetClsID)4); infoLabel->setPreferredWidth(240); infoLabel->setAutoResize(true ); int number = initJavaProgram( &pJavaList ); for( int i = 0 ; i < number ; i++ ) { nameBox->insertItem(ChineseAndEnglish(pJavaList[i].showName), i ); } if( number > 0 ) { nameBox->setCurrentItem( 0 ); } else { delete[] pJavaList; pJavaList = NULL; } domainBox->insertItem(ChineseAndEnglish("Untrusted"), 0 ); domainBox->insertItem(ChineseAndEnglish("Operator"), 1 ); domainBox->insertItem(ChineseAndEnglish("Manufacturer"), 2 ); QVBoxLayout* layout = getVBoxLayout(); ZScrollPanel *zsv = new ZScrollPanel(this , NULL , 0 , (ZSkinService::WidgetClsID)4); int height = heightForWidth(240) + 10; zsv->addChild(nameBox , 10 , height); height += (nameBox->getContentRect()).height() + nameBox->getBtnHSpacing() * 4 ; zsv->addChild(domainBox , 10 , height); height += (domainBox->getContentRect()).height() + domainBox->getBtnHSpacing() * 4 ; zsv->addChild(infoLabel , 10 , height); layout->addWidget(zsv); setSoftKey(softKey); dlg = NULL; startTimer(500); currentIndex = -1; } ~MyDialog( ) { killTimers(); if( pJavaList != NULL ) { delete[] pJavaList; } if( dlg != NULL ) { delete dlg; } } ZMessageDlg *dlg; int currentIndex; int currentDomian;public slots: virtual void timerEvent(QTimerEvent* e) { if( pJavaList == NULL ) { ZKbMainWidget::timerEvent(e); return; } int select = nameBox->currentItem(); if( currentIndex != select ) { char tmp[256]; sprintf( tmp , "名称:%s\n位置:%s\n路径:%s" , pJavaList[select].name , pJavaList[select].isCard == 0 ? "手机" : "内存卡" , pJavaList[select].path ); infoLabel->setText(ChineseAndEnglish(tmp)); infoLabel->setPreferredWidth(220); infoLabel->setAutoResize(true ); domainBox->setCurrentItem(getDomain(pJavaList[select].path)); currentIndex = select; currentDomian = domainBox->currentItem(); } if( currentDomian != domainBox->currentItem() ) { setDomain( pJavaList[select].path , domainBox->currentItem() ); currentDomian = domainBox->currentItem(); } ZKbMainWidget::timerEvent(e); } void about() { if( dlg == NULL ) { QString a = ChineseAndEnglish("关于"); QString b = ChineseAndEnglish("Java软件授权 ver1.0\nby Lasly\nEmail: flylasly@gmail.com"); dlg = new ZMessageDlg(a , b , (ZMessageDlg::MessageDlgType)2 , 0 , this , "about" , true , 0); } dlg->show(); }};int main( int argc, char **argv ){ ZApplication* a = new ZApplication( argc, argv ); MyDialog* w = new MyDialog(); a->setMainWidget( w ); w->show(); int ret = a->exec(); delete w; delete a; return ret;}#include "helloworld.moc"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -