1 /*
2     SPDX-FileCopyrightText: 2008 Joris Guisson <joris.guisson@gmail.com>
3     SPDX-FileCopyrightText: 2008 Ivan Vasic <ivasic@gmail.com>
4     SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "grouppolicydlg.h"
8 #include <groups/group.h>
9 
10 namespace kt
11 {
GroupPolicyDlg(Group * group,QWidget * parent)12 GroupPolicyDlg::GroupPolicyDlg(Group *group, QWidget *parent)
13     : QDialog(parent)
14     , group(group)
15 {
16     setupUi(this);
17     connect(buttonBox, &QDialogButtonBox::accepted, this, &GroupPolicyDlg::accept);
18     connect(buttonBox, &QDialogButtonBox::rejected, this, &GroupPolicyDlg::reject);
19     setWindowTitle(i18n("Policy for the %1 group", group->groupName()));
20 
21     const Group::Policy &p = group->groupPolicy();
22     m_default_location_enabled->setChecked(!p.default_save_location.isEmpty());
23     m_default_location->setEnabled(!p.default_save_location.isEmpty());
24     m_default_location->setUrl(QUrl::fromLocalFile(p.default_save_location));
25     m_default_location->setMode(KFile::Directory | KFile::ExistingOnly | KFile::LocalOnly);
26 
27     m_default_move_on_completion_enabled->setChecked(!p.default_move_on_completion_location.isEmpty());
28     m_default_move_on_completion_location->setEnabled(!p.default_move_on_completion_location.isEmpty());
29     m_default_move_on_completion_location->setUrl(QUrl::fromLocalFile(p.default_move_on_completion_location));
30     m_default_move_on_completion_location->setMode(KFile::Directory | KFile::ExistingOnly | KFile::LocalOnly);
31 
32     m_only_new->setChecked(p.only_apply_on_new_torrents);
33     m_max_share_ratio->setValue(p.max_share_ratio);
34     m_max_seed_time->setValue(p.max_seed_time);
35     m_max_upload_rate->setValue(p.max_upload_rate);
36     m_max_download_rate->setValue(p.max_download_rate);
37 }
38 
~GroupPolicyDlg()39 GroupPolicyDlg::~GroupPolicyDlg()
40 {
41 }
42 
accept()43 void GroupPolicyDlg::accept()
44 {
45     Group::Policy p;
46     if (m_default_location_enabled->isChecked() && m_default_location->url().isValid())
47         p.default_save_location = m_default_location->url().toDisplayString(QUrl::PreferLocalFile);
48 
49     if (m_default_move_on_completion_enabled->isChecked() && m_default_move_on_completion_location->url().isValid())
50         p.default_move_on_completion_location = m_default_move_on_completion_location->url().toDisplayString(QUrl::PreferLocalFile);
51 
52     p.only_apply_on_new_torrents = m_only_new->isChecked();
53     p.max_share_ratio = m_max_share_ratio->value();
54     p.max_seed_time = m_max_seed_time->value();
55     p.max_upload_rate = m_max_upload_rate->value();
56     p.max_download_rate = m_max_download_rate->value();
57     group->setGroupPolicy(p);
58     QDialog::accept();
59 }
60 
61 }
62