1
// vim:expandtab:shiftwidth=2:tabstop=2:
2
// Copyright (C) 2014 Canonical Ltd.
4
// This library is free software; you can redistribute it and/or
5
// modify it under the terms of the GNU Lesser General Public
6
// License as published by the Free Software Foundation; either
7
// version 2.1 of the License, or (at your option) any later version.
9
// This library is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
// Lesser General Public License for more details.
14
// You should have received a copy of the GNU Lesser General Public
15
// License along with this library; if not, write to the Free Software
16
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
#include "oxide_qt_file_picker.h"
22
#include <QStringList>
24
#include "base/strings/utf_string_conversions.h"
26
#include "qt/core/glue/oxide_qt_file_picker_delegate.h"
31
FilePicker::FilePicker(FilePickerDelegate* delegate,
32
content::RenderViewHost* rvh) :
33
oxide::FilePicker(rvh),
35
delegate_->file_picker_ = this;
38
void FilePicker::Run(const content::FileChooserParams& params) {
39
FilePickerDelegate::Mode mode;
40
if (params.mode == content::FileChooserParams::Open) {
41
mode = FilePickerDelegate::Open;
42
} else if (params.mode == content::FileChooserParams::OpenMultiple) {
43
mode = FilePickerDelegate::OpenMultiple;
44
} else if (params.mode == content::FileChooserParams::UploadFolder) {
45
mode = FilePickerDelegate::UploadFolder;
46
} else if (params.mode == content::FileChooserParams::Save) {
47
mode = FilePickerDelegate::Save;
49
QString title = QString::fromStdString(base::UTF16ToUTF8(params.title));
50
QFileInfo defaultFileName(QString::fromStdString(params.default_file_name.value()));
51
QStringList acceptTypes;
52
std::vector<base::string16>::const_iterator i;
53
for (i = params.accept_types.begin(); i != params.accept_types.end(); ++i) {
54
acceptTypes << QString::fromStdString(base::UTF16ToUTF8(*i));
56
delegate_->Show(mode, title, defaultFileName, acceptTypes);
59
void FilePicker::OnHide() {