OSDN Git Service

- Added the ability to do special refreshes for debugging. - Added the ability to...
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / dialog / OnlineNoteHistory.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.dialog;\r
21 \r
22 //**********************************************\r
23 //**********************************************\r
24 //* This is the dialog that shows a user\r
25 //* the note's history from Evernote.\r
26 //**********************************************\r
27 //**********************************************\r
28 \r
29 import java.text.SimpleDateFormat;\r
30 import java.util.ArrayList;\r
31 import java.util.List;\r
32 \r
33 import com.evernote.edam.notestore.NoteVersionId;\r
34 import com.evernote.edam.type.Note;\r
35 import com.trolltech.qt.core.QTemporaryFile;\r
36 import com.trolltech.qt.core.Qt.ContextMenuPolicy;\r
37 import com.trolltech.qt.gui.QComboBox;\r
38 import com.trolltech.qt.gui.QDialog;\r
39 import com.trolltech.qt.gui.QHBoxLayout;\r
40 import com.trolltech.qt.gui.QIcon;\r
41 import com.trolltech.qt.gui.QLabel;\r
42 import com.trolltech.qt.gui.QPushButton;\r
43 import com.trolltech.qt.gui.QVBoxLayout;\r
44 \r
45 import cx.fbn.nevernote.Global;\r
46 import cx.fbn.nevernote.gui.BrowserWindow;\r
47 import cx.fbn.nevernote.sql.DatabaseConnection;\r
48 import cx.fbn.nevernote.utilities.ApplicationLogger;\r
49 import cx.fbn.nevernote.xml.NoteFormatter;\r
50 \r
51 public class OnlineNoteHistory extends QDialog {\r
52         public final QPushButton        restoreAsNew;\r
53         public final QPushButton        restore;\r
54         private final DatabaseConnection  conn;\r
55         public final QComboBox          historyCombo;    \r
56         private final BrowserWindow     browser;\r
57         private final ApplicationLogger logger;\r
58         List<QTemporaryFile>    tempFiles;\r
59         private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
60         \r
61         // Constructor\r
62         public OnlineNoteHistory(ApplicationLogger l, DatabaseConnection c) {\r
63                 setWindowTitle(tr("Online Note History"));\r
64                 setWindowIcon(new QIcon(iconPath+"notebook-green.png"));\r
65                 QVBoxLayout main = new QVBoxLayout();\r
66                 setLayout(main);\r
67                 historyCombo = new QComboBox(this);\r
68                 \r
69                 QHBoxLayout comboLayout = new QHBoxLayout();\r
70                 comboLayout.addWidget(new QLabel(tr("History Date:")));\r
71                 comboLayout.addWidget(historyCombo);\r
72                 comboLayout.addStretch(100);\r
73                 \r
74                 main.addLayout(comboLayout);\r
75                                 \r
76                 conn = c;\r
77                 browser = new BrowserWindow(conn);\r
78                 main.addWidget(browser);\r
79                 browser.titleLabel.setVisible(false);\r
80                 browser.notebookBox.setVisible(false);\r
81                 browser.hideButtons();\r
82                 browser.tagEdit.setVisible(false);\r
83                 browser.tagLabel.setVisible(false);\r
84                 \r
85                 QHBoxLayout buttonLayout = new QHBoxLayout();\r
86                 buttonLayout.addStretch(100);\r
87                 restore = new QPushButton(tr("Restore Note"));\r
88                 restore.clicked.connect(this, "restorePushed()");\r
89                 \r
90                 restoreAsNew = new QPushButton(tr("Restore As New Note"));\r
91                 restoreAsNew.clicked.connect(this, "restoreAsNewPushed()");\r
92                 QPushButton cancel = new QPushButton(tr("Cancel"));\r
93                 cancel.clicked.connect(this, "cancelPressed()");\r
94                 \r
95                 buttonLayout.addWidget(restore);\r
96                 buttonLayout.addWidget(restoreAsNew);\r
97                 buttonLayout.addWidget(cancel);\r
98                 main.addLayout(buttonLayout);\r
99                 \r
100                 browser.getBrowser().setContextMenuPolicy(ContextMenuPolicy.NoContextMenu);\r
101                 tempFiles = new ArrayList<QTemporaryFile>();\r
102                 logger = l;\r
103         }\r
104         \r
105         @SuppressWarnings("unused")\r
106         private void restoreAsNewPushed() {\r
107                 this.close();\r
108         }\r
109         @SuppressWarnings("unused")\r
110         private void restorePushed() {\r
111                 this.close();\r
112         }\r
113         @SuppressWarnings("unused")\r
114         private void cancelPressed() {\r
115                 this.close();\r
116         }\r
117         \r
118         public void setCurrent(boolean isDirty) {\r
119                 if (isDirty) \r
120                         historyCombo.addItem(new String(tr("Current (Non Synchronized)")));\r
121                 else\r
122                         historyCombo.addItem(new String(tr("Current (Synchronized)")));\r
123                                 \r
124         }\r
125         \r
126         public void load(List<NoteVersionId> versions) {\r
127                 String fmt = Global.getDateFormat() + " " + Global.getTimeFormat();\r
128                 String dateTimeFormat = new String(fmt);\r
129                 SimpleDateFormat simple = new SimpleDateFormat(dateTimeFormat);\r
130                 \r
131                 for (int i=0; i<versions.size(); i++) {\r
132                         StringBuilder versionDate = new StringBuilder(simple.format(versions.get(i).getSaved()));\r
133                         historyCombo.addItem(versionDate.toString());\r
134                 }\r
135         }\r
136         \r
137         public void setContent(Note currentNote) {\r
138                 \r
139                 \r
140                 NoteFormatter formatter = new NoteFormatter(logger, conn, tempFiles);\r
141                 formatter.setNote(currentNote, false);\r
142                 formatter.setHighlight(null);\r
143                 formatter.setNoteHistory(true);\r
144                 \r
145                 StringBuffer js = new StringBuffer();\r
146                 \r
147                 // We need to prepend the note with <HEAD></HEAD> or encoded characters are ugly \r
148                 js.append("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">");       \r
149                 js.append("<style type=\"text/css\">en-crypt-temp { border-style:solid; border-color:blue; padding:1mm 1mm 1mm 1mm; }</style>");\r
150                 js.append("</head>");\r
151                 js.append(formatter.rebuildNoteHTML());\r
152                 js.append("</HTML>");\r
153                 \r
154                 browser.setNote(currentNote);\r
155                 browser.getBrowser().page().mainFrame().setHtml(js.toString());\r
156         }\r
157 }\r
158  \r
159 \r
160 \r
161         \r
162         \r
163         \r
164         \r
165 \r