From a1e2b4d3060456db6a2d81e0ceb267b259b695d1 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Tue, 24 Jul 2007 15:34:19 +0000 Subject: [PATCH] reenable media callbacks --- src/CMakeLists.txt | 29 ++++++++++++++++------------- src/zypper-media-callbacks.h | 14 +++++++++----- src/zypper-misc.cc | 24 ++++++++++++++++++++++++ src/zypper-misc.h | 2 ++ 4 files changed, 51 insertions(+), 18 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index af77002..bd3751f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,19 +3,6 @@ ADD_DEFINITIONS ( -DLOCALEDIR=\\\"${CMAKE_INSTALL_PREFIX}/share/locale\\\" ) -SET( zypper_SRCS - zypper.cc - zypper-command.cc - zypper-getopt.cc - zypper-sources.cc - zypper-misc.cc - zypper-utils.cc - zypper-search.cc - zypper-info.cc - zypper-tabulator.cc - zypper-callbacks.cc -) - SET (zypper_HEADERS zypper.h zypper-command.h @@ -33,6 +20,22 @@ SET (zypper_HEADERS zypper-source-callbacks.h ) +SET( zypper_SRCS + zypper.cc + zypper-command.cc + zypper-getopt.cc + zypper-sources.cc + zypper-misc.cc + zypper-utils.cc + zypper-search.cc + zypper-info.cc + zypper-tabulator.cc + zypper-callbacks.cc + ${zypper_HEADERS} +) + + + ADD_EXECUTABLE( zypper ${zypper_SRCS} ) TARGET_LINK_LIBRARIES( zypper ${ZYPP_LIBRARY} ${READLINE_LIBRARY} ) diff --git a/src/zypper-media-callbacks.h b/src/zypper-media-callbacks.h index 686bdf6..536f516 100644 --- a/src/zypper-media-callbacks.h +++ b/src/zypper-media-callbacks.h @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -26,23 +27,25 @@ using zypp::media::MediaChangeReport; using zypp::media::DownloadProgressReport; +using zypp::Repository; /////////////////////////////////////////////////////////////////// namespace ZmartRecipients { struct MediaChangeReportReceiver : public zypp::callback::ReceiveReport - {/* - virtual MediaChangeReport::Action requestMedia( zypp::Source_Ref source, unsigned mediumNr, MediaChangeReport::Error error, const std::string & description ) - { + { + virtual MediaChangeReport::Action requestMedia( Repository repo, + unsigned mediumNr, + MediaChangeReport::Error error, + const std::string & description ) + { cout << "Please insert media [" << description << "] # " << mediumNr << ". Retry [y/n]: " << endl; if (readBoolAnswer()) return MediaChangeReport::RETRY; else return MediaChangeReport::ABORT; - } - */ }; // progress for downloading a file @@ -87,6 +90,7 @@ class MediaCallbacks { public: MediaCallbacks() { + MIL << "Set media callbacks.." << endl; _mediaChangeReport.connect(); _mediaDownloadReport.connect(); } diff --git a/src/zypper-misc.cc b/src/zypper-misc.cc index e29b05a..2a0745a 100644 --- a/src/zypper-misc.cc +++ b/src/zypper-misc.cc @@ -25,6 +25,30 @@ extern ZYpp::Ptr God; extern RuntimeData gData; extern Settings gSettings; +// return the default value on input failure +// TODO make this locale dependent? +bool read_bool_with_default (bool defval) { + istream & stm = cin; + + string c = ""; + while (stm.good () && c != "y" && c != "Y" && c != "N" && c != "n") + c = zypp::str::getline (stm, zypp::str::TRIM); + + if (c == "y" || c == "Y") + return true; + else if (c == "n" || c == "N") + return false; + else + return defval; +} + +// Read an answer (ynYN) +// Defaults to 'false' +bool readBoolAnswer() +{ + return read_bool_with_default (false); +} + void cond_init_target () { static bool done = false; diff --git a/src/zypper-misc.h b/src/zypper-misc.h index f8d683c..333b067 100644 --- a/src/zypper-misc.h +++ b/src/zypper-misc.h @@ -16,6 +16,8 @@ #include "zypp/PoolItem.h" #include "zypper-tabulator.h" +bool readBoolAnswer(); + /** * Initialize rpm database on target, if not already initialized. */ -- 2.7.4