From 01a3b7ad4464682c1d4319151ab7791f6f0a9dd8 Mon Sep 17 00:00:00 2001
From: tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>
Date: Sat, 3 Apr 2010 22:53:41 +0000
Subject: Made program functional again

git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kdpkg@1110662 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
---
 kdpkg-install/Makefile.am |  2 +-
 kdpkg-install/console.cpp | 32 +++++++++++++++++++++++++-
 kdpkg-install/console.h   |  3 +++
 kdpkg-install/install.cpp | 57 ++++++++++++++++++++++++++++++++++++++---------
 kdpkg-install/install.h   |  1 +
 kdpkg-install/main.cpp    |  7 +++---
 kdpkg-install/process.cpp |  2 +-
 kdpkg-install/sh/kdpkg-sh | 39 +++++++++++++++++++++++---------
 kdpkg/Makefile.am         |  2 +-
 kdpkg/kdpkg.cpp           |  3 ++-
 kdpkg/main.cpp            |  7 +++---
 11 files changed, 124 insertions(+), 31 deletions(-)

diff --git a/kdpkg-install/Makefile.am b/kdpkg-install/Makefile.am
index c0ed3d9..18dde5c 100644
--- a/kdpkg-install/Makefile.am
+++ b/kdpkg-install/Makefile.am
@@ -9,7 +9,7 @@ METASOURCES = AUTO
 
 # the application source, library search path, and link libraries
 kdpkg_install_SOURCES = main.cpp install.cpp installdialog.ui process.cpp  console.cpp consoledialog.ui
-kdpkg_install_LDFLAGS = $(KDE_RPATH) $(all_libraries)
+kdpkg_install_LDFLAGS = $(KDE_RPATH) $(all_libraries) -lkio
 kdpkg_install_LDADD = $(LIB_KDEUI)
 
 
diff --git a/kdpkg-install/console.cpp b/kdpkg-install/console.cpp
index cc6f450..f1dfaa9 100644
--- a/kdpkg-install/console.cpp
+++ b/kdpkg-install/console.cpp
@@ -28,21 +28,51 @@
 #include <qwidgetstack.h>
 #include <qlistview.h>
 #include <qtextedit.h>
+#include <qstring.h>
 
 #include <qlabel.h>
 #include <qpushbutton.h>
 
 #include "console.h"
 
+#include <string>
+#include <stdio.h>
+
+using namespace std;
+
 console::console(QWidget *parent, const QStrList &run, const char *name, const QStringList &)
 : Widget(parent,name)
 {
+
+	// Get KDE prefix
+	// FIXME Is there a better way to do this???
+	string prefixcommand="kde-config --prefix";
+	FILE *pipe_prefix;
+	char prefix_result[2048];
+	int i;
+
+	if ((pipe_prefix = popen(prefixcommand.c_str(), "r")) == NULL)
+	{
+		m_kdePrefix = "/usr";
+	}
+	else {
+		fgets(prefix_result, 2048, pipe_prefix);
+		pclose(pipe_prefix);
+		for (i=0;i<2048;i++) {
+			if (prefix_result[i] == 0) {
+				prefix_result[i-1]=0;
+				i=2048;
+			}
+		}
+		m_kdePrefix = QString(prefix_result);
+	}
+
 	//label->setText( name );
 	loadKonsole();
 	konsoleFrame->installEventFilter( this );
 
 	// run command
-	terminal()->startProgram( "/usr/share/kdpkg/sh/kdpkg-sh", run );
+	terminal()->startProgram( m_kdePrefix + "/share/kdpkg/sh/kdpkg-sh", run );
 	connect( konsole, SIGNAL(destroyed()), this, SLOT( finish() ) );
 
 }
diff --git a/kdpkg-install/console.h b/kdpkg-install/console.h
index b2fd554..739969b 100644
--- a/kdpkg-install/console.h
+++ b/kdpkg-install/console.h
@@ -24,6 +24,8 @@
 
 #include "consoledialog.h"
 
+#include <qstring.h>
+
 #include <kde_terminal_interface.h>
 #include <kparts/part.h>
 
@@ -39,6 +41,7 @@ class console : public Widget
 			return static_cast<ExtTerminalInterface*>(konsole->qt_cast( "ExtTerminalInterface" ) );
 		}
 		virtual bool eventFilter( QObject *o, QEvent *e );
+		QString m_kdePrefix;
 
 	public slots:
 		virtual void finish();
diff --git a/kdpkg-install/install.cpp b/kdpkg-install/install.cpp
index 2501da4..9904018 100644
--- a/kdpkg-install/install.cpp
+++ b/kdpkg-install/install.cpp
@@ -21,6 +21,7 @@
 
 #include <kgenericfactory.h>
 #include <klocale.h>
+#include <kfiledialog.h>
 #include <kurlrequester.h>
 #include <kaboutapplication.h>
 
@@ -37,13 +38,17 @@
 #include <console.h>
 #include <install.h>
 
+#include <string>
+#include <stdio.h>
+
+using namespace std;
+
 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") );
+		path = KFileDialog::getOpenFileName( QString::null, i18n("Debian Package (*.deb)"), this, i18n("Choose a Debian package file to open"));
 	else
 		path = url;
 
@@ -56,7 +61,28 @@ install::install( const QString &url, QWidget *parent, const char *name, const Q
 	installPushButton->hide();
 	nextPushButton1->hide();
 
+	// Get KDE prefix
+	// FIXME Is there a better way to do this???
+	string prefixcommand="kde-config --prefix";
+	FILE *pipe_prefix;
+	char prefix_result[2048];
+	int i;
 
+	if ((pipe_prefix = popen(prefixcommand.c_str(), "r")) == NULL)
+	{
+		m_kdePrefix = "/usr";
+	}
+	else {
+		fgets(prefix_result, 2048, pipe_prefix);
+		pclose(pipe_prefix);
+		for (i=0;i<2048;i++) {
+			if (prefix_result[i] == 0) {
+				prefix_result[i-1]=0;
+				i=2048;
+			}
+		}
+		m_kdePrefix = QString(prefix_result);
+	}
 
 	if( !checkArchitecture() )
 		page2x1();
@@ -116,7 +142,7 @@ void install::page1()
 
 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>");
+	errorTextLabel->setText("<b>"+i18n("The architecture of this package does not match that of your system.  You will not be able to install this package!")+"</b>");
 	nextPushButton2->hide();
 	widgetStack->raiseWidget(2);
 
@@ -133,10 +159,10 @@ void install::page2x2()
 
 void install::page3()
 {
-	titleTextLabel->setText( "<b>"+i18n( "Resynchronization of the package index files.")+"</b>" );
+	titleTextLabel->setText( "<b>"+i18n( "Resynchronize Package Index")+"</b>" );
 	closePushButton->hide();
 
-	QStrList run; run.append( "/usr/share/kdpkg/sh/kdpkg-sh" );
+	QStrList run; run.append( m_kdePrefix + "/share/kdpkg/sh/kdpkg-sh" );
 		run.append( "update" );
 
 	QWidget *consoleWidget = new console(this, run );
@@ -151,7 +177,7 @@ void install::page4()
 {
 	installPushButton->hide();
 	closePushButton->hide();
-	titleTextLabel->setText( "<b>"+i18n( "Installation of the new package." )+"</b>" );
+	titleTextLabel->setText( "<b>"+i18n( "Install New Package" )+"</b>" );
 
 
 	if( !installPkg )
@@ -159,7 +185,7 @@ void install::page4()
 	if( !removePkg )
 		removePkg = "none";
 
-	QStrList run; run.append( "/usr/share/kdpkg/sh/kdpkg-sh" );
+	QStrList run; run.append( m_kdePrefix + "/share/kdpkg/sh/kdpkg-sh" );
 		run.append( "install" );
 		run.append( path );
 		run.append( installPkg );
@@ -181,6 +207,8 @@ void install::page4()
 
 void install::showDependencies()
 {
+	int start_index;
+	int stop_index;
 
 	// show packages which will be installed
 
@@ -214,7 +242,11 @@ void install::showDependencies()
 		}
 	}
 
-
+	while (missingDepends.find("(") != -1) {
+		start_index = missingDepends.find("(");
+		stop_index = missingDepends.find(")", start_index);
+		missingDepends.replace(start_index, stop_index-start_index+1, "");
+	}
 	this->shell->setCommand("apt-get -s install "+missingDepends);
 	this->shell->start(true);
 	QStringList installList = QStringList::split( "\n", this->shell->getBuffer().stripWhiteSpace() ).grep("Inst");
@@ -234,7 +266,7 @@ void install::showDependencies()
 			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->setPixmap( 0, QPixmap( m_kdePrefix + "/share/kdpkg/icons/install.png") );
 		item->setText( 1, name  );
 		item->setText( 2, pkgVersion );
 		item->setText( 3, sysVersion );
@@ -288,6 +320,11 @@ void install::showDependencies()
 	QString conflicts = fields.grep( "Conflicts" )[0].mid(11);
 	conflicts = conflicts.replace( ",", "" );
 	conflicts = conflicts+" "+rconflicts;
+	while (conflicts.find("(") != -1) {
+		start_index = conflicts.find("(");
+		stop_index = conflicts.find(")", start_index);
+		conflicts.replace(start_index, stop_index-start_index+1, "");
+	}
 
 	this->shell->setCommand("apt-get -s remove "+conflicts);
 	this->shell->start(true);
@@ -300,7 +337,7 @@ void install::showDependencies()
 		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->setPixmap( 0, QPixmap( m_kdePrefix + "/share/kdpkg/icons/remove.png") );
 		item->setText( 1, name );
 		item->setText( 3, sysVersion );
 
diff --git a/kdpkg-install/install.h b/kdpkg-install/install.h
index 96f1844..dafb90d 100644
--- a/kdpkg-install/install.h
+++ b/kdpkg-install/install.h
@@ -37,6 +37,7 @@ class install : public InstallDialog
 		QString removePkg;
 		QString path;
 		QStringList fields;
+		QString m_kdePrefix;
 		bool isInstalled(QString);
 		bool checkArchitecture();
 		bool isLocked();
diff --git a/kdpkg-install/main.cpp b/kdpkg-install/main.cpp
index 45b23d8..e0eec81 100644
--- a/kdpkg-install/main.cpp
+++ b/kdpkg-install/main.cpp
@@ -43,10 +43,11 @@ int main(int argc, char **argv)
 	about->setProgramLogo( QImage("/usr/share/icons/hicolor/32x32/apps/kdpkg.png") );
 	about->setShortDescription( I18N_NOOP("Frontend for dpkg.") );
 	about->setLicense(KAboutData::License_GPL_V2);
-   about->setHomepage("http://linux.wuertz.org");
-   about->setBugAddress("xadras@sidux.com");
-	about->setCopyrightStatement("(c) 2007 Fabian Würtz");
+   about->setHomepage("http://trinity.pearsoncomputing.net");
+   about->setBugAddress("http://bugs.pearsoncomputing.net");
+	about->setCopyrightStatement("(c) 2010 Timothy Pearson\r(c) 2007 Fabian Würtz");
 
+	about->addAuthor("Timothy Pearson (Trinity Project)", I18N_NOOP("Developer"), "kb9vqf@pearsoncomputing.net", "http://trinity.pearsoncomputing.net");
 	about->addAuthor("Fabian Würtz (xadras)", I18N_NOOP("Developer"), "xadras@sidux.com", "http://linux.wuertz.org/");
 
 
diff --git a/kdpkg-install/process.cpp b/kdpkg-install/process.cpp
index 9c02a77..d89ef4a 100644
--- a/kdpkg-install/process.cpp
+++ b/kdpkg-install/process.cpp
@@ -23,7 +23,7 @@
 		_process->clearArguments();
 		_buffer = QString::null;
 		
-		*_process << "/bin/sh";
+		*_process << "/bin/bash";
 		*_process << "-c";
 		*_process << command;
 	}
diff --git a/kdpkg-install/sh/kdpkg-sh b/kdpkg-install/sh/kdpkg-sh
index e192a09..59b3ad1 100755
--- a/kdpkg-install/sh/kdpkg-sh
+++ b/kdpkg-install/sh/kdpkg-sh
@@ -1,12 +1,19 @@
-#!/bin/sh
-# (C) Fabian Wuertz Feb 2008
+#!/bin/bash
+# (c) 2010 Timothy Pearson
+# (c) Fabian Wuertz Feb 2008
 
 
 if [ "$1" == "update" ]; then
 	apt-get update
-	echo ""
-	echo "Done! Press enter to continuo."
-	read
+	if [ $? -eq 0 ]; then
+		echo ""
+		echo "Update OK"
+	else
+		echo ""
+		echo "Errors were encountered while updating the package index"
+		echo "Please press enter to continue"
+		read
+	fi
 fi 
 
 if [ "$1" == "install" ]; then
@@ -19,10 +26,22 @@ if [ "$1" == "install" ]; then
 		apt-get remove $removePackage
 	fi
 	dpkg -i $2
-	apt-get install -f
-	echo ""
-	echo "Done! Press enter to continuo."
-	read
+	if [ $? -eq 0 ]; then
+		apt-get install -f
+		if [ $? -eq 0 ]; then
+			echo ""
+			echo "Installation OK"
+		else
+			echo ""
+			echo "Errors were encountered while installing your package"
+			echo "Please press enter to exit"
+			read
+		fi
+	else
+		echo ""
+		echo "Errors were encountered while installing your package"
+		echo "Please press enter to continue"
+		read
+	fi
 fi 
 
-
diff --git a/kdpkg/Makefile.am b/kdpkg/Makefile.am
index 7f07640..0b9b057 100644
--- a/kdpkg/Makefile.am
+++ b/kdpkg/Makefile.am
@@ -9,7 +9,7 @@ METASOURCES = AUTO
 
 # the application source, library search path, and link libraries
 kdpkg_SOURCES = main.cpp kdpkg.cpp kdpkgdialog.ui process.cpp
-kdpkg_LDFLAGS = $(KDE_RPATH) $(all_libraries)
+kdpkg_LDFLAGS = $(KDE_RPATH) $(all_libraries) -lkio
 kdpkg_LDADD = $(LIB_KDEUI)
 
 
diff --git a/kdpkg/kdpkg.cpp b/kdpkg/kdpkg.cpp
index 57b0c5a..1339089 100644
--- a/kdpkg/kdpkg.cpp
+++ b/kdpkg/kdpkg.cpp
@@ -18,6 +18,7 @@
  */
 
 
+#include <kfiledialog.h>
 #include <kmessagebox.h>
 #include <kgenericfactory.h>
 #include <kaboutapplication.h>
@@ -44,7 +45,7 @@ kdpkg::kdpkg( const QString &url, QWidget *parent, const char *name, const QStri
 	
 
 	if( !url )
-		 path = QFileDialog::getOpenFileName( "", i18n("Debian Package (*.deb)"), this, i18n("open file dialog"), i18n("Choose a file to open") );
+		path = KFileDialog::getOpenFileName( QString::null, i18n("Debian Package (*.deb)"), this, i18n("Choose a Debian package file to open"));
 	else
 		path = url;
 
diff --git a/kdpkg/main.cpp b/kdpkg/main.cpp
index b6d6266..5ac5b2e 100644
--- a/kdpkg/main.cpp
+++ b/kdpkg/main.cpp
@@ -43,10 +43,11 @@ int main(int argc, char **argv)
 	about->setProgramLogo( QImage("/usr/share/icons/hicolor/32x32/apps/kdpkg.png") );
 	about->setShortDescription( I18N_NOOP("Frontend for dpkg.") );
 	about->setLicense(KAboutData::License_GPL_V2);
-   about->setHomepage("http://linux.wuertz.org");
-   about->setBugAddress("xadras@sidux.com");
-	about->setCopyrightStatement("(c) 2007 Fabian Würtz");
+   about->setHomepage("http://trinity.pearsoncomputing.net");
+   about->setBugAddress("http://bugs.pearsoncomputing.net");
+	about->setCopyrightStatement("(c) 2010 Timothy Pearson\r(c) 2007 Fabian Würtz");
 
+	about->addAuthor("Timothy Pearson (Trinity Project)", I18N_NOOP("Developer"), "kb9vqf@pearsoncomputing.net", "http://trinity.pearsoncomputing.net");
 	about->addAuthor("Fabian Würtz (xadras)", I18N_NOOP("Developer"), "xadras@sidux.com", "http://xadras.wordpress.com/");
 
 	
-- 
cgit v1.2.3

