~abreu-alexandre/oxide/add-ua-to-downloadrequested

« back to all changes in this revision

Viewing changes to qt/quick/oxide_qquick_prompt_dialog.cc

Clean up the interfaces in qt/core/glue. Hopefully this will make it more obvious where to place new code (ie, only interfaces in qt/core/glue now)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// vim:expandtab:shiftwidth=2:tabstop=2:
2
 
// Copyright (C) 2013-2014 Canonical Ltd.
 
2
// Copyright (C) 2013-2015 Canonical Ltd.
3
3
 
4
4
// This library is free software; you can redistribute it and/or
5
5
// modify it under the terms of the GNU Lesser General Public
15
15
// License along with this library; if not, write to the Free Software
16
16
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17
17
 
18
 
#include "oxide_qquick_prompt_dialog_delegate.h"
 
18
#include "oxide_qquick_prompt_dialog.h"
19
19
 
20
20
#include <QObject>
21
21
#include <QString>
22
22
 
 
23
#include "qt/core/glue/oxide_qt_javascript_dialog_proxy_client.h"
23
24
#include "qt/quick/api/oxideqquickwebview_p.h"
24
25
 
25
26
namespace oxide {
33
34
 
34
35
 public:
35
36
  virtual ~PromptDialogContext() {}
36
 
  PromptDialogContext(PromptDialogDelegate* delegate);
 
37
  PromptDialogContext(oxide::qt::JavaScriptDialogProxyClient* client);
37
38
 
38
39
  QString message() const;
39
40
  QString defaultValue() const;
48
49
  void reject() const;
49
50
 
50
51
 private:
51
 
  PromptDialogDelegate* delegate_;
 
52
  oxide::qt::JavaScriptDialogProxyClient* client_;
52
53
  QString currentValue_;
53
54
};
54
55
 
55
 
PromptDialogContext::PromptDialogContext(PromptDialogDelegate* delegate) :
56
 
    delegate_(delegate) {}
 
56
PromptDialogContext::PromptDialogContext(
 
57
    oxide::qt::JavaScriptDialogProxyClient* client)
 
58
    : client_(client) {}
57
59
 
58
60
QString PromptDialogContext::message() const {
59
 
  return delegate_->messageText();
 
61
  return client_->messageText();
60
62
}
61
63
 
62
64
QString PromptDialogContext::defaultValue() const {
63
 
  return delegate_->defaultPromptText();
 
65
  return client_->defaultPromptText();
64
66
}
65
67
 
66
68
const QString& PromptDialogContext::currentValue() const {
75
77
}
76
78
 
77
79
void PromptDialogContext::accept(const QString& value) const {
78
 
  delegate_->Close(true, value);
 
80
  client_->close(true, value);
79
81
}
80
82
 
81
83
void PromptDialogContext::reject() const {
82
 
  delegate_->Close(false);
83
 
}
84
 
 
85
 
PromptDialogDelegate::PromptDialogDelegate(OxideQQuickWebView* webview) :
86
 
    JavaScriptDialogDelegate(webview) {}
87
 
 
88
 
bool PromptDialogDelegate::Show() {
89
 
  return show(new PromptDialogContext(this), web_view_->promptDialog());
90
 
}
91
 
 
92
 
void PromptDialogDelegate::Handle(bool accept, const QString& prompt_override) {
 
84
  client_->close(false);
 
85
}
 
86
 
 
87
bool PromptDialog::Show() {
 
88
  if (!view_) {
 
89
    qWarning() << "PromptDialog::Show: Can't show after the view has gone";
 
90
    return false;
 
91
  }
 
92
 
 
93
  return run(new PromptDialogContext(client_), view_->promptDialog());
 
94
}
 
95
 
 
96
void PromptDialog::Handle(bool accept, const QString& prompt_override) {
93
97
  PromptDialogContext* contextObject =
94
98
    qobject_cast<PromptDialogContext*>(context_->contextObject());
95
99
  if (accept) {
103
107
  }
104
108
}
105
109
 
 
110
PromptDialog::PromptDialog(OxideQQuickWebView* view,
 
111
                           oxide::qt::JavaScriptDialogProxyClient* client)
 
112
    : JavaScriptDialog(view, client) {}
 
113
 
106
114
} // namespace qquick
107
115
} // namespace oxide
108
116
 
109
 
#include "oxide_qquick_prompt_dialog_delegate.moc"
 
117
#include "oxide_qquick_prompt_dialog.moc"