Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/lintest/fb2edit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKandrashin Denis <mail@lintest.ru>2012-11-06 10:50:13 +0400
committerKandrashin Denis <mail@lintest.ru>2012-11-06 10:50:13 +0400
commite81199775564f0b93aec3058f2bf8ebb3758644e (patch)
tree5649d23f572cbc62ced9ff98ea7dffc1a078cb0d
parent95fd352126ff3c22c41f54d097a8d522009c1431 (diff)
Rename class: FbTemporaryList => FbStore
-rw-r--r--source/fb2save.cpp2
-rw-r--r--source/fb2temp.cpp48
-rw-r--r--source/fb2temp.hpp27
-rw-r--r--source/fb2text.hpp2
4 files changed, 42 insertions, 37 deletions
diff --git a/source/fb2save.cpp b/source/fb2save.cpp
index eab70c7..404c28e 100644
--- a/source/fb2save.cpp
+++ b/source/fb2save.cpp
@@ -241,7 +241,7 @@ void FbSaveWriter::writeFiles()
while (it.hasNext()) {
QString name = it.next();
if (name.isEmpty()) continue;
- FbTemporaryFile * file = m_view.files()->get(name);
+ FbBinary * file = m_view.files()->get(name);
if (!file) continue;
writeStartElement("binary", 2);
writeAttribute("id", name);
diff --git a/source/fb2temp.cpp b/source/fb2temp.cpp
index d0b4d4e..62f2ce7 100644
--- a/source/fb2temp.cpp
+++ b/source/fb2temp.cpp
@@ -14,17 +14,17 @@
#include "fb2text.hpp"
//---------------------------------------------------------------------------
-// FbTemporaryFile
+// FbBinary
//---------------------------------------------------------------------------
-FbTemporaryFile::FbTemporaryFile(const QString &name)
+FbBinary::FbBinary(const QString &name)
: QTemporaryFile()
, m_name(name)
, m_size(0)
{
}
-qint64 FbTemporaryFile::write(QByteArray &data)
+qint64 FbBinary::write(QByteArray &data)
{
open();
if (m_hash.isEmpty()) m_hash = md5(data);
@@ -36,12 +36,12 @@ qint64 FbTemporaryFile::write(QByteArray &data)
return m_size;
}
-QString FbTemporaryFile::md5(const QByteArray &data)
+QString FbBinary::md5(const QByteArray &data)
{
return QCryptographicHash::hash(data, QCryptographicHash::Md5).toBase64();
}
-QByteArray FbTemporaryFile::data()
+QByteArray FbBinary::data()
{
open();
QByteArray data = readAll();
@@ -50,26 +50,26 @@ QByteArray FbTemporaryFile::data()
}
//---------------------------------------------------------------------------
-// FbTemporaryList
+// FbStore
//---------------------------------------------------------------------------
-FbTemporaryList::FbTemporaryList()
+FbStore::FbStore()
{
}
-FbTemporaryList::~FbTemporaryList()
+FbStore::~FbStore()
{
FbTemporaryIterator it(*this);
while (it.hasNext()) delete it.next();
}
-QString FbTemporaryList::add(const QString &path, QByteArray &data)
+QString FbStore::add(const QString &path, QByteArray &data)
{
- QString hash = FbTemporaryFile::md5(data);
+ QString hash = FbBinary::md5(data);
QString name = this->name(hash);
if (name.isEmpty()) {
name = newName(path);
- FbTemporaryFile * temp = new FbTemporaryFile(name);
+ FbBinary * temp = new FbBinary(name);
temp->setHash(hash);
temp->write(data);
append(temp);
@@ -77,7 +77,7 @@ QString FbTemporaryList::add(const QString &path, QByteArray &data)
return name;
}
-QString FbTemporaryList::newName(const QString &path)
+QString FbStore::newName(const QString &path)
{
QFileInfo info(path);
QString name = info.fileName();
@@ -91,50 +91,50 @@ QString FbTemporaryList::newName(const QString &path)
}
}
-FbTemporaryFile * FbTemporaryList::get(const QString &name) const
+FbBinary * FbStore::get(const QString &name) const
{
FbTemporaryIterator it(*this);
while (it.hasNext()) {
- FbTemporaryFile * file = it.next();
+ FbBinary * file = it.next();
if (file->name() == name) return file;
}
return NULL;
}
-QByteArray FbTemporaryList::data(const QString &name) const
+QByteArray FbStore::data(const QString &name) const
{
FbTemporaryIterator it(*this);
while (it.hasNext()) {
- FbTemporaryFile *file = it.next();
+ FbBinary *file = it.next();
if (file->name() == name) return file->data();
}
return QByteArray();
}
-const QString & FbTemporaryList::set(const QString &name, QByteArray data, const QString &hash)
+const QString & FbStore::set(const QString &name, QByteArray data, const QString &hash)
{
- FbTemporaryFile * file = get(name);
- if (!file) append(file = new FbTemporaryFile(name));
+ FbBinary * file = get(name);
+ if (!file) append(file = new FbBinary(name));
file->setHash(hash);
file->write(data);
return file->hash();
}
-QString FbTemporaryList::name(const QString &hash) const
+QString FbStore::name(const QString &hash) const
{
FbTemporaryIterator it(*this);
while (it.hasNext()) {
- FbTemporaryFile *file = it.next();
+ FbBinary *file = it.next();
if (file->hash() == hash) return file->name();
}
return QString();
}
-bool FbTemporaryList::exists(const QString &name) const
+bool FbStore::exists(const QString &name) const
{
FbTemporaryIterator it(*this);
while (it.hasNext()) {
- FbTemporaryFile *file = it.next();
+ FbBinary *file = it.next();
if (file->name() == name) return true;
}
return false;
@@ -224,7 +224,7 @@ QNetworkReply * FbNetworkAccessManager::imageRequest(Operation op, const QNetwor
QVariant FbNetworkAccessManager::info(int row, int col) const
{
if (0 <= row && row < count()) {
- FbTemporaryFile *file = m_files[row];
+ FbBinary *file = m_files[row];
switch (col) {
case 2: return file->type();
case 3: return file->size();
diff --git a/source/fb2temp.hpp b/source/fb2temp.hpp
index 27edc86..c84106e 100644
--- a/source/fb2temp.hpp
+++ b/source/fb2temp.hpp
@@ -15,13 +15,13 @@ class FbTextEdit;
class FbNetworkAccessManager;
-class FbTemporaryFile : public QTemporaryFile
+class FbBinary : public QTemporaryFile
{
Q_OBJECT
public:
static QString md5(const QByteArray &data);
public:
- explicit FbTemporaryFile(const QString &name);
+ explicit FbBinary(const QString &name);
inline qint64 write(QByteArray &data);
void setHash(const QString &hash) { m_hash = hash; }
const QString & hash() const { return m_hash; }
@@ -36,23 +36,28 @@ private:
qint64 m_size;
};
-class FbTemporaryList : public QList<FbTemporaryFile*>
+typedef QList<FbBinary*> FbBinatyList;
+
+class FbStore : public QObject, private FbBinatyList
{
+ Q_OBJECT
public:
- explicit FbTemporaryList();
- virtual ~FbTemporaryList();
-
+ explicit FbStore();
+ virtual ~FbStore();
QString add(const QString &path, QByteArray &data);
bool exists(const QString &name) const;
- FbTemporaryFile * get(const QString &name) const;
+ FbBinary * get(const QString &name) const;
const QString & set(const QString &name, QByteArray data, const QString &hash = QString());
QString name(const QString &hash) const;
QByteArray data(const QString &name) const;
+public:
+ inline FbBinary * operator[](int i) const { return FbBinatyList::operator[](i); }
+ inline int count() const { return FbBinatyList::count(); }
private:
QString newName(const QString &path);
};
-typedef QListIterator<FbTemporaryFile*> FbTemporaryIterator;
+typedef QListIterator<FbBinary*> FbTemporaryIterator;
#if 0
@@ -156,7 +161,7 @@ class FbNetworkAccessManager : public QNetworkAccessManager
public:
explicit FbNetworkAccessManager(QObject *parent = 0);
- FbTemporaryList & files() { return m_files; }
+ FbStore & files() { return m_files; }
void setPath(const QString &path) { m_path = path; }
public slots:
@@ -165,7 +170,7 @@ public slots:
public:
QString add(const QString &path, QByteArray &data) { return m_files.add(path, data); }
bool exists(const QString &name) const { return m_files.exists(name); }
- FbTemporaryFile * get(const QString &name) const { return m_files.get(name); }
+ FbBinary * get(const QString &name) const { return m_files.get(name); }
int count() const { return m_files.count(); }
QByteArray data(int index) const;
QVariant info(int row, int col) const;
@@ -177,7 +182,7 @@ private:
QNetworkReply *imageRequest(Operation op, const QNetworkRequest &request);
private:
- FbTemporaryList m_files;
+ FbStore m_files;
QString m_path;
friend class FbListWidget::FbProxy;
};
diff --git a/source/fb2text.hpp b/source/fb2text.hpp
index 037e785..66293cf 100644
--- a/source/fb2text.hpp
+++ b/source/fb2text.hpp
@@ -119,7 +119,7 @@ private:
bool actionEnabled(QWebPage::WebAction action);
bool actionChecked(QWebPage::WebAction action);
void execCommand(const QString &cmd, const QString &arg);
- FbTemporaryFile * file(const QString &name);
+ FbBinary * file(const QString &name);
FbNoteView & noteView();
QWebElement body();
QWebElement doc();