KDb

SqliteVacuum.h
1/* This file is part of the KDE project
2 Copyright (C) 2006-2012 Jarosław Staniek <staniek@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#ifndef KDB_SQLITEVACUUM_H
21#define KDB_SQLITEVACUUM_H
22
23#include <QObject>
24#include <QString>
25#include <QProcess>
26
27#include "KDbTristate.h"
28#include "KDbResult.h"
29
30class QProgressDialog;
31
32//! @short Helper class performing interactive compacting (VACUUM) of the SQLite database
33/*! Proved SQLite database filename in the constructor.
34 Then execute run() should be executed.
35
36 QProgressDialog will be displayed. Its progress bar will be updated whenever another
37 table's data compacting is performed. User can click "Cancel" button in any time
38 (except the final committing) to cancel the operation. In this case,
39 it's guaranteed that the original file remains unchanged.
40
41 This is possible because we rely on SQLite's VACUUM SQL command, which itself temporarily
42 creates a copy of the original database file, and replaces the orginal with the new only
43 on success.
44*/
45class SqliteVacuum : public QObject, public KDbResultable
46{
48public:
49 explicit SqliteVacuum(const QString& filePath);
50 ~SqliteVacuum() override;
51
52 /*! Performs compacting procedure.
53 @return true on success, false on failure and cancelled if user
54 clicked "Cancel" button in the progress dialog. */
55 tristate run();
56
57public Q_SLOTS:
58 void readFromStdErr();
59 void dumpProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
60 void sqliteProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
61 void cancelClicked();
62
63private:
64 QString m_filePath;
65 QString m_tmpFilePath;
66 QProcess *m_dumpProcess;
67 QProcess *m_sqliteProcess;
68 QProgressDialog* m_dlg; // krazy:exclude=qclasses
69 int m_percent;
70 bool m_canceled;
71 Q_DISABLE_COPY(SqliteVacuum)
72};
73
74#endif
Interface for classes providing a result.
Helper class performing interactive compacting (VACUUM) of the SQLite database.
tristate run()
void readFromStdErr()
3-state logical type with three values: true, false and cancelled and convenient operators.
Q_OBJECTQ_OBJECT
Q_SLOTSQ_SLOTS
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:00:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.