forked from gyunaev/birdtray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
databaseaccounts.cpp
69 lines (54 loc) · 1.56 KB
/
databaseaccounts.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <QDir>
#include "databaseaccounts.h"
#include "sqlite_statement.h"
#include "sqlite3.h"
DatabaseAccounts::DatabaseAccounts( const QString& databasePath )
{
moveToThread( this );
mDbPath = databasePath;
}
const QList<DatabaseAccounts::Account> &DatabaseAccounts::accounts() const
{
return mAccounts;
}
void DatabaseAccounts::run()
{
// Query the accounts and post the events
queryAccounts();
// Post the quit event
this->quit();
// Run the event loop
exec();
}
void DatabaseAccounts::queryAccounts()
{
// Open the database
sqlite3 * sqlitedb;
if ( sqlite3_open_v2( mDbPath.toUtf8().data(),
&sqlitedb,
SQLITE_OPEN_READONLY, 0 ) != SQLITE_OK )
{
emit done(tr("Error opening sqlite database: %1").arg(sqlite3_errmsg(sqlitedb)));
return;
}
SQLiteStatement stmt;
if ( !stmt.prepare( sqlitedb, "SELECT id,folderURI FROM folderlocations") )
{
emit done(tr("Cannot access the database. If you're using Thunderbird 68+, "
"this method no longer works. Please use the Mork parser."));
return;
}
int res;
while ( (res = stmt.step()) != SQLITE_DONE )
{
Account acc;
// Get the ID and data
acc.id = stmt.columnInt64( 0 );
acc.uri = stmt.columnText( 1 );
mAccounts.push_back( acc );
}
emit done ( "" );
}
const QString DatabaseAccounts::getDatabasePath(const QString &directory) {
return QDir(directory).filePath("global-messages-db.sqlite");
}