contactselectiondialog.cpp 3.05 KB
Newer Older
Laurent Montel's avatar
Laurent Montel committed
1
/*
Laurent Montel's avatar
Laurent Montel committed
2
3
  Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
  Copyright (c) 2015 Laurent Montel <montel@kde.org>
Laurent Montel's avatar
Laurent Montel committed
4

Laurent Montel's avatar
Laurent Montel committed
5
6
7
8
  This library is free software; you can redistribute it and/or modify it
  under the terms of the GNU Library General Public License as published by
  the Free Software Foundation; either version 2 of the License, or (at your
  option) any later version.
Laurent Montel's avatar
Laurent Montel committed
9

Laurent Montel's avatar
Laurent Montel committed
10
11
12
13
  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 Library General Public
  License for more details.
Laurent Montel's avatar
Laurent Montel committed
14

Laurent Montel's avatar
Laurent Montel committed
15
16
17
18
  You should have received a copy of the GNU Library General Public License
  along with this library; see the file COPYING.LIB.  If not, write to the
  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  02110-1301, USA.
Laurent Montel's avatar
Laurent Montel committed
19
20
21
22
*/

#include "contactselectiondialog.h"
#include "contactselectionwidget.h"
Laurent Montel's avatar
Laurent Montel committed
23
24

#include <QVBoxLayout>
Laurent Montel's avatar
Laurent Montel committed
25
26
#include <KLocalizedString>
#include <QDialogButtonBox>
Laurent Montel's avatar
Laurent Montel committed
27
#include <QPushButton>
Laurent Montel's avatar
Laurent Montel committed
28

Laurent Montel's avatar
Laurent Montel committed
29
30
31
32
ContactSelectionDialog::ContactSelectionDialog(QItemSelectionModel *selectionModel, bool allowToSelectTypeToExport,
        QWidget *parent)
    : QDialog(parent),
      mVCardExport(Q_NULLPTR)
Laurent Montel's avatar
Laurent Montel committed
33
{
Laurent Montel's avatar
Laurent Montel committed
34
35
36
    setWindowTitle(i18n("Select Contacts"));
    QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
    QWidget *mainWidget = new QWidget(this);
Laurent Montel's avatar
Laurent Montel committed
37
38
    QVBoxLayout *mainLayout = new QVBoxLayout;
    setLayout(mainLayout);
Laurent Montel's avatar
Laurent Montel committed
39
40
41
42
43
44
45
46
47
48
    mainLayout->addWidget(mainWidget);

    QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
    okButton->setDefault(true);
    okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
    connect(buttonBox, &QDialogButtonBox::accepted, this, &ContactSelectionDialog::accept);
    connect(buttonBox, &QDialogButtonBox::rejected, this, &ContactSelectionDialog::reject);

    mSelectionWidget = new ContactSelectionWidget(selectionModel, this);
    if (allowToSelectTypeToExport) {
Laurent Montel's avatar
Laurent Montel committed
49
        mainLayout->addWidget(mSelectionWidget);
Laurent Montel's avatar
Laurent Montel committed
50
        mVCardExport = new VCardExportSelectionWidget;
Laurent Montel's avatar
Laurent Montel committed
51
        mainLayout->addWidget(mVCardExport);
Laurent Montel's avatar
Laurent Montel committed
52
    } else {
Laurent Montel's avatar
Laurent Montel committed
53
        mainLayout->addWidget(mSelectionWidget);
Laurent Montel's avatar
Laurent Montel committed
54
55
    }
    mainLayout->addWidget(buttonBox);
Laurent Montel's avatar
Laurent Montel committed
56
57
}

Laurent Montel's avatar
Laurent Montel committed
58
void ContactSelectionDialog::setMessageText(const QString &message)
Laurent Montel's avatar
Laurent Montel committed
59
{
Laurent Montel's avatar
Laurent Montel committed
60
61
    mSelectionWidget->setMessageText(message);
}
Laurent Montel's avatar
Laurent Montel committed
62

Laurent Montel's avatar
Laurent Montel committed
63
64
65
void ContactSelectionDialog::setDefaultAddressBook(const Akonadi::Collection &addressBook)
{
    mSelectionWidget->setDefaultAddressBook(addressBook);
Laurent Montel's avatar
Laurent Montel committed
66
}
Laurent Montel's avatar
Laurent Montel committed
67

Laurent Montel's avatar
Laurent Montel committed
68
69
70
71
72
Akonadi::Item::List ContactSelectionDialog::selectedItems() const
{
    return mSelectionWidget->selectedItems();
}

Laurent Montel's avatar
Laurent Montel committed
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
ContactList ContactSelectionDialog::selectedContacts() const
{
    return mSelectionWidget->selectedContacts();
}

VCardExportSelectionWidget::ExportFields ContactSelectionDialog::exportType() const
{
    if (mVCardExport) {
        return mVCardExport->exportType();
    } else {
        return VCardExportSelectionWidget::None;
    }
}

void ContactSelectionDialog::setAddGroupContact(bool addGroupContact)
{
    mSelectionWidget->setAddGroupContact(addGroupContact);
}