change account deletion process

The account deletion was performed by solely clicking the bin icon
in the configuration account panel of a selected account.
This was done without warning nor confirmation.

This patch moves the dedicated button to the account list bottom
as in the other desktop clients, and adds a confimation popup,
summarising the account identifiers (in order, alias, registered name,
ringID), and displays a warning about losing the account in case
it hasn't been exported or added to another device.

Change-Id: I259388da9e143400ab65e88d1fb7c223dbfbff19
Reviewed-by: Anthony Léonard <anthony.leonard@savoirfairelinux.com>
diff --git a/RingWinClient.pro b/RingWinClient.pro
index 23c6ee1..d7681cd 100644
--- a/RingWinClient.pro
+++ b/RingWinClient.pro
@@ -77,7 +77,8 @@
     contactrequestwidget.cpp \
     contactrequestitemdelegate.cpp \
     quickactcontactrequestwidget.cpp \
-    contactrequestlistwidget.cpp
+    contactrequestlistwidget.cpp \
+    deleteaccountdialog.cpp
 
 HEADERS  += mainwindow.h \
     callwidget.h \
@@ -118,7 +119,8 @@
     contactrequestwidget.h \
     contactrequestitemdelegate.h \
     quickactcontactrequestwidget.h \
-    contactrequestlistwidget.h
+    contactrequestlistwidget.h \
+    deleteaccountdialog.h
 
 contains(DEFINES, URI_PROTOCOL) {
  HEADERS += shmclient.h
@@ -145,7 +147,8 @@
     sendcontactrequestwidget.ui \
     currentaccountwidget.ui \
     contactrequestwidget.ui \
-    quickactcontactrequestwidget.ui
+    quickactcontactrequestwidget.ui \
+    deleteaccountdialog.ui
 
 win32: LIBS += -lole32 -luuid -lshlwapi
 LIBS += -lqrencode
diff --git a/accountdetails.cpp b/accountdetails.cpp
index 6960666..4225064 100644
--- a/accountdetails.cpp
+++ b/accountdetails.cpp
@@ -325,12 +325,6 @@
         RingtoneModel::instance().play(idx);
 }
 
-QPushButton*
-AccountDetails::getDeleteAccountButton()
-{
-    return ui->deleteAccountButton;
-}
-
 void
 AccountDetails::on_addDeviceButton_clicked()
 {
diff --git a/accountdetails.h b/accountdetails.h
index f0262bb..3e28b35 100644
--- a/accountdetails.h
+++ b/accountdetails.h
@@ -41,7 +41,6 @@
     explicit AccountDetails(QWidget* parent = 0);
     ~AccountDetails();
 
-    QPushButton* getDeleteAccountButton();
     void setAccount(Account* currentAccount);
     void save();
 
diff --git a/accountdetails.ui b/accountdetails.ui
index cfd1352..b0fa664 100644
--- a/accountdetails.ui
+++ b/accountdetails.ui
@@ -94,8 +94,8 @@
            <rect>
             <x>0</x>
             <y>0</y>
-            <width>843</width>
-            <height>692</height>
+            <width>829</width>
+            <height>756</height>
            </rect>
           </property>
           <layout class="QVBoxLayout" name="verticalLayout_12">
@@ -104,38 +104,6 @@
              <item>
               <layout class="QHBoxLayout" name="horizontalLayout_3">
                <item>
-                <widget class="QPushButton" name="deleteAccountButton">
-                 <property name="minimumSize">
-                  <size>
-                   <width>30</width>
-                   <height>30</height>
-                  </size>
-                 </property>
-                 <property name="maximumSize">
-                  <size>
-                   <width>30</width>
-                   <height>30</height>
-                  </size>
-                 </property>
-                 <property name="toolTip">
-                  <string>delete account</string>
-                 </property>
-                 <property name="text">
-                  <string/>
-                 </property>
-                 <property name="icon">
-                  <iconset resource="ressources.qrc">
-                   <normaloff>:/images/icons/ic_delete_black_18dp_2x.png</normaloff>:/images/icons/ic_delete_black_18dp_2x.png</iconset>
-                 </property>
-                 <property name="iconSize">
-                  <size>
-                   <width>24</width>
-                   <height>24</height>
-                  </size>
-                 </property>
-                </widget>
-               </item>
-               <item>
                 <widget class="QLabel" name="accountLabel">
                  <property name="sizePolicy">
                   <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
@@ -1170,8 +1138,8 @@
            <rect>
             <x>0</x>
             <y>0</y>
-            <width>809</width>
-            <height>930</height>
+            <width>811</width>
+            <height>956</height>
            </rect>
           </property>
           <layout class="QVBoxLayout" name="verticalLayout_11">
@@ -2027,8 +1995,8 @@
            <rect>
             <x>0</x>
             <y>0</y>
-            <width>827</width>
-            <height>907</height>
+            <width>829</width>
+            <height>923</height>
            </rect>
           </property>
           <layout class="QVBoxLayout" name="verticalLayout_13">
diff --git a/configurationwidget.cpp b/configurationwidget.cpp
index 5137b19..745dab3 100644
--- a/configurationwidget.cpp
+++ b/configurationwidget.cpp
@@ -60,6 +60,8 @@
 
 #include "winsparkle.h"
 
+#include "deleteaccountdialog.h"
+
 ConfigurationWidget::ConfigurationWidget(QWidget *parent) :
     NavWidget(parent),
     ui(new Ui::ConfigurationWidget),
@@ -78,13 +80,6 @@
         accountDetails_->save();
     });
 
-    connect(accountDetails_->getDeleteAccountButton(), &QPushButton::clicked, this, [=]() {
-        auto account = accountModel_->getAccountByModelIndex(
-                    ui->accountView->currentIndex());
-        accountModel_->remove(account);
-        accountModel_->save();
-    });
-
     connect(ui->exitSettingsButton, &QPushButton::clicked, this, [=]() {
         emit NavigationRequested(ScreenEnum::CallScreen);
     });
@@ -93,6 +88,13 @@
     accountStateDelegate_ = new AccountStateDelegate();
     ui->accountView->setItemDelegate(accountStateDelegate_);
 
+    // connect delete button to popup trigger
+    connect(ui->deleteAccountBtn, &QPushButton::clicked, [=](){
+        auto idx = ui->accountView->currentIndex();
+        DeleteAccountDialog dialog(idx);
+        dialog.exec();
+    });
+
     isLoading_ = true;
     ui->deviceBox->setModel(deviceModel_);
     connect(deviceModel_, SIGNAL(currentIndexChanged(int)),
diff --git a/configurationwidget.h b/configurationwidget.h
index 517d2a9..9564535 100644
--- a/configurationwidget.h
+++ b/configurationwidget.h
@@ -87,6 +87,7 @@
     AccountStateDelegate *accountStateDelegate_;
     QSettings settings_;
     QErrorMessage errorDlg_;
+
     void showPreview();
 };
 
diff --git a/configurationwidget.ui b/configurationwidget.ui
index f1dbdc3..286078e 100644
--- a/configurationwidget.ui
+++ b/configurationwidget.ui
@@ -1194,6 +1194,41 @@
               </property>
              </widget>
             </item>
+            <item>
+             <widget class="QPushButton" name="deleteAccountBtn">
+              <property name="sizePolicy">
+               <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+                <horstretch>0</horstretch>
+                <verstretch>0</verstretch>
+               </sizepolicy>
+              </property>
+              <property name="minimumSize">
+               <size>
+                <width>30</width>
+                <height>30</height>
+               </size>
+              </property>
+              <property name="maximumSize">
+               <size>
+                <width>30</width>
+                <height>30</height>
+               </size>
+              </property>
+              <property name="text">
+               <string/>
+              </property>
+              <property name="icon">
+               <iconset resource="ressources.qrc">
+                <normaloff>:/images/icons/ic_delete_black_18dp_2x.png</normaloff>:/images/icons/ic_delete_black_18dp_2x.png</iconset>
+              </property>
+              <property name="iconSize">
+               <size>
+                <width>24</width>
+                <height>24</height>
+               </size>
+              </property>
+             </widget>
+            </item>
            </layout>
           </item>
           <item>
diff --git a/deleteaccountdialog.cpp b/deleteaccountdialog.cpp
new file mode 100644
index 0000000..744d2b5
--- /dev/null
+++ b/deleteaccountdialog.cpp
@@ -0,0 +1,59 @@
+/***************************************************************************
+ * Copyright (C) 2015-2017 by Savoir-faire Linux                           *
+ * Author: Olivier Soldano <olivier.soldano@savoirfairelinux.com>          *
+ *                                                                         *
+ * This program is free software; you can redistribute it and/or modify    *
+ * it under the terms of the GNU General Public License as published by    *
+ * the Free Software Foundation; either version 3 of the License, or       *
+ * (at your option) any later version.                                     *
+ *                                                                         *
+ * This program is distributed in the hope that it will be useful,         *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of          *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
+ * GNU General Public License for more details.                            *
+ *                                                                         *
+ * You should have received a copy of the GNU General Public License       *
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.   *
+ **************************************************************************/
+
+#include "deleteaccountdialog.h"
+#include "ui_deleteaccountdialog.h"
+
+// LRC
+#include "accountmodel.h"
+#include "itemdataroles.h"
+#include "account.h"
+
+DeleteAccountDialog::DeleteAccountDialog(const QModelIndex & idx, QWidget *parent) :
+    QDialog(parent),
+    ui(new Ui::DeleteAccountDialog),
+    index_(idx)
+{
+    ui->setupUi(this);
+    ui->accountAliasLabel->setText(AccountModel::instance().data(index_, Qt::DisplayRole).toString());
+    auto ac = AccountModel::instance().getAccountByModelIndex(index_);
+    if (ac->protocol() == Account::Protocol::RING){
+        ui->accountIdLabel->setAlignment(Qt::AlignCenter);
+        ui->accountIdLabel->setText((ac->registeredName().isEmpty())? ac->username(): ac->registeredName() + "\n" + ac->username());
+    } else {
+        ui->warningLabel->hide();
+    }
+}
+
+DeleteAccountDialog::~DeleteAccountDialog()
+{
+    delete ui;
+}
+
+void DeleteAccountDialog::on_deleteCancelBtn_clicked()
+{
+    close();
+}
+
+void DeleteAccountDialog::on_deleteAcceptBtn_clicked()
+{
+    auto account = AccountModel::instance().getAccountByModelIndex(index_);
+    AccountModel::instance().remove(account);
+    AccountModel::instance().save();
+    close();
+}
diff --git a/deleteaccountdialog.h b/deleteaccountdialog.h
new file mode 100644
index 0000000..c247cc9
--- /dev/null
+++ b/deleteaccountdialog.h
@@ -0,0 +1,50 @@
+/***************************************************************************
+ * Copyright (C) 2015-2017 by Savoir-faire Linux                           *
+ * Author: Olivier Soldano <olivier.soldano@savoirfairelinux.com>          *
+ *                                                                         *
+ * This program is free software; you can redistribute it and/or modify    *
+ * it under the terms of the GNU General Public License as published by    *
+ * the Free Software Foundation; either version 3 of the License, or       *
+ * (at your option) any later version.                                     *
+ *                                                                         *
+ * This program is distributed in the hope that it will be useful,         *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of          *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
+ * GNU General Public License for more details.                            *
+ *                                                                         *
+ * You should have received a copy of the GNU General Public License       *
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.   *
+ **************************************************************************/
+
+#ifndef DELETEACCOUNTDIALOG_H
+#define DELETEACCOUNTDIALOG_H
+
+#include <QDialog>
+#include <QModelIndex>
+
+namespace Ui {
+class DeleteAccountDialog;
+}
+
+class DeleteAccountDialog : public QDialog
+{
+    Q_OBJECT
+
+public:
+    DeleteAccountDialog(const QModelIndex & idx, QWidget *parent = 0);
+    ~DeleteAccountDialog();
+
+signals:
+    deleteAcceptClicked();
+
+private slots:
+    void on_deleteCancelBtn_clicked();
+
+    void on_deleteAcceptBtn_clicked();
+
+private:
+    Ui::DeleteAccountDialog *ui;
+    QModelIndex index_;
+};
+
+#endif // DELETEACCOUNTDIALOG_H
diff --git a/deleteaccountdialog.ui b/deleteaccountdialog.ui
new file mode 100644
index 0000000..c5d9c9f
--- /dev/null
+++ b/deleteaccountdialog.ui
@@ -0,0 +1,187 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>DeleteAccountDialog</class>
+ <widget class="QDialog" name="DeleteAccountDialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>240</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Ring - account deletion</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout" stretch="3,3,1,1,1,0,3,0">
+   <item>
+    <spacer name="verticalSpacer">
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>20</width>
+       <height>40</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+   <item alignment="Qt::AlignHCenter">
+    <widget class="QLabel" name="deletionLabel1">
+     <property name="text">
+      <string>Do you realy want to delete account ?</string>
+     </property>
+    </widget>
+   </item>
+   <item alignment="Qt::AlignHCenter">
+    <widget class="QLabel" name="accountAliasLabel">
+     <property name="minimumSize">
+      <size>
+       <width>30</width>
+       <height>0</height>
+      </size>
+     </property>
+     <property name="text">
+      <string/>
+     </property>
+    </widget>
+   </item>
+   <item alignment="Qt::AlignHCenter">
+    <widget class="QLabel" name="accountIdLabel">
+     <property name="minimumSize">
+      <size>
+       <width>20</width>
+       <height>0</height>
+      </size>
+     </property>
+     <property name="text">
+      <string/>
+     </property>
+    </widget>
+   </item>
+   <item alignment="Qt::AlignHCenter">
+    <widget class="QLabel" name="deletionLabel2">
+     <property name="text">
+      <string>This action is irrevocable</string>
+     </property>
+    </widget>
+   </item>
+   <item alignment="Qt::AlignHCenter">
+    <widget class="QLabel" name="warningLabel">
+     <property name="text">
+      <string>If this account hasn't been exported, or added to another device, it will be lost</string>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignCenter</set>
+     </property>
+     <property name="wordWrap">
+      <bool>true</bool>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <spacer name="verticalSpacer_2">
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>20</width>
+       <height>40</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <property name="leftMargin">
+      <number>0</number>
+     </property>
+     <property name="topMargin">
+      <number>0</number>
+     </property>
+     <property name="rightMargin">
+      <number>0</number>
+     </property>
+     <property name="bottomMargin">
+      <number>0</number>
+     </property>
+     <item>
+      <spacer name="horizontalSpacer">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item>
+      <widget class="QPushButton" name="deleteCancelBtn">
+       <property name="sizePolicy">
+        <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
+         <horstretch>0</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
+       </property>
+       <property name="minimumSize">
+        <size>
+         <width>130</width>
+         <height>30</height>
+        </size>
+       </property>
+       <property name="text">
+        <string>Cancel</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <spacer name="horizontalSpacer_3">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item>
+      <widget class="QPushButton" name="deleteAcceptBtn">
+       <property name="minimumSize">
+        <size>
+         <width>130</width>
+         <height>30</height>
+        </size>
+       </property>
+       <property name="text">
+        <string>Ok</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <spacer name="horizontalSpacer_2">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+    </layout>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/stylesheet.css b/stylesheet.css
index 3496e1b..8838f61 100644
--- a/stylesheet.css
+++ b/stylesheet.css
@@ -223,7 +223,7 @@
     background-color: #34acbd;
 }
 
-QPushButton#deleteAccountButton, QToolButton#addAccountButton{
+QPushButton#deleteAccountBtn, QToolButton#addAccountButton{
     background: transparent;
 }
 
@@ -259,7 +259,8 @@
     background: rgb(77, 77, 77);
 }
 
-QDialog#WizardDialog, QWidget#welcomePage, QWidget#sendContactRequestPage{
+QDialog#WizardDialog, QWidget#welcomePage, QWidget#sendContactRequestPage,
+QDialog#DeleteAccountDialog{
     background: rgb(242, 242, 242);
     background-image : url(:/images/background-light.png);
     background-repeat : repeat-x;
@@ -295,14 +296,14 @@
 QPushButton#existingPushButton, QPushButton#newAccountButton, QPushButton#previousButton, QPushButton#exportButton,
 QPushButton#cancelAddButton, QPushButton#exportOnRingButton, QPushButton#addDeviceButton, QPushButton#exportEndedOkButton,
 QPushButton#errorPushButton, QPushButton#registerButton, QPushButton#sendContactRequestPageButton,
-QPushButton#sendContactRequestButton, QPushButton#acceptCRButton, QPushButton#discardCRButton{
+QPushButton#sendContactRequestButton, QPushButton#acceptCRButton, QPushButton#discardCRButton, QPushButton#deleteCancelBtn{
     background-color: #3AC0D2;
     border: 0px;
     color: white;
     font: 14px;
 }
 
-QPushButton#blockCRButton{
+QPushButton#blockCRButton, QPushButton#deleteAcceptBtn{
     background-color: rgb(251, 72, 71);
     border: 0px;
     color: white;
@@ -316,11 +317,12 @@
 QPushButton#exportButton:hover, QPushButton#cancelAddButton:hover, QPushButton#exportOnRingButton:hover,
 QPushButton#addDeviceButton:hover, QPushButton#exportEndedOkButton:hover, QPushButton#errorPushButton:hover,
 QPushButton#registerButton:hover, QPushButton#sendContactRequestPageButton:hover,
-QPushButton#sendContactRequestButton:hover, QPushButton#acceptCRButton:hover, QPushButton#discardCRButton:hover{
+QPushButton#sendContactRequestButton:hover, QPushButton#acceptCRButton:hover, QPushButton#discardCRButton:hover,
+QPushButton#deleteCancelBtn:hover{
     background-color: #4dc6d6;
 }
 
-QPushButton#blockCRButton:hover{
+QPushButton#blockCRButton:hover, QPushButton#deleteAcceptBtn:hover{
     background-color: rgb(252, 91, 90);
 }
 
@@ -332,10 +334,11 @@
 QPushButton#exportButton:pressed, QPushButton#cancelAddButton:pressed, QPushButton#exportOnRingButton:pressed,
 QPushButton#addDeviceButton:pressed, QPushButton#exportEndedOkButton:pressed, QPushButton#errorPushButton:pressed,
 QPushButton#registerButton:pressed, QPushButton#sendContactRequestPageButton:pressed,
-QPushButton#sendContactRequestButton:pressed, QPushButton#acceptCRButton:pressed, QPushButton#discardCRButton:pressed{
+QPushButton#sendContactRequestButton:pressed, QPushButton#acceptCRButton:pressed, QPushButton#discardCRButton:pressed,
+QPushButton#deleteCancelBtn:pressed{
     background-color: #34acbd;
 }
-QPushButton#blockCRButton:pressed{
+QPushButton#blockCRButton:pressed, QPushButton#deleteAcceptBtn:pressed{
     background-color: rgb(219, 55, 54);
 }
 
@@ -629,3 +632,26 @@
 QToolButton::menu-button {image:none;}
 
 QToolButton::menu-arrow {image:none;}
+
+QLabel#accountIdLabel, QLabel#accountAliasLabel, QLabel#deletionLabel1, QLabel#deletionLabel2,
+QLabel#warningLabel{
+    background: transparent;
+    font: 11pt "Sans Serif";
+}
+
+QLabel#accountAliasLabel, QLabel#deletionLabel1, QLabel#deletionLabel2{
+    color: black;
+}
+
+QLabel#warningLabel{
+    color: red;
+}
+
+QLabel#accountIdLabel{
+    color: LightSlateGrey;
+    font-style: italic;
+}
+
+QLabel#accountAliasLabel{
+    font-weight: bold;
+}