File indexing completed on 2024-04-21 08:47:05

0001 /* This file is part of the KDE project
0002 
0003    Copyright (C) 2008 Lukas Appelhans <l.appelhans@gmx.de>
0004    Copyright (C) 2009 Matthias Fuchs <mat69@gmx.net>
0005 
0006    This program is free software; you can redistribute it and/or
0007    modify it under the terms of the GNU General Public
0008    License as published by the Free Software Foundation; either
0009    version 2 of the License, or (at your option) any later version.
0010 */
0011 #include "groupsettingsdialog.h"
0012 
0013 #include "core/transfergrouphandler.h"
0014 
0015 GroupSettingsDialog::GroupSettingsDialog(QWidget *parent, TransferGroupHandler *group)
0016     : KGetSaveSizeDialog("GroupSettingsDialog", parent)
0017     , m_group(group)
0018 {
0019     setWindowTitle(i18n("Group Settings for %1", group->name()));
0020 
0021     ui.setupUi(this);
0022 
0023     ui.downloadBox->setValue(group->downloadLimit(Transfer::VisibleSpeedLimit));
0024     ui.uploadBox->setValue(group->uploadLimit(Transfer::VisibleSpeedLimit));
0025 
0026     ui.defaultFolderRequester->setMode(KFile::Directory);
0027     QString path = group->defaultFolder();
0028     ui.defaultFolderRequester->setUrl(QUrl::fromLocalFile(path));
0029     ui.defaultFolderRequester->setStartDir(QUrl(KGet::generalDestDir(true)));
0030 
0031     ui.regExpEdit->setText(group->regExp().pattern());
0032 
0033     ui.nepomukWidget->hide();
0034 
0035     connect(ui.buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
0036     connect(ui.buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
0037     connect(this, &GroupSettingsDialog::accepted, this, &GroupSettingsDialog::save);
0038 }
0039 
0040 GroupSettingsDialog::~GroupSettingsDialog()
0041 {
0042 }
0043 
0044 QSize GroupSettingsDialog::sizeHint() const
0045 {
0046     QSize sh = QDialog::sizeHint();
0047     sh.setWidth(sh.width() * 1.4);
0048     return sh;
0049 }
0050 
0051 void GroupSettingsDialog::save()
0052 {
0053     // check needed, otherwise "/" would be added as folder if the line was empty!
0054     if (ui.defaultFolderRequester->text().isEmpty()) {
0055         m_group->setDefaultFolder(QString());
0056     } else {
0057         m_group->setDefaultFolder(ui.defaultFolderRequester->url().toLocalFile());
0058     }
0059 
0060     m_group->setDownloadLimit(ui.downloadBox->value(), Transfer::VisibleSpeedLimit);
0061     m_group->setUploadLimit(ui.uploadBox->value(), Transfer::VisibleSpeedLimit);
0062 
0063     QRegularExpression regExp;
0064     regExp.setPattern(ui.regExpEdit->text());
0065     m_group->setRegExp(regExp);
0066 }
0067 
0068 #include "moc_groupsettingsdialog.cpp"