2929
3030#define DECORATION_SIZE 65
3131#define NUM_ITEMS 3
32+ #define REQUEST_START_ALL 1
3233
3334class MNHolder : public FurListRow <QWidget*>
3435{
@@ -63,7 +64,8 @@ class MNHolder : public FurListRow<QWidget*>
6364
6465MasterNodesWidget::MasterNodesWidget (PIVXGUI *parent) :
6566 PWidget(parent),
66- ui(new Ui::MasterNodesWidget)
67+ ui(new Ui::MasterNodesWidget),
68+ isLoading(false )
6769{
6870 ui->setupUi (this );
6971
@@ -97,6 +99,7 @@ MasterNodesWidget::MasterNodesWidget(PIVXGUI *parent) :
9799 /* Buttons */
98100 ui->pushButtonSave ->setText (tr (" Create Masternode Controller" ));
99101 setCssBtnPrimary (ui->pushButtonSave );
102+ setCssBtnPrimary (ui->pushButtonStartAll );
100103
101104 /* Options */
102105 ui->btnAbout ->setTitleClassAndText (" btn-title-grey" , " What is a Masternode?" );
@@ -117,6 +120,7 @@ MasterNodesWidget::MasterNodesWidget(PIVXGUI *parent) :
117120 setCssProperty (ui->labelEmpty , " text-empty" );
118121
119122 connect (ui->pushButtonSave , SIGNAL (clicked ()), this , SLOT (onCreateMNClicked ()));
123+ connect (ui->pushButtonStartAll , SIGNAL (clicked ()), this , SLOT (onStartAllClicked ()));
120124 connect (ui->listMn , SIGNAL (clicked (QModelIndex)), this , SLOT (onMNClicked (QModelIndex)));
121125 connect (ui->btnAbout , &OptionButton::clicked, [this ](){window->openFAQ (9 );});
122126 connect (ui->btnAboutController , &OptionButton::clicked, [this ](){window->openFAQ (10 );});
@@ -144,13 +148,10 @@ void MasterNodesWidget::loadWalletModel(){
144148}
145149
146150void MasterNodesWidget::updateListState () {
147- if (mnModel->rowCount () > 0 ) {
148- ui->listMn ->setVisible (true );
149- ui->emptyContainer ->setVisible (false );
150- } else {
151- ui->listMn ->setVisible (false );
152- ui->emptyContainer ->setVisible (true );
153- }
151+ bool show = mnModel->rowCount () > 0 ;
152+ ui->listMn ->setVisible (show);
153+ ui->emptyContainer ->setVisible (!show);
154+ ui->pushButtonStartAll ->setVisible (show);
154155}
155156
156157void MasterNodesWidget::onMNClicked (const QModelIndex &index){
@@ -197,29 +198,84 @@ void MasterNodesWidget::onEditMNClicked(){
197198 }
198199}
199200
200- void MasterNodesWidget::startAlias (QString strAlias){
201+ void MasterNodesWidget::startAlias (QString strAlias) {
201202 QString strStatusHtml;
202203 strStatusHtml += " Alias: " + strAlias + " " ;
203204
204205 for (CMasternodeConfig::CMasternodeEntry mne : masternodeConfig.getEntries ()) {
205206 if (mne.getAlias () == strAlias.toStdString ()) {
206207 std::string strError;
207- CMasternodeBroadcast mnb;
208- if (CMasternodeBroadcast::Create (mne.getIp (), mne.getPrivKey (), mne.getTxHash (), mne.getOutputIndex (), strError, mnb)) {
209- strStatusHtml += " successfully started." ;
210- mnodeman.UpdateMasternodeList (mnb);
211- mnb.Relay ();
212- mnModel->updateMNList ();
213- } else {
214- strStatusHtml += " failed to start.\n Error: " + QString::fromStdString (strError);
215- }
208+ strStatusHtml += (!startMN (mne, strError)) ? (" failed to start.\n Error: " + QString::fromStdString (strError)) : " successfully started." ;
216209 break ;
217210 }
218211 }
219- inform (strStatusHtml);
212+ // update UI and notify
213+ updateModelAndInform (strStatusHtml);
214+ }
215+
216+ void MasterNodesWidget::updateModelAndInform (QString informText) {
217+ mnModel->updateMNList ();
218+ inform (informText);
219+ }
220+
221+ bool MasterNodesWidget::startMN (CMasternodeConfig::CMasternodeEntry mne, std::string& strError) {
222+ CMasternodeBroadcast mnb;
223+ if (!CMasternodeBroadcast::Create (mne.getIp (), mne.getPrivKey (), mne.getTxHash (), mne.getOutputIndex (), strError, mnb))
224+ return false ;
225+
226+ mnodeman.UpdateMasternodeList (mnb);
227+ mnb.Relay ();
228+ return true ;
229+ }
230+
231+ void MasterNodesWidget::onStartAllClicked () {
232+ if (!verifyWalletUnlocked ()) return ;
233+ if (isLoading) {
234+ inform (tr (" Start all Masternodes is being executed, please wait" ));
235+ } else {
236+ isLoading = true ;
237+ if (!execute (REQUEST_START_ALL)) {
238+ isLoading = false ;
239+ inform (tr (" Cannot perform start all Mastenodes" ));
240+ }
241+ }
242+ }
243+
244+ bool MasterNodesWidget::startAll (QString& failText) {
245+ int amountOfMnFailed = 0 ;
246+ int amountOfMnStarted = 0 ;
247+ for (CMasternodeConfig::CMasternodeEntry mne : masternodeConfig.getEntries ()) {
248+ std::string strError;
249+ if (!startMN (mne, strError)) {
250+ amountOfMnFailed++;
251+ } else {
252+ amountOfMnStarted++;
253+ }
254+ }
255+ if (amountOfMnFailed > 0 ) {
256+ failText = tr (" %1 Masternodes failed to start, %2 started" ).arg (amountOfMnFailed).arg (amountOfMnStarted);
257+ }
258+ return true ;
259+ }
260+
261+ void MasterNodesWidget::run (int type) {
262+ if (type == REQUEST_START_ALL) {
263+ QString failText;
264+ QString inform = startAll (failText) ? tr (" All Masternodes started!" ) : failText;
265+ QMetaObject::invokeMethod (this , " updateModelAndInform" , Qt::QueuedConnection,
266+ Q_ARG (QString, inform));
267+ }
268+ isLoading = false ;
269+ }
270+
271+ void MasterNodesWidget::onError (QString error, int type) {
272+ if (type == REQUEST_START_ALL) {
273+ QMetaObject::invokeMethod (this , " inform" , Qt::QueuedConnection,
274+ Q_ARG (QString, " Error starting all Masternodes" ));
275+ }
220276}
221277
222- void MasterNodesWidget::onInfoMNClicked (){
278+ void MasterNodesWidget::onInfoMNClicked () {
223279 if (!verifyWalletUnlocked ()) return ;
224280 showHideOp (true );
225281 MnInfoDialog* dialog = new MnInfoDialog (window);
0 commit comments