import com.trolltech.qt.gui.QIcon;
import com.trolltech.qt.gui.QImage;
import com.trolltech.qt.gui.QLabel;
-import com.trolltech.qt.gui.QListWidget;
import com.trolltech.qt.gui.QMainWindow;
import com.trolltech.qt.gui.QMenu;
import com.trolltech.qt.gui.QMessageBox;
import cx.fbn.nevernote.dialog.DatabaseStatus;
import cx.fbn.nevernote.dialog.FindDialog;
import cx.fbn.nevernote.dialog.IgnoreSync;
+import cx.fbn.nevernote.dialog.LogFileDialog;
import cx.fbn.nevernote.dialog.LoginDialog;
import cx.fbn.nevernote.dialog.NotebookArchive;
import cx.fbn.nevernote.dialog.NotebookEdit;
private boolean closeAction = false; // Used to say when to close or when to minimize
private static Logger log = Logger.getLogger(NeverNote.class);
private String saveLastPath; // last path we used
+ private final QTimer messageTimer; // Timer to clear the status message.
String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
System.exit(16);
}
- thread().setPriority(Thread.MAX_PRIORITY);
+// thread().setPriority(Thread.MAX_PRIORITY);
logger = new ApplicationLogger("nevernote.log");
logger.log(logger.HIGH, "Starting Application");
mainLeftRightSplitter.addWidget(browserWindow);
}
+ messageTimer = new QTimer();
+ messageTimer.timeout.connect(this, "clearMessage()");
+ messageTimer.setInterval(1000*15);
+ clearMessage();
+
int sortCol = Global.getSortColumn();
int sortOrder = Global.getSortOrder();
noteTableView.sortByColumn(sortCol, SortOrder.resolve(sortOrder));
externalFileEditedSaver();
if (Global.isConnected && Global.synchronizeOnClose()) {
setMessage(tr("Performing synchronization before closing."));
+ syncRunner.syncNeeded = true;
syncRunner.addWork("SYNC");
+ syncRunner.addWork("STOP");
+ } else {
+ syncRunner.addWork("STOP");
+ syncRunner.keepRunning = false;
}
setMessage("Closing Program.");
threadMonitorTimer.stop();
- syncRunner.addWork("STOP");
- syncRunner.keepRunning = false;
thumbnailRunner.addWork("STOP");
- syncRunner.keepRunning = false;
indexRunner.addWork("STOP");
- syncRunner.keepRunning = false;
saveNote();
listManager.stop();
saveWindowState();
} catch (InterruptedException e1) {
e1.printStackTrace();
}
+
+ syncRunner.addWork("STOP");
if (!syncRunner.isIdle()) {
- try {
+ //try {
logger.log(logger.MEDIUM, "Waiting for syncThread to stop");
- syncThread.join();
+ System.out.println(tr("Synchronizing. Please be patient."));
+ while (!syncRunner.isIdle());
logger.log(logger.MEDIUM, "Sync thread has stopped");
- } catch (InterruptedException e1) {
- e1.printStackTrace();
- }
+ //} catch (InterruptedException e1) {
+ // e1.printStackTrace();
+ //}
}
if (encryptOnShutdown) {
}
public void setMessage(String s) {
logger.log(logger.HIGH, "Entering NeverNote.setMessage");
+
+ statusBar.show();
logger.log(logger.HIGH, "Message: " +s);
statusBar.showMessage(s);
emitLog.add(s);
+
+
+ messageTimer.stop();
+ messageTimer.setSingleShot(true);
+ messageTimer.start();
+
+
logger.log(logger.HIGH, "Leaving NeverNote.setMessage");
}
+
+ private void clearMessage() {
+ statusBar.clearMessage();
+ statusBar.hide();
+ }
private void waitCursor(boolean wait) {
if (wait) {
@SuppressWarnings("unused")
private void logger() {
logger.log(logger.HIGH, "Entering NeverNote.logger");
- QDialog dialog = new QDialog(this);
- QHBoxLayout layout = new QHBoxLayout();
- QListWidget textBox = new QListWidget();
- layout.addWidget(textBox);
- textBox.addItems(emitLog);
-
- dialog.setLayout(layout);
- dialog.setWindowTitle(tr("Mesasge Log"));
- dialog.show();
+ LogFileDialog dialog = new LogFileDialog(emitLog);
+ dialog.exec();
logger.log(logger.HIGH, "Leaving NeverNote.logger");
}
// Menu option "help/about" was selected
} catch (FileNotFoundException e) {
// File not found, so we'll just get empty strings anyway.
}
+
+ if (Global.getProxyValue("url").equals("")) {
+ System.setProperty("http.proxyHost","") ;
+ System.setProperty("http.proxyPort", "") ;
+ System.setProperty("https.proxyHost","") ;
+ System.setProperty("https.proxyPort", "") ;
+ } else {
+ // PROXY
+ System.setProperty("http.proxyHost",Global.getProxyValue("url")) ;
+ System.setProperty("http.proxyPort", Global.getProxyValue("port")) ;
+ System.setProperty("https.proxyHost",Global.getProxyValue("url")) ;
+ System.setProperty("https.proxyPort", Global.getProxyValue("port")) ;
+
+ if (Global.getProxyValue("userid").equals("")) {
+ Authenticator.setDefault(new Authenticator() {
+ @Override
+ protected PasswordAuthentication getPasswordAuthentication() {
+ return new
+ PasswordAuthentication(Global.getProxyValue("userid"),Global.getProxyValue("password").toCharArray());
+ }
+ });
+ }
+ }
+
+ syncRunner.userStoreUrl = Global.userStoreUrl;
+ syncRunner.noteStoreUrl = Global.noteStoreUrl;
+ syncRunner.noteStoreUrlBase = Global.noteStoreUrlBase;
+
String userid = aes.getUserid();
String password = aes.getPassword();
if (!userid.equals("") && !password.equals("")) {
Global.username = userid;
Global.password = password;
+ syncRunner.username = Global.username;
+ syncRunner.password = Global.password;
+ syncRunner.enConnect();
}
- // Show the login dialog box
- if (!Global.automaticLogin() || userid.equals("")|| password.equals("")) {
- LoginDialog login = new LoginDialog();
- login.exec();
+ Global.isConnected = syncRunner.isConnected;
- if (!login.okPressed()) {
- return;
- }
+ if (!Global.isConnected) {
+ // Show the login dialog box
+ if (!Global.automaticLogin() || userid.equals("")|| password.equals("")) {
+ LoginDialog login = new LoginDialog();
+ login.exec();
+
+ if (!login.okPressed()) {
+ return;
+ }
- Global.username = login.getUserid();
- Global.password = login.getPassword();
+ Global.username = login.getUserid();
+ Global.password = login.getPassword();
+ }
+ syncRunner.username = Global.username;
+ syncRunner.password = Global.password;
+ syncRunner.enConnect();
+ Global.isConnected = syncRunner.isConnected;
}
- syncRunner.username = Global.username;
- syncRunner.password = Global.password;
- syncRunner.userStoreUrl = Global.userStoreUrl;
- syncRunner.noteStoreUrl = Global.noteStoreUrl;
- syncRunner.noteStoreUrlBase = Global.noteStoreUrlBase;
- if (Global.getProxyValue("url").equals("")) {
- System.setProperty("http.proxyHost","") ;
- System.setProperty("http.proxyPort", "") ;
- System.setProperty("https.proxyHost","") ;
- System.setProperty("https.proxyPort", "") ;
- } else {
- // PROXY
- System.setProperty("http.proxyHost",Global.getProxyValue("url")) ;
- System.setProperty("http.proxyPort", Global.getProxyValue("port")) ;
- System.setProperty("https.proxyHost",Global.getProxyValue("url")) ;
- System.setProperty("https.proxyPort", Global.getProxyValue("port")) ;
-
- if (Global.getProxyValue("userid").equals("")) {
- Authenticator.setDefault(new Authenticator() {
- @Override
- protected PasswordAuthentication getPasswordAuthentication() {
- return new
- PasswordAuthentication(Global.getProxyValue("userid"),Global.getProxyValue("password").toCharArray());
- }});
- }
- }
-
-
- syncRunner.enConnect();
- Global.isConnected = syncRunner.isConnected;
+ if (!Global.isConnected)
+ return;
setupOnlineMenu();
setupConnectMenuOptions();
logger.log(logger.HIGH, "Leaving NeverNote.remoteConnect");
}
}
if (!match)
- goodNotebooks.add(listManager.getNotebookIndex().get(i).deepCopy());
+ //goodNotebooks.add(listManager.getNotebookIndex().get(i).deepCopy());
+ goodNotebooks.add((Notebook)Global.deepCopy(listManager.getNotebookIndex().get(i)));
}
// Now we have a list of good notebooks, so we can look for the default
found = false;
currentNote = newNote;
currentNoteGuid = currentNote.getGuid();
+ noteTableView.clearSelection();
refreshEvernoteNote(true);
listManager.countNotebookResults(listManager.getNoteIndex());
browserWindow.titleLabel.setFocus();
}
private void duplicateNote(String guid) {
- Note oldNote = conn.getNoteTable().getNote(guid, true, true, false, false, false);
+ Note oldNote = conn.getNoteTable().getNote(guid, true, false,false,false,true);
List<Resource> resList = conn.getNoteTable().noteResourceTable.getNoteResources(guid, true);
oldNote.setContent(conn.getNoteTable().getNoteContentBinary(guid));
oldNote.setResources(resList);
Long l = new Long(currentTime.getTimeInMillis());
String newGuid = new String(Long.toString(l));
- Note newNote = oldNote.deepCopy();
+// Note newNote = oldNote.deepCopy();
+ Note newNote = (Note)Global.deepCopy(oldNote);
newNote.setUpdateSequenceNum(0);
newNote.setGuid(newGuid);
newNote.setDeleted(0);
newNote.setActive(true);
+
+ /*
+ List<String> tagNames = new ArrayList<String>();
+ List<String> tagGuids = new ArrayList<String>();;
+ for (int i=0; i<oldNote.getTagGuidsSize(); i++) {
+ tagNames.add(oldNote.getTagNames().get(i));
+ tagGuids.add(oldNote.getTagGuids().get(i));
+ }
+
+ // Sort note Tags to make them look nice
+ for (int i=0; i<tagNames.size()-1; i++) {
+ if (tagNames.get(i).compareTo(tagNames.get(i+1))<0) {
+ String n1 = tagNames.get(i);
+ String n2 = tagNames.get(i+1);
+ tagNames.set(i, n2);
+ tagNames.set(i+1, n1);
+ }
+ }
+ newNote.setTagGuids(tagGuids);
+ newNote.setTagNames(tagNames);
+
+ // Add tag guids to note
+ */
+
+ // Duplicate resources
List<Resource> resList = oldNote.getResources();
if (resList == null)
resList = new ArrayList<Resource>();
resList.get(i).setGuid(newResGuid);
resList.get(i).setUpdateSequenceNum(0);
resList.get(i).setActive(true);
- conn.getNoteTable().noteResourceTable.saveNoteResource(new Resource(resList.get(i).deepCopy()), true);
+ conn.getNoteTable().noteResourceTable.saveNoteResource(
+ (Resource)Global.deepCopy(resList.get(i)), true);
}
newNote.setResources(resList);
+
+ // Add note to the database
listManager.addNote(newNote);
conn.getNoteTable().addNote(newNote, true);
listManager.getUnsynchronizedNotes().add(newNote.getGuid());
noteTableView.insertRow(newNote, true, -1);
+ currentNoteGuid = newNote.getGuid();
+ currentNote = newNote;
+ refreshEvernoteNote(true);
listManager.countNotebookResults(listManager.getNoteIndex());
waitCursor(false);
}