readBoolAnswer() moved from zypper-misc to zypper-callbacks
authorJan Kupec <jkupec@suse.cz>
Mon, 16 Jul 2007 15:41:49 +0000 (15:41 +0000)
committerJan Kupec <jkupec@suse.cz>
Mon, 16 Jul 2007 15:41:49 +0000 (15:41 +0000)
src/zypper-callbacks.cc
src/zypper-callbacks.h
src/zypper-keyring-callbacks.h
src/zypper-misc.cc
src/zypper-misc.h

index 15c928e..9f3600b 100644 (file)
@@ -20,6 +20,8 @@ void display_progress (const string& s, int percent) {
   cout_v << flush;
 }
 
+// ----------------------------------------------------------------------------
+
 void display_tick (const string& s) {
   static AliveCursor cursor;
 
@@ -27,6 +29,8 @@ void display_tick (const string& s) {
   cout_v << flush;
 }
 
+// ----------------------------------------------------------------------------
+
 void display_done (const string& s) {
   static AliveCursor cursor;
 
@@ -34,10 +38,14 @@ void display_done (const string& s) {
   cout_v << flush;
 }
 
+// ----------------------------------------------------------------------------
+
 void display_done () {
   cout_v << endl;
 }
 
+// ----------------------------------------------------------------------------
+
 //template<typename Action>
 //Action ...
 int read_action_ari (int default_action) {
@@ -82,6 +90,36 @@ int read_action_ari (int default_action) {
   return default_action;
 }
 
+// ----------------------------------------------------------------------------
+
+// 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);
+}
+
+// ----------------------------------------------------------------------------
+
 string to_string (zypp::Resolvable::constPtr resolvable) {
   ostringstream ss;
   ss << *resolvable;
index 259b368..099c548 100644 (file)
@@ -48,5 +48,15 @@ void display_error (Error error, const std::string& reason) {
  *    is ignored.
  */
 int read_action_ari (int default_action = -1);
+
+/**
+ * Prompt for Yes/No answer from stdin.
+ * 
+ * \todo work with default
+ * \todo non-interactive mode
+ * \todo make this localized
+ */
+bool readBoolAnswer();
+
 std::string to_string (zypp::Resolvable::constPtr resolvable);
 #endif
index 342d9e7..69e4e54 100644 (file)
@@ -20,7 +20,7 @@
 #include <zypp/Digest.h>
 
 #include "AliveCursor.h"
-#include "zypper-misc.h"
+#include "zypper-callbacks.h"
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp {
@@ -37,7 +37,6 @@ namespace zypp {
         return readBoolAnswer();
       }
       
-#ifndef LIBZYPP_1xx
       virtual bool askUserToImportKey( const PublicKey &key )
       {
         if ( geteuid() != 0 )
@@ -46,36 +45,25 @@ namespace zypp {
         cout << CLEARLN << _("Import key ") << key.id() << _(" to trusted keyring?") << "  [y/n]: " << flush;
         return readBoolAnswer();
       } 
-#endif
 
-#ifdef LIBZYPP_1xx
-      virtual bool askUserToAcceptUnknownKey( const std::string &file, const std::string &id, const std::string &/*keyname*/, const std::string &/*fingerprint*/ )
-#else
       virtual bool askUserToAcceptUnknownKey( const std::string &file, const std::string &id )
-#endif
       {
         cout << CLEARLN << file << _(" is signed with an unknown key id: ") << id << ", " << _("continue?") << " [y/n]: " << flush;
         return readBoolAnswer();
       }
 
-#ifdef LIBZYPP_1xx
-      virtual bool askUserToTrustKey( const std::string &keyid, const std::string &keyname, const std::string &fingerprint) {
-#else
-      virtual bool askUserToTrustKey( const PublicKey &key ) {
+      virtual bool askUserToTrustKey( const PublicKey &key )
+      {
        const std::string& keyid = key.id(), keyname = key.name(),
          fingerprint = key.fingerprint();
-#endif
         cout  << CLEARLN << _("Do you want to trust key id ") << keyid << " " << keyname << _(" fingerprint:") << fingerprint << " ? [y/n]: "  << flush;
         return readBoolAnswer();
       }
 
-#ifdef LIBZYPP_1xx
-      virtual bool askUserToAcceptVerificationFailed( const std::string &file, const std::string &keyid, const std::string &keyname, const std::string &fingerprint ) {
-#else
-      virtual bool askUserToAcceptVerificationFailed( const std::string &file,const PublicKey &key ) {
+      virtual bool askUserToAcceptVerificationFailed( const std::string &file,const PublicKey &key )
+      {
        const std::string& keyid = key.id(), keyname = key.name(),
          fingerprint = key.fingerprint();
-#endif
         cout << file << _("Signature verification for ") << file
             << _(" with public key id ") << keyid << " " << keyname << _(" fingerprint:") << fingerprint << _(" failed, THIS IS RISKY!") << ". " << _("continue?") << " [y/n]: " << endl;
         return readBoolAnswer(); // TODO do this with format()
index d65bd9d..a71526f 100644 (file)
@@ -1,8 +1,6 @@
 #include <fstream>
 #include <sstream>
 #include <boost/format.hpp>
-#include "zypper.h"
-#include "zypper-misc.h"
 
 #include <zypp/Patch.h>
 #include <zypp/base/Algorithm.h>
 #include <zypp/RepoInfo.h>
 #include <zypp/repo/RepoException.h>
 
+#include "zypper.h"
+#include "zypper-misc.h"
+#include "zypper-callbacks.h"
+
 using namespace zypp::detail;
 
 using namespace std;
@@ -33,30 +35,6 @@ void cond_init_target () {
   }
 }
 
-// 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);
-}
-
 // converts a user-supplied kind to a zypp kind object
 // returns an empty one if not recognized
 ResObject::Kind string_to_kind (const string &skind)
index 7a9daae..9692ba5 100644 (file)
@@ -21,7 +21,6 @@
  */
 void cond_init_target();
 
-bool readBoolAnswer();
 zypp::ResObject::Kind string_to_kind (const std::string &skind);
 void mark_for_install( const zypp::ResObject::Kind &kind,
                       const std::string &name );