2 * This file is part of NixNote/NeighborNote
3 * Copyright 2009 Randy Baumgarte
4 * Copyright 2013 Yuki Takahashi
6 * This file may be licensed under the terms of of the
7 * GNU General Public License Version 2 (the ``GPL'').
9 * Software distributed under the License is distributed
10 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
11 * express or implied. See the GPL for the specific language
12 * governing rights and limitations.
14 * You should have received a copy of the GPL along with this
15 * program. If not, go to http://www.gnu.org/licenses/gpl.html
16 * or write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 package cx.fbn.nevernote.dialog;
23 //**********************************************
24 //**********************************************
25 //* This is the dialog that shows a user
26 //* the note's history from Evernote.
27 //**********************************************
28 //**********************************************
30 import java.text.SimpleDateFormat;
31 import java.util.ArrayList;
32 import java.util.List;
34 import com.evernote.edam.notestore.NoteVersionId;
35 import com.evernote.edam.type.Note;
36 import com.trolltech.qt.core.QTemporaryFile;
37 import com.trolltech.qt.core.Qt.ContextMenuPolicy;
38 import com.trolltech.qt.gui.QComboBox;
39 import com.trolltech.qt.gui.QDialog;
40 import com.trolltech.qt.gui.QHBoxLayout;
41 import com.trolltech.qt.gui.QIcon;
42 import com.trolltech.qt.gui.QLabel;
43 import com.trolltech.qt.gui.QPushButton;
44 import com.trolltech.qt.gui.QVBoxLayout;
46 import cx.fbn.nevernote.Global;
47 import cx.fbn.nevernote.gui.BrowserWindow;
48 import cx.fbn.nevernote.neighbornote.ClipBoardObserver;
49 import cx.fbn.nevernote.sql.DatabaseConnection;
50 import cx.fbn.nevernote.utilities.ApplicationLogger;
51 import cx.fbn.nevernote.xml.NoteFormatter;
53 public class OnlineNoteHistory extends QDialog {
54 public final QPushButton restoreAsNew;
55 public final QPushButton restore;
56 private final DatabaseConnection conn;
57 public final QComboBox historyCombo;
58 private final BrowserWindow browser;
59 private final ApplicationLogger logger;
60 List<QTemporaryFile> tempFiles;
61 private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
63 private final ClipBoardObserver cbObserver;
65 // ICHANGED 引数にcbObserver追加
67 public OnlineNoteHistory(ApplicationLogger l, DatabaseConnection c, ClipBoardObserver cbObserver) {
68 setWindowTitle(tr("Online Note History"));
69 setWindowIcon(new QIcon(iconPath+"notebook-green.png"));
70 QVBoxLayout main = new QVBoxLayout();
72 historyCombo = new QComboBox(this);
74 QHBoxLayout comboLayout = new QHBoxLayout();
75 comboLayout.addWidget(new QLabel(tr("History Date:")));
76 comboLayout.addWidget(historyCombo);
77 comboLayout.addStretch(100);
79 main.addLayout(comboLayout);
83 this.cbObserver = cbObserver;
84 browser = new BrowserWindow(conn, this.cbObserver);
86 main.addWidget(browser);
87 browser.titleLabel.setVisible(false);
88 browser.notebookBox.setVisible(false);
89 browser.hideButtons();
90 browser.tagEdit.setVisible(false);
91 browser.tagLabel.setVisible(false);
93 QHBoxLayout buttonLayout = new QHBoxLayout();
94 buttonLayout.addStretch(100);
95 restore = new QPushButton(tr("Restore Note"));
96 restore.clicked.connect(this, "restorePushed()");
98 restoreAsNew = new QPushButton(tr("Restore As New Note"));
99 restoreAsNew.clicked.connect(this, "restoreAsNewPushed()");
100 QPushButton cancel = new QPushButton(tr("Cancel"));
101 cancel.clicked.connect(this, "cancelPressed()");
103 buttonLayout.addWidget(restore);
104 buttonLayout.addWidget(restoreAsNew);
105 buttonLayout.addWidget(cancel);
106 main.addLayout(buttonLayout);
108 browser.getBrowser().setContextMenuPolicy(ContextMenuPolicy.NoContextMenu);
109 tempFiles = new ArrayList<QTemporaryFile>();
113 @SuppressWarnings("unused")
114 private void restoreAsNewPushed() {
117 @SuppressWarnings("unused")
118 private void restorePushed() {
121 @SuppressWarnings("unused")
122 private void cancelPressed() {
126 public void setCurrent(boolean isDirty) {
128 historyCombo.addItem(new String(tr("Current (Non Synchronized)")));
130 historyCombo.addItem(new String(tr("Current (Synchronized)")));
134 public void load(List<NoteVersionId> versions) {
135 String fmt = Global.getDateFormat() + " " + Global.getTimeFormat();
136 String dateTimeFormat = new String(fmt);
137 SimpleDateFormat simple = new SimpleDateFormat(dateTimeFormat);
139 for (int i=0; i<versions.size(); i++) {
140 StringBuilder versionDate = new StringBuilder(simple.format(versions.get(i).getSaved()));
141 historyCombo.addItem(versionDate.toString());
145 public void setContent(Note currentNote) {
148 NoteFormatter formatter = new NoteFormatter(logger, conn, tempFiles);
149 formatter.setNote(currentNote, false);
150 formatter.setHighlight(null);
151 formatter.setNoteHistory(true);
153 StringBuffer js = new StringBuffer();
155 // We need to prepend the note with <HEAD></HEAD> or encoded characters are ugly
156 js.append("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
157 js.append("<style type=\"text/css\">en-crypt-temp { border-style:solid; border-color:blue; padding:1mm 1mm 1mm 1mm; }</style>");
158 js.append("</head>");
159 js.append(formatter.rebuildNoteHTML());
160 js.append("</HTML>");
162 browser.setNote(currentNote);
163 browser.getBrowser().page().mainFrame().setHtml(js.toString());