Remove doclist API specific fields from Entry class: kind, create_link, edit_link and alt_self

pull/40/head
Vitaliy Filippov 2015-05-16 12:35:41 +03:00
parent 770baca3fc
commit 2d8da5cab3
5 changed files with 37 additions and 46 deletions

View File

@ -108,7 +108,7 @@ void Drive::SyncFolders( )
for ( Feed::iterator i = feed.begin() ; i != feed.end() ; ++i )
{
Entry e( *i ) ;
if ( e.Kind() == "folder" )
if ( e.IsDir() )
{
if ( e.ParentHrefs().size() != 1 )
Log( "folder \"%1%\" has multiple parents, ignored", e.Title(), log::verbose ) ;

View File

@ -34,10 +34,9 @@ namespace gr { namespace v1 {
/// construct an entry for the root folder
Entry::Entry( ) :
m_title ( "." ),
m_kind ( "folder" ),
m_is_dir ( true ),
m_resource_id ( "folder:root" ),
m_self_href ( root_href ),
m_create_link ( root_create ),
m_change_stamp ( -1 ),
m_is_removed ( false )
{
@ -58,18 +57,22 @@ void Entry::Update( const xml::Node& n )
m_filename = n["docs:suggestedFilename"] ;
m_content_src = n["content"]["@src"] ;
m_self_href = n["link"].Find( "@rel", "self" )["@href"] ;
m_alt_self = n["link"].Find( "@rel", "http://schemas.google.com/docs/2007#alt-self" )["@href"] ;
m_mtime = DateTime( n["updated"] ) ;
m_resource_id = n["gd:resourceId"] ;
m_md5 = n["docs:md5Checksum"] ;
m_kind = n["category"].Find( "@scheme", "http://schemas.google.com/g/2005#kind" )["@label"] ;
m_edit_link = n["link"].Find( "@rel", "http://schemas.google.com/g/2005#resumable-edit-media")["@href"] ;
m_create_link = n["link"].Find( "@rel", "http://schemas.google.com/g/2005#resumable-create-media")["@href"] ;
m_is_dir = n["category"].Find( "@scheme", "http://schemas.google.com/g/2005#kind" )["@label"] == "folder" ;
m_is_editable = !n["link"].Find( "@rel", m_is_dir
? "http://schemas.google.com/g/2005#resumable-create-media" : "http://schemas.google.com/g/2005#resumable-edit-media" )
["@href"].empty() ;
// changestamp only appear in change feed entries
xml::NodeSet cs = n["docs:changestamp"]["@value"] ;
m_change_stamp = cs.empty() ? -1 : std::atoi( cs.front().Value().c_str() ) ;
if ( m_change_stamp != -1 )
{
m_self_href = n["link"].Find( "@rel", "http://schemas.google.com/docs/2007#alt-self" )["@href"] ;
}
m_parent_hrefs.clear( ) ;
xml::NodeSet parents = n["link"].Find( "@rel", "http://schemas.google.com/docs/2007#parent" ) ;
@ -97,9 +100,9 @@ std::string Entry::Filename() const
return m_filename ;
}
std::string Entry::Kind() const
bool Entry::IsDir() const
{
return m_kind ;
return m_is_dir ;
}
std::string Entry::MD5() const
@ -117,11 +120,6 @@ std::string Entry::SelfHref() const
return m_self_href ;
}
std::string Entry::AltSelf() const
{
return m_alt_self ;
}
std::string Entry::ParentHref() const
{
return m_parent_hrefs.empty() ? "" : m_parent_hrefs.front() ;
@ -142,14 +140,9 @@ std::string Entry::ContentSrc() const
return m_content_src ;
}
std::string Entry::EditLink() const
bool Entry::IsEditable() const
{
return m_edit_link ;
}
std::string Entry::CreateLink() const
{
return m_create_link ;
return m_is_editable ;
}
long Entry::ChangeStamp() const
@ -169,7 +162,7 @@ bool Entry::IsRemoved() const
std::string Entry::Name() const
{
return (m_kind == "file" || m_kind == "pdf") ? m_filename : m_title ;
return !m_filename.empty() ? m_filename : m_title ;
}
} } // end of namespace gr::v1

View File

@ -49,7 +49,7 @@ public :
std::string Title() const ;
std::string Filename() const ;
std::string Kind() const ;
bool IsDir() const ;
std::string MD5() const ;
DateTime MTime() const ;
@ -59,11 +59,9 @@ public :
std::string ETag() const ;
std::string SelfHref() const ;
std::string AltSelf() const ;
std::string ParentHref() const ;
std::string ContentSrc() const ;
std::string EditLink() const ;
std::string CreateLink() const ;
bool IsEditable() const ;
long ChangeStamp() const ;
bool IsChange() const ;
@ -76,21 +74,20 @@ public :
private :
std::string m_title ;
std::string m_filename ;
std::string m_kind ;
bool m_is_dir ;
std::string m_md5 ;
std::string m_etag ;
std::string m_resource_id ;
std::vector<std::string> m_parent_hrefs ;
std::string m_self_href ;
std::string m_alt_self ;
std::string m_content_src ;
std::string m_edit_link ;
std::string m_create_link ;
bool m_is_editable ;
long m_change_stamp ;
DateTime m_mtime ;
bool m_is_removed ;
} ;

View File

@ -95,7 +95,7 @@ void Resource::FromRemoteFolder( const Entry& remote, const DateTime& last_sync
{
fs::path path = Path() ;
if ( remote.CreateLink().empty() )
if ( !remote.IsEditable() )
Log( "folder %1% is read-only", path, log::verbose ) ;
// already sync
@ -143,7 +143,7 @@ void Resource::FromRemoteFolder( const Entry& remote, const DateTime& last_sync
void Resource::FromRemote( const Entry& remote, const DateTime& last_sync )
{
// sync folder
if ( remote.Kind() == "folder" && IsFolder() )
if ( remote.IsDir() && IsFolder() )
FromRemoteFolder( remote, last_sync ) ;
else
FromRemoteFile( remote, last_sync ) ;
@ -166,8 +166,8 @@ void Resource::AssignIDs( const Entry& remote )
{
m_id = remote.ResourceID() ;
m_href = remote.SelfHref() ;
m_edit = remote.EditLink() ;
m_create = remote.CreateLink() ;
m_edit = remote.IsEditable() ? feed_base + "/" + remote.ResourceID() : "";
m_create = remote.IsEditable() && remote.IsDir() ? root_create + (remote.ResourceID() == "folder:root" ? "" : "/" + remote.ResourceID() + "/contents") : "";
m_content = remote.ContentSrc() ;
m_etag = remote.ETag() ;
}

View File

@ -112,24 +112,25 @@ void State::FromLocal( const fs::path& p, Resource* folder )
void State::FromRemote( const Entry& e )
{
std::string fn = e.Filename() ;
std::string fn = e.Filename() ;
std::string k = e.IsDir() ? "folder" : "file";
if ( IsIgnore( e.Name() ) )
Log( "%1% %2% is ignored by grive", e.Kind(), e.Name(), log::verbose ) ;
Log( "%1% %2% is ignored by grive", k, e.Name(), log::verbose ) ;
// check if it is ignored
else if ( e.ParentHref() == m_res.Root()->SelfHref() && m_dir != "" && e.Name() != m_dir )
Log( "%1% %2% is ignored", e.Kind(), e.Name(), log::verbose );
Log( "%1% %2% is ignored", k, e.Name(), log::verbose );
// common checkings
else if ( e.Kind() != "folder" && (fn.empty() || e.ContentSrc().empty()) )
Log( "%1% \"%2%\" is a google document, ignored", e.Kind(), e.Name(), log::verbose ) ;
else if ( !e.IsDir() && (fn.empty() || e.ContentSrc().empty()) )
Log( "%1% \"%2%\" is a google document, ignored", k, e.Name(), log::verbose ) ;
else if ( fn.find('/') != fn.npos )
Log( "%1% \"%2%\" contains a slash in its name, ignored", e.Kind(), e.Name(), log::verbose ) ;
Log( "%1% \"%2%\" contains a slash in its name, ignored", k, e.Name(), log::verbose ) ;
else if ( !e.IsChange() && e.ParentHrefs().size() != 1 )
Log( "%1% \"%2%\" has multiple parents, ignored", e.Kind(), e.Name(), log::verbose ) ;
Log( "%1% \"%2%\" has multiple parents, ignored", k, e.Name(), log::verbose ) ;
else if ( e.IsChange() )
FromChange( e ) ;
@ -176,7 +177,7 @@ void State::FromChange( const Entry& e )
// entries in the change feed is always treated as newer in remote,
// so we override the last sync time to 0
if ( Resource *res = m_res.FindByHref( e.AltSelf() ) )
if ( Resource *res = m_res.FindByHref( e.SelfHref() ) )
m_res.Update( res, e, DateTime() ) ;
}
@ -205,10 +206,10 @@ bool State::Update( const Entry& e )
// folder entry exist in google drive, but not local. we should create
// the directory
else if ( e.Kind() == "folder" || !e.Filename().empty() )
else if ( e.IsDir() || !e.Filename().empty() )
{
// first create a dummy resource and update it later
child = new Resource( name, e.Kind() ) ;
child = new Resource( name, e.IsDir() ? "folder" : "file" ) ;
parent->AddChild( child ) ;
m_res.Insert( child ) ;