diff --git a/AccountListItem.cpp b/AccountListItem.cpp index 0e3e99d75f42333f2af487b8276d80ce578559d1..2d20a89548cf1aafd91521282e79e323ebf6b1ae 100644 --- a/AccountListItem.cpp +++ b/AccountListItem.cpp @@ -33,6 +33,7 @@ AccountListItem::AccountListItem(Account^ a) { _account = a; _editionMode = false; + } void diff --git a/AccountListItem.h b/AccountListItem.h index e9c0fa810e193fee6d363eebca99f19ea71a798d..4bbb2c0788826e81c9fe586dfc23bb7007e3e646 100644 --- a/AccountListItem.h +++ b/AccountListItem.h @@ -22,6 +22,8 @@ using namespace Windows::Data::Json; using namespace Windows::UI::Xaml; using namespace Windows::UI::Xaml::Data; +#include <RingDebug.h> + namespace RingClientUWP { namespace Controls { diff --git a/RingD.cpp b/RingD.cpp index 794cc11abc318d8b8adbd2301fb01b3881e0f89e..5fe326e27df72166af7ec31150519479d44e89c9 100644 --- a/RingD.cpp +++ b/RingD.cpp @@ -293,6 +293,19 @@ void RingClientUWP::RingD::updateAccount(String^ accountId) tasksList_.push(task); } +void RingClientUWP::RingD::deleteAccount(String ^ accountId) +{ + editModeOn_ = true; + + auto frame = dynamic_cast<Frame^>(Window::Current->Content); + dynamic_cast<RingClientUWP::MainPage^>(frame->Content)->showLoadingOverlay(true, true); + + auto task = ref new RingD::Task(Request::DeleteAccount); + task->_accountId = accountId; + + tasksList_.push(task); +} + void RingClientUWP::RingD::startDaemon() { @@ -733,6 +746,14 @@ RingD::dequeueTasks() DRing::setAccountDetails(Utils::toString(account->accountID_), accountDetails); break; } + case Request::DeleteAccount: + { + auto accountId = task->_accountId; + auto accountId2 = Utils::toString(accountId); + + DRing::removeAccount(accountId2); + break; + } default: break; } diff --git a/RingD.h b/RingD.h index 6689a27f26c8ab07f4022100cac380e6ccae0f2d..a304139f610ef5f5a00c38345cf6acf3041cd973 100644 --- a/RingD.h +++ b/RingD.h @@ -98,6 +98,7 @@ internal: void askToExportOnRing(String^ accountId, String^ password); void eraseCacheFolder(); void updateAccount(String^ accountId); + void deleteAccount(String^ accountId); /* TODO : move members */ ///bool hasConfig; // replaced by startingStatus @@ -130,7 +131,8 @@ private: RegisterDevice, GetKnownDevices, ExportOnRing, - UpdateAccount + UpdateAccount, + DeleteAccount }; diff --git a/SmartPanel.xaml b/SmartPanel.xaml index bb82ec53a962c5473a49fddf3a50689bf7ec9591..abab1f79f15624a8fbdefd66b466d866f9659f35 100644 --- a/SmartPanel.xaml +++ b/SmartPanel.xaml @@ -541,14 +541,14 @@ <ToggleSwitch x:Name="_upnpState_" Margin="20,10"/> <!-- delete account sub menu. --> - <!--<StackPanel Orientation="Horizontal" Margin="10"> + <StackPanel Orientation="Horizontal" Margin="10"> <TextBlock Style="{StaticResource TextSegoeStyle-20pt-black}" Text=""/> <TextBlock Text="Delete account" Margin="10"/> </StackPanel> <ToggleButton x:Name="_deleteAccountBtnEditionMenu_" Margin="20,10" - Content="Delete"/>--> + Content="Delete"/> </StackPanel> <!-- buttons yes/no to accept the modification. --> <Grid Grid.Row="1"> diff --git a/SmartPanel.xaml.cpp b/SmartPanel.xaml.cpp index 0153000be7daba7b7a511d15c23267c96dfae651..7a9029b6cb96976f3b220df541be5c79c0932780 100644 --- a/SmartPanel.xaml.cpp +++ b/SmartPanel.xaml.cpp @@ -63,7 +63,13 @@ SmartPanel::SmartPanel() /* connect delegates */ Configuration::UserPreferences::instance->selectIndex += ref new SelectIndex([this](int index) { - _accountsList_->SelectedIndex = index; + if (_accountsList_) { + auto accountsListSize = dynamic_cast<Vector<AccountListItem^>^>(_accountsList_->ItemsSource)->Size; + if (accountsListSize > index) + _accountsList_->SelectedIndex = index; + else + _accountsList_->SelectedIndex = 0; + } }); Configuration::UserPreferences::instance->loadProfileImage += ref new LoadProfileImage([this]() { StorageFolder^ localfolder = ApplicationData::Current->LocalFolder; @@ -728,11 +734,30 @@ void RingClientUWP::Views::SmartPanel::_acceptAccountModification__Click(Platfor { auto account = AccountListItemsViewModel::instance->_selectedItem->_account; auto accountId = account->accountID_; - account->name_ = _aliasTextBoxEditionMenu_->Text; - account->_upnpState = _upnpState_->IsOn; - RingD::instance->updateAccount(accountId); + // mettre ca en visibility du bouton delete + auto accountsListSize = dynamic_cast<Vector<AccountListItem^>^>(_accountsList_->ItemsSource)->Size; + + if (_deleteAccountBtnEditionMenu_->IsChecked && accountsListSize > 1) { + RingD::instance->deleteAccount(accountId); + + /* rebuild a new list of accounts without the one to delete */ + auto newAccountList = ref new Vector<AccountListItem^>(); + for each (AccountListItem^ item in AccountListItemsViewModel::instance->itemsList) { + if (item->_account->accountID_ != accountId) + newAccountList->Append(item); + } + + _accountsList_->ItemsSource = newAccountList; + + } else { + + account->name_ = _aliasTextBoxEditionMenu_->Text; + account->_upnpState = _upnpState_->IsOn; + + RingD::instance->updateAccount(accountId); + } _accountEditionMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;