OSDN Git Service

コピーライトの表示を修正。
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / dialog / OnlineNoteHistory.java
1 /*
2  * This file is part of NixNote/NeighborNote 
3  * Copyright 2009 Randy Baumgarte
4  * Copyright 2013 Yuki Takahashi
5  * 
6  * This file may be licensed under the terms of of the
7  * GNU General Public License Version 2 (the ``GPL'').
8  *
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.
13  *
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.
18  *
19 */
20
21 package cx.fbn.nevernote.dialog;
22
23 //**********************************************
24 //**********************************************
25 //* This is the dialog that shows a user
26 //* the note's history from Evernote.
27 //**********************************************
28 //**********************************************
29
30 import java.text.SimpleDateFormat;
31 import java.util.ArrayList;
32 import java.util.List;
33
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;
45
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;
52
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/");
62         // ICHANGED
63         private final ClipBoardObserver cbObserver;
64
65         // ICHANGED 引数にcbObserver追加
66         // Constructor
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();
71                 setLayout(main);
72                 historyCombo = new QComboBox(this);
73                 
74                 QHBoxLayout comboLayout = new QHBoxLayout();
75                 comboLayout.addWidget(new QLabel(tr("History Date:")));
76                 comboLayout.addWidget(historyCombo);
77                 comboLayout.addStretch(100);
78                 
79                 main.addLayout(comboLayout);
80                                 
81                 conn = c;
82                 // ICHANGED
83                 this.cbObserver = cbObserver;
84                 browser = new BrowserWindow(conn, this.cbObserver);
85                 
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);
92                 
93                 QHBoxLayout buttonLayout = new QHBoxLayout();
94                 buttonLayout.addStretch(100);
95                 restore = new QPushButton(tr("Restore Note"));
96                 restore.clicked.connect(this, "restorePushed()");
97                 
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()");
102                 
103                 buttonLayout.addWidget(restore);
104                 buttonLayout.addWidget(restoreAsNew);
105                 buttonLayout.addWidget(cancel);
106                 main.addLayout(buttonLayout);
107                 
108                 browser.getBrowser().setContextMenuPolicy(ContextMenuPolicy.NoContextMenu);
109                 tempFiles = new ArrayList<QTemporaryFile>();
110                 logger = l;
111         }
112         
113         @SuppressWarnings("unused")
114         private void restoreAsNewPushed() {
115                 this.close();
116         }
117         @SuppressWarnings("unused")
118         private void restorePushed() {
119                 this.close();
120         }
121         @SuppressWarnings("unused")
122         private void cancelPressed() {
123                 this.close();
124         }
125         
126         public void setCurrent(boolean isDirty) {
127                 if (isDirty) 
128                         historyCombo.addItem(new String(tr("Current (Non Synchronized)")));
129                 else
130                         historyCombo.addItem(new String(tr("Current (Synchronized)")));
131                                 
132         }
133         
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);
138                 
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());
142                 }
143         }
144         
145         public void setContent(Note currentNote) {
146                 
147                 
148                 NoteFormatter formatter = new NoteFormatter(logger, conn, tempFiles);
149                 formatter.setNote(currentNote, false);
150                 formatter.setHighlight(null);
151                 formatter.setNoteHistory(true);
152                 
153                 StringBuffer js = new StringBuffer();
154                 
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>");
161                 
162                 browser.setNote(currentNote);
163                 browser.getBrowser().page().mainFrame().setHtml(js.toString());
164         }
165 }
166  
167
168
169         
170         
171         
172         
173