diff options
| author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 | 
|---|---|---|
| committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 | 
| commit | 114a878c64ce6f8223cfd22d76a20eb16d177e5e (patch) | |
| tree | acaf47eb0fa12142d3896416a69e74cbf5a72242 /vcs/cvsservice/cvsentry.cpp | |
| download | tdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.tar.gz tdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.zip | |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdevelop@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'vcs/cvsservice/cvsentry.cpp')
| -rw-r--r-- | vcs/cvsservice/cvsentry.cpp | 187 | 
1 files changed, 187 insertions, 0 deletions
| diff --git a/vcs/cvsservice/cvsentry.cpp b/vcs/cvsservice/cvsentry.cpp new file mode 100644 index 00000000..ab8b2cc0 --- /dev/null +++ b/vcs/cvsservice/cvsentry.cpp @@ -0,0 +1,187 @@ +/*************************************************************************** + *   Copyright (C) 2003 by Mario Scalas                                    * + *   mario.scalas@libero.it                                                * + *                                                                         * + *   This program is free software; you can redistribute it and/or modify  * + *   it under the terms of the GNU General Public License as published by  * + *   the Free Software Foundation; either version 2 of the License, or     * + *   (at your option) any later version.                                   * + *                                                                         * + ***************************************************************************/ + +#include <qfile.h> +#include <qtextstream.h> + +#include "cvsentry.h" +#include "cvsdir.h" + +/////////////////////////////////////////////////////////////////////////////// +// Static +/////////////////////////////////////////////////////////////////////////////// + +const QString CVSEntry::invalidMarker = "<Invalid entry>"; +const QString CVSEntry::directoryMarker = "D"; +const QString CVSEntry::fileMarker = ""; +const QString CVSEntry::entrySeparator = "/"; + +/////////////////////////////////////////////////////////////////////////////// +// class CVSEntry +/////////////////////////////////////////////////////////////////////////////// + +CVSEntry::CVSEntry() +{ +    clean(); +} + +/////////////////////////////////////////////////////////////////////////////// + +CVSEntry::CVSEntry( const QString &aLine, const CVSDir& dir ) +{ +    parse( aLine, dir ); +} + +/////////////////////////////////////////////////////////////////////////////// + +void CVSEntry::clean() +{ +    m_type = invalidEntry; +    m_state = Unknown; +} + +/////////////////////////////////////////////////////////////////////////////// + +CVSEntry::EntryType CVSEntry::type() const +{ +    return m_type; +} + +/////////////////////////////////////////////////////////////////////////////// + +void CVSEntry::parse( const QString &aLine, const CVSDir& dir ) +{ +    clean(); + +    m_fields = QStringList::split( "/", aLine ); + +    if (aLine.startsWith( entrySeparator )) // Is a file? +    { +        m_type = fileEntry; // Is a file +    } +    else if (aLine.startsWith( directoryMarker )) // Must be a directory then +    { +        m_type = directoryEntry; // Is a directory +        m_fields.pop_front(); // QStringList::split() fills and empty item in head +	return; +    } +    else // What the hell is this? >:-) +    { +        m_type = invalidEntry; +	return; +    } + +    //if we're a file, keep going +    QDateTime entryFileDate(QDateTime::fromString(timeStamp())); +    QDateTime realFileDate; +    QFileInfo info(dir, m_fields[0]); +    realFileDate = info.lastModified(); + +    m_state = UpToDate; + +    if ( revision() == "0" ) +        m_state = Added; +    else if ( revision().length() > 3 && revision()[0] == '-' ) +        m_state = Removed; +    else if ( timeStamp().find('+') >= 0 ) +        m_state = Conflict; +    else +    { +        QDateTime date( QDateTime::fromString( timeStamp() ) ); +        QDateTime fileDateUTC; +        fileDateUTC.setTime_t( QFileInfo(dir, fileName()).lastModified().toTime_t(), Qt::UTC ); +        if ( date != fileDateUTC ) +            m_state = Modified; +    } +} + +/////////////////////////////////////////////////////////////////////////////// + +QString CVSEntry::fileName() const +{ +    if (type() != invalidEntry && m_fields.count() >= 1) +        return m_fields[0]; +    else +        return QString::null; +} + +/////////////////////////////////////////////////////////////////////////////// + +QString CVSEntry::revision() const +{ +    if (type() != invalidEntry && m_fields.count() >= 2) +        return m_fields[1]; +    else +        return QString::null; +} + +/////////////////////////////////////////////////////////////////////////////// + +QString CVSEntry::timeStamp() const +{ +    if (type() != invalidEntry && m_fields.count() >= 3) +        return m_fields[2]; +    else +        return QString::null; +} + +/////////////////////////////////////////////////////////////////////////////// + +QString CVSEntry::options() const +{ +    if (type() != invalidEntry && m_fields.count() >= 4) +        return m_fields[3]; +    else +        return QString::null; +} + +/////////////////////////////////////////////////////////////////////////////// + +QString CVSEntry::tag() const +{ +    if (type() != invalidEntry && m_fields.count() >= 5) +        return m_fields[4]; +    else +        return QString::null; +} + +/////////////////////////////////////////////////////////////////////////////// + +VCSFileInfo CVSEntry::toVCSFileInfo() const +{ +    VCSFileInfo::FileState fileState = VCSFileInfo::Unknown; +    if (isDirectory()) +        fileState = VCSFileInfo::Directory; + +    switch (m_state) +    { +        case Added: +            fileState = VCSFileInfo::Added; +            break; +        case Conflict: +            fileState = VCSFileInfo::Conflict; +            break; +        case Modified: +        case Removed: +            fileState = VCSFileInfo::Modified; +            break; +        case UpToDate: +            fileState = VCSFileInfo::Uptodate; +            break; +        default: +            fileState = VCSFileInfo::Unknown; +            break; +    } + +    return VCSFileInfo( fileName(), revision(), revision(), fileState ); +} + +//kate: space-indent on; indent-width 4; replace-tabs on; | 
