selectfilespage.cpp 3.13 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*****************************************************************************
 * This file is part of the KDE project                                      *
 *                                                                           *
 * Copyright (C) 2010-2011 Alejandro Fiestas Olivares <afiestas@kde.org>     *
 * Copyright (C) 2010-2011 UFO Coders <info@ufocoders.com>                   *
 *                                                                           *
 * 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.          *
 *                                                                           *
 * 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.                          *
 *                                                                           *
 * 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.                                               *
 *****************************************************************************/
22
23
24
25

#include "selectfilespage.h"
#include "../sendfilewizard.h"

David Rosca's avatar
David Rosca committed
26
27
28
#include <KFileItem>
#include <KFileWidget>
#include <KDirOperator>
29
#include <KLocalizedString>
30

David Rosca's avatar
David Rosca committed
31
#include <QVBoxLayout>
David Rosca's avatar
David Rosca committed
32
#include <QStandardPaths>
33

34
35
#include <BluezQt/Device>

36
37
SelectFilesPage::SelectFilesPage(QWidget *parent)
    : QWizardPage(parent)
38
{
David Rosca's avatar
David Rosca committed
39
    m_files = new KFileWidget(QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)), this);
40
41
42
43
    m_files->setMode(KFile::Files);
    m_files->setContentsMargins(0, 0, 0, 0);
    setContentsMargins(0, 0, 0, 0);

44
    connect(m_files, &KFileWidget::selectionChanged, this, &SelectFilesPage::selectionChanged);
45
46
47

    QVBoxLayout *layout = new QVBoxLayout(this);
    layout->addWidget(m_files);
48
    layout->setContentsMargins(0, 0, 0, 0);
49
50
}

51
52
53
54
void SelectFilesPage::initializePage()
{
    SendFileWizard *w = static_cast<SendFileWizard*>(wizard());

55
56
57
58
    const QSize sizeHint = m_files->dialogSizeHint();
    if (sizeHint.isValid())
        w->resize(sizeHint);
    
59
60
61
    w->setWindowTitle(i18nc("Send files to a Bluetooth device", "Send to %1", w->device()->name()));
}

62
63
64
65
void SelectFilesPage::selectionChanged()
{
    QStringList fileList;
    KFileItemList itemList = m_files->dirOperator()->selectedItems();
66
67

    Q_FOREACH (const KFileItem &file, itemList) {
68
69
        fileList << file.localPath();
    }
70
71

    static_cast<SendFileWizard*>(wizard())->setFiles(fileList);
David Rosca's avatar
David Rosca committed
72
    Q_EMIT completeChanged();
73
74
75
76
77
}

bool SelectFilesPage::isComplete() const
{
    return !m_files->dirOperator()->selectedItems().isEmpty();
78
}