]> Some of my projects - anidbudpclient.git/commitdiff
Fix File: actually reduce number of commands sent and make updateState work().
authorAPTX <marek321@gmail.com>
Thu, 12 Jan 2012 20:06:51 +0000 (21:06 +0100)
committerAPTX <marek321@gmail.com>
Thu, 12 Jan 2012 20:06:51 +0000 (21:06 +0100)
file.cpp
file.h

index e1f219197ca6c1ed549048c635b46c61193171d6..61f8bd9d2b0be50ace1b6c4cd0d9defddf8c0948 100644 (file)
--- a/file.cpp
+++ b/file.cpp
@@ -181,18 +181,21 @@ void File::updateState()
                actionsQueue.enqueue(Adding);
 
        actionsQueue.enqueue(SettingState);
+       if (notWorking) work();
 }
 
 void File::setState(const MyListState &state)
 {
        m_state = state;
        useDefaultState = false;
+       stateSet = false;
 }
 
 void File::clearState()
 {
        m_state = MyListState();
        useDefaultState = true;
+       stateSet = false;
 }
 
 MyListState File::state() const
@@ -266,17 +269,13 @@ qDebug() << "finishRenaming";
        {
                bool ok;
                m_lid = fileReply->value(FileFlag::Lid).toInt(&ok);
-
+#ifdef ANIDBUDPCLIENT_FILE_DEBUG
+qDebug() << "lid = " << m_lid;
+#endif
                if (!ok)
                        m_lid = 0;
        }
 
-       if (m_lid && actionsQueue.removeAll(Adding))
-       {
-               updateStatus(Adding, Success);
-               AniDBUdpClient::Client::instance()->cancel(addReply);
-       }
-
        QString name = fileReply->value(FileAnimeFlag::RomajiName).toString();
        if (name.isEmpty())
                name = fileReply->value(FileAnimeFlag::EnglishName).toString();
@@ -336,13 +335,9 @@ void File::finishAdding(bool success)
        }
 
        m_lid = addReply->lid();
+       stateSet = addReply->stateSet();
 
        updateStatus(Adding, Success);
-
-       if ((addReply->replyCode() == MYLIST_ENTRY_ADDED
-                       || addReply->replyCode() == MYLIST_ENTRY_EDITED)
-                       && actionsQueue.removeAll(SettingState))
-               updateStatus(SettingState, Success);
 }
 
 void File::finishMarking(bool success)
@@ -362,6 +357,9 @@ void File::finishSetState(bool success)
                updateStatus(SettingState, Failure);
                return;
        }
+
+       stateSet = addReply->stateSet();
+
        updateStatus(SettingState, Finished);
 }
 
@@ -553,6 +551,12 @@ void File::startSetState()
                return;
        }
 
+       if (stateSet)
+       {
+               updateStatus(SettingState, Finished);
+               return;
+       }
+
        MyListAddCommand setStateCommand;
        if (m_lid)
                setStateCommand = MyListAddCommand(m_lid);
@@ -576,6 +580,7 @@ void File::init()
        staticInit();
 
        m_lid = 0;
+       stateSet = false;
 
        m_size = 0;
 
diff --git a/file.h b/file.h
index 77a77ed206f44011ded908c476b59dd6eaa45ac5..fc1235cfd497e9661e385855bd0f8c93161f7c2d 100644 (file)
--- a/file.h
+++ b/file.h
@@ -130,6 +130,7 @@ private:
        void updateStatus(Action action, ActionState actionState);
 
        int m_lid;
+       bool stateSet;
 
        QQueue<Action> actionsQueue;