OSDN Git Service

Cleanup compiler warning messages and alter backup & restore to handle new database...
[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.util.List;\r
23 \r
24 import com.trolltech.qt.core.Qt.WidgetAttribute;\r
25 import com.trolltech.qt.gui.QCloseEvent;\r
26 import com.trolltech.qt.gui.QMdiSubWindow;\r
27 \r
28 import cx.fbn.nevernote.Global;\r
29 import cx.fbn.nevernote.sql.DatabaseConnection;\r
30 \r
31 public class ExternalBrowse extends QMdiSubWindow {\r
32         private final DatabaseConnection  conn;\r
33         private final BrowserWindow     browser;\r
34         public Signal4<String, String, Boolean, BrowserWindow> contentsChanged;\r
35         public Signal1<String>  windowClosing;\r
36         boolean noteDirty;\r
37         \r
38         // Constructor\r
39         public ExternalBrowse(DatabaseConnection c) {\r
40                 setAttribute(WidgetAttribute.WA_QuitOnClose, false);\r
41                 setWindowTitle(tr("NeverNote"));\r
42                 conn = c;\r
43                 contentsChanged = new Signal4<String, String, Boolean, BrowserWindow>();\r
44                 windowClosing = new Signal1<String>();\r
45                 browser = new BrowserWindow(conn);\r
46                 setWidget(browser);\r
47                 noteDirty = false;\r
48                 browser.titleLabel.textChanged.connect(this, "titleChanged(String)");\r
49                 browser.getBrowser().page().contentsChanged.connect(this, "contentChanged()");\r
50         }\r
51         \r
52         @SuppressWarnings("unused")\r
53         private void contentChanged() {\r
54                 noteDirty = true;\r
55                 contentsChanged.emit(getBrowserWindow().getNote().getGuid(), getBrowserWindow().getContent(), false, getBrowserWindow());\r
56         }\r
57 \r
58         \r
59         @Override\r
60         public void closeEvent(QCloseEvent event) {\r
61                 if (noteDirty) \r
62                         contentsChanged.emit(getBrowserWindow().getNote().getGuid(), getBrowserWindow().getContent(), true, getBrowserWindow());\r
63                 windowClosing.emit(getBrowserWindow().getNote().getGuid());\r
64         }\r
65         \r
66     public BrowserWindow getBrowserWindow() {\r
67         return browser;\r
68     }\r
69     \r
70     @SuppressWarnings("unused")\r
71         private void titleChanged(String value) {\r
72         setWindowTitle(tr("NeverNote - ") +value);\r
73     }\r
74     \r
75         @SuppressWarnings("unused")\r
76         private void updateTitle(String guid, String title) {\r
77                 if (guid.equals(getBrowserWindow().getNote().getGuid())) {\r
78                         getBrowserWindow().loadingData(true);\r
79                         getBrowserWindow().setTitle(title);\r
80                         getBrowserWindow().getNote().setTitle(title);\r
81                         getBrowserWindow().loadingData(false);\r
82                 }\r
83         }\r
84         @SuppressWarnings("unused")\r
85         private void updateNotebook(String guid, String notebook) {\r
86                 if (guid.equals(getBrowserWindow().getNote().getGuid())) {\r
87                         getBrowserWindow().loadingData(true);\r
88                         getBrowserWindow().setNotebook(notebook);\r
89                         getBrowserWindow().loadingData(false);\r
90                 }\r
91         }\r
92         \r
93         @SuppressWarnings("unused")\r
94         private void updateTags(String guid, List<String> tags) {\r
95                 if (guid.equals(getBrowserWindow().getNote().getGuid())) {\r
96                         StringBuffer tagLine = new StringBuffer(100);\r
97                         for (int i=0; i<tags.size(); i++) {\r
98                                 if (i>0)\r
99                                         tagLine.append(Global.tagDelimeter+" ");\r
100                                 tagLine.append(tags.get(i));\r
101                                 \r
102                         }\r
103                         getBrowserWindow().loadingData(true);\r
104                         getBrowserWindow().getTagLine().setText(tagLine.toString());\r
105                         getBrowserWindow().loadingData(false);\r
106                 }\r
107         }\r
108 \r
109 }\r