Skip to content

Commit 9d1a581

Browse files
committed
Create appearance.{ui,h,cpp}
1 parent 325b661 commit 9d1a581

File tree

13 files changed

+451
-345
lines changed

13 files changed

+451
-345
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ set(PROJECT_SOURCES
4545
src/settings.h
4646
src/xml.cpp
4747
src/xml.h
48+
src/appearance.cpp
49+
src/appearance.h
50+
src/appearance.ui
51+
src/find-themes.cpp
52+
src/find-themes.h
4853
)
4954
set(PROJECT_OTHER_FILES
5055
.github/workflows/build.yml

src/appearance.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include "appearance.h"
2+
#include "find-themes.h"
3+
#include "macros.h"
4+
#include "settings.h"
5+
#include "./ui_appearance.h"
6+
7+
Appearance::Appearance(QWidget *parent) : QWidget(parent), ui(new Ui::pageAppearance)
8+
{
9+
ui->setupUi(this);
10+
}
11+
12+
Appearance::~Appearance()
13+
{
14+
delete ui;
15+
}
16+
17+
void Appearance::activate()
18+
{
19+
/* # APPEARANCE */
20+
21+
/* Labwc Theme */
22+
QStringList labwcThemes = findLabwcThemes();
23+
ui->openboxTheme->addItems(labwcThemes);
24+
ui->openboxTheme->setCurrentIndex(labwcThemes.indexOf(getStr("/labwc_config/theme/name")));
25+
26+
/* Corner Radius */
27+
ui->cornerRadius->setValue(getInt("/labwc_config/theme/cornerRadius"));
28+
29+
/* Drop Shadows */
30+
ui->dropShadows->addItem("no");
31+
ui->dropShadows->addItem("yes");
32+
ui->dropShadows->setCurrentIndex(getBool("/labwc_config/theme/dropShadows"));
33+
34+
/* Icon Theme */
35+
QStringList themes = findIconThemes(LAB_ICON_THEME_TYPE_ICON);
36+
ui->iconTheme->addItems(themes);
37+
ui->iconTheme->setCurrentIndex(themes.indexOf(getStr("/labwc_config/theme/icon")));
38+
}
39+
40+
void Appearance::onApply()
41+
{
42+
setInt("/labwc_config/theme/cornerRadius", ui->cornerRadius->value());
43+
setStr("/labwc_config/theme/name", TEXT(ui->openboxTheme));
44+
setBool("/labwc_config/theme/dropShadows", TEXT(ui->dropShadows));
45+
setStr("/labwc_config/theme/icon", TEXT(ui->iconTheme));
46+
}

src/appearance.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef APPEARANCE_H
2+
#define APPEARANCE_H
3+
#include <QWidget>
4+
5+
QT_BEGIN_NAMESPACE
6+
namespace Ui {
7+
class pageAppearance;
8+
}
9+
QT_END_NAMESPACE
10+
11+
class Appearance : public QWidget
12+
{
13+
Q_OBJECT
14+
15+
public:
16+
Appearance(QWidget *parent = nullptr);
17+
~Appearance();
18+
19+
void activate();
20+
void onApply();
21+
22+
private:
23+
Ui::pageAppearance *ui;
24+
};
25+
#endif // APPEARANCE_H

src/appearance.ui

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>pageAppearance</class>
4+
<widget class="QWidget" name="pageAppearance">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>232</width>
10+
<height>153</height>
11+
</rect>
12+
</property>
13+
<layout class="QFormLayout" name="layPage1">
14+
<property name="leftMargin">
15+
<number>6</number>
16+
</property>
17+
<property name="topMargin">
18+
<number>6</number>
19+
</property>
20+
<property name="rightMargin">
21+
<number>6</number>
22+
</property>
23+
<property name="bottomMargin">
24+
<number>6</number>
25+
</property>
26+
<item row="0" column="0">
27+
<widget class="QLabel" name="label">
28+
<property name="text">
29+
<string>Labwc Theme</string>
30+
</property>
31+
</widget>
32+
</item>
33+
<item row="0" column="1">
34+
<widget class="QComboBox" name="openboxTheme"/>
35+
</item>
36+
<item row="1" column="0">
37+
<widget class="QLabel" name="label_2">
38+
<property name="text">
39+
<string>Corner Radius</string>
40+
</property>
41+
</widget>
42+
</item>
43+
<item row="1" column="1">
44+
<widget class="QSpinBox" name="cornerRadius"/>
45+
</item>
46+
<item row="2" column="0">
47+
<widget class="QLabel" name="label_8">
48+
<property name="text">
49+
<string>Drop Shadows</string>
50+
</property>
51+
</widget>
52+
</item>
53+
<item row="2" column="1">
54+
<widget class="QComboBox" name="dropShadows"/>
55+
</item>
56+
<item row="3" column="0">
57+
<widget class="QLabel" name="label_1">
58+
<property name="text">
59+
<string>Icon Theme</string>
60+
</property>
61+
</widget>
62+
</item>
63+
<item row="3" column="1">
64+
<widget class="QComboBox" name="iconTheme"/>
65+
</item>
66+
</layout>
67+
</widget>
68+
<resources/>
69+
<connections/>
70+
</ui>

src/find-themes.cpp

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#include <QDir>
2+
#include <QString>
3+
#include <QStandardPaths>
4+
#include "find-themes.h"
5+
#include "log.h"
6+
7+
static bool hasOnlyCursorSubdir(QString path)
8+
{
9+
QStringList entries = QDir(path).entryList(QDir::Dirs | QDir::NoDotAndDotDot);
10+
return entries.contains("cursors") && entries.length() == 1;
11+
}
12+
13+
static bool hasCursorSubdir(QString path)
14+
{
15+
QStringList entries = QDir(path).entryList(QDir::Dirs | QDir::NoDotAndDotDot);
16+
return entries.contains("cursors");
17+
}
18+
19+
QStringList findIconThemes(enum lab_icon_theme_type type)
20+
{
21+
QStringList paths;
22+
23+
// Setup paths including
24+
// - $HOME/.icons
25+
// - $XDG_DATA_HOME/icons
26+
// - $XDG_DATA_DIRS/icons
27+
paths.push_back(QString(qgetenv("HOME") + "/.icons"));
28+
QStringList standardPaths =
29+
QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
30+
for (const QString &path : std::as_const(standardPaths)) {
31+
paths.push_back(QString(path + "/icons"));
32+
}
33+
34+
// Iterate over paths and use any icon-theme which has more than just a
35+
// "cursors" subdirectory (because that means it's for cursors only)
36+
QStringList themes;
37+
themes.push_front("");
38+
themes.push_front("Adwaita");
39+
for (const QString &path : std::as_const(paths)) {
40+
QDir dir(path);
41+
QStringList entries = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
42+
for (const QString &entry : std::as_const(entries)) {
43+
switch (type) {
44+
case LAB_ICON_THEME_TYPE_ICON:
45+
if (hasOnlyCursorSubdir(QString(path + "/" + entry))) {
46+
continue;
47+
}
48+
themes.push_back(entry);
49+
break;
50+
case LAB_ICON_THEME_TYPE_CURSOR:
51+
if (hasCursorSubdir(QString(path + "/" + entry))) {
52+
themes.push_back(entry);
53+
}
54+
break;
55+
default:
56+
break;
57+
}
58+
}
59+
}
60+
themes.removeDuplicates();
61+
themes.sort(Qt::CaseInsensitive);
62+
return themes;
63+
}
64+
65+
static bool hasOpenboxOrLabwcSubdir(QString path)
66+
{
67+
QStringList entries = QDir(path).entryList(QDir::Dirs | QDir::NoDotAndDotDot);
68+
return entries.contains("openbox-3") || entries.contains("labwc");
69+
}
70+
71+
QStringList findLabwcThemes(void)
72+
{
73+
QStringList paths;
74+
75+
paths.push_back(QString(qgetenv("HOME") + "/.themes"));
76+
QStringList standardPaths =
77+
QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
78+
for (const QString &path : std::as_const(standardPaths)) {
79+
paths.push_back(QString(path + "/themes"));
80+
}
81+
82+
QStringList themes;
83+
themes.push_front("Adwaita");
84+
for (const QString &path : std::as_const(paths)) {
85+
QDir dir(path);
86+
QStringList entries = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
87+
for (const QString &entry : std::as_const(entries)) {
88+
if (hasOpenboxOrLabwcSubdir(QString(path + "/" + entry))) {
89+
themes.push_back(entry);
90+
}
91+
}
92+
}
93+
themes.removeDuplicates();
94+
themes.sort(Qt::CaseInsensitive);
95+
return themes;
96+
}

src/find-themes.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef FIND_THEMES_H
2+
#define FIND_THEMES_H
3+
4+
enum lab_icon_theme_type {
5+
LAB_ICON_THEME_TYPE_NONE = 0,
6+
LAB_ICON_THEME_TYPE_ICON,
7+
LAB_ICON_THEME_TYPE_CURSOR,
8+
};
9+
10+
QStringList findIconThemes(enum lab_icon_theme_type type);
11+
QStringList findLabwcThemes(void);
12+
13+
#endif // FIND_THEMES_H

src/macros.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef MACROS_H
2+
#define MACROS_H
3+
4+
#define TEXT(widget) widget->currentText().toLatin1().data()
5+
6+
#endif // MACROS_H

src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ int main(int argc, char *argv[])
8787
// The 'settings' vector contains the master state of all settings that can
8888
// be changed by labwc-tweaks.
8989
std::vector<std::shared_ptr<Setting>> settings;
90-
initSettings(settings);
90+
initSettings(&settings);
9191

92-
MainDialog window(settings);
92+
MainDialog window;
9393
window.show();
9494

9595
// Make work the window icon also when the application is not (yet) installed

0 commit comments

Comments
 (0)