OSDN Git Service

Allow proxy settings for OAuth interface.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / NeverNote.java
index a311ffd..ff0bf46 100644 (file)
@@ -134,6 +134,8 @@ import com.trolltech.qt.gui.QTextEdit;
 import com.trolltech.qt.gui.QToolBar;
 import com.trolltech.qt.gui.QTreeWidgetItem;
 import com.trolltech.qt.network.QNetworkAccessManager;
+import com.trolltech.qt.network.QNetworkProxy;
+import com.trolltech.qt.network.QNetworkProxy.ProxyType;
 import com.trolltech.qt.network.QNetworkReply;
 import com.trolltech.qt.network.QNetworkRequest;
 import com.trolltech.qt.webkit.QWebPage.WebAction;
@@ -263,6 +265,7 @@ public class NeverNote extends QMainWindow{
     QTimer                                     authTimer;                                      // Refresh authentication
     QTimer                                     externalFileSaveTimer;          // Save files altered externally
     QTimer                                     thumbnailTimer;                         // Wakeup & scan for thumbnails
+    QTimer                                     debugTimer;
     List<String>                       externalFiles;                          // External files to save later
     List<String>                       importFilesKeep;                        // Auto-import files to save later
     List<String>                       importFilesDelete;                      // Auto-import files to save later
@@ -474,6 +477,10 @@ public class NeverNote extends QMainWindow{
                thumbnailTimer.setInterval(500*1000);  // Thumbnail every minute
                thumbnailTimer.start();
                
+//             debugTimer = new QTimer();
+//             debugTimer.timeout.connect(this, "debugDirty()");
+//             debugTimer.start(1000*60);
+               
                logger.log(logger.EXTREME, "Starting authentication timer");
                authTimer = new QTimer();
                authTimer.timeout.connect(this, "authTimer()");
@@ -773,7 +780,8 @@ public class NeverNote extends QMainWindow{
                noteTableView.proxyModel.blocked = true;
                // We sort the table twice to fix a bug.  For some reaosn the table won't sort properly if it is in narrow
                // list view and sorted descending on the date  created.  By sorting it twice it forces the proper sort.  Ugly.
-               noteTableView.sortByColumn(sortCol, SortOrder.resolve(0));   
+               if (sortCol == 0 && sortOrder == 1 && Global.getListView() == Global.View_List_Narrow) 
+                       noteTableView.sortByColumn(sortCol, SortOrder.resolve(0));   
                noteTableView.sortByColumn(sortCol, SortOrder.resolve(sortOrder));
                noteTableView.proxyModel.blocked = false;
                noteTableView.proxyModel.sortChanged.connect(this, "tableSortOrderChanged(Integer,Integer)");
@@ -790,9 +798,22 @@ public class NeverNote extends QMainWindow{
                }
        }
                
+   
+                       
+                       
                if (Global.checkVersionUpgrade())
                        checkForUpdates();
        }
+       
+       
+       public void debugDirty() {
+               List<Note> dirty = conn.getNoteTable().getDirty();
+               logger.log(logger.LOW, "------ Dirty Notes List Begin ------");
+               for (int i=0; i<dirty.size(); i++) {
+                       logger.log(logger.LOW, "GUID: " +dirty.get(i).getGuid() + " Title:" + dirty.get(i).getTitle());
+               }
+               logger.log(logger.LOW, "------ Dirty Notes List End ------");
+       }
                
        // Main entry point
        public static void main(String[] args) {
@@ -822,6 +843,39 @@ public class NeverNote extends QMainWindow{
             QMessageBox.critical(null, "Startup error", "Aborting: " + e.getMessage());
             return;
         }
+        
+               // Setup proxy crap
+               String proxyUrl = Global.getProxyValue("url");
+               String proxyPort = Global.getProxyValue("port");
+               String proxyUserid = Global.getProxyValue("userid");
+               String proxyPassword = Global.getProxyValue("password");
+               boolean proxySet = false;
+               QNetworkProxy proxy = new QNetworkProxy();
+               proxy.setType(ProxyType.HttpProxy);
+               if (!proxyUrl.trim().equals("")) {
+                       System.out.println("Proxy URL found: " +proxyUrl);
+                       proxySet = true;
+                       proxy.setHostName(proxyUrl);
+               }
+               if (!proxyPort.trim().equals("")) {
+                       System.out.println("Proxy Port found: " +proxyPort);
+                       proxySet = true;
+                       proxy.setPort(Integer.parseInt(proxyPort));
+               }
+               if (!proxyUserid.trim().equals("")) {
+                       System.out.println("Proxy Userid found: " +proxyUserid);
+                       proxySet = true;
+                       proxy.setUser(proxyUserid);
+               }
+               if (!proxyPassword.trim().equals("")) {
+                       System.out.println("Proxy URL found: " +proxyPassword);
+                       proxySet = true;
+                       proxy.setPassword(proxyPassword);
+               }
+               if (proxySet) {
+                       QNetworkProxy.setApplicationProxy(proxy);
+               }
+                       
 
         NeverNote application = new NeverNote(dbConn);
                if (Global.syncOnly) {
@@ -1134,20 +1188,28 @@ public class NeverNote extends QMainWindow{
                close();
        }
        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");
+               if (logger != null) 
+                       logger.log(logger.HIGH, "Entering NeverNote.setMessage");
+               else
+                       System.out.println("*** ERROR *** " +s);
+               
+               if (statusBar != null) {
+                       statusBar.show();
+                       if (logger != null) 
+                               logger.log(logger.HIGH, "Message: " +s);
+                       statusBar.showMessage(s);
+                       if (emitLog != null)
+                               emitLog.add(s);
+               
+                       if (messageTimer != null) {
+                               messageTimer.stop();
+                               messageTimer.setSingleShot(true);
+                               messageTimer.start();
+                       }
+               }
+                       
+               if (logger != null) 
+                       logger.log(logger.HIGH, "Leaving NeverNote.setMessage");
        }
        
        private void clearMessage() {
@@ -1436,7 +1498,8 @@ public class NeverNote extends QMainWindow{
                clearSavedSearchFilter();
                if (Global.mimicEvernoteInterface) {
                        clearTagFilter();
-                       searchField.clear();
+                       //searchField.clear();
+                       searchField.clearEditText();
                }
                menuBar.noteRestoreAction.setVisible(false);            
        menuBar.notebookEditAction.setEnabled(true);
@@ -2756,8 +2819,8 @@ public class NeverNote extends QMainWindow{
                QMessageBox.about(this, 
                                                tr("About NixNote"),
                                                tr("<h4><center><b>NixNote</b></center></h4><hr><center>Version ")
-                                               //+Global.version
-                                               +"1.2.120724"
+                                               +Global.version
+                                               //+"1.2.120724"
                                                +tr("<hr>"
                                                                +"Open Source Evernote Client.<br><br>" 
                                                                +"Licensed under GPL v2.  <br><hr><br>"
@@ -3472,7 +3535,7 @@ public class NeverNote extends QMainWindow{
                        syncRunner.enConnect();
                        Global.isConnected = syncRunner.isConnected;
                }
-               Global.username = syncRunner.username;
+//             Global.username = syncRunner.username;
                        
                if (!Global.isConnected)
                        return;
@@ -6105,12 +6168,26 @@ public class NeverNote extends QMainWindow{
                
 //             importKeepWatcher.addPath(records.get(i).folder.replace('\\', '/'));
                for (int i=0; i<records.size(); i++) {
+                       logger.log(logger.LOW, "Adding file monitor: " +records.get(i).folder);
                        if (records.get(i).keep) 
                                importKeepWatcher.addPath(records.get(i).folder);
                        else
                                importDeleteWatcher.addPath(records.get(i).folder);
                }
                
+               logger.log(logger.EXTREME, "List of directories being watched (kept)...");
+               List<String> monitorDelete = importKeepWatcher.directories();
+               for (int i=0; i<monitorDelete.size(); i++) {
+                       logger.log(logger.EXTREME, monitorDelete.get(i));
+               }
+               logger.log(logger.EXTREME, "<end of list>");
+               logger.log(logger.EXTREME, "List of directories being watched (delete)...");
+               monitorDelete = importDeleteWatcher.directories();
+               for (int i=0; i<monitorDelete.size(); i++) {
+                       logger.log(logger.EXTREME, monitorDelete.get(i));
+               }
+               logger.log(logger.EXTREME, "<end of list>");
+               
                importKeepWatcher.directoryChanged.connect(this, "folderImportKeep(String)");
                importDeleteWatcher.directoryChanged.connect(this, "folderImportDelete(String)");
                
@@ -6127,6 +6204,8 @@ public class NeverNote extends QMainWindow{
                        }
                }
        }
+       
+       // Menu folderImport action triggered
        public void folderImport() {
                List<WatchFolderRecord> recs = conn.getWatchFolderTable().getAll();
                WatchFolder dialog = new WatchFolder(recs, listManager.getNotebookIndex());
@@ -6160,8 +6239,9 @@ public class NeverNote extends QMainWindow{
                setupFolderImports();
        }
        
+       
        public void folderImportKeep(String dirName) throws NoSuchAlgorithmException {
-               
+               logger.log(logger.LOW, "Inside folderImportKeep");
                String whichOS = System.getProperty("os.name");
                if (whichOS.contains("Windows")) 
                        dirName = dirName.replace('/','\\');
@@ -6173,40 +6253,44 @@ public class NeverNote extends QMainWindow{
                String notebook = conn.getWatchFolderTable().getNotebook(dirName);
 
                for (int i=0; i<list.size(); i++){
-                       
+                       logger.log(logger.LOW, "File found: " +list.get(i).fileName());
                        boolean redundant = false;
                        // Check if we've already imported this one or if it existed before
                        for (int j=0; j<importedFiles.size(); j++) {
+                               logger.log(logger.LOW, "redundant file list: " +list.get(i).absoluteFilePath());
                                if (importedFiles.get(j).equals(list.get(i).absoluteFilePath()))
                                        redundant = true;
                        }
                        
+                       logger.log(logger.LOW, "Checking if redundant: " +redundant);
                        if (!redundant) {
                                importer.setFileInfo(list.get(i));
                                importer.setFileName(list.get(i).absoluteFilePath());
                        
                        
+                               logger.log(logger.LOW, "File importing is a file: " +list.get(i).isFile());
+                               logger.log(logger.LOW, "File importing is a valid: " +importer.isValidType());
                                if (list.get(i).isFile() && importer.isValidType()) {
                        
                                        if (!importer.importFile()) {
                                                // If we can't get to the file, it is probably locked.  We'll try again later.
                                                logger.log(logger.LOW, "Unable to save externally edited file.  Saving for later.");
                                                importFilesKeep.add(list.get(i).absoluteFilePath());
-                                               return;
+                                       } else {
+
+                                               Note newNote = importer.getNote();
+                                               newNote.setNotebookGuid(notebook);
+                                               newNote.setTitle(dir.at(i));
+                                               NoteMetadata metadata = new NoteMetadata();
+                                               metadata.setDirty(true);
+                                               metadata.setGuid(newNote.getGuid());
+                                               listManager.addNote(newNote, metadata);
+                                               conn.getNoteTable().addNote(newNote, true);
+                                               noteTableView.insertRow(newNote, metadata, true, -1);
+                                               listManager.updateNoteContent(newNote.getGuid(), importer.getNoteContent());
+                                               listManager.countNotebookResults(listManager.getNoteIndex());
+                                               importedFiles.add(list.get(i).absoluteFilePath());
                                        }
-
-                                       Note newNote = importer.getNote();
-                                       newNote.setNotebookGuid(notebook);
-                                       newNote.setTitle(dir.at(i));
-                                       NoteMetadata metadata = new NoteMetadata();
-                                       metadata.setDirty(true);
-                                       metadata.setGuid(newNote.getGuid());
-                                       listManager.addNote(newNote, metadata);
-                                       conn.getNoteTable().addNote(newNote, true);
-                                       noteTableView.insertRow(newNote, metadata, true, -1);
-                                       listManager.updateNoteContent(newNote.getGuid(), importer.getNoteContent());
-                                       listManager.countNotebookResults(listManager.getNoteIndex());
-                                       importedFiles.add(list.get(i).absoluteFilePath());
                                }
                        }
                }
@@ -6215,7 +6299,7 @@ public class NeverNote extends QMainWindow{
        }
        
        public void folderImportDelete(String dirName) {
-               
+               logger.log(logger.LOW, "Inside folderImportDelete");
                String whichOS = System.getProperty("os.name");
                if (whichOS.contains("Windows")) 
                        dirName = dirName.replace('/','\\');
@@ -6226,30 +6310,33 @@ public class NeverNote extends QMainWindow{
                String notebook = conn.getWatchFolderTable().getNotebook(dirName);
                
                for (int i=0; i<list.size(); i++){
+                       logger.log(logger.LOW, "File found: " +list.get(i).fileName());
                        importer.setFileInfo(list.get(i));
                        importer.setFileName(list.get(i).absoluteFilePath());
                        
+                       logger.log(logger.LOW, "File importing is a file: " +list.get(i).isFile());
+                       logger.log(logger.LOW, "File importing is a valid: " +importer.isValidType());
                        if (list.get(i).isFile() && importer.isValidType()) {
                
                                if (!importer.importFile()) {
                                        // If we can't get to the file, it is probably locked.  We'll try again later.
                                        logger.log(logger.LOW, "Unable to save externally edited file.  Saving for later.");
                                        importFilesKeep.add(list.get(i).absoluteFilePath());
-                                       return;
-                               }
+                               } else {
                
-                               Note newNote = importer.getNote();
-                               newNote.setNotebookGuid(notebook);
-                               newNote.setTitle(dir.at(i));
-                               NoteMetadata metadata = new NoteMetadata();
-                               metadata.setDirty(true);
-                               metadata.setGuid(newNote.getGuid());
-                               listManager.addNote(newNote, metadata);
-                               conn.getNoteTable().addNote(newNote, true);
-                               noteTableView.insertRow(newNote, metadata, true, -1);
-                               listManager.updateNoteContent(newNote.getGuid(), importer.getNoteContent());
-                               listManager.countNotebookResults(listManager.getNoteIndex());
-                               dir.remove(dir.at(i));
+                                       Note newNote = importer.getNote();
+                                       newNote.setNotebookGuid(notebook);
+                                       newNote.setTitle(dir.at(i));
+                                       NoteMetadata metadata = new NoteMetadata();
+                                       metadata.setDirty(true);
+                                       metadata.setGuid(newNote.getGuid());
+                                       listManager.addNote(newNote, metadata);
+                                       conn.getNoteTable().addNote(newNote, true);
+                                       noteTableView.insertRow(newNote, metadata, true, -1);
+                                       listManager.updateNoteContent(newNote.getGuid(), importer.getNoteContent());
+                                       listManager.countNotebookResults(listManager.getNoteIndex());
+                                       dir.remove(dir.at(i));
+                               }
                        }
                }
        }