Skip to content

Commit 1a4b2e8

Browse files
committed
Database: import file to database from json #53
1 parent 4eabbae commit 1a4b2e8

6 files changed

Lines changed: 34 additions & 3 deletions

File tree

App/Client/Favorite/FavoriteDatabase.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ bool CFavoriteDatabase::OnInitializeDatabase()
147147

148148
m_IconDB.SetDatabase(GetDatabase(), m_pPara);
149149
bRet = m_IconDB.OnInitializeDatabase();
150+
if(!bRet) return false;
151+
m_FileDB.SetDatabase(GetDatabase(), m_pPara);
152+
bRet = m_FileDB.OnInitializeDatabase();
150153
return bRet;
151154
}
152155

@@ -468,7 +471,7 @@ bool CFavoriteDatabase::ImportFromJson(int parentId, const QJsonArray &obj)
468471
}
469472

470473
QString szFile;
471-
bool bRet = CDatabaseFile::ImportFileFromJson(itemObj, szFile);
474+
bool bRet = m_FileDB.ImportFileToDatabaseFromJson(itemObj, szFile);
472475
if(!bRet) continue;
473476
QIcon icon;
474477
bRet = CDatabaseIcon::ImportIconFromJson(itemObj, icon);

App/Client/Favorite/FavoriteDatabase.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class CFavoriteDatabase : public CDatabaseTree
5757
bool OnInitializeSqliteDatabase() override;
5858
bool OnInitializeMySqlDatabase() override;
5959
CDatabaseIcon m_IconDB;
60+
CDatabaseFile m_FileDB;
6061

6162
// CDatabaseTree interface
6263
protected:

App/Client/Recent/RecentDatabase.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ bool CRecentDatabase::OnInitializeDatabase()
3636
// Create icon table
3737
m_IconDB.SetDatabase(GetDatabase(), m_pPara);
3838
bRet = m_IconDB.OnInitializeDatabase();
39+
if(!bRet) return bRet;
40+
m_FileDB.SetDatabase(GetDatabase(), m_pPara);
41+
bRet = m_FileDB.OnInitializeDatabase();
3942
return bRet;
4043
}
4144

@@ -343,7 +346,7 @@ bool CRecentDatabase::ImportFromJson(const QJsonObject &obj)
343346
QJsonObject itemObj = it->toObject();
344347
RecentItem item;
345348

346-
bool bRet = CDatabaseFile::ImportFileFromJson(itemObj, item.szFile);
349+
bool bRet = m_FileDB.ImportFileToDatabaseFromJson(itemObj, item.szFile);
347350
if(!bRet) continue;
348351

349352
// Check if is exist in recent

App/Client/Recent/RecentDatabase.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@ class CRecentDatabase : public CDatabase
4141
virtual bool ImportFromJson(const QJsonObject &obj) override;
4242

4343
CDatabaseIcon m_IconDB;
44+
CDatabaseFile m_FileDB;
4445
};
4546

Src/Database.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,14 @@ bool CDatabaseFile::ImportFileFromJson(const QJsonObject &obj, QString &szFile)
601601
return true;
602602
}
603603

604+
bool CDatabaseFile::ImportFileToDatabaseFromJson(const QJsonObject &obj, QString &szFile)
605+
{
606+
bool bRet = ImportFileFromJson(obj, szFile);
607+
if(!bRet) return bRet;
608+
bRet = Save(szFile);
609+
return bRet;
610+
}
611+
604612
CDatabaseFile::CDatabaseFile(QObject* parent) : CDatabase(parent)
605613
{
606614
m_szConnectName = "file_connect";

Src/Database.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ class PLUGIN_EXPORT CDatabaseIcon : public CDatabase
8686
QString m_szTableName;
8787
};
8888

89+
/*!
90+
* \brief The CDatabaseFile class
91+
* \note The file field is filename, don't include path.
92+
*/
8993
class PLUGIN_EXPORT CDatabaseFile : public CDatabase
9094
{
9195
Q_OBJECT
@@ -94,15 +98,26 @@ class PLUGIN_EXPORT CDatabaseFile : public CDatabase
9498
explicit CDatabaseFile(QObject* parent = nullptr);
9599
explicit CDatabaseFile(const QString& szPrefix, QObject *parent = nullptr);
96100

101+
/*!
102+
* \brief Load
103+
* \param szFile: the file path
104+
* \note The file field in database is filename, don't include path.
105+
*/
97106
QByteArray Load(const QString &szFile);
107+
/*!
108+
* \brief Save
109+
* \param szFile: the file path
110+
* \note The file field in database is filename, don't include path.
111+
*/
98112
bool Save(const QString& szFile);
99113

100114
virtual bool ExportToJson(QJsonObject &obj) override;
101115
virtual bool ImportFromJson(const QJsonObject &obj) override;
102116

103117
static bool ExportFileToJson(const QString &szFile, QJsonObject &obj);
104118
static bool ImportFileFromJson(const QJsonObject &obj, QString &szFile);
105-
119+
bool ImportFileToDatabaseFromJson(const QJsonObject &obj, QString &szFile);
120+
106121
protected:
107122
virtual bool OnInitializeSqliteDatabase() override;
108123
virtual bool OnInitializeMySqlDatabase() override;

0 commit comments

Comments
 (0)