KDb

SqliteVacuum.h
1 /* This file is part of the KDE project
2  Copyright (C) 2006-2012 JarosÅ‚aw Staniek <[email protected]>
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 
30 class 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 */
45 class SqliteVacuum : public QObject, public KDbResultable
46 {
47  Q_OBJECT
48 public:
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 
57 public 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 
63 private:
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;
72 };
73 
74 #endif
Q_OBJECTQ_OBJECT
tristate run()
Q_SLOTSQ_SLOTS
Interface for classes providing a result.
3-state logical type with three values: true, false and cancelled and convenient operators.
Definition: KDbTristate.h:100
void readFromStdErr()
Helper class performing interactive compacting (VACUUM) of the SQLite database.
Definition: SqliteVacuum.h:45
Q_DISABLE_COPY(Class)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jun 25 2022 06:21:34 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.