- CompactMailDelegate: card-based view for narrow panels (<420px) * Avatar with hash-based color, sender + date (relative format) * Subject line with attachment icon * Action buttons: flag, delete, category, more (context menu) * Unread highlight with light blue background + bold sender - MailListView: automatic switch between tree/table (wide) and list/cards (narrow) * QStackedWidget with QTreeView + QListView sharing same proxy model * resizeEvent threshold at 420px * Signals forwarded to MainMainWindow for actions - FolderTreeDelegate: custom paint for folder tree * Unread count badge (blue pill) right-aligned on folder nodes * Account nodes bold, folder nodes normal weight * Proper indentation per depth level - MailItemDao::countUnreadByFolderId() for real-time unread counts - MainMainWindow handlers for compact actions (flag, delete, category, more menu)
157 lines
5.8 KiB
Plaintext
157 lines
5.8 KiB
Plaintext
#include <QString>
|
|
#include <QDebug>
|
|
#include <QCoreApplication>
|
|
#include <QUuid>
|
|
#include "src/db/databasemanager.h"
|
|
#include "src/db/dao/mailitemdao.h"
|
|
#include "src/db/dao/folderdao.h"
|
|
#include "src/db/dao/accountdao.h"
|
|
#include "src/core/mailitem.h"
|
|
#include "src/core/models/account.h"
|
|
#include "src/core/models/folder.h"
|
|
#include <QSqlQuery>
|
|
#include <QSqlDatabase>
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
QCoreApplication app(argc, argv);
|
|
// Initialize database (will open/create wino-mail.sqlite in current dir)
|
|
if (!DatabaseManager::instance().initialize()) {
|
|
qCritical() << "Failed to initialize database";
|
|
return 1;
|
|
}
|
|
qInfo() << "Database initialized";
|
|
|
|
// Debug: print table schema
|
|
QSqlDatabase& db = DatabaseManager::instance().database();
|
|
QSqlQuery query(db);
|
|
if (query.exec("PRAGMA table_info(MailCopy)")) {
|
|
qInfo() << "MailCopy table schema:";
|
|
while (query.next()) {
|
|
qInfo() << " cid:" << query.value(0).toInt()
|
|
<< " name:" << query.value(1).toString()
|
|
<< " type:" << query.value(2).toString()
|
|
<< " notnull:" << query.value(3).toInt()
|
|
<< " dflt_value:" << query.value(4).toString()
|
|
<< " pk:" << query.value(5).toInt();
|
|
}
|
|
} else {
|
|
qWarning() << "Failed to get table info:" << query.lastError().text();
|
|
}
|
|
|
|
// Create and insert an Account
|
|
Account account;
|
|
account.setId(1);
|
|
account.setEmail(QStringLiteral("test@example.com"));
|
|
account.setDisplayName(QStringLiteral("Test User"));
|
|
account.setSignature(QStringLiteral("Test signature"));
|
|
account.setType(AccountType::Outlook);
|
|
if (!AccountDao::insert(account)) {
|
|
qCritical() << "Failed to insert account";
|
|
return 1;
|
|
}
|
|
qInfo() << "Inserted account with ID:" << account.id();
|
|
|
|
// Create and insert a Folder (Inbox) under the account
|
|
Folder folder;
|
|
folder.setId(1);
|
|
folder.setAccountId(1);
|
|
folder.setName(QStringLiteral("Inbox"));
|
|
folder.setInbox(true);
|
|
if (!FolderDao::insert(folder)) {
|
|
qCritical() << "Failed to insert folder";
|
|
return 1;
|
|
}
|
|
qInfo() << "Inserted folder with ID:" << folder.id();
|
|
|
|
// Create a test MailItem
|
|
MailItem item;
|
|
item.setFolderId(1); // Inbox folder
|
|
item.setMessageId(QUuid::createUuid().toString(QUuid::WithoutBraces));
|
|
item.setSubject(QStringLiteral("Test Subject"));
|
|
item.setSender(QStringLiteral("sender@example.com"));
|
|
item.setRecipient(QStringLiteral("recipient@example.com")); // maps to recipient column
|
|
item.setTo(QStringLiteral("to@example.com"));
|
|
item.setCc(QStringLiteral("cc@example.com"));
|
|
item.setBcc(QStringLiteral("bcc@example.com"));
|
|
item.setDate(QDateTime::currentDateTimeUtc());
|
|
item.setRead(false);
|
|
item.setFlagged(false);
|
|
item.setSize(1024);
|
|
item.setFileId(QStringLiteral("file123"));
|
|
item.setUid(12345);
|
|
item.setBodyHtml(QStringLiteral("<html><body>Hello</body></html>"));
|
|
|
|
// Insert
|
|
bool ok = MailItemDao::insert(item);
|
|
if (!ok) {
|
|
qCritical() << "Failed to insert mail item";
|
|
return 1;
|
|
}
|
|
qInfo() << "Inserted mail item with ID:" << item.id();
|
|
|
|
// Debug: let's see what's in the table for the inserted row
|
|
QSqlQuery query2(db);
|
|
query2.prepare("SELECT * FROM MailCopy WHERE id = :id");
|
|
query2.bindValue(":id", item.id());
|
|
if (query2.exec() && query2.next()) {
|
|
qInfo() << "Row found in MailCopy:";
|
|
qInfo() << " id:" << query2.value(0).toInt();
|
|
qInfo() << " folderId:" << query2.value(1).toInt();
|
|
qInfo() << " messageId:" << query2.value(2).toString();
|
|
qInfo() << " subject:" << query2.value(3).toString();
|
|
qInfo() << " sender:" << query2.value(4).toString();
|
|
qInfo() << " recipient:" << query2.value(5).toString();
|
|
qInfo() << " date:" << query2.value(6).toDateTime();
|
|
qInfo() << " read:" << query2.value(7).toBool();
|
|
qInfo() << " flagged:" << query2.value(8).toBool();
|
|
qInfo() << " hasAttachment:" << query2.value(9).toBool();
|
|
qInfo() << " size:" << query2.value(10).toLongLong();
|
|
qInfo() << " uid:" << query2.value(11).toLongLong();
|
|
qInfo() << " fileId:" << query2.value(12).toString();
|
|
qInfo() << " bodyHtml:" << query2.value(13).toString();
|
|
qInfo() << " toAddr:" << query2.value(14).toString();
|
|
qInfo() << " ccAddr:" << query2.value(15).toString();
|
|
qInfo() << " bccAddr:" << query2.value(16).toString();
|
|
} else {
|
|
qWarning() << "Failed to fetch row:" << query2.lastError().text();
|
|
}
|
|
|
|
// Retrieve by ID
|
|
auto opt = MailItemDao::findById(item.id());
|
|
if (!opt) {
|
|
qCritical() << "Failed to fetch inserted mail item";
|
|
return 1;
|
|
}
|
|
MailItem fetched = *opt;
|
|
qInfo() << "Fetched ID:" << fetched.id();
|
|
qInfo() << "Subject:" << fetched.subject();
|
|
qInfo() << "From:" << fetched.sender();
|
|
qInfo() << "To:" << fetched.to();
|
|
qInfo() << "CC:" << fetched.cc();
|
|
qInfo() << "BCC:" << fetched.bcc();
|
|
qInfo() << "Recipient column (recipient):" << fetched.recipient();
|
|
|
|
// Verify fields match
|
|
bool ok2 = (fetched.messageId() == item.messageId() &&
|
|
fetched.subject() == item.subject() &&
|
|
fixed.sender() == item.sender() &&
|
|
fetched.recipient() == item.recipient() &&
|
|
fetched.to() == item.to() &&
|
|
fetched.cc() == item.cc() &&
|
|
fetched.bcc() == item.bcc() &&
|
|
fetched.bodyHtml() == item.bodyHtml());
|
|
if (ok2) {
|
|
qInfo() << "All fields match!";
|
|
} else {
|
|
qCritical() << "Mismatch in fields";
|
|
return 1;
|
|
}
|
|
|
|
// Clean up (optional)
|
|
MailItemDao::remove(item.id());
|
|
FolderDao::remove(folder.id());
|
|
AccountDao::remove(account.id());
|
|
|
|
return 0;
|
|
} |