OSDN Git Service

Add Linked notebooks to the ignore sync process.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / NeverNote.java
index 3ab1cfb..b9f098d 100644 (file)
@@ -699,76 +699,7 @@ public class NeverNote extends QMainWindow{
                if (Global.checkVersionUpgrade())
                        checkForUpdates();
        }
-       
-       public void checkForUpdates() {
-               // Send off thread to check for a new version
-               versionChecker = new QNetworkAccessManager(this);
-               versionChecker.finished.connect(this, "upgradeFileRead(QNetworkReply)");
-               QNetworkRequest request = new QNetworkRequest();
-               request.setUrl(new QUrl(Global.getUpdatesAvailableUrl()));
-               versionChecker.get(request);
-       }
-       private void upgradeFileRead(QNetworkReply reply) {
-               if (!reply.isReadable())
-                       return;
-               
-               String winVersion = Global.version;
-               String osxVersion = Global.version;
-               String linuxVersion = Global.version;
-               String linux64Version = Global.version;
-               String version = Global.version;
-               
-               // Determine the versions available
-               QByteArray data = reply.readLine();
-               while (data != null && !reply.atEnd()) {
-                       String line = data.toString();
-                       String lineVersion;
-                       if (line.contains(":")) 
-                               lineVersion = line.substring(line.indexOf(":")+1).replace(" ", "").replace("\n", "");
-                       else
-                               lineVersion = "";
-                       if (line.toLowerCase().contains("windows")) 
-                               winVersion = lineVersion;
-                       else if (line.toLowerCase().contains("os-x")) 
-                               osxVersion = lineVersion;
-                       else if (line.toLowerCase().contains("linux amd64")) 
-                               linux64Version = lineVersion;
-                       else if (line.toLowerCase().contains("linux i386")) 
-                               linuxVersion = lineVersion;
-                       else if (line.toLowerCase().contains("default")) 
-                               version = lineVersion;
-                       
-                       // Read the next line
-                       data = reply.readLine();
-               }
-               
-               // Now we need to determine what system we are on.
-               if (System.getProperty("os.name").toLowerCase().contains("windows"))
-                       version = winVersion;
-               if (System.getProperty("os.name").toLowerCase().contains("mac os"))
-                       version = osxVersion;
-               if (System.getProperty("os.name").toLowerCase().contains("Linux")) {
-                       if (System.getProperty("os.arch").contains("amd64") ||
-                               System.getProperty("os.arch").contains("x86_64") ||
-                               System.getProperty("os.arch").contains("i686"))
-                                       version = linux64Version;
-                       else
-                               version = linuxVersion;
-               }
-               
                
-               if (Global.version.equals(version))
-                       return;
-               
-               UpgradeAvailableDialog dialog = new UpgradeAvailableDialog();
-               dialog.exec();
-               if (dialog.remindMe())
-                       Global.setCheckVersionUpgrade(true);
-               else
-                       Global.setCheckVersionUpgrade(false);
-       }
-
-       
        // Main entry point
        public static void main(String[] args) {
                log.setLevel(Level.FATAL);
@@ -1197,8 +1128,15 @@ public class NeverNote extends QMainWindow{
        }    
        // Load the style sheet
        private void loadStyleSheet() {
-               String fileName = Global.getFileManager().getQssDirPath("default.qss");
+               String fileName = Global.getFileManager().getQssDirPathUser("default.qss");
+               fileName = Global.getFileManager().getQssDirPath("default.qss");
                QFile file = new QFile(fileName);
+               
+               // If a user default.qss doesn't exist, we use the one shipped with NeverNote
+               if (!file.exists()) {
+                       fileName = Global.getFileManager().getQssDirPath("default.qss");
+                       file = new QFile(fileName);
+               }
                file.open(OpenModeFlag.ReadOnly);
                String styleSheet = file.readAll().toString();
                file.close();
@@ -2564,7 +2502,75 @@ public class NeverNote extends QMainWindow{
                Global.saveWindowVisible("leftPanel", hidden);
                
        }
+       public void checkForUpdates() {
+               // Send off thread to check for a new version
+               versionChecker = new QNetworkAccessManager(this);
+               versionChecker.finished.connect(this, "upgradeFileRead(QNetworkReply)");
+               QNetworkRequest request = new QNetworkRequest();
+               request.setUrl(new QUrl(Global.getUpdatesAvailableUrl()));
+               versionChecker.get(request);
+       }
+       @SuppressWarnings("unused")
+       private void upgradeFileRead(QNetworkReply reply) {
+               if (!reply.isReadable())
+                       return;
+               
+               String winVersion = Global.version;
+               String osxVersion = Global.version;
+               String linuxVersion = Global.version;
+               String linux64Version = Global.version;
+               String version = Global.version;
+               
+               // Determine the versions available
+               QByteArray data = reply.readLine();
+               while (data != null && !reply.atEnd()) {
+                       String line = data.toString();
+                       String lineVersion;
+                       if (line.contains(":")) 
+                               lineVersion = line.substring(line.indexOf(":")+1).replace(" ", "").replace("\n", "");
+                       else
+                               lineVersion = "";
+                       if (line.toLowerCase().contains("windows")) 
+                               winVersion = lineVersion;
+                       else if (line.toLowerCase().contains("os-x")) 
+                               osxVersion = lineVersion;
+                       else if (line.toLowerCase().contains("linux amd64")) 
+                               linux64Version = lineVersion;
+                       else if (line.toLowerCase().contains("linux i386")) 
+                               linuxVersion = lineVersion;
+                       else if (line.toLowerCase().contains("default")) 
+                               version = lineVersion;
                        
+                       // Read the next line
+                       data = reply.readLine();
+               }
+               
+               // Now we need to determine what system we are on.
+               if (System.getProperty("os.name").toLowerCase().contains("windows"))
+                       version = winVersion;
+               if (System.getProperty("os.name").toLowerCase().contains("mac os"))
+                       version = osxVersion;
+               if (System.getProperty("os.name").toLowerCase().contains("Linux")) {
+                       if (System.getProperty("os.arch").contains("amd64") ||
+                               System.getProperty("os.arch").contains("x86_64") ||
+                               System.getProperty("os.arch").contains("i686"))
+                                       version = linux64Version;
+                       else
+                               version = linuxVersion;
+               }
+               
+               
+               if (Global.version.equals(version))
+                       return;
+               
+               UpgradeAvailableDialog dialog = new UpgradeAvailableDialog();
+               dialog.exec();
+               if (dialog.remindMe())
+                       Global.setCheckVersionUpgrade(true);
+               else
+                       Global.setCheckVersionUpgrade(false);
+       }
+               
        
     //***************************************************************
     //***************************************************************
@@ -4874,9 +4880,11 @@ public class NeverNote extends QMainWindow{
        // Get a list of valid notebooks
        List<Notebook> notebooks = null; 
        List<Tag> tags = null;
+       List<LinkedNotebook> linkedNotebooks = null;
        try {
                        notebooks = syncRunner.noteStore.listNotebooks(syncRunner.authToken);
                        tags = syncRunner.noteStore.listTags(syncRunner.authToken);
+                       linkedNotebooks = syncRunner.noteStore.listLinkedNotebooks(syncRunner.authToken);
                } catch (EDAMUserException e) {
                        setMessage("EDAMUserException: " +e.getMessage());
                        return;
@@ -4886,6 +4894,9 @@ public class NeverNote extends QMainWindow{
                } catch (TException e) {
                        setMessage("EDAMTransactionException: " +e.getMessage());
                        return;
+               } catch (EDAMNotFoundException e) {
+                       setMessage("EDAMNotFoundException: " +e.getMessage());
+                       return;
                }
        
                // Split up notebooks into synchronized & non-synchronized
@@ -4914,7 +4925,20 @@ public class NeverNote extends QMainWindow{
                }
        }
        
-               IgnoreSync ignore = new IgnoreSync(notebooks, ignoredBooks, tags, ignoredTags);
+       // split up linked notebooks into synchronized & non-synchronized
+       List<LinkedNotebook> ignoredLinkedNotebooks = new ArrayList<LinkedNotebook>();
+       List<String> dbIgnoredLinkedNotebooks = conn.getSyncTable().getIgnoreRecords("LINKEDNOTEBOOK");
+       for (int i=linkedNotebooks.size()-1; i>=0; i--) {
+               String notebookGuid = linkedNotebooks.get(i).getGuid();
+               for (int j=0; j<dbIgnoredLinkedNotebooks.size(); j++) {
+                       if (notebookGuid.equalsIgnoreCase(dbIgnoredLinkedNotebooks.get(j))) {
+                               ignoredLinkedNotebooks.add(linkedNotebooks.get(i));
+                               j=dbIgnoredLinkedNotebooks.size();
+                       }
+               }
+       }
+       
+               IgnoreSync ignore = new IgnoreSync(notebooks, ignoredBooks, tags, ignoredTags, linkedNotebooks, ignoredLinkedNotebooks);
                ignore.exec();
                if (!ignore.okClicked())
                        return;
@@ -4959,7 +4983,26 @@ public class NeverNote extends QMainWindow{
                        }
                }
                
-               conn.getNoteTable().expungeIgnoreSynchronizedNotes(newNotebooks, newTags);
+               // Clear out old tags & add new ones
+               List<String> oldIgnoreLinkedNotebooks = conn.getSyncTable().getIgnoreRecords("LINKEDNOTEBOOK");
+               for (int i=0; i<oldIgnoreLinkedNotebooks.size(); i++) {
+                       conn.getSyncTable().deleteRecord("IGNORELINKEDNOTEBOOK-"+oldIgnoreLinkedNotebooks.get(i));
+               }
+               
+               List<String> newLinked = new ArrayList<String>();
+               for (int i=ignore.getIgnoredLinkedNotebookList().count()-1; i>=0; i--) {
+                       String text = ignore.getIgnoredLinkedNotebookList().takeItem(i).text();
+                       for (int j=0; j<linkedNotebooks.size(); j++) {
+                               if (linkedNotebooks.get(j).getShareName().equalsIgnoreCase(text)) {
+                                       LinkedNotebook t = linkedNotebooks.get(j);
+                                       conn.getSyncTable().addRecord("IGNORELINKEDNOTEBOOK-"+t.getGuid(), t.getGuid());
+                                       newLinked.add(t.getGuid());
+                                       j=linkedNotebooks.size();
+                               }
+                       }
+               }
+               
+               conn.getNoteTable().expungeIgnoreSynchronizedNotes(newNotebooks, newTags, newLinked);
                waitCursor(false);
                refreshLists();
     }