blob: a88ea6e3152ee1b02d95345e961802bf19e74518 [file] [log] [blame]
Edric Milaret43f3c1e2015-07-16 17:52:47 -04001/***************************************************************************
Edric Milaretbab169d2016-01-07 15:13:33 -05002 * Copyright (C) 2015-2016 by Savoir-faire Linux *
Edric Milaret43f3c1e2015-07-16 17:52:47 -04003 * Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>*
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17 **************************************************************************/
18
Edric Milaret5f316da2015-09-28 11:57:42 -040019#pragma once
Edric Milaret43f3c1e2015-07-16 17:52:47 -040020
21#include <QDialog>
Edric Milaretbe0aa5a2015-07-31 15:08:39 -040022#include <QSortFilterProxyModel>
Edric Milaret43f3c1e2015-07-16 17:52:47 -040023
24#include "personmodel.h"
Edric Milaretbe0aa5a2015-07-31 15:08:39 -040025#include "contactmethod.h"
Edric Milaret43f3c1e2015-07-16 17:52:47 -040026
27namespace Ui {
28class ContactPicker;
29}
30
Edric Milaretbe0aa5a2015-07-31 15:08:39 -040031class OnlyPersonProxyModel : public QSortFilterProxyModel
32{
33public:
34 OnlyPersonProxyModel(QAbstractItemModel* parent) : QSortFilterProxyModel(parent)
35 {
36 setSourceModel(parent);
37 }
38 virtual bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
39 {
40 bool match = filterRegExp().indexIn(sourceModel()->index(source_row,0,source_parent).data(Qt::DisplayRole).toString()) != -1;
41 return match && !sourceModel()->index(source_row,0,source_parent).parent().isValid();
42 }
43};
44
Edric Milaret43f3c1e2015-07-16 17:52:47 -040045class ContactPicker : public QDialog
46{
47 Q_OBJECT
48
49public:
Edric Milaretbe0aa5a2015-07-31 15:08:39 -040050 explicit ContactPicker(ContactMethod* number, QWidget *parent = 0);
Edric Milaret43f3c1e2015-07-16 17:52:47 -040051 ~ContactPicker();
52
Edric Milaretbe0aa5a2015-07-31 15:08:39 -040053protected slots:
54 void accept();
Edric Milaret43f3c1e2015-07-16 17:52:47 -040055
56//UI SLOTS
57private slots:
58 void on_contactView_doubleClicked(const QModelIndex &index);
Edric Milaretbe0aa5a2015-07-31 15:08:39 -040059 void on_okButton_clicked();
60 void on_createNewButton_clicked();
61
62 void on_searchBar_textChanged(const QString &arg1);
Edric Milaret43f3c1e2015-07-16 17:52:47 -040063
64private:
65 Ui::ContactPicker *ui;
66 Person *personSelected_;
Edric Milaretbe0aa5a2015-07-31 15:08:39 -040067 ContactMethod* number_;
68 OnlyPersonProxyModel* contactProxyModel_;
Edric Milaret43f3c1e2015-07-16 17:52:47 -040069};