Changeset View
Changeset View
Standalone View
Standalone View
src/settings/general/previewssettingspage.cpp
Show All 28 Lines | |||||
29 | #include <KServiceTypeTrader> | 29 | #include <KServiceTypeTrader> | ||
30 | 30 | | |||
31 | #include <QHBoxLayout> | 31 | #include <QHBoxLayout> | ||
32 | #include <QLabel> | 32 | #include <QLabel> | ||
33 | #include <QListView> | 33 | #include <QListView> | ||
34 | #include <QPainter> | 34 | #include <QPainter> | ||
35 | #include <QSortFilterProxyModel> | 35 | #include <QSortFilterProxyModel> | ||
36 | #include <QSpinBox> | 36 | #include <QSpinBox> | ||
37 | #include <QCheckBox> | ||||
37 | 38 | | |||
38 | // default settings | 39 | // default settings | ||
39 | namespace { | 40 | namespace { | ||
40 | const int MaxRemotePreviewSize = 0; // 0 MB | 41 | const int MaxRemotePreviewSize = 0; // 0 MB | ||
41 | } | 42 | } | ||
42 | 43 | | |||
43 | PreviewsSettingsPage::PreviewsSettingsPage(QWidget* parent) : | 44 | PreviewsSettingsPage::PreviewsSettingsPage(QWidget* parent) : | ||
44 | SettingsPageBase(parent), | 45 | SettingsPageBase(parent), | ||
45 | m_initialized(false), | 46 | m_initialized(false), | ||
46 | m_listView(nullptr), | 47 | m_listView(nullptr), | ||
47 | m_enabledPreviewPlugins(), | 48 | m_enabledPreviewPlugins(), | ||
48 | m_remoteFileSizeBox(nullptr) | 49 | m_remoteFileSizeBox(nullptr), | ||
50 | m_autoPlayMediaFiles(nullptr) | ||||
49 | { | 51 | { | ||
50 | QVBoxLayout* topLayout = new QVBoxLayout(this); | 52 | QVBoxLayout* topLayout = new QVBoxLayout(this); | ||
51 | 53 | | |||
52 | QLabel* showPreviewsLabel = new QLabel(i18nc("@title:group", "Show previews in the view for:"), this); | 54 | QLabel* showPreviewsLabel = new QLabel(i18nc("@title:group", "Show previews in the view for:"), this); | ||
53 | 55 | | |||
54 | m_listView = new QListView(this); | 56 | m_listView = new QListView(this); | ||
55 | 57 | | |||
56 | ServiceItemDelegate* delegate = new ServiceItemDelegate(m_listView, m_listView); | 58 | ServiceItemDelegate* delegate = new ServiceItemDelegate(m_listView, m_listView); | ||
Show All 16 Lines | |||||
73 | m_remoteFileSizeBox->setSingleStep(1); | 75 | m_remoteFileSizeBox->setSingleStep(1); | ||
74 | m_remoteFileSizeBox->setSuffix(QStringLiteral(" MB")); | 76 | m_remoteFileSizeBox->setSuffix(QStringLiteral(" MB")); | ||
75 | m_remoteFileSizeBox->setRange(0, 9999999); /* MB */ | 77 | m_remoteFileSizeBox->setRange(0, 9999999); /* MB */ | ||
76 | 78 | | |||
77 | QHBoxLayout* fileSizeBoxLayout = new QHBoxLayout(); | 79 | QHBoxLayout* fileSizeBoxLayout = new QHBoxLayout(); | ||
78 | fileSizeBoxLayout->addWidget(remoteFileSizeLabel, 0, Qt::AlignRight); | 80 | fileSizeBoxLayout->addWidget(remoteFileSizeLabel, 0, Qt::AlignRight); | ||
79 | fileSizeBoxLayout->addWidget(m_remoteFileSizeBox); | 81 | fileSizeBoxLayout->addWidget(m_remoteFileSizeBox); | ||
80 | 82 | | |||
83 | m_autoPlayMediaFiles = new QCheckBox(i18nc("@option:check", "Play media files automatically while hovering"), this); | ||||
84 | | ||||
81 | topLayout->addWidget(showPreviewsLabel); | 85 | topLayout->addWidget(showPreviewsLabel); | ||
82 | topLayout->addWidget(m_listView); | 86 | topLayout->addWidget(m_listView); | ||
83 | topLayout->addLayout(fileSizeBoxLayout); | 87 | topLayout->addLayout(fileSizeBoxLayout); | ||
88 | topLayout->addWidget(m_autoPlayMediaFiles); | ||||
84 | 89 | | |||
85 | loadSettings(); | 90 | loadSettings(); | ||
86 | 91 | | |||
87 | connect(m_listView, &QListView::clicked, this, &PreviewsSettingsPage::changed); | 92 | connect(m_listView, &QListView::clicked, this, &PreviewsSettingsPage::changed); | ||
88 | connect(m_remoteFileSizeBox, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &PreviewsSettingsPage::changed); | 93 | connect(m_remoteFileSizeBox, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &PreviewsSettingsPage::changed); | ||
94 | connect(m_autoPlayMediaFiles, &QCheckBox::toggled, this, &PreviewsSettingsPage::changed); | ||||
89 | } | 95 | } | ||
90 | 96 | | |||
91 | PreviewsSettingsPage::~PreviewsSettingsPage() | 97 | PreviewsSettingsPage::~PreviewsSettingsPage() | ||
92 | { | 98 | { | ||
93 | } | 99 | } | ||
94 | 100 | | |||
95 | void PreviewsSettingsPage::applySettings() | 101 | void PreviewsSettingsPage::applySettings() | ||
96 | { | 102 | { | ||
Show All 14 Lines | |||||
111 | KConfigGroup globalConfig(KSharedConfig::openConfig(), QStringLiteral("PreviewSettings")); | 117 | KConfigGroup globalConfig(KSharedConfig::openConfig(), QStringLiteral("PreviewSettings")); | ||
112 | globalConfig.writeEntry("Plugins", m_enabledPreviewPlugins); | 118 | globalConfig.writeEntry("Plugins", m_enabledPreviewPlugins); | ||
113 | 119 | | |||
114 | const qulonglong maximumRemoteSize = static_cast<qulonglong>(m_remoteFileSizeBox->value()) * 1024 * 1024; | 120 | const qulonglong maximumRemoteSize = static_cast<qulonglong>(m_remoteFileSizeBox->value()) * 1024 * 1024; | ||
115 | globalConfig.writeEntry("MaximumRemoteSize", | 121 | globalConfig.writeEntry("MaximumRemoteSize", | ||
116 | maximumRemoteSize, | 122 | maximumRemoteSize, | ||
117 | KConfigBase::Normal | KConfigBase::Global); | 123 | KConfigBase::Normal | KConfigBase::Global); | ||
118 | globalConfig.sync(); | 124 | globalConfig.sync(); | ||
125 | | ||||
126 | GeneralSettings* settings = GeneralSettings::self(); | ||||
127 | settings->setAutoPlayMediaFiles(m_autoPlayMediaFiles->isChecked()); | ||||
128 | settings->save(); | ||||
119 | } | 129 | } | ||
120 | 130 | | |||
121 | void PreviewsSettingsPage::restoreDefaults() | 131 | void PreviewsSettingsPage::restoreDefaults() | ||
122 | { | 132 | { | ||
123 | m_remoteFileSizeBox->setValue(MaxRemotePreviewSize); | 133 | m_remoteFileSizeBox->setValue(MaxRemotePreviewSize); | ||
134 | m_autoPlayMediaFiles->setChecked(false); | ||||
124 | } | 135 | } | ||
125 | 136 | | |||
126 | void PreviewsSettingsPage::showEvent(QShowEvent* event) | 137 | void PreviewsSettingsPage::showEvent(QShowEvent* event) | ||
127 | { | 138 | { | ||
128 | if (!event->spontaneous() && !m_initialized) { | 139 | if (!event->spontaneous() && !m_initialized) { | ||
129 | loadPreviewPlugins(); | 140 | loadPreviewPlugins(); | ||
130 | m_initialized = true; | 141 | m_initialized = true; | ||
131 | } | 142 | } | ||
Show All 35 Lines | |||||
167 | { | 178 | { | ||
168 | const KConfigGroup globalConfig(KSharedConfig::openConfig(), QStringLiteral("PreviewSettings")); | 179 | const KConfigGroup globalConfig(KSharedConfig::openConfig(), QStringLiteral("PreviewSettings")); | ||
169 | m_enabledPreviewPlugins = globalConfig.readEntry("Plugins", KIO::PreviewJob::defaultPlugins()); | 180 | m_enabledPreviewPlugins = globalConfig.readEntry("Plugins", KIO::PreviewJob::defaultPlugins()); | ||
170 | 181 | | |||
171 | const qulonglong defaultRemotePreview = static_cast<qulonglong>(MaxRemotePreviewSize) * 1024 * 1024; | 182 | const qulonglong defaultRemotePreview = static_cast<qulonglong>(MaxRemotePreviewSize) * 1024 * 1024; | ||
172 | const qulonglong maxRemoteByteSize = globalConfig.readEntry("MaximumRemoteSize", defaultRemotePreview); | 183 | const qulonglong maxRemoteByteSize = globalConfig.readEntry("MaximumRemoteSize", defaultRemotePreview); | ||
173 | const int maxRemoteMByteSize = maxRemoteByteSize / (1024 * 1024); | 184 | const int maxRemoteMByteSize = maxRemoteByteSize / (1024 * 1024); | ||
174 | m_remoteFileSizeBox->setValue(maxRemoteMByteSize); | 185 | m_remoteFileSizeBox->setValue(maxRemoteMByteSize); | ||
186 | | ||||
187 | m_autoPlayMediaFiles->setChecked(GeneralSettings::autoPlayMediaFiles()); | ||||
175 | } | 188 | } | ||
176 | 189 | |