From 773c451050525f6f6f162136b0a05925545f0711 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Tue, 14 Nov 2006 21:17:51 +0000 Subject: [PATCH] - remember GUI settings in a cleaner way --- src/GUI.cpp | 104 +++++++++--------------------------------- src/torrentAddition.h | 19 ++------ 2 files changed, 26 insertions(+), 97 deletions(-) diff --git a/src/GUI.cpp b/src/GUI.cpp index e7d5d7cbb..4b2b8fda0 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -795,28 +795,14 @@ bool GUI::hasFilteredFiles(const QString& fileName){ // Save last checked search engines to a file void GUI::saveCheckedSearchEngines(int) const{ - qDebug("Saving checked window size"); - QFile lastSearchEngines(misc::qBittorrentPath()+"lastSearchEngines.txt"); - // delete old file - lastSearchEngines.remove(); - if(lastSearchEngines.open(QIODevice::WriteOnly | QIODevice::Text)){ - if(mininova->isChecked()) - lastSearchEngines.write(QByteArray("mininova\n")); - if(piratebay->isChecked()) - lastSearchEngines.write(QByteArray("piratebay\n")); -// if(reactor->isChecked()) -// lastSearchEngines.write(QByteArray("reactor\n")); - if(isohunt->isChecked()) - lastSearchEngines.write(QByteArray("isohunt\n")); -// if(btjunkie->isChecked()) -// lastSearchEngines.write(QByteArray("btjunkie\n")); - if(meganova->isChecked()) - lastSearchEngines.write(QByteArray("meganova\n")); - lastSearchEngines.close(); - qDebug("Saved checked search engines"); - }else{ - std::cerr << "Error: Could not save last checked search engines\n"; - } + QSettings settings("qBittorrent", "qBittorrent"); + settings.beginGroup("SearchEngines"); + settings.setValue("mininova", mininova->isChecked()); + settings.setValue("piratebay", piratebay->isChecked()); + settings.setValue("isohunt", isohunt->isChecked()); + settings.setValue("meganova", meganova->isChecked()); + settings.endGroup(); + qDebug("Saved checked search engines"); } // Save columns width in a file to remember them @@ -916,51 +902,14 @@ bool GUI::loadColWidthSearchList(){ // load last checked search engines from a file void GUI::loadCheckedSearchEngines(){ qDebug("Loading checked search engines"); - QFile lastSearchEngines(misc::qBittorrentPath()+"lastSearchEngines.txt"); - QStringList searchEnginesList; - if(lastSearchEngines.exists()){ - if(lastSearchEngines.open(QIODevice::ReadOnly | QIODevice::Text)){ - QByteArray searchEngine; - while(!lastSearchEngines.atEnd()){ - searchEngine = lastSearchEngines.readLine(); - searchEnginesList << QString(searchEngine.data()); - } - lastSearchEngines.close(); - if(searchEnginesList.indexOf("mininova\n") != -1){ - mininova->setChecked(true); - }else{ - mininova->setChecked(false); - } - if(searchEnginesList.indexOf("piratebay\n") != -1){ - piratebay->setChecked(true); - }else{ - piratebay->setChecked(false); - } -// if(searchEnginesList.indexOf("reactor\n") != -1){ -// reactor->setChecked(true); -// }else{ -// reactor->setChecked(false); -// } - if(searchEnginesList.indexOf("isohunt\n") != -1){ - isohunt->setChecked(true); - }else{ - isohunt->setChecked(false); - } -// if(searchEnginesList.indexOf("btjunkie\n") != -1){ -// btjunkie->setChecked(true); -// }else{ -// btjunkie->setChecked(false); -// } - if(searchEnginesList.indexOf("meganova\n") != -1){ - meganova->setChecked(true); - }else{ - meganova->setChecked(false); - } - qDebug("Checked search engines loaded"); - }else{ - std::cerr << "Error: Could not load last checked search engines\n"; - } - } + QSettings settings("qBittorrent", "qBittorrent"); + settings.beginGroup("SearchEngines"); + mininova->setChecked(settings.value("mininova", true).toBool()); + piratebay->setChecked(settings.value("piratebay", false).toBool()); + isohunt->setChecked(settings.value("isohunt", false).toBool()); + meganova->setChecked(settings.value("meganova", false).toBool()); + settings.endGroup(); + qDebug("Loaded checked search engines"); } // Display About Dialog @@ -1054,19 +1003,11 @@ void GUI::dragEnterEvent(QDragEnterEvent *event){ // torrents to download list void GUI::askForTorrents(){ QStringList pathsList; - QString lastDir = misc::qBittorrentPath()+"lastDir.txt"; - QString dirPath=QDir::homePath(); - QFile lastDirFile(lastDir); - // Load remembered last dir - if(lastDirFile.exists()){ - lastDirFile.open(QIODevice::ReadOnly | QIODevice::Text); - dirPath=lastDirFile.readLine(); - lastDirFile.close(); - } + QSettings settings("qBittorrent", "qBittorrent"); // Open File Open Dialog // Note: it is possible to select more than one file pathsList = QFileDialog::getOpenFileNames(this, - tr("Open Torrent Files"), dirPath, + tr("Open Torrent Files"), settings.value("MainWindowLastDir", QDir::homePath()).toString(), tr("Torrent Files")+" (*.torrent)"); if(!pathsList.empty()){ for(int i=0; i #include #include +#include #include #include @@ -66,15 +67,8 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{ if(home[home.length()-1] != QDir::separator()){ home += QDir::separator(); } - QString dirPath = home+"qBT_dir"; - QFile lastDirFile(misc::qBittorrentPath()+"lastDirTorrentAdd.txt"); - // Load remembered last dir - if(lastDirFile.exists()){ - lastDirFile.open(QIODevice::ReadOnly | QIODevice::Text); - dirPath=lastDirFile.readLine(); - lastDirFile.close(); - } - savePathTxt->setText(dirPath); + QSettings settings("qBittorrent", "qBittorrent"); + savePathTxt->setText(settings.value("LastDirTorrentAdd", home+"qBT_dir").toString()); } void showLoad(QString filePath, bool fromScanDir=false, QString from_url=QString::null){ @@ -248,11 +242,8 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{ savepath_file.write(savePath.path().toUtf8()); savepath_file.close(); // Save last dir to remember it - QFile lastDirFile(misc::qBittorrentPath()+"lastDirTorrentAdd.txt"); - if(lastDirFile.open(QIODevice::WriteOnly | QIODevice::Text)){ - lastDirFile.write(savePathTxt->text().toUtf8()); - lastDirFile.close(); - } + QSettings settings("qBittorrent", "qBittorrent"); + settings.setValue("LastDirTorrentAdd", savePathTxt->text()); // Create .incremental file if necessary if(checkIncrementalDL->isChecked()){ QFile incremental_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileName+".incremental");