11#include " MainWindow.h"
22#include " ui_MainWindow.h"
3- #include < QtGui/QFileDialog>
4- #include < QSettings>
3+ #include < QFileDialog>
54#include < QFile>
65#include < QApplication>
76#include < QTextStream>
@@ -35,7 +34,6 @@ MainWindow::MainWindow(QWidget* parent)
3534 init ();
3635
3736 activateFields (false );
38- updatePreferences ();
3937 resetBrowser ();
4038 updateRecentFileActions ();
4139}
@@ -108,10 +106,9 @@ void MainWindow::init()
108106 connect (editWin, SIGNAL (updateRecordText (int , int , QByteArray)), this , SLOT (updateRecordText (int , int , QByteArray)));
109107
110108 // Load window settings
111- QSettings settings (QApplication::organizationName (), QApplication::organizationName ());
112- restoreGeometry (settings.value (" MainWindow/geometry" ).toByteArray ());
113- restoreState (settings.value (" MainWindow/windowState" ).toByteArray ());
114- ui->comboLogSubmittedBy ->setCurrentIndex (ui->comboLogSubmittedBy ->findText (settings.value (" SQLLogDock/Log" , " Application" ).toString ()));
109+ restoreGeometry (PreferencesDialog::getSettingsValue (" MainWindow" , " geometry" ).toByteArray ());
110+ restoreState (PreferencesDialog::getSettingsValue (" MainWindow" , " windowState" ).toByteArray ());
111+ ui->comboLogSubmittedBy ->setCurrentIndex (ui->comboLogSubmittedBy ->findText (PreferencesDialog::getSettingsValue (" SQLLogDock" , " Log" ).toString ()));
115112
116113 // Set other window settings
117114 setAcceptDrops (true );
@@ -136,7 +133,7 @@ void MainWindow::fileOpen(const QString & fileName)
136133 wFile = QFileDialog::getOpenFileName (
137134 this ,
138135 tr (" Choose a database file" ),
139- defaultlocation);
136+ PreferencesDialog::getSettingsValue ( " db " , " defaultlocation" ). toString () );
140137 }
141138 if (QFile::exists (wFile) )
142139 {
@@ -163,7 +160,7 @@ void MainWindow::fileOpen()
163160
164161void MainWindow::fileNew ()
165162{
166- QString fileName = QFileDialog::getSaveFileName (this , tr (" Choose a filename to save under" ), defaultlocation);
163+ QString fileName = QFileDialog::getSaveFileName (this , tr (" Choose a filename to save under" ), PreferencesDialog::getSettingsValue ( " db " , " defaultlocation" ). toString () );
167164 if (!fileName.isEmpty ())
168165 {
169166 if (QFile::exists (fileName))
@@ -366,10 +363,9 @@ void MainWindow::fileExit()
366363
367364void MainWindow::closeEvent ( QCloseEvent* event )
368365{
369- QSettings settings (QApplication::organizationName (), QApplication::organizationName ());
370- settings.setValue (" MainWindow/geometry" , saveGeometry ());
371- settings.setValue (" MainWindow/windowState" , saveState ());
372- settings.setValue (" SQLLogDock/Log" , ui->comboLogSubmittedBy ->currentText ());
366+ PreferencesDialog::setSettingsValue (" MainWindow" , " geometry" , saveGeometry ());
367+ PreferencesDialog::setSettingsValue (" MainWindow" , " windowState" , saveState ());
368+ PreferencesDialog::setSettingsValue (" SQLLogDock" , " Log" , ui->comboLogSubmittedBy ->currentText ());
373369 fileExit ();
374370 QMainWindow::closeEvent (event);
375371}
@@ -832,7 +828,7 @@ void MainWindow::importTableFromCSV()
832828 QString wFile = QFileDialog::getOpenFileName (
833829 this ,
834830 tr (" Choose a text file" ),
835- defaultlocation,
831+ PreferencesDialog::getSettingsValue ( " db " , " defaultlocation" ). toString () ,
836832 tr (" Text files(*.csv *.txt);;All files(*)" ));
837833
838834 if (QFile::exists (wFile) )
@@ -849,7 +845,7 @@ void MainWindow::importTableFromCSV()
849845
850846void MainWindow::exportTableToCSV ()
851847{
852- ExportCsvDialog dialog (&db, defaultlocation, this );
848+ ExportCsvDialog dialog (&db, this );
853849 dialog.exec ();
854850}
855851
@@ -883,7 +879,7 @@ void MainWindow::exportDatabaseToSQL()
883879 QString fileName = QFileDialog::getSaveFileName (
884880 this ,
885881 tr (" Choose a filename to export" ),
886- defaultlocation,
882+ PreferencesDialog::getSettingsValue ( " db " , " defaultlocation" ). toString () ,
887883 tr (" Text files(*.sql *.txt)" ));
888884
889885 if (fileName.size ())
@@ -900,7 +896,7 @@ void MainWindow::importDatabaseFromSQL()
900896 QString fileName = QFileDialog::getOpenFileName (
901897 this ,
902898 tr (" Choose a file to import" ),
903- defaultlocation,
899+ PreferencesDialog::getSettingsValue ( " db " , " defaultlocation" ). toString () ,
904900 tr (" Text files(*.sql *.txt);;All files(*)" ));
905901
906902 if (fileName.size () > 0 )
@@ -911,7 +907,7 @@ void MainWindow::importDatabaseFromSQL()
911907 QString newDBfile = QFileDialog::getSaveFileName (
912908 this ,
913909 tr (" Choose a filename to save under" ),
914- defaultlocation);
910+ PreferencesDialog::getSettingsValue ( " db " , " defaultlocation" ). toString () );
915911 if (QFile::exists (newDBfile) )
916912 {
917913 QString err = tr (" File %1 already exists. Please choose a different name." ).arg (newDBfile);
@@ -936,20 +932,11 @@ void MainWindow::openPreferences()
936932 PreferencesDialog dialog (this );
937933 if (dialog.exec ())
938934 {
939- updatePreferences ( );
935+ db. setDefaultNewData ( PreferencesDialog::getSettingsValue ( " db " , " defaultnewdata " ). toString () );
940936 resetBrowser ();
941937 }
942938}
943939
944- void MainWindow::updatePreferences ()
945- {
946- PreferencesDialog prefs (this );
947-
948- db.setDefaultNewData (prefs.defaultnewdata );
949- defaultlocation= prefs.defaultlocation ;
950- editWin->defaultlocation = defaultlocation;
951- }
952-
953940// ******************************************************************
954941// ** Tree Events
955942// ******************************************************************
@@ -1046,10 +1033,7 @@ void MainWindow::openRecentFile()
10461033
10471034void MainWindow::updateRecentFileActions ()
10481035{
1049- QSettings settings (QApplication::organizationName (), QApplication::organizationName ());
1050- QStringList files = settings.value (" recentFileList" ).toStringList ();
1051-
1052-
1036+ QStringList files = PreferencesDialog::getSettingsValue (" General" , " recentFileList" ).toStringList ();
10531037 int numRecentFiles = qMin (files.size (), (int )MaxRecentFiles);
10541038
10551039 for (int i = 0 ; i < numRecentFiles; ++i) {
@@ -1070,14 +1054,13 @@ void MainWindow::setCurrentFile(const QString &fileName)
10701054 setWindowTitle ( QApplication::applicationName () +" - " +fileName);
10711055 activateFields (true );
10721056
1073- QSettings settings (QApplication::organizationName (), QApplication::organizationName ());
1074- QStringList files = settings.value (" recentFileList" ).toStringList ();
1057+ QStringList files = PreferencesDialog::getSettingsValue (" General" , " recentFileList" ).toStringList ();
10751058 files.removeAll (fileName);
10761059 files.prepend (fileName);
10771060 while (files.size () > MaxRecentFiles)
10781061 files.removeLast ();
10791062
1080- settings. setValue ( " recentFileList" , files);
1063+ PreferencesDialog::setSettingsValue ( " General " , " recentFileList" , files);
10811064
10821065 foreach (QWidget *widget, QApplication::topLevelWidgets ()) {
10831066 MainWindow *mainWin = qobject_cast<MainWindow *>(widget);
0 commit comments