# HG changeset patch # User Chris Cannam # Date 1290605010 0 # Node ID 06f4fffd5287f765e752a722e409fc9e7f2dce3e # Parent 879af4608c5eac77d7636edaf8c6de25e884f2ad * Rename StatParser to FileStates; start thinking about selections diff -r 879af4608c5e -r 06f4fffd5287 easyhg.pro --- a/easyhg.pro Tue Nov 23 21:04:02 2010 +0000 +++ b/easyhg.pro Wed Nov 24 13:23:30 2010 +0000 @@ -31,7 +31,7 @@ repositorydialog.h \ multichoicedialog.h \ selectablelabel.h \ - statparser.h \ + filestates.h \ filestatuswidget.h SOURCES = main.cpp \ mainwindow.cpp \ @@ -55,7 +55,7 @@ repositorydialog.cpp \ multichoicedialog.cpp \ selectablelabel.cpp \ - statparser.cpp \ + filestates.cpp \ filestatuswidget.cpp macx-* { diff -r 879af4608c5e -r 06f4fffd5287 filestates.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/filestates.cpp Wed Nov 24 13:23:30 2010 +0000 @@ -0,0 +1,64 @@ +#include "filestates.h" + +#include "debug.h" + +#include + +FileStates::FileStates(QString text) +{ + text.replace("\r\n", "\n"); + + QMap buckets; + buckets['M'] = &modified; + buckets['A'] = &added; + buckets['R'] = &removed; + buckets['!'] = &missing; + buckets['?'] = &unknown; + + QStringList lines = text.split("\n", QString::SkipEmptyParts); + foreach (QString line, lines) { + if (line.length() < 3 || line[1] != ' ') { + continue; + } + QChar tag = line[0]; + QString file = line.right(line.length() - 2); + if (buckets.contains(tag)) { + buckets[tag]->push_back(file); + } + } + + DEBUG << "FileStates: " << modified.size() << " modified, " << added.size() + << " added, " << removed.size() << " removed, " << missing.size() + << " missing, " << unknown.size() << " unknown" << endl; +} + +QStringList FileStates::getFilesInState(State s) +{ + switch (s) { + + case Modified: return modified; + case Added: return added; + case Unknown: return unknown; + case Removed: return removed; + case Missing: return missing; + + case UpToDate: // not supported yet + default: + return QStringList(); + } +} + +FileStates::State FileStates::getStateOfFile(QString file) +{ + // slow, but let's worry about that if it becomes a problem + for (int is = int(FirstState); is <= int(LastState); ++is) { + QStringList fl = getFilesInState(State(is)); + foreach (QString f, fl) if (f == file) return State(is); + } + DEBUG << "FileStates: WARNING: getStateOfFile: file " + << file << " is unknown to us: returning Unknown state, " + << "but unknown to us is not supposed to be the same " + << "thing as unknown state..." + << endl; + return Unknown; +} diff -r 879af4608c5e -r 06f4fffd5287 filestates.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/filestates.h Wed Nov 24 13:23:30 2010 +0000 @@ -0,0 +1,52 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + EasyMercurial + + Based on HgExplorer by Jari Korhonen + Copyright (c) 2010 Jari Korhonen + Copyright (c) 2010 Chris Cannam + Copyright (c) 2010 Queen Mary, University of London + + 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. See the file + COPYING included with this distribution for more information. +*/ + +#ifndef FILESTATES_H +#define FILESTATES_H + +#include + +class FileStates +{ +public: + FileStates() { } + FileStates(QString text); + + enum State { + + UpToDate, + Modified, + Added, + Unknown, + Removed, + Missing, + + FirstState = UpToDate, + LastState = Missing + }; + + QStringList modified; + QStringList added; + QStringList unknown; + QStringList removed; + QStringList missing; + + QStringList getFilesInState(State); + State getStateOfFile(QString file); +}; + +#endif // FILESTATES_H diff -r 879af4608c5e -r 06f4fffd5287 filestatuswidget.cpp --- a/filestatuswidget.cpp Tue Nov 23 21:04:02 2010 +0000 +++ b/filestatuswidget.cpp Wed Nov 24 13:23:30 2010 +0000 @@ -91,16 +91,16 @@ } void -FileStatusWidget::setStatParser(StatParser p) +FileStatusWidget::setFileStates(FileStates p) { - m_statParser = p; + m_fileStates = p; updateWidgets(); } void FileStatusWidget::updateWidgets() { - StatParser &sp = m_statParser; + FileStates &sp = m_fileStates; QMap listmap; listmap[&sp.modified] = m_modifiedList; listmap[&sp.added] = m_addedList; diff -r 879af4608c5e -r 06f4fffd5287 filestatuswidget.h --- a/filestatuswidget.h Tue Nov 23 21:04:02 2010 +0000 +++ b/filestatuswidget.h Wed Nov 24 13:23:30 2010 +0000 @@ -18,7 +18,7 @@ #ifndef FILESTATUSWIDGET_H #define FILESTATUSWIDGET_H -#include "statparser.h" +#include "filestates.h" #include @@ -38,13 +38,13 @@ QString remoteURL() const { return m_remoteURL; } void setRemoteURL(QString u); - StatParser statParser() const { return m_statParser; } - void setStatParser(StatParser sp); + FileStates fileStates() const { return m_fileStates; } + void setFileStates(FileStates sp); bool haveChangesToCommit() const { - return !m_statParser.added.empty() || - !m_statParser.removed.empty() || - !m_statParser.modified.empty(); + return !m_fileStates.added.empty() || + !m_fileStates.removed.empty() || + !m_fileStates.modified.empty(); } private: @@ -54,7 +54,7 @@ QString m_remoteURL; QLabel *m_remoteURLLabel; - StatParser m_statParser; + FileStates m_fileStates; QListWidget *m_modifiedList; QListWidget *m_addedList; diff -r 879af4608c5e -r 06f4fffd5287 hgexpwidget.cpp --- a/hgexpwidget.cpp Tue Nov 23 21:04:02 2010 +0000 +++ b/hgexpwidget.cpp Wed Nov 24 13:23:30 2010 +0000 @@ -64,8 +64,8 @@ void HgExpWidget::updateWorkFolderFileList(QString fileList) { - statParser = StatParser(fileList); - fileStatusWidget->setStatParser(statParser); + fileStates = FileStates(fileList); + fileStatusWidget->setFileStates(fileStates); } void HgExpWidget::updateLocalRepoHgLogList(QString hgLogList) diff -r 879af4608c5e -r 06f4fffd5287 hgexpwidget.h --- a/hgexpwidget.h Tue Nov 23 21:04:02 2010 +0000 +++ b/hgexpwidget.h Wed Nov 24 13:23:30 2010 +0000 @@ -20,7 +20,7 @@ #include "changeset.h" #include "common.h" -#include "statparser.h" +#include "filestates.h" #include #include @@ -47,10 +47,12 @@ void updateLocalRepoHgLogList(QString hgLogList); void setWorkFolderAndRepoNames(QString workFolderPath, QString remoteRepoPath); - //!!! StatParser really should be renamed to express "status state" rather than activity - StatParser getStatParser() { return statParser; } + FileStates getFileStates() { return fileStates; } bool canCommit() const; + bool canAdd() const; + bool canRemove() const; + bool canDoFolderDiff() const; private: FileStatusWidget *fileStatusWidget; @@ -60,7 +62,7 @@ QWidget *historyGraphPanner; QWidget *historyPageWidget; - StatParser statParser; + FileStates fileStates; Changesets parseChangeSets(QString changeSetsStr); }; diff -r 879af4608c5e -r 06f4fffd5287 statparser.cpp --- a/statparser.cpp Tue Nov 23 21:04:02 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ -#include "statparser.h" - -#include "debug.h" - -#include - -StatParser::StatParser(QString text) -{ - text.replace("\r\n", "\n"); - - QMap buckets; - buckets['M'] = &modified; - buckets['A'] = &added; - buckets['R'] = &removed; - buckets['!'] = &missing; - buckets['?'] = &unknown; - - QStringList lines = text.split("\n", QString::SkipEmptyParts); - foreach (QString line, lines) { - if (line.length() < 3 || line[1] != ' ') { - continue; - } - QChar tag = line[0]; - QString file = line.right(line.length() - 2); - if (buckets.contains(tag)) { - buckets[tag]->push_back(file); - } - } - - DEBUG << "StatParser: " << modified.size() << " modified, " << added.size() - << " added, " << removed.size() << " removed, " << missing.size() - << " missing, " << unknown.size() << " unknown" << endl; -} diff -r 879af4608c5e -r 06f4fffd5287 statparser.h --- a/statparser.h Tue Nov 23 21:04:02 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ - -/* - EasyMercurial - - Based on HgExplorer by Jari Korhonen - Copyright (c) 2010 Jari Korhonen - Copyright (c) 2010 Chris Cannam - Copyright (c) 2010 Queen Mary, University of London - - 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. See the file - COPYING included with this distribution for more information. -*/ - -#ifndef STATPARSER_H -#define STATPARSER_H - -#include - -class StatParser -{ -public: - StatParser() { } - StatParser(QString text); - - QStringList modified; - QStringList added; - QStringList unknown; - QStringList removed; - QStringList missing; -}; - -#endif // STATPARSER_H