[rkward-cvs] rkward/rkward/dialogs rkloadlibsdialog.cpp, 1.21, 1.22 rkloadlibsdialog.h, 1.8, 1.9

Thomas Friedrichsmeier tfry at users.sourceforge.net
Fri Sep 8 11:17:56 UTC 2006


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

Modified Files:
	rkloadlibsdialog.cpp rkloadlibsdialog.h 
Log Message:
RCommands may have several receivers, RKCommandReceiver does not elaborate housekeeping.
Progress on package installation. New method is still pretty messy, but works in principle

Index: rkloadlibsdialog.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/dialogs/rkloadlibsdialog.cpp,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** rkloadlibsdialog.cpp	1 Sep 2006 15:06:35 -0000	1.21
--- rkloadlibsdialog.cpp	8 Sep 2006 11:17:54 -0000	1.22
***************
*** 24,27 ****
--- 24,28 ----
  #include <qcheckbox.h>
  #include <qdir.h>
+ #include <qregexp.h>
  
  #include <klocale.h>
***************
*** 78,86 ****
  }
  
- void RKLoadLibsDialog::deleteThisNow () {
- 	RK_TRACE (DIALOGS);
- 	deleteLater ();
- }
- 
  //static
  void RKLoadLibsDialog::showInstallPackagesModal (QWidget *parent, RCommandChain *chain) {
--- 79,82 ----
***************
*** 97,101 ****
  
  	if (num_child_widgets <= 0) {
! 		deleteThis ();
  	}
  }
--- 93,97 ----
  
  	if (num_child_widgets <= 0) {
! 		deleteLater ();
  	}
  }
***************
*** 236,256 ****
  }
  
! 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;
  }
  
--- 232,284 ----
  }
  
! bool RKLoadLibsDialog::installPackages (const QStringList &packages, const QString &to_libloc, bool install_dependencies, bool as_root) {
  	RK_TRACE (DIALOGS);
  
! 	if (packages.isEmpty ()) return false;
! 	QString command_string = "install.packages (pkgs=c (\"" + packages.join ("\", \"") + "\")" + ", lib=\"" + to_libloc + "\""; 
! 	if (RKSettingsModuleRPackages::archivePackages ()) command_string += ", destdir=\"" + QDir (RKSettingsModuleGeneral::filesPath ()).filePath (".packagetemp") + "\"";
! 	if (install_dependencies) command_string += ", dependencies=TRUE, repos=\"@CRAN@\"";
! 	command_string += ")";
  
! 	command_string += "; q ()\n";
! 	QFile file (QDir (RKSettingsModuleGeneral::filesPath ()).filePath ("install_script.R"));
! 	if (file.open (IO_WriteOnly)) {
! 		QTextStream stream (&file);
! 		stream << "options (repos=" + repos_string + ")\n" + command_string;
! 		file.close();
! 	}
! 	KProcess *proc = new KProcess;
! 	if (as_root) {
! 		*proc << "kdesu" << "-t";
! 	};
! 	*proc << "$R_HOME/bin/R --no-save < " + file.name ();
  
! 	connect (proc, SIGNAL (processExited (KProcess *)), this, SLOT (processExited (KProcess *)));
! 	connect (proc, SIGNAL (receivedStdout (KProcess *, char *, int)), this, SLOT (installationProcessOutput (KProcess *, char *, int)));
! 	connect (proc, SIGNAL (receivedStderr (KProcess *, char *, int)), this, SLOT (installationProcessOutput (KProcess *, char *, int)));
! 	installation_error_dialog->newError ("test");
! 	proc->start (KProcess::NotifyOnExit, KProcess::AllOutput);
! /*//	if (as_root) {
! 		RK_ASSERT (!repos_string.isEmpty ());
! 		command_string = "options (repos=" + repos_string + ")\n" + command_string;
! //	}
! 	proc->writeStdin (command_string, command_string.length ()); */
  
! 	if (RKCancelDialog::showCancelDialog (i18n ("Installing packages..."), i18n ("Please, stand by while installing packages."), this, this, SIGNAL (installationComplete ())) == QDialog::Rejected) {
! 		proc->kill ();
! 	};
! 	if ((!proc->normalExit ()) || (proc->exitStatus ())) {
! 		installation_error_dialog->newError (QString::null);		// to make sure it is shown
! 	}
! //	installation_error_dialog->resetOutput ();
! 	file.remove ();
! 	delete proc;
! 
! 	return true;
! /*	RCommand *command = new RCommand (command_string, 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; */
  }
  
***************
*** 391,395 ****
  	RK_TRACE (DIALOGS);
  	doLoadUnload ();
! 	deleteThis ();
  }
  
--- 419,423 ----
  	RK_TRACE (DIALOGS);
  	doLoadUnload ();
! 	deleteLater ();
  }
  
***************
*** 443,447 ****
  void LoadUnloadWidget::cancel () {
  	RK_TRACE (DIALOGS);
! 	deleteThis ();
  }
  
--- 471,475 ----
  void LoadUnloadWidget::cancel () {
  	RK_TRACE (DIALOGS);
! 	deleteLater ();
  }
  
***************
*** 513,523 ****
  			delete placeholder;
  			placeholder = 0;
! 			RK_ASSERT ((command->stringVectorLength () % 4) == 0);
  			int count = (command->stringVectorLength () / 4);
  			for (int i=0; i < count; ++i) {
! 				new QListViewItem (updateable_view, command->getStringVector ()[i], command->getStringVector ()[count + i], command->getStringVector ()[2*count + i], command->getStringVector ()[3* count + i]);
  			}
- 			updateable_view->setEnabled (true);
  
  			if (updateable_view->firstChild ()) {
  				update_selected_button->setEnabled (true);
--- 541,552 ----
  			delete placeholder;
  			placeholder = 0;
! 			RK_ASSERT ((command->stringVectorLength () % 4) == 1);
  			int count = (command->stringVectorLength () / 4);
  			for (int i=0; i < count; ++i) {
! 				new QListViewItem (updateable_view, command->getStringVector ()[i], command->getStringVector ()[count + i], command->getStringVector ()[2*count + i], command->getStringVector ()[3*count + i]);
  			}
  
+ 			updateable_view->setEnabled (true);
+ 	
  			if (updateable_view->firstChild ()) {
  				update_selected_button->setEnabled (true);
***************
*** 526,529 ****
--- 555,561 ----
  				placeholder = new QListViewItem (updateable_view, i18n ("[No updates available]"));
  			}
+ 
+ 			// this is after the repository was chosen. Update the repository string.
+ 			parent->repos_string = command->getStringVector ()[4 * count];
  		} else {
  			get_list_button->setEnabled (true);
***************
*** 537,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 ());
  }
  
--- 569,578 ----
  void UpdatePackagesWidget::updatePackages (const QStringList &list) {
  	RK_TRACE (DIALOGS);
+ 	bool as_root = false;
  
  	if (list.isEmpty ()) return;
! 	if (!install_params->checkWritable (&as_root)) return;
  
! 	parent->installPackages (list, install_params->libraryLocation (), install_params->installDependencies (), as_root);
  }
  
***************
*** 564,568 ****
  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);
--- 597,601 ----
  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\"], rk.make.repos.string ()))", 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);
***************
*** 574,583 ****
  void UpdatePackagesWidget::ok () {
  	RK_TRACE (DIALOGS);
! 	deleteThis ();
  }
  
  void UpdatePackagesWidget::cancel () {
  	RK_TRACE (DIALOGS);
! 	deleteThis ();
  }
  
--- 607,616 ----
  void UpdatePackagesWidget::ok () {
  	RK_TRACE (DIALOGS);
! 	deleteLater ();
  }
  
  void UpdatePackagesWidget::cancel () {
  	RK_TRACE (DIALOGS);
! 	deleteLater ();
  }
  
***************
*** 685,694 ****
  void InstallPackagesWidget::ok () {
  	RK_TRACE (DIALOGS);
! 	deleteThis ();
  }
  
  void InstallPackagesWidget::cancel () {
  	RK_TRACE (DIALOGS);
! 	deleteThis ();
  }
  
--- 718,727 ----
  void InstallPackagesWidget::ok () {
  	RK_TRACE (DIALOGS);
! 	deleteLater ();
  }
  
  void InstallPackagesWidget::cancel () {
  	RK_TRACE (DIALOGS);
! 	deleteLater ();
  }
  
***************
*** 734,746 ****
  }
  
! 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;
  }
--- 767,785 ----
  }
  
! bool PackageInstallParamsWidget::checkWritable (bool *as_root) {
  	RK_TRACE (DIALOGS);
+ 	RK_ASSERT (as_root);
  
  	QFileInfo fi = QFileInfo (libraryLocation ());
! 	if (!fi.isWritable ()) {
! 		int res = KMessageBox::questionYesNo (this, i18n ("The directory you are trying to install to (%1) is not writable with your current user permissions. If you are the adminitstrator of this machine, you can try to install the packages as root (you'll be prompted for the root password). Otherwise you'll have to chose a different library location to install to (if none are writable, you will probably want to use the \"Configure Repositories\"-button to set up a writable directory to install packages to).").arg (libraryLocation ()), i18n ("Selected library location not writable"), KGuiItem (i18n ("Become root")), KGuiItem (i18n ("&Cancel")));
! 		if (res == KMessageBox::Yes) {
! 			*as_root = true;
! 			return true;
! 		}
  		return false;
  	}
  
+ 	*as_root = false;
  	return true;
  }
***************
*** 750,761 ****
  
  	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);
! 		}
! 	}
  }
  
--- 789,793 ----
  
  	libloc_selector->clear ();
! 	libloc_selector->insertStringList (newlist);
  }
  

Index: rkloadlibsdialog.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/dialogs/rkloadlibsdialog.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** rkloadlibsdialog.h	1 Sep 2006 15:06:35 -0000	1.8
--- rkloadlibsdialog.h	8 Sep 2006 11:17:54 -0000	1.9
***************
*** 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 */
--- 53,57 ----
  	bool downloadPackages (const QStringList &packages);
  	void installDownloadedPackages (bool become_root);
! 	bool installPackages (const QStringList &packages, const QString &to_libloc, bool install_dependencies, bool as_root);
  
  	/** opens a modal RKLoadLibsDialog with the "Install new Packages" tab on front (To be used when a require () fails in the R backend */
***************
*** 64,70 ****
  	void rCommandDone (RCommand *command);
  	void closeEvent (QCloseEvent *e);
- /** reimplemented from RCommandReceiver to call QObject::deleteLater () instead of delete this. Not entirely sure, what's going on, but otherwise we
- get a double deletion -> crash */
- 	void deleteThisNow ();
  protected slots:
  	void slotOk ();
--- 64,67 ----
***************
*** 86,89 ****
--- 83,87 ----
  	int num_child_widgets;
  	bool accepted;
+ 	QString repos_string;
  };
  
***************
*** 206,210 ****
  	bool installDependencies ();
  	QString libraryLocation ();
! 	bool checkWritable ();
  public slots:
  	void liblocsChanged (const QStringList &newlist);
--- 204,208 ----
  	bool installDependencies ();
  	QString libraryLocation ();
! 	bool checkWritable (bool *as_root);
  public slots:
  	void liblocsChanged (const QStringList &newlist);





More information about the rkward-tracker mailing list