[rkward-cvs] rkward/rkward/dialogs rkloadlibsdialog.cpp, 1.20, 1.21 rkloadlibsdialog.h, 1.7, 1.8

Thomas Friedrichsmeier tfry at users.sourceforge.net
Fri Sep 1 15:06:37 UTC 2006


Update of /cvsroot/rkward/rkward/rkward/dialogs
In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv27153/dialogs

Modified Files:
	rkloadlibsdialog.cpp rkloadlibsdialog.h 
Log Message:
Started adding liblocs-selector to package-management dialog. Several fixes

Index: rkloadlibsdialog.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/dialogs/rkloadlibsdialog.cpp,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** rkloadlibsdialog.cpp	18 Aug 2006 14:37:30 -0000	1.20
--- rkloadlibsdialog.cpp	1 Sep 2006 15:06:35 -0000	1.21
***************
*** 39,42 ****
--- 39,44 ----
  
  #define DOWNLOAD_PACKAGES_COMMAND 1
+ #define GET_CURRENT_LIBLOCS_COMMAND 2
+ #define INSTALL_PACKAGES_COMMAND 1
  
  RKLoadLibsDialog::RKLoadLibsDialog (QWidget *parent, RCommandChain *chain, bool modal) : KDialogBase (KDialogBase::Tabbed, Qt::WStyle_DialogBorder, parent, 0, modal, i18n ("Configure Packages"), KDialogBase::Ok | KDialogBase::Apply | KDialogBase::Cancel | KDialogBase::User1) {
***************
*** 63,66 ****
--- 65,70 ----
  	num_child_widgets = 3;
  	accepted = false;
+ 
+ 	RKGlobals::rInterface ()->issueCommand (".libPaths ()", RCommand::App | RCommand::GetStringVector, QString::null, this, GET_CURRENT_LIBLOCS_COMMAND, chain);
  }
  
***************
*** 142,145 ****
--- 146,159 ----
  		if (command->failed ()) error_dialog->newError (command->error ());
  		emit (downloadComplete ());
+ 	} else if (command->getFlags () == INSTALL_PACKAGES_COMMAND) {
+ 		if (command->failed ()) error_dialog->newError (command->error ());
+ 		emit (installationComplete ());
+ 	} else if (command->getFlags () == GET_CURRENT_LIBLOCS_COMMAND) {
+ 		RK_ASSERT (command->stringVectorLength () > 0);
+ 		QStringList current_library_locations;
+ 		for (int i=0; i < command->stringVectorLength (); ++i) {
+ 			current_library_locations.append (command->getStringVector ()[i]);
+ 		}
+ 		emit (libraryLocationsChanged (current_library_locations));
  	} else {
  		RK_ASSERT (false);
***************
*** 222,225 ****
--- 236,259 ----
  }
  
+ bool RKLoadLibsDialog::installPackages (const QStringList &packages, const QString &to_libloc, bool install_dependencies) {
+ 	RK_TRACE (DIALOGS);
+ 
+ 	QString download_arg;
+ 	if (RKSettingsModuleRPackages::archivePackages ()) download_arg = ", destdir=\"" + QDir (RKSettingsModuleGeneral::filesPath ()).filePath (".packagetemp") + "\"";
+ 
+ 	QString dependencies_arg;
+ 	if (install_dependencies) dependencies_arg = ", dependencies=TRUE"; 
+ 
+ 	if (packages.isEmpty ()) return false;
+ 
+ 	QString package_string = "c (\"" + packages.join ("\", \"") + "\")";
+ 	RCommand *command = new RCommand ("install.packages (pkgs=" + package_string + ", lib=\"" + to_libloc + "\"" + download_arg + dependencies_arg + ")", RCommand::App, QString::null, this, INSTALL_PACKAGES_COMMAND);
+ 	RKGlobals::rInterface ()->issueCommand (command, chain);
+ 
+ 	if (RKCancelDialog::showCancelDialog (i18n ("Downloading / Installing"), i18n ("Please, stand by while downloading/installing selected packages."), this, this, SIGNAL (installationComplete ()), command) == QDialog::Rejected) return false;
+ 	return true;
+ }
+ 
+ 
  void RKLoadLibsDialog::installationProcessOutput (KProcess *, char *buffer, int buflen) {
  	RK_TRACE (DIALOGS);
***************
*** 430,435 ****
  	updateable_view->addColumn (i18n ("Name"));
  	updateable_view->addColumn (i18n ("Location"));
! 	updateable_view->addColumn (i18n ("Local"));
! 	updateable_view->addColumn (i18n ("Online"));
  	updateable_view->setSelectionMode (QListView::Extended);
  	hbox->addWidget (updateable_view);
--- 464,469 ----
  	updateable_view->addColumn (i18n ("Name"));
  	updateable_view->addColumn (i18n ("Location"));
! 	updateable_view->addColumn (i18n ("Local Version"));
! 	updateable_view->addColumn (i18n ("Online Version"));
  	updateable_view->setSelectionMode (QListView::Extended);
  	hbox->addWidget (updateable_view);
***************
*** 441,445 ****
  	connect (update_selected_button, SIGNAL (clicked ()), this, SLOT (updateSelectedButtonClicked ()));
  	update_all_button = new QPushButton (i18n ("Update All"), this);
! 	connect (update_selected_button, SIGNAL (clicked ()), this, SLOT (updateAllButtonClicked ()));
  	become_root_box = new QCheckBox (i18n ("As \"root\" user"), this);
  	become_root_box->setChecked (true);
--- 475,482 ----
  	connect (update_selected_button, SIGNAL (clicked ()), this, SLOT (updateSelectedButtonClicked ()));
  	update_all_button = new QPushButton (i18n ("Update All"), this);
! 	connect (update_all_button, SIGNAL (clicked ()), this, SLOT (updateAllButtonClicked ()));
! 	install_params = new PackageInstallParamsWidget (this, false);
! 	connect (parent, SIGNAL (libraryLocationsChanged (const QStringList &)), install_params, SLOT (liblocsChanged (const QStringList &)));
! 
  	become_root_box = new QCheckBox (i18n ("As \"root\" user"), this);
  	become_root_box->setChecked (true);
***************
*** 449,452 ****
--- 486,490 ----
  	buttonvbox->addWidget (update_all_button);
  	buttonvbox->addStretch (1);
+ 	buttonvbox->addWidget (install_params);
  	buttonvbox->addWidget (become_root_box);
  	buttonvbox->addStretch (1);
***************
*** 498,504 ****
  
  void UpdatePackagesWidget::updatePackages (const QStringList &list) {
! 	if (!list.isEmpty ()) {
! 		if (parent->downloadPackages (list)) parent->installDownloadedPackages (become_root_box->isChecked ());
! 	}
  }
  
--- 536,545 ----
  
  void UpdatePackagesWidget::updatePackages (const QStringList &list) {
! 	RK_TRACE (DIALOGS);
! 
! 	if (list.isEmpty ()) return;
! 	if (!install_params->checkWritable ()) return;
! 
! 	parent->installPackages (list, install_params->libraryLocation (), install_params->installDependencies ());
  }
  
***************
*** 523,529 ****
  void UpdatePackagesWidget::getListButtonClicked () {
  	RK_TRACE (DIALOGS);
! 	RCommand *command = new RCommand ("as.vector (old.packages ())", RCommand::App | RCommand::GetStringVector, QString::null, this, FIND_OLD_PACKAGES_COMMAND);
  	RKGlobals::rInterface ()->issueCommand (command, parent->chain);
! 	
  	get_list_button->setEnabled (false);
  	RKCancelDialog::showCancelDialog (i18n ("Fetch list"), i18n ("Please, stand by while downloading the list of packages."), this, this, SIGNAL (actionDone ()), command);
--- 564,571 ----
  void UpdatePackagesWidget::getListButtonClicked () {
  	RK_TRACE (DIALOGS);
! 	RCommand *command = new RCommand ("rk.temp.old <- old.packages (); as.vector (c (rk.temp.old[,\"Package\"], rk.temp.old[,\"LibPath\"], rk.temp.old[,\"Installed\"], rk.temp.old[,\"ReposVer\"]))", RCommand::App | RCommand::GetStringVector, QString::null, this, FIND_OLD_PACKAGES_COMMAND);
  	RKGlobals::rInterface ()->issueCommand (command, parent->chain);
! 	RKGlobals::rInterface ()->issueCommand ("rm (rk.temp.old)", RCommand::App, QString::null, 0, 0, parent->chain);
! 
  	get_list_button->setEnabled (false);
  	RKCancelDialog::showCancelDialog (i18n ("Fetch list"), i18n ("Please, stand by while downloading the list of packages."), this, this, SIGNAL (actionDone ()), command);
***************
*** 651,653 ****
--- 693,762 ----
  }
  
+ /////////////////////// PackageInstallParamsWidget //////////////////////////
+ 
+ #include <qcombobox.h>
+ #include <qfileinfo.h>
+ #include <kmessagebox.h>
+ 
+ PackageInstallParamsWidget::PackageInstallParamsWidget (QWidget *parent, bool ask_depends) : QWidget (parent) {
+ 	RK_TRACE (DIALOGS);
+ 
+ 	QVBoxLayout *vbox = new QVBoxLayout (this, 0, KDialog::spacingHint ());
+ 	vbox->addWidget (new QLabel (i18n ("Install packages to:"), this));
+ 	libloc_selector = new QComboBox (this);
+ 	vbox->addWidget (libloc_selector);
+ 
+ 	if (ask_depends) {
+ 		dependencies = new QCheckBox (i18n ("Include dependencies"), this);
+ 		dependencies->setChecked (true);
+ 		vbox->addStretch ();
+ 		vbox->addWidget (dependencies);
+ 	} else {
+ 		dependencies = 0;
+ 	}
+ }
+ 
+ PackageInstallParamsWidget::~PackageInstallParamsWidget () {
+ 	RK_TRACE (DIALOGS);
+ }
+ 
+ bool PackageInstallParamsWidget::installDependencies () {
+ 	RK_TRACE (DIALOGS);
+ 
+ 	if (!dependencies) return false;
+ 	return dependencies->isChecked ();
+ }
+ 
+ QString PackageInstallParamsWidget::libraryLocation () {
+ 	RK_TRACE (DIALOGS);
+ 
+ 	return (libloc_selector->currentText ());
+ }
+ 
+ bool PackageInstallParamsWidget::checkWritable () {
+ 	RK_TRACE (DIALOGS);
+ 
+ 	QFileInfo fi = QFileInfo (libraryLocation ());
+ 	if (libraryLocation ().isEmpty () || (!fi.isWritable ())) {
+ 		KMessageBox::error (this, i18n ("No user writable library location was selected to install the package(s) to. You will probably want to use the \"Configure Repositories\"-button to select a writable directory to install packages to."), i18n ("No writable library location selected"));
+ 		return false;
+ 	}
+ 
+ 	return true;
+ }
+ 
+ void PackageInstallParamsWidget::liblocsChanged (const QStringList &newlist) {
+ 	RK_TRACE (DIALOGS);
+ 
+ 	libloc_selector->clear ();
+ 	bool haveone = false;
+ 	for (QStringList::const_iterator it = newlist.begin (); it != newlist.end (); ++it) {
+ 		QFileInfo fi = QFileInfo (*it);
+ 		if (fi.isWritable ()) {
+ 			haveone = true;
+ 			libloc_selector->insertItem (*it);
+ 		}
+ 	}
+ }
+ 
  #include "rkloadlibsdialog.moc"

Index: rkloadlibsdialog.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/dialogs/rkloadlibsdialog.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** rkloadlibsdialog.h	26 Oct 2005 16:10:31 -0000	1.7
--- rkloadlibsdialog.h	1 Sep 2006 15:06:35 -0000	1.8
***************
*** 26,29 ****
--- 26,30 ----
  
  class QListView;
+ class QComboBox;
  class QPushButton;
  class RKErrorDialog;
***************
*** 33,36 ****
--- 34,38 ----
  class QCheckBox;
  class KProcess;
+ class PackageInstallParamsWidget;
  
  /**
***************
*** 51,54 ****
--- 53,57 ----
  	bool downloadPackages (const QStringList &packages);
  	void installDownloadedPackages (bool become_root);
+ 	bool installPackages (const QStringList &packages, const QString &to_libloc, bool install_dependencies);
  
  	/** opens a modal RKLoadLibsDialog with the "Install new Packages" tab on front (To be used when a require () fails in the R backend */
***************
*** 57,60 ****
--- 60,64 ----
  	void downloadComplete ();
  	void installationComplete ();
+ 	void libraryLocationsChanged (const QStringList &);
  protected:
  	void rCommandDone (RCommand *command);
***************
*** 150,153 ****
--- 154,158 ----
  	QPushButton *get_list_button;
  	QCheckBox *become_root_box;
+ 	PackageInstallParamsWidget *install_params;
  	
  	RKLoadLibsDialog *parent;
***************
*** 187,190 ****
--- 192,216 ----
  };
  
+ /**
+ Simple helper class for RKLoadLibsDialog to allow selection of installation parameters
+ 
+ @author Thomas Friedrichsmeier
+ */
+ class PackageInstallParamsWidget : public QWidget {
+ Q_OBJECT
+ public:
+ 	PackageInstallParamsWidget (QWidget *parent, bool ask_depends);
+ 	
+ 	~PackageInstallParamsWidget ();
+ 
+ 	bool installDependencies ();
+ 	QString libraryLocation ();
+ 	bool checkWritable ();
+ public slots:
+ 	void liblocsChanged (const QStringList &newlist);
+ private:
+ 	QComboBox *libloc_selector;
+ 	QCheckBox *dependencies;
+ };
  
  #endif





More information about the rkward-tracker mailing list