# # # patch "src/model/GetFile.cpp" # from [54bfdc61b73d50418793fca0b86bc05f434ee311] # to [48e5c3805ba8a423eb292346a7064eb3e0f86422] # # patch "src/model/GetFile.h" # from [341b069c5778068d50bbf01cd34557a04b639db3] # to [10f469a2c421e93d9ba10d3235b76321dcc08910] # ============================================================ --- src/model/GetFile.cpp 54bfdc61b73d50418793fca0b86bc05f434ee311 +++ src/model/GetFile.cpp 48e5c3805ba8a423eb292346a7064eb3e0f86422 @@ -19,21 +19,18 @@ ***************************************************************************/ #include "GetFile.h" -#include "Guitone.h" +#include "MonotoneUtil.h" + #include #include -GetFile::GetFile(QObject *parent) : QAbstractItemModel(parent) -{ - mtnDelegate = new MonotoneDelegate(this); -} +GetFile::GetFile(QObject * parent, const QString & db) + : QAbstractItemModel(parent), AutomateCommand(db) +{} -GetFile::~GetFile() -{ - delete mtnDelegate; -} +GetFile::~GetFile() {} -bool GetFile::readFileByName(const QString & fileName, const QString & rev) +void GetFile::readFileByName(const QString & fileName, const QString & rev) { QStringList cmd; cmd << "get_file_of" << fileName; @@ -41,43 +38,55 @@ bool GetFile::readFileByName(const QStri QStringList opts; if (rev.isEmpty()) { - opts << "r" << MonotoneDelegate::getBaseWorkspaceRevision(this); + opts << "r" << MonotoneUtil::getBaseWorkspaceRevision(getDbPath()); } else { opts << "r" << rev; } - return readFile(cmd, opts); + readFile(cmd, opts); } -bool GetFile::readFileById(const QString & fileID) +void GetFile::readFileById(const QString & fileID) { QStringList cmd; cmd << "get_file" << fileID; - return readFile(cmd, QStringList()); + readFile(cmd, QStringList()); } -bool GetFile::readFile(QStringList cmd, QStringList opts) +void GetFile::readFile(QStringList cmd, QStringList opts) { // reset attached views reset(); - - return mtnDelegate->triggerCommand(cmd, opts); + MonotoneTask task(cmd, opts); + AutomateCommand::enqueueTask(task); } -void GetFile::parseOutput() +void GetFile::processTaskResult(const MonotoneTask & task) { + if (task.getReturnCode() != 0) + { + C(QString("Command returned with a non-zero return code (%1)") + .arg(task.getOutputUtf8())); + return; + } + + // FIXME: if the file contents is misinterpreted as utf-8, we have a + // problem here. The only thing we could do here is to let the user + // select the charset of the file and re-read it afterwards + QString output = task.getOutputUtf8(); + QRegExp rx("\\0x00"); - if (rx.indexIn(AutomateCommand::data) != -1) + if (rx.indexIn(output) != -1) { // FIXME: signal this anywhere... W("File is binary"); return; } - QStringList lines(AutomateCommand::data.split(QRegExp("\\n|\\r\\n"))); + QStringList lines(output.split(QRegExp("\\n|\\r\\n"))); // skip the last line since this contains a newline from automate for (int i=0, s=lines.size() - 1; i @@ -36,39 +33,39 @@ struct ContentLine { ContentLine(QString c, Marker m) : content(c), marker(m) {} }; -typedef QVector Content; +typedef QVector Content; class GetFile : public QAbstractItemModel, public AutomateCommand { Q_OBJECT public: - GetFile(QObject*); + GetFile(QObject *, const QString &); virtual ~GetFile(); // needed Qt Model methods - QVariant data(const QModelIndex&, int) const; - Qt::ItemFlags flags(const QModelIndex&) const; + QVariant data(const QModelIndex &, int) const; + Qt::ItemFlags flags(const QModelIndex &) const; QVariant headerData(int, Qt::Orientation, int) const; - QModelIndex index(int, int, const QModelIndex&) const; - QModelIndex parent(const QModelIndex&) const; - int rowCount(const QModelIndex&) const; - int columnCount(const QModelIndex&) const; + QModelIndex index(int, int, const QModelIndex &) const; + QModelIndex parent(const QModelIndex &) const; + int rowCount(const QModelIndex &) const; + int columnCount(const QModelIndex &) const; QModelIndex getNextGroup(const QModelIndex &, bool recurse = false); QModelIndex getPrevGroup(const QModelIndex &, bool recurse = false); public slots: - bool readFileById(const QString &); - bool readFileByName(const QString &, const QString & rev = QString()); + void readFileById(const QString &); + void readFileByName(const QString &, const QString & rev = QString()); void applyDiff(Diff * diff); signals: void fileRead(); private: - bool readFile(QStringList, QStringList); - void parseOutput(); + void readFile(QStringList, QStringList); + void processTaskResult(const MonotoneTask &); Content fileContents; - MonotoneDelegate * mtnDelegate; }; #endif +