diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-04-03 02:35:45 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-04-03 02:35:45 +0000 |
commit | 7f4a6a18c55be5b74ab3782f63509157a9a25afc (patch) | |
tree | ca86feaa6b8f013654038663b113e106debdca00 /kdpkg-install/install.cpp | |
download | kdpkg-7f4a6a18c55be5b74ab3782f63509157a9a25afc.tar.gz kdpkg-7f4a6a18c55be5b74ab3782f63509157a9a25afc.zip |
Initial import of kdpkg Debian package installer
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kdpkg@1110433 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kdpkg-install/install.cpp')
-rw-r--r-- | kdpkg-install/install.cpp | 392 |
1 files changed, 392 insertions, 0 deletions
diff --git a/kdpkg-install/install.cpp b/kdpkg-install/install.cpp new file mode 100644 index 0000000..2548c1b --- /dev/null +++ b/kdpkg-install/install.cpp @@ -0,0 +1,392 @@ +/* + * install.cpp + * + * Copyright (c) 2007 Fabian Wuertz + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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. + * + * 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 + */ + + + +#include <kgenericfactory.h> +#include <klocale.h> +#include <kurlrequester.h> +#include <kaboutapplication.h> + +#include <qlistbox.h> +#include <qfile.h> +#include <qpushbutton.h> +#include <qwidgetstack.h> +#include <qlabel.h> +#include <qlistview.h> +#include <qregexp.h> +#include <qradiobutton.h> +#include <qfiledialog.h> + +#include <console.h> +#include <install.h> + +install::install( const QString &url, QWidget *parent, const char *name, const QStringList &) +:InstallDialog(parent, name) +{ + + + if( !url ) + path = QFileDialog::getOpenFileName( "", i18n("Debian Package (*.deb)"), this, i18n("open file dialog"), i18n("Choose a file to open") ); + else + path = url; + + this->shell = new Process(); + + this->shell->setCommand("dpkg -f "+path); + this->shell->start(true); + fields = QStringList::split( "\n", this->shell->getBuffer().stripWhiteSpace() ); + + installPushButton->hide(); + nextPushButton1->hide(); + + + + if( !checkArchitecture() ) + page2x1(); + else if( isLocked() ) + page2x2(); + + +} + +//----------------------------------------------------------------------------// +//--- next -------------------------------------------------------------------// +//----------------------------------------------------------------------------// + +void install::next1() +{ + if( !isLocked() ) + { + nextPushButton1->hide(); + nextPushButton2->show(); + widgetStack->raiseWidget(0); + } +} + + +void install::next2() +{ + nextPushButton2->hide(); + if( syncRadioButton->isChecked() ) + page3(); + else + page1(); +} + + + +//----------------------------------------------------------------------------// +//--- pages ------------------------------------------------------------------// +//----------------------------------------------------------------------------// + + +// page 0: skip apt-get update? +// page 1: dependencies +// page 2: warnings +// page 3: apt-get update +// page 4: install package + + +void install::page1() +{ + showDependencies(); + + widgetStack->raiseWidget(1); + installPushButton->show(); + closePushButton->show(); + titleTextLabel->setText( "<b>"+i18n( "The following packages will be installed, updated or removed:" )+"</b>" ); +} + +void install::page2x1() +{ + errorTextLabel->setText("<b>"+i18n("The architecture of the package and the system doesn't match! You will not be able to install this package!")+"</b>"); + nextPushButton2->hide(); + widgetStack->raiseWidget(2); + +} + +void install::page2x2() +{ + errorTextLabel->setText("<b>"+i18n("The package database is used by another process (E.g Synaptic)! Please terminate this process and press next.")+"</b>"); + nextPushButton1->show(); + nextPushButton2->hide(); + widgetStack->raiseWidget(2); +} + + +void install::page3() +{ + titleTextLabel->setText( "<b>"+i18n( "Resynchronization of the package index files.")+"</b>" ); + closePushButton->hide(); + + QStrList run; run.append( "/usr/share/kdpkg/sh/kdpkg-sh" ); + run.append( "update" ); + + QWidget *consoleWidget = new console(this, run ); + widgetStack->addWidget(consoleWidget, 3); + widgetStack->raiseWidget(3); + + connect( consoleWidget, SIGNAL( finished(bool) ), this, SLOT( page1() )); +} + + +void install::page4() +{ + installPushButton->hide(); + closePushButton->hide(); + titleTextLabel->setText( "<b>"+i18n( "Installation of the new package." )+"</b>" ); + + + if( !installPkg ) + installPkg = "none"; + if( !removePkg ) + removePkg = "none"; + + QStrList run; run.append( "/usr/share/kdpkg/sh/kdpkg-sh" ); + run.append( "install" ); + run.append( path ); + run.append( installPkg ); + run.append( removePkg ); + + QWidget *consoleWidget = new console(this, run ); + widgetStack->addWidget(consoleWidget, 4); + widgetStack->raiseWidget(4); + + connect( consoleWidget, SIGNAL( finished(bool) ), this, SLOT( close() )); + + +} + + +//----------------------------------------------------------------------------// +//--- showDependencies -------------------------------------------------------// +//----------------------------------------------------------------------------// + +void install::showDependencies() +{ + + // show packages which will be installed + + QString tmpString = fields.grep( QRegExp("^Depends:") )[0].mid(9); + tmpString += ", "+fields.grep( "Pre-Depends:" )[0].mid(13); + + + QStringList allDepends = QStringList::split( ", ", tmpString ); + + QString missingDepends; + QStringList tmp; + + for(uint i = 0; i < allDepends.count(); i++) + { + if( allDepends[i].contains("|") ) { + tmp = QStringList::split( " | ", allDepends[i] ); + uint j = 0; + bool exit = FALSE; + while ( !exit && j < tmp.count() ) { + if( isInstalled(tmp[j]) ) + exit = TRUE; + j++; + } + if( !exit ) + missingDepends += tmp[0]+" "; + } + else + { + if( !isInstalled( allDepends[i] ) ) + missingDepends += QStringList::split( " ", allDepends[i] )[0]+" "; + } + } + + + this->shell->setCommand("apt-get -s install "+missingDepends); + this->shell->start(true); + QStringList installList = QStringList::split( "\n", this->shell->getBuffer().stripWhiteSpace() ).grep("Inst"); + + + for(uint i = 0; i < installList.count(); i++) + { + QString name = QStringList::split( " ", installList[i] )[1]; + QString pkgVersion; + QString sysVersion; + if( installList[i].contains("[") ) + { + pkgVersion = QStringList::split( " ", installList[i] )[3].mid(1); + sysVersion = QStringList::split( " ", installList[i] )[2].mid(1).replace("]", ""); + } + else + pkgVersion = QStringList::split( " ", installList[i] )[2].mid(1); + + QListViewItem * item = new QListViewItem( dependenciesListView, 0 ); + item->setPixmap( 0, QPixmap( "/usr/share/kdpkg/icons/install.png") ); + item->setText( 1, name ); + item->setText( 2, pkgVersion ); + item->setText( 3, sysVersion ); + + installPkg += name+","; + } + + // find rconflicts + + QString pkgName = fields.grep("Package:")[0].mid(9); + QString pkgVersion = fields.grep("Version:")[0].mid(9); + + QString rconflicts; + + this->shell->setCommand("cat /var/lib/dpkg/status | grep "+pkgName+" -B 16| grep Conflicts -B 16"); + this->shell->start(true); + QStringList input1 = QStringList::split( "\n\n", this->shell->getBuffer().stripWhiteSpace() ); + + for(uint i = 0; i < input1.count(); i++) + { + if( input1[i].contains(pkgName) ) + { + QStringList input2 = QStringList::split( "\n", input1[i] ); + QString name = QStringList::split( " ", input2.grep("Package:")[0] )[1]; + QString cVersion = input2.grep("Conflicts:")[0].mid(11); // conflictVersion + cVersion = QStringList::split( ",", cVersion ).grep(pkgName)[0]; + cVersion = QStringList::split( "(", cVersion )[1]; + cVersion = cVersion.replace(")", ""); + QString op = QStringList::split( " ", cVersion )[0]; + cVersion = QStringList::split( " ", cVersion )[1]; + + if( cVersion == "") + { + rconflicts += name+" "; + printf("1"); + } + else + { + printf("2"); + this->shell->setCommand("if dpkg --compare-versions "+pkgVersion+" \""+op+"\" "+cVersion+"; then echo \"TRUE\"; fi"); + this->shell->start(true); + if( this->shell->getBuffer().stripWhiteSpace() == "TRUE" ) + rconflicts += name+" "; + } + } + } + + + // show packages which will be removed + + QString conflicts = fields.grep( "Conflicts" )[0].mid(11); + conflicts = conflicts.replace( ",", "" ); + conflicts = conflicts+" "+rconflicts; + + this->shell->setCommand("apt-get -s remove "+conflicts); + this->shell->start(true); + QStringList removeList = QStringList::split( "\n", this->shell->getBuffer().stripWhiteSpace() ).grep("Remv"); + + + for(uint i = 0; i < removeList.count(); i++) + { + QString name = QStringList::split( " ", removeList[i] )[1]; + QString sysVersion = QStringList::split( " [", removeList[i] )[1].replace("]", ""); + + QListViewItem * item = new QListViewItem( dependenciesListView, 0 ); + item->setPixmap( 0, QPixmap( "/usr/share/kdpkg/icons/remove.png") ); + item->setText( 1, name ); + item->setText( 3, sysVersion ); + + removePkg += name+","; + } +} + +//----------------------------------------------------------------------------// +//--- isInstalled ------------------------------------------------------------// +//----------------------------------------------------------------------------// + +bool install::isInstalled(QString input) +{ + QString package = QStringList::split( " ", input )[0]; + QString version = QStringList::split( " (", input )[1].replace(")", ""); + + + this->shell->setCommand("apt-cache policy "+package); + this->shell->start(true); + QString sysVersion = QStringList::split( "\n", this->shell->getBuffer().stripWhiteSpace() )[1]; + sysVersion = QStringList::split( ":", sysVersion)[1].replace(" ",""); + + + if( sysVersion.contains("(") || sysVersion == "" ) + return FALSE; + else if( version != "" ) + { + QString op = QStringList::split( " ", version )[0]; + QString pkgVersion = QStringList::split( " ", version )[1]; + + this->shell->setCommand("if dpkg --compare-versions "+sysVersion+" \""+op+"\" "+pkgVersion+"; then echo \"TRUE\"; fi"); + this->shell->start(true); + if( this->shell->getBuffer().stripWhiteSpace() == "TRUE" ) + return TRUE; + else + return FALSE; + } + else + return TRUE; +} + +//----------------------------------------------------------------------------// +//--- about ------------------------------------------------------------------// +//----------------------------------------------------------------------------// + +void install::showAbout() +{ + KAboutApplication* about = new KAboutApplication ( this ); + about->show(); +} + +//----------------------------------------------------------------------------// +//--- checks -----------------------------------------------------------------// +//----------------------------------------------------------------------------// + +bool install::checkArchitecture() +{ + QString arch = fields.grep("Architecture:")[0].mid(14); + + if(arch == "all") + return TRUE; + + // get architecture + this->shell->setCommand("dpkg --print-architecture"); + this->shell->start(true); + + if( arch == this->shell->getBuffer().stripWhiteSpace() ) + return TRUE; + + return FALSE; + +} + + +bool install::isLocked() +{ + this->shell->setCommand("apt-get install -s" ); + this->shell->start(true); + if( this->shell->getBuffer().stripWhiteSpace().contains("...") ) + return FALSE; + else + return TRUE; +} + + + + + +#include "install.moc" |