2 * This file is part of NeverNote
\r
3 * Copyright 2009 Randy Baumgarte
\r
5 * This file may be licensed under the terms of of the
\r
6 * GNU General Public License Version 2 (the ``GPL'').
\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
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
20 package cx.fbn.nevernote.gui;
\r
22 import java.io.File;
\r
23 import java.net.FileNameMap;
\r
24 import java.net.URI;
\r
25 import java.net.URLConnection;
\r
26 import java.security.MessageDigest;
\r
27 import java.security.NoSuchAlgorithmException;
\r
28 import java.text.SimpleDateFormat;
\r
29 import java.util.ArrayList;
\r
30 import java.util.Calendar;
\r
31 import java.util.Date;
\r
32 import java.util.GregorianCalendar;
\r
33 import java.util.HashMap;
\r
34 import java.util.List;
\r
36 import com.evernote.edam.limits.Constants;
\r
37 import com.evernote.edam.type.Data;
\r
38 import com.evernote.edam.type.Note;
\r
39 import com.evernote.edam.type.Notebook;
\r
40 import com.evernote.edam.type.Resource;
\r
41 import com.evernote.edam.type.ResourceAttributes;
\r
42 import com.evernote.edam.type.Tag;
\r
43 import com.trolltech.qt.core.QByteArray;
\r
44 import com.trolltech.qt.core.QDataStream;
\r
45 import com.trolltech.qt.core.QDateTime;
\r
46 import com.trolltech.qt.core.QEvent;
\r
47 import com.trolltech.qt.core.QFile;
\r
48 import com.trolltech.qt.core.QFileSystemWatcher;
\r
49 import com.trolltech.qt.core.QIODevice;
\r
50 import com.trolltech.qt.core.QMimeData;
\r
51 import com.trolltech.qt.core.QUrl;
\r
52 import com.trolltech.qt.gui.QApplication;
\r
53 import com.trolltech.qt.gui.QCalendarWidget;
\r
54 import com.trolltech.qt.gui.QClipboard;
\r
55 import com.trolltech.qt.gui.QColor;
\r
56 import com.trolltech.qt.gui.QComboBox;
\r
57 import com.trolltech.qt.gui.QDateEdit;
\r
58 import com.trolltech.qt.gui.QDesktopServices;
\r
59 import com.trolltech.qt.gui.QFileDialog;
\r
60 import com.trolltech.qt.gui.QFileDialog.AcceptMode;
\r
61 import com.trolltech.qt.gui.QFileDialog.FileMode;
\r
62 import com.trolltech.qt.gui.QFontDatabase;
\r
63 import com.trolltech.qt.gui.QFormLayout;
\r
64 import com.trolltech.qt.gui.QGridLayout;
\r
65 import com.trolltech.qt.gui.QHBoxLayout;
\r
66 import com.trolltech.qt.gui.QIcon;
\r
67 import com.trolltech.qt.gui.QImage;
\r
68 import com.trolltech.qt.gui.QKeySequence;
\r
69 import com.trolltech.qt.gui.QLabel;
\r
70 import com.trolltech.qt.gui.QLineEdit;
\r
71 import com.trolltech.qt.gui.QListWidgetItem;
\r
72 import com.trolltech.qt.gui.QMatrix;
\r
73 import com.trolltech.qt.gui.QMessageBox;
\r
74 import com.trolltech.qt.gui.QPushButton;
\r
75 import com.trolltech.qt.gui.QShortcut;
\r
76 import com.trolltech.qt.gui.QTimeEdit;
\r
77 import com.trolltech.qt.gui.QVBoxLayout;
\r
78 import com.trolltech.qt.gui.QWidget;
\r
79 import com.trolltech.qt.network.QNetworkRequest;
\r
80 import com.trolltech.qt.webkit.QWebPage;
\r
81 import com.trolltech.qt.webkit.QWebPage.WebAction;
\r
82 import com.trolltech.qt.webkit.QWebSettings;
\r
83 import com.trolltech.qt.webkit.QWebView;
\r
85 import cx.fbn.nevernote.Global;
\r
86 import cx.fbn.nevernote.dialog.EnCryptDialog;
\r
87 import cx.fbn.nevernote.dialog.EnDecryptDialog;
\r
88 import cx.fbn.nevernote.dialog.GeoDialog;
\r
89 import cx.fbn.nevernote.dialog.InsertLinkDialog;
\r
90 import cx.fbn.nevernote.dialog.TableDialog;
\r
91 import cx.fbn.nevernote.dialog.TagAssign;
\r
92 import cx.fbn.nevernote.evernote.EnCrypt;
\r
93 import cx.fbn.nevernote.signals.NoteResourceSignal;
\r
94 import cx.fbn.nevernote.signals.NoteSignal;
\r
95 import cx.fbn.nevernote.sql.DatabaseConnection;
\r
96 import cx.fbn.nevernote.utilities.ApplicationLogger;
\r
97 import cx.fbn.nevernote.utilities.FileUtils;
\r
99 public class BrowserWindow extends QWidget {
\r
101 public final QLineEdit titleLabel;
\r
102 private final QLineEdit urlText;
\r
103 private final QLabel authorLabel;
\r
104 private final QLineEdit authorText;
\r
105 private final QComboBox geoBox;
\r
106 public final TagLineEdit tagEdit;
\r
107 public final QLabel tagLabel;
\r
108 private final QLabel urlLabel;
\r
109 private final QLabel alteredLabel;
\r
110 private final QDateEdit alteredDate;
\r
111 private final QTimeEdit alteredTime;
\r
112 private final QDateEdit createdDate;
\r
113 private final QTimeEdit createdTime;
\r
114 private final QLabel subjectLabel;
\r
115 private final QDateEdit subjectDate;
\r
116 private final QTimeEdit subjectTime;
\r
117 public final QComboBox notebookBox;
\r
118 private final QLabel notebookLabel;
\r
119 private final QLabel createdLabel;
\r
120 public final QComboBox fontSize;
\r
121 private boolean extendedOn;
\r
122 public boolean buttonsVisible;
\r
123 private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
\r
124 private final ContentView browser;
\r
125 private List<Tag> allTags;
\r
126 private List<String> currentTags;
\r
127 public NoteSignal noteSignal;
\r
128 private List<Notebook> notebookList;
\r
129 private Note currentNote;
\r
130 private String saveNoteTitle;
\r
131 private String saveTagList;
\r
132 private boolean insideList;
\r
133 // private String selectedText;
\r
134 private final DatabaseConnection conn;
\r
135 private final QCalendarWidget createdCalendarWidget;
\r
136 private final QCalendarWidget alteredCalendarWidget;
\r
137 private final QCalendarWidget subjectCalendarWidget;
\r
139 public final QPushButton undoButton;
\r
140 public final QPushButton redoButton;
\r
141 public final QPushButton cutButton;
\r
142 public final QPushButton copyButton;
\r
143 public final QPushButton pasteButton;
\r
144 public final QPushButton boldButton;
\r
145 public final QPushButton underlineButton;
\r
146 public final QPushButton italicButton;
\r
147 public final Signal0 focusLost;
\r
148 public final NoteResourceSignal resourceSignal;
\r
150 public QPushButton rightAlignButton;
\r
151 public QPushButton leftAlignButton;
\r
152 public QPushButton centerAlignButton;
\r
154 public final QPushButton strikethroughButton;
\r
155 public final QPushButton hlineButton;
\r
156 public final QPushButton indentButton;
\r
157 public final QPushButton outdentButton;
\r
158 public final QPushButton bulletListButton;
\r
159 public final QPushButton numberListButton;
\r
161 public final QShortcut focusTitleShortcut;
\r
162 public final QShortcut focusTagShortcut;
\r
163 public final QShortcut focusNoteShortcut;
\r
164 public final QShortcut focusUrlShortcut;
\r
165 public final QShortcut focusAuthorShortcut;
\r
167 public final QComboBox fontList;
\r
168 public final QPushButton fontColor;
\r
169 private final ColorMenu fontColorMenu;
\r
170 public final QPushButton fontHilight;
\r
171 // public final ColorComboBox fontHilight;
\r
172 private final ColorMenu fontHilightColorMenu;
\r
173 public final QFileSystemWatcher fileWatcher;
\r
174 public int cursorPosition;
\r
175 private boolean forceTextPaste = false;
\r
176 private String selectedFile;
\r
177 private String currentHyperlink;
\r
178 public boolean keepPDFNavigationHidden;
\r
179 private final ApplicationLogger logger;
\r
181 private final HashMap<String,Integer> previewPageList;
\r
184 public BrowserWindow(DatabaseConnection c) {
\r
185 logger = new ApplicationLogger("browser.log");
\r
186 logger.log(logger.HIGH, "Setting up browser");
\r
188 fileWatcher = new QFileSystemWatcher();
\r
189 // fileWatcher.fileChanged.connect(this, "fileChanged(String)");
\r
190 noteSignal = new NoteSignal();
\r
191 titleLabel = new QLineEdit();
\r
192 titleLabel.setMaxLength(Constants.EDAM_NOTE_TITLE_LEN_MAX);
\r
193 urlText = new QLineEdit();
\r
194 authorText = new QLineEdit();
\r
195 geoBox = new QComboBox();
\r
196 urlLabel = new QLabel();
\r
197 authorLabel = new QLabel();
\r
200 focusLost = new Signal0();
\r
202 tagEdit = new TagLineEdit(allTags);
\r
203 tagLabel = new QLabel("Tags:");
\r
204 tagEdit.focusLost.connect(this, "modifyTagsTyping()");
\r
206 createdCalendarWidget = new QCalendarWidget();
\r
207 createdDate = new QDateEdit();
\r
208 createdDate.setDisplayFormat(Global.getDateFormat());
\r
209 createdDate.setCalendarPopup(true);
\r
210 createdDate.setCalendarWidget(createdCalendarWidget);
\r
211 createdTime = new QTimeEdit();
\r
212 createdDate.dateChanged.connect(this, "createdChanged()");
\r
213 createdTime.timeChanged.connect(this, "createdChanged()");
\r
215 alteredCalendarWidget = new QCalendarWidget();
\r
216 alteredDate = new QDateEdit();
\r
217 alteredDate.setDisplayFormat(Global.getDateFormat());
\r
218 alteredDate.setCalendarPopup(true);
\r
219 alteredDate.setCalendarWidget(alteredCalendarWidget);
\r
220 alteredTime = new QTimeEdit();
\r
221 alteredLabel = new QLabel("Altered:");
\r
222 alteredDate.dateChanged.connect(this, "alteredChanged()");
\r
223 alteredTime.timeChanged.connect(this, "alteredChanged()");
\r
225 subjectCalendarWidget = new QCalendarWidget();
\r
226 subjectDate = new QDateEdit();
\r
227 subjectDate.setDisplayFormat(Global.getDateFormat());
\r
228 subjectDate.setCalendarPopup(true);
\r
229 subjectDate.setCalendarWidget(subjectCalendarWidget);
\r
230 subjectTime = new QTimeEdit();
\r
231 subjectLabel = new QLabel("Subject Date:");
\r
232 subjectDate.dateChanged.connect(this, "subjectDateTimeChanged()");
\r
233 subjectTime.timeChanged.connect(this, "subjectDateTimeChanged()");
\r
234 authorText.textChanged.connect(this, "authorChanged()");
\r
235 urlText.textChanged.connect(this, "sourceUrlChanged()");
\r
237 notebookBox = new QComboBox();
\r
238 notebookLabel = new QLabel("Notebook");
\r
239 createdLabel = new QLabel("Created:");
\r
240 // selectedText = new String();
\r
242 urlLabel.setVisible(false);
\r
243 urlText.setVisible(false);
\r
244 authorLabel.setVisible(false);
\r
246 geoBox.setVisible(false);
\r
247 geoBox.addItem(new QIcon(iconPath+"globe.png"), "");
\r
248 geoBox.addItem(new String("Set"));
\r
249 geoBox.addItem(new String("Clear"));
\r
250 geoBox.addItem(new String("View On Map"));
\r
251 geoBox.activated.connect(this, "geoBoxChanged()");
\r
253 authorText.setVisible(false);
\r
254 createdDate.setVisible(false);
\r
255 alteredLabel.setVisible(false);
\r
256 //notebookBox.setVisible(false);
\r
257 notebookLabel.setVisible(false);
\r
258 createdLabel.setVisible(false);
\r
259 createdTime.setVisible(false);
\r
260 alteredDate.setVisible(false);
\r
261 alteredTime.setVisible(false);
\r
262 subjectLabel.setVisible(false);
\r
263 subjectDate.setVisible(false);
\r
264 subjectTime.setVisible(false);
\r
265 extendedOn = false;
\r
266 buttonsVisible = true;
\r
267 setAcceptDrops(true);
\r
269 browser = new ContentView(this);
\r
270 browser.page().setLinkDelegationPolicy(
\r
271 QWebPage.LinkDelegationPolicy.DelegateAllLinks);
\r
272 browser.linkClicked.connect(this, "linkClicked(QUrl)");
\r
273 currentHyperlink = "";
\r
275 QVBoxLayout v = new QVBoxLayout();
\r
276 QFormLayout notebookLayout = new QFormLayout();
\r
277 QGridLayout dateLayout = new QGridLayout();
\r
278 titleLabel.setReadOnly(false);
\r
279 titleLabel.editingFinished.connect(this, "titleEdited()");
\r
280 browser.page().contentsChanged.connect(this, "contentChanged()");
\r
281 browser.page().selectionChanged.connect(this, "selectionChanged()");
\r
282 browser.page().mainFrame().javaScriptWindowObjectCleared.connect(this,
\r
283 "exposeToJavascript()");
\r
285 notebookBox.activated.connect(this, "notebookChanged()");
\r
286 resourceSignal = new NoteResourceSignal();
\r
288 QHBoxLayout tagLayout = new QHBoxLayout();
\r
289 v.addWidget(titleLabel, 0);
\r
290 notebookLayout.addRow(notebookLabel, notebookBox);
\r
291 tagLayout.addLayout(notebookLayout, 0);
\r
292 tagLayout.stretch(4);
\r
293 tagLayout.addWidget(tagLabel, 0);
\r
294 tagLayout.addWidget(tagEdit, 1);
\r
295 v.addLayout(tagLayout);
\r
297 QHBoxLayout urlLayout = new QHBoxLayout();
\r
298 urlLayout.addWidget(urlLabel, 0);
\r
299 urlLayout.addWidget(urlText, 0);
\r
300 v.addLayout(urlLayout);
\r
302 QHBoxLayout authorLayout = new QHBoxLayout();
\r
303 authorLayout.addWidget(authorLabel, 0);
\r
304 authorLayout.addWidget(authorText, 0);
\r
305 authorLayout.addWidget(geoBox);
\r
306 v.addLayout(authorLayout);
\r
308 dateLayout.addWidget(createdLabel, 0, 0);
\r
309 dateLayout.addWidget(createdDate, 0, 1);
\r
310 dateLayout.addWidget(createdTime, 0, 2);
\r
311 dateLayout.setColumnStretch(9, 100);
\r
312 dateLayout.addWidget(alteredLabel, 0, 3);
\r
313 dateLayout.addWidget(alteredDate, 0, 4);
\r
314 dateLayout.addWidget(alteredTime, 0, 5);
\r
315 dateLayout.addWidget(subjectLabel, 0, 6);
\r
316 dateLayout.addWidget(subjectDate, 0, 7);
\r
317 dateLayout.addWidget(subjectTime, 0, 8);
\r
318 v.addLayout(dateLayout, 0);
\r
320 undoButton = newEditorButton("undo", "Undo Change");
\r
321 redoButton = newEditorButton("redo", "Redo Change");
\r
322 cutButton = newEditorButton("cut", "Cut");
\r
323 copyButton = newEditorButton("copy", "Copy");
\r
324 pasteButton = newEditorButton("paste", "Paste");
\r
325 boldButton = newEditorButton("bold", "Bold");
\r
326 underlineButton = newEditorButton("underline", "Underline");
\r
327 italicButton = newEditorButton("italic", "Italic");
\r
329 rightAlignButton = newEditorButton("justifyRight", "Right Align");
\r
330 leftAlignButton = newEditorButton("justifyLeft", "Left Align");
\r
331 centerAlignButton = newEditorButton("justifyCenter", "Center Align");
\r
333 strikethroughButton = newEditorButton("strikethrough", "Strikethrough");
\r
334 hlineButton = newEditorButton("hline", "Insert Horizontal Line");
\r
335 indentButton = newEditorButton("indent", "Shift Right");
\r
336 outdentButton = newEditorButton("outdent", "Shift Left");
\r
337 bulletListButton = newEditorButton("bulletList", "Bullet List");
\r
338 numberListButton = newEditorButton("numberList", "Number List");
\r
341 QHBoxLayout buttonLayout;
\r
342 buttonLayout = new QHBoxLayout();
\r
343 buttonLayout.setSpacing(0);
\r
344 v.addLayout(buttonLayout);
\r
346 buttonLayout.addWidget(undoButton);
\r
347 buttonLayout.addWidget(redoButton);
\r
349 buttonLayout.addWidget(newSeparator(), 0);
\r
350 buttonLayout.addWidget(cutButton);
\r
351 buttonLayout.addWidget(copyButton);
\r
352 buttonLayout.addWidget(pasteButton);
\r
354 buttonLayout.addWidget(newSeparator(), 0);
\r
355 buttonLayout.addWidget(boldButton);
\r
356 buttonLayout.addWidget(italicButton);
\r
357 buttonLayout.addWidget(underlineButton);
\r
358 buttonLayout.addWidget(strikethroughButton);
\r
360 buttonLayout.addWidget(newSeparator(), 0);
\r
361 buttonLayout.addWidget(leftAlignButton);
\r
362 buttonLayout.addWidget(centerAlignButton);
\r
363 buttonLayout.addWidget(rightAlignButton);
\r
365 buttonLayout.addWidget(newSeparator(), 0);
\r
366 buttonLayout.addWidget(hlineButton);
\r
368 buttonLayout.addWidget(indentButton);
\r
369 buttonLayout.addWidget(outdentButton);
\r
370 buttonLayout.addWidget(bulletListButton);
\r
371 buttonLayout.addWidget(numberListButton);
\r
373 // Setup the font & font size combo boxes
\r
374 buttonLayout.addWidget(newSeparator(), 0);
\r
375 fontList = new QComboBox();
\r
376 fontSize = new QComboBox();
\r
377 fontList.setToolTip("Font");
\r
378 fontSize.setToolTip("Font Size");
\r
379 fontList.activated.connect(this, "fontChanged(String)");
\r
380 fontSize.activated.connect(this, "fontSizeChanged(String)");
\r
381 buttonLayout.addWidget(fontList, 0);
\r
382 buttonLayout.addWidget(fontSize, 0);
\r
383 QFontDatabase fonts = new QFontDatabase();
\r
384 List<String> fontFamilies = fonts.families();
\r
385 for (int i = 0; i < fontFamilies.size(); i++) {
\r
386 fontList.addItem(fontFamilies.get(i));
\r
388 loadFontSize(fontFamilies.get(i));
\r
392 buttonLayout.addWidget(newSeparator(), 0);
\r
393 fontColor = newEditorButton("fontColor", "Font Color");
\r
394 fontColorMenu = new ColorMenu(this);
\r
395 fontColor.setMenu(fontColorMenu.getMenu());
\r
396 fontColorMenu.getMenu().triggered.connect(this, "fontColorClicked()");
\r
397 buttonLayout.addWidget(fontColor);
\r
398 fontHilight = newEditorButton("fontHilight", "Font Hilight Color");
\r
399 fontHilightColorMenu = new ColorMenu(this);
\r
400 fontHilight.setMenu(fontHilightColorMenu.getMenu());
\r
401 fontHilightColorMenu.getMenu().triggered.connect(this, "fontHilightClicked()");
\r
402 buttonLayout.addWidget(fontHilight);
\r
404 buttonLayout.addWidget(new QLabel(), 1);
\r
405 v.addWidget(browser, 1);
\r
406 // v.addLayout(buttonLayout,0);
\r
409 browser.downloadAttachmentRequested.connect(this,
\r
410 "downloadAttachment(QNetworkRequest)");
\r
411 browser.downloadImageRequested.connect(this,
\r
412 "downloadImage(QNetworkRequest)");
\r
413 setTabOrder(notebookBox, tagEdit);
\r
414 setTabOrder(tagEdit, browser);
\r
416 focusNoteShortcut = new QShortcut(this);
\r
417 setupShortcut(focusNoteShortcut, "Focus_Note");
\r
418 focusNoteShortcut.activated.connect(this, "focusNote()");
\r
419 focusTitleShortcut = new QShortcut(this);
\r
420 setupShortcut(focusTitleShortcut, "Focus_Title");
\r
421 focusTitleShortcut.activated.connect(this, "focusTitle()");
\r
422 focusTagShortcut = new QShortcut(this);
\r
423 setupShortcut(focusTagShortcut, "Focus_Tag");
\r
424 focusTagShortcut.activated.connect(this, "focusTag()");
\r
425 focusAuthorShortcut = new QShortcut(this);
\r
426 setupShortcut(focusAuthorShortcut, "Focus_Author");
\r
427 focusAuthorShortcut.activated.connect(this, "focusAuthor()");
\r
428 focusUrlShortcut = new QShortcut(this);
\r
429 setupShortcut(focusUrlShortcut, "Focus_Url");
\r
430 focusUrlShortcut.activated.connect(this, "focusUrl()");
\r
432 browser.page().mainFrame().setTextSizeMultiplier(Global.getTextSizeMultiplier());
\r
433 browser.page().mainFrame().setZoomFactor(Global.getZoomFactor());
\r
435 previewPageList = new HashMap<String,Integer>();
\r
437 browser.page().microFocusChanged.connect(this, "microFocusChanged()");
\r
438 logger.log(logger.HIGH, "Browser setup complete");
\r
442 private void setupShortcut(QShortcut action, String text) {
\r
443 if (!Global.shortcutKeys.containsAction(text))
\r
445 action.setKey(new QKeySequence(Global.shortcutKeys.getShortcut(text)));
\r
451 // Getter for the QWebView
\r
452 public QWebView getBrowser() {
\r
456 // Block signals while loading data or things are flagged as dirty by
\r
458 public void loadingData(boolean val) {
\r
459 logger.log(logger.EXTREME, "Entering BrowserWindow.loadingData() " +val);
\r
460 notebookBox.blockSignals(val);
\r
461 browser.page().blockSignals(val);
\r
462 browser.page().mainFrame().blockSignals(val);
\r
463 titleLabel.blockSignals(val);
\r
464 alteredDate.blockSignals(val);
\r
465 alteredTime.blockSignals(val);
\r
466 createdTime.blockSignals(val);
\r
467 createdDate.blockSignals(val);
\r
468 subjectDate.blockSignals(val);
\r
469 subjectTime.blockSignals(val);
\r
470 urlText.blockSignals(val);
\r
471 authorText.blockSignals(val);
\r
473 exposeToJavascript();
\r
474 logger.log(logger.EXTREME, "Exiting BrowserWindow.loadingData() " +val);
\r
478 public void setReadOnly(boolean v) {
\r
480 titleLabel.setEnabled(!v);
\r
481 notebookBox.setEnabled(!v);
\r
482 tagEdit.setEnabled(!v);
\r
483 authorLabel.setEnabled(!v);
\r
484 geoBox.setEnabled(!v);
\r
485 urlText.setEnabled(!v);
\r
486 createdDate.setEnabled(!v);
\r
487 subjectDate.setEnabled(!v);
\r
488 alteredDate.setEnabled(!v);
\r
489 getBrowser().setEnabled(true);
\r
492 // expose this class to Javascript on the web page
\r
493 private void exposeToJavascript() {
\r
494 browser.page().mainFrame().addToJavaScriptWindowObject("jambi", this);
\r
497 // Custom event queue
\r
499 public boolean event(QEvent e) {
\r
500 if (e.type().equals(QEvent.Type.FocusOut)) {
\r
501 logger.log(logger.EXTREME, "Focus lost");
\r
504 return super.event(e);
\r
507 // clear out browser
\r
508 public void clear() {
\r
509 logger.log(logger.EXTREME, "Entering BrowserWindow.clear()");
\r
511 browser.setContent(new QByteArray());
\r
512 tagEdit.setText("");
\r
513 urlLabel.setText("Source URL:");
\r
514 titleLabel.setText("");
\r
515 logger.log(logger.EXTREME, "Exiting BrowserWindow.clear()");
\r
518 // get/set current note
\r
519 public void setNote(Note n) {
\r
523 saveNoteTitle = n.getTitle();
\r
527 public Note getNote() {
\r
528 return currentNote;
\r
531 // New Editor Button
\r
532 private QPushButton newEditorButton(String name, String toolTip) {
\r
533 QPushButton button = new QPushButton();
\r
534 QIcon icon = new QIcon(iconPath + name + ".gif");
\r
535 button.setIcon(icon);
\r
536 button.setToolTip(toolTip);
\r
537 button.clicked.connect(this, name + "Clicked()");
\r
542 private QLabel newSeparator() {
\r
543 return new QLabel(" ");
\r
546 // Set the title in the window
\r
547 public void setTitle(String t) {
\r
548 titleLabel.setText(t);
\r
553 // Return the current text title
\r
554 public String getTitle() {
\r
555 return titleLabel.text();
\r
558 // Set the tag name string
\r
559 public void setTag(String t) {
\r
561 tagEdit.setText(t);
\r
564 // Set the source URL
\r
565 public void setUrl(String t) {
\r
566 urlLabel.setText("Source URL:\t");
\r
567 urlText.setText(t);
\r
570 public void setAuthor(String t) {
\r
571 authorLabel.setText("Author:\t");
\r
572 authorText.setText(t);
\r
575 // Set the creation date
\r
576 public void setCreation(long date) {
\r
577 QDateTime dt = new QDateTime();
\r
578 dt.setTime_t((int) (date / 1000));
\r
579 createdDate.setDateTime(dt);
\r
580 createdTime.setDateTime(dt);
\r
581 createdDate.setDisplayFormat(Global.getDateFormat());
\r
582 createdTime.setDisplayFormat(Global.getTimeFormat());
\r
585 // Set the creation date
\r
586 public void setAltered(long date) {
\r
587 QDateTime dt = new QDateTime();
\r
588 dt.setTime_t((int) (date / 1000));
\r
589 alteredDate.setDateTime(dt);
\r
590 alteredTime.setDateTime(dt);
\r
591 alteredDate.setDisplayFormat(Global.getDateFormat());
\r
592 alteredTime.setDisplayFormat(Global.getTimeFormat());
\r
595 // Set the subject date
\r
596 public void setSubjectDate(long date) {
\r
597 QDateTime dt = new QDateTime();
\r
598 dt.setTime_t((int) (date / 1000));
\r
599 subjectDate.setDateTime(dt);
\r
600 subjectTime.setDateTime(dt);
\r
601 subjectDate.setDisplayFormat(Global.getDateFormat());
\r
602 subjectTime.setDisplayFormat(Global.getTimeFormat());
\r
605 // Toggle the extended attribute information
\r
606 public void toggleInformation() {
\r
608 extendedOn = false;
\r
612 urlLabel.setVisible(extendedOn);
\r
613 urlText.setVisible(extendedOn);
\r
614 authorText.setVisible(extendedOn);
\r
615 geoBox.setVisible(extendedOn);
\r
616 authorLabel.setVisible(extendedOn);
\r
617 createdDate.setVisible(extendedOn);
\r
618 createdTime.setVisible(extendedOn);
\r
619 createdLabel.setVisible(extendedOn);
\r
620 alteredLabel.setVisible(extendedOn);
\r
621 alteredDate.setVisible(extendedOn);
\r
622 alteredTime.setVisible(extendedOn);
\r
623 //notebookBox.setVisible(extendedOn);
\r
624 notebookLabel.setVisible(extendedOn);
\r
625 subjectLabel.setVisible(extendedOn);
\r
626 subjectDate.setVisible(extendedOn);
\r
627 subjectTime.setVisible(extendedOn);
\r
630 public void hideButtons() {
\r
632 buttonsVisible = false;
\r
634 undoButton.setVisible(false);
\r
635 redoButton.setVisible(false);
\r
636 cutButton.setVisible(false);
\r
637 copyButton.setVisible(false);
\r
638 pasteButton.setVisible(false);
\r
639 boldButton.setVisible(false);
\r
640 underlineButton.setVisible(false);
\r
641 italicButton.setVisible(false);
\r
643 rightAlignButton.setVisible(false);
\r
644 leftAlignButton.setVisible(false);
\r
645 centerAlignButton.setVisible(false);
\r
647 strikethroughButton.setVisible(false);
\r
648 hlineButton.setVisible(false);
\r
649 indentButton.setVisible(false);
\r
650 outdentButton.setVisible(false);
\r
651 bulletListButton.setVisible(false);
\r
652 numberListButton.setVisible(false);
\r
654 fontList.setVisible(false);
\r
655 fontSize.setVisible(false);
\r
656 fontColor.setVisible(false);
\r
657 fontHilight.setVisible(false);
\r
662 // Is the extended view on?
\r
663 public boolean isExtended() {
\r
667 // Listener for when a link is clicked
\r
668 @SuppressWarnings("unused")
\r
669 private void openFile() {
\r
670 logger.log(logger.EXTREME, "Starting openFile()");
\r
671 File fileHandle = new File(selectedFile);
\r
672 URI fileURL = fileHandle.toURI();
\r
673 String localURL = fileURL.toString();
\r
674 QUrl url = new QUrl(localURL);
\r
675 QFile file = new QFile(selectedFile);
\r
677 logger.log(logger.EXTREME, "Adding to fileWatcher:"+file.fileName());
\r
678 fileWatcher.addPath(file.fileName());
\r
680 if (!QDesktopServices.openUrl(url)) {
\r
681 logger.log(logger.LOW, "Error opening file :" +url);
\r
686 // Listener for when a link is clicked
\r
687 @SuppressWarnings("unused")
\r
688 private void linkClicked(QUrl url) {
\r
689 logger.log(logger.EXTREME, "URL Clicked: " +url.toString());
\r
690 if (url.toString().substring(0,8).equals("nnres://")) {
\r
691 logger.log(logger.EXTREME, "URL is NN resource");
\r
692 if (url.toString().endsWith("/vnd.evernote.ink")) {
\r
693 logger.log(logger.EXTREME, "Unable to open ink note");
\r
694 QMessageBox.information(this, "Unable Open", "This is an ink note.\n"+
\r
695 "Ink notes are not supported since Evernote has not\n published any specifications on them\n" +
\r
696 "and I'm too lazy to figure them out by myself.");
\r
699 String fullName = url.toString().substring(8);
\r
700 int index = fullName.indexOf(".");
\r
704 type = fullName.substring(index+1);
\r
705 guid = fullName.substring(0,index);
\r
707 index = guid.indexOf(Global.attachmentNameDelimeter);
\r
709 guid = guid.substring(0,index);
\r
711 List<Resource> resList = currentNote.getResources();
\r
712 Resource res = null;
\r
713 for (int i=0; i<resList.size(); i++) {
\r
714 if (resList.get(i).getGuid().equals(guid)) {
\r
715 res = resList.get(i);
\r
720 String resGuid = Global.resourceMap.get(guid);
\r
721 if (resGuid != null)
\r
722 res = conn.getNoteTable().noteResourceTable.getNoteResource(resGuid, true);
\r
726 if (res.getAttributes() != null &&
\r
727 res.getAttributes().getFileName() != null &&
\r
728 !res.getAttributes().getFileName().trim().equals(""))
\r
729 fileName = res.getGuid()+Global.attachmentNameDelimeter+res.getAttributes().getFileName();
\r
731 fileName = res.getGuid()+"."+type;
\r
732 QFile file = new QFile(Global.getFileManager().getResDirPath(fileName));
\r
733 QFile.OpenMode mode = new QFile.OpenMode();
\r
734 mode.set(QFile.OpenModeFlag.WriteOnly);
\r
735 boolean openResult = file.open(mode);
\r
736 logger.log(logger.EXTREME, "File opened:" +openResult);
\r
737 QDataStream out = new QDataStream(file);
\r
738 Resource resBinary = conn.getNoteTable().noteResourceTable.getNoteResource(res.getGuid(), true);
\r
739 QByteArray binData = new QByteArray(resBinary.getData().getBody());
\r
741 logger.log(logger.EXTREME, "Writing resource");
\r
742 out.writeBytes(binData.toByteArray());
\r
745 String whichOS = System.getProperty("os.name");
\r
746 if (whichOS.contains("Windows"))
\r
747 url.setUrl("file:///"+file.fileName());
\r
749 url.setUrl("file://"+file.fileName());
\r
750 // fileWatcher.removePath(file.fileName());
\r
751 logger.log(logger.EXTREME, "Adding file watcher " +file.fileName());
\r
752 fileWatcher.addPath(file.fileName());
\r
754 // If we can't open it, then prompt the user to save it.
\r
755 if (!QDesktopServices.openUrl(url)) {
\r
756 logger.log(logger.EXTREME, "We can't handle this. Where do we put it?");
\r
757 QFileDialog dialog = new QFileDialog();
\r
759 if (dialog.exec()!=0) {
\r
760 List<String> fileNames = dialog.selectedFiles(); //gets all selected filenames
\r
761 if (fileNames.size() == 0)
\r
763 String sf = fileNames.get(0);
\r
764 QFile saveFile = new QFile(sf);
\r
765 mode.set(QFile.OpenModeFlag.WriteOnly);
\r
766 saveFile.open(mode);
\r
767 QDataStream saveOut = new QDataStream(saveFile);
\r
768 saveOut.writeBytes(binData.toByteArray());
\r
776 logger.log(logger.EXTREME, "Launching URL");
\r
777 QDesktopServices.openUrl(url);
\r
780 // Listener for when BOLD is clicked
\r
781 @SuppressWarnings("unused")
\r
782 private void undoClicked() {
\r
783 browser.page().triggerAction(WebAction.Undo);
\r
784 browser.setFocus();
\r
787 // Listener for when BOLD is clicked
\r
788 @SuppressWarnings("unused")
\r
789 private void redoClicked() {
\r
790 browser.page().triggerAction(WebAction.Redo);
\r
791 browser.setFocus();
\r
794 // Listener for when BOLD is clicked
\r
795 @SuppressWarnings("unused")
\r
796 private void boldClicked() {
\r
797 browser.page().triggerAction(WebAction.ToggleBold);
\r
798 microFocusChanged();
\r
799 browser.setFocus();
\r
802 // Listener for when Italics is clicked
\r
803 @SuppressWarnings("unused")
\r
804 private void italicClicked() {
\r
805 browser.page().triggerAction(WebAction.ToggleItalic);
\r
806 microFocusChanged();
\r
807 browser.setFocus();
\r
810 // Listener for when UNDERLINE is clicked
\r
811 @SuppressWarnings("unused")
\r
812 private void underlineClicked() {
\r
813 browser.page().triggerAction(WebAction.ToggleUnderline);
\r
814 microFocusChanged();
\r
815 browser.setFocus();
\r
818 // Listener for when Strikethrough is clicked
\r
819 @SuppressWarnings("unused")
\r
820 private void strikethroughClicked() {
\r
821 browser.page().mainFrame().evaluateJavaScript(
\r
822 "document.execCommand('strikeThrough', false, '');");
\r
823 browser.setFocus();
\r
826 // Listener for when cut is clicked
\r
827 @SuppressWarnings("unused")
\r
828 private void cutClicked() {
\r
829 browser.page().triggerAction(WebAction.Cut);
\r
830 browser.setFocus();
\r
833 // Listener when COPY is clicked
\r
834 @SuppressWarnings("unused")
\r
835 private void copyClicked() {
\r
836 browser.page().triggerAction(WebAction.Copy);
\r
837 browser.setFocus();
\r
840 // Listener when PASTE is clicked
\r
841 void pasteClicked() {
\r
842 logger.log(logger.EXTREME, "Paste Clicked");
\r
843 if (forceTextPaste) {
\r
844 pasteWithoutFormattingClicked();
\r
847 QClipboard clipboard = QApplication.clipboard();
\r
848 QMimeData mime = clipboard.mimeData();
\r
850 // String x = mime.html();
\r
852 if (mime.hasImage()) {
\r
853 logger.log(logger.EXTREME, "Image paste found");
\r
855 browser.setFocus();
\r
859 if (mime.hasUrls()) {
\r
860 logger.log(logger.EXTREME, "URL paste found");
\r
862 browser.setFocus();
\r
866 String text = mime.html();
\r
867 if (text.contains("en-tag") && mime.hasHtml()) {
\r
868 logger.log(logger.EXTREME, "Intra-note paste found");
\r
869 text = fixInternotePaste(text);
\r
870 mime.setHtml(text);
\r
871 clipboard.setMimeData(mime);
\r
874 logger.log(logger.EXTREME, "Final paste choice encountered");
\r
875 browser.page().triggerAction(WebAction.Paste);
\r
876 browser.setFocus();
\r
880 // Paste text without formatting
\r
881 private void pasteWithoutFormattingClicked() {
\r
882 logger.log(logger.EXTREME, "Paste without format clipped");
\r
883 QClipboard clipboard = QApplication.clipboard();
\r
884 QMimeData mime = clipboard.mimeData();
\r
885 if (!mime.hasText())
\r
887 String text = mime.text();
\r
888 clipboard.setText(text);
\r
889 browser.page().triggerAction(WebAction.Paste);
\r
890 QApplication.clipboard().setMimeData(mime);
\r
891 browser.setFocus();
\r
895 // insert date/time
\r
896 @SuppressWarnings("unused")
\r
897 private void insertDateTime() {
\r
898 String fmt = Global.getDateFormat() + " " + Global.getTimeFormat();
\r
899 String dateTimeFormat = new String(fmt);
\r
900 SimpleDateFormat simple = new SimpleDateFormat(dateTimeFormat);
\r
901 Calendar cal = Calendar.getInstance();
\r
903 browser.page().mainFrame().evaluateJavaScript(
\r
904 "document.execCommand('insertHtml', false, '"+simple.format(cal.getTime())+"');");
\r
906 browser.setFocus();
\r
910 // Listener when Left is clicked
\r
911 @SuppressWarnings("unused")
\r
912 private void justifyLeftClicked() {
\r
913 browser.page().mainFrame().evaluateJavaScript(
\r
914 "document.execCommand('JustifyLeft', false, '');");
\r
915 browser.setFocus();
\r
918 // Listener when Center is clicked
\r
919 @SuppressWarnings("unused")
\r
920 private void justifyCenterClicked() {
\r
921 browser.page().mainFrame().evaluateJavaScript(
\r
922 "document.execCommand('JustifyCenter', false, '');");
\r
923 browser.setFocus();
\r
926 // Listener when Left is clicked
\r
927 @SuppressWarnings("unused")
\r
928 private void justifyRightClicked() {
\r
929 browser.page().mainFrame().evaluateJavaScript(
\r
930 "document.execCommand('JustifyRight', false, '');");
\r
931 browser.setFocus();
\r
934 // Listener when HLINE is clicked
\r
935 @SuppressWarnings("unused")
\r
936 private void hlineClicked() {
\r
937 browser.page().mainFrame().evaluateJavaScript(
\r
938 "document.execCommand('insertHorizontalRule', false, '');");
\r
939 browser.setFocus();
\r
942 // Listener when outdent is clicked
\r
943 private void outdentClicked() {
\r
944 browser.page().mainFrame().evaluateJavaScript(
\r
945 "document.execCommand('outdent', false, '');");
\r
946 browser.setFocus();
\r
949 // Listener when a bullet list is clicked
\r
950 @SuppressWarnings("unused")
\r
951 private void bulletListClicked() {
\r
952 browser.page().mainFrame().evaluateJavaScript(
\r
953 "document.execCommand('InsertUnorderedList', false, '');");
\r
954 browser.setFocus();
\r
957 // Listener when a bullet list is clicked
\r
958 @SuppressWarnings("unused")
\r
959 private void numberListClicked() {
\r
960 browser.page().mainFrame().evaluateJavaScript(
\r
961 "document.execCommand('InsertOrderedList', false, '');");
\r
962 browser.setFocus();
\r
965 // Listener when indent is clicked
\r
966 private void indentClicked() {
\r
967 browser.page().mainFrame().evaluateJavaScript(
\r
968 "document.execCommand('indent', false, '');");
\r
969 browser.setFocus();
\r
972 // Listener when the font name is changed
\r
973 @SuppressWarnings("unused")
\r
974 private void fontChanged(String font) {
\r
975 browser.page().mainFrame().evaluateJavaScript(
\r
976 "document.execCommand('fontName',false,'" + font + "');");
\r
977 browser.setFocus();
\r
980 // Listener when a font size is changed
\r
981 @SuppressWarnings("unused")
\r
982 private void fontSizeChanged(String font) {
\r
983 String text = browser.selectedText();
\r
984 if (text.trim().equalsIgnoreCase(""))
\r
987 String selectedText = browser.selectedText();
\r
988 String url = "<span style=\"font-size:" +font +"pt; \">"+selectedText +"</a>";
\r
989 String script = "document.execCommand('insertHtml', false, '"+url+"');";
\r
990 browser.page().mainFrame().evaluateJavaScript(script);
\r
991 /* browser.page().mainFrame().evaluateJavaScript(
\r
992 "document.execCommand('fontSize',false,'"
\r
995 browser.setFocus();
\r
998 // Load the font combo box based upon the font selected
\r
999 private void loadFontSize(String name) {
\r
1000 QFontDatabase db = new QFontDatabase();
\r
1002 List<Integer> points = db.pointSizes(name);
\r
1003 for (int i=0; i<points.size(); i++) {
\r
1004 fontSize.addItem(points.get(i).toString());
\r
1007 fontSize.addItem("x-small");
\r
1008 fontSize.addItem("small");
\r
1009 fontSize.addItem("medium");
\r
1010 fontSize.addItem("large");
\r
1011 fontSize.addItem("x-large");
\r
1012 fontSize.addItem("xx-large");
\r
1013 fontSize.addItem("xxx-large");
\r
1017 // Listener when a font size is changed
\r
1018 @SuppressWarnings("unused")
\r
1019 private void fontColorClicked() {
\r
1020 // QColorDialog dialog = new QColorDialog();
\r
1021 // QColor color = QColorDialog.getColor();
\r
1022 QColor color = fontColorMenu.getColor();
\r
1023 if (color.isValid())
\r
1024 browser.page().mainFrame().evaluateJavaScript(
\r
1025 "document.execCommand('foreColor',false,'" + color.name()
\r
1027 browser.setFocus();
\r
1030 // Listener for when a background color change is requested
\r
1031 @SuppressWarnings("unused")
\r
1032 private void fontHilightClicked() {
\r
1033 // QColorDialog dialog = new QColorDialog();
\r
1034 // QColor color = QColorDialog.getColor();
\r
1035 QColor color = fontHilightColorMenu.getColor();
\r
1036 if (color.isValid())
\r
1037 browser.page().mainFrame().evaluateJavaScript(
\r
1038 "document.execCommand('backColor',false,'" + color.name()
\r
1040 browser.setFocus();
\r
1043 // Listener for when a background color change is requested
\r
1044 @SuppressWarnings("unused")
\r
1045 private void superscriptClicked() {
\r
1046 browser.page().mainFrame().evaluateJavaScript(
\r
1047 "document.execCommand('superscript');");
\r
1048 browser.setFocus();
\r
1051 // Listener for when a background color change is requested
\r
1052 @SuppressWarnings("unused")
\r
1053 private void subscriptClicked() {
\r
1054 browser.page().mainFrame().evaluateJavaScript(
\r
1055 "document.execCommand('subscript');");
\r
1056 browser.setFocus();
\r
1058 // Insert a to-do checkbox
\r
1059 @SuppressWarnings("unused")
\r
1060 private void todoClicked() {
\r
1061 FileNameMap fileNameMap = URLConnection.getFileNameMap();
\r
1062 String script_start = new String(
\r
1063 "document.execCommand('insertHtml', false, '");
\r
1064 String script_end = new String("');");
\r
1065 String todo = new String(
\r
1066 "<input TYPE=\"CHECKBOX\" value=\"false\" onClick=\"value=checked; window.jambi.contentChanged(); \" />");
\r
1067 browser.page().mainFrame().evaluateJavaScript(
\r
1068 script_start + todo + script_end);
\r
1069 browser.setFocus();
\r
1072 // Encrypt the selected text
\r
1073 @SuppressWarnings("unused")
\r
1074 private void encryptText() {
\r
1075 String text = browser.selectedText();
\r
1076 if (text.trim().equalsIgnoreCase(""))
\r
1079 EnCryptDialog dialog = new EnCryptDialog();
\r
1081 if (!dialog.okPressed()) {
\r
1085 EnCrypt crypt = new EnCrypt();
\r
1086 String encrypted = crypt.encrypt(text, dialog.getPassword().trim(), 64);
\r
1088 if (encrypted.trim().equals("")) {
\r
1089 QMessageBox.information(this, "Error", "Error Encrypting String");
\r
1092 StringBuffer buffer = new StringBuffer(encrypted.length() + 100);
\r
1093 buffer.append("<img en-tag=\"en-crypt\" cipher=\"RC2\" hint=\""
\r
1094 + dialog.getHint().replace("'","\\'") + "\" length=\"64\" ");
\r
1095 buffer.append("contentEditable=\"false\" alt=\"");
\r
1096 buffer.append(encrypted);
\r
1097 // NFC FIXME: should this be a file URL like in handleLocalAttachment and importAttachment?
\r
1098 buffer.append("\" src=\"").append(FileUtils.toForwardSlashedPath(Global.getFileManager().getImageDirPath("encrypt.png")));
\r
1099 Global.cryptCounter++;
\r
1100 buffer.append(" id=\"crypt"+Global.cryptCounter.toString() +"\"");
\r
1101 buffer.append(" onMouseOver=\"style.cursor=\\'hand\\'\"");
\r
1102 buffer.append(" onClick=\"window.jambi.decryptText(\\'crypt"+Global.cryptCounter.toString()
\r
1103 +"\\', \\'"+encrypted+"\\', \\'"+dialog.getHint().replace("'", "\\&apos;")+"\\');\"");
\r
1104 buffer.append("style=\"display:block\" />");
\r
1106 String script_start = new String(
\r
1107 "document.execCommand('insertHtml', false, '");
\r
1108 String script_end = new String("');");
\r
1109 browser.page().mainFrame().evaluateJavaScript(
\r
1110 script_start + buffer.toString() + script_end);
\r
1114 // Insert a hyperlink
\r
1115 public void insertLink() {
\r
1116 logger.log(logger.EXTREME, "Inserting link");
\r
1117 String text = browser.selectedText();
\r
1118 if (text.trim().equalsIgnoreCase(""))
\r
1121 InsertLinkDialog dialog = new InsertLinkDialog();
\r
1122 if (currentHyperlink != null && currentHyperlink != "") {
\r
1123 dialog.setUrl(currentHyperlink);
\r
1126 if (!dialog.okPressed()) {
\r
1127 logger.log(logger.EXTREME, "Insert link canceled");
\r
1130 if (browser.insertLinkAction.text().equalsIgnoreCase("Insert Hyperlink")) {
\r
1131 String selectedText = browser.selectedText();
\r
1132 logger.log(logger.EXTREME, "Inserting link on text "+selectedText);
\r
1133 logger.log(logger.EXTREME, "URL Link " +dialog.getUrl().trim());
\r
1134 String url = "<a href=\"" +dialog.getUrl().trim()+"\" >"+selectedText +"</a>";
\r
1135 String script = "document.execCommand('insertHtml', false, '"+url+"');";
\r
1136 browser.page().mainFrame().evaluateJavaScript(script);
\r
1139 String js = new String( "function getCursorPos() {"
\r
1141 +"if (window.getSelection) {"
\r
1142 +" var selObj = window.getSelection();"
\r
1143 +" var selRange = selObj.getRangeAt(0);"
\r
1144 +" var workingNode = window.getSelection().anchorNode.parentNode;"
\r
1145 +" while(workingNode != null) { "
\r
1146 +" if (workingNode.nodeName.toLowerCase()=='a') workingNode.setAttribute('href','" +dialog.getUrl() +"');"
\r
1147 +" workingNode = workingNode.parentNode;"
\r
1150 +"} getCursorPos();");
\r
1151 browser.page().mainFrame().evaluateJavaScript(js);
\r
1158 public void insertTable() {
\r
1159 TableDialog dialog = new TableDialog();
\r
1161 if (!dialog.okPressed()) {
\r
1165 int cols = dialog.getCols();
\r
1166 int rows = dialog.getRows();
\r
1167 int width = dialog.getWidth();
\r
1168 boolean percent = dialog.isPercent();
\r
1170 String newHTML = "<table border=\"1\" width=\"" +new Integer(width).toString();
\r
1172 newHTML = newHTML +"%";
\r
1173 newHTML = newHTML + "\"><tbody>";
\r
1175 for (int i=0; i<rows; i++) {
\r
1176 newHTML = newHTML +"<tr>";
\r
1177 for (int j=0; j<cols; j++) {
\r
1178 newHTML = newHTML +"<td> </td>";
\r
1180 newHTML = newHTML +"</tr>";
\r
1182 newHTML = newHTML+"</tbody></table>";
\r
1184 String script = "document.execCommand('insertHtml', false, '"+newHTML+"');";
\r
1185 browser.page().mainFrame().evaluateJavaScript(script);
\r
1189 // Text content changed
\r
1190 @SuppressWarnings("unused")
\r
1191 private void selectionChanged() {
\r
1192 browser.encryptAction.setEnabled(true);
\r
1193 browser.insertLinkAction.setEnabled(true);
\r
1194 String scriptStart = "var selection_text = (window.getSelection()).toString();"
\r
1195 + "var range = (window.getSelection()).getRangeAt(0);"
\r
1196 + "var parent_html = range.commonAncestorContainer.innerHTML;"
\r
1197 + "if (parent_html == undefined) {window.jambi.saveSelectedText(selection_text); return;}"
\r
1198 + "var first_text = range.startContainer.nodeValue.substr(range.startOffset);"
\r
1199 + "var last_text = (range.endContainer.nodeValue).substring(0,range.endOffset);"
\r
1200 + "var start = parent_html.indexOf(first_text);"
\r
1201 + "var end = parent_html.indexOf(last_text,start+1)+last_text.length;"
\r
1202 + "var value = parent_html.substring(start,end);"
\r
1203 + "window.jambi.saveSelectedText(value);" ;
\r
1204 browser.page().mainFrame().evaluateJavaScript(scriptStart);
\r
1208 public void saveSelectedText(String text) {
\r
1209 boolean enabled = true;
\r
1210 if (text.trim().length() == 0)
\r
1212 if (text.indexOf("en-tag=\"en-crypt\"") >= 0)
\r
1214 if (text.indexOf("<img en-tag=\"en-media\"") >= 0)
\r
1216 if (text.indexOf("<a en-tag=\"en-media\"") >= 0)
\r
1218 if (text.indexOf("<input ") >= 0)
\r
1221 browser.encryptAction.setEnabled(enabled);
\r
1222 browser.insertLinkAction.setEnabled(enabled);
\r
1223 // selectedText = text;
\r
1226 // Decrypt clicked text
\r
1227 public void decryptText(String id, String text, String hint) {
\r
1228 EnCrypt crypt = new EnCrypt();
\r
1229 String plainText = null;
\r
1230 Calendar currentTime = new GregorianCalendar();
\r
1231 Long l = new Long(currentTime.getTimeInMillis());
\r
1232 String slot = new String(Long.toString(l));
\r
1234 // First, try to decrypt with any keys we already have
\r
1235 for (int i=0; i<Global.passwordRemember.size(); i++) {
\r
1236 plainText = crypt.decrypt(text, Global.passwordRemember.get(i), 64);
\r
1237 if (plainText != null) {
\r
1238 slot = new String(Long.toString(l));
\r
1239 Global.passwordSafe.put(slot, Global.passwordRemember.get(i));
\r
1240 removeEncryption(id, plainText, false, slot);
\r
1246 EnDecryptDialog dialog = new EnDecryptDialog();
\r
1247 dialog.setHint(hint);
\r
1248 while (plainText == null || !dialog.okPressed()) {
\r
1250 if (!dialog.okPressed()) {
\r
1253 plainText = crypt.decrypt(text, dialog.getPassword().trim(), 64);
\r
1254 if (plainText == null) {
\r
1255 QMessageBox.warning(this, "Incorrect Password", "The password entered is not correct");
\r
1258 Global.passwordSafe.put(slot, dialog.getPassword());
\r
1259 removeEncryption(id, plainText, dialog.permanentlyDecrypt(), slot);
\r
1260 if (dialog.rememberPassword())
\r
1261 Global.passwordRemember.add(dialog.getPassword());
\r
1265 // Get the editor tag line
\r
1266 public TagLineEdit getTagLine() {
\r
1270 // Modify a note's tags
\r
1271 @SuppressWarnings("unused")
\r
1272 private void modifyTags() {
\r
1273 TagAssign tagWindow = new TagAssign(allTags, currentTags);
\r
1275 if (tagWindow.okClicked()) {
\r
1276 currentTags.clear();
\r
1277 StringBuffer tagDisplay = new StringBuffer();
\r
1279 List<QListWidgetItem> newTags = tagWindow.getTagList()
\r
1281 for (int i = 0; i < newTags.size(); i++) {
\r
1282 currentTags.add(newTags.get(i).text());
\r
1283 tagDisplay.append(newTags.get(i).text());
\r
1284 if (i < newTags.size() - 1) {
\r
1285 tagDisplay.append(Global.tagDelimeter + " ");
\r
1288 tagEdit.setText(tagDisplay.toString());
\r
1289 noteSignal.tagsChanged.emit(currentNote.getGuid(), currentTags);
\r
1293 // Tag line has been modified by typing text
\r
1294 @SuppressWarnings("unused")
\r
1295 private void modifyTagsTyping() {
\r
1297 String newTags = tagEdit.text();
\r
1298 List<String> test = tagEdit.tagCompleter.getTagList();
\r
1299 if (newTags.equalsIgnoreCase(saveTagList))
\r
1302 // We know something has changed...
\r
1303 String oldTagArray[] = saveTagList.split(Global.tagDelimeter);
\r
1304 String newTagArray[] = newTags.split(Global.tagDelimeter);
\r
1306 List<String> newTagList = new ArrayList<String>();
\r
1307 List<String> oldTagList = new ArrayList<String>();
\r
1309 for (int i = 0; i < oldTagArray.length; i++)
\r
1310 if (!oldTagArray[i].trim().equals(""))
\r
1311 oldTagList.add(oldTagArray[i]);
\r
1312 for (int i = 0; i < newTagArray.length; i++)
\r
1313 if (!newTagArray[i].trim().equals(""))
\r
1314 newTagList.add(newTagArray[i]);
\r
1316 // We now have lists of the new & old. Remove duplicates. If all
\r
1317 // are removed from both then nothing has really changed
\r
1318 for (int i = newTagList.size() - 1; i >= 0; i--) {
\r
1319 String nTag = newTagList.get(i);
\r
1320 for (int j = oldTagList.size() - 1; j >= 0; j--) {
\r
1321 String oTag = oldTagList.get(j);
\r
1322 if (oTag.equalsIgnoreCase(nTag)) {
\r
1323 oldTagList.remove(j);
\r
1324 newTagList.remove(i);
\r
1330 if (oldTagList.size() != 0 || newTagList.size() != 0) {
\r
1331 currentTags.clear();
\r
1332 for (int i = 0; i < newTagArray.length; i++)
\r
1333 if (!newTagArray[i].trim().equals(""))
\r
1334 currentTags.add(newTagArray[i].trim());
\r
1336 noteSignal.tagsChanged.emit(currentNote.getGuid(), currentTags);
\r
1341 // Tab button was pressed
\r
1342 public void tabPressed() {
\r
1343 if (!insideList) {
\r
1344 String script_start = new String(
\r
1345 "document.execCommand('insertHtml', false, ' ');");
\r
1346 browser.page().mainFrame().evaluateJavaScript(script_start);
\r
1351 public void backtabPressed() {
\r
1356 public void setInsideList() {
\r
1357 insideList = true;
\r
1360 // The title has been edited
\r
1361 @SuppressWarnings("unused")
\r
1362 private void titleEdited() {
\r
1363 // If we don't have a good note, or if the current title
\r
1364 // matches the old title then we don't need to do anything
\r
1365 if (currentNote == null)
\r
1367 if (currentNote.getTitle().trim().equals(titleLabel.text().trim()))
\r
1370 // If we have a real change, we need to save it.
\r
1371 noteSignal.titleChanged.emit(currentNote.getGuid(), titleLabel.text());
\r
1372 currentNote.setTitle(titleLabel.text());
\r
1373 saveNoteTitle = titleLabel.text();
\r
1377 // Set the list of note tags
\r
1378 public void setAllTags(List<Tag> l) {
\r
1380 tagEdit.setTagList(l);
\r
1383 // Setter for the current tags
\r
1384 public void setCurrentTags(List<String> s) {
\r
1388 // Save the list of notebooks
\r
1389 public void setNotebookList(List<Notebook> n) {
\r
1391 loadNotebookList();
\r
1394 // Load the notebook list and select the current notebook
\r
1395 private void loadNotebookList() {
\r
1396 if (notebookBox.count() != 0)
\r
1397 notebookBox.clear();
\r
1398 if (notebookList == null)
\r
1401 for (int i = 0; i < notebookList.size(); i++) {
\r
1402 notebookBox.addItem(notebookList.get(i).getName());
\r
1403 if (currentNote != null) {
\r
1404 if (currentNote.getNotebookGuid().equals(
\r
1405 notebookList.get(i).getGuid())) {
\r
1406 notebookBox.setCurrentIndex(i);
\r
1412 // Get the contents of the editor
\r
1413 public String getContent() {
\r
1414 return browser.page().currentFrame().toHtml();
\r
1417 // The note contents have changed
\r
1418 public void contentChanged() {
\r
1419 String content = getContent();
\r
1421 noteSignal.noteChanged.emit(currentNote.getGuid(), content);
\r
1424 // noteSignal.noteChanged.emit(currentNote.getGuid(), unicode);
\r
1427 // The notebook selection has changed
\r
1428 @SuppressWarnings("unused")
\r
1429 private void notebookChanged() {
\r
1430 boolean changed = false;
\r
1431 String n = notebookBox.currentText();
\r
1432 for (int i = 0; i < notebookList.size(); i++) {
\r
1433 if (n.equals(notebookList.get(i).getName())) {
\r
1434 if (!notebookList.get(i).getGuid().equals(currentNote.getNotebookGuid())) {
\r
1435 currentNote.setNotebookGuid(notebookList.get(i).getGuid());
\r
1438 i = notebookList.size();
\r
1442 // If the notebook changed, signal the update
\r
1444 noteSignal.notebookChanged.emit(currentNote.getGuid(), currentNote
\r
1445 .getNotebookGuid());
\r
1448 // Check the note title
\r
1449 private void checkNoteTitle() {
\r
1450 String text = browser.page().currentFrame().toPlainText();
\r
1451 if (saveNoteTitle.trim().equals("")) {
\r
1452 int newLine = text.indexOf("\n");
\r
1453 if (newLine > 0) {
\r
1454 text = text.substring(0, newLine);
\r
1455 if (text.trim().equals(""))
\r
1456 text = "Untitled Note";
\r
1457 titleLabel.setText(text);
\r
1459 if (text.length() > 20)
\r
1460 titleLabel.setText(text.substring(0, 20));
\r
1462 if (text.trim().equals(""))
\r
1463 titleLabel.setText("Untitled Note");
\r
1465 titleLabel.setText(text);
\r
1468 noteSignal.titleChanged.emit(currentNote.getGuid(), titleLabel
\r
1473 // Return the note contents so we can email them
\r
1474 public String getContentsToEmail() {
\r
1475 return browser.page().currentFrame().toPlainText().trim();
\r
1477 * int body = browser.page().currentFrame().toHtml().indexOf("<body>");
\r
1478 * String temp = browser.page().currentFrame().toHtml(); if (body == -1)
\r
1479 * temp = "<html><body><b>Test</b></body></html>"; else temp =
\r
1480 * "<html>"+temp.substring(body); return temp; // return
\r
1481 * urlEncode(browser.page().currentFrame().toHtml());
\r
1485 // Insert an image into the editor
\r
1486 private void insertImage(QMimeData mime) {
\r
1487 logger.log(logger.EXTREME, "Entering insertImage");
\r
1488 QImage img = (QImage) mime.imageData();
\r
1489 String script_start = new String(
\r
1490 "document.execCommand('insertHTML', false, '");
\r
1491 String script_end = new String("');");
\r
1493 long now = new Date().getTime();
\r
1494 String path = Global.getFileManager().getResDirPath(
\r
1495 (new Long(now).toString()) + ".jpg");
\r
1497 // This block is just a hack to make sure we wait at least 1ms so we
\r
1499 // have collisions on image names
\r
1500 long i = new Date().getTime();
\r
1502 i = new Date().getTime();
\r
1504 // Open the file & write the data
\r
1505 QFile tfile = new QFile(path);
\r
1506 tfile.open(new QIODevice.OpenMode(QIODevice.OpenModeFlag.WriteOnly));
\r
1510 Resource newRes = createResource(QUrl.fromLocalFile(path).toString(), 0, "image/jpeg", false);
\r
1511 if (newRes == null)
\r
1513 currentNote.getResources().add(newRes);
\r
1515 // do the actual insert into the note
\r
1516 StringBuffer buffer = new StringBuffer(100);
\r
1517 buffer.append("<img src=\"");
\r
1518 buffer.append(tfile.fileName());
\r
1519 buffer.append("\" en-tag=en-media type=\"image/jpeg\""
\r
1520 +" hash=\""+Global.byteArrayToHexString(newRes.getData().getBodyHash()) +"\""
\r
1521 +" guid=\"" +newRes.getGuid() +"\""
\r
1522 +" onContextMenu=\"window.jambi.imageContextMenu('" +tfile.fileName() +"');\""
\r
1524 browser.page().mainFrame().evaluateJavaScript(
\r
1525 script_start + buffer + script_end);
\r
1530 // Handle URLs that are trying to be pasted
\r
1531 public void handleUrls(QMimeData mime) {
\r
1532 logger.log(logger.EXTREME, "Starting handleUrls");
\r
1533 FileNameMap fileNameMap = URLConnection.getFileNameMap();
\r
1535 List<QUrl> urlList = mime.urls();
\r
1536 String url = new String();
\r
1537 String script_start = new String(
\r
1538 "document.execCommand('createLink', false, '");
\r
1539 String script_end = new String("');");
\r
1541 for (int i = 0; i < urlList.size(); i++) {
\r
1542 url = urlList.get(i).toString();
\r
1543 // Find out what type of file we have
\r
1544 String mimeType = fileNameMap.getContentTypeFor(url);
\r
1546 // If null returned, we need to guess at the file type
\r
1547 if (mimeType == null)
\r
1548 mimeType = "application/"
\r
1549 + url.substring(url.lastIndexOf(".") + 1);
\r
1551 // Check if we have an image or some other type of file
\r
1552 if (url.substring(0, 5).equalsIgnoreCase("file:")
\r
1553 && mimeType.substring(0, 5).equalsIgnoreCase("image")) {
\r
1554 handleLocalImageURLPaste(mime, mimeType);
\r
1557 String[] type = mimeType.split("/");
\r
1558 boolean valid = validAttachment(type[1]);
\r
1559 boolean smallEnough = checkFileAttachmentSize(url);
\r
1560 if (smallEnough && valid
\r
1561 && url.substring(0, 5).equalsIgnoreCase("file:")
\r
1562 && !mimeType.substring(0, 5).equalsIgnoreCase("image")) {
\r
1563 handleLocalAttachment(mime, mimeType);
\r
1566 browser.page().mainFrame().evaluateJavaScript(
\r
1567 script_start + url + script_end);
\r
1572 // If a URL being pasted is an image URL, then attach the image
\r
1573 private void handleLocalImageURLPaste(QMimeData mime, String mimeType) {
\r
1574 List<QUrl> urlList = mime.urls();
\r
1575 String url = new String();
\r
1576 String script_start_image = new String(
\r
1577 "document.execCommand('insertHtml', false, '");
\r
1578 String script_end = new String("');");
\r
1579 StringBuffer buffer;
\r
1581 // Copy the image over into the resource directory and create a new resource
\r
1582 // record for each url pasted
\r
1583 for (int i = 0; i < urlList.size(); i++) {
\r
1584 url = urlList.get(i).toString();
\r
1586 Resource newRes = createResource(url, i, mimeType, false);
\r
1587 if (newRes == null)
\r
1589 currentNote.getResources().add(newRes);
\r
1590 buffer = new StringBuffer(100);
\r
1592 // Open the file & write the data
\r
1593 String fileName = Global.getFileManager().getResDirPath(newRes.getGuid());
\r
1594 QFile tfile = new QFile(fileName);
\r
1595 tfile.open(new QIODevice.OpenMode(QIODevice.OpenModeFlag.WriteOnly));
\r
1596 tfile.write(newRes.getData().getBody());
\r
1598 buffer.append(script_start_image);
\r
1599 buffer.append("<img src=\"" + FileUtils.toForwardSlashedPath(fileName));
\r
1600 // if (mimeType.equalsIgnoreCase("image/jpg"))
\r
1601 // mimeType = "image/jpeg";
\r
1602 buffer.append("\" en-tag=\"en-media\" type=\"" + mimeType +"\""
\r
1603 +" hash=\""+Global.byteArrayToHexString(newRes.getData().getBodyHash()) +"\""
\r
1604 +" guid=\"" +newRes.getGuid() +"\""
\r
1605 +" onContextMenu=\"window.jambi.imageContextMenu('" +tfile.fileName() +"');\""
\r
1607 buffer.append(script_end);
\r
1608 browser.page().mainFrame().evaluateJavaScript(buffer.toString());
\r
1614 // If a URL being pasted is a local file URL, then attach the file
\r
1615 private void handleLocalAttachment(QMimeData mime, String mimeType) {
\r
1616 logger.log(logger.EXTREME, "Attaching local file");
\r
1617 List<QUrl> urlList = mime.urls();
\r
1618 String script_start = new String(
\r
1619 "document.execCommand('insertHtml', false, '");
\r
1620 String script_end = new String("');");
\r
1621 StringBuffer buffer;
\r
1623 for (int i = 0; i < urlList.size(); i++) {
\r
1624 buffer = new StringBuffer(100);
\r
1625 String url = urlList.get(i).toString();
\r
1627 // Start building the HTML
\r
1628 String[] type = mimeType.split("/");
\r
1629 String icon = findIcon(type[1]);
\r
1630 if (icon.equals("attachment.png"))
\r
1631 icon = findIcon(type[0]);
\r
1632 if (icon.equals("attachment.png"))
\r
1633 icon = findIcon(url.substring(url.lastIndexOf(".")+1));
\r
1634 StringBuffer imageBuffer = new StringBuffer();
\r
1635 String imageURL = FileUtils.toFileURLString(Global.getFileManager().getImageDirFile(icon));
\r
1637 logger.log(logger.EXTREME, "Creating resource ");
\r
1638 Resource newRes = createResource(url, i, mimeType, true);
\r
1639 if (newRes == null)
\r
1641 logger.log(logger.EXTREME, "New resource size: " +newRes.getData().getSize());
\r
1642 currentNote.getResources().add(newRes);
\r
1644 String fileName = newRes.getGuid() + Global.attachmentNameDelimeter+newRes.getAttributes().getFileName();
\r
1645 // If we have a PDF, we need to setup the preview.
\r
1646 if (icon.equalsIgnoreCase("pdf.png") && Global.pdfPreview()) {
\r
1647 logger.log(logger.EXTREME, "Setting up PDF preview");
\r
1648 if (newRes.getAttributes() != null &&
\r
1649 newRes.getAttributes().getFileName() != null &&
\r
1650 !newRes.getAttributes().getFileName().trim().equals(""))
\r
1651 fileName = newRes.getGuid()+Global.attachmentNameDelimeter+
\r
1652 newRes.getAttributes().getFileName();
\r
1654 fileName = newRes.getGuid()+".pdf";
\r
1655 QFile file = new QFile(Global.getFileManager().getResDirPath(fileName));
\r
1656 QFile.OpenMode mode = new QFile.OpenMode();
\r
1657 mode.set(QFile.OpenModeFlag.WriteOnly);
\r
1659 QDataStream out = new QDataStream(file);
\r
1660 // Resource resBinary = conn.getNoteTable().noteResourceTable.getNoteResource(newRes.getGuid(), true);
\r
1661 QByteArray binData = new QByteArray(newRes.getData().getBody());
\r
1662 // resBinary = null;
\r
1663 out.writeBytes(binData.toByteArray());
\r
1666 PDFPreview pdfPreview = new PDFPreview();
\r
1667 if (pdfPreview.setupPreview(Global.getFileManager().getResDirPath(fileName), "pdf",0)) {
\r
1668 // NFC TODO: should this be a 'file://' url like the ones above?
\r
1669 imageURL = file.fileName() + ".png";
\r
1673 logger.log(logger.EXTREME, "Generating link tags");
\r
1674 buffer.append("<a en-tag=\"en-media\" guid=\"" +newRes.getGuid()+"\" ");
\r
1675 buffer.append(" onContextMenu=\"window.jambi.imageContextMenu('")
\r
1676 .append(Global.getFileManager().getResDirPath(fileName))
\r
1677 .append("');\" "); buffer.append("type=\"" + mimeType + "\" href=\"nnres://" + fileName +"\" hash=\""+Global.byteArrayToHexString(newRes.getData().getBodyHash()) +"\" >");
\r
1678 buffer.append("<img src=\"" + imageURL + "\" title=\"" +newRes.getAttributes().getFileName());
\r
1679 buffer.append("\"></img>");
\r
1680 buffer.append("</a>");
\r
1681 browser.page().mainFrame().evaluateJavaScript(
\r
1682 script_start + buffer.toString() + script_end);
\r
1686 private Resource createResource(String url, int sequence, String mime, boolean attachment) {
\r
1687 logger.log(logger.EXTREME, "Inside create resource");
\r
1688 QFile resourceFile;
\r
1689 url = new QUrl(url).toLocalFile();
\r
1690 url = url.replace("/", File.separator);
\r
1691 resourceFile = new QFile(url);
\r
1692 resourceFile.open(new QIODevice.OpenMode(QIODevice.OpenModeFlag.ReadOnly));
\r
1693 byte[] fileData = resourceFile.readAll().toByteArray();
\r
1694 resourceFile.close();
\r
1695 if (fileData.length == 0)
\r
1699 md = MessageDigest.getInstance("MD5");
\r
1700 md.update(fileData);
\r
1701 byte[] hash = md.digest();
\r
1703 Resource r = new Resource();
\r
1704 Calendar time = new GregorianCalendar();
\r
1705 long prevTime = time.getTimeInMillis();
\r
1706 while (prevTime == time.getTimeInMillis()) {
\r
1707 time = new GregorianCalendar();
\r
1709 r.setGuid(time.getTimeInMillis()+new Integer(sequence).toString());
\r
1710 r.setNoteGuid(currentNote.getGuid());
\r
1712 r.setActive(true);
\r
1713 r.setUpdateSequenceNum(0);
\r
1714 r.setWidth((short) 0);
\r
1715 r.setHeight((short) 0);
\r
1716 r.setDuration((short) 0);
\r
1718 Data d = new Data();
\r
1719 d.setBody(fileData);
\r
1720 d.setBodyIsSet(true);
\r
1721 d.setBodyHash(hash);
\r
1722 d.setBodyHashIsSet(true);
\r
1724 d.setSize(fileData.length);
\r
1726 int fileNamePos = url.lastIndexOf(File.separator);
\r
1727 if (fileNamePos == -1)
\r
1728 fileNamePos = url.lastIndexOf("/");
\r
1729 String fileName = url.substring(fileNamePos+1);
\r
1730 ResourceAttributes a = new ResourceAttributes();
\r
1732 a.setAltitudeIsSet(false);
\r
1733 a.setLongitude(0);
\r
1734 a.setLongitudeIsSet(false);
\r
1736 a.setLatitudeIsSet(false);
\r
1737 a.setCameraMake("");
\r
1738 a.setCameraMakeIsSet(false);
\r
1739 a.setCameraModel("");
\r
1740 a.setCameraModelIsSet(false);
\r
1741 a.setAttachment(attachment);
\r
1742 a.setAttachmentIsSet(true);
\r
1743 a.setClientWillIndex(false);
\r
1744 a.setClientWillIndexIsSet(true);
\r
1745 a.setRecoType("");
\r
1746 a.setRecoTypeIsSet(false);
\r
1747 a.setSourceURL(url);
\r
1748 a.setSourceURLIsSet(true);
\r
1749 a.setTimestamp(0);
\r
1750 a.setTimestampIsSet(false);
\r
1751 a.setFileName(fileName);
\r
1752 a.setFileNameIsSet(true);
\r
1753 r.setAttributes(a);
\r
1755 conn.getNoteTable().noteResourceTable.saveNoteResource(r, true);
\r
1757 } catch (NoSuchAlgorithmException e1) {
\r
1758 e1.printStackTrace();
\r
1764 // find the appropriate icon for an attachment
\r
1765 private String findIcon(String appl) {
\r
1766 appl = appl.toLowerCase();
\r
1767 File f = Global.getFileManager().getImageDirFile(appl + ".png");
\r
1769 return appl+".png";
\r
1770 return "attachment.png";
\r
1773 // Check if the account supports this type of attachment
\r
1774 private boolean validAttachment(String type) {
\r
1775 if (Global.isPremium())
\r
1777 if (type.equalsIgnoreCase("JPG"))
\r
1779 if (type.equalsIgnoreCase("PNG"))
\r
1781 if (type.equalsIgnoreCase("GIF"))
\r
1783 if (type.equalsIgnoreCase("MP3"))
\r
1785 if (type.equalsIgnoreCase("WAV"))
\r
1787 if (type.equalsIgnoreCase("AMR"))
\r
1789 if (type.equalsIgnoreCase("PDF"))
\r
1791 String error = "Non-premium accounts can only attach JPG, PNG, GIF, MP3, WAV, AMR, or PDF files.";
\r
1792 QMessageBox.information(this, "Non-Premium Account", error);
\r
1797 // Check the file attachment to be sure it isn't over 25 mb
\r
1798 private boolean checkFileAttachmentSize(String url) {
\r
1799 String fileName = url.substring(8);
\r
1800 QFile resourceFile = new QFile(fileName);
\r
1801 resourceFile.open(new QIODevice.OpenMode(
\r
1802 QIODevice.OpenModeFlag.ReadOnly));
\r
1803 long size = resourceFile.size();
\r
1804 resourceFile.close();
\r
1805 size = size / 1024 / 1024;
\r
1806 if (size < 50 && Global.isPremium())
\r
1811 String error = "A file attachment may not exceed 25MB.";
\r
1812 QMessageBox.information(this, "Attachment Size", error);
\r
1817 @SuppressWarnings("unused")
\r
1818 private void createdChanged() {
\r
1819 QDateTime dt = new QDateTime();
\r
1820 dt.setDate(createdDate.date());
\r
1821 dt.setTime(createdTime.time());
\r
1822 noteSignal.createdDateChanged.emit(currentNote.getGuid(), dt);
\r
1826 @SuppressWarnings("unused")
\r
1827 private void alteredChanged() {
\r
1828 QDateTime dt = new QDateTime();
\r
1829 dt.setDate(alteredDate.date());
\r
1830 dt.setTime(alteredTime.time());
\r
1831 noteSignal.alteredDateChanged.emit(currentNote.getGuid(), dt);
\r
1834 @SuppressWarnings("unused")
\r
1835 private void subjectDateTimeChanged() {
\r
1836 QDateTime dt = new QDateTime();
\r
1837 dt.setDate(subjectDate.date());
\r
1838 dt.setTime(subjectTime.time());
\r
1839 noteSignal.subjectDateChanged.emit(currentNote.getGuid(), dt);
\r
1843 @SuppressWarnings("unused")
\r
1844 private void sourceUrlChanged() {
\r
1845 noteSignal.sourceUrlChanged.emit(currentNote.getGuid(), urlText.text());
\r
1848 @SuppressWarnings("unused")
\r
1849 private void authorChanged() {
\r
1850 noteSignal.authorChanged.emit(currentNote.getGuid(), authorText.text());
\r
1853 private void geoBoxChanged() {
\r
1854 int index = geoBox.currentIndex();
\r
1855 geoBox.setCurrentIndex(0);
\r
1857 GeoDialog box = new GeoDialog();
\r
1858 box.setLongitude(currentNote.getAttributes().getLongitude());
\r
1859 box.setLatitude(currentNote.getAttributes().getLatitude());
\r
1860 box.setAltitude(currentNote.getAttributes().getAltitude());
\r
1862 if (!box.okPressed())
\r
1864 double alt = box.getAltitude();
\r
1865 double lat = box.getLatitude();
\r
1866 double lon = box.getLongitude();
\r
1867 if (alt != currentNote.getAttributes().getAltitude() ||
\r
1868 lon != currentNote.getAttributes().getLongitude() ||
\r
1869 lat != currentNote.getAttributes().getLatitude()) {
\r
1870 noteSignal.geoChanged.emit(currentNote.getGuid(), lon, lat, alt);
\r
1871 currentNote.getAttributes().setAltitude(alt);
\r
1872 currentNote.getAttributes().setLongitude(lon);
\r
1873 currentNote.getAttributes().setLatitude(lat);
\r
1878 noteSignal.geoChanged.emit(currentNote.getGuid(), 0.0, 0.0, 0.0);
\r
1879 currentNote.getAttributes().setAltitude(0.0);
\r
1880 currentNote.getAttributes().setLongitude(0.0);
\r
1881 currentNote.getAttributes().setLatitude(0.0);
\r
1884 if (index == 3 || index == 0) {
\r
1885 QDesktopServices.openUrl(new QUrl("http://maps.google.com/maps?z=6&q="+currentNote.getAttributes().getLatitude() +"," +currentNote.getAttributes().getLongitude()));
\r
1889 // ************************************************************
\r
1890 // * User chose to save an attachment. Pares out the request *
\r
1891 // * into a guid & file. Save the result. *
\r
1892 // ************************************************************
\r
1893 public void downloadAttachment(QNetworkRequest request) {
\r
1895 QFileDialog fd = new QFileDialog(this);
\r
1896 fd.setFileMode(FileMode.AnyFile);
\r
1897 fd.setConfirmOverwrite(true);
\r
1898 fd.setWindowTitle("Save File");
\r
1899 fd.setAcceptMode(AcceptMode.AcceptSave);
\r
1900 fd.setDirectory(System.getProperty("user.home"));
\r
1901 String name = request.url().toString();
\r
1903 int pos = name.lastIndexOf(Global.attachmentNameDelimeter);
\r
1905 guid = name.substring(0, pos).replace("nnres://", "");
\r
1906 name = name.substring(pos +Global.attachmentNameDelimeter.length());
\r
1907 fd.selectFile(name);
\r
1908 pos = name.lastIndexOf('.');
\r
1910 String mimeType = "(*." + name.substring(pos + 1)
\r
1911 + ");; All Files (*)";
\r
1912 fd.setFilter(tr(mimeType));
\r
1918 // Strip URL prefix and base dir
\r
1919 guid = guid.replace("nnres://", "")
\r
1920 .replace(FileUtils.toForwardSlashedPath(Global.getFileManager().getResDirPath()), "");
\r
1922 pos = guid.lastIndexOf('.');
\r
1924 guid = guid.substring(0,pos);
\r
1925 if (fd.exec() != 0 && fd.selectedFiles().size() > 0) {
\r
1926 name = name.replace('\\', '/');
\r
1927 Resource resBinary = conn.getNoteTable().noteResourceTable.getNoteResource(guid, true);
\r
1928 QFile saveFile = new QFile(fd.selectedFiles().get(0));
\r
1929 QFile.OpenMode mode = new QFile.OpenMode();
\r
1930 mode.set(QFile.OpenModeFlag.WriteOnly);
\r
1931 saveFile.open(mode);
\r
1932 QDataStream saveOut = new QDataStream(saveFile);
\r
1933 QByteArray binData = new QByteArray(resBinary.getData().getBody());
\r
1934 saveOut.writeBytes(binData.toByteArray());
\r
1941 // ************************************************************
\r
1942 // * User chose to save an attachment. Pares out the request *
\r
1943 // * into a guid & file. Save the result. --- DONE FROM downloadAttachment now!!!!!
\r
1944 // ************************************************************
\r
1945 // NFC TODO: unused? remove
\r
1946 public void downloadImage(QNetworkRequest request) {
\r
1947 QFileDialog fd = new QFileDialog(this);
\r
1948 fd.setFileMode(FileMode.AnyFile);
\r
1949 fd.setConfirmOverwrite(true);
\r
1950 fd.setWindowTitle("Save File");
\r
1951 fd.setAcceptMode(AcceptMode.AcceptSave);
\r
1952 fd.setDirectory(System.getProperty("user.home"));
\r
1953 String name = request.url().toString();
\r
1954 name = name.replace("nnres://", "");
\r
1955 String dPath = FileUtils.toForwardSlashedPath(Global.getFileManager().getResDirPath());
\r
1956 name = name.replace(dPath, "");
\r
1957 int pos = name.lastIndexOf('.');
\r
1958 String guid = name;
\r
1960 String mimeType = "(*." + name.substring(pos + 1)
\r
1961 + ");; All Files (*)";
\r
1962 fd.setFilter(tr(mimeType));
\r
1963 guid = guid.substring(0,pos);
\r
1965 pos = name.lastIndexOf(Global.attachmentNameDelimeter);
\r
1967 guid = name.substring(0, pos);
\r
1968 fd.selectFile(name.substring(pos+Global.attachmentNameDelimeter.length()));
\r
1970 if (fd.exec() != 0 && fd.selectedFiles().size() > 0) {
\r
1971 Resource resBinary = conn.getNoteTable().noteResourceTable.getNoteResource(guid, true);
\r
1972 String fileName = fd.selectedFiles().get(0);
\r
1973 QFile saveFile = new QFile(fileName);
\r
1974 QFile.OpenMode mode = new QFile.OpenMode();
\r
1975 mode.set(QFile.OpenModeFlag.WriteOnly);
\r
1976 saveFile.open(mode);
\r
1977 QDataStream saveOut = new QDataStream(saveFile);
\r
1978 QByteArray binData = new QByteArray(resBinary.getData().getBody());
\r
1979 saveOut.writeBytes(binData.toByteArray());
\r
1985 // *************************************************************
\r
1986 // * decrypt any hidden text. We could do an XML parse, but
\r
1987 // * it is quicker here just to scan for an <img tag & do the fix
\r
1988 // * the manual way
\r
1989 // *************************************************************
\r
1990 private void removeEncryption(String id, String plainText, boolean permanent, String slot) {
\r
1992 plainText = " <en-crypt-temp slot=\""+slot +"\">" +plainText+"</en-crypt-temp> ";
\r
1995 String html = browser.page().mainFrame().toHtml();
\r
1996 String text = html;
\r
1997 int imagePos = html.indexOf("<img");
\r
1999 for ( ;imagePos>0; ) {
\r
2000 // Find the end tag
\r
2001 endPos = text.indexOf(">", imagePos);
\r
2002 String tag = text.substring(imagePos-1,endPos);
\r
2003 if (tag.indexOf("id=\""+id+"\"") > -1) {
\r
2004 text = text.substring(0,imagePos) +plainText+text.substring(endPos+1);
\r
2006 browser.setContent(new QByteArray(text));
\r
2009 imagePos = text.indexOf("<img", imagePos+1);
\r
2014 //****************************************************************
\r
2015 //* Focus shortcuts
\r
2016 //****************************************************************
\r
2017 @SuppressWarnings("unused")
\r
2018 private void focusTitle() {
\r
2019 titleLabel.setFocus();
\r
2021 @SuppressWarnings("unused")
\r
2022 private void focusTag() {
\r
2023 tagEdit.setFocus();
\r
2025 @SuppressWarnings("unused")
\r
2026 private void focusNote() {
\r
2027 browser.setFocus();
\r
2029 @SuppressWarnings("unused")
\r
2030 private void focusAuthor() {
\r
2031 authorLabel.setFocus();
\r
2033 @SuppressWarnings("unused")
\r
2034 private void focusUrl() {
\r
2035 urlLabel.setFocus();
\r
2039 //*****************************************************************
\r
2040 //* Set the document background color
\r
2041 //*****************************************************************
\r
2042 public void setBackgroundColor(String color) {
\r
2043 String js = "function changeBackground(color) {"
\r
2044 +"document.body.style.background = color;"
\r
2046 +"changeBackground('" +color+"');";
\r
2047 browser.page().mainFrame().evaluateJavaScript(js);
\r
2052 //****************************************************************
\r
2053 //* MicroFocus changed
\r
2054 //****************************************************************
\r
2055 private void microFocusChanged() {
\r
2057 boldButton.setDown(false);
\r
2058 italicButton.setDown(false);
\r
2059 underlineButton.setDown(false);
\r
2060 browser.openAction.setEnabled(false);
\r
2061 browser.downloadAttachment.setEnabled(false);
\r
2062 browser.downloadImage.setEnabled(false);
\r
2063 browser.rotateImageLeft.setEnabled(false);
\r
2064 browser.rotateImageRight.setEnabled(false);
\r
2065 browser.insertTableAction.setEnabled(true);
\r
2066 browser.insertTableRowAction.setEnabled(false);
\r
2067 browser.deleteTableRowAction.setEnabled(false);
\r
2068 browser.insertLinkAction.setText("Insert Hyperlink");
\r
2069 currentHyperlink ="";
\r
2070 insideList = false;
\r
2071 forceTextPaste = false;
\r
2073 String js = new String( "function getCursorPos() {"
\r
2075 +"if (window.getSelection) {"
\r
2076 +" var selObj = window.getSelection();"
\r
2077 +" var selRange = selObj.getRangeAt(0);"
\r
2078 +" var workingNode = window.getSelection().anchorNode.parentNode;"
\r
2079 +" while(workingNode != null) { "
\r
2080 // +" window.jambi.printNode(workingNode.nodeName);"
\r
2081 +" if (workingNode.nodeName=='EN-CRYPT-TEMP') window.jambi.forceTextPaste();"
\r
2082 +" if (workingNode.nodeName=='B') window.jambi.boldActive();"
\r
2083 +" if (workingNode.nodeName=='I') window.jambi.italicActive();"
\r
2084 +" if (workingNode.nodeName=='U') window.jambi.underlineActive();"
\r
2085 +" if (workingNode.nodeName=='UL') window.jambi.setInsideList();"
\r
2086 +" if (workingNode.nodeName=='OL') window.jambi.setInsideList();"
\r
2087 +" if (workingNode.nodeName=='LI') window.jambi.setInsideList();"
\r
2088 +" if (workingNode.nodeName=='TBODY') window.jambi.setInsideTable();"
\r
2089 +" if (workingNode.nodeName=='A') {for(var x = 0; x < workingNode.attributes.length; x++ ) {if (workingNode.attributes[x].nodeName.toLowerCase() == 'href') window.jambi.setInsideLink(workingNode.attributes[x].nodeValue);}}"
\r
2090 +" if (workingNode.nodeName=='SPAN') {"
\r
2091 +" if (workingNode.getAttribute('style') == 'text-decoration: underline;') window.jambi.underlineActive();"
\r
2093 +" workingNode = workingNode.parentNode;"
\r
2096 +"} getCursorPos();");
\r
2097 browser.page().mainFrame().evaluateJavaScript(js);
\r
2100 public void printNode(String n) {
\r
2101 System.out.println("Node Vaule: " +n);
\r
2105 //****************************************************************
\r
2106 //* Insert a table row
\r
2107 //****************************************************************
\r
2108 public void insertTableRow() {
\r
2110 String js = new String( "function insertTableRow() {"
\r
2111 +" var selObj = window.getSelection();"
\r
2112 +" var selRange = selObj.getRangeAt(0);"
\r
2113 +" var workingNode = window.getSelection().anchorNode.parentNode;"
\r
2114 +" var cellCount = 0;"
\r
2115 +" while(workingNode != null) { "
\r
2116 +" if (workingNode.nodeName.toLowerCase()=='tr') {"
\r
2117 +" row = document.createElement('TR');"
\r
2118 +" var nodes = workingNode.getElementsByTagName('td');"
\r
2119 +" for (j=0; j<nodes.length; j=j+1) {"
\r
2120 +" cell = document.createElement('TD');"
\r
2121 +" cell.innerHTML=' ';"
\r
2122 +" row.appendChild(cell);"
\r
2124 +" workingNode.parentNode.insertBefore(row,workingNode.nextSibling);"
\r
2127 +" workingNode = workingNode.parentNode;"
\r
2129 +"} insertTableRow();");
\r
2130 browser.page().mainFrame().evaluateJavaScript(js);
\r
2133 //****************************************************************
\r
2134 //* Insert a table row
\r
2135 //****************************************************************
\r
2136 public void deleteTableRow() {
\r
2138 String js = new String( "function deleteTableRow() {"
\r
2139 +" var selObj = window.getSelection();"
\r
2140 +" var selRange = selObj.getRangeAt(0);"
\r
2141 +" var workingNode = window.getSelection().anchorNode.parentNode;"
\r
2142 +" var cellCount = 0;"
\r
2143 +" while(workingNode != null) { "
\r
2144 +" if (workingNode.nodeName.toLowerCase()=='tr') {"
\r
2145 +" workingNode.parentNode.removeChild(workingNode);"
\r
2148 +" workingNode = workingNode.parentNode;"
\r
2150 +"} deleteTableRow();");
\r
2151 browser.page().mainFrame().evaluateJavaScript(js);
\r
2154 public void setInsideTable() {
\r
2155 browser.insertTableRowAction.setEnabled(true);
\r
2156 browser.deleteTableRowAction.setEnabled(true);
\r
2157 browser.insertTableAction.setEnabled(false);
\r
2158 browser.encryptAction.setEnabled(false);
\r
2161 public void setInsideLink(String link) {
\r
2162 browser.insertLinkAction.setText("Edit Hyperlink");
\r
2163 currentHyperlink = link;
\r
2166 public void italicActive() {
\r
2167 italicButton.setDown(true);
\r
2169 public void boldActive() {
\r
2170 boldButton.setDown(true);
\r
2172 public void underlineActive() {
\r
2173 underlineButton.setDown(true);
\r
2175 public void forceTextPaste() {
\r
2176 forceTextPaste = true;
\r
2178 public void imageContextMenu(String f) {
\r
2179 browser.downloadImage.setEnabled(true);
\r
2180 browser.rotateImageRight.setEnabled(true);
\r
2181 browser.rotateImageLeft.setEnabled(true);
\r
2182 browser.openAction.setEnabled(true);
\r
2185 public void rotateImageRight() {
\r
2186 QWebSettings.setMaximumPagesInCache(0);
\r
2187 QWebSettings.setObjectCacheCapacities(0, 0, 0);
\r
2188 QImage image = new QImage(selectedFile);
\r
2189 QMatrix matrix = new QMatrix();
\r
2190 matrix.rotate( 90.0 );
\r
2191 image = image.transformed(matrix);
\r
2192 image.save(selectedFile);
\r
2193 QWebSettings.setMaximumPagesInCache(0);
\r
2194 QWebSettings.setObjectCacheCapacities(0, 0, 0);
\r
2195 browser.setHtml(browser.page().mainFrame().toHtml());
\r
2198 // resourceSignal.contentChanged.emit(selectedFile);
\r
2201 public void rotateImageLeft() {
\r
2202 QImage image = new QImage(selectedFile);
\r
2203 QMatrix matrix = new QMatrix();
\r
2204 matrix.rotate( -90.0 );
\r
2205 image = image.transformed(matrix);
\r
2206 image.save(selectedFile);
\r
2207 browser.setHtml(browser.page().mainFrame().toHtml());
\r
2210 // resourceSignal.contentChanged.emit(selectedFile);
\r
2212 public void resourceContextMenu(String f) {
\r
2213 browser.downloadAttachment.setEnabled(true);
\r
2214 browser.openAction.setEnabled(true);
\r
2219 //****************************************************************
\r
2220 //* Apply CSS style to specified word
\r
2221 //****************************************************************
\r
2222 /* public void applyStyleToWords(String word, String style) {
\r
2223 QFile script = new QFile("D:\\NeverNote\\js\\hilight1.js");
\r
2224 script.open(OpenModeFlag.ReadOnly);
\r
2225 String s = script.readAll().toString();
\r
2226 String js = new String(s +" findit('"+word+"', '"+style+"');");
\r
2227 browser.page().mainFrame().evaluateJavaScript(js);
\r
2228 System.out.println(getContent());
\r
2231 //****************************************************************
\r
2232 //* Someone tried to paste a resource between notes, so we need *
\r
2233 //* to do some special handling. *
\r
2234 //****************************************************************
\r
2235 private String fixInternotePaste(String text) {
\r
2236 logger.log(logger.EXTREME, "Fixing internote paste");
\r
2237 String returnValue = fixInternotePasteSearch(text, "<img", "src=\"");
\r
2238 return fixInternotePasteSearch(returnValue, "<a", "href=\"nnres://");
\r
2240 private String fixInternotePasteSearch(String text, String type, String locTag) {
\r
2242 // First, let's fix the images.
\r
2243 int startPos = text.indexOf(type);
\r
2245 for (; startPos>=0;) {
\r
2246 endPos = text.indexOf(">", startPos+1);
\r
2247 String segment = text.substring(startPos, endPos);
\r
2248 if (segment.indexOf("en-tag") > -1) {
\r
2249 String newSegment = segment;
\r
2251 int guidStartPos = segment.indexOf("guid=\"");
\r
2252 int guidEndPos = segment.indexOf("\"", guidStartPos+7);
\r
2253 String guid = segment.substring(guidStartPos+6,guidEndPos);
\r
2255 Calendar currentTime = new GregorianCalendar();
\r
2256 Long l = new Long(currentTime.getTimeInMillis());
\r
2257 long prevTime = l;
\r
2258 while (l==prevTime) {
\r
2259 currentTime = new GregorianCalendar();
\r
2260 l= new Long(currentTime.getTimeInMillis());
\r
2263 Resource r = conn.getNoteTable().noteResourceTable.getNoteResource(guid, true);
\r
2266 String randint = new String(Long.toString(l));
\r
2267 String extension = null;
\r
2268 if (r.getMime()!= null) {
\r
2269 extension = r.getMime().toLowerCase();
\r
2270 if (extension.indexOf("/")>-1)
\r
2271 extension = extension.substring(extension.indexOf("/")+1);
\r
2273 String newFile = randint;
\r
2274 if (r.getAttributes().getFileName() != null && r.getAttributes().getFileName() != "")
\r
2275 if (!locTag.startsWith("src"))
\r
2276 newFile = newFile+Global.attachmentNameDelimeter+r.getAttributes().getFileName();
\r
2277 r.setNoteGuid(currentNote.getGuid());
\r
2279 r.setGuid(randint);
\r
2280 conn.getNoteTable().noteResourceTable.saveNoteResource(r, true);
\r
2281 QFile f = new QFile(Global.getFileManager().getResDirPath(newFile));
\r
2282 QByteArray bin = new QByteArray(r.getData().getBody());
\r
2283 f.open(QFile.OpenModeFlag.WriteOnly);
\r
2286 newSegment = newSegment.replace("guid=\""+guid, "guid=\""+randint);
\r
2287 currentNote.getResources().add(r);
\r
2289 int startSrcPos = newSegment.indexOf(locTag);
\r
2290 int endSrcPos = newSegment.indexOf("\"",startSrcPos+locTag.length()+1);
\r
2292 if (locTag.startsWith("src")) {
\r
2293 source = newSegment.substring(startSrcPos+locTag.length(),endSrcPos);
\r
2294 newSegment = newSegment.replace(source,
\r
2295 FileUtils.toForwardSlashedPath(Global.getFileManager().getResDirPath(newFile)));
\r
2297 source = newSegment.substring(startSrcPos+locTag.length(),endSrcPos);
\r
2298 newSegment = newSegment.replace(source, newFile);
\r
2301 text = text.substring(0,startPos) + newSegment + text.substring(endPos);
\r
2303 startPos = text.indexOf(type, startPos+1);
\r
2309 public void nextPage(String file) {
\r
2310 logger.log(logger.EXTREME, "Starting nextPage()");
\r
2312 Integer pageNumber;
\r
2313 if (previewPageList.containsKey(file))
\r
2314 pageNumber = previewPageList.get(file)+1;
\r
2317 previewPageList.remove(file);
\r
2318 previewPageList.put(file, pageNumber);
\r
2319 PDFPreview pdfPreview = new PDFPreview();
\r
2320 boolean goodPreview = pdfPreview.setupPreview(file, "pdf", pageNumber);
\r
2321 if (goodPreview) {
\r
2323 // String html = getContent();
\r
2324 QWebSettings.setMaximumPagesInCache(0);
\r
2325 QWebSettings.setObjectCacheCapacities(0, 0, 0);
\r
2326 // browser.setContent(new QByteArray());
\r
2327 browser.setHtml(browser.page().mainFrame().toHtml());
\r
2329 // browser.setContent(new QByteArray(html));
\r
2330 // browser.triggerPageAction(WebAction.Reload);
\r
2331 // pdfMouseOver(selectedFile);
\r
2335 public void previousPage(String file) {
\r
2336 logger.log(logger.EXTREME, "Starting previousPage()");
\r
2338 Integer pageNumber;
\r
2339 if (previewPageList.containsKey(file))
\r
2340 pageNumber = previewPageList.get(file)-1;
\r
2343 previewPageList.remove(file);
\r
2344 previewPageList.put(file, pageNumber);
\r
2345 PDFPreview pdfPreview = new PDFPreview();
\r
2346 boolean goodPreview = pdfPreview.setupPreview(file, "pdf", pageNumber);
\r
2347 if (goodPreview) {
\r
2349 // String html = getContent();
\r
2350 QWebSettings.setMaximumPagesInCache(0);
\r
2351 QWebSettings.setObjectCacheCapacities(0, 0, 0);
\r
2352 browser.setHtml(browser.page().mainFrame().toHtml());
\r
2354 // browser.setContent(new QByteArray(html));
\r
2355 // browser.triggerPageAction(WebAction.Reload);
\r
2359 /* public void pdfMouseOver(String name) {
\r
2361 if (previewPageList.containsKey(selectedFile))
\r
2362 pageNumber = previewPageList.get(selectedFile)+1;
\r
2366 if (pageNumber <= 1)
\r
2367 browser.previousPageAction.setEnabled(false);
\r
2369 browser.previousPageAction.setEnabled(true);
\r
2371 PDFPreview pdf = new PDFPreview();
\r
2372 int totalPages = pdf.getPageCount(name);
\r
2373 if (previewPageList.containsKey(selectedFile))
\r
2374 pageNumber = previewPageList.get(selectedFile)+1;
\r
2377 if (totalPages > pageNumber)
\r
2378 browser.nextPageAction.setEnabled(true);
\r
2380 browser.nextPageAction.setEnabled(false);
\r
2384 public void pdfMouseOut() {
\r
2385 // browser.nextPageAction.setVisible(false);
\r
2386 // browser.previousPageAction.setVisible(false);
\r