# # # add_file "guitone/src/model/GetFile.cpp" # content [c92f6cf00400806ebfedb2045d83ad8b502ea72e] # # add_file "guitone/src/model/GetFile.h" # content [f5b57cf148d9ca611caabcf3f57a77a650e74916] # # patch "guitone/guitone.pro" # from [c39c04b1068a4e5016cbd856f6969e2dadbe7e52] # to [49a24c7330525835a70b169a086f4ea9ee5e3f6d] # # patch "guitone/src/model/AutomateCommand.h" # from [64acc51ae628a094660e8a49916ee11352451187] # to [d2da7fedc8d1805b46dabc0892ac3fd44570d7bd] # ============================================================ --- guitone/src/model/GetFile.cpp c92f6cf00400806ebfedb2045d83ad8b502ea72e +++ guitone/src/model/GetFile.cpp c92f6cf00400806ebfedb2045d83ad8b502ea72e @@ -0,0 +1,127 @@ +/*************************************************************************** + * Copyright (C) 2006 by Thomas Keller * + * address@hidden * + * * + * 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. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "GetFile.h" +#include "../monotone/Monotone.h" + +GetFile::GetFile(QObject *parent) + : AutomateCommand(parent) +{ +} + +GetFile::~GetFile() {} + +bool GetFile::readFileByName(QString fileName, QString revision) +{ + QStringList cmd; + cmd << "get_file_of" << fileName; + + QStringList opts; + if (revision.length() > 0) + { + opts << "r" << revision; + } + + return readFile(cmd, opts); +} + +bool GetFile::readFileById(QString fileID) +{ + QStringList cmd; + cmd << "get_file" << fileID; + + return readFile(cmd, QStringList()); +} + +bool GetFile::readFile(QStringList cmd, QStringList opts) +{ + // reset attached views + reset(); + + Monotone *mtn = Monotone::singleton(); + + return mtn->triggerCommand(this, cmd, opts); +} + +void GetFile::parseOutput(AutomateCommand *caller) +{ + // if not we are the caller, omit the parsing + if (caller != this) return; + + QRegExp rx("\\0x00"); + if (rx.indexIn(AutomateCommand::data) != -1) + { + emit parseError(tr("File is binary.")); + return; + } + + fileContents = AutomateCommand::data.split("/[\\r\\n]+/"); + + emit fileRead(); +} + +int GetFile::columnCount(const QModelIndex &parent) const +{ + return 1; +} + +QVariant GetFile::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + { + return QVariant(); + } + + if (role != Qt::DisplayRole) + { + return QVariant(); + } + + int row = index.row(); + if (row >= fileContents.size()) return QVariant(); + + return QVariant(fileContents.at(row)); +} + +Qt::ItemFlags GetFile::flags(const QModelIndex &index) const +{ + return Qt::ItemIsEnabled; +} + +QVariant GetFile::headerData(int section, Qt::Orientation orientation, int role) const +{ + return QVariant(); +} + +int GetFile::rowCount(const QModelIndex& parent) const +{ + return fileContents.size(); +} + +QModelIndex GetFile::index(int row, int column, const QModelIndex& parent) const +{ + return hasIndex(row, column, parent) ? createIndex(row, column, 0) : QModelIndex(); +} + +QModelIndex GetFile::parent(const QModelIndex& index) const +{ + return QModelIndex(); +} + ============================================================ --- guitone/src/model/GetFile.h f5b57cf148d9ca611caabcf3f57a77a650e74916 +++ guitone/src/model/GetFile.h f5b57cf148d9ca611caabcf3f57a77a650e74916 @@ -0,0 +1,57 @@ +/*************************************************************************** + * Copyright (C) 2006 by Thomas Keller * + * address@hidden * + * * + * 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. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +// TODO: enable editing of items as well as dropping/adding them + +#ifndef GET_FILE_H +#define GET_FILE_H + +#include "AutomateCommand.h" + +class GetFile : public AutomateCommand +{ + Q_OBJECT +public: + GetFile(QObject*); + virtual ~GetFile(); + + // needed Qt Model methods + 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; + +public slots: + bool readFileById(QString); + bool readFileByName(QString, QString); + +signals: + void fileRead(); + +private: + bool readFile(QStringList, QStringList); + void parseOutput(AutomateCommand*); + QStringList fileContents; +}; + +#endif ============================================================ --- guitone/guitone.pro c39c04b1068a4e5016cbd856f6969e2dadbe7e52 +++ guitone/guitone.pro 49a24c7330525835a70b169a086f4ea9ee5e3f6d @@ -23,6 +23,7 @@ HEADERS += src/view/Guitone.h \ src/model/Select.h \ src/model/Certs.h \ src/model/Graph.h \ + src/model/GetFile.h \ src/util/IconProvider.h \ src/util/StanzaParser.h \ src/util/Settings.h \ @@ -45,6 +46,7 @@ SOURCES += src/view/Guitone.cpp \ src/model/Select.cpp \ src/model/Certs.cpp \ src/model/Graph.cpp \ + src/model/GetFile.cpp \ src/util/IconProvider.cpp \ src/util/StanzaParser.cpp \ src/util/Settings.cpp \ ============================================================ --- guitone/src/model/AutomateCommand.h 64acc51ae628a094660e8a49916ee11352451187 +++ guitone/src/model/AutomateCommand.h d2da7fedc8d1805b46dabc0892ac3fd44570d7bd @@ -37,7 +37,10 @@ public: inline void setData(QString output) { data = output; }; virtual void clearData(); virtual bool handleError(int); - + +signals: + void parseError(QString); + protected: // its not allowed to create objects of this type directly AutomateCommand(QObject*);