Database defragmentation feature added, this fixed #1.
This commit is contained in:
parent
23682726d2
commit
b16d14e175
BIN
resources/graphics/icons/mini-kfaenza/defragment-database.png
Normal file
BIN
resources/graphics/icons/mini-kfaenza/defragment-database.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.6 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 2.5 KiB |
@ -221,6 +221,7 @@ QSqlDatabase DatabaseFactory::initializeFileBasedDatabase(const QString &connect
|
|||||||
return database;
|
return database;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QSqlDatabase DatabaseFactory::connection(const QString &connection_name,
|
QSqlDatabase DatabaseFactory::connection(const QString &connection_name,
|
||||||
DesiredType desired_type) {
|
DesiredType desired_type) {
|
||||||
if (desired_type == DatabaseFactory::StrictlyInMemory ||
|
if (desired_type == DatabaseFactory::StrictlyInMemory ||
|
||||||
@ -331,3 +332,10 @@ void DatabaseFactory::determineInMemoryDatabase() {
|
|||||||
qDebug("Working database source was determined as %s.",
|
qDebug("Working database source was determined as %s.",
|
||||||
m_inMemoryEnabled ? "in-memory database" : "file-based database");
|
m_inMemoryEnabled ? "in-memory database" : "file-based database");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DatabaseFactory::vacuumDatabase() {
|
||||||
|
QSqlDatabase database = connection(objectName(), FromSettings);
|
||||||
|
QSqlQuery query_vacuum(database);
|
||||||
|
|
||||||
|
return query_vacuum.exec("VACUUM");
|
||||||
|
}
|
||||||
|
@ -41,6 +41,16 @@ class DatabaseFactory : public QObject {
|
|||||||
// Sets m_inMemoryEnabled according to user settings.
|
// Sets m_inMemoryEnabled according to user settings.
|
||||||
void determineInMemoryDatabase();
|
void determineInMemoryDatabase();
|
||||||
|
|
||||||
|
// Performs "VACUUM" on the database and
|
||||||
|
// returns true of operation succeeded.
|
||||||
|
bool vacuumDatabase();
|
||||||
|
|
||||||
|
// Returns whether in-memory database feature is currently
|
||||||
|
// used.
|
||||||
|
inline bool usingInMemoryDatabase() const {
|
||||||
|
return m_inMemoryEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
// Singleton getter.
|
// Singleton getter.
|
||||||
static DatabaseFactory *instance();
|
static DatabaseFactory *instance();
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "gui/feedmessageviewer.h"
|
#include "gui/feedmessageviewer.h"
|
||||||
|
|
||||||
#include "core/settings.h"
|
#include "core/settings.h"
|
||||||
|
#include "core/databasefactory.h"
|
||||||
#include "core/messagesproxymodel.h"
|
#include "core/messagesproxymodel.h"
|
||||||
#include "core/feeddownloader.h"
|
#include "core/feeddownloader.h"
|
||||||
#include "core/feedsmodelstandardfeed.h"
|
#include "core/feedsmodelstandardfeed.h"
|
||||||
@ -216,6 +217,8 @@ void FeedMessageViewer::createConnections() {
|
|||||||
SIGNAL(triggered()), m_feedsView, SLOT(openSelectedFeedsInNewspaperMode()));
|
SIGNAL(triggered()), m_feedsView, SLOT(openSelectedFeedsInNewspaperMode()));
|
||||||
connect(form_main->m_ui->m_actionDeleteSelectedFeedCategory,
|
connect(form_main->m_ui->m_actionDeleteSelectedFeedCategory,
|
||||||
SIGNAL(triggered()), m_feedsView, SLOT(deleteSelectedItem()));
|
SIGNAL(triggered()), m_feedsView, SLOT(deleteSelectedItem()));
|
||||||
|
connect(form_main->m_ui->m_actionDefragmentDatabase,
|
||||||
|
SIGNAL(triggered()), this, SLOT(vacuumDatabase()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeedMessageViewer::initialize() {
|
void FeedMessageViewer::initialize() {
|
||||||
@ -279,3 +282,57 @@ void FeedMessageViewer::initializeViews() {
|
|||||||
// Set layout as active.
|
// Set layout as active.
|
||||||
setLayout(central_layout);
|
setLayout(central_layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FeedMessageViewer::vacuumDatabase() {
|
||||||
|
bool is_tray_activated = SystemTrayIcon::isSystemTrayActivated();
|
||||||
|
|
||||||
|
if (!SystemFactory::instance()->applicationCloseLock()->tryLock()) {
|
||||||
|
// Lock was not obtained because
|
||||||
|
// it is used probably by feed updater or application
|
||||||
|
// is quitting.
|
||||||
|
if (is_tray_activated) {
|
||||||
|
SystemTrayIcon::instance()->showMessage(tr("Cannot defragment database"),
|
||||||
|
tr("Database cannot be defragmented because feed update is ongoing."),
|
||||||
|
QSystemTrayIcon::Warning);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
MessageBox::show(this,
|
||||||
|
QMessageBox::Warning,
|
||||||
|
tr("Cannot defragment database"),
|
||||||
|
tr("Database cannot be defragmented because feed update is ongoing."));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Thus, cannot delete and quit the method.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DatabaseFactory::instance()->vacuumDatabase()) {
|
||||||
|
if (is_tray_activated) {
|
||||||
|
SystemTrayIcon::instance()->showMessage(tr("Database defragmented"),
|
||||||
|
tr("Database was successfully defragmented."),
|
||||||
|
QSystemTrayIcon::Information);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
MessageBox::show(this,
|
||||||
|
QMessageBox::Information,
|
||||||
|
tr("Database defragmented"),
|
||||||
|
tr("Database was successfully defragmented."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (is_tray_activated) {
|
||||||
|
SystemTrayIcon::instance()->showMessage(tr("Database was not defragmented"),
|
||||||
|
tr("Database was not defragmented, try again later."),
|
||||||
|
QSystemTrayIcon::Warning);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
MessageBox::show(this,
|
||||||
|
QMessageBox::Warning,
|
||||||
|
tr("Database was not defragmented"),
|
||||||
|
tr("Database was not defragmented, try again later."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SystemFactory::instance()->applicationCloseLock()->unlock();
|
||||||
|
}
|
||||||
|
@ -43,6 +43,9 @@ class FeedMessageViewer : public TabContent {
|
|||||||
// stops any child widgets/workers.
|
// stops any child widgets/workers.
|
||||||
void quit();
|
void quit();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void vacuumDatabase();
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
// Updates counts of messages for example in tray icon.
|
// Updates counts of messages for example in tray icon.
|
||||||
void updateTrayIconStatus(int unread_messages, int total_messages);
|
void updateTrayIconStatus(int unread_messages, int total_messages);
|
||||||
|
@ -224,6 +224,7 @@ void FormMain::setupIcons() {
|
|||||||
m_ui->m_actionExport->setIcon(icon_theme_factory->fromTheme("document-export"));
|
m_ui->m_actionExport->setIcon(icon_theme_factory->fromTheme("document-export"));
|
||||||
m_ui->m_actionFullscreen->setIcon(icon_theme_factory->fromTheme("view-fullscreen"));
|
m_ui->m_actionFullscreen->setIcon(icon_theme_factory->fromTheme("view-fullscreen"));
|
||||||
m_ui->m_actionSwitchMainWindow->setIcon(icon_theme_factory->fromTheme("view-switch"));
|
m_ui->m_actionSwitchMainWindow->setIcon(icon_theme_factory->fromTheme("view-switch"));
|
||||||
|
m_ui->m_actionDefragmentDatabase->setIcon(icon_theme_factory->fromTheme("defragment-database"));
|
||||||
|
|
||||||
// Web browser.
|
// Web browser.
|
||||||
m_ui->m_actionAddBrowser->setIcon(icon_theme_factory->fromTheme("list-add"));
|
m_ui->m_actionAddBrowser->setIcon(icon_theme_factory->fromTheme("list-add"));
|
||||||
|
@ -74,6 +74,8 @@
|
|||||||
<string>&Tools</string>
|
<string>&Tools</string>
|
||||||
</property>
|
</property>
|
||||||
<addaction name="m_actionSettings"/>
|
<addaction name="m_actionSettings"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
|
<addaction name="m_actionDefragmentDatabase"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenu" name="m_menuWebBrowser">
|
<widget class="QMenu" name="m_menuWebBrowser">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
@ -447,6 +449,14 @@
|
|||||||
<string notr="true"/>
|
<string notr="true"/>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="m_actionDefragmentDatabase">
|
||||||
|
<property name="text">
|
||||||
|
<string>Defragment database</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Defragment database file so that its size decreases.</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user