2020#include < QFile>
2121#include < QDir>
2222#include < QMenu>
23+ #include < QCloseEvent>
2324#include < huggle_core/core.hpp>
2425#include < huggle_core/configuration.hpp>
2526#include < huggle_core/exception.hpp>
@@ -215,6 +216,25 @@ Preferences::~Preferences()
215216 delete this ->ui ;
216217}
217218
219+ void Preferences::closeEvent (QCloseEvent *event)
220+ {
221+ if (this ->forceClose )
222+ {
223+ event->accept ();
224+ return ;
225+ }
226+
227+ int result = UiGeneric::pMessageBox (this , _l (" preferences-unsaved-title" ),
228+ _l (" preferences-unsaved-text" ),
229+ MessageBoxStyleQuestion);
230+ if (result == QMessageBox::No)
231+ {
232+ event->ignore ();
233+ return ;
234+ }
235+ event->accept ();
236+ }
237+
218238static void SetValue (HuggleQueueFilterMatch matching, QComboBox *item)
219239{
220240 switch (matching)
@@ -404,7 +424,7 @@ void Huggle::Preferences::on_checkBox_InstantReverts_clicked()
404424
405425void Preferences::RecordKeys (int row, int column)
406426{
407- if (this ->RewritingForm )
427+ if (this ->shortcutsRewriting )
408428 return ;
409429 if (column != 2 )
410430 {
@@ -443,13 +463,13 @@ void Preferences::RecordKeys(int row, int column)
443463 }
444464 }
445465
446- this ->ModifiedForm = true ;
447- this ->RewritingForm = true ;
466+ this ->shortcutsModified = true ;
467+ this ->shortcutsRewriting = true ;
448468 this ->IgnoreConflicts = false ;
449469 hcfg->Shortcuts [id].Modified = true ;
450470 hcfg->Shortcuts [id].QAccel = key;
451471 this ->ui ->tableWidget_2 ->setItem (row, column, new QTableWidgetItem (key));
452- this ->RewritingForm = false ;
472+ this ->shortcutsRewriting = false ;
453473 return ;
454474
455475 revert:
@@ -848,19 +868,22 @@ void Huggle::Preferences::on_pushButton_OK_clicked()
848868 {
849869 hcfg->UserConfig ->GoNext = Configuration_OnNext_Next;
850870 }
851- if (this ->ModifiedForm )
871+ if (this ->shortcutsModified )
852872 {
853873 // we need to reload the shortcuts in main form
854874 hcfg->ReloadOfMainformNeeded = true ;
855875 }
856876 Configuration::SaveSystemConfig ();
857877 MainWindow::HuggleMain->ReloadInterface ();
878+
858879 this ->hide ();
859880}
860881
861882void Huggle::Preferences::on_pushButton_CloseWin_clicked ()
862883{
884+ this ->forceClose = true ;
863885 this ->close ();
886+ this ->forceClose = false ;
864887}
865888
866889void Huggle::Preferences::on_pushButton_QueueSave_clicked ()
@@ -1047,4 +1070,4 @@ void Huggle::Preferences::on_pushButton_ResetConfig_clicked()
10471070 }
10481071 UiGeneric::MessageBox (_l (" preferences-reset-config-done" ), _l (" preferences-reset-config-restart" ));
10491072 MainWindow::HuggleMain->Exit ();
1050- }
1073+ }
0 commit comments