OSDN Git Service

Change the editor button bar from a QHBoxLayout to a QToolBar. This will allow the...
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / gui / BrowserWindow.java
1 /*\r
2  * This file is part of NeverNote \r
3  * Copyright 2009 Randy Baumgarte\r
4  * \r
5  * This file may be licensed under the terms of of the\r
6  * GNU General Public License Version 2 (the ``GPL'').\r
7  *\r
8  * Software distributed under the License is distributed\r
9  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either\r
10  * express or implied. See the GPL for the specific language\r
11  * governing rights and limitations.\r
12  *\r
13  * You should have received a copy of the GPL along with this\r
14  * program. If not, go to http://www.gnu.org/licenses/gpl.html\r
15  * or write to the Free Software Foundation, Inc.,\r
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
17  *\r
18  */\r
19 \r
20 package cx.fbn.nevernote.gui;\r
21 \r
22 import java.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.Collections;\r
32 import java.util.Date;\r
33 import java.util.GregorianCalendar;\r
34 import java.util.HashMap;\r
35 import java.util.List;\r
36 \r
37 import com.evernote.edam.limits.Constants;\r
38 import com.evernote.edam.type.Data;\r
39 import com.evernote.edam.type.Note;\r
40 import com.evernote.edam.type.Notebook;\r
41 import com.evernote.edam.type.Resource;\r
42 import com.evernote.edam.type.ResourceAttributes;\r
43 import com.evernote.edam.type.Tag;\r
44 import com.trolltech.qt.core.QByteArray;\r
45 import com.trolltech.qt.core.QDataStream;\r
46 import com.trolltech.qt.core.QDateTime;\r
47 import com.trolltech.qt.core.QEvent;\r
48 import com.trolltech.qt.core.QFile;\r
49 import com.trolltech.qt.core.QFileSystemWatcher;\r
50 import com.trolltech.qt.core.QIODevice;\r
51 import com.trolltech.qt.core.QMimeData;\r
52 import com.trolltech.qt.core.QUrl;\r
53 import com.trolltech.qt.gui.QAction;\r
54 import com.trolltech.qt.gui.QApplication;\r
55 import com.trolltech.qt.gui.QCalendarWidget;\r
56 import com.trolltech.qt.gui.QClipboard;\r
57 import com.trolltech.qt.gui.QColor;\r
58 import com.trolltech.qt.gui.QComboBox;\r
59 import com.trolltech.qt.gui.QDateEdit;\r
60 import com.trolltech.qt.gui.QDesktopServices;\r
61 import com.trolltech.qt.gui.QFileDialog;\r
62 import com.trolltech.qt.gui.QFileDialog.AcceptMode;\r
63 import com.trolltech.qt.gui.QFileDialog.FileMode;\r
64 import com.trolltech.qt.gui.QFontDatabase;\r
65 import com.trolltech.qt.gui.QFormLayout;\r
66 import com.trolltech.qt.gui.QGridLayout;\r
67 import com.trolltech.qt.gui.QHBoxLayout;\r
68 import com.trolltech.qt.gui.QIcon;\r
69 import com.trolltech.qt.gui.QImage;\r
70 import com.trolltech.qt.gui.QKeySequence;\r
71 import com.trolltech.qt.gui.QLabel;\r
72 import com.trolltech.qt.gui.QLineEdit;\r
73 import com.trolltech.qt.gui.QListWidgetItem;\r
74 import com.trolltech.qt.gui.QMatrix;\r
75 import com.trolltech.qt.gui.QMessageBox;\r
76 import com.trolltech.qt.gui.QPushButton;\r
77 import com.trolltech.qt.gui.QShortcut;\r
78 import com.trolltech.qt.gui.QTimeEdit;\r
79 import com.trolltech.qt.gui.QVBoxLayout;\r
80 import com.trolltech.qt.gui.QWidget;\r
81 import com.trolltech.qt.network.QNetworkRequest;\r
82 import com.trolltech.qt.webkit.QWebPage;\r
83 import com.trolltech.qt.webkit.QWebPage.WebAction;\r
84 import com.trolltech.qt.webkit.QWebSettings;\r
85 import com.trolltech.qt.webkit.QWebView;\r
86 \r
87 import cx.fbn.nevernote.Global;\r
88 import cx.fbn.nevernote.dialog.EnCryptDialog;\r
89 import cx.fbn.nevernote.dialog.EnDecryptDialog;\r
90 import cx.fbn.nevernote.dialog.GeoDialog;\r
91 import cx.fbn.nevernote.dialog.InsertLinkDialog;\r
92 import cx.fbn.nevernote.dialog.TableDialog;\r
93 import cx.fbn.nevernote.dialog.TagAssign;\r
94 import cx.fbn.nevernote.evernote.EnCrypt;\r
95 import cx.fbn.nevernote.signals.NoteResourceSignal;\r
96 import cx.fbn.nevernote.signals.NoteSignal;\r
97 import cx.fbn.nevernote.sql.DatabaseConnection;\r
98 import cx.fbn.nevernote.utilities.ApplicationLogger;\r
99 import cx.fbn.nevernote.utilities.FileUtils;\r
100 \r
101 public class BrowserWindow extends QWidget {\r
102 \r
103         public final QLineEdit titleLabel;\r
104         private final QLineEdit urlText;\r
105         private final QLabel authorLabel;\r
106         private final QLineEdit authorText;\r
107         private final QComboBox geoBox;\r
108         public final TagLineEdit tagEdit;\r
109         public final QLabel tagLabel;\r
110         private final QPushButton urlLabel;\r
111         private final QLabel alteredLabel;\r
112         private final QDateEdit alteredDate;\r
113         private final QTimeEdit alteredTime;\r
114         private final QDateEdit createdDate;\r
115         private final QTimeEdit createdTime;\r
116         private final QLabel subjectLabel;\r
117         private final QDateEdit subjectDate;\r
118         private final QTimeEdit subjectTime;\r
119         public final QComboBox notebookBox;\r
120         private final QLabel notebookLabel;\r
121         private final QLabel createdLabel;\r
122         public final QComboBox fontSize;\r
123         public final QAction    fontSizeAction;\r
124         private boolean extendedOn;\r
125         public boolean buttonsVisible;\r
126         private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
127         private final ContentView browser;\r
128         private List<Tag> allTags;\r
129         private List<String> currentTags;\r
130         public NoteSignal noteSignal;\r
131         private List<Notebook> notebookList;\r
132         private Note currentNote;\r
133         private String saveNoteTitle;\r
134         private String saveTagList;\r
135         private boolean insideList;\r
136 //      private String selectedText;\r
137         private final DatabaseConnection conn;\r
138         private final QCalendarWidget createdCalendarWidget;\r
139         private final QCalendarWidget alteredCalendarWidget;\r
140         private final QCalendarWidget subjectCalendarWidget;\r
141 \r
142         public final QPushButton undoButton;\r
143         public final QAction    undoAction;\r
144         public final QPushButton redoButton;\r
145         public final QAction    redoAction;\r
146         public final QPushButton cutButton;\r
147         public final QAction    cutAction;\r
148         public final QPushButton copyButton;\r
149         public final QAction    copyAction;\r
150         public final QPushButton pasteButton;\r
151         public final QAction    pasteAction;\r
152         public final QPushButton boldButton;\r
153         public final QAction    boldAction;\r
154         public final QPushButton underlineButton;\r
155         public final QAction    underlineAction;\r
156         public final QPushButton italicButton;\r
157         public final QAction    italicAction;\r
158         public final Signal0 focusLost;\r
159         public final NoteResourceSignal resourceSignal;\r
160 \r
161         public QPushButton rightAlignButton;\r
162         public final QAction    rightAlignAction;\r
163         public QPushButton leftAlignButton;\r
164         public final QAction    leftAlignAction;\r
165         public QPushButton centerAlignButton;\r
166         public final QAction    centerAlignAction;\r
167 \r
168         public final QPushButton strikethroughButton;\r
169         public final QAction    strikethroughAction;\r
170         public final QPushButton hlineButton;\r
171         public final QAction    hlineAction;\r
172         public final QPushButton indentButton;\r
173         public final QAction    indentAction;\r
174         public final QPushButton outdentButton;\r
175         public final QAction    outdentAction;\r
176         public final QPushButton bulletListButton;\r
177         public final QAction    bulletListAction;\r
178         public final QPushButton numberListButton;\r
179         public final QAction    numberListAction;\r
180 \r
181         public final QShortcut focusTitleShortcut;\r
182         public final QShortcut focusTagShortcut;\r
183         public final QShortcut focusNoteShortcut;\r
184         public final QShortcut focusUrlShortcut;\r
185         public final QShortcut focusAuthorShortcut;\r
186         \r
187         public EditorButtonBar buttonLayout;\r
188         public final QComboBox fontList;\r
189         public final QAction    fontListAction;\r
190         public final QPushButton fontColor;\r
191         public final QAction    fontColorAction;\r
192         private final ColorMenu fontColorMenu;\r
193         public final QPushButton fontHilight;\r
194         public final QAction    fontHilightAction;\r
195 //      public final ColorComboBox fontHilight;\r
196         private final ColorMenu fontHilightColorMenu;\r
197         public final QFileSystemWatcher fileWatcher;\r
198         public int cursorPosition;\r
199         private boolean forceTextPaste = false;\r
200         private String selectedFile;\r
201         private String currentHyperlink;\r
202         public boolean keepPDFNavigationHidden;\r
203         private final ApplicationLogger logger;\r
204         \r
205         private final HashMap<String,Integer> previewPageList; \r
206         \r
207         \r
208         public BrowserWindow(DatabaseConnection c) {\r
209                 logger = new ApplicationLogger("browser.log");\r
210                 logger.log(logger.HIGH, "Setting up browser");\r
211                 \r
212                 fileWatcher = new QFileSystemWatcher();\r
213 //              fileWatcher.fileChanged.connect(this, "fileChanged(String)");\r
214                 noteSignal = new NoteSignal();\r
215                 titleLabel = new QLineEdit();\r
216                 titleLabel.setMaxLength(Constants.EDAM_NOTE_TITLE_LEN_MAX);\r
217                 urlText = new QLineEdit();\r
218                 authorText = new QLineEdit();\r
219                 geoBox = new QComboBox();\r
220                 urlLabel = new QPushButton();\r
221                 urlLabel.clicked.connect(this, "sourceUrlClicked()");\r
222                 authorLabel = new QLabel();\r
223                 conn = c;\r
224                 \r
225                 focusLost = new Signal0();\r
226 \r
227                 tagEdit = new TagLineEdit(allTags);\r
228                 tagLabel = new QLabel("Tags:");\r
229                 tagEdit.focusLost.connect(this, "modifyTagsTyping()");\r
230 \r
231                 createdCalendarWidget = new QCalendarWidget();\r
232                 createdDate = new QDateEdit();\r
233                 createdDate.setDisplayFormat(Global.getDateFormat());\r
234                 createdDate.setCalendarPopup(true);\r
235                 createdDate.setCalendarWidget(createdCalendarWidget);\r
236                 createdTime = new QTimeEdit();\r
237                 createdDate.dateChanged.connect(this, "createdChanged()");\r
238                 createdTime.timeChanged.connect(this, "createdChanged()");\r
239 \r
240                 alteredCalendarWidget = new QCalendarWidget();\r
241                 alteredDate = new QDateEdit();\r
242                 alteredDate.setDisplayFormat(Global.getDateFormat());\r
243                 alteredDate.setCalendarPopup(true);\r
244                 alteredDate.setCalendarWidget(alteredCalendarWidget);\r
245                 alteredTime = new QTimeEdit();\r
246                 alteredLabel = new QLabel("Altered:");\r
247                 alteredDate.dateChanged.connect(this, "alteredChanged()");\r
248                 alteredTime.timeChanged.connect(this, "alteredChanged()");\r
249 \r
250                 subjectCalendarWidget = new QCalendarWidget();\r
251                 subjectDate = new QDateEdit();\r
252                 subjectDate.setDisplayFormat(Global.getDateFormat());\r
253                 subjectDate.setCalendarPopup(true);\r
254                 subjectDate.setCalendarWidget(subjectCalendarWidget);\r
255                 subjectTime = new QTimeEdit();\r
256                 subjectLabel = new QLabel(tr("Subject Date:"));\r
257                 subjectDate.dateChanged.connect(this, "subjectDateTimeChanged()");\r
258                 subjectTime.timeChanged.connect(this, "subjectDateTimeChanged()");\r
259                 authorText.textChanged.connect(this, "authorChanged()");\r
260                 urlText.textChanged.connect(this, "sourceUrlChanged()");\r
261 \r
262                 notebookBox = new QComboBox();\r
263                 notebookLabel = new QLabel(tr("Notebook"));\r
264                 createdLabel = new QLabel(tr("Created:"));\r
265                 // selectedText = new String();\r
266 \r
267                 urlLabel.setVisible(false);\r
268                 urlText.setVisible(false);\r
269                 authorLabel.setVisible(false);\r
270                 \r
271                 geoBox.setVisible(false);\r
272                 geoBox.addItem(new QIcon(iconPath+"globe.png"), "");\r
273                 geoBox.addItem(new String(tr("Set")));\r
274                 geoBox.addItem(new String(tr("Clear")));\r
275                 geoBox.addItem(new String(tr("View On Map")));\r
276                 geoBox.activated.connect(this, "geoBoxChanged()");\r
277                 \r
278                 authorText.setVisible(false);\r
279                 createdDate.setVisible(false);\r
280                 alteredLabel.setVisible(false);\r
281                 //notebookBox.setVisible(false);\r
282                 notebookLabel.setVisible(false);\r
283                 createdLabel.setVisible(false);\r
284                 createdTime.setVisible(false);\r
285                 alteredDate.setVisible(false);\r
286                 alteredTime.setVisible(false);\r
287                 subjectLabel.setVisible(false);\r
288                 subjectDate.setVisible(false);\r
289                 subjectTime.setVisible(false);\r
290                 extendedOn = false;\r
291                 buttonsVisible = true;\r
292                 setAcceptDrops(true);\r
293 \r
294                 browser = new ContentView(this);\r
295                 browser.page().setLinkDelegationPolicy(\r
296                                 QWebPage.LinkDelegationPolicy.DelegateAllLinks);\r
297                 browser.linkClicked.connect(this, "linkClicked(QUrl)");\r
298                 currentHyperlink = "";\r
299                 \r
300                 QVBoxLayout v = new QVBoxLayout();\r
301                 QFormLayout notebookLayout = new QFormLayout();\r
302                 QGridLayout dateLayout = new QGridLayout();\r
303                 titleLabel.setReadOnly(false);\r
304                 titleLabel.editingFinished.connect(this, "titleEdited()");\r
305                 browser.page().contentsChanged.connect(this, "contentChanged()");\r
306                 browser.page().selectionChanged.connect(this, "selectionChanged()");\r
307                 browser.page().mainFrame().javaScriptWindowObjectCleared.connect(this,\r
308                                 "exposeToJavascript()");\r
309 \r
310                 notebookBox.activated.connect(this, "notebookChanged()");\r
311                 resourceSignal = new NoteResourceSignal();\r
312                 \r
313                 QHBoxLayout tagLayout = new QHBoxLayout();\r
314                 v.addWidget(titleLabel, 0);\r
315                 notebookLayout.addRow(notebookLabel, notebookBox);\r
316                 tagLayout.addLayout(notebookLayout, 0);\r
317                 tagLayout.stretch(4);\r
318                 tagLayout.addWidget(tagLabel, 0);\r
319                 tagLayout.addWidget(tagEdit, 1);\r
320                 v.addLayout(tagLayout);\r
321 \r
322                 QHBoxLayout urlLayout = new QHBoxLayout();\r
323                 urlLayout.addWidget(urlLabel, 0);\r
324                 urlLayout.addWidget(urlText, 0);\r
325                 v.addLayout(urlLayout);\r
326 \r
327                 QHBoxLayout authorLayout = new QHBoxLayout();\r
328                 authorLayout.addWidget(authorLabel, 0);\r
329                 authorLayout.addWidget(authorText, 0);\r
330                 authorLayout.addWidget(geoBox);\r
331                 v.addLayout(authorLayout);\r
332 \r
333                 dateLayout.addWidget(createdLabel, 0, 0);\r
334                 dateLayout.addWidget(createdDate, 0, 1);\r
335                 dateLayout.addWidget(createdTime, 0, 2);\r
336                 dateLayout.setColumnStretch(9, 100);\r
337                 dateLayout.addWidget(alteredLabel, 0, 3);\r
338                 dateLayout.addWidget(alteredDate, 0, 4);\r
339                 dateLayout.addWidget(alteredTime, 0, 5);\r
340                 dateLayout.addWidget(subjectLabel, 0, 6);\r
341                 dateLayout.addWidget(subjectDate, 0, 7);\r
342                 dateLayout.addWidget(subjectTime, 0, 8);\r
343                 v.addLayout(dateLayout, 0);\r
344 \r
345                 undoButton = newEditorButton("undo", tr("Undo Change"));\r
346                 redoButton = newEditorButton("redo", tr("Redo Change"));\r
347                 cutButton = newEditorButton("cut", tr("Cut"));\r
348                 copyButton = newEditorButton("copy", tr("Copy"));\r
349                 pasteButton = newEditorButton("paste", tr("Paste"));\r
350                 boldButton = newEditorButton("bold", tr("Bold"));\r
351                 underlineButton = newEditorButton("underline", tr("Underline"));\r
352                 italicButton = newEditorButton("italic", tr("Italic"));\r
353 \r
354                 rightAlignButton = newEditorButton("justifyRight", tr("Right Align"));\r
355                 leftAlignButton = newEditorButton("justifyLeft", tr("Left Align"));\r
356                 centerAlignButton = newEditorButton("justifyCenter", tr("Center Align"));\r
357 \r
358                 strikethroughButton = newEditorButton("strikethrough", tr("Strikethrough"));\r
359                 hlineButton = newEditorButton("hline", tr("Insert Horizontal Line"));\r
360                 indentButton = newEditorButton("indent", tr("Shift Right"));\r
361                 outdentButton = newEditorButton("outdent", tr("Shift Left"));\r
362                 bulletListButton = newEditorButton("bulletList", tr("Bullet List"));\r
363                 numberListButton = newEditorButton("numberList", tr("Number List"));\r
364 \r
365                 \r
366                 buttonLayout = new EditorButtonBar();\r
367 //              buttonLayout.setSpacing(0);\r
368                 v.addWidget(buttonLayout);\r
369                 \r
370                 undoAction = buttonLayout.addWidget(undoButton);\r
371                 buttonLayout.toggleUndoVisible.triggered.connect(this, "toggleUndoVisible(Boolean)");\r
372                 redoAction = buttonLayout.addWidget(redoButton);\r
373                 buttonLayout.toggleRedoVisible.triggered.connect(this, "toggleRedoVisible(Boolean)");\r
374                 \r
375                 buttonLayout.addWidget(newSeparator());\r
376                 cutAction = buttonLayout.addWidget(cutButton);\r
377                 buttonLayout.toggleCutVisible.triggered.connect(this, "toggleCutVisible(Boolean)");\r
378                 copyAction = buttonLayout.addWidget(copyButton);\r
379                 buttonLayout.toggleCopyVisible.triggered.connect(this, "toggleCopyVisible(Boolean)");\r
380                 pasteAction = buttonLayout.addWidget(pasteButton);\r
381                 buttonLayout.togglePasteVisible.triggered.connect(this, "togglePasteVisible(Boolean)");\r
382 \r
383                 buttonLayout.addWidget(newSeparator());\r
384                 boldAction = buttonLayout.addWidget(boldButton);\r
385                 buttonLayout.toggleBoldVisible.triggered.connect(this, "toggleBoldVisible(Boolean)");\r
386                 italicAction = buttonLayout.addWidget(italicButton);\r
387                 buttonLayout.toggleItalicVisible.triggered.connect(this, "toggleItalicVisible(Boolean)");\r
388                 underlineAction = buttonLayout.addWidget(underlineButton);\r
389                 buttonLayout.toggleUnderlineVisible.triggered.connect(this, "toggleUnderlineVisible(Boolean)");\r
390                 strikethroughAction = buttonLayout.addWidget(strikethroughButton);\r
391                 buttonLayout.toggleStrikethroughVisible.triggered.connect(this, "toggleStrikethroughVisible(Boolean)");\r
392 \r
393                 \r
394                 buttonLayout.addWidget(newSeparator());\r
395                 leftAlignAction = buttonLayout.addWidget(leftAlignButton);\r
396                 buttonLayout.toggleLeftAlignVisible.triggered.connect(this, "toggleLeftAlignVisible(Boolean)");\r
397                 centerAlignAction = buttonLayout.addWidget(centerAlignButton);\r
398                 buttonLayout.toggleCenterAlignVisible.triggered.connect(this, "toggleCenterAlignVisible(Boolean)");\r
399                 rightAlignAction = buttonLayout.addWidget(rightAlignButton);\r
400                 buttonLayout.toggleRightAlignVisible.triggered.connect(this, "toggleRightAlignVisible(Boolean)");\r
401 \r
402                 buttonLayout.addWidget(newSeparator());\r
403                 hlineAction = buttonLayout.addWidget(hlineButton);\r
404                 buttonLayout.toggleHLineVisible.triggered.connect(this, "toggleHLineVisible(Boolean)");\r
405 \r
406                 indentAction = buttonLayout.addWidget(indentButton);\r
407                 buttonLayout.toggleIndentVisible.triggered.connect(this, "toggleIndentVisible(Boolean)");\r
408                 outdentAction = buttonLayout.addWidget(outdentButton);\r
409                 buttonLayout.toggleOutdentVisible.triggered.connect(this, "toggleOutdentVisible(Boolean)");\r
410                 bulletListAction = buttonLayout.addWidget(bulletListButton);\r
411                 buttonLayout.toggleBulletListVisible.triggered.connect(this, "toggleBulletListVisible(Boolean)");\r
412                 numberListAction = buttonLayout.addWidget(numberListButton);\r
413                 buttonLayout.toggleNumberListVisible.triggered.connect(this, "toggleNumberListVisible(Boolean)");\r
414 \r
415                 // Setup the font & font size combo boxes\r
416                 buttonLayout.addWidget(newSeparator());\r
417                 fontList = new QComboBox();\r
418                 fontSize = new QComboBox();\r
419                 fontList.setToolTip("Font");\r
420                 fontSize.setToolTip("Font Size");\r
421                 fontList.activated.connect(this, "fontChanged(String)");\r
422                 fontSize.activated.connect(this, "fontSizeChanged(String)");\r
423                 fontListAction = buttonLayout.addWidget(fontList);\r
424                 buttonLayout.toggleFontVisible.triggered.connect(this, "toggleFontListVisible(Boolean)");\r
425                 fontSizeAction = buttonLayout.addWidget(fontSize);\r
426                 buttonLayout.toggleFontSizeVisible.triggered.connect(this, "toggleFontSizeVisible(Boolean)");\r
427                 QFontDatabase fonts = new QFontDatabase();\r
428                 List<String> fontFamilies = fonts.families();\r
429                 for (int i = 0; i < fontFamilies.size(); i++) {\r
430                         fontList.addItem(fontFamilies.get(i));\r
431                         if (i == 0) {\r
432                                 loadFontSize(fontFamilies.get(i));\r
433                         }\r
434                 }\r
435 \r
436 //              buttonLayout.addWidget(newSeparator(), 0);\r
437                 fontColor = newEditorButton("fontColor", tr("Font Color"));\r
438                 fontColorMenu = new ColorMenu(this);\r
439                 fontColor.setMenu(fontColorMenu.getMenu());\r
440                 fontColorMenu.getMenu().triggered.connect(this, "fontColorClicked()");\r
441                 fontColorAction = buttonLayout.addWidget(fontColor);\r
442                 buttonLayout.toggleFontColorVisible.triggered.connect(this, "toggleFontColorVisible(Boolean)");\r
443                 fontHilight = newEditorButton("fontHilight", tr("Font Hilight Color"));\r
444                 fontHilightColorMenu = new ColorMenu(this);\r
445                 fontHilight.setMenu(fontHilightColorMenu.getMenu());\r
446                 fontHilightColorMenu.getMenu().triggered.connect(this, "fontHilightClicked()");\r
447                 fontHilightAction = buttonLayout.addWidget(fontHilight);\r
448                 buttonLayout.toggleFontHilight.triggered.connect(this, "toggleFontHilightVisible(Boolean)");\r
449 \r
450 //              buttonLayout.addWidget(new QLabel(), 1);\r
451                 v.addWidget(browser, 1);\r
452                 setLayout(v);\r
453 \r
454                 browser.downloadAttachmentRequested.connect(this,\r
455                                 "downloadAttachment(QNetworkRequest)");\r
456                 browser.downloadImageRequested.connect(this,\r
457                                 "downloadImage(QNetworkRequest)");\r
458                 setTabOrder(notebookBox, tagEdit);\r
459                 setTabOrder(tagEdit, browser);\r
460                 \r
461                 focusNoteShortcut = new QShortcut(this);\r
462                 setupShortcut(focusNoteShortcut, "Focus_Note");\r
463                 focusNoteShortcut.activated.connect(this, "focusNote()");\r
464                 focusTitleShortcut = new QShortcut(this);\r
465                 setupShortcut(focusTitleShortcut, "Focus_Title");\r
466                 focusTitleShortcut.activated.connect(this, "focusTitle()");\r
467                 focusTagShortcut = new QShortcut(this);\r
468                 setupShortcut(focusTagShortcut, "Focus_Tag");\r
469                 focusTagShortcut.activated.connect(this, "focusTag()");\r
470                 focusAuthorShortcut = new QShortcut(this);\r
471                 setupShortcut(focusAuthorShortcut, "Focus_Author");\r
472                 focusAuthorShortcut.activated.connect(this, "focusAuthor()");\r
473                 focusUrlShortcut = new QShortcut(this);\r
474                 setupShortcut(focusUrlShortcut, "Focus_Url");\r
475                 focusUrlShortcut.activated.connect(this, "focusUrl()");\r
476                 \r
477                 browser.page().mainFrame().setTextSizeMultiplier(Global.getTextSizeMultiplier());\r
478                 browser.page().mainFrame().setZoomFactor(Global.getZoomFactor());\r
479                 \r
480                  previewPageList = new HashMap<String,Integer>();\r
481                 \r
482                 browser.page().microFocusChanged.connect(this, "microFocusChanged()");\r
483                 logger.log(logger.HIGH, "Browser setup complete");\r
484         }\r
485 \r
486         \r
487         private void setupShortcut(QShortcut action, String text) {\r
488                 if (!Global.shortcutKeys.containsAction(text))\r
489                         return;\r
490                 action.setKey(new QKeySequence(Global.shortcutKeys.getShortcut(text)));\r
491         }\r
492         \r
493         \r
494 \r
495         \r
496         // Getter for the QWebView\r
497         public QWebView getBrowser() {\r
498                 return browser;\r
499         }\r
500 \r
501         // Block signals while loading data or things are flagged as dirty by\r
502         // mistake\r
503         public void loadingData(boolean val) {\r
504                 logger.log(logger.EXTREME, "Entering BrowserWindow.loadingData() " +val);\r
505                 notebookBox.blockSignals(val);\r
506                 browser.page().blockSignals(val);\r
507                 browser.page().mainFrame().blockSignals(val);\r
508                 titleLabel.blockSignals(val);\r
509                 alteredDate.blockSignals(val);\r
510                 alteredTime.blockSignals(val);\r
511                 createdTime.blockSignals(val);\r
512                 createdDate.blockSignals(val);\r
513                 subjectDate.blockSignals(val);\r
514                 subjectTime.blockSignals(val);\r
515                 urlText.blockSignals(val);\r
516                 authorText.blockSignals(val);\r
517                 if (!val)\r
518                         exposeToJavascript();\r
519                 logger.log(logger.EXTREME, "Exiting BrowserWindow.loadingData() " +val);\r
520         }\r
521 \r
522         // Enable/disable\r
523         public void setReadOnly(boolean v) {\r
524                 setEnabled(true);\r
525                 titleLabel.setEnabled(!v);\r
526                 notebookBox.setEnabled(!v);\r
527                 tagEdit.setEnabled(!v);\r
528                 authorLabel.setEnabled(!v);\r
529                 geoBox.setEnabled(!v);\r
530                 urlText.setEnabled(!v);\r
531                 createdDate.setEnabled(!v);\r
532                 subjectDate.setEnabled(!v);\r
533                 alteredDate.setEnabled(!v);\r
534                 getBrowser().setEnabled(true);\r
535         }\r
536         \r
537         // expose this class to Javascript on the web page\r
538         private void exposeToJavascript() {\r
539                 browser.page().mainFrame().addToJavaScriptWindowObject("jambi", this);\r
540         }\r
541 \r
542         // Custom event queue\r
543         @Override\r
544         public boolean event(QEvent e) {\r
545                 if (e.type().equals(QEvent.Type.FocusOut)) {\r
546                         logger.log(logger.EXTREME, "Focus lost");\r
547                         focusLost.emit();\r
548                 }\r
549                 return super.event(e);\r
550         }\r
551 \r
552         // clear out browser\r
553         public void clear() {\r
554                 logger.log(logger.EXTREME, "Entering BrowserWindow.clear()");\r
555                 setNote(null);\r
556                 browser.setContent(new QByteArray());\r
557                 tagEdit.setText("");\r
558                 tagEdit.tagCompleter.reset();\r
559                 urlLabel.setText(tr("Source URL:"));\r
560                 titleLabel.setText("");\r
561                 logger.log(logger.EXTREME, "Exiting BrowserWindow.clear()");\r
562         }\r
563 \r
564         // get/set current note\r
565         public void setNote(Note n) {\r
566                 currentNote = n;\r
567                 if (n == null)\r
568                         n = new Note();\r
569                 saveNoteTitle = n.getTitle();\r
570 \r
571         }\r
572 \r
573         public Note getNote() {\r
574                 return currentNote;\r
575         }\r
576 \r
577         // New Editor Button\r
578         private QPushButton newEditorButton(String name, String toolTip) {\r
579                 QPushButton button = new QPushButton();\r
580                 QIcon icon = new QIcon(iconPath + name + ".gif");\r
581                 button.setIcon(icon);\r
582                 button.setToolTip(toolTip);\r
583                 button.clicked.connect(this, name + "Clicked()");\r
584                 return button;\r
585         }\r
586 \r
587         // New Separator\r
588         private QLabel newSeparator() {\r
589                 return new QLabel("   ");\r
590         }\r
591 \r
592         // Set the title in the window\r
593         public void setTitle(String t) {\r
594                 titleLabel.setText(t);\r
595                 saveNoteTitle = t;\r
596                 checkNoteTitle();\r
597         }\r
598 \r
599         // Return the current text title\r
600         public String getTitle() {\r
601                 return titleLabel.text();\r
602         }\r
603 \r
604         // Set the tag name string\r
605         public void setTag(String t) {\r
606                 saveTagList = t;\r
607                 tagEdit.setText(t);\r
608                 tagEdit.tagCompleter.reset();\r
609         }\r
610 \r
611         // Set the source URL\r
612         public void setUrl(String t) {\r
613                 urlLabel.setText(tr("Source URL:\t"));\r
614                 urlText.setText(t);\r
615         }\r
616 \r
617         // The user want's to launch a web browser on the source of the URL\r
618         public void sourceUrlClicked() {\r
619                 // Make sure we have a valid URL\r
620                 if (urlText.text().trim().equals(""))\r
621                         return;\r
622                 \r
623                 String url = urlText.text();\r
624                 if (!url.toLowerCase().startsWith(tr("http://")))\r
625                         url = tr("http://") +url;\r
626                 \r
627         if (!QDesktopServices.openUrl(new QUrl(url))) {\r
628                 logger.log(logger.LOW, "Error opening file :" +url);\r
629         }\r
630         }\r
631         \r
632         public void setAuthor(String t) {\r
633                 authorLabel.setText(tr("Author:\t"));\r
634                 authorText.setText(t);\r
635         }\r
636 \r
637         // Set the creation date\r
638         public void setCreation(long date) {\r
639                 QDateTime dt = new QDateTime();\r
640                 dt.setTime_t((int) (date / 1000));\r
641                 createdDate.setDateTime(dt);\r
642                 createdTime.setDateTime(dt);\r
643                 createdDate.setDisplayFormat(Global.getDateFormat());\r
644                 createdTime.setDisplayFormat(Global.getTimeFormat());\r
645         }\r
646 \r
647         // Set the creation date\r
648         public void setAltered(long date) {\r
649                 QDateTime dt = new QDateTime();\r
650                 dt.setTime_t((int) (date / 1000));\r
651                 alteredDate.setDateTime(dt);\r
652                 alteredTime.setDateTime(dt);\r
653                 alteredDate.setDisplayFormat(Global.getDateFormat());\r
654                 alteredTime.setDisplayFormat(Global.getTimeFormat());\r
655         }\r
656 \r
657         // Set the subject date\r
658         public void setSubjectDate(long date) {\r
659                 QDateTime dt = new QDateTime();\r
660                 dt.setTime_t((int) (date / 1000));\r
661                 subjectDate.setDateTime(dt);\r
662                 subjectTime.setDateTime(dt);\r
663                 subjectDate.setDisplayFormat(Global.getDateFormat());\r
664                 subjectTime.setDisplayFormat(Global.getTimeFormat());\r
665         }\r
666 \r
667         // Toggle the extended attribute information\r
668         public void toggleInformation() {\r
669                 if (extendedOn) {\r
670                         extendedOn = false;\r
671                 } else {\r
672                         extendedOn = true;\r
673                 }\r
674                 urlLabel.setVisible(extendedOn);\r
675                 urlText.setVisible(extendedOn);\r
676                 authorText.setVisible(extendedOn);\r
677                 geoBox.setVisible(extendedOn);\r
678                 authorLabel.setVisible(extendedOn);\r
679                 createdDate.setVisible(extendedOn);\r
680                 createdTime.setVisible(extendedOn);\r
681                 createdLabel.setVisible(extendedOn);\r
682                 alteredLabel.setVisible(extendedOn);\r
683                 alteredDate.setVisible(extendedOn);\r
684                 alteredTime.setVisible(extendedOn);\r
685                 //notebookBox.setVisible(extendedOn);\r
686                 notebookLabel.setVisible(extendedOn);\r
687                 subjectLabel.setVisible(extendedOn);\r
688                 subjectDate.setVisible(extendedOn);\r
689                 subjectTime.setVisible(extendedOn);\r
690         }\r
691 \r
692         public void hideButtons() {\r
693 \r
694                 undoButton.parentWidget().setVisible(false);\r
695                 buttonsVisible = false;\r
696         }\r
697 \r
698 \r
699         // Is the extended view on?\r
700         public boolean isExtended() {\r
701                 return extendedOn;\r
702         }\r
703 \r
704         // Listener for when a link is clicked\r
705         @SuppressWarnings("unused")\r
706         private void openFile() {\r
707                 logger.log(logger.EXTREME, "Starting openFile()");\r
708                 File fileHandle = new File(selectedFile);\r
709                 URI fileURL = fileHandle.toURI();\r
710                 String localURL = fileURL.toString();\r
711                 QUrl url = new QUrl(localURL);\r
712                 QFile file = new QFile(selectedFile);\r
713                 \r
714                 logger.log(logger.EXTREME, "Adding to fileWatcher:"+file.fileName());\r
715                 fileWatcher.addPath(file.fileName());\r
716         \r
717         if (!QDesktopServices.openUrl(url)) {\r
718                 logger.log(logger.LOW, "Error opening file :" +url);\r
719         }\r
720         }\r
721         \r
722         \r
723         // Listener for when a link is clicked\r
724         @SuppressWarnings("unused")\r
725         private void linkClicked(QUrl url) {\r
726                 logger.log(logger.EXTREME, "URL Clicked: " +url.toString());\r
727                 if (url.toString().substring(0,8).equals("nnres://")) {\r
728                         logger.log(logger.EXTREME, "URL is NN resource");\r
729                         if (url.toString().endsWith("/vnd.evernote.ink")) {\r
730                                 logger.log(logger.EXTREME, "Unable to open ink note");\r
731                                 QMessageBox.information(this, tr("Unable Open"), tr("This is an ink note.\n"+\r
732                                         "Ink notes are not supported since Evernote has not\n published any specifications on them\n" +\r
733                                         "and I'm too lazy to figure them out by myself."));\r
734                                 return;\r
735                         }\r
736                         String fullName = url.toString().substring(8);\r
737                         int index = fullName.indexOf(".");\r
738                         String guid = "";\r
739                         String type = "";\r
740                         if (index >-1) {\r
741                                 type = fullName.substring(index+1);\r
742                                 guid = fullName.substring(0,index);\r
743                         }\r
744                         index = guid.indexOf(Global.attachmentNameDelimeter);\r
745                         if (index > -1) {\r
746                                 guid = guid.substring(0,index);\r
747                         }\r
748                         List<Resource> resList = currentNote.getResources();\r
749                         Resource res = null;\r
750                         for (int i=0; i<resList.size(); i++) {\r
751                                 if (resList.get(i).getGuid().equals(guid)) {\r
752                                         res = resList.get(i);\r
753                                         i=resList.size();\r
754                                 }\r
755                         }\r
756                         if (res == null) {\r
757                                 String resGuid = Global.resourceMap.get(guid);\r
758                                 if (resGuid != null) \r
759                                         res = conn.getNoteTable().noteResourceTable.getNoteResource(resGuid, true);\r
760                         }\r
761                         if (res != null) {\r
762                                 String fileName;\r
763                                 if (res.getAttributes() != null && \r
764                                                 res.getAttributes().getFileName() != null && \r
765                                                 !res.getAttributes().getFileName().trim().equals(""))\r
766                                         fileName = res.getGuid()+Global.attachmentNameDelimeter+res.getAttributes().getFileName();\r
767                                 else\r
768                                         fileName = res.getGuid()+"."+type;\r
769                                 QFile file = new QFile(Global.getFileManager().getResDirPath(fileName));\r
770                         QFile.OpenMode mode = new QFile.OpenMode();\r
771                         mode.set(QFile.OpenModeFlag.WriteOnly);\r
772                         boolean openResult = file.open(mode);\r
773                                 logger.log(logger.EXTREME, "File opened:" +openResult);\r
774                         QDataStream out = new QDataStream(file);\r
775                         Resource resBinary = conn.getNoteTable().noteResourceTable.getNoteResource(res.getGuid(), true);\r
776                                 QByteArray binData = new QByteArray(resBinary.getData().getBody());\r
777                                 resBinary = null;\r
778                                 logger.log(logger.EXTREME, "Writing resource");\r
779                         out.writeBytes(binData.toByteArray());\r
780                         file.close();\r
781                                 \r
782                         String whichOS = System.getProperty("os.name");\r
783                                 if (whichOS.contains("Windows")) \r
784                                 url.setUrl("file:///"+file.fileName());\r
785                         else\r
786                                 url.setUrl("file://"+file.fileName());\r
787                  //       fileWatcher.removePath(file.fileName());\r
788                                 logger.log(logger.EXTREME, "Adding file watcher " +file.fileName());\r
789                                 fileWatcher.addPath(file.fileName());\r
790                         \r
791                         // If we can't open it, then prompt the user to save it.\r
792                         if (!QDesktopServices.openUrl(url)) {\r
793                                         logger.log(logger.EXTREME, "We can't handle this.  Where do we put it?");\r
794                                 QFileDialog dialog = new QFileDialog();\r
795                                 dialog.show();\r
796                                 if (dialog.exec()!=0) {\r
797                                         List<String> fileNames = dialog.selectedFiles(); //gets all selected filenames\r
798                                         if (fileNames.size() == 0) \r
799                                                 return;\r
800                                         String sf = fileNames.get(0);\r
801                                         QFile saveFile = new QFile(sf);\r
802                                         mode.set(QFile.OpenModeFlag.WriteOnly);\r
803                                         saveFile.open(mode);\r
804                                         QDataStream saveOut = new QDataStream(saveFile);\r
805                                         saveOut.writeBytes(binData.toByteArray());\r
806                                         saveFile.close();\r
807                                         return;\r
808                                 }\r
809                                 }\r
810                         }\r
811                         return;\r
812                 }\r
813                 logger.log(logger.EXTREME, "Launching URL");\r
814                 QDesktopServices.openUrl(url);\r
815         }\r
816 \r
817         // Listener for when BOLD is clicked\r
818         @SuppressWarnings("unused")\r
819         private void undoClicked() {\r
820                 browser.page().triggerAction(WebAction.Undo);\r
821                 browser.setFocus();\r
822         }\r
823 \r
824         // Listener for when BOLD is clicked\r
825         @SuppressWarnings("unused")\r
826         private void redoClicked() {\r
827                 browser.page().triggerAction(WebAction.Redo);\r
828                 browser.setFocus();\r
829         }\r
830 \r
831         // Listener for when BOLD is clicked\r
832         @SuppressWarnings("unused")\r
833         private void boldClicked() {\r
834                 browser.page().triggerAction(WebAction.ToggleBold);\r
835                 microFocusChanged();\r
836                 browser.setFocus();\r
837         }\r
838 \r
839         // Listener for when Italics is clicked\r
840         @SuppressWarnings("unused")\r
841         private void italicClicked() {\r
842                 browser.page().triggerAction(WebAction.ToggleItalic);\r
843                 microFocusChanged();\r
844                 browser.setFocus();\r
845         }\r
846 \r
847         // Listener for when UNDERLINE is clicked\r
848         @SuppressWarnings("unused")\r
849         private void underlineClicked() {\r
850                 browser.page().triggerAction(WebAction.ToggleUnderline);\r
851                 microFocusChanged();\r
852                 browser.setFocus();\r
853         }\r
854 \r
855         // Listener for when Strikethrough is clicked\r
856         @SuppressWarnings("unused")\r
857         private void strikethroughClicked() {\r
858                 browser.page().mainFrame().evaluateJavaScript(\r
859                                 "document.execCommand('strikeThrough', false, '');");\r
860                 browser.setFocus();\r
861         }\r
862 \r
863         // Listener for when cut is clicked\r
864         @SuppressWarnings("unused")\r
865         private void cutClicked() {\r
866                 browser.page().triggerAction(WebAction.Cut);\r
867                 browser.setFocus();\r
868         }\r
869 \r
870         // Listener when COPY is clicked\r
871         @SuppressWarnings("unused")\r
872         private void copyClicked() {\r
873                 browser.page().triggerAction(WebAction.Copy);\r
874                 browser.setFocus();\r
875         }\r
876 \r
877         // Listener when PASTE is clicked\r
878         void pasteClicked() {\r
879                 logger.log(logger.EXTREME, "Paste Clicked");\r
880                 if (forceTextPaste) {\r
881                         pasteWithoutFormattingClicked();\r
882                         return;\r
883                 }\r
884                 QClipboard clipboard = QApplication.clipboard();\r
885                 QMimeData mime = clipboard.mimeData();\r
886                 \r
887 //               String x = mime.html();\r
888 \r
889                 if (mime.hasImage()) {\r
890                         logger.log(logger.EXTREME, "Image paste found");\r
891                         insertImage(mime);\r
892                         browser.setFocus();\r
893                         return;\r
894                 }\r
895 \r
896                 if (mime.hasUrls()) {\r
897                         logger.log(logger.EXTREME, "URL paste found");\r
898                         handleUrls(mime);\r
899                         browser.setFocus();\r
900                         return;\r
901                 }\r
902                 \r
903                 String text = mime.html();\r
904                 if (text.contains("en-tag") && mime.hasHtml()) {\r
905                         logger.log(logger.EXTREME, "Intra-note paste found");\r
906                         text = fixInternotePaste(text);\r
907                         mime.setHtml(text);\r
908                         clipboard.setMimeData(mime);\r
909                 }\r
910 \r
911                 logger.log(logger.EXTREME, "Final paste choice encountered");\r
912                 browser.page().triggerAction(WebAction.Paste);\r
913                 browser.setFocus();\r
914 \r
915         }\r
916 \r
917         // Paste text without formatting\r
918         private void pasteWithoutFormattingClicked() {\r
919                 logger.log(logger.EXTREME, "Paste without format clipped");\r
920                 QClipboard clipboard = QApplication.clipboard();\r
921                 QMimeData mime = clipboard.mimeData();\r
922                 if (!mime.hasText())\r
923                         return;\r
924                 String text = mime.text();\r
925                 clipboard.setText(text);\r
926                 browser.page().triggerAction(WebAction.Paste);\r
927                 QApplication.clipboard().setMimeData(mime);\r
928                 browser.setFocus();\r
929 \r
930         }\r
931         \r
932         // insert date/time\r
933         @SuppressWarnings("unused")\r
934         private void insertDateTime() {\r
935                 String fmt = Global.getDateFormat() + " " + Global.getTimeFormat();\r
936                 String dateTimeFormat = new String(fmt);\r
937                 SimpleDateFormat simple = new SimpleDateFormat(dateTimeFormat);\r
938                 Calendar cal = Calendar.getInstance();\r
939                 \r
940                 browser.page().mainFrame().evaluateJavaScript(\r
941                         "document.execCommand('insertHtml', false, '"+simple.format(cal.getTime())+"');");\r
942                 \r
943                 browser.setFocus();\r
944 \r
945         }\r
946 \r
947         // Listener when Left is clicked\r
948         @SuppressWarnings("unused")\r
949         private void justifyLeftClicked() {\r
950                 browser.page().mainFrame().evaluateJavaScript(\r
951                                 "document.execCommand('JustifyLeft', false, '');");\r
952                 browser.setFocus();\r
953         }\r
954 \r
955         // Listener when Center is clicked\r
956         @SuppressWarnings("unused")\r
957         private void justifyCenterClicked() {\r
958                 browser.page().mainFrame().evaluateJavaScript(\r
959                                 "document.execCommand('JustifyCenter', false, '');");\r
960                 browser.setFocus();\r
961         }\r
962 \r
963         // Listener when Left is clicked\r
964         @SuppressWarnings("unused")\r
965         private void justifyRightClicked() {\r
966                 browser.page().mainFrame().evaluateJavaScript(\r
967                                 "document.execCommand('JustifyRight', false, '');");\r
968                 browser.setFocus();\r
969         }\r
970 \r
971         // Listener when HLINE is clicked\r
972         @SuppressWarnings("unused")\r
973         private void hlineClicked() {\r
974                 browser.page().mainFrame().evaluateJavaScript(\r
975                                 "document.execCommand('insertHorizontalRule', false, '');");\r
976                 browser.setFocus();\r
977         }\r
978 \r
979         // Listener when outdent is clicked\r
980         private void outdentClicked() {\r
981                 browser.page().mainFrame().evaluateJavaScript(\r
982                                 "document.execCommand('outdent', false, '');");\r
983                 browser.setFocus();\r
984         }\r
985 \r
986         // Listener when a bullet list is clicked\r
987         @SuppressWarnings("unused")\r
988         private void bulletListClicked() {\r
989                 browser.page().mainFrame().evaluateJavaScript(\r
990                                 "document.execCommand('InsertUnorderedList', false, '');");\r
991                 browser.setFocus();\r
992         }\r
993 \r
994         // Listener when a bullet list is clicked\r
995         @SuppressWarnings("unused")\r
996         private void numberListClicked() {\r
997                 browser.page().mainFrame().evaluateJavaScript(\r
998                                 "document.execCommand('InsertOrderedList', false, '');");\r
999                 browser.setFocus();\r
1000         }\r
1001 \r
1002         // Listener when indent is clicked\r
1003         private void indentClicked() {\r
1004                 browser.page().mainFrame().evaluateJavaScript(\r
1005                                 "document.execCommand('indent', false, '');");\r
1006                 browser.setFocus();\r
1007         }\r
1008 \r
1009         // Listener when the font name is changed\r
1010         @SuppressWarnings("unused")\r
1011         private void fontChanged(String font) {\r
1012                 browser.page().mainFrame().evaluateJavaScript(\r
1013                                 "document.execCommand('fontName',false,'" + font + "');");\r
1014                 browser.setFocus();\r
1015         }\r
1016 \r
1017         // Listener when a font size is changed\r
1018         @SuppressWarnings("unused")\r
1019         private void fontSizeChanged(String font) {\r
1020                 String text = browser.selectedText();\r
1021                 if (text.trim().equalsIgnoreCase(""))\r
1022                         return;\r
1023 \r
1024                 String selectedText = browser.selectedText();\r
1025                 String url = "<span style=\"font-size:" +font +"pt; \">"+selectedText +"</a>";\r
1026                 String script = "document.execCommand('insertHtml', false, '"+url+"');";\r
1027                 browser.page().mainFrame().evaluateJavaScript(script);\r
1028 /*              browser.page().mainFrame().evaluateJavaScript(\r
1029                                 "document.execCommand('fontSize',false,'"\r
1030                                                 + font + "');");\r
1031 */\r
1032                 browser.setFocus();\r
1033         }\r
1034 \r
1035         // Load the font combo box based upon the font selected\r
1036         private void loadFontSize(String name) {        \r
1037                 QFontDatabase db = new QFontDatabase(); \r
1038                 fontSize.clear();\r
1039                 List<Integer> points = db.pointSizes(name); \r
1040                 for (int i=0; i<points.size(); i++) { \r
1041                         fontSize.addItem(points.get(i).toString()); \r
1042                 }\r
1043                 /*\r
1044                 fontSize.addItem("x-small");\r
1045                 fontSize.addItem("small");\r
1046                 fontSize.addItem("medium");\r
1047                 fontSize.addItem("large");\r
1048                 fontSize.addItem("x-large");\r
1049                 fontSize.addItem("xx-large");\r
1050                 fontSize.addItem("xxx-large");\r
1051                 */\r
1052         }\r
1053 \r
1054         // Listener when a font size is changed\r
1055         @SuppressWarnings("unused")\r
1056         private void fontColorClicked() {\r
1057 //              QColorDialog dialog = new QColorDialog();\r
1058 //              QColor color = QColorDialog.getColor();\r
1059                 QColor color = fontColorMenu.getColor();\r
1060                 if (color.isValid())\r
1061                         browser.page().mainFrame().evaluateJavaScript(\r
1062                                         "document.execCommand('foreColor',false,'" + color.name()\r
1063                                                         + "');");\r
1064                 browser.setFocus();\r
1065         }\r
1066 \r
1067         // Listener for when a background color change is requested\r
1068         @SuppressWarnings("unused")\r
1069         private void fontHilightClicked() {\r
1070 //              QColorDialog dialog = new QColorDialog();\r
1071 //              QColor color = QColorDialog.getColor();\r
1072                 QColor color = fontHilightColorMenu.getColor();\r
1073                 if (color.isValid())\r
1074                         browser.page().mainFrame().evaluateJavaScript(\r
1075                                         "document.execCommand('backColor',false,'" + color.name()\r
1076                                                         + "');");\r
1077                 browser.setFocus();\r
1078         }\r
1079         \r
1080         // Listener for when a background color change is requested\r
1081         @SuppressWarnings("unused")\r
1082         private void superscriptClicked() {\r
1083                 browser.page().mainFrame().evaluateJavaScript(\r
1084                                         "document.execCommand('superscript');");\r
1085                 browser.setFocus();\r
1086         }\r
1087         \r
1088         // Listener for when a background color change is requested\r
1089         @SuppressWarnings("unused")\r
1090         private void subscriptClicked() {\r
1091                 browser.page().mainFrame().evaluateJavaScript(\r
1092                                         "document.execCommand('subscript');");\r
1093                 browser.setFocus();\r
1094         }\r
1095         // Insert a to-do checkbox\r
1096         @SuppressWarnings("unused")\r
1097         private void todoClicked() {\r
1098                 FileNameMap fileNameMap = URLConnection.getFileNameMap();\r
1099                 String script_start = new String(\r
1100                                 "document.execCommand('insertHtml', false, '");\r
1101                 String script_end = new String("');");\r
1102                 String todo = new String(\r
1103                                 "<input TYPE=\"CHECKBOX\" value=\"false\" onClick=\"value=checked; window.jambi.contentChanged(); \" />");\r
1104                 browser.page().mainFrame().evaluateJavaScript(\r
1105                                 script_start + todo + script_end);\r
1106                 browser.setFocus();\r
1107         }\r
1108 \r
1109         // Encrypt the selected text\r
1110         @SuppressWarnings("unused")\r
1111         private void encryptText() {\r
1112                 String text = browser.selectedText();\r
1113                 if (text.trim().equalsIgnoreCase(""))\r
1114                         return;\r
1115 \r
1116                 EnCryptDialog dialog = new EnCryptDialog();\r
1117                 dialog.exec();\r
1118                 if (!dialog.okPressed()) {\r
1119                         return;\r
1120                 }\r
1121 \r
1122                 EnCrypt crypt = new EnCrypt();\r
1123                 String encrypted = crypt.encrypt(text, dialog.getPassword().trim(), 64);\r
1124 \r
1125                 if (encrypted.trim().equals("")) {\r
1126                         QMessageBox.information(this, tr("Error"), tr("Error Encrypting String"));\r
1127                         return;\r
1128                 }\r
1129                 StringBuffer buffer = new StringBuffer(encrypted.length() + 100);\r
1130                 buffer.append("<img en-tag=\"en-crypt\" cipher=\"RC2\" hint=\""\r
1131                                 + dialog.getHint().replace("'","\\'") + "\" length=\"64\" ");\r
1132                 buffer.append("contentEditable=\"false\" alt=\"");\r
1133                 buffer.append(encrypted);\r
1134                 // NFC FIXME: should this be a file URL like in handleLocalAttachment and importAttachment?\r
1135                 buffer.append("\" src=\"").append(FileUtils.toForwardSlashedPath(Global.getFileManager().getImageDirPath("encrypt.png") +"\""));\r
1136                 Global.cryptCounter++;\r
1137                 buffer.append(" id=\"crypt"+Global.cryptCounter.toString() +"\"");\r
1138                 buffer.append(" onMouseOver=\"style.cursor=\\'hand\\'\"");\r
1139                 buffer.append(" onClick=\"window.jambi.decryptText(\\'crypt"+Global.cryptCounter.toString() \r
1140                                 +"\\', \\'"+encrypted+"\\', \\'"+dialog.getHint().replace("'", "\\&amp;apos;")+"\\');\"");\r
1141                 buffer.append("style=\"display:block\" />");\r
1142 \r
1143                 String script_start = new String(\r
1144                                 "document.execCommand('insertHtml', false, '");\r
1145                 String script_end = new String("');");\r
1146                 browser.page().mainFrame().evaluateJavaScript(\r
1147                                 script_start + buffer.toString() + script_end);\r
1148         }\r
1149 \r
1150         \r
1151         // Insert a hyperlink\r
1152         public void insertLink() {\r
1153                 logger.log(logger.EXTREME, "Inserting link");\r
1154                 String text = browser.selectedText();\r
1155                 if (text.trim().equalsIgnoreCase(""))\r
1156                         return;\r
1157 \r
1158                 InsertLinkDialog dialog = new InsertLinkDialog();\r
1159                 if (currentHyperlink != null && currentHyperlink != "") {\r
1160                         dialog.setUrl(currentHyperlink);\r
1161                 }\r
1162                 dialog.exec();\r
1163                 if (!dialog.okPressed()) {\r
1164                         logger.log(logger.EXTREME, "Insert link canceled");\r
1165                         return;\r
1166                 }\r
1167                 if (browser.insertLinkAction.text().equalsIgnoreCase("Insert Hyperlink")) {\r
1168                         String selectedText = browser.selectedText();\r
1169                         logger.log(logger.EXTREME, "Inserting link on text "+selectedText);\r
1170                         logger.log(logger.EXTREME, "URL Link " +dialog.getUrl().trim());\r
1171                         String url = "<a href=\"" +dialog.getUrl().trim()+"\" >"+selectedText +"</a>";\r
1172                         String script = "document.execCommand('insertHtml', false, '"+url+"');";\r
1173                         browser.page().mainFrame().evaluateJavaScript(script);\r
1174                         return;\r
1175                 } else {\r
1176                         String js = new String( "function getCursorPos() {"\r
1177                                         +"var cursorPos;"\r
1178                                         +"if (window.getSelection) {"\r
1179                                         +"   var selObj = window.getSelection();"\r
1180                                         +"   var selRange = selObj.getRangeAt(0);"\r
1181                                         +"   var workingNode = window.getSelection().anchorNode.parentNode;"\r
1182                                         +"   while(workingNode != null) { " \r
1183                                         +"      if (workingNode.nodeName.toLowerCase()=='a') workingNode.setAttribute('href','" +dialog.getUrl() +"');"\r
1184                                         +"      workingNode = workingNode.parentNode;"\r
1185                                         +"   }"\r
1186                                         +"}"\r
1187                                         +"} getCursorPos();");\r
1188                                 browser.page().mainFrame().evaluateJavaScript(js);\r
1189                                 contentChanged();\r
1190                 }\r
1191                 \r
1192         }\r
1193         \r
1194         // Insert a table\r
1195         public void insertTable() {\r
1196                 TableDialog dialog = new TableDialog();\r
1197                 dialog.exec();\r
1198                 if (!dialog.okPressed()) {\r
1199                         return;\r
1200                 }\r
1201                 \r
1202                 int cols = dialog.getCols();\r
1203                 int rows = dialog.getRows();\r
1204                 int width = dialog.getWidth();\r
1205                 boolean percent = dialog.isPercent();\r
1206                 \r
1207                 String newHTML = "<table border=\"1\" width=\"" +new Integer(width).toString();\r
1208                 if (percent)\r
1209                         newHTML = newHTML +"%";\r
1210                 newHTML = newHTML + "\"><tbody>";\r
1211 \r
1212                 for (int i=0; i<rows; i++) {\r
1213                         newHTML = newHTML +"<tr>";\r
1214                         for (int j=0; j<cols; j++) {\r
1215                                 newHTML = newHTML +"<td>&nbsp;</td>";\r
1216                         }\r
1217                         newHTML = newHTML +"</tr>";\r
1218                 }\r
1219                 newHTML = newHTML+"</tbody></table>";   \r
1220         \r
1221                 String script = "document.execCommand('insertHtml', false, '"+newHTML+"');";\r
1222                 browser.page().mainFrame().evaluateJavaScript(script);\r
1223         }\r
1224         \r
1225         \r
1226         // Text content changed\r
1227         @SuppressWarnings("unused")\r
1228         private void selectionChanged() {\r
1229                 browser.encryptAction.setEnabled(true);\r
1230                 browser.insertLinkAction.setEnabled(true);\r
1231                 String scriptStart = "var selection_text = (window.getSelection()).toString();"\r
1232                                 + "var range = (window.getSelection()).getRangeAt(0);"\r
1233                                 + "var parent_html = range.commonAncestorContainer.innerHTML;"\r
1234                                 + "if (parent_html == undefined) {window.jambi.saveSelectedText(selection_text); return;}"\r
1235                                 + "var first_text = range.startContainer.nodeValue.substr(range.startOffset);"\r
1236                                 + "var last_text = (range.endContainer.nodeValue).substring(0,range.endOffset);"\r
1237                                 + "var start = parent_html.indexOf(first_text);"\r
1238                                 + "var end = parent_html.indexOf(last_text,start+1)+last_text.length;"\r
1239                                 + "var value = parent_html.substring(start,end);"\r
1240                                 + "window.jambi.saveSelectedText(value);" ;\r
1241                 browser.page().mainFrame().evaluateJavaScript(scriptStart);\r
1242 \r
1243         }\r
1244 \r
1245         public void saveSelectedText(String text) {\r
1246                 boolean enabled = true;\r
1247                 if (text.trim().length() == 0)\r
1248                         enabled=false;\r
1249                 if (text.indexOf("en-tag=\"en-crypt\"") >= 0)\r
1250                         enabled=false;\r
1251                 if (text.indexOf("<img en-tag=\"en-media\"") >= 0)\r
1252                         enabled=false;\r
1253                 if (text.indexOf("<a en-tag=\"en-media\"") >= 0)\r
1254                         enabled=false;\r
1255                 if (text.indexOf("<input ") >= 0)\r
1256                         enabled=false;\r
1257                 \r
1258                 browser.encryptAction.setEnabled(enabled);\r
1259                 browser.insertLinkAction.setEnabled(enabled);\r
1260 //              selectedText = text;\r
1261         }\r
1262 \r
1263         // Decrypt clicked text\r
1264         public void decryptText(String id, String text, String hint) {\r
1265                 EnCrypt crypt = new EnCrypt();\r
1266                 String plainText = null;\r
1267                 Calendar currentTime = new GregorianCalendar();\r
1268                 Long l = new Long(currentTime.getTimeInMillis());\r
1269                 String slot = new String(Long.toString(l));\r
1270                 \r
1271                 // First, try to decrypt with any keys we already have\r
1272                 for (int i=0; i<Global.passwordRemember.size(); i++) {\r
1273                         plainText = crypt.decrypt(text, Global.passwordRemember.get(i), 64);\r
1274                         if (plainText != null) {\r
1275                                 slot = new String(Long.toString(l));\r
1276                                 Global.passwordSafe.put(slot, Global.passwordRemember.get(i));\r
1277                                 removeEncryption(id, plainText, false, slot);   \r
1278                                 return;\r
1279                         }\r
1280                 }\r
1281                 \r
1282                 \r
1283                 EnDecryptDialog dialog = new EnDecryptDialog();\r
1284                 dialog.setHint(hint);\r
1285                 while (plainText == null || !dialog.okPressed()) {\r
1286                         dialog.exec();\r
1287                         if (!dialog.okPressed()) {\r
1288                                 return;\r
1289                         }\r
1290                         plainText = crypt.decrypt(text, dialog.getPassword().trim(), 64);\r
1291                         if (plainText == null) {\r
1292                                 QMessageBox.warning(this, "Incorrect Password", "The password entered is not correct");\r
1293                         }\r
1294                 }\r
1295                 Global.passwordSafe.put(slot, dialog.getPassword());\r
1296                 removeEncryption(id, plainText, dialog.permanentlyDecrypt(), slot);\r
1297                 if (dialog.rememberPassword())\r
1298                         Global.passwordRemember.add(dialog.getPassword());\r
1299 \r
1300         }\r
1301 \r
1302         // Get the editor tag line\r
1303         public TagLineEdit getTagLine() {\r
1304                 return tagEdit;\r
1305         }\r
1306 \r
1307         // Modify a note's tags\r
1308         @SuppressWarnings("unused")\r
1309         private void modifyTags() {\r
1310                 TagAssign tagWindow = new TagAssign(allTags, currentTags);\r
1311                 tagWindow.exec();\r
1312                 if (tagWindow.okClicked()) {\r
1313                         currentTags.clear();\r
1314                         StringBuffer tagDisplay = new StringBuffer();\r
1315 \r
1316                         List<QListWidgetItem> newTags = tagWindow.getTagList()\r
1317                                         .selectedItems();\r
1318                         for (int i = 0; i < newTags.size(); i++) {\r
1319                                 currentTags.add(newTags.get(i).text());\r
1320                                 tagDisplay.append(newTags.get(i).text());\r
1321                                 if (i < newTags.size() - 1) {\r
1322                                         tagDisplay.append(Global.tagDelimeter + " ");\r
1323                                 }\r
1324                         }\r
1325                         tagEdit.setText(tagDisplay.toString());\r
1326                         noteSignal.tagsChanged.emit(currentNote.getGuid(), currentTags);\r
1327                 }\r
1328         }\r
1329 \r
1330         // Tag line has been modified by typing text\r
1331         @SuppressWarnings("unused")\r
1332         private void modifyTagsTyping() {\r
1333                 String completionText = "";\r
1334                 if (tagEdit.currentCompleterSelection != null && !tagEdit.currentCompleterSelection.equals("")) {\r
1335                         completionText = tagEdit.currentCompleterSelection;\r
1336                         tagEdit.currentCompleterSelection = "";\r
1337                 }\r
1338                 \r
1339                 if (tagEdit.text().equalsIgnoreCase(saveTagList))\r
1340                         return;\r
1341 \r
1342                 // We know something has changed...\r
1343                 String oldTagArray[] = saveTagList.split(Global.tagDelimeter);\r
1344                 String newTagArray[] = tagEdit.text().split(Global.tagDelimeter);\r
1345                 \r
1346                 if (!completionText.equals("") && newTagArray.length > 0) {\r
1347                         newTagArray[newTagArray.length-1] = completionText;\r
1348                 }\r
1349                 // Remove any potential duplicates from the new list\r
1350                 for (int i=0; i<newTagArray.length; i++) {\r
1351                         boolean foundOnce = false;\r
1352                         for (int j=0; j<newTagArray.length; j++) {\r
1353                                 if (newTagArray[j].equalsIgnoreCase(newTagArray[i])) {\r
1354                                         if (!foundOnce) {\r
1355                                                 foundOnce = true;\r
1356                                         } else\r
1357                                                 newTagArray[j] = "";\r
1358                                 }\r
1359                         }\r
1360                 }\r
1361 \r
1362                 List<String> newTagList = new ArrayList<String>();\r
1363                 List<String> oldTagList = new ArrayList<String>();\r
1364 \r
1365                 for (int i = 0; i < oldTagArray.length; i++)\r
1366                         if (!oldTagArray[i].trim().equals(""))\r
1367                                 oldTagList.add(oldTagArray[i]);\r
1368                 for (int i = 0; i < newTagArray.length; i++)\r
1369                         if (!newTagArray[i].trim().equals(""))\r
1370                                 newTagList.add(newTagArray[i]);\r
1371 \r
1372                 // Let's cleanup the appearance of the tag list\r
1373                 Collections.sort(newTagList);\r
1374                 String newDisplay = "";\r
1375                 for (int i=0; i<newTagList.size(); i++) {\r
1376                         newDisplay = newDisplay+newTagList.get(i);\r
1377                         if (i<newTagList.size()-1)\r
1378                                 newDisplay = newDisplay+", ";\r
1379                 }\r
1380                 tagEdit.blockSignals(true);\r
1381                 tagEdit.setText(newDisplay);\r
1382                 tagEdit.blockSignals(false);\r
1383                 \r
1384                 // We now have lists of the new & old. Remove duplicates. If all\r
1385                 // are removed from both then nothing has really changed\r
1386                 for (int i = newTagList.size() - 1; i >= 0; i--) {\r
1387                         String nTag = newTagList.get(i);\r
1388                         for (int j = oldTagList.size() - 1; j >= 0; j--) {\r
1389                                 String oTag = oldTagList.get(j);\r
1390                                 if (oTag.equalsIgnoreCase(nTag)) {\r
1391                                         oldTagList.remove(j);\r
1392                                         newTagList.remove(i);\r
1393                                         j = -1;\r
1394                                 }\r
1395                         }\r
1396                 }\r
1397 \r
1398                 if (oldTagList.size() != 0 || newTagList.size() != 0) {\r
1399                         currentTags.clear();\r
1400                         newTagArray = tagEdit.text().split(Global.tagDelimeter);\r
1401                         for (int i = 0; i < newTagArray.length; i++)\r
1402                                 if (!newTagArray[i].trim().equals(""))\r
1403                                         currentTags.add(newTagArray[i].trim());\r
1404 \r
1405                         noteSignal.tagsChanged.emit(currentNote.getGuid(), currentTags);\r
1406                 }\r
1407                 \r
1408         }\r
1409 \r
1410         // Tab button was pressed\r
1411         public void tabPressed() {\r
1412                 if (!insideList) {\r
1413                         String script_start = new String(\r
1414                         "document.execCommand('insertHtml', false, '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');");\r
1415                         browser.page().mainFrame().evaluateJavaScript(script_start);\r
1416                 } else \r
1417                         indentClicked();\r
1418         }\r
1419         \r
1420         public void backtabPressed() {\r
1421                 if (insideList)\r
1422                         outdentClicked();\r
1423         }\r
1424         \r
1425         public void setInsideList() {\r
1426                 insideList = true;\r
1427         }\r
1428         \r
1429         // The title has been edited\r
1430         @SuppressWarnings("unused")\r
1431         private void titleEdited() {\r
1432                 // If we don't have a good note, or if the current title\r
1433                 // matches the old title then we don't need to do anything\r
1434                 if (currentNote == null)\r
1435                         return;\r
1436                 if (currentNote.getTitle().trim().equals(titleLabel.text().trim()))\r
1437                         return;\r
1438                 \r
1439                 // If we have a real change, we need to save it.\r
1440                 noteSignal.titleChanged.emit(currentNote.getGuid(), titleLabel.text());\r
1441                 currentNote.setTitle(titleLabel.text());\r
1442                 saveNoteTitle = titleLabel.text();\r
1443                 checkNoteTitle();\r
1444         }\r
1445 \r
1446         // Set the list of note tags\r
1447         public void setAllTags(List<Tag> l) {\r
1448                 allTags = l;\r
1449                 tagEdit.setTagList(l);\r
1450         }\r
1451 \r
1452         // Setter for the current tags\r
1453         public void setCurrentTags(List<String> s) {\r
1454                 currentTags = s;\r
1455         }\r
1456 \r
1457         // Save the list of notebooks\r
1458         public void setNotebookList(List<Notebook> n) {\r
1459                 notebookList = n;\r
1460                 loadNotebookList();\r
1461         }\r
1462 \r
1463         // Load the notebook list and select the current notebook\r
1464         private void loadNotebookList() {\r
1465                 if (notebookBox.count() != 0)\r
1466                         notebookBox.clear();\r
1467                 if (notebookList == null)\r
1468                         return;\r
1469 \r
1470                 for (int i = 0; i < notebookList.size(); i++) {\r
1471                         notebookBox.addItem(notebookList.get(i).getName());\r
1472                         if (currentNote != null) {\r
1473                                 if (currentNote.getNotebookGuid().equals(\r
1474                                                 notebookList.get(i).getGuid())) {\r
1475                                         notebookBox.setCurrentIndex(i);\r
1476                                 }\r
1477                         }\r
1478                 }\r
1479         }\r
1480 \r
1481         // Get the contents of the editor\r
1482         public String getContent() {\r
1483                 return browser.page().currentFrame().toHtml();\r
1484         }\r
1485 \r
1486         // The note contents have changed\r
1487         public void contentChanged() {\r
1488                 String content = getContent();\r
1489                 checkNoteTitle();\r
1490                 noteSignal.noteChanged.emit(currentNote.getGuid(), content); \r
1491         }\r
1492 \r
1493         // The notebook selection has changed\r
1494         @SuppressWarnings("unused")\r
1495         private void notebookChanged() {\r
1496                 boolean changed = false;\r
1497                 String n = notebookBox.currentText();\r
1498                 for (int i = 0; i < notebookList.size(); i++) {\r
1499                         if (n.equals(notebookList.get(i).getName())) {\r
1500                                 if (!notebookList.get(i).getGuid().equals(currentNote.getNotebookGuid())) {\r
1501                                         currentNote.setNotebookGuid(notebookList.get(i).getGuid());\r
1502                                         changed = true;\r
1503                                 }\r
1504                                 i = notebookList.size();\r
1505                         }\r
1506                 }\r
1507                 \r
1508                 // If the notebook changed, signal the update\r
1509                 if (changed)\r
1510                         noteSignal.notebookChanged.emit(currentNote.getGuid(), currentNote\r
1511                                         .getNotebookGuid());\r
1512         }\r
1513 \r
1514         // Check the note title\r
1515         private void checkNoteTitle() {\r
1516                 String text = browser.page().currentFrame().toPlainText();\r
1517                 if (saveNoteTitle.trim().equals("")) {\r
1518                         int newLine = text.indexOf("\n");\r
1519                         if (newLine > 0) {\r
1520                                 text = text.substring(0, newLine);\r
1521                                 if (text.trim().equals(""))\r
1522                                         text = tr("Untitled Note");\r
1523                                 titleLabel.setText(text);\r
1524                         } else {\r
1525                                 if (text.length() > 20)\r
1526                                         titleLabel.setText(text.substring(0, 20));\r
1527                                 else {\r
1528                                         if (text.trim().equals(""))\r
1529                                                 titleLabel.setText(tr("Untitled Note"));\r
1530                                         else\r
1531                                                 titleLabel.setText(text);\r
1532                                 }\r
1533                         }\r
1534                         noteSignal.titleChanged.emit(currentNote.getGuid(), titleLabel\r
1535                                         .text());\r
1536                 }\r
1537         }\r
1538 \r
1539         // Return the note contents so we can email them\r
1540         public String getContentsToEmail() {\r
1541                 return browser.page().currentFrame().toPlainText().trim();\r
1542                 /*\r
1543                  * int body = browser.page().currentFrame().toHtml().indexOf("<body>");\r
1544                  * String temp = browser.page().currentFrame().toHtml(); if (body == -1)\r
1545                  * temp = "<html><body><b>Test</b></body></html>"; else temp =\r
1546                  * "<html>"+temp.substring(body); return temp; // return\r
1547                  * urlEncode(browser.page().currentFrame().toHtml());\r
1548                  */\r
1549         }\r
1550 \r
1551         // Insert an image into the editor\r
1552         private void insertImage(QMimeData mime) {\r
1553                 logger.log(logger.EXTREME, "Entering insertImage");\r
1554                 QImage img = (QImage) mime.imageData();\r
1555                 String script_start = new String(\r
1556                                 "document.execCommand('insertHTML', false, '");\r
1557                 String script_end = new String("');");\r
1558 \r
1559                 long now = new Date().getTime();\r
1560                 String path = Global.getFileManager().getResDirPath(\r
1561                                 (new Long(now).toString()) + ".jpg");\r
1562 \r
1563                 // This block is just a hack to make sure we wait at least 1ms so we\r
1564                 // don't\r
1565                 // have collisions on image names\r
1566                 long i = new Date().getTime();\r
1567                 while (now == i)\r
1568                         i = new Date().getTime();\r
1569 \r
1570                 // Open the file & write the data\r
1571                 QFile tfile = new QFile(path);\r
1572                 tfile.open(new QIODevice.OpenMode(QIODevice.OpenModeFlag.WriteOnly));\r
1573                 img.save(tfile);\r
1574                 tfile.close();\r
1575                 \r
1576                 Resource newRes = createResource(QUrl.fromLocalFile(path).toString(), 0, "image/jpeg", false);\r
1577                 if (newRes == null)\r
1578                         return;\r
1579                 currentNote.getResources().add(newRes);\r
1580 \r
1581                 // do the actual insert into the note\r
1582                 StringBuffer buffer = new StringBuffer(100);\r
1583                 buffer.append("<img src=\"");\r
1584                 buffer.append(tfile.fileName());\r
1585                 buffer.append("\" en-tag=en-media type=\"image/jpeg\""\r
1586                                 +" hash=\""+Global.byteArrayToHexString(newRes.getData().getBodyHash()) +"\""\r
1587                                 +" guid=\"" +newRes.getGuid() +"\""\r
1588 //                              +" onContextMenu=\"window.jambi.imageContextMenu('" +tfile.fileName() +"');\""\r
1589                                 +" onContextMenu=\"window.jambi.imageContextMenu(&amp." +tfile.fileName() +"&amp.);\""\r
1590                                 + " />");\r
1591                 \r
1592                 browser.page().mainFrame().evaluateJavaScript(\r
1593                                 script_start + buffer + script_end);\r
1594 \r
1595                 return;\r
1596         }\r
1597 \r
1598         // Handle URLs that are trying to be pasted\r
1599         public void handleUrls(QMimeData mime) {\r
1600                 logger.log(logger.EXTREME, "Starting handleUrls");\r
1601                 FileNameMap fileNameMap = URLConnection.getFileNameMap();\r
1602 \r
1603                 List<QUrl> urlList = mime.urls();\r
1604                 String url = new String();\r
1605                 String script_start = new String(\r
1606                                 "document.execCommand('createLink', false, '");\r
1607                 String script_end = new String("');");\r
1608 \r
1609                 for (int i = 0; i < urlList.size(); i++) {\r
1610                         url = urlList.get(i).toString();\r
1611                         // Find out what type of file we have\r
1612                         String mimeType = fileNameMap.getContentTypeFor(url);\r
1613 \r
1614                         // If null returned, we need to guess at the file type\r
1615                         if (mimeType == null)\r
1616                                 mimeType = "application/"\r
1617                                                 + url.substring(url.lastIndexOf(".") + 1);\r
1618 \r
1619                         // Check if we have an image or some other type of file\r
1620                         if (url.substring(0, 5).equalsIgnoreCase("file:")\r
1621                                         && mimeType.substring(0, 5).equalsIgnoreCase("image")) {\r
1622                                 handleLocalImageURLPaste(mime, mimeType);\r
1623                                 return;\r
1624                         }\r
1625                         String[] type = mimeType.split("/");\r
1626                         boolean valid = validAttachment(type[1]);\r
1627                         boolean smallEnough = checkFileAttachmentSize(url);\r
1628                         if (smallEnough && valid\r
1629                                         && url.substring(0, 5).equalsIgnoreCase("file:")\r
1630                                         && !mimeType.substring(0, 5).equalsIgnoreCase("image")) {\r
1631                                 handleLocalAttachment(mime, mimeType);\r
1632                                 return;\r
1633                         }\r
1634                         browser.page().mainFrame().evaluateJavaScript(\r
1635                                         script_start + url + script_end);\r
1636                 }\r
1637                 return;\r
1638         }\r
1639 \r
1640         // If a URL being pasted is an image URL, then attach the image\r
1641         private void handleLocalImageURLPaste(QMimeData mime, String mimeType) {\r
1642                 List<QUrl> urlList = mime.urls();\r
1643                 String url = new String();\r
1644                 String script_start_image = new String(\r
1645                                 "document.execCommand('insertHtml', false, '");\r
1646                 String script_end = new String("');");\r
1647                 StringBuffer buffer;\r
1648 \r
1649                 // Copy the image over into the resource directory and create a new resource \r
1650                 // record for each url pasted\r
1651                 for (int i = 0; i < urlList.size(); i++) {\r
1652                         url = urlList.get(i).toString();\r
1653 \r
1654                         Resource newRes = createResource(url, i, mimeType, false);\r
1655                         if (newRes == null)\r
1656                                 return;\r
1657                         currentNote.getResources().add(newRes);\r
1658                         buffer = new StringBuffer(100);\r
1659                         \r
1660                         // Open the file & write the data\r
1661                         String fileName = Global.getFileManager().getResDirPath(newRes.getGuid());\r
1662                         QFile tfile = new QFile(fileName);\r
1663                         tfile.open(new QIODevice.OpenMode(QIODevice.OpenModeFlag.WriteOnly));\r
1664                         tfile.write(newRes.getData().getBody());\r
1665                         tfile.close();\r
1666                         buffer.append(script_start_image);\r
1667                         buffer.append("<img src=\"" + FileUtils.toForwardSlashedPath(fileName));\r
1668 //                      if (mimeType.equalsIgnoreCase("image/jpg"))\r
1669 //                              mimeType = "image/jpeg";\r
1670                         buffer.append("\" en-tag=\"en-media\" type=\"" + mimeType +"\""\r
1671                                         +" hash=\""+Global.byteArrayToHexString(newRes.getData().getBodyHash()) +"\""\r
1672                                         +" guid=\"" +newRes.getGuid() +"\""\r
1673                                         +" onContextMenu=\"window.jambi.imageContextMenu(&apos;" +tfile.fileName() +"&apos;);\""\r
1674                                         + " />");\r
1675                         buffer.append(script_end);\r
1676                         browser.page().mainFrame().evaluateJavaScript(buffer.toString());\r
1677                 }\r
1678                 return;\r
1679         }\r
1680         \r
1681 \r
1682         // If a URL being pasted is a local file URL, then attach the file\r
1683         private void handleLocalAttachment(QMimeData mime, String mimeType) {\r
1684                 logger.log(logger.EXTREME, "Attaching local file");\r
1685                 List<QUrl> urlList = mime.urls();\r
1686                 String script_start = new String(\r
1687                                 "document.execCommand('insertHtml', false, '");\r
1688                 String script_end = new String("');");\r
1689                 StringBuffer buffer;\r
1690 \r
1691                         String[] type = mimeType.split("/");\r
1692                         String icon = findIcon(type[1]);\r
1693                         if (icon.equals("attachment.png"))\r
1694                                 icon = findIcon(type[0]);\r
1695                         buffer = new StringBuffer(100);\r
1696 \r
1697                 for (int i = 0; i < urlList.size(); i++) {\r
1698                         String url = urlList.get(i).toString();\r
1699 \r
1700                         // Start building the HTML\r
1701                         if (icon.equals("attachment.png"))\r
1702                                 icon = findIcon(url.substring(url.lastIndexOf(".")+1));\r
1703                         String imageURL = FileUtils.toFileURLString(Global.getFileManager().getImageDirFile(icon));\r
1704 \r
1705                         logger.log(logger.EXTREME, "Creating resource ");\r
1706                         Resource newRes = createResource(url, i, mimeType, true);\r
1707                         if (newRes == null)\r
1708                                 return;\r
1709                         logger.log(logger.EXTREME, "New resource size: " +newRes.getData().getSize());\r
1710                         currentNote.getResources().add(newRes);\r
1711                         \r
1712                         String fileName = newRes.getGuid() + Global.attachmentNameDelimeter+newRes.getAttributes().getFileName();\r
1713                         // If we have a PDF, we need to setup the preview.\r
1714                         if (icon.equalsIgnoreCase("pdf.png") && Global.pdfPreview()) {\r
1715                                 logger.log(logger.EXTREME, "Setting up PDF preview");\r
1716                                 if (newRes.getAttributes() != null && \r
1717                                                 newRes.getAttributes().getFileName() != null && \r
1718                                                 !newRes.getAttributes().getFileName().trim().equals(""))\r
1719                                         fileName = newRes.getGuid()+Global.attachmentNameDelimeter+\r
1720                                                 newRes.getAttributes().getFileName();\r
1721                                 else\r
1722                                         fileName = newRes.getGuid()+".pdf";\r
1723                                 QFile file = new QFile(Global.getFileManager().getResDirPath(fileName));\r
1724                         QFile.OpenMode mode = new QFile.OpenMode();\r
1725                         mode.set(QFile.OpenModeFlag.WriteOnly);\r
1726                         file.open(mode);\r
1727                         QDataStream out = new QDataStream(file);\r
1728 //                      Resource resBinary = conn.getNoteTable().noteResourceTable.getNoteResource(newRes.getGuid(), true);\r
1729                                 QByteArray binData = new QByteArray(newRes.getData().getBody());\r
1730 //                              resBinary = null;\r
1731                         out.writeBytes(binData.toByteArray());\r
1732                         file.close();\r
1733 \r
1734                                 PDFPreview pdfPreview = new PDFPreview();\r
1735                                 if (pdfPreview.setupPreview(Global.getFileManager().getResDirPath(fileName), "pdf",0)) {\r
1736                                 // NFC TODO: should this be a 'file://' url like the ones above?\r
1737                                 imageURL = file.fileName() + ".png";\r
1738                                 }\r
1739                         }\r
1740                                                 \r
1741                         logger.log(logger.EXTREME, "Generating link tags");\r
1742                         buffer.delete(0, buffer.length());\r
1743                         buffer.append("<a en-tag=\"en-media\" guid=\"" +newRes.getGuid()+"\" ");\r
1744                         buffer.append(" onContextMenu=\"window.jambi.imageContextMenu(&apos;")\r
1745                       .append(Global.getFileManager().getResDirPath(fileName))\r
1746                       .append("&apos;);\" ");                   buffer.append("type=\"" + mimeType + "\" href=\"nnres://" + fileName +"\" hash=\""+Global.byteArrayToHexString(newRes.getData().getBodyHash()) +"\" >");\r
1747                         buffer.append("<img src=\"" + imageURL + "\" title=\"" +newRes.getAttributes().getFileName());\r
1748                         buffer.append("\"></img>");\r
1749                         buffer.append("</a>");\r
1750                         browser.page().mainFrame().evaluateJavaScript(\r
1751                                         script_start + buffer.toString() + script_end);\r
1752                 }\r
1753                 return;\r
1754         }\r
1755 \r
1756         private Resource createResource(String url, int sequence, String mime, boolean attachment) {\r
1757                 logger.log(logger.EXTREME, "Inside create resource");\r
1758                 QFile resourceFile;\r
1759                 String urlTest = new QUrl(url).toLocalFile();\r
1760                 if (!urlTest.equals(""))\r
1761                         url = urlTest;\r
1762                 url = url.replace("/", File.separator);\r
1763         resourceFile = new QFile(url); \r
1764         resourceFile.open(new QIODevice.OpenMode(QIODevice.OpenModeFlag.ReadOnly));\r
1765         byte[] fileData = resourceFile.readAll().toByteArray();\r
1766         resourceFile.close();\r
1767         if (fileData.length == 0)\r
1768                 return null;\r
1769         MessageDigest md;\r
1770         try {\r
1771                 md = MessageDigest.getInstance("MD5");\r
1772                 md.update(fileData);\r
1773                 byte[] hash = md.digest();\r
1774   \r
1775                 Resource r = new Resource();\r
1776                 Calendar time = new GregorianCalendar();\r
1777                 long prevTime = time.getTimeInMillis();\r
1778                 while (prevTime == time.getTimeInMillis()) {\r
1779                         time = new GregorianCalendar();\r
1780                 }\r
1781                 r.setGuid(time.getTimeInMillis()+new Integer(sequence).toString());\r
1782                 r.setNoteGuid(currentNote.getGuid());\r
1783                 r.setMime(mime);\r
1784                 r.setActive(true);\r
1785                 r.setUpdateSequenceNum(0);\r
1786                 r.setWidth((short) 0);\r
1787                 r.setHeight((short) 0);\r
1788                 r.setDuration((short) 0);\r
1789                                 \r
1790                 Data d = new Data();\r
1791                 d.setBody(fileData);\r
1792                 d.setBodyIsSet(true);\r
1793                 d.setBodyHash(hash);\r
1794                 d.setBodyHashIsSet(true);\r
1795                 r.setData(d);\r
1796                 d.setSize(fileData.length);\r
1797                 \r
1798                 int fileNamePos = url.lastIndexOf(File.separator);\r
1799                 if (fileNamePos == -1)\r
1800                         fileNamePos = url.lastIndexOf("/");\r
1801                         String fileName = url.substring(fileNamePos+1);\r
1802                 ResourceAttributes a = new ResourceAttributes();\r
1803                 a.setAltitude(0);\r
1804                 a.setAltitudeIsSet(false);\r
1805                 a.setLongitude(0);\r
1806                 a.setLongitudeIsSet(false);\r
1807                 a.setLatitude(0);\r
1808                 a.setLatitudeIsSet(false);\r
1809                 a.setCameraMake("");\r
1810                 a.setCameraMakeIsSet(false);\r
1811                 a.setCameraModel("");\r
1812                 a.setCameraModelIsSet(false);\r
1813                 a.setAttachment(attachment);\r
1814                 a.setAttachmentIsSet(true);\r
1815                 a.setClientWillIndex(false);\r
1816                 a.setClientWillIndexIsSet(true);\r
1817                 a.setRecoType("");\r
1818                 a.setRecoTypeIsSet(false);\r
1819                 a.setSourceURL(url);\r
1820                 a.setSourceURLIsSet(true);\r
1821                 a.setTimestamp(0);\r
1822                 a.setTimestampIsSet(false);\r
1823                 a.setFileName(fileName);\r
1824                 a.setFileNameIsSet(true);\r
1825                 r.setAttributes(a);\r
1826                 \r
1827                 conn.getNoteTable().noteResourceTable.saveNoteResource(r, true);\r
1828                 return r;\r
1829         } catch (NoSuchAlgorithmException e1) {\r
1830                 e1.printStackTrace();\r
1831                 }\r
1832         return null;\r
1833         }\r
1834         \r
1835 \r
1836     // find the appropriate icon for an attachment\r
1837     private String findIcon(String appl) {\r
1838         appl = appl.toLowerCase();\r
1839         File f = Global.getFileManager().getImageDirFile(appl + ".png");\r
1840         if (f.exists())\r
1841                 return appl+".png";\r
1842         return "attachment.png";\r
1843     }\r
1844 \r
1845         // Check if the account supports this type of attachment\r
1846         private boolean validAttachment(String type) {\r
1847                 if (Global.isPremium())\r
1848                         return true;\r
1849                 if (type.equalsIgnoreCase("JPG"))\r
1850                         return true;\r
1851                 if (type.equalsIgnoreCase("PNG"))\r
1852                         return true;\r
1853                 if (type.equalsIgnoreCase("GIF"))\r
1854                         return true;\r
1855                 if (type.equalsIgnoreCase("MP3"))\r
1856                         return true;\r
1857                 if (type.equalsIgnoreCase("WAV"))\r
1858                         return true;\r
1859                 if (type.equalsIgnoreCase("AMR"))\r
1860                         return true;\r
1861                 if (type.equalsIgnoreCase("PDF"))\r
1862                         return true;\r
1863                 String error = tr("Non-premium accounts can only attach JPG, PNG, GIF, MP3, WAV, AMR, or PDF files.");\r
1864                 QMessageBox.information(this, tr("Non-Premium Account"), error);\r
1865 \r
1866                 return false;\r
1867         }\r
1868 \r
1869         // Check the file attachment to be sure it isn't over 25 mb\r
1870         private boolean checkFileAttachmentSize(String url) {\r
1871                 String fileName = url.substring(8);\r
1872                 QFile resourceFile = new QFile(fileName);\r
1873                 resourceFile.open(new QIODevice.OpenMode(\r
1874                                 QIODevice.OpenModeFlag.ReadOnly));\r
1875                 long size = resourceFile.size();\r
1876                 resourceFile.close();\r
1877                 size = size / 1024 / 1024;\r
1878                 if (size < 50 && Global.isPremium())\r
1879                         return true;\r
1880                 if (size < 25)\r
1881                         return true;\r
1882 \r
1883                 String error = tr("A file attachment may not exceed 25MB.");\r
1884                 QMessageBox.information(this, tr("Attachment Size"), error);\r
1885                 return false;\r
1886         }\r
1887 \r
1888 \r
1889         @SuppressWarnings("unused")\r
1890         private void createdChanged() {\r
1891                 QDateTime dt = new QDateTime();\r
1892                 dt.setDate(createdDate.date());\r
1893                 dt.setTime(createdTime.time());\r
1894                 noteSignal.createdDateChanged.emit(currentNote.getGuid(), dt);\r
1895 \r
1896         }\r
1897 \r
1898         @SuppressWarnings("unused")\r
1899         private void alteredChanged() {\r
1900                 QDateTime dt = new QDateTime();\r
1901                 dt.setDate(alteredDate.date());\r
1902                 dt.setTime(alteredTime.time());\r
1903                 noteSignal.alteredDateChanged.emit(currentNote.getGuid(), dt);\r
1904         }\r
1905 \r
1906         @SuppressWarnings("unused")\r
1907         private void subjectDateTimeChanged() {\r
1908                 QDateTime dt = new QDateTime();\r
1909                 dt.setDate(subjectDate.date());\r
1910                 dt.setTime(subjectTime.time());\r
1911                 noteSignal.subjectDateChanged.emit(currentNote.getGuid(), dt);\r
1912 \r
1913         }\r
1914 \r
1915         @SuppressWarnings("unused")\r
1916         private void sourceUrlChanged() {\r
1917                 noteSignal.sourceUrlChanged.emit(currentNote.getGuid(), urlText.text());\r
1918         }\r
1919 \r
1920         @SuppressWarnings("unused")\r
1921         private void authorChanged() {\r
1922                 noteSignal.authorChanged.emit(currentNote.getGuid(), authorText.text());\r
1923         }\r
1924         \r
1925         @SuppressWarnings("unused")\r
1926         private void geoBoxChanged() {\r
1927                 int index = geoBox.currentIndex();\r
1928                 geoBox.setCurrentIndex(0);\r
1929                 if (index == 1) {\r
1930                         GeoDialog box = new GeoDialog();\r
1931                         box.setLongitude(currentNote.getAttributes().getLongitude());\r
1932                         box.setLatitude(currentNote.getAttributes().getLatitude());\r
1933                         box.setAltitude(currentNote.getAttributes().getAltitude());\r
1934                         box.exec();\r
1935                         if (!box.okPressed())\r
1936                                 return;\r
1937                         double alt = box.getAltitude();\r
1938                         double lat = box.getLatitude();\r
1939                         double lon = box.getLongitude();\r
1940                         if (alt != currentNote.getAttributes().getAltitude() ||\r
1941                                 lon != currentNote.getAttributes().getLongitude() ||\r
1942                                 lat != currentNote.getAttributes().getLatitude()) {\r
1943                                         noteSignal.geoChanged.emit(currentNote.getGuid(), lon, lat, alt);\r
1944                                         currentNote.getAttributes().setAltitude(alt);\r
1945                                         currentNote.getAttributes().setLongitude(lon);\r
1946                                         currentNote.getAttributes().setLatitude(lat);\r
1947                         }\r
1948                 }\r
1949                 \r
1950                 if (index == 2) {\r
1951                         noteSignal.geoChanged.emit(currentNote.getGuid(), 0.0, 0.0, 0.0);\r
1952                         currentNote.getAttributes().setAltitude(0.0);\r
1953                         currentNote.getAttributes().setLongitude(0.0);\r
1954                         currentNote.getAttributes().setLatitude(0.0);\r
1955                 }\r
1956                 \r
1957                 if (index == 3 || index == 0) {\r
1958                         QDesktopServices.openUrl(new QUrl("http://maps.google.com/maps?z=6&q="+currentNote.getAttributes().getLatitude() +"," +currentNote.getAttributes().getLongitude()));\r
1959                 }\r
1960         }\r
1961 \r
1962         // ************************************************************\r
1963         // * User chose to save an attachment. Pares out the request *\r
1964         // * into a guid & file. Save the result. *\r
1965         // ************************************************************\r
1966         public void downloadAttachment(QNetworkRequest request) {\r
1967                 String guid;\r
1968                 QFileDialog fd = new QFileDialog(this);\r
1969                 fd.setFileMode(FileMode.AnyFile);\r
1970                 fd.setConfirmOverwrite(true);\r
1971                 fd.setWindowTitle(tr("Save File"));\r
1972                 fd.setAcceptMode(AcceptMode.AcceptSave);\r
1973                 fd.setDirectory(System.getProperty("user.home"));\r
1974                 String name = request.url().toString();\r
1975 \r
1976                 int pos = name.lastIndexOf(Global.attachmentNameDelimeter);\r
1977                 if (pos > -1) {\r
1978                         guid = name.substring(0, pos).replace("nnres://", "");\r
1979                         name = name.substring(pos +Global.attachmentNameDelimeter.length());\r
1980                         fd.selectFile(name);\r
1981                         pos = name.lastIndexOf('.');\r
1982                         if (pos > -1) {\r
1983                                 String mimeType = "(*." + name.substring(pos + 1)\r
1984                                                 + ");; All Files (*)";\r
1985                                 fd.setFilter(tr(mimeType));\r
1986                         }\r
1987                 } else {\r
1988                         guid = name;\r
1989                 }\r
1990 \r
1991                 // Strip URL prefix and base dir\r
1992                 guid = guid.replace("nnres://", "")\r
1993                         .replace(FileUtils.toForwardSlashedPath(Global.getFileManager().getResDirPath()), "");\r
1994 \r
1995                 pos = guid.lastIndexOf('.');\r
1996                 if (pos > 0)\r
1997                         guid = guid.substring(0,pos);\r
1998                 if (fd.exec() != 0 && fd.selectedFiles().size() > 0) {\r
1999                         name = name.replace('\\', '/');\r
2000                         Resource resBinary = conn.getNoteTable().noteResourceTable.getNoteResource(guid, true);\r
2001                         QFile saveFile = new QFile(fd.selectedFiles().get(0));\r
2002                         QFile.OpenMode mode = new QFile.OpenMode();\r
2003                         mode.set(QFile.OpenModeFlag.WriteOnly);\r
2004                         saveFile.open(mode);\r
2005                         QDataStream saveOut = new QDataStream(saveFile);\r
2006                         QByteArray binData = new QByteArray(resBinary.getData().getBody());\r
2007                         saveOut.writeBytes(binData.toByteArray());\r
2008                         saveFile.close();\r
2009 \r
2010                 }\r
2011         }\r
2012 \r
2013         \r
2014         // ************************************************************\r
2015         // * User chose to save an attachment. Pares out the request *\r
2016         // * into a guid & file. Save the result. --- DONE FROM downloadAttachment now!!!!!   \r
2017         // ************************************************************\r
2018         // NFC TODO: unused? remove\r
2019         public void downloadImage(QNetworkRequest request) {\r
2020                 QFileDialog fd = new QFileDialog(this);\r
2021                 fd.setFileMode(FileMode.AnyFile);\r
2022                 fd.setConfirmOverwrite(true);\r
2023                 fd.setWindowTitle(tr("Save File"));\r
2024                 fd.setAcceptMode(AcceptMode.AcceptSave);\r
2025                 fd.setDirectory(System.getProperty("user.home"));\r
2026                 String name = request.url().toString();\r
2027                 name = name.replace("nnres://", "");\r
2028                 String dPath = FileUtils.toForwardSlashedPath(Global.getFileManager().getResDirPath());\r
2029                 name = name.replace(dPath, "");\r
2030                 int pos = name.lastIndexOf('.');\r
2031                 String guid = name;\r
2032                 if (pos > -1) {\r
2033                         String mimeType = "(*." + name.substring(pos + 1)\r
2034                         + ");; All Files (*)";\r
2035                                 fd.setFilter(tr(mimeType));\r
2036                         guid = guid.substring(0,pos);\r
2037                 }\r
2038                 pos = name.lastIndexOf(Global.attachmentNameDelimeter);\r
2039                 if (pos > -1) {\r
2040                         guid = name.substring(0, pos);\r
2041                         fd.selectFile(name.substring(pos+Global.attachmentNameDelimeter.length()));             \r
2042                 }\r
2043                 if (fd.exec() != 0 && fd.selectedFiles().size() > 0) {\r
2044                         Resource resBinary = conn.getNoteTable().noteResourceTable.getNoteResource(guid, true);\r
2045                         String fileName = fd.selectedFiles().get(0);\r
2046                         QFile saveFile = new QFile(fileName);\r
2047                         QFile.OpenMode mode = new QFile.OpenMode();\r
2048                         mode.set(QFile.OpenModeFlag.WriteOnly);\r
2049                         saveFile.open(mode);\r
2050                         QDataStream saveOut = new QDataStream(saveFile);\r
2051                         QByteArray binData = new QByteArray(resBinary.getData().getBody());\r
2052                         saveOut.writeBytes(binData.toByteArray());\r
2053                         saveFile.close();\r
2054                 }\r
2055         }\r
2056 \r
2057         \r
2058         // *************************************************************\r
2059         // * decrypt any hidden text.  We could do an XML parse, but \r
2060         // * it is quicker here just to scan for an <img tag & do the fix\r
2061         // * the manual way\r
2062         // *************************************************************\r
2063         private void removeEncryption(String id, String plainText, boolean permanent, String slot) {\r
2064                 if (!permanent) {\r
2065                         plainText = " <en-crypt-temp slot=\""+slot  +"\">" +plainText+"</en-crypt-temp> ";\r
2066                 }\r
2067                 \r
2068                 String html = browser.page().mainFrame().toHtml();\r
2069                 String text = html;\r
2070                 int imagePos = html.indexOf("<img");\r
2071                 int endPos;\r
2072                 for ( ;imagePos>0; ) {\r
2073                         // Find the end tag\r
2074                         endPos = text.indexOf(">", imagePos);\r
2075                         String tag = text.substring(imagePos-1,endPos);\r
2076                         if (tag.indexOf("id=\""+id+"\"") > -1) {\r
2077                                         text = text.substring(0,imagePos) +plainText+text.substring(endPos+1);\r
2078                                                                                 \r
2079                                         browser.setContent(new QByteArray(text));\r
2080                                         contentChanged();\r
2081                         }\r
2082                         imagePos = text.indexOf("<img", imagePos+1);\r
2083                 }\r
2084         }\r
2085         \r
2086         \r
2087         //****************************************************************\r
2088         //* Focus shortcuts\r
2089         //****************************************************************\r
2090         @SuppressWarnings("unused")\r
2091         private void focusTitle() {\r
2092                 titleLabel.setFocus();\r
2093         }\r
2094         @SuppressWarnings("unused")\r
2095         private void focusTag() {\r
2096                 tagEdit.setFocus();\r
2097         }\r
2098         @SuppressWarnings("unused")\r
2099         private void focusNote() {\r
2100                 browser.setFocus();\r
2101         }\r
2102         @SuppressWarnings("unused")\r
2103         private void focusAuthor() {\r
2104                 authorLabel.setFocus();\r
2105         }\r
2106         @SuppressWarnings("unused")\r
2107         private void focusUrl() {\r
2108                 urlLabel.setFocus();\r
2109         }\r
2110         \r
2111 \r
2112         //*****************************************************************\r
2113         //* Set the document background color\r
2114         //*****************************************************************\r
2115         public void setBackgroundColor(String color) {\r
2116                 String js = "function changeBackground(color) {"\r
2117                         +"document.body.style.background = color;"\r
2118                         +"}" \r
2119                         +"changeBackground('" +color+"');";\r
2120                 browser.page().mainFrame().evaluateJavaScript(js);\r
2121                 contentChanged();\r
2122         }\r
2123         \r
2124         \r
2125         //****************************************************************\r
2126         //* MicroFocus changed\r
2127         //****************************************************************\r
2128         private void microFocusChanged() {\r
2129                 boldButton.setDown(false);\r
2130                 italicButton.setDown(false);\r
2131                 underlineButton.setDown(false);\r
2132                 browser.openAction.setEnabled(false);\r
2133                 browser.downloadAttachment.setEnabled(false);\r
2134                 browser.downloadImage.setEnabled(false);\r
2135                 browser.rotateImageLeft.setEnabled(false);\r
2136                 browser.rotateImageRight.setEnabled(false);\r
2137                 browser.insertTableAction.setEnabled(true);\r
2138                 browser.insertTableRowAction.setEnabled(false);\r
2139                 browser.deleteTableRowAction.setEnabled(false);\r
2140                 browser.insertLinkAction.setText(tr("Insert Hyperlink"));\r
2141                 currentHyperlink ="";\r
2142                 insideList = false;\r
2143                 forceTextPaste = false;\r
2144                 \r
2145                 String js = new String( "function getCursorPos() {"\r
2146                         +"var cursorPos;"\r
2147                         +"if (window.getSelection) {"\r
2148                         +"   var selObj = window.getSelection();"\r
2149                         +"   var selRange = selObj.getRangeAt(0);"\r
2150                         +"   var workingNode = window.getSelection().anchorNode.parentNode;"\r
2151                         +"   while(workingNode != null) { " \r
2152 //                      +"      window.jambi.printNode(workingNode.nodeName);"\r
2153                         +"      if (workingNode.nodeName=='EN-CRYPT-TEMP') window.jambi.forceTextPaste();"\r
2154                         +"      if (workingNode.nodeName=='B') window.jambi.boldActive();"\r
2155                         +"      if (workingNode.nodeName=='I') window.jambi.italicActive();"\r
2156                         +"      if (workingNode.nodeName=='U') window.jambi.underlineActive();"\r
2157                         +"      if (workingNode.nodeName=='UL') window.jambi.setInsideList();"\r
2158                         +"      if (workingNode.nodeName=='OL') window.jambi.setInsideList();"\r
2159                         +"      if (workingNode.nodeName=='LI') window.jambi.setInsideList();"\r
2160                         +"      if (workingNode.nodeName=='TBODY') window.jambi.setInsideTable();"\r
2161                         +"      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
2162                         +"      if (workingNode.nodeName=='SPAN') {"\r
2163                         +"         if (workingNode.getAttribute('style') == 'text-decoration: underline;') window.jambi.underlineActive();"\r
2164                         +"      }"\r
2165                         +"      workingNode = workingNode.parentNode;"\r
2166                         +"   }"\r
2167                         +"}"\r
2168                         +"} getCursorPos();");\r
2169                 browser.page().mainFrame().evaluateJavaScript(js);\r
2170         }\r
2171         \r
2172         public void printNode(String n) {\r
2173                 System.out.println("Node Vaule: " +n);\r
2174         }\r
2175         \r
2176         \r
2177         //****************************************************************\r
2178         //* Insert a table row\r
2179         //****************************************************************\r
2180         public void insertTableRow() {\r
2181                 \r
2182                 String js = new String( "function insertTableRow() {"\r
2183                         +"   var selObj = window.getSelection();"\r
2184                         +"   var selRange = selObj.getRangeAt(0);"\r
2185                         +"   var workingNode = window.getSelection().anchorNode.parentNode;"\r
2186                         +"   var cellCount = 0;"\r
2187                         +"   while(workingNode != null) { " \r
2188                         +"      if (workingNode.nodeName.toLowerCase()=='tr') {"\r
2189                         +"           row = document.createElement('TR');"\r
2190                         +"           var nodes = workingNode.getElementsByTagName('td');"\r
2191                         +"           for (j=0; j<nodes.length; j=j+1) {"\r
2192                         +"              cell = document.createElement('TD');"\r
2193                         +"              cell.innerHTML='&nbsp;';"\r
2194                         +"              row.appendChild(cell);"\r
2195                         +"           }"                 \r
2196                         +"           workingNode.parentNode.insertBefore(row,workingNode.nextSibling);"\r
2197                         +"           return;"\r
2198                         +"      }"\r
2199                         +"      workingNode = workingNode.parentNode;"\r
2200                         +"   }"\r
2201                         +"} insertTableRow();");\r
2202                 browser.page().mainFrame().evaluateJavaScript(js);\r
2203                 contentChanged();\r
2204         }\r
2205         //****************************************************************\r
2206         //* Insert a table row\r
2207         //****************************************************************\r
2208         public void deleteTableRow() {\r
2209                 \r
2210                 String js = new String( "function deleteTableRow() {"\r
2211                         +"   var selObj = window.getSelection();"\r
2212                         +"   var selRange = selObj.getRangeAt(0);"\r
2213                         +"   var workingNode = window.getSelection().anchorNode.parentNode;"\r
2214                         +"   var cellCount = 0;"\r
2215                         +"   while(workingNode != null) { " \r
2216                         +"      if (workingNode.nodeName.toLowerCase()=='tr') {"\r
2217                         +"           workingNode.parentNode.removeChild(workingNode);"\r
2218                         +"           return;"\r
2219                         +"      }"\r
2220                         +"      workingNode = workingNode.parentNode;"\r
2221                         +"   }"\r
2222                         +"} deleteTableRow();");\r
2223                 browser.page().mainFrame().evaluateJavaScript(js);\r
2224                 contentChanged();\r
2225         }\r
2226         public void setInsideTable() {\r
2227                 browser.insertTableRowAction.setEnabled(true);\r
2228                 browser.deleteTableRowAction.setEnabled(true);\r
2229                 browser.insertTableAction.setEnabled(false);\r
2230                 browser.encryptAction.setEnabled(false);\r
2231         }\r
2232         \r
2233         public void setInsideLink(String link) {\r
2234                 browser.insertLinkAction.setText(tr("Edit Hyperlink"));\r
2235                 currentHyperlink = link;\r
2236         }\r
2237         \r
2238         public void italicActive() {\r
2239                 italicButton.setDown(true);\r
2240         }\r
2241         public void boldActive() {\r
2242                 boldButton.setDown(true);\r
2243         }\r
2244         public void underlineActive() {\r
2245                 underlineButton.setDown(true);\r
2246         }\r
2247         public void forceTextPaste() {\r
2248                 forceTextPaste = true;\r
2249         }\r
2250         public void imageContextMenu(String f) {\r
2251                 browser.downloadImage.setEnabled(true);\r
2252                 browser.rotateImageRight.setEnabled(true);\r
2253                 browser.rotateImageLeft.setEnabled(true);\r
2254                 browser.openAction.setEnabled(true);\r
2255                 selectedFile = f;\r
2256         }\r
2257         public void rotateImageRight() {\r
2258                 QWebSettings.setMaximumPagesInCache(0);\r
2259                 QWebSettings.setObjectCacheCapacities(0, 0, 0);\r
2260                 QImage image = new QImage(selectedFile);\r
2261                 QMatrix matrix = new QMatrix();\r
2262                 matrix.rotate( 90.0 );\r
2263                 image = image.transformed(matrix);\r
2264                 image.save(selectedFile);\r
2265                 QWebSettings.setMaximumPagesInCache(0);\r
2266                 QWebSettings.setObjectCacheCapacities(0, 0, 0);\r
2267                 browser.setHtml(browser.page().mainFrame().toHtml());\r
2268                 browser.reload();\r
2269                 contentChanged();\r
2270 //              resourceSignal.contentChanged.emit(selectedFile);\r
2271 \r
2272         }\r
2273         public void rotateImageLeft() {\r
2274                 QImage image = new QImage(selectedFile);\r
2275                 QMatrix matrix = new QMatrix();\r
2276                 matrix.rotate( -90.0 );\r
2277                 image = image.transformed(matrix);\r
2278                 image.save(selectedFile);\r
2279                 browser.setHtml(browser.page().mainFrame().toHtml());\r
2280                 browser.reload();\r
2281                 contentChanged();\r
2282 //              resourceSignal.contentChanged.emit(selectedFile);\r
2283         }\r
2284         public void resourceContextMenu(String f) {\r
2285                 browser.downloadAttachment.setEnabled(true);\r
2286                 browser.openAction.setEnabled(true);\r
2287                 selectedFile = f;\r
2288         }\r
2289         \r
2290         \r
2291         //****************************************************************\r
2292         //* Apply CSS style to specified word\r
2293         //****************************************************************\r
2294 /*      public void applyStyleToWords(String word, String style) {\r
2295                 QFile script = new QFile("D:\\NeverNote\\js\\hilight1.js");\r
2296                 script.open(OpenModeFlag.ReadOnly);\r
2297                 String s = script.readAll().toString();\r
2298                 String js = new String(s +" findit('"+word+"', '"+style+"');");\r
2299                 browser.page().mainFrame().evaluateJavaScript(js);\r
2300                 System.out.println(getContent());\r
2301         }\r
2302 */      \r
2303         //****************************************************************\r
2304         //* Someone tried to paste a resource between notes, so we need  *\r
2305         //* to do some special handling.                                 *\r
2306         //****************************************************************\r
2307         private String fixInternotePaste(String text) {\r
2308                 logger.log(logger.EXTREME, "Fixing internote paste");\r
2309                 String returnValue = fixInternotePasteSearch(text, "<img", "src=\"");\r
2310                 return fixInternotePasteSearch(returnValue, "<a", "href=\"nnres://");\r
2311         }\r
2312         private String fixInternotePasteSearch(String text, String type, String locTag) {\r
2313                 \r
2314                 // First, let's fix the images.\r
2315                 int startPos = text.indexOf(type);\r
2316                 int endPos;\r
2317                 for (; startPos>=0;) {\r
2318                         endPos = text.indexOf(">", startPos+1);\r
2319                         String segment = text.substring(startPos, endPos);\r
2320                         if (segment.indexOf("en-tag") > -1) {\r
2321                                 String newSegment = segment;\r
2322                                 \r
2323                                 int guidStartPos = segment.indexOf("guid=\"");\r
2324                                 int guidEndPos = segment.indexOf("\"", guidStartPos+7);\r
2325                                 String guid = segment.substring(guidStartPos+6,guidEndPos);\r
2326                                 \r
2327                                 int mimeStartPos = segment.indexOf("type");\r
2328                                 int mimeEndPos = segment.indexOf("\"", mimeStartPos+7);\r
2329                                 String mime = segment.substring(mimeStartPos+6,mimeEndPos);\r
2330 \r
2331                                 int srcStartPos = segment.indexOf("src");\r
2332                                 int srcEndPos = segment.indexOf("\"", srcStartPos+6);\r
2333                                 String src = segment.substring(srcStartPos+5,srcEndPos);\r
2334                                 \r
2335                                 Calendar currentTime = new GregorianCalendar();\r
2336                                 Long l = new Long(currentTime.getTimeInMillis());\r
2337                                 long prevTime = l;\r
2338                                 while (l==prevTime) {\r
2339                                         currentTime = new GregorianCalendar();\r
2340                                         l= new Long(currentTime.getTimeInMillis());\r
2341                                 }\r
2342                                 \r
2343                                 Resource r = conn.getNoteTable().noteResourceTable.getNoteResource(guid, true);\r
2344                                 // if r==null, then the image doesn't exist (it was probably cut out of another note, so \r
2345                                 // we need to recereate it\r
2346                                 if (r==null) {\r
2347                                         r = createResource(src, 1, mime, false);\r
2348                                         if (r==null)\r
2349                                                 return "";\r
2350                                 }\r
2351                         String randint = new String(Long.toString(l));\r
2352                         String extension = null;\r
2353                         if (r.getMime()!= null) {\r
2354                                 extension = r.getMime().toLowerCase();\r
2355                                 if (extension.indexOf("/")>-1)\r
2356                                         extension = extension.substring(extension.indexOf("/")+1);\r
2357                         }\r
2358                         String newFile = randint;\r
2359                         if (r.getAttributes().getFileName() != null && r.getAttributes().getFileName() != "")\r
2360                                 if (!locTag.startsWith("src"))\r
2361                                         newFile = newFile+Global.attachmentNameDelimeter+r.getAttributes().getFileName();\r
2362                         r.setNoteGuid(currentNote.getGuid());\r
2363                         \r
2364                         r.setGuid(randint);\r
2365                         conn.getNoteTable().noteResourceTable.saveNoteResource(r, true);\r
2366                                 QFile f = new QFile(Global.getFileManager().getResDirPath(newFile));\r
2367                                 QByteArray bin = new QByteArray(r.getData().getBody());\r
2368                                 f.open(QFile.OpenModeFlag.WriteOnly);\r
2369                                 f.write(bin);\r
2370                                 f.close();\r
2371                                 newSegment = newSegment.replace("guid=\""+guid, "guid=\""+randint);\r
2372                                 currentNote.getResources().add(r);\r
2373                                 \r
2374                                 int startSrcPos = newSegment.indexOf(locTag);\r
2375                                 int endSrcPos = newSegment.indexOf("\"",startSrcPos+locTag.length()+1);\r
2376                                 String source; \r
2377                                 if (locTag.startsWith("src")) {\r
2378                                          source = newSegment.substring(startSrcPos+locTag.length(),endSrcPos);\r
2379                                                 newSegment = newSegment.replace(source,\r
2380                                                         FileUtils.toForwardSlashedPath(Global.getFileManager().getResDirPath(newFile)));\r
2381                                 } else {\r
2382                                         source = newSegment.substring(startSrcPos+locTag.length(),endSrcPos);\r
2383                                         newSegment = newSegment.replace(source, newFile);\r
2384                                 }\r
2385                                 \r
2386                                 text = text.substring(0,startPos) + newSegment + text.substring(endPos);\r
2387                         }\r
2388                         startPos = text.indexOf(type, startPos+1);\r
2389                 }\r
2390                 return text;\r
2391         }\r
2392 \r
2393 \r
2394         public void nextPage(String file) {\r
2395                 logger.log(logger.EXTREME, "Starting nextPage()");\r
2396                 \r
2397                 Integer pageNumber;\r
2398                 if (previewPageList.containsKey(file))\r
2399                         pageNumber = previewPageList.get(file)+1;\r
2400                 else\r
2401                         pageNumber = 2;\r
2402                 previewPageList.remove(file);\r
2403                 previewPageList.put(file, pageNumber);\r
2404                 PDFPreview pdfPreview = new PDFPreview();\r
2405                 boolean goodPreview = pdfPreview.setupPreview(file, "pdf", pageNumber);\r
2406                 if (goodPreview) {\r
2407 \r
2408 //                      String html = getContent();\r
2409                         QWebSettings.setMaximumPagesInCache(0);\r
2410                         QWebSettings.setObjectCacheCapacities(0, 0, 0);\r
2411 //                      browser.setContent(new QByteArray());\r
2412                         browser.setHtml(browser.page().mainFrame().toHtml());\r
2413                         browser.reload();\r
2414 //                      browser.setContent(new QByteArray(html));\r
2415 //                      browser.triggerPageAction(WebAction.Reload);\r
2416 //                      pdfMouseOver(selectedFile);\r
2417                 }\r
2418         }\r
2419 \r
2420         public void previousPage(String file) {\r
2421                 logger.log(logger.EXTREME, "Starting previousPage()");\r
2422                 \r
2423                 Integer pageNumber;\r
2424                 if (previewPageList.containsKey(file))\r
2425                         pageNumber = previewPageList.get(file)-1;\r
2426                 else\r
2427                         pageNumber = 1;\r
2428                 previewPageList.remove(file);\r
2429                 previewPageList.put(file, pageNumber);\r
2430                 PDFPreview pdfPreview = new PDFPreview();\r
2431                 boolean goodPreview = pdfPreview.setupPreview(file, "pdf", pageNumber);\r
2432                 if (goodPreview) {\r
2433 \r
2434 //                      String html = getContent();\r
2435                         QWebSettings.setMaximumPagesInCache(0);\r
2436                         QWebSettings.setObjectCacheCapacities(0, 0, 0);\r
2437                         browser.setHtml(browser.page().mainFrame().toHtml());\r
2438                         browser.reload();\r
2439 //                      browser.setContent(new QByteArray(html));\r
2440 //                      browser.triggerPageAction(WebAction.Reload);\r
2441                 }\r
2442         }\r
2443         \r
2444 /*      public void pdfMouseOver(String name) { \r
2445                 int pageNumber;\r
2446                 if (previewPageList.containsKey(selectedFile))\r
2447                         pageNumber = previewPageList.get(selectedFile)+1;\r
2448                 else\r
2449                         pageNumber = 1;\r
2450                 \r
2451                 if (pageNumber <= 1)\r
2452                         browser.previousPageAction.setEnabled(false);\r
2453                 else\r
2454                         browser.previousPageAction.setEnabled(true);\r
2455                 \r
2456                 PDFPreview pdf = new PDFPreview();\r
2457                 int totalPages = pdf.getPageCount(name);\r
2458                 if (previewPageList.containsKey(selectedFile))\r
2459                         pageNumber = previewPageList.get(selectedFile)+1;\r
2460                 else\r
2461                         pageNumber = 1;\r
2462                 if (totalPages > pageNumber)\r
2463                         browser.nextPageAction.setEnabled(true);\r
2464                 else\r
2465                         browser.nextPageAction.setEnabled(false);\r
2466         }\r
2467         \r
2468 \r
2469         public void pdfMouseOut() { \r
2470 //              browser.nextPageAction.setVisible(false);\r
2471 //              browser.previousPageAction.setVisible(false);\r
2472         }\r
2473 */\r
2474         \r
2475         private void toggleUndoVisible(Boolean toggle) {\r
2476                 undoAction.setVisible(toggle);\r
2477                 Global.saveEditorButtonsVisible("undo", toggle);\r
2478         }\r
2479         private void toggleRedoVisible(Boolean toggle) {\r
2480                 redoAction.setVisible(toggle);\r
2481                 Global.saveEditorButtonsVisible("redo", toggle);\r
2482         }\r
2483         private void toggleCutVisible(Boolean toggle) {\r
2484                 cutAction.setVisible(toggle);\r
2485                 Global.saveEditorButtonsVisible("cut", toggle);\r
2486         }\r
2487         private void toggleCopyVisible(Boolean toggle) {\r
2488                 copyAction.setVisible(toggle);\r
2489                 Global.saveEditorButtonsVisible("copy", toggle);\r
2490         }\r
2491         private void togglePasteVisible(Boolean toggle) {\r
2492                 pasteAction.setVisible(toggle);\r
2493                 Global.saveEditorButtonsVisible("paste", toggle);\r
2494         }\r
2495         private void toggleBoldVisible(Boolean toggle) {\r
2496                 boldAction.setVisible(toggle);\r
2497                 Global.saveEditorButtonsVisible("bold", toggle);\r
2498         }\r
2499         private void toggleItalicVisible(Boolean toggle) {\r
2500                 italicAction.setVisible(toggle);\r
2501                 Global.saveEditorButtonsVisible("italic", toggle);\r
2502         }\r
2503         private void toggleUnderlineVisible(Boolean toggle) {\r
2504                 underlineAction.setVisible(toggle);\r
2505                 Global.saveEditorButtonsVisible("underline", toggle);\r
2506         }\r
2507         private void toggleStrikethroughVisible(Boolean toggle) {\r
2508                 strikethroughAction.setVisible(toggle);\r
2509                 Global.saveEditorButtonsVisible("strikethrough", toggle);\r
2510         }\r
2511         private void toggleLeftAlignVisible(Boolean toggle) {\r
2512                 leftAlignAction.setVisible(toggle);\r
2513                 Global.saveEditorButtonsVisible("alignLeft", toggle);\r
2514         }\r
2515         private void toggleRightAlignVisible(Boolean toggle) {\r
2516                 rightAlignAction.setVisible(toggle);\r
2517                 Global.saveEditorButtonsVisible("alignRight", toggle);\r
2518         }       \r
2519         private void toggleCenterAlignVisible(Boolean toggle) {\r
2520                 centerAlignAction.setVisible(toggle);\r
2521                 Global.saveEditorButtonsVisible("alignCenter", toggle);\r
2522         }\r
2523         private void toggleHLineVisible(Boolean toggle) {\r
2524                 hlineAction.setVisible(toggle);\r
2525                 Global.saveEditorButtonsVisible("hline", toggle);\r
2526         }\r
2527         private void toggleIndentVisible(Boolean toggle) {\r
2528                 indentAction.setVisible(toggle);\r
2529                 Global.saveEditorButtonsVisible("indent", toggle);\r
2530         }\r
2531         private void toggleOutdentVisible(Boolean toggle) {\r
2532                 outdentAction.setVisible(toggle);\r
2533                 Global.saveEditorButtonsVisible("outdent", toggle);\r
2534         }\r
2535         private void toggleBulletListVisible(Boolean toggle) {\r
2536                 bulletListAction.setVisible(toggle);\r
2537                 Global.saveEditorButtonsVisible("bulletList", toggle);\r
2538         }\r
2539         private void toggleNumberListVisible(Boolean toggle) {\r
2540                 numberListAction.setVisible(toggle);\r
2541                 Global.saveEditorButtonsVisible("numberList", toggle);\r
2542         }\r
2543         private void toggleFontListVisible(Boolean toggle) {\r
2544                 fontListAction.setVisible(toggle);\r
2545                 Global.saveEditorButtonsVisible("font", toggle);\r
2546         }\r
2547         private void toggleFontColorVisible(Boolean toggle) {\r
2548                 fontColorAction.setVisible(toggle);\r
2549                 Global.saveEditorButtonsVisible("fontColor", toggle);\r
2550         }\r
2551         private void toggleFontSizeVisible(Boolean toggle) {\r
2552                 fontSizeAction.setVisible(toggle);\r
2553                 Global.saveEditorButtonsVisible("fontSize", toggle);\r
2554         }\r
2555         private void toggleFontHilightVisible(Boolean toggle) {\r
2556                 fontHilightAction.setVisible(toggle);\r
2557                 Global.saveEditorButtonsVisible("fontHilight", toggle);\r
2558         }\r
2559 \r
2560 \r
2561 \r
2562 \r
2563 }\r