#include #include #include #include #include #include #include "constants.h" #include "playground.h" #include "rsshit_db.h" #include "user.h" int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); // Set up code that uses the Qt event loop here. // Call a.quit() or a.exit() to quit the application. // A not very useful example would be including // #include // near the top of the file and calling // QTimer::singleShot(5000, &a, &QCoreApplication::quit); // which quits the application after 5 seconds. // If you do not need a running Qt event loop, remove the call // to a.exec() or use the Non-Qt Plain C++ Application template. QFile dbSqliteResource{rsshit::db::dbSqliteResourceFilename}; const auto dataLocation = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); qDebug() << "data location:" << dataLocation; if (!QDir{}.mkpath(dataLocation)) { qWarning() << "cannot create " << dataLocation; return EXIT_FAILURE; } const QString newDbFilepath{dataLocation + '/' + QFileInfo{dbSqliteResource}.fileName()}; #define RECREATE_DB_FILE #ifdef RECREATE_DB_FILE if (!QFile::remove(newDbFilepath)) { qWarning() << "cannot remove" << newDbFilepath; } if (!dbSqliteResource.copy(newDbFilepath)) { qWarning() << "cannot copy db file (" << dbSqliteResource.fileName() << ") from resources to data dir (" << newDbFilepath << "):" << dbSqliteResource.errorString(); return EXIT_FAILURE; } #endif QFile newDbFile{newDbFilepath}; if (!newDbFile.setPermissions(QFileDevice::Permission::ReadUser | QFileDevice::Permission::WriteUser)) { qWarning() << "cannot set file permissions:" << newDbFile.fileName() << Qt::endl << newDbFile.errorString(); return EXIT_FAILURE; } User user{"admin", "123"}; qDebug() << "verify password 123:" << user.verifyPassword("123"); qDebug() << "verify password 321:" << user.verifyPassword("321"); qDebug() << "user.getDbId()" << user.getDbId(); qDebug() << "user.createInDb()" << user.createInDb(); qDebug() << "user.createInDb()" << user.getOrInsertDbId(); qDebug() << "user.createInDb()" << user.createInDb(); Playground playground; QTimer::singleShot(0, [&]() { // const QString url{"https://jenngott.com/feed/"}; // const QUrl url{"https://liliputing.com/feed"}; // playground.fetchUrl(url); // return; // QFile f{"/tmp/rss/feed"}; QFile f{"/home/nikita/tmp/rss/feed"}; // QFile f{"/tmp/rss/feed.1"}; // QFile f{"/tmp/rss/rss"}; if (!f.open(QFile::ReadOnly)) { qWarning() << "cannot open file" << f.fileName() << ":" << f.errorString(); return; } const auto channel = playground.parseFeed(&f); if (!applyToDb(channel)) { qWarning() << "cannot apply channel to db"; return; } }); return a.exec(); }