File indexing completed on 2024-04-28 04:57:29

0001 /* This file is part of the KDE project
0002 
0003    Copyright (C) 2007 Lukas Appelhans <l.appelhans@gmx.de>
0004 
0005    This program is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU General Public
0007    License as published by the Free Software Foundation; either
0008    version 2 of the License, or (at your option) any later version.
0009 */
0010 #include "btsettingswidget.h"
0011 
0012 #include "bittorrentsettings.h"
0013 #include "kget_macro.h"
0014 
0015 #include "kget_debug.h"
0016 #include <qobject.h>
0017 
0018 KGET_EXPORT_PLUGIN_CONFIG(BTSettingsWidget)
0019 
0020 BTSettingsWidget::BTSettingsWidget(QObject *parent, const KPluginMetaData &data)
0021     : KCModule(parent, data)
0022 {
0023     setupUi(widget());
0024 
0025     connect(portBox, &QSpinBox::valueChanged, this, &BTSettingsWidget::markAsChanged);
0026     connect(uploadBox, &QSpinBox::valueChanged, this, &BTSettingsWidget::markAsChanged);
0027     connect(downloadBox, &QSpinBox::valueChanged, this, &BTSettingsWidget::markAsChanged);
0028     connect(torrentEdit, &KUrlRequester::textChanged, this, &BTSettingsWidget::markAsChanged);
0029     connect(tempEdit, &KUrlRequester::textChanged, this, &BTSettingsWidget::markAsChanged);
0030     connect(preallocBox, &QCheckBox::stateChanged, this, &BTSettingsWidget::markAsChanged);
0031     connect(utpBox, &QCheckBox::stateChanged, this, &BTSettingsWidget::markAsChanged);
0032 }
0033 
0034 void BTSettingsWidget::load()
0035 {
0036     torrentEdit->setMode(KFile::Directory);
0037     tempEdit->setMode(KFile::Directory);
0038     defaults();
0039 }
0040 
0041 void BTSettingsWidget::save()
0042 {
0043     qCDebug(KGET_DEBUG) << "Save Bittorrent-config";
0044     BittorrentSettings::setPort(portBox->value());
0045     BittorrentSettings::setUploadLimit(uploadBox->value());
0046     BittorrentSettings::setDownloadLimit(downloadBox->value());
0047     BittorrentSettings::setTorrentDir(torrentEdit->url().url());
0048     BittorrentSettings::setTmpDir(tempEdit->url().url());
0049     BittorrentSettings::setPreAlloc(preallocBox->isChecked());
0050     BittorrentSettings::setEnableUTP(utpBox->isChecked());
0051 
0052     BittorrentSettings::self()->save();
0053 }
0054 
0055 void BTSettingsWidget::defaults()
0056 {
0057     portBox->setValue(BittorrentSettings::port());
0058     uploadBox->setValue(BittorrentSettings::uploadLimit());
0059     downloadBox->setValue(BittorrentSettings::downloadLimit());
0060     torrentEdit->setUrl(QUrl::fromLocalFile(BittorrentSettings::torrentDir()));
0061     tempEdit->setUrl(QUrl::fromLocalFile(BittorrentSettings::tmpDir()));
0062     preallocBox->setChecked(BittorrentSettings::preAlloc());
0063     utpBox->setChecked(BittorrentSettings::enableUTP());
0064 }
0065 
0066 #include "btsettingswidget.moc"
0067 #include "moc_btsettingswidget.cpp"