- allow to set SourceInfo bools as undeterminate too.
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Wed, 28 Jun 2006 09:37:26 +0000 (09:37 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Wed, 28 Jun 2006 09:37:26 +0000 (09:37 +0000)
- implement knownSources()
- test it in a test program

zypp/cache/KnownSourcesCache.cpp
zypp/parser/xmlstore/XMLSourceCacheParser.cc
zypp/source/SourceInfo.cc
zypp/source/SourceInfo.h
zypp/target/store/serialize.cc

index bf0c88a..9f51603 100644 (file)
@@ -67,7 +67,34 @@ KnownSourcesCache::~KnownSourcesCache()
 
 source::SourceInfoList KnownSourcesCache::knownSources() const
 {
-  return source::SourceInfoList();
+  source::SourceInfoList sources;
+  
+  try {
+    sqlite3_connection con(ZYPP_DB_FILE);
+
+    {
+      sqlite3_command cmd(con, "select * from sources;");
+      sqlite3_reader reader = cmd.executereader();
+
+      while(reader.read())
+      {
+        source::SourceInfo info;
+        info.setAlias(reader.getstring(1));
+        info.setUrl(reader.getstring(2));
+        info.setEnabled( (reader.getint(4) == 1 ) ? true : false );
+        info.setAutorefresh( (reader.getint(5) == 1 ) ? true : false );
+        info.setType(reader.getstring(6));
+        info.setCacheDir(reader.getstring(7));
+        info.setPath(reader.getstring(8));
+        sources.push_back(info);
+      }
+    }
+    con.close();
+  }
+  catch(exception &ex) {
+    ERR << "Exception Occured: " << ex.what() << endl;
+  }
+  return sources;
 }
 
 void KnownSourcesCache::storeSource( const source::SourceInfo &info )
@@ -81,12 +108,12 @@ void KnownSourcesCache::storeSource( const source::SourceInfo &info )
       sqlite3_command cmd(con, "insert into sources ( alias, url, description, enabled, autorefresh, type, cachedir, path) values ( ?, ?, ?, ? , ?, ?, ?, ?);");
       cmd.bind(1, info.alias());
       cmd.bind(2, info.url().asCompleteString());
-      // FIXME 
+      // FIXME no description
       cmd.bind(4, info.enabled() ? 1 : 0 );
       cmd.bind(5, info.autorefresh() ? 1 : 0 );
       cmd.bind(6, info.type());
-      cmd.bind(6, info.cacheDir().asString());
-      cmd.bind(7, info.path().asString());
+      cmd.bind(7, info.cacheDir().asString());
+      cmd.bind(8, info.path().asString());
       
       cmd.executenonquery();
     }
index fb20230..326bf42 100644 (file)
@@ -67,7 +67,7 @@ namespace xmlstore {
               else if ( (_helper.content(child) == "false") || (_helper.content(child) == "0") )
                 dataPtr->setEnabled(false);
               else
-                dataPtr->setEnabled(indeterminate);
+                dataPtr->setEnabled(boost::indeterminate);
             }
             else if (name == "auto-refresh")
             {
@@ -76,7 +76,7 @@ namespace xmlstore {
               if ( (_helper.content(child) == "false") || (_helper.content(child) == "0") )
                 dataPtr->setAutorefresh(false);
               else
-                dataPtr->setAutorefresh(indeterminate);
+                dataPtr->setAutorefresh(boost::indeterminate);
             }
             else if (name == "type")
             {
index 5074fc4..d3f2b8e 100644 (file)
 */
 
 #include <string>
+#include <iostream>
 #include "zypp/source/SourceInfo.h"
 
+using namespace boost;
+
 ///////////////////////////////////////////////////////////////////
 namespace zypp
 { /////////////////////////////////////////////////////////////////
 namespace source
 {
   
+  SourceInfo::SourceInfo() :
+      _enabled (indeterminate),
+  _autorefresh(indeterminate)
+  {
+      
+  }
+    
+  SourceInfo::SourceInfo( const Url & url, const Pathname & path, const std::string & alias, const Pathname & cache_dir, tribool autorefresh)
+  : _enabled (true),
+  _autorefresh(autorefresh),
+  _url(url),
+  _cache_dir(cache_dir),
+  _path(path),
+  _alias(alias)
+  {
+      
+  }
+    
+  SourceInfo & SourceInfo::setEnabled( boost::tribool enabled )
+  {
+    _enabled = enabled;
+    return *this;
+  }
+    
+  SourceInfo & SourceInfo::setAutorefresh( boost::tribool autorefresh )
+  {
+    _autorefresh = autorefresh;
+    return *this;
+  }
+    
+  SourceInfo & SourceInfo::setUrl( const Url &url )
+  {
+    _url = url;
+    return *this;
+  }
+    
+  SourceInfo & SourceInfo::setPath( const Pathname &p )
+  {
+    _path = p;
+    return *this;
+  }
+    
+  SourceInfo & SourceInfo::setAlias( const std::string &alias )
+  {
+    _alias = alias;
+    return *this;
+  }
+    
+  SourceInfo & SourceInfo::setType( const std::string &t )
+  {
+    _type = t;
+    return *this;
+  }
+    
+  SourceInfo & SourceInfo::setCacheDir( const Pathname &p )
+  {
+    _cache_dir = p;
+    return *this;
+  }
+     
+  tribool SourceInfo::enabled() const
+  { return _enabled; }
+        
+  tribool SourceInfo::autorefresh() const
+  { return _enabled; }    
+    
+  Pathname SourceInfo::cacheDir() const
+  { return _cache_dir; }
+    
+  Pathname SourceInfo::path() const
+  { return _path; }
+    
+  std::string SourceInfo::alias() const
+  { return _alias; }
+    
+  std::string SourceInfo::type() const
+  { return _type; }
+    
+  Url SourceInfo::url() const
+  { return _url; }
   
+  std::ostream & SourceInfo::dumpOn( std::ostream & str ) const
+  {
+    str << "--------------------------------------" << std::endl;
+    str << "- alias       : " << alias() << std::endl;
+    str << "- url         : " << url() << std::endl;
+    str << "- type        : " << type() << std::endl;
+    str << "- enabled     : " << enabled() << std::endl;
+    str << "- autorefresh : " << autorefresh() << std::endl;
+    str << "- path        : " << path() << std::endl;
+    str << "- cache_dir   : " << cacheDir() << std::endl;
+    return str;
+  }
   
 }
   /////////////////////////////////////////////////////////////////
index 942ab61..94fa5bc 100644 (file)
@@ -18,8 +18,6 @@
 #include "zypp/Pathname.h"
 #include "zypp/Url.h"
 
-using namespace boost;
-
 ///////////////////////////////////////////////////////////////////
 namespace zypp
 { /////////////////////////////////////////////////////////////////
@@ -30,91 +28,32 @@ namespace source
   {
     public:
       
-    SourceInfo() :
-        _enabled (indeterminate),
-        _autorefresh(indeterminate)
-    {
-      
-    }
-    
-    SourceInfo( const Url & url, const Pathname & path, const std::string & alias = "", const Pathname & cache_dir = "", tribool autorefresh = indeterminate)
-      : _enabled (true),
-    _autorefresh(autorefresh),
-    _url(url),
-    _cache_dir(cache_dir),
-    _path(path),
-    _alias(alias)
-    {
-      
-    }
-    
-    SourceInfo & setEnabled( bool enabled )
-    {
-      _enabled = enabled;
-      return *this;
-    }
-    
-    SourceInfo & setAutorefresh( bool autorefresh )
-    {
-      _autorefresh = autorefresh;
-      return *this;
-    }
-    
-    SourceInfo & setUrl( const Url &url )
-    {
-      _url = url;
-      return *this;
-    }
+    SourceInfo();
     
-    SourceInfo & setPath( const Pathname &p )
-    {
-      _path = p;
-      return *this;
-    }
+    SourceInfo( const Url & url, const Pathname & path, const std::string & alias = "", const Pathname & cache_dir = "", boost::tribool autorefresh = boost::indeterminate);
     
-    SourceInfo & setAlias( const std::string &alias )
-    {
-      _alias = alias;
-      return *this;
-    }
+    SourceInfo & setEnabled( boost::tribool enabled );
+    SourceInfo & setAutorefresh( boost::tribool autorefresh );
+    SourceInfo & setUrl( const Url &url );
+    SourceInfo & setPath( const Pathname &p );
+    SourceInfo & setAlias( const std::string &alias );
+    SourceInfo & setType( const std::string &t );
+    SourceInfo & setCacheDir( const Pathname &p );
+    boost::tribool enabled() const;
+    boost::tribool autorefresh() const;
+    Pathname cacheDir() const;
+    Pathname path() const;
+    std::string alias() const;
+    std::string type() const;
+    Url url() const;
     
-    SourceInfo & setType( const std::string &t )
-    {
-      _type = t;
-      return *this;
-    }
-    
-    SourceInfo & setCacheDir( const Pathname &p )
-    {
-      _cache_dir = p;
-      return *this;
-    }
-     
-    tribool enabled() const
-    { return _enabled; }
-        
-    tribool autorefresh() const
-    { return _enabled; }    
-    
-    Pathname cacheDir() const
-    { return _cache_dir; }
-    
-    Pathname path() const
-    { return _path; }
-    
-    std::string alias() const
-    { return _alias; }
-    
-    std::string type() const
-    { return _type; }
-    
-    Url url() const
-    { return _url; }
+    /** Overload to realize stream output. */
+    std::ostream & dumpOn( std::ostream & str ) const;
     
     private:
     
-    tribool _enabled;
-    tribool _autorefresh;
+    boost::tribool _enabled;
+    boost::tribool _autorefresh;
     std::string _type;
     Url _url;
     Pathname _cache_dir;
@@ -122,6 +61,10 @@ namespace source
     std::string _alias;
   };  
   
+  /** \relates SourceInfo Stream output */
+  inline std::ostream & operator<<( std::ostream & str, const SourceInfo & obj )
+  { return obj.dumpOn( str ); }
+  
   typedef std::list<SourceInfo> SourceInfoList;
 }
   /////////////////////////////////////////////////////////////////
index 3ebf376..d31ead5 100644 (file)
@@ -55,7 +55,7 @@ static std::string xml_tag_enclose( const std::string &text, const std::string &
   return result;
 }
 
-static std::ostream & operator<<( std::ostream & str, const tribool obj )
+static std::ostream & operator<<( std::ostream & str, const boost::tribool obj )
 {
   if (obj)
     return str << "true";