OSDN Git Service

クリーンアップ
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / gui / TabBrowse.java
1 /*
2  * This file is part of NeighborNote
3  * Copyright 2013 Yuki Takahashi
4  * 
5  * This file may be licensed under the terms of of the
6  * GNU General Public License Version 2 (the ``GPL'').
7  *
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.
12  *
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.
17  *
18 */
19
20 package cx.fbn.nevernote.gui;
21
22 import java.awt.Desktop;
23
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;
31
32 import cx.fbn.nevernote.clipboard.ClipBoardObserver;
33 import cx.fbn.nevernote.dialog.FindDialog;
34 import cx.fbn.nevernote.sql.DatabaseConnection;
35
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;
41         String saveTitle;
42         private final FindDialog find; // Text search in note dialog
43         private final TabBrowserWidget parent;
44         private final ClipBoardObserver cbObserver;
45
46         // コンストラクタ
47         public TabBrowse(DatabaseConnection c, TabBrowserWidget p, ClipBoardObserver cbObserver) {
48                 conn = c;
49                 parent = p;
50                 this.cbObserver = cbObserver;
51                 contentsChanged = new Signal4<String, String, Boolean, BrowserWindow>();
52                 browser = new BrowserWindow(conn, this.cbObserver);
53                 QVBoxLayout v = new QVBoxLayout();
54                 v.addWidget(browser);
55                 setLayout(v);
56                 noteDirty = false;
57                 browser.titleLabel.textChanged.connect(this, "titleChanged(String)");
58                 browser.getBrowser().page().contentsChanged.connect(this,
59                                 "contentChanged()");
60                 find = new FindDialog();
61                 find.getOkButton().clicked.connect(this, "doFindText()");
62         }
63
64         @SuppressWarnings("unused")
65         private void contentChanged() {
66                 noteDirty = true;
67                 contentsChanged.emit(getBrowserWindow().getNote().getGuid(),
68                                 getBrowserWindow().getContent(), false, getBrowserWindow());
69         }
70
71         public BrowserWindow getBrowserWindow() {
72                 return browser;
73         }
74
75         
76         @SuppressWarnings("unused")
77         private void titleChanged(String value) {
78                 int index = parent.indexOf(this);
79                 if(index >= 0){
80                         parent.setTabTitle(index, value);
81                 }
82         }
83
84         @SuppressWarnings("unused")
85         private void findText() {
86                 find.show();
87                 find.setFocusOnTextField();
88         }
89
90         @SuppressWarnings("unused")
91         private void doFindText() {
92                 browser.getBrowser().page().findText(find.getText(), find.getFlags());
93                 find.setFocus();
94         }
95
96         @SuppressWarnings("unused")
97         private void printNote() {
98
99                 QPrintDialog dialog = new QPrintDialog();
100                 if (dialog.exec() == QDialog.DialogCode.Accepted.value()) {
101                         QPrinter printer = dialog.printer();
102                         browser.getBrowser().print(printer);
103                 }
104         }
105
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();
111
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);
117                 }
118         }
119
120         // noteDirtyの値を返す
121         public boolean getNoteDirty() {
122                 return noteDirty;
123         }
124 }