File: personmanager_p.h

package info (click to toggle)
kpeople 5.54.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 844 kB
  • sloc: cpp: 4,006; sh: 16; makefile: 9
file content (92 lines) | stat: -rw-r--r-- 3,024 bytes parent folder | download
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
    Copyright (C) 2013  David Edmundson <davidedmundson@kde.org>
    Copyright 2013  Martin Klapetek <mklapetek@kde.org>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#ifndef PERSONMANAGER_H
#define PERSONMANAGER_H

#include <QObject>
#include <QStringList>
#include <QMultiHash>

#include <QSqlDatabase>
#include <QSqlQuery>

#include <kpeople/kpeople_export.h>

/**
 * This is a private internal class that manages all the internal mapping of contacts <---> persons
 * It stores the connection to the database as well as signals communicating with other clients
 *
 * It is a singleton.
 *
 */

class KPEOPLE_EXPORT PersonManager : public QObject
{
    Q_OBJECT

public:
    /**
     * Create or return a singleton instance of the PersonManager
     *
     * @databasePath the path to the database to be used.
     * If null the correct database is used.
     * This is for testing purposes only.
     */
    static PersonManager *instance(const QString &databasePath = QString());

//DATA RETRIEVAL------------

    /** Retuns a list of all known personIDs in the database*/
    QMultiHash< QString /*PersonUri*/, QString /*ContactUri*/> allPersons() const;

    /**
     * Returns the ID of a person associated with a given contact
     * If no person for that contact exists, an empty string is returned
     */
    QString personUriForContact(const QString &contactUri) const;

    /**
     * Returns a list of contactUris associated with a given person
     */
    QStringList contactsForPersonUri(const QString &personUri) const;

public Q_SLOTS:
    //merge all ids (person IDs and contactUris into a single person)
    //returns the ID that will be created
    //users should KPeople::mergeContacts from global.h
    QString mergeContacts(const QStringList &ids);

    //unmerge a contact. Either remove a contact from a given person or remove a person
    //users should KPeople::unmergeContact from global.h
    bool unmergeContact(const QString &id);

Q_SIGNALS:
    void contactRemovedFromPerson(const QString &contactUri);
    void contactAddedToPerson(const QString &contactUri, const QString &newPersonUri);

protected:
    explicit PersonManager(const QString &databasePath, QObject *parent = nullptr);
    virtual ~PersonManager();

private:
    QSqlDatabase m_db;
};

#endif // PERSONMANAGER_H