Skip to content

Commit

Permalink
Fix last commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
tnodir committed Oct 1, 2019
1 parent 2d5157e commit a0848e3
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 30 deletions.
41 changes: 27 additions & 14 deletions src/ui/3rdparty/sqlite/sqlitedb.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "sqlitedb.h"

#include <QDataStream>
#include <QDateTime>
#include <QBuffer>
#include <QDebug>
#include <QDir>
Expand Down Expand Up @@ -79,7 +80,7 @@ QVariant SqliteDb::executeEx(const char *sql,
for (const QVariant &v : vars) {
++index;

const int vType = v.type();
const qint16 vType = v.type();

switch (vType) {
case QVariant::Invalid:
Expand Down Expand Up @@ -116,23 +117,28 @@ QVariant SqliteDb::executeEx(const char *sql,

// Write content
{
QByteArray bufData;

QBuffer buf(&bufData);
buf.open(QIODevice::WriteOnly);

switch (vType) {
case QVariant::DateTime: {
const qint64 msecs = v.toDateTime().toMSecsSinceEpoch();
stream << msecs;
break;
}
case QVariant::Image: {
QByteArray bufData;

QBuffer buf(&bufData);
buf.open(QIODevice::WriteOnly);

const QImage image = v.value<QImage>();
image.save(&buf, "PNG");

buf.close();
stream << bufData;
break;
}
default:
Q_UNREACHABLE();
}

buf.close();
stream << bufData;
}

const char *bits = data.constData();
Expand Down Expand Up @@ -175,16 +181,22 @@ QVariant SqliteDb::executeEx(const char *sql,
QDataStream stream(data);

// Load type
int vType;
qint16 vType;
stream >> vType;

// Load content
{
QByteArray bufData;
stream >> bufData;

switch (vType) {
case QVariant::DateTime: {
qint64 msecs;
stream >> msecs;
v = QDateTime::fromMSecsSinceEpoch(msecs);
break;
}
case QVariant::Image: {
QByteArray bufData;
stream >> bufData;

QImage image;
image.loadFromData(bufData, "PNG");
v = image;
Expand Down Expand Up @@ -289,7 +301,7 @@ bool SqliteDb::migrate(const QString &sqlDir, int version,
void *migrateContext)
{
// Check version
const int userVersion = this->userVersion();
int userVersion = this->userVersion();
if (userVersion == version)
return true;

Expand All @@ -306,6 +318,7 @@ bool SqliteDb::migrate(const QString &sqlDir, int version,
qWarning() << "SQLite: Cannot re-create the DB" << m_filePath;
return false;
}
userVersion = 0;
}

// Run migration SQL scripts
Expand Down
2 changes: 1 addition & 1 deletion src/ui/util/app/appinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ QString AppInfo::iconPath() const

bool AppInfo::isFileModified(const QString &appPath) const
{
return !fileModTime.isNull()
return fileModTime != 0
&& fileModTime != AppUtil::getModTime(appPath);
}
4 changes: 1 addition & 3 deletions src/ui/util/app/appinfo.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef APPINFO_H
#define APPINFO_H

#include <QDateTime>
#include <QObject>

class AppInfo
Expand All @@ -20,13 +19,12 @@ class AppInfo

public:
qint64 iconId = 0;
qint64 fileModTime = 0;

QString fileDescription;
QString companyName;
QString productName;
QString productVersion;

QDateTime fileModTime;
};

Q_DECLARE_METATYPE(AppInfo)
Expand Down
15 changes: 7 additions & 8 deletions src/ui/util/app/appinfomanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ namespace {

const char * const sqlSelectAppInfo =
"SELECT file_descr, company_name,"
" product_name, product_ver, icon_id,"
" file_mod_time"
" product_name, product_ver, file_mod_time, icon_id"
" FROM app WHERE path = ?1;"
;

Expand Down Expand Up @@ -53,8 +52,8 @@ const char * const sqlUpdateIconRefCount =

const char * const sqlInsertAppInfo =
"INSERT INTO app(path, file_descr, company_name,"
" product_name, product_ver, icon_id,"
" file_mod_time, access_time)"
" product_name, product_ver, file_mod_time,"
" icon_id, access_time)"
" VALUES(?1, ?2, ?3, ?4, ?5, ?6, ?7, datetime('now'));"
;

Expand Down Expand Up @@ -157,7 +156,7 @@ bool AppInfoManager::loadInfoFromDb(const QString &appPath, AppInfo &appInfo)
const QVariantList vars = QVariantList() << appPath;

// Load version info
const int resultCount = 5;
const int resultCount = 6;
const QVariantList list = m_sqliteDb->executeEx(
sqlSelectAppInfo, vars, resultCount)
.toList();
Expand All @@ -168,8 +167,8 @@ bool AppInfoManager::loadInfoFromDb(const QString &appPath, AppInfo &appInfo)
appInfo.companyName = list.at(1).toString();
appInfo.productName = list.at(2).toString();
appInfo.productVersion = list.at(3).toString();
appInfo.iconId = list.at(4).toLongLong();
appInfo.fileModTime = list.at(5).toDateTime();
appInfo.fileModTime = list.at(4).toLongLong();
appInfo.iconId = list.at(5).toLongLong();

// Update last access time
m_sqliteDb->executeEx(sqlUpdateAppAccessTime, vars);
Expand Down Expand Up @@ -226,8 +225,8 @@ bool AppInfoManager::saveToDb(const QString &appPath, AppInfo &appInfo,
<< appInfo.companyName
<< appInfo.productName
<< appInfo.productVersion
<< iconId
<< appInfo.fileModTime
<< iconId
;

m_sqliteDb->executeEx(sqlInsertAppInfo, vars, 0, &ok);
Expand Down
5 changes: 3 additions & 2 deletions src/ui/util/app/apputil.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "apputil.h"

#include <QDateTime>
#include <QDir>
#include <QPixmap>

Expand Down Expand Up @@ -157,8 +158,8 @@ QImage AppUtil::getIcon(const QString &appPath)
.toImage();
}

QDateTime AppUtil::getModTime(const QString &appPath)
qint64 AppUtil::getModTime(const QString &appPath)
{
QFileInfo fi(appPath);
return fi.lastModified();
return fi.lastModified().toMSecsSinceEpoch();
}
2 changes: 1 addition & 1 deletion src/ui/util/app/apputil.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AppUtil
public:
static bool getInfo(const QString &appPath, AppInfo &appInfo);
static QImage getIcon(const QString &appPath);
static QDateTime getModTime(const QString &appPath);
static qint64 getModTime(const QString &appPath);
};

#endif // APPUTIL_H
2 changes: 1 addition & 1 deletion src/ui/util/app/migrations/1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ CREATE TABLE app(
company_name TEXT,
product_name TEXT,
product_ver TEXT,
file_mod_time INTEGER,
icon_id INTEGER,
file_mod_time DATETIME,
access_time DATETIME
) WITHOUT ROWID;

Expand Down

0 comments on commit a0848e3

Please sign in to comment.