~osomon/oxide/i18n

« back to all changes in this revision

Viewing changes to qt/core/browser/oxide_qt_file_picker.cc

  • Committer: Olivier Tilloy
  • Date: 2014-04-08 10:03:11 UTC
  • mfrom: (312.2.173 oxide)
  • Revision ID: olivier.tilloy@canonical.com-20140408100311-b3zb7q1jfrevbrf1
Merge the latest changes from trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// vim:expandtab:shiftwidth=2:tabstop=2:
 
2
// Copyright (C) 2014 Canonical Ltd.
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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
 
17
 
 
18
#include "oxide_qt_file_picker.h"
 
19
 
 
20
#include <QFileInfo>
 
21
#include <QString>
 
22
#include <QStringList>
 
23
 
 
24
#include "base/strings/utf_string_conversions.h"
 
25
 
 
26
#include "qt/core/glue/oxide_qt_file_picker_delegate.h"
 
27
 
 
28
namespace oxide {
 
29
namespace qt {
 
30
 
 
31
FilePicker::FilePicker(FilePickerDelegate* delegate,
 
32
                       content::RenderViewHost* rvh) :
 
33
    oxide::FilePicker(rvh),
 
34
    delegate_(delegate) {
 
35
  delegate_->file_picker_ = this;
 
36
}
 
37
 
 
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;
 
48
  }
 
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));
 
55
  }
 
56
  delegate_->Show(mode, title, defaultFileName, acceptTypes);
 
57
}
 
58
 
 
59
void FilePicker::OnHide() {
 
60
  delegate_->Hide();
 
61
}
 
62
 
 
63
} // namespace qt
 
64
} // namespace oxide