diff --git a/src/lay/SaltManagerInstallConfirmationDialog.ui b/src/lay/SaltManagerInstallConfirmationDialog.ui index d8dcf20e4..104ed0ae7 100644 --- a/src/lay/SaltManagerInstallConfirmationDialog.ui +++ b/src/lay/SaltManagerInstallConfirmationDialog.ui @@ -13,7 +13,7 @@ Ready for Installation - + @@ -25,66 +25,304 @@ - - - Qt::NoFocus - - - false - - - true - - - - Package - - - - - Action - - - - - Version - - - - - Download link - - - - - - - - Press "Ok" to install or update these packages or "Cancel" to abort. - - - - - + Qt::Vertical - - QSizePolicy::Fixed - - - - 20 - 6 - - - - - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - + + + + + + Qt::NoFocus + + + false + + + true + + + + Package + + + + + Action + + + + + Version + + + + + Download link + + + + + + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Press "Ok" to install or update these packages or "Cancel" to abort. + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 6 + + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 300 + 20 + + + + + + + + Ok + + + + + + + Cancel + + + + + + + + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 16 + 16 + + + + false + + + QListView::Adjust + + + true + + + false + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + :/warn_16.png + + + + + + + There are errors or warnings + + + + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Close + + + + + + + + + + + @@ -128,38 +366,5 @@ - - - buttonBox - accepted() - SaltManagerInstallConfirmationDialog - accept() - - - 273 - 431 - - - 276 - 448 - - - - - buttonBox - rejected() - SaltManagerInstallConfirmationDialog - reject() - - - 351 - 426 - - - 363 - 445 - - - - + diff --git a/src/lay/images/marked_64.png b/src/lay/images/marked_64.png index 02c23d603..52103f767 100644 Binary files a/src/lay/images/marked_64.png and b/src/lay/images/marked_64.png differ diff --git a/src/lay/laySaltDownloadManager.cc b/src/lay/laySaltDownloadManager.cc index 08956c7f6..efe5066b5 100644 --- a/src/lay/laySaltDownloadManager.cc +++ b/src/lay/laySaltDownloadManager.cc @@ -25,8 +25,7 @@ #include "tlFileUtils.h" #include "tlWebDAV.h" -#include "ui_SaltManagerInstallConfirmationDialog.h" - +#include #include #include @@ -35,32 +34,81 @@ namespace lay // ---------------------------------------------------------------------------------- -class ConfirmationDialog - : public QDialog, private Ui::SaltManagerInstallConfirmationDialog +ConfirmationDialog::ConfirmationDialog (QWidget *parent) + : QDialog (parent), m_confirmed (false), m_cancelled (false), m_closed (false), m_file (50000, true) { -public: - ConfirmationDialog (QWidget *parent) - : QDialog (parent) - { - Ui::SaltManagerInstallConfirmationDialog::setupUi (this); + Ui::SaltManagerInstallConfirmationDialog::setupUi (this); + + connect (ok_button, SIGNAL (clicked ()), this, SLOT (confirm_pressed ())); + connect (cancel_button, SIGNAL (clicked ()), this, SLOT (cancel_pressed ())); + connect (close_button, SIGNAL (clicked ()), this, SLOT (close_pressed ())); + + log_panel->hide (); + attn_frame->hide (); + log_view->setModel (&m_file); + + connect (&m_file, SIGNAL (layoutChanged ()), log_view, SLOT (scrollToBottom ())); + connect (&m_file, SIGNAL (attention_changed (bool)), attn_frame, SLOT (setVisible (bool))); +} + +void +ConfirmationDialog::add_info (const std::string &name, bool update, const std::string &version, const std::string &url) +{ + QTreeWidgetItem *item = new QTreeWidgetItem (list); + m_items_by_name.insert (std::make_pair (name, item)); + + item->setFlags (item->flags () & ~Qt::ItemIsSelectable); + + item->setText (0, tl::to_qstring (name)); + item->setText (1, update ? tr ("UPDATE") : tr ("INSTALL")); + item->setText (2, tl::to_qstring (version)); + item->setText (3, tl::to_qstring (url)); + + for (int column = 0; column < list->colorCount (); ++column) { + item->setData (column, Qt::ForegroundRole, update ? Qt::blue : Qt::black); } +} - void add_info (const std::string &name, bool update, const std::string &version, const std::string &url) - { - QTreeWidgetItem *item = new QTreeWidgetItem (list); +void +ConfirmationDialog::separator () +{ + m_file.separator (); +} - item->setFlags (item->flags () & ~Qt::ItemIsSelectable); +void +ConfirmationDialog::mark_error (const std::string &name) +{ + set_icon_for_name (name, QIcon (QString::fromUtf8 (":/error_16.png"))); +} - item->setText (0, tl::to_qstring (name)); - item->setText (1, update ? tr ("UPDATE") : tr ("INSTALL")); - item->setText (2, tl::to_qstring (version)); - item->setText (3, tl::to_qstring (url)); +void +ConfirmationDialog::mark_success (const std::string &name) +{ + set_icon_for_name (name, QIcon (QString::fromUtf8 (":/marked_16.png"))); +} - for (int column = 0; column < list->colorCount (); ++column) { - item->setData (column, Qt::ForegroundRole, update ? Qt::blue : Qt::black); - } +void +ConfirmationDialog::set_icon_for_name (const std::string &name, const QIcon &icon) +{ + std::map::const_iterator i = m_items_by_name.find (name); + if (i != m_items_by_name.end ()) { + i->second->setData (0, Qt::DecorationRole, icon); } -}; +} + +void +ConfirmationDialog::start () +{ + confirm_panel->hide (); + log_panel->show (); + close_button->setEnabled (false); +} + +void +ConfirmationDialog::finish () +{ + close_button->setEnabled (true); +} // ---------------------------------------------------------------------------------- @@ -182,23 +230,17 @@ SaltDownloadManager::fetch_missing (const lay::Salt &salt_mine, tl::AbsoluteProg } } -bool -SaltDownloadManager::show_confirmation_dialog (QWidget *parent, const lay::Salt &salt) +lay::ConfirmationDialog * +SaltDownloadManager::make_confirmation_dialog (QWidget *parent, const lay::Salt &salt) { - // Stop with a warning if there is nothing to do - if (m_registry.empty()) { - QMessageBox::warning (parent, tr ("Nothing to do"), tr ("No packages need update or are marked for installation")); - return false; - } - - lay::ConfirmationDialog dialog (parent); + lay::ConfirmationDialog *dialog = new lay::ConfirmationDialog (parent); // First the packages to update for (std::map::const_iterator p = m_registry.begin (); p != m_registry.end (); ++p) { const lay::SaltGrain *g = salt.grain_by_name (p->first); if (g) { // \342\206\222 is UTF-8 "right arrow" - dialog.add_info (p->first, true, g->version () + " \342\206\222 " + p->second.version, p->second.url); + dialog->add_info (p->first, true, g->version () + " \342\206\222 " + p->second.version, p->second.url); } } @@ -206,19 +248,37 @@ SaltDownloadManager::show_confirmation_dialog (QWidget *parent, const lay::Salt for (std::map::const_iterator p = m_registry.begin (); p != m_registry.end (); ++p) { const lay::SaltGrain *g = salt.grain_by_name (p->first); if (!g) { - dialog.add_info (p->first, false, p->second.version, p->second.url); + dialog->add_info (p->first, false, p->second.version, p->second.url); } } - return dialog.exec (); + return dialog; } bool -SaltDownloadManager::execute (lay::Salt &salt) +SaltDownloadManager::execute (QWidget *parent, lay::Salt &salt) { - bool result = true; + // Stop with a warning if there is nothing to do + if (m_registry.empty()) { + QMessageBox::warning (parent, tr ("Nothing to do"), tr ("No packages need update or are marked for installation")); + return true; + } - tl::RelativeProgress progress (tl::to_string (QObject::tr ("Downloading packages")), m_registry.size (), 1); + std::auto_ptr dialog (make_confirmation_dialog (parent, salt)); + + dialog->setModal (true); + dialog->show (); + + while (! dialog->is_confirmed ()) { + QCoreApplication::processEvents (QEventLoop::AllEvents | QEventLoop::WaitForMoreEvents, 100); + if (dialog->is_cancelled () || ! dialog->isVisible ()) { + return false; + } + } + + dialog->start (); + + bool result = true; for (std::map::const_iterator p = m_registry.begin (); p != m_registry.end (); ++p) { @@ -230,13 +290,22 @@ SaltDownloadManager::execute (lay::Salt &salt) } if (! salt.create_grain (p->second.grain, target)) { + dialog->mark_error (p->first); result = false; + } else { + dialog->mark_success (p->first); } - ++progress; + dialog->separator (); } + dialog->finish (); + + while (! dialog->is_closed () && dialog->isVisible ()) { + QCoreApplication::processEvents (QEventLoop::AllEvents | QEventLoop::WaitForMoreEvents, 100); + } + return result; } diff --git a/src/lay/laySaltDownloadManager.h b/src/lay/laySaltDownloadManager.h index 89fd74620..43490537e 100644 --- a/src/lay/laySaltDownloadManager.h +++ b/src/lay/laySaltDownloadManager.h @@ -25,8 +25,11 @@ #include "layCommon.h" #include "laySaltGrain.h" +#include "layLogViewerDialog.h" #include "tlProgress.h" +#include "ui_SaltManagerInstallConfirmationDialog.h" + #include #include #include @@ -36,6 +39,40 @@ namespace lay class Salt; +class ConfirmationDialog + : public QDialog, private Ui::SaltManagerInstallConfirmationDialog +{ +Q_OBJECT + +public: + ConfirmationDialog (QWidget *parent); + + void add_info (const std::string &name, bool update, const std::string &version, const std::string &url); + + bool is_confirmed () const { return m_confirmed; } + bool is_cancelled () const { return m_cancelled; } + bool is_closed () const { return m_closed; } + + void start (); + void separator (); + void finish (); + + void mark_error (const std::string &name); + void mark_success (const std::string &name); + +private slots: + void confirm_pressed () { m_confirmed = true; } + void cancel_pressed () { m_cancelled = true; } + void close_pressed () { m_closed = true; } + +private: + bool m_confirmed, m_cancelled, m_closed; + lay::LogFile m_file; + std::map m_items_by_name; + + void set_icon_for_name (const std::string &name, const QIcon &icon); +}; + /** * @brief The download manager * @@ -73,25 +110,16 @@ public: */ void compute_dependencies (const lay::Salt &salt, const Salt &salt_mine); - /** - * @brief Presents a dialog showing the packages scheduled for download - * - * This method requires all dependencies to be computed. It will return false - * if the dialog is not confirmed. - * - * "salt" needs to be the currently installed packages so the dialog can - * indicate which packages will be updated. - */ - bool show_confirmation_dialog (QWidget *parent, const lay::Salt &salt); - /** * @brief Actually execute the downloads * - * This method will return false if anything goes wrong. - * Failed packages will be removed entirely after they have been listed in - * an error dialog. + * This method will show a confirmation dialog and start installation + * if this dialog is confirmed. It will return false if + * the dialog was cancelled and an exception if something goes + * wrong. + * It will return true if the packages were installed successfully. */ - bool execute (lay::Salt &salt); + bool execute (QWidget *parent, lay::Salt &salt); private: struct Descriptor @@ -110,6 +138,7 @@ private: bool needs_iteration (); void fetch_missing (const lay::Salt &salt_mine, tl::AbsoluteProgress &progress); + lay::ConfirmationDialog *make_confirmation_dialog (QWidget *parent, const lay::Salt &salt); }; } diff --git a/src/lay/laySaltManagerDialog.cc b/src/lay/laySaltManagerDialog.cc index 2fbcd53aa..6e07bb979 100644 --- a/src/lay/laySaltManagerDialog.cc +++ b/src/lay/laySaltManagerDialog.cc @@ -529,16 +529,12 @@ BEGIN_PROTECTED } manager.compute_dependencies (*mp_salt, m_salt_mine); - - if (manager.show_confirmation_dialog (this, *mp_salt)) { + if (manager.execute (this, *mp_salt)) { if (update) { unmark_all_update (); } else { unmark_all_new (); } - if (! manager.execute (*mp_salt)) { - throw tl::Exception (tl::to_string (tr ("Failed to install some of the selected packages. Please see log for details."))); - } } END_PROTECTED