OSDN Git Service

Cleanup unneded variables in ExternalBrowse.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / gui / ExternalBrowse.java
1 /*\r
2  * This file is part of NeverNote \r
3  * Copyright 2009 Randy Baumgarte\r
4  * \r
5  * This file may be licensed under the terms of of the\r
6  * GNU General Public License Version 2 (the ``GPL'').\r
7  *\r
8  * Software distributed under the License is distributed\r
9  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either\r
10  * express or implied. See the GPL for the specific language\r
11  * governing rights and limitations.\r
12  *\r
13  * You should have received a copy of the GPL along with this\r
14  * program. If not, go to http://www.gnu.org/licenses/gpl.html\r
15  * or write to the Free Software Foundation, Inc.,\r
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
17  *\r
18 */\r
19 \r
20 package cx.fbn.nevernote.gui;\r
21 \r
22 import java.awt.Desktop;\r
23 import java.util.List;\r
24 \r
25 import com.trolltech.qt.core.QUrl;\r
26 import com.trolltech.qt.core.Qt.WidgetAttribute;\r
27 import com.trolltech.qt.gui.QCloseEvent;\r
28 import com.trolltech.qt.gui.QDesktopServices;\r
29 import com.trolltech.qt.gui.QDialog;\r
30 import com.trolltech.qt.gui.QMdiSubWindow;\r
31 import com.trolltech.qt.gui.QPrintDialog;\r
32 import com.trolltech.qt.gui.QPrinter;\r
33 \r
34 import cx.fbn.nevernote.Global;\r
35 import cx.fbn.nevernote.dialog.FindDialog;\r
36 import cx.fbn.nevernote.sql.DatabaseConnection;\r
37 \r
38 public class ExternalBrowse extends QMdiSubWindow {\r
39         private final DatabaseConnection  conn;\r
40         private final BrowserWindow     browser;\r
41         public Signal4<String, String, Boolean, BrowserWindow> contentsChanged;\r
42         public Signal1<String>  windowClosing;\r
43         boolean noteDirty;\r
44         private final FindDialog        find;                                           // Text search in note dialog\r
45 //      ExternalBrowserMenuBar          menu;\r
46         ExternalBrowserMenuBar  menu;\r
47         \r
48         // Constructor\r
49         public ExternalBrowse(DatabaseConnection c) {\r
50                 setAttribute(WidgetAttribute.WA_QuitOnClose, false);\r
51                 setWindowTitle(tr("NeverNote"));\r
52                 conn = c;\r
53                 contentsChanged = new Signal4<String, String, Boolean, BrowserWindow>();\r
54                 windowClosing = new Signal1<String>();\r
55                 browser = new BrowserWindow(conn);\r
56                 menu = new ExternalBrowserMenuBar(this);\r
57                 for (int i=0; i<menu.actions().size(); i++) {\r
58                         addAction(menu.actions().get(i));\r
59                 }\r
60                 \r
61                 setWidget(browser);\r
62                 noteDirty = false;\r
63                 browser.titleLabel.textChanged.connect(this, "titleChanged(String)");\r
64                 browser.getBrowser().page().contentsChanged.connect(this, "contentChanged()");\r
65                 find = new FindDialog();\r
66                 find.getOkButton().clicked.connect(this, "doFindText()");\r
67         }\r
68         \r
69         @SuppressWarnings("unused")\r
70         private void contentChanged() {\r
71                 noteDirty = true;\r
72                 contentsChanged.emit(getBrowserWindow().getNote().getGuid(), getBrowserWindow().getContent(), false, getBrowserWindow());\r
73         }\r
74 \r
75         \r
76         @Override\r
77         public void closeEvent(QCloseEvent event) {\r
78                 if (noteDirty) \r
79                         contentsChanged.emit(getBrowserWindow().getNote().getGuid(), getBrowserWindow().getContent(), true, getBrowserWindow());\r
80                 windowClosing.emit(getBrowserWindow().getNote().getGuid());\r
81         }\r
82         \r
83     public BrowserWindow getBrowserWindow() {\r
84         return browser;\r
85     }\r
86     \r
87     @SuppressWarnings("unused")\r
88         private void titleChanged(String value) {\r
89         setWindowTitle(tr("NeverNote - ") +value);\r
90     }\r
91     \r
92         @SuppressWarnings("unused")\r
93         private void updateTitle(String guid, String title) {\r
94                 if (guid.equals(getBrowserWindow().getNote().getGuid())) {\r
95                         getBrowserWindow().loadingData(true);\r
96                         getBrowserWindow().setTitle(title);\r
97                         getBrowserWindow().getNote().setTitle(title);\r
98                         getBrowserWindow().loadingData(false);\r
99                 }\r
100         }\r
101         @SuppressWarnings("unused")\r
102         private void updateNotebook(String guid, String notebook) {\r
103                 if (guid.equals(getBrowserWindow().getNote().getGuid())) {\r
104                         getBrowserWindow().loadingData(true);\r
105                         getBrowserWindow().setNotebook(notebook);\r
106                         getBrowserWindow().loadingData(false);\r
107                 }\r
108         }\r
109         \r
110         @SuppressWarnings("unused")\r
111         private void updateTags(String guid, List<String> tags) {\r
112                 if (guid.equals(getBrowserWindow().getNote().getGuid())) {\r
113                         StringBuffer tagLine = new StringBuffer(100);\r
114                         for (int i=0; i<tags.size(); i++) {\r
115                                 if (i>0)\r
116                                         tagLine.append(Global.tagDelimeter+" ");\r
117                                 tagLine.append(tags.get(i));\r
118                                 \r
119                         }\r
120                         getBrowserWindow().loadingData(true);\r
121                         getBrowserWindow().getTagLine().setText(tagLine.toString());\r
122                         getBrowserWindow().loadingData(false);\r
123                 }\r
124         }\r
125 \r
126         \r
127     @SuppressWarnings("unused")\r
128         private void findText() {\r
129         find.show();\r
130         find.setFocusOnTextField();\r
131     }\r
132     @SuppressWarnings("unused")\r
133         private void doFindText() {\r
134         browser.getBrowser().page().findText(find.getText(), find.getFlags());\r
135         find.setFocus();\r
136     }\r
137 \r
138         \r
139     @SuppressWarnings("unused")\r
140         private void printNote() {\r
141 \r
142         QPrintDialog dialog = new QPrintDialog();\r
143         if (dialog.exec() == QDialog.DialogCode.Accepted.value()) {\r
144                 QPrinter printer = dialog.printer();\r
145                 browser.getBrowser().print(printer);\r
146         }\r
147     }\r
148     \r
149     // Listener triggered when the email button is pressed\r
150     @SuppressWarnings("unused")\r
151         private void emailNote() {\r
152         if (Desktop.isDesktopSupported()) {\r
153             Desktop desktop = Desktop.getDesktop();\r
154             \r
155             String text2 = browser.getContentsToEmail();\r
156             QUrl url = new QUrl("mailto:");\r
157             url.addQueryItem("subject", browser.getTitle());\r
158             url.addQueryItem("body", text2);\r
159             QDesktopServices.openUrl(url);\r
160         }\r
161     }\r
162 }\r