return m_markingState;
}
+File::ActionState File::settingStateState() const
+{
+ return m_settingStateState;
+}
+
+
void File::setRenameDelegate(FileRenameDelegate *renameHelper)
{
m_renameDelegate = renameHelper;
return true;
}
-void File::setState(const MyListAddCommand &state)
+void File::updateState()
+{
+ if (m_hashingState != Success)
+ actionsQueue.enqueue(Hashing);
+
+ if (m_addingState != Success)
+ actionsQueue.enqueue(Adding);
+
+ actionsQueue.enqueue(SettingState);
+}
+
+void File::setState(const MyListState &state)
{
m_state = state;
+ useDefaultState = false;
+}
+
+void File::clearState()
+{
+ m_state = MyListState();
+ useDefaultState = true;
+}
+
+MyListState File::state() const
+{
+ return m_state;
+}
+
+MyListState File::defaultState()
+{
+ return m_defaultState;
+}
+
+void File::setDefaultState(const MyListState &defaultState)
+{
+ m_defaultState = defaultState;
+}
+
+ClientInterface *File::clientInterface()
+{
+ return m_clientInterface;
+}
+
+void File::setClientInterface(ClientInterface *clientInterface)
+{
+ m_clientInterface = clientInterface;
}
void File::finishHashing()
void File::finishSetState(bool success)
{
-
+ if (!success)
+ {
+ updateStatus(SettingState, Failure);
+ return;
+ }
+ updateStatus(SettingState, Finished);
}
void File::work()
case MarkingWatched:
startMarking();
break;
+ case SettingState:
+ startSetState();
default:
break;
}
delete addReply;
MyListAddCommand addCommand(m_ed2k, size(), false);
- addCommand.setState(StateOnHdd);
+ if (useDefaultState)
+ addCommand.setMyListState(m_defaultState);
+ else
+ addCommand.setMyListState(m_state);
addReply = clientInstance()->send(addCommand);
work();
return;
}
- MyListAddCommand markCommand(0);
+
+ MyListAddCommand markCommand;
if (addReply->lid())
markCommand = MyListAddCommand(addReply->lid());
else
void File::startSetState()
{
- m_state.setEd2k(m_ed2k);
- m_state.setSize(m_file.size());
- m_state.setEdit(true);
+ if (!canContinue(m_markingState))
+ {
+ work();
+ return;
+ }
+
+ MyListAddCommand setStateCommand;
+ if (addReply && addReply->lid())
+ setStateCommand = MyListAddCommand(addReply->lid());
+ else
+ setStateCommand = MyListAddCommand(m_ed2k, size(), true);
+
+ if (useDefaultState)
+ setStateCommand.setMyListState(m_defaultState);
+ else
+ setStateCommand.setMyListState(m_state);
+
+ if (setStateReply)
+ delete setStateReply;
+ setStateReply = clientInstance()->send(setStateCommand);
+ connect(setStateReply, SIGNAL(replyReady(bool)), this, SLOT(finishSetState(bool)));
+ updateStatus(SettingState, InProgress);
}
void File::init()
{
+ staticInit();
+
hashResult = 0;
fileReply = 0;
addReply = 0;
markReply = 0;
+ setStateReply = 0;
m_hashingProgress = 0;
- m_hashingState = m_renamingState = m_addingState = m_markingState = NotStarted;
+ m_hashingState = m_renamingState = m_addingState = m_markingState = m_settingStateState = NotStarted;
notWorking = true;
m_renameDelegate = 0;
connect(this, SIGNAL(statusUpdate(AniDBUdpClient::File::Action,AniDBUdpClient::File::ActionState)), this, SLOT(workOnFinished(AniDBUdpClient::File::Action,AniDBUdpClient::File::ActionState)));
}
+void File::staticInit()
+{
+ static bool initialized = false;
+ if (initialized)
+ return;
+ initialized = true;
+
+ m_defaultState.setState(StateOnHdd);
+}
+
bool File::canContinue(ActionState state)
{
return state & OkToContinue;
case MarkingWatched:
m_markingState = actionState;
break;
+ case SettingState:
+ m_settingStateState = actionState;
+ break;
+ default:
+ break;
}
emit statusUpdate(action, actionState);
}
-
ClientInterface *File::clientInstance() const
{
return m_clientInterface ? m_clientInterface : Client::instance();
}
+MyListState File::m_defaultState;
ClientInterface *File::m_clientInterface = 0;
-ClientInterface *File::clientInterface()
-{
- return m_clientInterface;
-}
-
-void File::setClientInterface(ClientInterface *clientInterface)
-{
- m_clientInterface = clientInterface;
-}
-
} // namespace AniDBUdpClient
Renaming,
Adding,
MarkingWatched,
+ SettingState,
All = -1,
};
Success = 0x00000004,
Failure = 0x00000008,
- Finished = 0x00000010,
+ Finished = 0x00000010 | Success,
OkToContinue = NotStarted | Failure,
};
ActionState renamingState() const;
ActionState addingState() const;
ActionState markingState() const;
+ ActionState settingStateState() const;
void setRenameDelegate(FileRenameDelegate *renameDelegate);
FileRenameDelegate *renameDelegate() const;
bool addToMyList();
bool markWatched();
- void setState(const MyListAddCommand &state);
+ void updateState();
+
+public:
+ void setState(const MyListState &state);
+ void clearState();
+ MyListState state() const;
+
+ static MyListState defaultState();
+ static void setDefaultState(const MyListState &defaultState);
+
+ static ClientInterface *clientInterface();
+ static void setClientInterface(ClientInterface *clientInterface);
signals:
void statusUpdate(AniDBUdpClient::File::Action action, AniDBUdpClient::File::ActionState state, int percent = 0);
void startSetState();
void init();
+ static void staticInit();
bool canContinue(ActionState state);
void updateStatus(Action action, ActionState actionState);
ActionState m_renamingState;
ActionState m_addingState;
ActionState m_markingState;
+ ActionState m_settingStateState;
HashResult *hashResult;
FileReply *fileReply;
MyListAddReply *addReply;
MyListAddReply *markReply;
+ MyListAddReply *setStateReply;
FileRenameDelegate *m_renameDelegate;
- MyListAddCommand m_state;
+ bool useDefaultState;
+ MyListState m_state;
+ static MyListState m_defaultState;
ClientInterface *clientInstance() const;
static ClientInterface *m_clientInterface;
-
-public:
- static ClientInterface *clientInterface();
- static void setClientInterface(ClientInterface *clientInterface);
};
} // namespace AniDBUdpClient