diff options
| author | Karol Kosek <krkk@krkk.ct8.pl> | 2021-01-16 11:53:59 +0100 |
|---|---|---|
| committer | Felix Queißner <felix@ib-queissner.de> | 2021-01-16 20:27:39 +0100 |
| commit | 82d86b5eb5c783d8c49f0513c6211fa225f77891 (patch) | |
| tree | 1efab972f4b088e5807001dd7d7d18a11b72872b /src/favouritecollection.cpp.bak | |
| parent | fa2df5fdeea9153523f3d50e0be50718ba13f670 (diff) | |
| download | kristall-82d86b5eb5c783d8c49f0513c6211fa225f77891.tar.gz | |
Remove .bak files
Diffstat (limited to 'src/favouritecollection.cpp.bak')
| -rw-r--r-- | src/favouritecollection.cpp.bak | 144 |
1 files changed, 0 insertions, 144 deletions
diff --git a/src/favouritecollection.cpp.bak b/src/favouritecollection.cpp.bak deleted file mode 100644 index 7b9bec5..0000000 --- a/src/favouritecollection.cpp.bak +++ /dev/null @@ -1,144 +0,0 @@ -#include "favouritecollection.hpp" - -#include <QFile> - -FavouriteCollection::FavouriteCollection(QObject *parent) : - QAbstractListModel(parent) -{ - -} - -void FavouriteCollection::add(QUrl const & url) -{ - if(contains(url)) - return; - - beginInsertRows(QModelIndex{}, items.size(), items.size() + 1); - items.push_back(url); - endInsertRows(); -} - -void FavouriteCollection::remove(QUrl const & url) -{ - for(int i = 0; i < items.size(); i++) - { - if(items.at(i) == url) { - beginRemoveRows(QModelIndex{}, i, i + 1); - items.removeAt(i); - endRemoveRows(); - return; - } - } -} - -bool FavouriteCollection::contains(const QUrl &url) -{ - for(auto const & item : items) { - if(item == url) - return true; - } - return false; -} - -QUrl FavouriteCollection::get(const QModelIndex &index) const -{ - if(index.isValid()) { - return items.at(index.row()); - } else { - return QUrl { }; - } -} - -bool FavouriteCollection::save(const QString &fileName) const -{ - QFile file(fileName); - if(not file.open(QFile::WriteOnly)) - return false; - - for(auto const & url: items) - { - QByteArray blob = (url.toString() + "\n").toUtf8(); - - qint64 offset = 0; - while(offset < blob.size()) - { - auto len = file.write(blob.data() + offset, blob.size() - offset); - if(len <= 0) { - file.close(); - return false; - } - offset += len; - } - } - - file.close(); - return true; -} - -bool FavouriteCollection::save(QSettings &settings) const -{ - settings.beginWriteArray("favourites", items.size()); - for(int i = 0; i < items.size(); i++) - { - settings.setArrayIndex(i); - settings.setValue("url", items[i].toString()); - } - settings.endArray(); - return true; -} - -bool FavouriteCollection::load(const QString &fileName) -{ - QFile file(fileName); - if(not file.open(QFile::ReadOnly)) - return false; - auto data = file.readAll(); - - beginResetModel(); - - items.clear(); - for(auto line : data.split('\n')) { - if(line.size() > 0) { - items.push_back(QUrl(QString::fromUtf8(line))); - } - } - endResetModel(); - - return true; -} - -bool FavouriteCollection::load(QSettings & settings) -{ - int len = settings.beginReadArray("favourites"); - items.resize(len); - for(int i = 0; i < items.size(); i++) - { - settings.setArrayIndex(i); - items[i] = settings.value("url").toString(); - } - settings.endArray(); - return true; -} - -int FavouriteCollection::rowCount(const QModelIndex &parent) const -{ - Q_UNUSED(parent) - return items.size(); -} - -bool FavouriteCollection::setData(const QModelIndex &index, const QVariant &value, int role) -{ - Q_UNUSED(value) - Q_UNUSED(index) - Q_UNUSED(role) - return false; -} - -QVariant FavouriteCollection::data(const QModelIndex &index, int role) const -{ - if(role != Qt::DisplayRole) { - return QVariant{}; - } - return items.at(index.row()).toString(); -} - |
