104 lines
2.4 KiB
C++
104 lines
2.4 KiB
C++
/*
|
|
* Copyright 2012-2018 Morgan McMillian <gilag@monkeystew.com>
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#include "LocalFile.h"
|
|
|
|
LocalFile::LocalFile() {
|
|
mPath = "data/todo";
|
|
mFile = mPath + "/todo.txt";
|
|
mDone = mPath + "/done.txt";
|
|
if (!dir.exists(mPath)) {
|
|
dir.mkdir(mPath);
|
|
}
|
|
}
|
|
|
|
LocalFile::~LocalFile() {
|
|
// TODO Auto-generated destructor stub
|
|
}
|
|
|
|
QStringList LocalFile::load() const {
|
|
QStringList data;
|
|
QFile file(mFile);
|
|
file.open(QIODevice::ReadOnly);
|
|
QTextStream in(&file);
|
|
while (!in.atEnd()) {
|
|
QString line = in.readLine();
|
|
data << line;
|
|
}
|
|
return data;
|
|
}
|
|
|
|
QStringList LocalFile::loadArchive() const {
|
|
QStringList data;
|
|
QFile file(mDone);
|
|
file.open(QIODevice::ReadOnly);
|
|
QTextStream in(&file);
|
|
while (!in.atEnd()) {
|
|
QString line = in.readLine();
|
|
data << line;
|
|
}
|
|
return data;
|
|
}
|
|
|
|
void LocalFile::save(const QStringList &data) {
|
|
QSettings settings;
|
|
QString lnend = settings.value("windowsbreak").toBool() ? "\r\n" : "\n";
|
|
QFile file(mFile);
|
|
file.open(QIODevice::WriteOnly);
|
|
QTextStream out(&file);
|
|
foreach (QString line, data) {
|
|
out << line << lnend;
|
|
}
|
|
file.close();
|
|
}
|
|
|
|
void LocalFile::saveArchive(const QStringList &data) {
|
|
QSettings settings;
|
|
QString lnend = settings.value("windowsbreak").toBool() ? "\r\n" : "\n";
|
|
QFile file(mDone);
|
|
file.open(QIODevice::WriteOnly);
|
|
QTextStream out(&file);
|
|
foreach (QString line, data) {
|
|
out << line << lnend;
|
|
}
|
|
file.close();
|
|
}
|
|
|
|
void LocalFile::archive(const QStringList &data) {
|
|
QSettings settings;
|
|
QString lnend = settings.value("windowsbreak").toBool() ? "\r\n" : "\n";
|
|
QFile file(mDone);
|
|
file.open(QIODevice::Append);
|
|
QTextStream out(&file);
|
|
foreach (QString line, data) {
|
|
out << line << lnend;
|
|
}
|
|
file.close();
|
|
}
|
|
|
|
QString LocalFile::path() const {
|
|
return mPath;
|
|
}
|
|
|
|
void LocalFile::setPath(const QString &path) {
|
|
mPath = path;
|
|
if (!dir.exists(mPath)) {
|
|
dir.mkdir(mPath);
|
|
}
|
|
mFile = mPath + "/todo.txt";
|
|
mDone = mPath + "/done.txt";
|
|
}
|