Browse Source

- remember GUI settings in a cleaner way

adaptive-webui-19844
Christophe Dumez 18 years ago
parent
commit
773c451050
  1. 104
      src/GUI.cpp
  2. 19
      src/torrentAddition.h

104
src/GUI.cpp

@ -795,28 +795,14 @@ bool GUI::hasFilteredFiles(const QString& fileName){
// Save last checked search engines to a file // Save last checked search engines to a file
void GUI::saveCheckedSearchEngines(int) const{ void GUI::saveCheckedSearchEngines(int) const{
qDebug("Saving checked window size"); QSettings settings("qBittorrent", "qBittorrent");
QFile lastSearchEngines(misc::qBittorrentPath()+"lastSearchEngines.txt"); settings.beginGroup("SearchEngines");
// delete old file settings.setValue("mininova", mininova->isChecked());
lastSearchEngines.remove(); settings.setValue("piratebay", piratebay->isChecked());
if(lastSearchEngines.open(QIODevice::WriteOnly | QIODevice::Text)){ settings.setValue("isohunt", isohunt->isChecked());
if(mininova->isChecked()) settings.setValue("meganova", meganova->isChecked());
lastSearchEngines.write(QByteArray("mininova\n")); settings.endGroup();
if(piratebay->isChecked()) qDebug("Saved checked search engines");
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";
}
} }
// Save columns width in a file to remember them // Save columns width in a file to remember them
@ -916,51 +902,14 @@ bool GUI::loadColWidthSearchList(){
// load last checked search engines from a file // load last checked search engines from a file
void GUI::loadCheckedSearchEngines(){ void GUI::loadCheckedSearchEngines(){
qDebug("Loading checked search engines"); qDebug("Loading checked search engines");
QFile lastSearchEngines(misc::qBittorrentPath()+"lastSearchEngines.txt"); QSettings settings("qBittorrent", "qBittorrent");
QStringList searchEnginesList; settings.beginGroup("SearchEngines");
if(lastSearchEngines.exists()){ mininova->setChecked(settings.value("mininova", true).toBool());
if(lastSearchEngines.open(QIODevice::ReadOnly | QIODevice::Text)){ piratebay->setChecked(settings.value("piratebay", false).toBool());
QByteArray searchEngine; isohunt->setChecked(settings.value("isohunt", false).toBool());
while(!lastSearchEngines.atEnd()){ meganova->setChecked(settings.value("meganova", false).toBool());
searchEngine = lastSearchEngines.readLine(); settings.endGroup();
searchEnginesList << QString(searchEngine.data()); qDebug("Loaded checked search engines");
}
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";
}
}
} }
// Display About Dialog // Display About Dialog
@ -1054,19 +1003,11 @@ void GUI::dragEnterEvent(QDragEnterEvent *event){
// torrents to download list // torrents to download list
void GUI::askForTorrents(){ void GUI::askForTorrents(){
QStringList pathsList; QStringList pathsList;
QString lastDir = misc::qBittorrentPath()+"lastDir.txt"; QSettings settings("qBittorrent", "qBittorrent");
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();
}
// Open File Open Dialog // Open File Open Dialog
// Note: it is possible to select more than one file // Note: it is possible to select more than one file
pathsList = QFileDialog::getOpenFileNames(this, pathsList = QFileDialog::getOpenFileNames(this,
tr("Open Torrent Files"), dirPath, tr("Open Torrent Files"), settings.value("MainWindowLastDir", QDir::homePath()).toString(),
tr("Torrent Files")+" (*.torrent)"); tr("Torrent Files")+" (*.torrent)");
if(!pathsList.empty()){ if(!pathsList.empty()){
for(int i=0; i<pathsList.size(); ++i){ for(int i=0; i<pathsList.size(); ++i){
@ -1080,12 +1021,9 @@ void GUI::askForTorrents(){
} }
} }
// Save last dir to remember it // Save last dir to remember it
if(lastDirFile.open(QIODevice::WriteOnly | QIODevice::Text)){ QStringList top_dir = pathsList.at(0).split(QDir::separator());
QStringList top_dir = pathsList.at(0).split(QDir::separator()); top_dir.removeLast();
top_dir.removeLast(); settings.setValue("MainWindowLastDir", top_dir.join(QDir::separator()));
lastDirFile.write(top_dir.join(QDir::separator()).toUtf8());
lastDirFile.close();
}
} }
} }

19
src/torrentAddition.h

@ -28,6 +28,7 @@
#include <fstream> #include <fstream>
#include <QMessageBox> #include <QMessageBox>
#include <QMenu> #include <QMenu>
#include <QSettings>
#include <libtorrent/session.hpp> #include <libtorrent/session.hpp>
#include <libtorrent/bencode.hpp> #include <libtorrent/bencode.hpp>
@ -66,15 +67,8 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
if(home[home.length()-1] != QDir::separator()){ if(home[home.length()-1] != QDir::separator()){
home += QDir::separator(); home += QDir::separator();
} }
QString dirPath = home+"qBT_dir"; QSettings settings("qBittorrent", "qBittorrent");
QFile lastDirFile(misc::qBittorrentPath()+"lastDirTorrentAdd.txt"); savePathTxt->setText(settings.value("LastDirTorrentAdd", home+"qBT_dir").toString());
// Load remembered last dir
if(lastDirFile.exists()){
lastDirFile.open(QIODevice::ReadOnly | QIODevice::Text);
dirPath=lastDirFile.readLine();
lastDirFile.close();
}
savePathTxt->setText(dirPath);
} }
void showLoad(QString filePath, bool fromScanDir=false, QString from_url=QString::null){ 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.write(savePath.path().toUtf8());
savepath_file.close(); savepath_file.close();
// Save last dir to remember it // Save last dir to remember it
QFile lastDirFile(misc::qBittorrentPath()+"lastDirTorrentAdd.txt"); QSettings settings("qBittorrent", "qBittorrent");
if(lastDirFile.open(QIODevice::WriteOnly | QIODevice::Text)){ settings.setValue("LastDirTorrentAdd", savePathTxt->text());
lastDirFile.write(savePathTxt->text().toUtf8());
lastDirFile.close();
}
// Create .incremental file if necessary // Create .incremental file if necessary
if(checkIncrementalDL->isChecked()){ if(checkIncrementalDL->isChecked()){
QFile incremental_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileName+".incremental"); QFile incremental_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileName+".incremental");

Loading…
Cancel
Save