Changeset View
Changeset View
Standalone View
Standalone View
src/settings/general/previewssettingspage.cpp
Show All 33 Lines | |||||
34 | #include <QPainter> | 34 | #include <QPainter> | ||
35 | #include <QShowEvent> | 35 | #include <QShowEvent> | ||
36 | #include <QSortFilterProxyModel> | 36 | #include <QSortFilterProxyModel> | ||
37 | #include <QSpinBox> | 37 | #include <QSpinBox> | ||
38 | 38 | | |||
39 | // default settings | 39 | // default settings | ||
40 | namespace { | 40 | namespace { | ||
41 | const int MaxRemotePreviewSize = 0; // 0 MB | 41 | const int MaxRemotePreviewSize = 0; // 0 MB | ||
42 | const int MaxPreviewSize = 50; // 50 MB | ||||
42 | } | 43 | } | ||
43 | 44 | | |||
44 | PreviewsSettingsPage::PreviewsSettingsPage(QWidget* parent) : | 45 | PreviewsSettingsPage::PreviewsSettingsPage(QWidget* parent) : | ||
45 | SettingsPageBase(parent), | 46 | SettingsPageBase(parent), | ||
46 | m_initialized(false), | 47 | m_initialized(false), | ||
47 | m_listView(nullptr), | 48 | m_listView(nullptr), | ||
48 | m_enabledPreviewPlugins(), | 49 | m_enabledPreviewPlugins(), | ||
49 | m_remoteFileSizeBox(nullptr) | 50 | m_remoteFileSizeBox(nullptr), | ||
51 | m_FileSizeBox(nullptr) | ||||
50 | { | 52 | { | ||
51 | QVBoxLayout* topLayout = new QVBoxLayout(this); | 53 | QVBoxLayout* topLayout = new QVBoxLayout(this); | ||
52 | 54 | | |||
53 | QLabel* showPreviewsLabel = new QLabel(i18nc("@title:group", "Show previews in the view for:"), this); | 55 | QLabel* showPreviewsLabel = new QLabel(i18nc("@title:group", "Show previews in the view for:"), this); | ||
54 | 56 | | |||
55 | m_listView = new QListView(this); | 57 | m_listView = new QListView(this); | ||
56 | 58 | | |||
57 | ServiceItemDelegate* delegate = new ServiceItemDelegate(m_listView, m_listView); | 59 | ServiceItemDelegate* delegate = new ServiceItemDelegate(m_listView, m_listView); | ||
Show All 16 Lines | |||||
74 | m_remoteFileSizeBox->setSingleStep(1); | 76 | m_remoteFileSizeBox->setSingleStep(1); | ||
75 | m_remoteFileSizeBox->setSuffix(QStringLiteral(" MB")); | 77 | m_remoteFileSizeBox->setSuffix(QStringLiteral(" MB")); | ||
76 | m_remoteFileSizeBox->setRange(0, 9999999); /* MB */ | 78 | m_remoteFileSizeBox->setRange(0, 9999999); /* MB */ | ||
77 | 79 | | |||
78 | QHBoxLayout* fileSizeBoxLayout = new QHBoxLayout(); | 80 | QHBoxLayout* fileSizeBoxLayout = new QHBoxLayout(); | ||
79 | fileSizeBoxLayout->addWidget(remoteFileSizeLabel, 0, Qt::AlignRight); | 81 | fileSizeBoxLayout->addWidget(remoteFileSizeLabel, 0, Qt::AlignRight); | ||
80 | fileSizeBoxLayout->addWidget(m_remoteFileSizeBox); | 82 | fileSizeBoxLayout->addWidget(m_remoteFileSizeBox); | ||
81 | 83 | | |||
84 | QLabel* FileSizeLabel = new QLabel(i18nc("@label", "Skip previews for files above:"), this); | ||||
85 | | ||||
86 | m_FileSizeBox = new QSpinBox(this); | ||||
87 | m_FileSizeBox->setSingleStep(1); | ||||
88 | m_FileSizeBox->setSuffix(QStringLiteral(" MB")); | ||||
89 | m_FileSizeBox->setRange(0, 9999999); /* MB */ | ||||
90 | | ||||
91 | QHBoxLayout* fileSizeBoxLayout2 = new QHBoxLayout(); | ||||
92 | fileSizeBoxLayout2->addWidget(FileSizeLabel, 50, Qt::AlignRight); | ||||
93 | fileSizeBoxLayout2->addWidget(m_FileSizeBox); | ||||
94 | | ||||
82 | topLayout->addWidget(showPreviewsLabel); | 95 | topLayout->addWidget(showPreviewsLabel); | ||
83 | topLayout->addWidget(m_listView); | 96 | topLayout->addWidget(m_listView); | ||
84 | topLayout->addLayout(fileSizeBoxLayout); | 97 | topLayout->addLayout(fileSizeBoxLayout); | ||
98 | topLayout->addLayout(fileSizeBoxLayout2); | ||||
85 | 99 | | |||
86 | loadSettings(); | 100 | loadSettings(); | ||
87 | 101 | | |||
88 | connect(m_listView, &QListView::clicked, this, &PreviewsSettingsPage::changed); | 102 | connect(m_listView, &QListView::clicked, this, &PreviewsSettingsPage::changed); | ||
89 | connect(m_remoteFileSizeBox, QOverload<int>::of(&QSpinBox::valueChanged), this, &PreviewsSettingsPage::changed); | 103 | connect(m_remoteFileSizeBox, QOverload<int>::of(&QSpinBox::valueChanged), this, &PreviewsSettingsPage::changed); | ||
104 | connect(m_FileSizeBox, QOverload<int>::of(&QSpinBox::valueChanged), this, &PreviewsSettingsPage::changed); | ||||
90 | } | 105 | } | ||
91 | 106 | | |||
92 | PreviewsSettingsPage::~PreviewsSettingsPage() | 107 | PreviewsSettingsPage::~PreviewsSettingsPage() | ||
93 | { | 108 | { | ||
94 | } | 109 | } | ||
95 | 110 | | |||
96 | void PreviewsSettingsPage::applySettings() | 111 | void PreviewsSettingsPage::applySettings() | ||
97 | { | 112 | { | ||
Show All 13 Lines | |||||
111 | 126 | | |||
112 | KConfigGroup globalConfig(KSharedConfig::openConfig(), QStringLiteral("PreviewSettings")); | 127 | KConfigGroup globalConfig(KSharedConfig::openConfig(), QStringLiteral("PreviewSettings")); | ||
113 | globalConfig.writeEntry("Plugins", m_enabledPreviewPlugins); | 128 | globalConfig.writeEntry("Plugins", m_enabledPreviewPlugins); | ||
114 | 129 | | |||
115 | const qulonglong maximumRemoteSize = static_cast<qulonglong>(m_remoteFileSizeBox->value()) * 1024 * 1024; | 130 | const qulonglong maximumRemoteSize = static_cast<qulonglong>(m_remoteFileSizeBox->value()) * 1024 * 1024; | ||
116 | globalConfig.writeEntry("MaximumRemoteSize", | 131 | globalConfig.writeEntry("MaximumRemoteSize", | ||
117 | maximumRemoteSize, | 132 | maximumRemoteSize, | ||
118 | KConfigBase::Normal | KConfigBase::Global); | 133 | KConfigBase::Normal | KConfigBase::Global); | ||
134 | | ||||
135 | const qulonglong maximumSize = static_cast<qulonglong>(m_FileSizeBox->value())* 1024 * 1024; | ||||
136 | globalConfig.writeEntry("MaximumSize", | ||||
137 | maximumSize, | ||||
138 | KConfigBase::Normal | KConfigBase::Global); | ||||
119 | globalConfig.sync(); | 139 | globalConfig.sync(); | ||
120 | } | 140 | } | ||
121 | 141 | | |||
122 | void PreviewsSettingsPage::restoreDefaults() | 142 | void PreviewsSettingsPage::restoreDefaults() | ||
123 | { | 143 | { | ||
124 | m_remoteFileSizeBox->setValue(MaxRemotePreviewSize); | 144 | m_remoteFileSizeBox->setValue(MaxRemotePreviewSize); | ||
145 | m_FileSizeBox->setValue(MaxPreviewSize); | ||||
125 | } | 146 | } | ||
126 | 147 | | |||
127 | void PreviewsSettingsPage::showEvent(QShowEvent* event) | 148 | void PreviewsSettingsPage::showEvent(QShowEvent* event) | ||
128 | { | 149 | { | ||
129 | if (!event->spontaneous() && !m_initialized) { | 150 | if (!event->spontaneous() && !m_initialized) { | ||
130 | loadPreviewPlugins(); | 151 | loadPreviewPlugins(); | ||
131 | m_initialized = true; | 152 | m_initialized = true; | ||
132 | } | 153 | } | ||
Show All 35 Lines | |||||
168 | { | 189 | { | ||
169 | const KConfigGroup globalConfig(KSharedConfig::openConfig(), QStringLiteral("PreviewSettings")); | 190 | const KConfigGroup globalConfig(KSharedConfig::openConfig(), QStringLiteral("PreviewSettings")); | ||
170 | m_enabledPreviewPlugins = globalConfig.readEntry("Plugins", KIO::PreviewJob::defaultPlugins()); | 191 | m_enabledPreviewPlugins = globalConfig.readEntry("Plugins", KIO::PreviewJob::defaultPlugins()); | ||
171 | 192 | | |||
172 | const qulonglong defaultRemotePreview = static_cast<qulonglong>(MaxRemotePreviewSize) * 1024 * 1024; | 193 | const qulonglong defaultRemotePreview = static_cast<qulonglong>(MaxRemotePreviewSize) * 1024 * 1024; | ||
173 | const qulonglong maxRemoteByteSize = globalConfig.readEntry("MaximumRemoteSize", defaultRemotePreview); | 194 | const qulonglong maxRemoteByteSize = globalConfig.readEntry("MaximumRemoteSize", defaultRemotePreview); | ||
174 | const int maxRemoteMByteSize = maxRemoteByteSize / (1024 * 1024); | 195 | const int maxRemoteMByteSize = maxRemoteByteSize / (1024 * 1024); | ||
175 | m_remoteFileSizeBox->setValue(maxRemoteMByteSize); | 196 | m_remoteFileSizeBox->setValue(maxRemoteMByteSize); | ||
197 | | ||||
198 | const qulonglong defaultPreview = static_cast<qulonglong>(MaxPreviewSize)* 1024 * 1024; | ||||
199 | const qulonglong maxByteSize = globalConfig.readEntry("MaximumSize", defaultPreview); | ||||
200 | const int maxMByteSize = maxByteSize / (1024 * 1024); | ||||
201 | m_FileSizeBox->setValue(maxMByteSize); | ||||
176 | } | 202 | } | ||
177 | 203 | |