2 * This file is part of NeighborNote
3 * Copyright 2013 Yuki Takahashi
5 * This file may be licensed under the terms of of the
6 * GNU General Public License Version 2 (the ``GPL'').
8 * Software distributed under the License is distributed
9 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
10 * express or implied. See the GPL for the specific language
11 * governing rights and limitations.
13 * You should have received a copy of the GPL along with this
14 * program. If not, go to http://www.gnu.org/licenses/gpl.html
15 * or write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package cx.fbn.nevernote.gui;
22 import java.awt.Desktop;
24 import com.trolltech.qt.core.QUrl;
25 import com.trolltech.qt.gui.QDesktopServices;
26 import com.trolltech.qt.gui.QDialog;
27 import com.trolltech.qt.gui.QPrintDialog;
28 import com.trolltech.qt.gui.QPrinter;
29 import com.trolltech.qt.gui.QVBoxLayout;
30 import com.trolltech.qt.gui.QWidget;
32 import cx.fbn.nevernote.clipboard.ClipBoardObserver;
33 import cx.fbn.nevernote.dialog.FindDialog;
34 import cx.fbn.nevernote.sql.DatabaseConnection;
36 public class TabBrowse extends QWidget {
37 private final DatabaseConnection conn;
38 private final BrowserWindow browser;
39 public Signal4<String, String, Boolean, BrowserWindow> contentsChanged;
40 private boolean noteDirty;
42 private final FindDialog find; // Text search in note dialog
43 private final TabBrowserWidget parent;
44 private final ClipBoardObserver cbObserver;
47 public TabBrowse(DatabaseConnection c, TabBrowserWidget p, ClipBoardObserver cbObserver) {
50 this.cbObserver = cbObserver;
51 contentsChanged = new Signal4<String, String, Boolean, BrowserWindow>();
52 browser = new BrowserWindow(conn, this.cbObserver);
53 QVBoxLayout v = new QVBoxLayout();
57 browser.titleLabel.textChanged.connect(this, "titleChanged(String)");
58 browser.getBrowser().page().contentsChanged.connect(this,
60 find = new FindDialog();
61 find.getOkButton().clicked.connect(this, "doFindText()");
64 @SuppressWarnings("unused")
65 private void contentChanged() {
67 contentsChanged.emit(getBrowserWindow().getNote().getGuid(),
68 getBrowserWindow().getContent(), false, getBrowserWindow());
71 public BrowserWindow getBrowserWindow() {
76 @SuppressWarnings("unused")
77 private void titleChanged(String value) {
78 int index = parent.indexOf(this);
80 parent.setTabTitle(index, value);
84 @SuppressWarnings("unused")
85 private void findText() {
87 find.setFocusOnTextField();
90 @SuppressWarnings("unused")
91 private void doFindText() {
92 browser.getBrowser().page().findText(find.getText(), find.getFlags());
96 @SuppressWarnings("unused")
97 private void printNote() {
99 QPrintDialog dialog = new QPrintDialog();
100 if (dialog.exec() == QDialog.DialogCode.Accepted.value()) {
101 QPrinter printer = dialog.printer();
102 browser.getBrowser().print(printer);
106 // Listener triggered when the email button is pressed
107 @SuppressWarnings("unused")
108 private void emailNote() {
109 if (Desktop.isDesktopSupported()) {
110 Desktop desktop = Desktop.getDesktop();
112 String text2 = browser.getContentsToEmail();
113 QUrl url = new QUrl("mailto:");
114 url.addQueryItem("subject", browser.getTitle());
115 url.addQueryItem("body", text2);
116 QDesktopServices.openUrl(url);
121 public boolean getNoteDirty() {