Skip to content

Commit 68ad76c

Browse files
committed
App: fix save to database display bug
1 parent ef30692 commit 68ad76c

12 files changed

Lines changed: 97 additions & 8 deletions

File tree

App/Client/ParameterApp.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
#include "ParameterApp.h"
1+
22
#include <QSettings>
33
#include <QDir>
44
#include "RabbitCommonDir.h"
55
#ifdef HAVE_ICE
66
#include "Ice.h"
77
#endif
8+
#include "ParameterGlobal.h"
9+
#include "ParameterApp.h"
810

911
CParameterApp::CParameterApp(QObject *parent) : CParameter(parent, "MainWindow"),
10-
m_Database(this),
12+
m_pGloablParamter(nullptr),
1113
m_bReceiveShortCut(false),
1214
m_bSaveMainWindowStatus(true),
1315
m_ViewType(ViewType::Tab),
@@ -172,6 +174,16 @@ int CParameterApp::OnSave(QSettings &set)
172174
return 0;
173175
}
174176

177+
CParameterGlobal* CParameterApp::GetGlobalParameters() const
178+
{
179+
return m_pGloablParamter;
180+
}
181+
182+
void CParameterApp::SetGlobalParameters(CParameterGlobal* para)
183+
{
184+
m_pGloablParamter = para;
185+
}
186+
175187
bool CParameterApp::GetReceiveShortCut() const
176188
{
177189
return m_bReceiveShortCut;

App/Client/ParameterApp.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "Parameter.h"
66
#include "ParameterDatabase.h"
77

8+
class CParameterGlobal;
89
class CParameterApp : public CParameter
910
{
1011
Q_OBJECT
@@ -14,6 +15,11 @@ class CParameterApp : public CParameter
1415
virtual ~CParameterApp();
1516

1617
CParameterDatabase m_Database;
18+
CParameterGlobal* GetGlobalParameters() const;
19+
20+
private:
21+
Q_INVOKABLE void SetGlobalParameters(CParameterGlobal* pGlobal);
22+
CParameterGlobal* m_pGloablParamter;
1723

1824
protected:
1925
virtual int OnLoad(QSettings &set);

App/Client/Recent/RecentDatabase.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,11 @@ QList<CRecentDatabase::RecentItem> CRecentDatabase::GetRecents(int limit, int of
336336
return items;
337337
}
338338

339+
bool CRecentDatabase::HasFileContents(const RecentItem &item)
340+
{
341+
return m_FileDB.IsExist(item.szFile);
342+
}
343+
339344
bool CRecentDatabase::ExportToJson(QJsonObject &obj)
340345
{
341346
QJsonArray recents;

App/Client/Recent/RecentDatabase.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class CRecentDatabase : public CDatabase
3838
bool UpdateRecent(const RecentItem &item);
3939
QList<RecentItem> GetRecents(int limit = -1, int offset = 0);
4040

41+
bool HasFileContents(const RecentItem &item);
42+
4143
private:
4244
bool OnInitializeDatabase() override;
4345
virtual bool OnInitializeSqliteDatabase() override;

App/Client/Recent/RecentModel.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <QLoggingCategory>
55
#include "RecentModel.h"
66
#include "ParameterApp.h"
7+
#include "ParameterGlobal.h"
78

89
static Q_LOGGING_CATEGORY(log, "App.Recent.Model")
910
CRecentModel::CRecentModel(CParameterApp *pPara, CRecentDatabase *pDb, QObject *parent)
@@ -23,8 +24,21 @@ Qt::ItemFlags CRecentModel::flags(const QModelIndex &index) const
2324
return f;
2425

2526
auto item = m_Items.at(index.row());
26-
QFileInfo fi(item.GetFile());
27-
if(fi.exists())
27+
QString szFile = item.GetFile();
28+
if(szFile.isEmpty()) {
29+
return f;
30+
}
31+
32+
bool bExist = false;
33+
QFileInfo fi(szFile);
34+
if(m_pParameterApp->GetGlobalParameters()->GetSaveSettingsType()
35+
== CParameterGlobal::SaveSettingsType::File) {
36+
bExist = fi.exists();
37+
} else {
38+
bExist = m_pDatabase->HasFileContents(item);
39+
}
40+
41+
if(bExist)
2842
f |= Qt::ItemIsEnabled;
2943
else
3044
f &= ~Qt::ItemIsEnabled;

App/Client/mainwindow.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,21 @@ int MainWindow::Initial()
424424
}
425425
m_Manager.EnumPlugins(this);
426426

427-
if(m_Manager.GetGlobalParameters())
427+
if(m_Manager.GetGlobalParameters()) {
428+
//m_Parameter.SetGlobalParameters(m_Manager.GetGlobalParameters());
429+
bool bRet = QMetaObject::invokeMethod(
430+
&m_Parameter,
431+
"SetGlobalParameters",
432+
Qt::DirectConnection,
433+
Q_ARG(CParameterGlobal*, m_Manager.GetGlobalParameters()));
434+
if(!bRet) {
435+
szErr = tr("Failed to set global parameters");
436+
qCritical(log) << szErr;
437+
nRet = -1;
438+
break;
439+
}
428440
m_Parameter.m_Database = m_Manager.GetGlobalParameters()->m_Database;
441+
}
429442

430443
if(m_pRecent) {
431444
szMsg = tr("Load list recent dock ......");
@@ -450,6 +463,18 @@ int MainWindow::Initial()
450463
for(auto it = recents.rbegin(); it != recents.rend(); it++) {
451464
m_pRecentMenu->addRecentFile(it->GetFile(), it->szName, it->icon);
452465
}
466+
m_pRecentMenu->slotShowFileEixst(
467+
m_Parameter.GetGlobalParameters()->GetSaveSettingsType() == CParameterGlobal::File);
468+
bool check = connect(
469+
m_Parameter.GetGlobalParameters(),
470+
&CParameterGlobal::sigSaveSettingsTypeChanged,
471+
m_pRecentMenu, [this]() {
472+
if(!(m_pRecentMenu && m_Parameter.GetGlobalParameters()))
473+
return;
474+
m_pRecentMenu->slotShowFileEixst(
475+
m_Parameter.GetGlobalParameters()->GetSaveSettingsType() == CParameterGlobal::File);
476+
});
477+
Q_ASSERT(check);
453478
}
454479
}
455480

Plugins/WebBrowser/Bookmark/BookmarkDatabase.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,13 @@ CBookmarkDatabase::~CBookmarkDatabase()
5959

6060
bool CBookmarkDatabase::OnInitializeDatabase()
6161
{
62+
bool bRet = false;
6263
m_UrlDB.SetDatabase(GetDatabase(), m_pPara);
63-
m_UrlDB.OnInitializeDatabase();
64+
bRet = m_UrlDB.OnInitializeDatabase();
65+
if(!bRet) return false;
6466
m_TreeDB.SetDatabase(GetDatabase(), m_pPara);
65-
m_TreeDB.OnInitializeDatabase();
67+
bRet = m_TreeDB.OnInitializeDatabase();
68+
if(!bRet) return false;
6669

6770
if(m_TreeDB.GetNodeCount() == 0) {
6871
m_TreeDB.AddNode(tr("Bookmarks"), 0);

Plugins/WebBrowser/History/HistoryDatabase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ bool CHistoryDatabase::OnInitializeDatabase()
7474
success = CDatabase::OnInitializeDatabase();
7575
if(!success) return false;
7676
m_UrlDB.SetDatabase(GetDatabase(), m_pPara);
77-
m_UrlDB.OnInitializeDatabase();
77+
success = m_UrlDB.OnInitializeDatabase();
7878
return success;
7979
}
8080

Src/Database/Database.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,3 +803,20 @@ bool CDatabaseFile::OnInitializeMySqlDatabase()
803803

804804
return true;
805805
}
806+
807+
bool CDatabaseFile::IsExist(const QString &szFile)
808+
{
809+
QSqlQuery query(GetDatabase());
810+
query.prepare("SELECT * from " + m_szTableName +
811+
" WHERE `file`=:file");
812+
query.bindValue(":file", szFile);
813+
bool ok = query.exec();
814+
if(!ok) {
815+
qCritical(log) << "Failed to the file:" << szFile << " is exist in"
816+
<< m_szTableName << "table:"
817+
<< m_szTableName << query.lastError().text()
818+
<< "Sql:" << query.executedQuery();
819+
return false;
820+
}
821+
return query.next();
822+
}

Src/Database/Database.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ class PLUGIN_EXPORT CDatabaseFile : public CDatabase
128128
public:
129129
explicit CDatabaseFile(QObject* parent = nullptr);
130130
explicit CDatabaseFile(const QString& szPrefix, QObject *parent = nullptr);
131+
132+
bool IsExist(const QString& szFile);
131133

132134
/*!
133135
* \brief Load

0 commit comments

Comments
 (0)