OSDN Git Service

Evernote APIの帯域制限超過時にエラーメッセージを表示するようにした
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / NeverNote.java
index 2c73548..90adc7b 100644 (file)
@@ -49,6 +49,7 @@ import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
 import org.h2.tools.ChangeFileEncryption;
 
+import com.evernote.edam.error.EDAMErrorCode;
 import com.evernote.edam.error.EDAMNotFoundException;
 import com.evernote.edam.error.EDAMSystemException;
 import com.evernote.edam.error.EDAMUserException;
@@ -484,6 +485,7 @@ public class NeverNote extends QMainWindow{
         syncRunner.status.message.connect(this, "setMessage(String)");
         syncRunner.syncSignal.finished.connect(this, "syncThreadComplete(Boolean)");
         syncRunner.syncSignal.errorDisconnect.connect(this, "remoteErrorDisconnect()");
+        syncRunner.limitSignal.rateLimitReached.connect(this, "informRateLimit(Integer)");
         syncRunning = false;   
                if (syncTime > 0) {
                        automaticSync = true;
@@ -3221,6 +3223,7 @@ public class NeverNote extends QMainWindow{
        logger.log(logger.HIGH, "Entering NeverNote.setupToolBar");
        toolBar = addToolBar(tr("Tool Bar"));   
        toolBar.setObjectName("toolBar");
+       toolBar.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon);
        menuBar.setupToolBarVisible();
        if (!Global.isWindowVisible("toolBar"))
                toolBar.setVisible(false);
@@ -3230,18 +3233,22 @@ public class NeverNote extends QMainWindow{
 //     toolBar.addWidget(menuBar);
 //     menuBar.setSizePolicy(Policy.Minimum, Policy.Minimum);
 //     toolBar.addSeparator();
-       prevButton = toolBar.addAction(tr("Previous"));
+       prevButton = toolBar.addAction(tr(""));
+       prevButton.setToolTip(tr("Previous"));
        QIcon prevIcon = new QIcon(iconPath+"back.png");
        prevButton.setIcon(prevIcon);
        prevButton.triggered.connect(this, "previousViewedAction()");   
        togglePrevArrowButton(Global.isToolbarButtonVisible("prevArrow"));
        
-       nextButton = toolBar.addAction(tr("Next"));
+       nextButton = toolBar.addAction(tr(""));
+       nextButton.setToolTip(tr("Next"));
        QIcon nextIcon = new QIcon(iconPath+"forward.png");
        nextButton.setIcon(nextIcon);
        nextButton.triggered.connect(this, "nextViewedAction()");       
        toggleNextArrowButton(Global.isToolbarButtonVisible("nextArrow"));
        
+       toolBar.addSeparator();
+       
        upButton = toolBar.addAction(tr("Up"));
        QIcon upIcon = new QIcon(iconPath+"up.png");
        upButton.setIcon(upIcon);
@@ -6218,6 +6225,9 @@ public class NeverNote extends QMainWindow{
                        setMessage("EDAMUserException: " +e.getMessage());
                        return;
                } catch (EDAMSystemException e) {
+                       if (e.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) {
+                               QMessageBox.warning(this, tr("Rate limit reached"), tr("Rate limit reached.\nRetry your request in " + e.getRateLimitDuration() + " seconds."));
+                       }
                        setMessage("EDAMSystemException: " +e.getMessage());
                        return;
                } catch (EDAMNotFoundException e) {
@@ -6278,6 +6288,9 @@ public class NeverNote extends QMainWindow{
                                waitCursor(false);
                                return null;
                        } catch (EDAMSystemException e) {
+                               if (e.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) {
+                                       QMessageBox.warning(this, tr("Rate limit reached"), tr("Rate limit reached.\nRetry your request in " + e.getRateLimitDuration() + " seconds."));
+                               }
                                setMessage("EDAMSystemException: " +e.getMessage());
                                waitCursor(false);
                                return null;
@@ -6342,6 +6355,9 @@ public class NeverNote extends QMainWindow{
                        setMessage("EDAMUserException: " +e.getMessage());
                        return;
                } catch (EDAMSystemException e) {
+                       if (e.getErrorCode() == EDAMErrorCode.RATE_LIMIT_REACHED) {
+                               QMessageBox.warning(this, tr("Rate limit reached"), tr("Rate limit reached.\nRetry your request in " + e.getRateLimitDuration() + " seconds."));
+                       }
                        setMessage("EDAMSystemException: " +e.getMessage());
                        return;
                } catch (TException e) {
@@ -7785,4 +7801,10 @@ public class NeverNote extends QMainWindow{
        public RensoNoteList getRensoNoteList() {
                return rensoNoteListDock.getRensoNoteList();
        }
+       
+       // 帯域制限の超過をユーザに通知
+       @SuppressWarnings("unused")
+       private void informRateLimit(Integer rateLimitDuration) {
+               QMessageBox.warning(this, tr("Rate limit reached"), tr("Rate limit reached.\nRetry your request in " + rateLimitDuration + " seconds."));
+       }
 }