[rkward-cvs] SF.net SVN: rkward:[3827] trunk/rkward
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Sun Sep 25 12:40:12 UTC 2011
Revision: 3827
http://rkward.svn.sourceforge.net/rkward/?rev=3827&view=rev
Author: tfry
Date: 2011-09-25 12:40:12 +0000 (Sun, 25 Sep 2011)
Log Message:
-----------
If the selected library location is not writable, offer to add and use a default one. Also some minor cleanups.
Modified Paths:
--------------
trunk/rkward/ChangeLog
trunk/rkward/rkward/dialogs/rkloadlibsdialog.cpp
trunk/rkward/rkward/dialogs/rkloadlibsdialog.h
trunk/rkward/rkward/settings/rksettingsmoduler.cpp
trunk/rkward/rkward/settings/rksettingsmoduler.h
Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog 2011-09-25 12:29:45 UTC (rev 3826)
+++ trunk/rkward/ChangeLog 2011-09-25 12:40:12 UTC (rev 3827)
@@ -1,4 +1,5 @@
-- Reworked package installation / update dialog TODO: implement removing, "check all updateable", clean layout, fix size, more tips, fix sorting
+- Offer to add a new library location, automatically, if location selected for installation is not writable
+- Reworked package installation / update dialog TODO: implement removing, more tips
- Fixed: Integrated help browser would not update navigation history when following page internal links
- Documentation on writing RKWard plugins is now accessible, locally
- The file filter for R script files is now configurable, and includes *.Rhistory, by default
Modified: trunk/rkward/rkward/dialogs/rkloadlibsdialog.cpp
===================================================================
--- trunk/rkward/rkward/dialogs/rkloadlibsdialog.cpp 2011-09-25 12:29:45 UTC (rev 3826)
+++ trunk/rkward/rkward/dialogs/rkloadlibsdialog.cpp 2011-09-25 12:40:12 UTC (rev 3827)
@@ -162,19 +162,31 @@
if (command->getFlags () == GET_CURRENT_LIBLOCS_COMMAND) {
RK_ASSERT (command->getDataType () == RData::StringVector);
RK_ASSERT (command->getDataLength () > 0);
- QStringList current_library_locations;
+ library_locations.clear ();
for (unsigned int i=0; i < command->getDataLength (); ++i) {
- current_library_locations.append (command->getStringVector ()[i]);
+ library_locations.append (command->getStringVector ()[i]);
}
- emit (libraryLocationsChanged (current_library_locations));
+ emit (libraryLocationsChanged (library_locations));
} else {
RK_ASSERT (false);
}
}
+void RKLoadLibsDialog::addLibraryLocation (const QString& new_loc) {
+ RK_TRACE (DIALOGS);
+
+ if (library_locations.contains (new_loc)) return;
+
+ if (QDir ().mkpath (new_loc)) RKSettingsModuleRPackages::addLibraryLocation (new_loc, chain);
+ library_locations.prepend (new_loc);
+ emit (libraryLocationsChanged (library_locations));
+}
+
bool RKLoadLibsDialog::installPackages (const QStringList &packages, const QString &to_libloc, bool install_dependencies, bool as_root, const QStringList& repos) {
RK_TRACE (DIALOGS);
+ addLibraryLocation (to_libloc);
+
if (packages.isEmpty ()) return false;
QString command_string = "install.packages (pkgs=c (\"" + packages.join ("\", \"") + "\")" + ", lib=\"" + to_libloc + "\"";
QString downloaddir = QDir (RKSettingsModuleGeneral::filesPath ()).filePath ("package_archive");
@@ -548,6 +560,7 @@
packages_view->setEnabled (false);
packages_view->setMinimumHeight (packages_view->sizeHintForRow (0) * 15); // force a decent height
hbox->addWidget (packages_view);
+ hbox->setStretchFactor (packages_view, 2);
QVBoxLayout *buttonvbox = new QVBoxLayout ();
hbox->addLayout (buttonvbox);
@@ -560,7 +573,7 @@
mark_all_updates_button = new QPushButton (i18n ("Select all updates"), this);
connect (mark_all_updates_button, SIGNAL (clicked()), this, SLOT (markAllUpdates()));
- install_params = new PackageInstallParamsWidget (this, true);
+ install_params = new PackageInstallParamsWidget (this);
connect (parent, SIGNAL (libraryLocationsChanged (const QStringList &)), install_params, SLOT (liblocsChanged (const QStringList &)));
buttonvbox->addWidget (label);
@@ -588,16 +601,6 @@
if (!packages_status->initialized ()) initialize ();
}
-void InstallPackagesWidget::installPackages (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, packages_status->currentRepositories ());
-}
-
void InstallPackagesWidget::initialize () {
RK_TRACE (DIALOGS);
@@ -633,24 +636,34 @@
packages_view->scrollTo (model->mapFromSource (index));
}
-void InstallPackagesWidget::doInstall () {
+void InstallPackagesWidget::doInstall (bool refresh) {
RK_TRACE (DIALOGS);
- installPackages (packages_status->packagesToInstall ());
- packages_status->clearStatus ();
+ QStringList install = packages_status->packagesToInstall ();
+ if (!install.isEmpty ()) {
+ bool as_root = false;
+
+ QString dest = install_params->getInstallLocation (&as_root, parent->chain);
+ if (!dest.isEmpty ()) {
+ parent->installPackages (install, dest, install_params->installDependencies (), as_root, packages_status->currentRepositories ());
+ if (refresh) {
+ packages_status->clearStatus ();
+ initialize ();
+ }
+ }
+ }
}
void InstallPackagesWidget::apply () {
RK_TRACE (DIALOGS);
- doInstall ();
- initialize (); // refresh list
+ doInstall (true);
}
void InstallPackagesWidget::ok () {
RK_TRACE (DIALOGS);
- doInstall ();
+ doInstall (false);
deleteLater ();
}
@@ -664,7 +677,7 @@
#include <qcombobox.h>
#include <qfileinfo.h>
-PackageInstallParamsWidget::PackageInstallParamsWidget (QWidget *parent, bool ask_depends) : QWidget (parent) {
+PackageInstallParamsWidget::PackageInstallParamsWidget (QWidget *parent) : QWidget (parent) {
RK_TRACE (DIALOGS);
QVBoxLayout *vbox = new QVBoxLayout (this);
@@ -673,14 +686,10 @@
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;
- }
+ dependencies = new QCheckBox (i18n ("Include dependencies"), this);
+ dependencies->setChecked (true);
+ vbox->addStretch ();
+ vbox->addWidget (dependencies);
}
PackageInstallParamsWidget::~PackageInstallParamsWidget () {
@@ -690,44 +699,36 @@
bool PackageInstallParamsWidget::installDependencies () {
RK_TRACE (DIALOGS);
- if (!dependencies) return false;
return dependencies->isChecked ();
}
-QString PackageInstallParamsWidget::libraryLocation () {
+QString PackageInstallParamsWidget::getInstallLocation (bool *as_root, RCommandChain *chain) {
RK_TRACE (DIALOGS);
-
- return (libloc_selector->currentText ());
-}
-
-bool PackageInstallParamsWidget::checkWritable (bool *as_root) {
- RK_TRACE (DIALOGS);
RK_ASSERT (as_root);
- QFileInfo fi = QFileInfo (libraryLocation ());
+ *as_root = false;
+ QString libloc = libloc_selector->currentText ();
+ QString altlibloc = QDir (RKSettingsModuleGeneral::filesPath ()).absoluteFilePath ("library");
+ QFileInfo fi = QFileInfo (libloc);
if (!fi.isWritable ()) {
QString mcaption = i18n ("Selected library location not writable");
- QString message = i18n ("The directory you are trying to install to (%1) is not writable with your current user permissions. "
- "You can chose a different library location to install to (if none are wirtable, you will probably want to use the "
- "\"Configure Repositories\"-button to set up a writable directory to install package to).\n", libraryLocation ());
+ QString message = i18n ("<p>The directory you have selected for installation (%1) is not writable with your current user permissions.</p>"
+ "<p>Would you like to install to %2, instead (you can also press \"Cancel\" and use the \"Configure Repositories\"-button to set up a different directory)?</p>", libloc, altlibloc);
#ifdef Q_WS_WIN
- message.append (i18n ("If have access to an administrator account on this machine, you can use that to install the package(s), or "
- "you could change the permissions of '%1'. Sorry, automatic switching to Administrator is not yet supported in RKWard on Windows", libraryLocation ()));
- int res = KMessageBox::warningContinueCancel (this, message, mcaption, KGuiItem (i18n ("Attempt installation, anyway")));
- if (res == KMessageBox::Continue) return true;
+ message.append (i18n ("<p>Alternatively, if you have access to an administrator account on this machine, you can use that to install the package(s), or "
+ "you could change the permissions of '%1'. Sorry, automatic switching to Administrator is not yet supported in RKWard on Windows.</p>", libloc));
+ int res = KMessageBox::warningContinueCancel (this, message, mcaption, KGuiItem (i18n ("Install to %1", altlibloc)));
+ if (res == KMessageBox::Continue) libloc = altlibloc;
#else
- message.append (i18n ("If you are the administrator of this machine, you can try to install the packages as root (you'll be prompted for the root password)."));
- int res = KMessageBox::warningContinueCancel (this, message, mcaption, KGuiItem (i18n ("Become root")));
- if (res == KMessageBox::Continue) {
- *as_root = true;
- return true;
- }
+ message.append (i18n ("<p>Alternatively, if you are the administrator of this machine, you can try to install the packages as root (you'll be prompted for the root password).</p>"));
+ int res = KMessageBox::warningYesNoCancel (this, message, mcaption, KGuiItem (i18n ("Install to %1", altlibloc)), KGuiItem (i18n ("Become root")));
+ if (res == KMessageBox::Yes) libloc = altlibloc;
+ if (res == KMessageBox::No) *as_root = true;
#endif
- return false;
+ if (res == KMessageBox::Cancel) libloc = QString ();
}
- *as_root = false;
- return true;
+ return libloc;
}
void PackageInstallParamsWidget::liblocsChanged (const QStringList &newlist) {
Modified: trunk/rkward/rkward/dialogs/rkloadlibsdialog.h
===================================================================
--- trunk/rkward/rkward/dialogs/rkloadlibsdialog.h 2011-09-25 12:29:45 UTC (rev 3826)
+++ trunk/rkward/rkward/dialogs/rkloadlibsdialog.h 2011-09-25 12:40:12 UTC (rev 3827)
@@ -64,10 +64,11 @@
@param chain RCommandChain to run the necessary commands in
@param package_name name of the required package */
static void showInstallPackagesModal (QWidget *parent, RCommandChain *chain, const QString &package_name);
+ QStringList currentLibraryLocations () const { return library_locations; };
signals:
void downloadComplete ();
void installationComplete ();
- void libraryLocationsChanged (const QStringList &);
+ void libraryLocationsChanged (const QStringList &liblocs);
void installationOutput (const QString &output);
void installationError (const QString &error);
void installedPackagesChanged ();
@@ -84,6 +85,7 @@
void automatedInstall ();
void slotPageChanged ();
private:
+ void addLibraryLocation (const QString &new_loc);
void tryDestruct ();
friend class LoadUnloadWidget;
friend class InstallPackagesWidget;
@@ -92,6 +94,8 @@
InstallPackagesWidget *install_packages_widget; // needed for automated installation
KPageWidgetItem *install_packages_pageitem;
+ QStringList library_locations;
+
QString auto_install_package;
int num_child_widgets;
bool accepted;
@@ -243,8 +247,7 @@
void activated ();
void markAllUpdates ();
private:
- void doInstall ();
- void installPackages (const QStringList &list);
+ void doInstall (bool refresh);
QTreeView *packages_view;
RKRPackageInstallationStatus *packages_status;
QSortFilterProxyModel *model;
@@ -264,13 +267,12 @@
class PackageInstallParamsWidget : public QWidget {
Q_OBJECT
public:
- PackageInstallParamsWidget (QWidget *parent, bool ask_depends);
+ PackageInstallParamsWidget (QWidget *parent);
~PackageInstallParamsWidget ();
bool installDependencies ();
- QString libraryLocation ();
- bool checkWritable (bool *as_root);
+ QString getInstallLocation (bool *as_root, RCommandChain *chain);
public slots:
void liblocsChanged (const QStringList &newlist);
private:
Modified: trunk/rkward/rkward/settings/rksettingsmoduler.cpp
===================================================================
--- trunk/rkward/rkward/settings/rksettingsmoduler.cpp 2011-09-25 12:29:45 UTC (rev 3826)
+++ trunk/rkward/rkward/settings/rksettingsmoduler.cpp 2011-09-25 12:40:12 UTC (rev 3827)
@@ -366,6 +366,15 @@
RK_TRACE (SETTINGS);
}
+void RKSettingsModuleRPackages::addLibraryLocation (const QString& new_loc, RCommandChain *chain) {
+ RK_TRACE (SETTINGS);
+
+ if (!libraryLocations ().contains (new_loc)) liblocs.append (new_loc);
+
+ // update the backend in any case. User might have changed liblocs, there.
+ RKGlobals::rInterface ()->issueCommand (".libPaths (unique (c (" + RObject::rQuote (new_loc) + ", .libPaths ())))", RCommand::App | RCommand::Sync, QString (), 0, 0, chain);
+}
+
void RKSettingsModuleRPackages::settingChanged () {
RK_TRACE (SETTINGS);
change ();
@@ -421,8 +430,25 @@
}
}
+QString RKSettingsModuleRPackages::libLocsCommand () {
+ RK_TRACE (SETTINGS);
+
+ QString command = ".libPaths (unique (c (";
+ bool first = true;
+ QStringList ll = libraryLocations ();
+ foreach (const QString libloc, ll) {
+ if (first) first = false;
+ else command.append (", ");
+ command.append (RObject::rQuote (libloc));
+ }
+ command.append (")))");
+
+ return command;
+}
+
//static
QStringList RKSettingsModuleRPackages::makeRRunTimeOptionCommands () {
+ RK_TRACE (SETTINGS);
QStringList list;
// package repositories
@@ -433,20 +459,7 @@
list.append (command + "))\n");
// library locations
- command = ".libPaths (unique (c (";
- bool first = true;
- for (QStringList::const_iterator it = liblocs.begin (); it != liblocs.end (); ++it) {
- if (first) first = false;
- else command.append (", ");
- command.append ("\"" + *it + "\"");
- }
- for (QStringList::const_iterator it = defaultliblocs.begin (); it != defaultliblocs.end (); ++it) {
- if (first) first = false;
- else command.append (", ");
- command.append ("\"" + *it + "\"");
- }
- command.append (")))");
- list.append (command);
+ list.append (libLocsCommand ());
return list;
}
Modified: trunk/rkward/rkward/settings/rksettingsmoduler.h
===================================================================
--- trunk/rkward/rkward/settings/rksettingsmoduler.h 2011-09-25 12:29:45 UTC (rev 3826)
+++ trunk/rkward/rkward/settings/rksettingsmoduler.h 2011-09-25 12:40:12 UTC (rev 3827)
@@ -121,6 +121,8 @@
static QStringList makeRRunTimeOptionCommands ();
static bool archivePackages () { return archive_packages; }
+ static void addLibraryLocation (const QString& new_loc, RCommandChain *chain);
+ static QStringList libraryLocations () { return (liblocs + defaultliblocs); };
/** returns the list of packages which are essential to rkward. This is hard-coded. */
static QStringList essentialPackages () { return essential_packages.split ("\n"); };
@@ -134,6 +136,8 @@
protected:
void rCommandDone (RCommand *command);
private:
+ static QString libLocsCommand ();
+
MultiStringSelector *libloc_selector;
QCheckBox *archive_packages_box;
MultiStringSelector *repository_selector;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the rkward-tracker
mailing list