Browse Source

Create Options object only when necessary (to save memory)

adaptive-webui-19844
Christophe Dumez 18 years ago
parent
commit
6d65ef067d
  1. 1
      Changelog
  2. 5
      TODO
  3. 81
      src/GUI.cpp
  4. 7
      src/GUI.h
  5. 6
      src/main.cpp
  6. 19
      src/options_imp.cpp
  7. 7
      src/options_imp.h

1
Changelog

@ -21,6 +21,7 @@
- BUGFIX: Fixed directory scanning (stop trying to download the same files several times) - BUGFIX: Fixed directory scanning (stop trying to download the same files several times)
- BUGFIX: Fixed bad loading of scan dir in option (widgets still disabled) - BUGFIX: Fixed bad loading of scan dir in option (widgets still disabled)
- BUGFIX: Threads are now stopped cleanly before their destruction - BUGFIX: Threads are now stopped cleanly before their destruction
- BUGFIX: Create Options object only when necessary (to save memory)
- I18N: Better internationalization thanks to dynamic text support - I18N: Better internationalization thanks to dynamic text support
- COSMETIC: Replaced OSD messages by Qt4.2 systray messages - COSMETIC: Replaced OSD messages by Qt4.2 systray messages

5
TODO

@ -42,7 +42,4 @@
// In v0.9.0 // In v0.9.0
- Update translations (FR, SV, NB, PL done) - Update translations (FR, SV, NB, PL done)
- Splitting torrent part from GUI (bug squashing + cleanup) - Splitting torrent part from GUI (bug squashing + cleanup)
- Create options object only when necessary to save up some memory - Wait for libtorrent v0.12 official release
- Wait for libtorrent v0.12 official release
Info: current TOP output:
25461 chris 15 0 106m 23m 14m S 0.7 2.4 0:01.60 qbittorrent

81
src/GUI.cpp

@ -133,9 +133,9 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent){
connect(&BTSession, SIGNAL(aboutToDownloadFromUrl(const QString&)), this, SLOT(displayDownloadingUrlInfos(const QString&))); connect(&BTSession, SIGNAL(aboutToDownloadFromUrl(const QString&)), this, SLOT(displayDownloadingUrlInfos(const QString&)));
// creating options // creating options
options = new options_imp(this); options = new options_imp(this);
connect(options, SIGNAL(status_changed(const QString&)), this, SLOT(OptionsSaved(const QString&))); connect(options, SIGNAL(status_changed(const QString&, bool)), this, SLOT(OptionsSaved(const QString&, bool)));
// Configure BT session according to options // Configure BT session according to options
configureSession(); configureSession(true);
// Resume unfinished torrents // Resume unfinished torrents
BTSession.resumeUnfinishedTorrents(); BTSession.resumeUnfinishedTorrents();
// Add torrent given on command line // Add torrent given on command line
@ -255,6 +255,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent){
setAcceptDrops(true); setAcceptDrops(true);
// Set info Bar infos // Set info Bar infos
setInfoBar(tr("qBittorrent %1 started.", "e.g: qBittorrent v0.x started.").arg(QString(VERSION))); setInfoBar(tr("qBittorrent %1 started.", "e.g: qBittorrent v0.x started.").arg(QString(VERSION)));
show();
qDebug("GUI Built"); qDebug("GUI Built");
} }
@ -264,7 +265,6 @@ GUI::~GUI(){
searchProcess->kill(); searchProcess->kill();
searchProcess->waitForFinished(); searchProcess->waitForFinished();
delete searchProcess; delete searchProcess;
delete options;
delete checkConnect; delete checkConnect;
delete refresher; delete refresher;
delete myTrayIcon; delete myTrayIcon;
@ -375,6 +375,8 @@ void GUI::displayDLListMenu(const QPoint& pos){
QModelIndex index; QModelIndex index;
// Enable/disable pause/start action given the DL state // Enable/disable pause/start action given the DL state
QModelIndexList selectedIndexes = downloadList->selectionModel()->selectedIndexes(); QModelIndexList selectedIndexes = downloadList->selectionModel()->selectedIndexes();
QSettings settings("qBittorrent", "qBittorrent");
QString previewProgram = settings.value("Options/Misc/PreviewProgram", QString()).toString();
foreach(index, selectedIndexes){ foreach(index, selectedIndexes){
if(index.column() == NAME){ if(index.column() == NAME){
// Get the file name // Get the file name
@ -389,7 +391,7 @@ void GUI::displayDLListMenu(const QPoint& pos){
myDLLlistMenu.addAction(actionDelete); myDLLlistMenu.addAction(actionDelete);
myDLLlistMenu.addAction(actionDelete_Permanently); myDLLlistMenu.addAction(actionDelete_Permanently);
myDLLlistMenu.addAction(actionTorrent_Properties); myDLLlistMenu.addAction(actionTorrent_Properties);
if(!options->getPreviewProgram().isEmpty() && BTSession.isFilePreviewPossible(fileHash) && selectedIndexes.size()<=DLListModel->columnCount()){ if(!previewProgram.isEmpty() && BTSession.isFilePreviewPossible(fileHash) && selectedIndexes.size()<=DLListModel->columnCount()){
myDLLlistMenu.addAction(actionPreview_file); myDLLlistMenu.addAction(actionPreview_file);
} }
break; break;
@ -427,7 +429,9 @@ void GUI::previewFile(const QString& filePath){
// Launch program preview // Launch program preview
QStringList params; QStringList params;
params << tmpPath; params << tmpPath;
previewProcess->start(options->getPreviewProgram(), params, QIODevice::ReadOnly); QSettings settings("qBittorrent", "qBittorrent");
QString previewProgram = settings.value("Options/Misc/PreviewProgram", QString()).toString();
previewProcess->start(previewProgram, params, QIODevice::ReadOnly);
}else{ }else{
QMessageBox::critical(0, tr("Preview process already running"), tr("There is already another preview process running.\nPlease close the other one first.")); QMessageBox::critical(0, tr("Preview process already running"), tr("There is already another preview process running.\nPlease close the other one first."));
} }
@ -806,12 +810,14 @@ void GUI::showAbout(){
// Called when we close the program // Called when we close the program
void GUI::closeEvent(QCloseEvent *e){ void GUI::closeEvent(QCloseEvent *e){
if(options->getGoToSysTrayOnExitingWindow() && !this->isHidden()){ QSettings settings("qBittorrent", "qBittorrent");
bool goToSystrayOnExit = settings.value("Options/Misc/GoToSystrayOnExit", false).toBool();
if(goToSystrayOnExit && !this->isHidden()){
hide(); hide();
e->ignore(); e->ignore();
return; return;
} }
if(options->getConfirmOnExit()){ if(settings.value("Options/Misc/ConfirmOnExit", true).toBool()){
if(QMessageBox::question(this, if(QMessageBox::question(this,
tr("Are you sure you want to quit?")+" -- "+tr("qBittorrent"), tr("Are you sure you want to quit?")+" -- "+tr("qBittorrent"),
tr("Are you sure you want to quit qBittorrent?"), tr("Are you sure you want to quit qBittorrent?"),
@ -822,7 +828,7 @@ void GUI::closeEvent(QCloseEvent *e){
} }
} }
// Clean finished torrents on exit if asked for // Clean finished torrents on exit if asked for
if(options->getClearFinishedOnExit()){ if(settings.value("Options/Misc/ClearFinishedDownloads", true).toBool()){
torrent_handle h; torrent_handle h;
// XXX: Probably move this to the bittorrent part // XXX: Probably move this to the bittorrent part
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup"); QDir torrentBackup(misc::qBittorrentPath() + "BT_backup");
@ -859,7 +865,9 @@ void GUI::showCreateWindow(){
// Called when we minimize the program // Called when we minimize the program
void GUI::hideEvent(QHideEvent *e){ void GUI::hideEvent(QHideEvent *e){
if(options->getGoToSysTrayOnMinimizingWindow()){ qDebug("* Receiced hideEvent()");
QSettings settings("qBittorrent", "qBittorrent");
if(settings.value("Options/Misc/GoToSystray", true).toBool()){
// Hide window // Hide window
hide(); hide();
} }
@ -873,8 +881,10 @@ void GUI::dropEvent(QDropEvent *event){
QStringList files=event->mimeData()->text().split('\n'); QStringList files=event->mimeData()->text().split('\n');
// Add file to download list // Add file to download list
QString file; QString file;
QSettings settings("qBittorrent", "qBittorrent");
bool useTorrentAdditionDialog = settings.value("Options/Misc/TorrentAdditionDialog/Enabled", true).toBool();
foreach(file, files){ foreach(file, files){
if(options->useAdditionDialog()){ if(useTorrentAdditionDialog){
torrentAdditionDialog *dialog = new torrentAdditionDialog(this); torrentAdditionDialog *dialog = new torrentAdditionDialog(this);
connect(dialog, SIGNAL(torrentAddition(const QString&, bool, const QString&)), &BTSession, SLOT(addTorrent(const QString&, bool, const QString&))); connect(dialog, SIGNAL(torrentAddition(const QString&, bool, const QString&)), &BTSession, SLOT(addTorrent(const QString&, bool, const QString&)));
connect(dialog, SIGNAL(setInfoBarGUI(const QString&, const QString&)), this, SLOT(setInfoBar(const QString&, const QString&))); connect(dialog, SIGNAL(setInfoBarGUI(const QString&, const QString&)), this, SLOT(setInfoBar(const QString&, const QString&)));
@ -909,8 +919,10 @@ void GUI::askForTorrents(){
tr("Open Torrent Files"), settings.value("MainWindowLastDir", QDir::homePath()).toString(), tr("Open Torrent Files"), settings.value("MainWindowLastDir", QDir::homePath()).toString(),
tr("Torrent Files")+" (*.torrent)"); tr("Torrent Files")+" (*.torrent)");
if(!pathsList.empty()){ if(!pathsList.empty()){
QSettings settings("qBittorrent", "qBittorrent");
bool useTorrentAdditionDialog = settings.value("Options/Misc/TorrentAdditionDialog/Enabled", true).toBool();
for(int i=0; i<pathsList.size(); ++i){ for(int i=0; i<pathsList.size(); ++i){
if(options->useAdditionDialog()){ if(useTorrentAdditionDialog){
torrentAdditionDialog *dialog = new torrentAdditionDialog(this); torrentAdditionDialog *dialog = new torrentAdditionDialog(this);
connect(dialog, SIGNAL(torrentAddition(const QString&, bool, const QString&)), &BTSession, SLOT(addTorrent(const QString&, bool, const QString&))); connect(dialog, SIGNAL(torrentAddition(const QString&, bool, const QString&)), &BTSession, SLOT(addTorrent(const QString&, bool, const QString&)));
connect(dialog, SIGNAL(setInfoBarGUI(const QString&, const QString&)), this, SLOT(setInfoBar(const QString&, const QString&))); connect(dialog, SIGNAL(setInfoBarGUI(const QString&, const QString&)), this, SLOT(setInfoBar(const QString&, const QString&)));
@ -1060,7 +1072,8 @@ QString GUI::getSavePath(QString hash){
qDebug("Save path: %s", line.data()); qDebug("Save path: %s", line.data());
savePath = QString::fromUtf8(line.data()); savePath = QString::fromUtf8(line.data());
}else{ }else{
savePath = options->getSavePath(); QSettings settings("qBittorrent", "qBittorrent");
savePath = settings.value("Options/Main/ScanDir", QString()).toString();
} }
// Checking if savePath Dir exists // Checking if savePath Dir exists
// create it if it is not // create it if it is not
@ -1081,12 +1094,14 @@ QString GUI::getSavePath(QString hash){
// the parameter type. // the parameter type.
void GUI::processParams(const QStringList& params){ void GUI::processParams(const QStringList& params){
QString param; QString param;
QSettings settings("qBittorrent", "qBittorrent");
bool useTorrentAdditionDialog = settings.value("Options/Misc/TorrentAdditionDialog/Enabled", true).toBool();
foreach(param, params){ foreach(param, params){
param = param.trimmed(); param = param.trimmed();
if(param.startsWith("http://", Qt::CaseInsensitive) || param.startsWith("ftp://", Qt::CaseInsensitive) || param.startsWith("https://", Qt::CaseInsensitive)){ if(param.startsWith("http://", Qt::CaseInsensitive) || param.startsWith("ftp://", Qt::CaseInsensitive) || param.startsWith("https://", Qt::CaseInsensitive)){
BTSession.downloadFromUrl(param); BTSession.downloadFromUrl(param);
}else{ }else{
if(options->useAdditionDialog()){ if(useTorrentAdditionDialog){
torrentAdditionDialog *dialog = new torrentAdditionDialog(this); torrentAdditionDialog *dialog = new torrentAdditionDialog(this);
connect(dialog, SIGNAL(torrentAddition(const QString&, bool, const QString&)), &BTSession, SLOT(addTorrent(const QString&, bool, const QString&))); connect(dialog, SIGNAL(torrentAddition(const QString&, bool, const QString&)), &BTSession, SLOT(addTorrent(const QString&, bool, const QString&)));
connect(dialog, SIGNAL(setInfoBarGUI(const QString&, const QString&)), this, SLOT(setInfoBar(const QString&, const QString&))); connect(dialog, SIGNAL(setInfoBarGUI(const QString&, const QString&)), this, SLOT(setInfoBar(const QString&, const QString&)));
@ -1100,8 +1115,10 @@ void GUI::processParams(const QStringList& params){
void GUI::processScannedFiles(const QStringList& params){ void GUI::processScannedFiles(const QStringList& params){
QString param; QString param;
QSettings settings("qBittorrent", "qBittorrent");
bool useTorrentAdditionDialog = settings.value("Options/Misc/TorrentAdditionDialog/Enabled", true).toBool();
foreach(param, params){ foreach(param, params){
if(options->useAdditionDialog()){ if(useTorrentAdditionDialog){
torrentAdditionDialog *dialog = new torrentAdditionDialog(this); torrentAdditionDialog *dialog = new torrentAdditionDialog(this);
connect(dialog, SIGNAL(torrentAddition(const QString&, bool, const QString&)), &BTSession, SLOT(addTorrent(const QString&, bool, const QString&))); connect(dialog, SIGNAL(torrentAddition(const QString&, bool, const QString&)), &BTSession, SLOT(addTorrent(const QString&, bool, const QString&)));
connect(dialog, SIGNAL(setInfoBarGUI(const QString&, const QString&)), this, SLOT(setInfoBar(const QString&, const QString&))); connect(dialog, SIGNAL(setInfoBarGUI(const QString&, const QString&)), this, SLOT(setInfoBar(const QString&, const QString&)));
@ -1113,7 +1130,9 @@ void GUI::processScannedFiles(const QStringList& params){
} }
void GUI::processDownloadedFiles(const QString& path, const QString& url){ void GUI::processDownloadedFiles(const QString& path, const QString& url){
if(options->useAdditionDialog()){ QSettings settings("qBittorrent", "qBittorrent");
bool useTorrentAdditionDialog = settings.value("Options/Misc/TorrentAdditionDialog/Enabled", true).toBool();
if(useTorrentAdditionDialog){
torrentAdditionDialog *dialog = new torrentAdditionDialog(this); torrentAdditionDialog *dialog = new torrentAdditionDialog(this);
connect(dialog, SIGNAL(torrentAddition(const QString&, bool, const QString&)), &BTSession, SLOT(addTorrent(const QString&, bool, const QString&))); connect(dialog, SIGNAL(torrentAddition(const QString&, bool, const QString&)), &BTSession, SLOT(addTorrent(const QString&, bool, const QString&)));
connect(dialog, SIGNAL(setInfoBarGUI(const QString&, const QString&)), this, SLOT(setInfoBar(const QString&, const QString&))); connect(dialog, SIGNAL(setInfoBarGUI(const QString&, const QString&)), this, SLOT(setInfoBar(const QString&, const QString&)));
@ -1135,7 +1154,7 @@ void GUI::showProperties(const QModelIndex &index){
} }
// Set BT session configuration // Set BT session configuration
void GUI::configureSession(){ void GUI::configureSession(bool deleteOptions){
qDebug("Configuring session"); qDebug("Configuring session");
QPair<int, int> limits; QPair<int, int> limits;
unsigned short old_listenPort, new_listenPort; unsigned short old_listenPort, new_listenPort;
@ -1206,6 +1225,9 @@ void GUI::configureSession(){
}else{ }else{
BTSession.enableDirectoryScanning(options->getScanDir()); BTSession.enableDirectoryScanning(options->getScanDir());
} }
if(deleteOptions){
delete options;
}
qDebug("Session configured"); qDebug("Session configured");
} }
@ -1319,16 +1341,20 @@ void GUI::propertiesSelection(){
// called when a torrent has finished // called when a torrent has finished
void GUI::finishedTorrent(torrent_handle& h){ void GUI::finishedTorrent(torrent_handle& h){
QSettings settings("qBittorrent", "qBittorrent");
QString fileName = QString(h.name().c_str()); QString fileName = QString(h.name().c_str());
setInfoBar(tr("%1 has finished downloading.", "e.g: xxx.avi has finished downloading.").arg(fileName)); setInfoBar(tr("%1 has finished downloading.", "e.g: xxx.avi has finished downloading.").arg(fileName));
if(options->getUseOSDAlways() || (options->getUseOSDWhenHiddenOnly() && (isMinimized() || isHidden()))) { bool useOSD = (settings.value("Options/Misc/OSDEnabled", 1).toInt() > 0);
if(useOSD && (isMinimized() || isHidden())) {
myTrayIcon->showMessage(tr("Download finished"), tr("%1 has finished downloading.", "e.g: xxx.avi has finished downloading.").arg(fileName), QSystemTrayIcon::Information, TIME_TRAY_BALLOON); myTrayIcon->showMessage(tr("Download finished"), tr("%1 has finished downloading.", "e.g: xxx.avi has finished downloading.").arg(fileName), QSystemTrayIcon::Information, TIME_TRAY_BALLOON);
} }
} }
// Notification when disk is full // Notification when disk is full
void GUI::fullDiskError(torrent_handle& h){ void GUI::fullDiskError(torrent_handle& h){
if(options->getUseOSDAlways() || (options->getUseOSDWhenHiddenOnly() && (isMinimized() || isHidden()))) { QSettings settings("qBittorrent", "qBittorrent");
bool useOSD = (settings.value("Options/Misc/OSDEnabled", 1).toInt() > 0);
if(useOSD && (isMinimized() || isHidden())) {
myTrayIcon->showMessage(tr("I/O Error", "i.e: Input/Output Error"), tr("An error occured when trying to read or write %1. The disk is probably full, download has been paused", "e.g: An error occured when trying to read or write xxx.avi. The disk is probably full, download has been paused").arg(QString(h.name().c_str())), QSystemTrayIcon::Critical, TIME_TRAY_BALLOON); myTrayIcon->showMessage(tr("I/O Error", "i.e: Input/Output Error"), tr("An error occured when trying to read or write %1. The disk is probably full, download has been paused", "e.g: An error occured when trying to read or write xxx.avi. The disk is probably full, download has been paused").arg(QString(h.name().c_str())), QSystemTrayIcon::Critical, TIME_TRAY_BALLOON);
} }
// Download will be paused by libtorrent. Updating GUI information accordingly // Download will be paused by libtorrent. Updating GUI information accordingly
@ -1703,7 +1729,9 @@ void GUI::on_update_nova_button_clicked(){
// Search can be finished for 3 reasons : // Search can be finished for 3 reasons :
// Error | Stopped by user | Finished normally // Error | Stopped by user | Finished normally
void GUI::searchFinished(int exitcode,QProcess::ExitStatus){ void GUI::searchFinished(int exitcode,QProcess::ExitStatus){
if(options->getUseOSDAlways() || (options->getUseOSDWhenHiddenOnly() && (isMinimized() || isHidden()))) { QSettings settings("qBittorrent", "qBittorrent");
bool useOSD = (settings.value("Options/Misc/OSDEnabled", 1).toInt() > 0);
if(useOSD && (isMinimized() || isHidden())) {
myTrayIcon->showMessage(tr("Search Engine"), tr("Search has finished"), QSystemTrayIcon::Information, TIME_TRAY_BALLOON); myTrayIcon->showMessage(tr("Search Engine"), tr("Search has finished"), QSystemTrayIcon::Information, TIME_TRAY_BALLOON);
} }
if(exitcode){ if(exitcode){
@ -1829,24 +1857,19 @@ void GUI::displayDownloadingUrlInfos(const QString& url){
* * * *
*****************************************************/ *****************************************************/
// Set locale in options, this is required
// because main() can set the locale and it
// can't access options object directly.
void GUI::setLocale(QString locale){
options->setLocale(locale);
}
// Display Program Options // Display Program Options
void GUI::showOptions() const{ void GUI::showOptions(){
options = new options_imp(this);
connect(options, SIGNAL(status_changed(const QString&, bool)), this, SLOT(OptionsSaved(const QString&, bool)));
options->show(); options->show();
} }
// Is executed each time options are saved // Is executed each time options are saved
void GUI::OptionsSaved(const QString& info){ void GUI::OptionsSaved(const QString& info, bool deleteOptions){
// Update info bar // Update info bar
setInfoBar(info); setInfoBar(info);
// Update session // Update session
configureSession(); configureSession(deleteOptions);
} }
/***************************************************** /*****************************************************

7
src/GUI.h

@ -146,7 +146,7 @@ class GUI : public QMainWindow, private Ui::MainWindow{
void deletePermanently(); void deletePermanently();
void deleteSelection(); void deleteSelection();
void checkConnectionStatus(); void checkConnectionStatus();
void configureSession(); void configureSession(bool deleteOptions);
void processParams(const QStringList& params); void processParams(const QStringList& params);
void addUnauthenticatedTracker(QPair<torrent_handle,std::string> tracker); void addUnauthenticatedTracker(QPair<torrent_handle,std::string> tracker);
void processScannedFiles(const QStringList& params); void processScannedFiles(const QStringList& params);
@ -169,13 +169,12 @@ class GUI : public QMainWindow, private Ui::MainWindow{
// Utils slots // Utils slots
void setRowColor(int row, const QString& color, bool inDLList=true); void setRowColor(int row, const QString& color, bool inDLList=true);
// Options slots // Options slots
void showOptions() const; void showOptions();
void OptionsSaved(const QString& info); void OptionsSaved(const QString& info, bool deleteOptions);
// HTTP slots // HTTP slots
void askForTorrentUrl(); void askForTorrentUrl();
public slots: public slots:
void setLocale(QString locale);
void torrentAdded(const QString& path, torrent_handle& h, bool fastResume); void torrentAdded(const QString& path, torrent_handle& h, bool fastResume);
void torrentDuplicate(const QString& path); void torrentDuplicate(const QString& path);
void torrentCorrupted(const QString& path); void torrentCorrupted(const QString& path);

6
src/main.cpp

@ -86,10 +86,10 @@ int main(int argc, char *argv[]){
// Open options file to read locale // Open options file to read locale
QSettings settings("qBittorrent", "qBittorrent"); QSettings settings("qBittorrent", "qBittorrent");
locale = settings.value("Options/Language/Locale", QString()).toString(); locale = settings.value("Options/Language/Locale", QString()).toString();
QTranslator translator; QTranslator translator;
if(locale.isEmpty()){ if(locale.isEmpty()){
locale = QLocale::system().name(); locale = QLocale::system().name();
settings.setValue("Options/Language/Locale", locale);
} }
if(translator.load(QString(":/lang/qbittorrent_") + locale)){ if(translator.load(QString(":/lang/qbittorrent_") + locale)){
qDebug("%s locale recognized, using translation.", (const char*)locale.toUtf8()); qDebug("%s locale recognized, using translation.", (const char*)locale.toUtf8());
@ -103,10 +103,6 @@ int main(int argc, char *argv[]){
// Remove first argument (program name) // Remove first argument (program name)
torrentCmdLine.removeFirst(); torrentCmdLine.removeFirst();
GUI window(0, torrentCmdLine); GUI window(0, torrentCmdLine);
// Set locale
window.setLocale(locale);
// Show main window
window.show();
splash->finish(&window); splash->finish(&window);
delete splash; delete splash;
return app.exec(); return app.exec();

19
src/options_imp.cpp

@ -30,6 +30,7 @@
// Constructor // Constructor
options_imp::options_imp(QWidget *parent):QDialog(parent){ options_imp::options_imp(QWidget *parent):QDialog(parent){
qDebug("-> Constructing Options");
QString savePath; QString savePath;
setupUi(this); setupUi(this);
// Setting icons // Setting icons
@ -157,6 +158,11 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){
} }
} }
// Main destructor
options_imp::~options_imp(){
qDebug("-> destructing Options");
}
void options_imp::saveOptions(){ void options_imp::saveOptions(){
QSettings settings("qBittorrent", "qBittorrent"); QSettings settings("qBittorrent", "qBittorrent");
// Check if min port < max port // Check if min port < max port
@ -235,8 +241,6 @@ void options_imp::saveOptions(){
} }
} }
settings.endGroup(); settings.endGroup();
// set infobar text
emit status_changed(tr("Options were saved successfully."));
// Disable apply Button // Disable apply Button
applyButton->setEnabled(false); applyButton->setEnabled(false);
} }
@ -516,8 +520,13 @@ void options_imp::on_okButton_clicked(){
if(applyButton->isEnabled()){ if(applyButton->isEnabled()){
saveOptions(); saveOptions();
applyButton->setEnabled(false); applyButton->setEnabled(false);
// set infobar text
emit status_changed(tr("Options were saved successfully."), true);
this->hide();
}else{
setAttribute(Qt::WA_DeleteOnClose);
accept();
} }
this->hide();
} }
bool options_imp::getClearFinishedOnExit() const{ bool options_imp::getClearFinishedOnExit() const{
@ -526,10 +535,12 @@ bool options_imp::getClearFinishedOnExit() const{
void options_imp::on_applyButton_clicked(){ void options_imp::on_applyButton_clicked(){
saveOptions(); saveOptions();
emit optionsApplied(tr("Options were saved successfully."), false);
} }
void options_imp::on_cancelButton_clicked(){ void options_imp::on_cancelButton_clicked(){
this->hide(); setAttribute(Qt::WA_DeleteOnClose);
reject();
} }
void options_imp::disableDownload(int checkBoxValue){ void options_imp::disableDownload(int checkBoxValue){

7
src/options_imp.h

@ -38,8 +38,9 @@ class options_imp : public QDialog, private Ui::Dialog{
QStringList locales; QStringList locales;
public: public:
// Contructor // Contructor / Destructor
options_imp(QWidget *parent=0); options_imp(QWidget *parent=0);
~options_imp();
// Methods // Methods
void saveOptions(); void saveOptions();
@ -106,7 +107,9 @@ class options_imp : public QDialog, private Ui::Dialog{
void setLocale(QString locale); void setLocale(QString locale);
signals: signals:
void status_changed(const QString&) const; void status_changed(const QString&, bool) const;
void optionsApplied(const QString&, bool);
void exitWithCancel();
}; };
#endif #endif

Loading…
Cancel
Save