...
 
Commits (4)
......@@ -2,7 +2,7 @@
#define DBMANAGER_MIGRATE_FROM
// This file was generated by `/db/gen_migration_data.rb`.
// Last changed at: 2018-05-10 21:51:11 +0200
// Last changed at: 2019-11-25 02:11:26 +0100
void DbManager::migrateFrom(qlonglong version)
{
......@@ -56,6 +56,15 @@ void DbManager::migrateFrom(qlonglong version)
version = 20180510214908;
// qDebug() << "====== done ========";
}
if (version < 20191125012230)
{
// qDebug() << "migrating to version 20191125012230";
query.exec("CREATE TABLE `uploads` (`id` integer NOT NULL PRIMARY KEY AUTOINCREMENT, `submission_type` varchar(255) NOT NULL, `part` integer, `key` varchar(255), `file_path` varchar(255) NOT NULL, `title` varchar(255) NOT NULL, `message` varchar(255) NOT NULL, `keywords` varchar(255) NOT NULL, `category` integer DEFAULT (1) NOT NULL, `lock_comments` integer DEFAULT (0), `scrap` integer DEFAULT (0), `theme` integer DEFAULT (1) NOT NULL, `species` integer DEFAULT (1) NOT NULL, `gender` integer DEFAULT (0), `rating` integer DEFAULT (0) NOT NULL, `sort_id` integer NOT NULL, `created_at` integer NOT NULL, `completed_at` integer)");
query.exec("INSERT INTO `schema_migrations` (`version`) VALUES (20191125012230)");
version = 20191125012230;
// qDebug() << "====== done ========";
}
}
#endif // DBMANAGER_MIGRATE_FROM
Sequel.migration do
change do
create_table(:uploads) do
primary_key :id
String :submission_type, null: false
Integer :part
String :key
String :file_path, null: false
String :title, null: false
String :message, null: false
String :keywords, null: false
Integer :category, null: false, default: 1
Integer :lock_comments, default: 0
Integer :scrap, default: 0
Integer :theme, null: false, default: 1
Integer :species, null: false, default: 1
Integer :gender, default: 0
# maturity rating -- 0=>General, 2=>Mature, 1=>Adult
Integer :rating, null: false, default: 0
Integer :sort_id, null: false
Integer :created_at, null: false # UNIX timestamp
Integer :completed_at # UNIX timestamp
end
end
end
......@@ -33,8 +33,11 @@ SOURCES += \
src/mainwindow.cpp \
src/furaffinityclient.cpp \
src/dbmanager.cpp \
src/models/upload.cpp \
src/settings/settingsdialog.cpp \
src/settings/accountswidget.cpp \
src/uploaddialog.cpp \
src/uploadqueuewidget.cpp \
src/webdialog.cpp \
src/models/appsetting.cpp \
src/models/fauser.cpp \
......@@ -44,11 +47,14 @@ SOURCES += \
HEADERS += \
src/mainwindow.h \
src/furaffinityclient.h \
src/models/upload.h \
src/settings/nsettings.h \
src/dbmanager.h \
db/inc/dbmanager_migrate_from.h \
src/settings/settingsdialog.h \
src/settings/accountswidget.h \
src/uploaddialog.h \
src/uploadqueuewidget.h \
src/webdialog.h \
src/models/appsetting.h \
src/models/fauser.h \
......@@ -59,6 +65,8 @@ FORMS += \
src/mainwindow.ui \
src/settings/accountswidget.ui \
src/settings/settingsdialog.ui \
src/uploaddialog.ui \
src/uploadqueuewidget.ui \
src/webdialog.ui
# Crystal lib building - QMake style!
......
......@@ -22,8 +22,6 @@ void DbManager::init()
db.open();
mgr->runMigrations();
db.close();
}
//!
......
......@@ -67,7 +67,6 @@ bool FurAffinityClient::setUserFromDb(int accountId)
query.bindValue(":id", accountId);
if (!query.exec())
{
db.close();
return false;
}
......@@ -79,7 +78,6 @@ bool FurAffinityClient::setUserFromDb(int accountId)
query.bindValue(":account_id", accountId);
if (!query.exec())
{
db.close();
return false;
}
......@@ -100,7 +98,6 @@ bool FurAffinityClient::setUserFromDb(int accountId)
if (tmpUsername.isEmpty() || tmpCookieA.isEmpty() || tmpCookieB.isEmpty())
{
db.close();
return false;
}
......
......@@ -18,6 +18,8 @@ int main(int argc, char *argv[])
QCoreApplication::setApplicationName("nFurAffinity");
QCoreApplication::setOrganizationName("nilsding");
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
LIBXML_TEST_VERSION
// create app data dir if it does not exist yet
......
......@@ -17,6 +17,9 @@ MainWindow::MainWindow(QWidget *parent) :
qagAccounts = new QActionGroup(this);
ui->setupUi(this);
widgetUploadQueue = new UploadQueueWidget(this);
ui->centralTabs->addTab(widgetUploadQueue, widgetUploadQueue->windowTitle());
loadSettings();
}
......@@ -101,7 +104,6 @@ void MainWindow::refreshAccounts()
if (!query.exec("SELECT `id`, `username` FROM `accounts`"))
{
db.close();
return;
}
......@@ -137,8 +139,6 @@ void MainWindow::refreshAccounts()
}
ui->menu_Accounts->addActions(qagAccounts->actions());
db.close();
if (qagAccounts->actions().empty())
{
ui->menu_Accounts->addAction(ui->action_NoAccounts);
......
......@@ -5,6 +5,7 @@
#include <QActionGroup>
#include "furaffinityclient.h"
#include "uploadqueuewidget.h"
namespace Ui {
class MainWindow;
......@@ -36,6 +37,7 @@ private:
Ui::MainWindow *ui;
QActionGroup *qagAccounts;
FurAffinityClient *client;
UploadQueueWidget *widgetUploadQueue;
void storeSettings();
......
......@@ -11,19 +11,25 @@
</rect>
</property>
<property name="windowTitle">
<string>nilsding's FurAffinity tool</string>
<string>Jyrki's FurAffinity tool</string>
</property>
<property name="unifiedTitleAndToolBarOnMac">
<bool>true</bool>
</property>
<widget class="QWidget" name="centralWidget"/>
<widget class="QWidget" name="centralWidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTabWidget" name="centralTabs"/>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>22</height>
<height>29</height>
</rect>
</property>
<widget class="QMenu" name="menu_File">
......@@ -59,7 +65,6 @@
</attribute>
<addaction name="actionRefresh"/>
</widget>
<widget class="QStatusBar" name="statusBar"/>
<action name="action_Quit">
<property name="text">
<string>&amp;Quit</string>
......
......@@ -22,7 +22,6 @@ QString AppSetting::get(const QString &name, bool *ok)
{
*ok = false;
}
db.close();
return "";
}
......@@ -30,7 +29,6 @@ QString AppSetting::get(const QString &name, bool *ok)
{
*ok = true;
}
db.close();
return query.value("value").toString();
}
......@@ -46,10 +44,8 @@ bool AppSetting::set(const QString &name, const QString &value)
if (!query.exec())
{
db.close();
return false;
}
db.close();
return true;
}
......@@ -20,12 +20,9 @@ FaUser *FaUser::find(int id)
if (!(query.exec() && query.first()))
{
db.close();
return nullptr;
}
db.close();
auto faUser = new FaUser;
faUser->m_id = query.value("id").toInt();
faUser->m_username = query.value("username").toString();
......@@ -47,12 +44,9 @@ FaUser *FaUser::findByUsername(const QString &username)
if (!(query.exec() && query.first()))
{
db.close();
return nullptr;
}
db.close();
auto faUser = new FaUser;
faUser->m_id = query.value("id").toInt();
faUser->m_username = query.value("username").toString();
......@@ -80,7 +74,6 @@ FaUser *FaUser::findOrCreateByUsername(const QString &username)
if (!query.exec())
{
db.close();
return nullptr;
}
......@@ -88,8 +81,6 @@ FaUser *FaUser::findOrCreateByUsername(const QString &username)
faUser->m_id = query.lastInsertId().toInt();
faUser->m_username = username;
db.close();
return faUser;
}
......@@ -103,10 +94,12 @@ bool FaUser::save()
QStringList queryStringList;
queryStringList << QString("UPDATE `fa_users` SET");
QStringList fieldStringList;
if (m_username_changed)
{
queryStringList << "`username` = :username";
fieldStringList << "`username` = :username";
}
queryStringList << fieldStringList.join(", ");
queryStringList << QString("WHERE `id` = :id");
QSqlDatabase db = QSqlDatabase::database();
......@@ -122,7 +115,6 @@ bool FaUser::save()
}
bool ok = query.exec();
db.close();
return ok;
}
......@@ -19,12 +19,9 @@ Favorite *Favorite::find(qlonglong id)
if (!(query.exec() && query.first()))
{
db.close();
return nullptr;
}
db.close();
auto favorite = new Favorite;
favorite->m_id = query.value("id").toLongLong();
favorite->m_faUserId = query.value("fa_user_id").toInt();
......@@ -58,7 +55,6 @@ Favorite *Favorite::findOrCreate(qlonglong id,
if (!query.exec())
{
db.close();
return nullptr;
}
......@@ -68,8 +64,6 @@ Favorite *Favorite::findOrCreate(qlonglong id,
favorite->m_submissionId = submissionId;
favorite->m_createdAt = createdAt;
db.close();
return favorite;
}
......@@ -83,7 +77,7 @@ Favorite *Favorite::findOrCreate(qlonglong id,
bool Favorite::save()
{
if (!(m_faUserId_changed && m_submissionId_changed && m_createdAt_changed))
if (!(m_faUserId_changed || m_submissionId_changed || m_createdAt_changed))
{
return true;
}
......@@ -91,18 +85,20 @@ bool Favorite::save()
QStringList queryStringList;
queryStringList << QString("UPDATE `favorites` SET");
QStringList fieldStringList;
if (m_faUserId_changed)
{
queryStringList << "`fa_user_id` = :fa_user_id";
fieldStringList << "`fa_user_id` = :fa_user_id";
}
if (m_submissionId_changed)
{
queryStringList << "`submission_id` = :submission_id";
fieldStringList << "`submission_id` = :submission_id";
}
if (m_createdAt_changed)
{
queryStringList << "`created_at` = :created_at";
fieldStringList << "`created_at` = :created_at";
}
queryStringList << fieldStringList.join(", ");
queryStringList << QString("WHERE `id` = :id");
QSqlDatabase db = QSqlDatabase::database();
......@@ -128,7 +124,6 @@ bool Favorite::save()
}
bool ok = query.exec();
db.close();
return ok;
}
......@@ -20,12 +20,9 @@ Submission *Submission::find(qlonglong id)
if (!(query.exec() && query.first()))
{
db.close();
return nullptr;
}
db.close();
auto submission = new Submission;
submission->m_id = query.value("id").toLongLong();
submission->m_title = query.value("title").toString();
......@@ -50,7 +47,6 @@ Submission *Submission::findOrCreate(qlonglong id, const QString &title)
if (!query.exec())
{
db.close();
return nullptr;
}
......@@ -58,8 +54,6 @@ Submission *Submission::findOrCreate(qlonglong id, const QString &title)
submission->m_id = query.lastInsertId().toLongLong();
submission->m_title = title;
db.close();
return submission;
}
......@@ -73,10 +67,12 @@ bool Submission::save()
QStringList queryStringList;
queryStringList << QString("UPDATE `submissions` SET");
QStringList fieldStringList;
if (m_title_changed)
{
queryStringList << "`title` = :title";
fieldStringList << "`title` = :title";
}
queryStringList << fieldStringList.join(", ");
queryStringList << QString("WHERE `id` = :id");
QSqlDatabase db = QSqlDatabase::database();
......@@ -92,7 +88,6 @@ bool Submission::save()
}
bool ok = query.exec();
db.close();
return ok;
}
#include "upload.h"
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QVariant>
#include <QStringList>
#include <QSqlError>
#include <iostream>
Upload::Upload(QObject* parent) : QObject(parent)
{
}
Upload* Upload::find(qlonglong id)
{
QSqlDatabase db = QSqlDatabase::database();
QSqlQuery query;
query.prepare("SELECT * FROM `uploads` WHERE `id` = :id");
query.bindValue(":id", id);
if (!(query.exec() && query.first()))
{
return nullptr;
}
auto upload = new Upload;
upload->m_id = query.value("id").toLongLong();
upload->m_submissionType = query.value("submission_type").toString();
upload->m_part = query.value("part").toInt();
upload->m_key = query.value("key").toString();
upload->m_filePath = query.value("file_path").toString();
upload->m_title = query.value("title").toString();
upload->m_message = query.value("message").toString();
upload->m_keywords = query.value("keywords").toString();
upload->m_category = query.value("category").toInt();
upload->m_lockComments = query.value("lock_comments").toInt() == 1 ? true : false;
upload->m_scrap = query.value("scrap").toInt() == 1 ? true : false;
upload->m_theme = query.value("theme").toInt();
upload->m_species = query.value("species").toInt();
upload->m_gender = query.value("gender").toInt();
upload->m_rating = query.value("rating").toInt();
upload->m_sortId = query.value("sort_id").toInt();
upload->m_createdAt = QDateTime::fromSecsSinceEpoch(
query.value("created_at").toLongLong());
upload->m_completedAt = QDateTime::fromSecsSinceEpoch(
query.value("completed_at").toLongLong());
return upload;
}
bool Upload::create(QString submissionType, int part, QString key,
QString filePath, QString title, QString message,
QString keywords, int category, bool lockComments,
bool scrap, int theme, int species, int gender,
int rating, int sortId)
{
QSqlDatabase db = QSqlDatabase::database();
QSqlQuery query;
query.prepare("INSERT INTO `uploads` "
"(`submission_type`, `part`, `key`, `file_path`, `title`,"
" `message`, `keywords`, `category`, `lock_comments`,"
" `scrap`, `theme`, `species`, `gender`, `rating`,"
" `sort_id`, `created_at`) VALUES"
"(:submission_type, :part, :key, :file_path, :title,"
" :message, :keywords, :category, :lock_comments, :scrap,"
" :theme, :species, :gender, :rating, :sort_id, :created_at)");
query.bindValue(":submission_type", submissionType);
query.bindValue(":part", part);
query.bindValue(":key", key);
query.bindValue(":file_path", filePath);
query.bindValue(":title", title);
query.bindValue(":message", message);
query.bindValue(":keywords", keywords);
query.bindValue(":category", category);
query.bindValue(":lock_comments", lockComments);
query.bindValue(":scrap", scrap);
query.bindValue(":theme", theme);
query.bindValue(":species", species);
query.bindValue(":gender", gender);
query.bindValue(":rating", rating);
query.bindValue(":sort_id", sortId);
query.bindValue(":created_at", QDateTime::currentSecsSinceEpoch());
if (!query.exec())
{
return false;
}
return true;
}
bool Upload::save()
{
if (!(m_submissionType_changed || m_part_changed || m_key_changed
|| m_filePath_changed || m_title_changed || m_message_changed
|| m_keywords_changed || m_category_changed || m_lockComments_changed
|| m_scrap_changed || m_theme_changed || m_species_changed
|| m_gender_changed || m_rating_changed || m_sortId_changed
|| m_createdAt_changed || m_completedAt_changed))
{
return true;
}
QStringList queryStringList;
queryStringList << QString("UPDATE `uploads` SET");
QStringList fieldStringList;
if (m_submissionType_changed)
{
fieldStringList << "`submission_type` = :submission_type";
}
if (m_part_changed)
{
fieldStringList << "`part` = :part";
}
if (m_key_changed)
{
fieldStringList << "`key` = :key";
}
if (m_filePath_changed)
{
fieldStringList << "`file_path` = :file_path";
}
if (m_title_changed)
{
fieldStringList << "`title` = :title";
}
if (m_message_changed)
{
fieldStringList << "`message` = :message";
}
if (m_keywords_changed)
{
fieldStringList << "`keywords` = :keywords";
}
if (m_category_changed)
{
fieldStringList << "`category` = :category";
}
if (m_lockComments_changed)
{
fieldStringList << "`lock_comments` = :lock_comments";
}
if (m_scrap_changed)
{
fieldStringList << "`scrap` = :scrap";
}
if (m_theme_changed)
{
fieldStringList << "`theme` = :theme";
}
if (m_species_changed)
{
fieldStringList << "`species` = :species";
}
if (m_gender_changed)
{
fieldStringList << "`gender` = :gender";
}
if (m_rating_changed)
{
fieldStringList << "`rating` = :rating";
}
if (m_sortId_changed)
{
fieldStringList << "`sort_id` = :sort_id";
}
if (m_createdAt_changed)
{
fieldStringList << "`created_at` = :created_at";
}
if (m_completedAt_changed)
{
fieldStringList << "`completed_at` = :completed_at";
}
queryStringList << fieldStringList.join(", ");
queryStringList << QString("WHERE `id` = :id");
QSqlDatabase db = QSqlDatabase::database();
QSqlQuery query;
std::cout << queryStringList.join(" ").toStdString() << std::endl;
query.prepare(queryStringList.join(" "));
query.bindValue(":id", m_id);
if (m_submissionType_changed)
{
query.bindValue(":submission_type", m_submissionType);
m_submissionType_changed = false;
}
if (m_part_changed)
{
query.bindValue(":part", m_part);
m_part_changed = false;
}
if (m_key_changed)
{
query.bindValue(":key", m_key);
m_key_changed = false;
}
if (m_filePath_changed)
{
query.bindValue(":file_path", m_filePath);
m_filePath_changed = false;
}
if (m_title_changed)
{
query.bindValue(":title", m_title);
m_title_changed = false;
}
if (m_message_changed)
{
query.bindValue(":message", m_message);
m_message_changed = false;
}
if (m_keywords_changed)
{
query.bindValue(":keywords", m_keywords);
m_keywords_changed = false;
}
if (m_category_changed)
{
query.bindValue(":category", m_category);
m_category_changed = false;
}
if (m_lockComments_changed)
{
query.bindValue(":lock_comments", m_lockComments ? 1 : 0);
m_lockComments_changed = false;
}
if (m_scrap_changed)
{
query.bindValue(":scrap", m_scrap ? 1 : 0);
m_scrap_changed = false;
}
if (m_theme_changed)
{
query.bindValue(":theme", m_theme);
m_theme_changed = false;
}
if (m_species_changed)
{
query.bindValue(":species", m_species);
m_species_changed = false;
}
if (m_gender_changed)
{
query.bindValue(":gender", m_gender);
m_gender_changed = false;
}
if (m_rating_changed)
{
query.bindValue(":rating", m_rating);
m_rating_changed = false;
}
if (m_sortId_changed)
{
query.bindValue(":sort_id", m_sortId);
m_sortId_changed = false;
}
if (m_createdAt_changed)
{
query.bindValue(":created_at", m_createdAt.toSecsSinceEpoch());
m_createdAt_changed = false;
}
if (m_completedAt_changed)
{
query.bindValue(":completed_at", m_completedAt.toSecsSinceEpoch());
m_completedAt_changed = false;
}
bool ok = query.exec();
std::cout << query.lastError().text().toStdString() << std::endl;
return ok;
}
#ifndef UPLOAD_H
#define UPLOAD_H
#include <QObject>
#include <QDateTime>
class Upload : public QObject
{
Q_OBJECT
Q_PROPERTY(qlonglong id READ id)
Q_PROPERTY(QString submissionType READ submissionType WRITE setSubmissionType
NOTIFY submissionTypeChanged)
Q_PROPERTY(int part READ part WRITE setPart NOTIFY partChanged)
Q_PROPERTY(QString key READ key WRITE setKey NOTIFY keyChanged)
Q_PROPERTY(QString filePath READ filePath WRITE setFilePath
NOTIFY filePathChanged)
Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
Q_PROPERTY(QString message READ message WRITE setMessage NOTIFY messageChanged)
Q_PROPERTY(QString keywords READ keywords WRITE setKeywords NOTIFY keywordsChanged)
Q_PROPERTY(int category READ category WRITE setCategory NOTIFY categoryChanged)
Q_PROPERTY(bool lockComments READ lockComments WRITE setLockComments
NOTIFY lockCommentsChanged)
Q_PROPERTY(bool scrap READ scrap WRITE setScrap NOTIFY scrapChanged)
Q_PROPERTY(int theme READ theme WRITE setTheme NOTIFY themeChanged)
Q_PROPERTY(int species READ species WRITE setSpecies NOTIFY speciesChanged)
Q_PROPERTY(int gender READ gender WRITE setGender NOTIFY genderChanged)
Q_PROPERTY(int rating READ rating WRITE setRating NOTIFY ratingChanged)
Q_PROPERTY(int sortId READ sortId WRITE setSortId NOTIFY sortIdChanged)
Q_PROPERTY(QDateTime createdAt READ createdAt WRITE setCreatedAt
NOTIFY createdAtChanged)
Q_PROPERTY(QDateTime completedAt READ completedAt WRITE setCompletedAt
NOTIFY completedAtChanged)
public:
explicit Upload(QObject* parent = nullptr);
static Upload* find(qlonglong id);
static bool create(QString submissionType, int part, QString key,
QString filePath, QString title, QString message,
QString keywords, int category, bool lockComments,
bool scrap, int theme, int species, int gender,
int rating, int sortId);
bool save();
qlonglong id() const
{
return m_id;
}
QString submissionType() const
{
return m_submissionType;
}
int part() const
{
return m_part;
}
QString key() const
{
return m_key;
}
QString filePath() const
{
return m_filePath;
}
QString title() const
{
return m_title;
}
QString message() const
{
return m_message;
}
QString keywords() const
{
return m_keywords;
}
int category() const
{
return m_category;
}
bool lockComments() const
{
return m_lockComments;
}
bool scrap() const
{
return m_scrap;
}
int theme() const
{
return m_theme;
}
int species() const
{
return m_species;
}
int gender() const
{
return m_gender;
}
int rating() const
{
return m_rating;
}
int sortId() const
{
return m_sortId;
}
QDateTime createdAt() const
{
return m_createdAt;
}
QDateTime completedAt() const
{
return m_completedAt;
}
signals:
void submissionTypeChanged(QString submissionType);
void partChanged(int part);
void keyChanged(QString key);
void filePathChanged(QString filePath);
void titleChanged(QString title);
void messageChanged(QString message);
void keywordsChanged(QString keywords);
void categoryChanged(int category);
void lockCommentsChanged(bool lockComments);
void scrapChanged(bool scrap);
void themeChanged(int theme);
void speciesChanged(int species);
void genderChanged(int gender);
void ratingChanged(int rating);
void sortIdChanged(int sortId);
void createdAtChanged(QDateTime createdAt);
void completedAtChanged(QDateTime completedAt);
public slots:
void setSubmissionType(QString submissionType)
{
if (m_submissionType == submissionType)
return;
m_submissionType = submissionType;
m_submissionType_changed = true;
emit submissionTypeChanged(m_submissionType);
}
void setPart(int part)
{
if (m_part == part)
return;
m_part = part;
m_part_changed = true;
emit partChanged(m_part);
}
void setKey(QString key)
{
if (m_key == key)
return;
m_key = key;
m_key_changed = true;
emit keyChanged(m_key);
}
void setFilePath(QString filePath)
{
if (m_filePath == filePath)
return;
m_filePath = filePath;
m_filePath_changed = true;
emit filePathChanged(m_filePath);
}
void setTitle(QString title)
{
if (m_title == title)
return;
m_title = title;
m_title_changed = true;
emit titleChanged(m_title);
}
void setMessage(QString message)
{
if (m_message == message)
return;
m_message = message;
m_message_changed = true;
emit messageChanged(m_message);
}
void setKeywords(QString keywords)
{
if (m_keywords == keywords)
return;
m_keywords = keywords;
m_keywords_changed = true;
emit keywordsChanged(m_keywords);
}
void setCategory(int category)
{
if (m_category == category)
return;
m_category = category;
m_category_changed = true;
emit categoryChanged(m_category);
}
void setLockComments(bool lockComments)
{
if (m_lockComments == lockComments)
return;
m_lockComments = lockComments;
m_lockComments_changed = true;
emit lockCommentsChanged(m_lockComments);
}
void setScrap(bool scrap)
{
if (m_scrap == scrap)
return;
m_scrap = scrap;
m_scrap_changed = true;
emit scrapChanged(m_scrap);
}
void setTheme(int theme)
{
if (m_theme == theme)
return;
m_theme = theme;
m_theme_changed = true;
emit themeChanged(m_theme);
}
void setSpecies(int species)
{
if (m_species == species)
return;
m_species = species;
m_species_changed = true;
emit speciesChanged(m_species);
}
void setGender(int gender)
{
if (m_gender == gender)
return;
m_gender = gender;
m_gender_changed = true;
emit genderChanged(m_gender);
}
void setRating(int rating)
{
if (m_rating == rating)
return;
m_rating = rating;
m_rating_changed = true;
emit ratingChanged(m_rating);
}
void setSortId(int sortId)
{
if (m_sortId == sortId)
return;
m_sortId = sortId;
m_sortId_changed = true;
emit sortIdChanged(m_sortId);
}
void setCreatedAt(QDateTime createdAt)
{
if (m_createdAt == createdAt)
return;
m_createdAt = createdAt;
m_createdAt_changed = true;
emit createdAtChanged(m_createdAt);
}
void setCompletedAt(QDateTime completedAt)
{
if (m_completedAt == completedAt)
return;
m_completedAt = completedAt;
m_completedAt_changed = true;
emit completedAtChanged(m_completedAt);
}
private:
qlonglong m_id;
QString m_submissionType;
bool m_submissionType_changed = false;
int m_part;
bool m_part_changed = false;
QString m_key;
bool m_key_changed = false;
QString m_filePath;
bool m_filePath_changed = false;
QString m_title;
bool m_title_changed = false;
QString m_message;
bool m_message_changed = false;
QString m_keywords;
bool m_keywords_changed = false;
int m_category;
bool m_category_changed = false;
bool m_lockComments;
bool m_lockComments_changed = false;
bool m_scrap;
bool m_scrap_changed = false;
int m_theme;
bool m_theme_changed = false;
int m_species;
bool m_species_changed = false;
int m_gender;
bool m_gender_changed = false;
int m_rating;
bool m_rating_changed = false;
int m_sortId;
bool m_sortId_changed = false;
QDateTime m_createdAt;
bool m_createdAt_changed = false;
QDateTime m_completedAt;
bool m_completedAt_changed = false;
};
#endif // UPLOAD_H
......@@ -105,7 +105,6 @@ void AccountsWidget::reloadModel()
{
QSqlDatabase db = QSqlDatabase::database();
accountsModel->setQuery("SELECT `username` FROM accounts");
db.close();
}
void AccountsWidget::addNewUser(const QString &userName)
......@@ -124,7 +123,6 @@ void AccountsWidget::addNewUser(const QString &userName)
tr("Could not insert new record:\n\n%1")
.arg(query.lastError().databaseText()));
db.close();
return;
}
......@@ -146,7 +144,6 @@ void AccountsWidget::addNewUser(const QString &userName)
tr("Could not insert new record:\n\n%1")
.arg(query.lastError().databaseText()));
db.close();
return;
}
......@@ -166,11 +163,9 @@ void AccountsWidget::addNewUser(const QString &userName)
tr("Could not insert new record:\n\n%1")
.arg(query.lastError().databaseText()));
db.close();
return;
}
db.close();
reloadModel();
}
......@@ -192,7 +187,6 @@ void AccountsWidget::deleteUser(const QString &userName)
tr("Could not delete records:\n\n%1")
.arg(query.lastError().databaseText()));
db.close();
return;
}
......@@ -206,11 +200,9 @@ void AccountsWidget::deleteUser(const QString &userName)
tr("Could not delete records:\n\n%1")
.arg(query.lastError().databaseText()));
db.close();
return;
}
db.close();
reloadModel();
}
......
This diff is collapsed.
#ifndef UPLOADDIALOG_H
#define UPLOADDIALOG_H
#include <QDialog>
#include "models/upload.h"
namespace Ui {
class UploadDialog;
}
class UploadDialog : public QDialog
{
Q_OBJECT
public:
explicit UploadDialog(QWidget *parent = nullptr);
~UploadDialog() override;
void fetchUploadDetails(int id);
private slots:
void on_qpbOpenFile_clicked();
void accept() override;
void on_qleFilePath_textChanged(const QString &arg1);
private:
Ui::UploadDialog *ui;
Upload* m_upload = nullptr;
void populateComboboxes();
};
#endif // UPLOADDIALOG_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>UploadDialog</class>
<widget class="QDialog" name="UploadDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>900</width>
<height>622</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>900</width>
<height>350</height>
</size>
</property>
<property name="windowTitle">
<string>Edit Upload</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="0,0,0">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="qlSubmissionFile">
<property name="text">
<string>Submission file:</string>
</property>
<property name="buddy">
<cstring>qleFilePath</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,0">
<item>
<widget class="QLineEdit" name="qleFilePath"/>
</item>
<item>
<widget class="QPushButton" name="qpbOpenFile">
<property name="icon">
<iconset theme="document-open">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="qlTitle">
<property name="text">
<string>Title:</string>
</property>
<property name="buddy">
<cstring>qleTitle</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="qleTitle">
<property name="maxLength">
<number>60</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="qlDescription">
<property name="text">
<string>Description:</string>
</property>
<property name="buddy">
<cstring>qpteDescription</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPlainTextEdit" name="qpteDescription">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>2</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="tabChangesFocus">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="qcbLockComments">
<property name="text">
<string>Lock comments</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="qlKeywords">
<property name="text">
<string>Keywords:</string>
</property>
<property name="buddy">
<cstring>qleKeywords</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="qleKeywords">
<property name="maxLength">
<number>250</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QFormLayout" name="formLayout_3">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="qlCategory">
<property name="text">
<string>Category:</string>
</property>
<property name="buddy">
<cstring>qcbCategory</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="qcbCategory"/>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="qcbScrap">
<property name="text">
<string>Put in scraps</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="qlTheme">
<property name="text">
<string>Theme:</string>
</property>
<property name="buddy">
<cstring>qcbTheme</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="qcbTheme"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="qlSpecies">
<property name="text">
<string>Species:</string>
</property>
<property name="buddy">
<cstring>qcbSpecies</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="qcbSpecies"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="qlGender">
<property name="text">
<string>Gender:</string>
</property>
<property name="buddy">
<cstring>qcbGender</cstring>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="qcbGender"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="qlRating">
<property name="text">
<string>Maturity Rating:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QRadioButton" name="qrbGeneral">
<property name="text">
<string>General</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="qrbMature">
<property name="text">
<string>Mature</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="qrbAdult">
<property name="text">
<string>Adult</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="qlPreview">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>1</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>UploadDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>UploadDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
#include "uploadqueuewidget.h"
#include "ui_uploadqueuewidget.h"
#include "uploaddialog.h"
#include "models/upload.h"
#include <QSqlRecord>
#include <QMessageBox>
UploadQueueWidget::UploadQueueWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::UploadQueueWidget)
{
ui->setupUi(this);
tableModel = new QSqlTableModel(this, QSqlDatabase::database());
tableModel->setTable("uploads");
tableModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
tableModel->select();
ui->qlvUploads->setModel(tableModel);
}
UploadQueueWidget::~UploadQueueWidget()
{
delete ui;
}
void UploadQueueWidget::on_qpbAdd_clicked()
{
UploadDialog ud;
ud.exec();
qobject_cast<QSqlTableModel*>(ui->qlvUploads->model())->select();
}
void UploadQueueWidget::on_qpbEdit_clicked()
{
auto index = ui->qlvUploads->currentIndex();
if (!index.isValid())
{
QMessageBox::warning(this, tr("Warning"), tr("You must select an item"));
return;
}
auto model = qobject_cast<QSqlTableModel*>(ui->qlvUploads->model());
UploadDialog ud;
ud.fetchUploadDetails(model->record(index.row()).value("id").toInt());
ud.exec();
model->select();
}
void UploadQueueWidget::on_qlvUploads_clicked(const QModelIndex &index)
{
auto model = qobject_cast<QSqlTableModel*>(ui->qlvUploads->model());
auto upload = Upload::find(model->record(index.row()).value("id").toInt());
if (upload)
{
ui->qlPreview->setStyleSheet(
QString("image: url(\"%1\");")
.arg(upload->filePath().replace("\"", "\\\"")));
upload->deleteLater();
}
}
#ifndef UPLOADQUEUEWIDGET_H
#define UPLOADQUEUEWIDGET_H
#include <QWidget>
#include <QSqlTableModel>
namespace Ui {
class UploadQueueWidget;
}
class UploadQueueWidget : public QWidget
{
Q_OBJECT
public:
explicit UploadQueueWidget(QWidget *parent = nullptr);
~UploadQueueWidget();
private slots:
void on_qpbAdd_clicked();
void on_qpbEdit_clicked();
void on_qlvUploads_clicked(const QModelIndex &index);
private:
Ui::UploadQueueWidget *ui;
QSqlTableModel *tableModel;
};
#endif // UPLOADQUEUEWIDGET_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>UploadQueueWidget</class>
<widget class="QWidget" name="UploadQueueWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>422</width>
<height>314</height>
</rect>
</property>
<property name="windowTitle">
<string>Upload Queue</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="1,0">
<item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,0">
<item>
<widget class="QListView" name="qlvUploads"/>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<widget class="QPushButton" name="qpbAdd">
<property name="text">
<string>&amp;Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="qpbEdit">
<property name="text">
<string>&amp;Edit</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="qpbDelete">
<property name="text">
<string>&amp;Delete</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="qcbUpload">
<property name="text">
<string>&amp;Upload</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="qlPreview">
<property name="minimumSize">
<size>
<width>90</width>
<height>90</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="2,1">
<item>
<widget class="QLabel" name="qlStatus">
<property name="text">
<string>Done</string>
</property>
</widget>
</item>