-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathConfigureDesktopDialog.cxx
164 lines (134 loc) · 5.71 KB
/
ConfigureDesktopDialog.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
This file is part of liquidshell.
SPDX-FileCopyrightText: 2017 - 2024 Martin Koller <kollix@aon.at>
SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <ConfigureDesktopDialog.hxx>
#include <QStandardPaths>
#include <QMimeDatabase>
#include <QImageReader>
#include <QApplication>
#include <QScreen>
#include <QDebug>
#include <KNSWidgets/Dialog>
//--------------------------------------------------------------------------------
ConfigureDesktopDialog::ConfigureDesktopDialog(QWidget *parent, const DesktopWidget::Wallpaper &wp)
: QDialog(parent), wallpaper(wp)
{
ui.setupUi(this);
ui.iconView->setIconSize(QSize(200, 200));
connect(ui.iconView, &QListWidget::itemClicked,
[this](QListWidgetItem *item)
{
ui.kurlrequester->setUrl(QUrl::fromLocalFile(item->data(Qt::UserRole).toString()));
wallpaper.fileName = ui.kurlrequester->url().toLocalFile();
emit changed();
});
showImages();
QPushButton *newstuff = ui.buttonBox->addButton(i18n("Get New Wallpapers..."), QDialogButtonBox::ActionRole);
newstuff->setIcon(QIcon::fromTheme("get-hot-new-stuff"));
connect(newstuff, &QPushButton::clicked,
[this]()
{
KNSWidgets::Dialog dialog("wallpaper.knsrc", this);
dialog.setWindowTitle(i18n("Download Wallpapers"));
dialog.exec();
if ( dialog.changedEntries().count() )
showImages();
});
ui.kcolorcombo->setColor(wallpaper.color);
ui.kurlrequester->setUrl(QUrl::fromLocalFile(wallpaper.fileName));
connect(ui.kcolorcombo, &KColorCombo::activated,
[this](const QColor &col) { wallpaper.color = col; emit changed(); });
connect(ui.kurlrequester, &KUrlRequester::urlSelected,
[this](const QUrl &url) { wallpaper.fileName = url.toLocalFile(); emit changed(); });
connect(ui.kurlrequester, &KUrlRequester::returnPressed,
[this](const QString &text) { wallpaper.fileName = text; emit changed(); });
if ( wallpaper.mode == "Scaled" )
ui.scaledIgnoreRatioButton->setChecked(true);
else if ( wallpaper.mode == "ScaledKeepRatio" )
ui.scaledKeepRatioButton->setChecked(true);
else if ( wallpaper.mode == "ScaledKeepRatioExpand" )
ui.scaledKeepRatioClipButton->setChecked(true);
else
ui.origSizeButton->setChecked(true);
buttonGroup.addButton(ui.origSizeButton);
buttonGroup.addButton(ui.scaledIgnoreRatioButton);
buttonGroup.addButton(ui.scaledKeepRatioButton);
buttonGroup.addButton(ui.scaledKeepRatioClipButton);
connect(&buttonGroup, SIGNAL(buttonClicked(QAbstractButton *)),
this, SLOT(buttonClicked(QAbstractButton *)));
}
//--------------------------------------------------------------------------------
void ConfigureDesktopDialog::returnPressed(const QString &text)
{
wallpaper.fileName = text;
emit changed();
}
//--------------------------------------------------------------------------------
void ConfigureDesktopDialog::buttonClicked(QAbstractButton *button)
{
if ( button == ui.origSizeButton )
wallpaper.mode = "";
else if ( button == ui.scaledIgnoreRatioButton )
wallpaper.mode = "Scaled";
else if ( button == ui.scaledKeepRatioButton )
wallpaper.mode = "ScaledKeepRatio";
else if ( button == ui.scaledKeepRatioClipButton )
wallpaper.mode = "ScaledKeepRatioExpand";
emit changed();
}
//--------------------------------------------------------------------------------
void ConfigureDesktopDialog::showImages()
{
// create filter (list of patterns) for image files we can read
QMimeDatabase db;
QStringList filterList;
foreach (const QByteArray &type, QImageReader::supportedMimeTypes())
{
QMimeType mime(db.mimeTypeForName(QString::fromLatin1(type)));
if ( mime.isValid() )
{
foreach (const QString &pattern, mime.globPatterns())
filterList << pattern;
}
}
ui.iconView->clear();
QStringList dirNames = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation,
"wallpapers", QStandardPaths::LocateDirectory);
const QString geometryString = QString("%1x%2")
.arg(QApplication::primaryScreen()->size().width())
.arg(QApplication::primaryScreen()->size().height());
for (const QString &dirName : dirNames)
{
// check for file directly in this folder
QStringList fileNames = QDir(dirName).entryList(filterList, QDir::Files | QDir::Readable);
for (const QString &fileName : fileNames)
{
QPixmap pixmap(dirName + '/' + fileName);
QListWidgetItem *item = new QListWidgetItem(pixmap, fileName, ui.iconView);
item->setData(Qt::UserRole, dirName + '/' + fileName);
item->setToolTip(QString("%1 (%2x%3)").arg(fileName).arg(pixmap.width()).arg(pixmap.height()));
}
// check for files in the special subdirs
for (const QString &subdir : QDir(dirName).entryList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::Readable))
{
QDir dir(dirName + '/' + subdir + "/contents/images");
QString chosenFilePath;
for (const QString &fileName : dir.entryList(filterList, QDir::Files | QDir::Readable))
{
chosenFilePath = dir.absoluteFilePath(fileName);
if ( fileName.startsWith(geometryString) )
break; // just take one
}
if ( !chosenFilePath.isEmpty() )
{
QPixmap pixmap(chosenFilePath);
QListWidgetItem *item = new QListWidgetItem(pixmap, subdir, ui.iconView);
item->setData(Qt::UserRole, chosenFilePath);
item->setToolTip(QString("%1 (%2x%3)").arg(subdir).arg(pixmap.width()).arg(pixmap.height()));
}
}
}
}
//--------------------------------------------------------------------------------