📄 packagewizard.cpp
字号:
// if ( token[1] == "http_proxy" )// http->setText(token[2]);// else if ( token[1] == "ftp_proxy" )// ftp->setText(token[2]);// else if ( token[1] == "proxy_username" )// username->setText(token[2]);// else if ( token[1] == "proxy_password" )// password->setText(token[2]); } else { // Old style? int eq = l.find('='); if ( eq >= 0 ) { QString v = l.mid(eq+1).stripWhiteSpace(); if ( v[0] == '"' || v[0] == '\'' ) { int cl=v.find(v[0],1); if ( cl >= 0 ) v = v.mid(1,cl-1); } if ( l.left(12) == "IPKG_SOURCE=" ) { ipkg_old=1; ServerListItem* item = new ServerListItem(servers,v); currentserver=item; item->setText(1, v); } else if ( l.left(13) == "#IPKG_SOURCE=" ) { ServerListItem* item = new ServerListItem(servers,v); item->setText(1, v); } else if ( l.left(10) == "IPKG_ROOT=" ) { // ### no UI// } else if ( l.left(20) == "IPKG_PROXY_USERNAME=" ) {// username->setText(v);// } else if ( l.left(20) == "IPKG_PROXY_PASSWORD=" ) {// password->setText(v);// } else if ( l.left(16) == "IPKG_PROXY_HTTP=" ) {// http->setText(v);// } else if ( l.left(16) == "IPKG_PROXY_FTP=" ) {// ftp->setText(v); } } } } if ( ipkg_old ) { // Should be radiobuttons if ( currentserver ) currentserver->setOn(TRUE); } } if ( !currentserver ) { currentserver = new ServerListItem(servers,tr("Trolltech Qtopia")); currentserver->setText(1,"http://qtopia.net/packages/"+Global::architecture()); currentserver->setOn(TRUE); } return TRUE;}void PackageWizard::readSettings(){ // read from config file(s) readIpkgConfig(QPEApplication::qpeDir()+"/etc/ipkg.conf");}void PackageWizard::writeSettings(){ QFile conf(QPEApplication::qpeDir()+"/etc/ipkg.conf"); if ( conf.open(IO_WriteOnly) ) { QTextStream s(&conf); s << "# Written by Qtopia Package Manager\n"; // No tr if ( !ipkg_old ) { for (QListViewItem* i = servers->firstChild(); i; i = i->nextSibling()) { ServerListItem* item = (ServerListItem*)i; if ( !item->isOn() ) s << "#"; QString id = item->id(); s << "src " << id << " " << item->text(1) << "\n"; } // No UI for alt dests s << "dest root /\n"; // No tr// if ( !username->text().isEmpty() )// s << "option proxy_username " << username->text() << "\n";// if ( !password->text().isEmpty() )// s << "option proxy_password " << password->text() << "\n";// if ( !http->text().isEmpty() )// s << "option http_proxy " << http->text() << "\n";// if ( !ftp->text().isEmpty() )// s << "option ftp_proxy " << ftp->text() << "\n"; } else { // Old style bool src_selected=FALSE; for (QListViewItem* i = servers->firstChild(); i; i = i->nextSibling()) { ServerListItem* item = (ServerListItem*)i; if ( item->isOn() ) src_selected=TRUE; else s << "#"; s << "IPKG_SOURCE=\"" << item->text(1) << "\"\n"; } s << "IPKG_ROOT=/\n"// << "IPKG_PROXY_USERNAME=\"" << username->text() << "\"\n"// << "IPKG_PROXY_PASSWORD=\"" << password->text() << "\"\n"// << "IPKG_PROXY_HTTP=\"" << http->text() << "\"\n"// << "IPKG_PROXY_FTP=\"" << ftp->text() << "\"\n" ; } conf.close(); } else { qWarning("Cannot write to $QPEDIR/etc/ipkg.conf"); }}void PackageWizard::selectPackages( const QStringList& l ){ QDict<void> d; for (QStringList::ConstIterator it = l.begin(); it != l.end(); ++it) d.replace(*it,(void*)1); QListViewItem* i; for ( i = packagelist->firstChild(); i; i = i->nextSibling() ) { PackageItem* pit = (PackageItem*)i; i->setSelected( d[pit->name()] ); }}QStringList PackageWizard::findPackages( const QRegExp& r ){ QStringList matches; QString info = ipkgInfoOutput(); if ( !info.isEmpty() ) { QStringList lines = QStringList::split('\n',info,TRUE); QRegExp re = r; QString description=""; QString name; for (QStringList::Iterator it = lines.begin(); it!=lines.end(); ++it) { QString line = *it; if ( line.length()<=1 ) { // EOR if ( re.match(description) >= 0 ) matches.append(name); description=""; name=""; } else if ( line[0] == ' ' || line[0] == '\t' ) { // continuation description.append(" "); description.append(Qtopia::escapeString(line)); } else { int sep = line.find(QRegExp(":[\t ]+")); if ( sep >= 0 ) { QString tag = line.left(sep); if ( tag == "Package" ) // No tr name = line.mid(sep+2).simplifyWhiteSpace(); if ( !description.isEmpty() ) description.append("<br>"); description.append("<b>"); description.append(Qtopia::escapeString(tag)); description.append(":</b> "); description.append(Qtopia::escapeString(line.mid(sep+2))); } } } } return matches;}/*! Install \a ipk to \a location. Returns FALSE on error, otherwise TRUE. */bool PackageWizard::installIpkg( const QString &ipk, const QString &location, QString& out ){ //qDebug( "installing %s to '%s'", ipk.ascii(), location.ascii() ); out = QString("installing %1 to %2").arg(ipk).arg(location); QStringList cmd; QStringList orig_packages; if ( !location.isEmpty() ) { // ??????? mkdir( location.ascii(), 0777 ); cmd += "-d"; cmd += location; } cmd += "install"; // No tr cmd += ipk; bool r = runIpkg( cmd, out ); return r;}/* void PackageWizard::doUpgrade(){ startMultiRun(2); QString out; runIpkg("update",out); runIpkg("upgrade",out); updatePackageList(); endRun();} *//*void PackageWizard::doIt(){ bool ok = commitWithIpkg(); updatePackageList(); // things may have changed if (!ok) qApp->beep();}*/QStringList PackageWizard::linksInPackage(const QString& pkg, const QString & root ){ QString files; QStringList cmd; cmd << ipkg_name; if ( root != "/" ) cmd << "-d" << root; cmd << "files" << pkg; // No tr Process ipkg_files( cmd ); QStringList r; if ( ipkg_files.exec("",files) ) { QStringList lines = QStringList::split('\n',files,FALSE); for (QStringList::Iterator it = lines.begin(); it!=lines.end(); ++it) { QString fn = *it; // Quickly weed out most of the files that do not end // with ".desktop" (8 chars) if ( fn.length() < 8 || fn.constref(fn.length()-8) != '.' ) continue; if ( root != "/" && fn.startsWith( root ) ) fn = fn.mid( root.length() ); if ( fn.startsWith("//") ) // a ipkg bug fn = fn.mid(1); // Two supported symlink conventions if ( fn.left(12)=="/opt/Qtopia/" ) { fn.replace(0,12,QPEApplication::qpeDir()); } else if ( fn.left(15)=="/opt/QtPalmtop/" ) { fn.replace(0,15,QPEApplication::qpeDir()); } if ( Global::isDocumentFileName(fn) || Global::isAppLnkFileName(fn) ) { r.append(fn); } } } return r;}void PackageWizard::showError(const QString& err){ QDialog dlg(this,"error",TRUE); // No tr (new QVBoxLayout(&dlg,4,2))->setAutoAdd(TRUE); QLabel lbl(tr("Error"),&dlg); QMultiLineEdit e(&dlg); e.setReadOnly(TRUE); e.setText(err); QPushButton c(tr("Close"),&dlg); dlg.connect(&c,SIGNAL(clicked()),SLOT(accept())); dlg.showMaximized(); dlg.exec();}bool PackageWizard::commitWithIpkg(){ // A full implementation would do the following, but we'll just do // it simply and non-interactively for now. // // setenv IPKG_CONF_DIR for a null $IPKG_CONF_DIR/ipkg.conf // setenv IPKG_SOURCE, IPKG_ROOT, etc. // run ipkg, processing interactivity as dialogs // - "... (Y/I/N/O/D) [default=N] ?" -> ... // - "[Press ENTER to continue]" (if D chosen above) // - "The following packages are marked `Essential'... Install them now [Y/n] ?" // - "The following packages...ready to be installed:... Install them now [Y/n] ?" // return FALSE cancelled QStringList to_do; for ( QListViewItem* i = packagelist->firstChild(); i; i = i->nextSibling() ) { PackageItem* pit = (PackageItem*)i; if ( pit->isSelected() ) to_do.append(pit->id()); } bool ok=TRUE; int jobs = to_do.count(); QString errlog; if ( jobs ) { startMultiRun(jobs); QStringList linksChanged; if ( mode_rm->isChecked() ) { for (QStringList::ConstIterator it=to_do.begin(); it!=to_do.end(); ++it) { QString out; QStringList cmd; QString *root = installedRootDict ? installedRootDict->take(*it) : 0; QStringList l = linksInPackage(*it, root ? *root : QString("/")); if ( root ) cmd << "-d" << *root; delete root; cmd << "remove" << *it; // No tr if ( !runIpkg( cmd, out) ) { ok = FALSE; errlog += out; } else { linksChanged += l; } } } if ( mode_doc->isChecked() || mode_net->isChecked() ) { QString loc = location->installationPath(); for (QStringList::ConstIterator it=to_do.begin(); it!=to_do.end(); ++it) { QString out; if ( !installIpkg( *it, loc, out ) ) { errlog += getenv("PATH"); errlog += "\n"; errlog += "install ipkg returned false for " + loc + "\n"; ok = FALSE; errlog += out; } else { linksChanged += linksInPackage(packageId(*it), loc ); } } if ( !ok ) { QString out; revertFailedInstalls(out); errlog += out; } } // We could be smarter about when we do this, and use the // "create" or "remove" arguments to update only what's needed, // but it doesn't take that long. system( "qtopia-update-symlinks" ); // ##### If we looked in the list of files, we could send out accurate // ##### messages. But we don't bother yet, and just do an "all".#ifndef QT_NO_COP for (QStringList::ConstIterator it=linksChanged.begin(); it!=linksChanged.end(); ++it) { QCopEnvelope e("QPE/System", "linkChanged(QString)"); e << *it; }#endif#if QT_VERSION > 230 // a bug breaks this otherwise if ( !ok ) showError(errlog);#endif endRun(); } return ok;}QString PackageWizard::ipkgStatusOutput(){ if ( cachedIpkgStatusOutput.isEmpty() ) { Process ipkg_status( QStringList() << ipkg_name << "status" ); // No tr cachedIpkgStatusOutput.detach(); ipkg_status.exec( 0, cachedIpkgStatusOutput ); StorageInfo storage; const QList<FileSystem>& sifs(storage.fileSystems()); QListIterator<FileSystem> sit(sifs); FileSystem* fs; for ( ; (fs=sit.current()); ++sit ) { //qDebug( "looking at %s", fs->path().latin1() ); if ( fs->path() != "/" && QFile::exists( fs->path() +#ifdef IPKGSIM QPEApplication::qpeDir() +#endif "/usr/lib/ipkg/status" ) ) { QCString subOut; Process ipkg2( QStringList() << ipkg_name << "-d" << fs->path() << "status" ); // No tr ipkg2.exec( 0, subOut ); //qDebug( " result %s", subOut.data() ); cachedIpkgStatusOutput += subOut; } } } return QString::fromLocal8Bit( cachedIpkgStatusOutput );}QString PackageWizard::ipkgInfoOutput(){ if ( cachedIpkgInfoOutput.isEmpty() ) { Process ipkg_info( QStringList() << ipkg_name << "info" ); cachedIpkgInfoOutput.detach(); ipkg_info.exec( 0, cachedIpkgInfoOutput ); } return QString::fromLocal8Bit( cachedIpkgInfoOutput );}void PackageWizard::setCachedIpkgOutputDirty(){ cachedIpkgStatusOutput = cachedIpkgInfoOutput = "";}void PackageWizard::startMultiRun(int jobs){ startRun(); progress()->setTotalSteps(jobs); progress()->setProgress(0);}void PackageWizard::startRun(){ setEnabled(FALSE); progress()->setEnabled(TRUE); progress()->show();}void PackageWizard::endRun(){ QPEApplication::setTempScreenSaverMode(QPEApplication::Enable); progress()->hide(); progress()->reset(); setEnabled(TRUE); setAppropriates();}bool PackageWizard::runIpkg(const QStringList& args, QString& out){ bool justone = progress()->progress() == -1; if ( justone ) { startMultiRun(1); } else { startRun(); } QStringList cmd; cmd += ipkg_name; if ( !ipkg_old ) cmd += "-force-defaults"; cmd += args; qDebug("runn comand %s", (const char *)cmd.join(" ").local8Bit()); qApp->processEvents(); QPEApplication::setTempScreenSaverMode(QPEApplication::DisableSuspend); Process ipkg_status(cmd); bool r = ipkg_status.exec("",out); //qDebug( "RESULT %s", out.latin1() ); progress()->setProgress(progress()->progress()+1); setCachedIpkgOutputDirty(); if ( justone ) endRun(); return r;}/*// simple hack to get support for ipkg mimetypevoid PackageWizard::maybeInstall( const QString &ipk ){ int pos = ipk.findRev( "/" ); QString package = ipk.mid( pos + 1 ); pos = package.find ( "_" ); if ( pos != -1 ) package = package.left( pos ); bool ok; QString dest = getDestination( &ok, TRUE ); if ( ok ) { startRun(); QString out; installIpkg( ipk, dest, out );#ifndef QT_NO_COP QCopEnvelope e("QPE/System", "linkChanged(QString)"); QString lf = QString::null; e << lf;#endif endRun(); }}*/void PackageWizard::setDocument(const QString& fileref){ if ( fileref.isNull() ) return; DocLnk doc( fileref ); if ( doc.file().isEmpty() ) return; qcopDocument = doc.file(); mode_doc->setChecked(TRUE); setAppropriates(); showPage(page_location); packagelist->clear(); QDict<void> installed = installedPackages(); bool inst = installed.find(packageId(doc.file())); PackageItem* item = new PackageItem(packagelist,doc,inst); item->parseInfo(); item->setSelected(TRUE);}void PackageWizard::done(int y){ if ( finishButton()->isEnabled() ) { setFinishEnabled( page_confirmation, FALSE ); if ( y && !committed ) { if ( commitWithIpkg() ) { finishButton()->setText(tr("Close")); committed = TRUE; setAppropriates(); } setFinishEnabled( page_confirmation, TRUE ); return; } else { // nothing. } } PackageWizardBase::done(y); close();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -