From: APTX Date: Fri, 11 Feb 2011 00:19:20 +0000 (+0100) Subject: Add ability to set Arbitrary mylist state to File X-Git-Url: https://gitweb.aptx.org/?a=commitdiff_plain;h=f32f4280f142aac10d4c676bca7ca8545c5b4e32;p=anidbudpclient.git Add ability to set Arbitrary mylist state to File --- diff --git a/file.cpp b/file.cpp index 71d8861..624acb9 100644 --- a/file.cpp +++ b/file.cpp @@ -92,6 +92,12 @@ File::ActionState File::markingState() const return m_markingState; } +File::ActionState File::settingStateState() const +{ + return m_settingStateState; +} + + void File::setRenameDelegate(FileRenameDelegate *renameHelper) { m_renameDelegate = renameHelper; @@ -155,9 +161,52 @@ bool File::markWatched() 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() @@ -252,7 +301,12 @@ void File::finishMarking(bool success) void File::finishSetState(bool success) { - + if (!success) + { + updateStatus(SettingState, Failure); + return; + } + updateStatus(SettingState, Finished); } void File::work() @@ -292,6 +346,8 @@ qDebug() << "Next work:" << a; case MarkingWatched: startMarking(); break; + case SettingState: + startSetState(); default: break; } @@ -391,7 +447,10 @@ void File::startAdding() 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); @@ -408,7 +467,8 @@ void File::startMarking() work(); return; } - MyListAddCommand markCommand(0); + + MyListAddCommand markCommand; if (addReply->lid()) markCommand = MyListAddCommand(addReply->lid()); else @@ -423,19 +483,41 @@ void File::startMarking() 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; @@ -443,6 +525,16 @@ void File::init() 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; @@ -464,26 +556,21 @@ void File::updateStatus(Action action, ActionState actionState) 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 diff --git a/file.h b/file.h index 8e04798..f97d7c0 100644 --- a/file.h +++ b/file.h @@ -39,6 +39,7 @@ public: Renaming, Adding, MarkingWatched, + SettingState, All = -1, }; @@ -49,7 +50,7 @@ public: Success = 0x00000004, Failure = 0x00000008, - Finished = 0x00000010, + Finished = 0x00000010 | Success, OkToContinue = NotStarted | Failure, }; @@ -71,6 +72,7 @@ public: ActionState renamingState() const; ActionState addingState() const; ActionState markingState() const; + ActionState settingStateState() const; void setRenameDelegate(FileRenameDelegate *renameDelegate); FileRenameDelegate *renameDelegate() const; @@ -81,7 +83,18 @@ public slots: 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); @@ -108,6 +121,7 @@ private: void startSetState(); void init(); + static void staticInit(); bool canContinue(ActionState state); void updateStatus(Action action, ActionState actionState); @@ -124,23 +138,23 @@ private: 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