Skip to content

Minor house keeping #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ QString environment_get(const char *key)
continue;
}
if (elements[0].trimmed() == QString(key)) {
qDebug() << "fount it!" << elements;
return elements[1].trimmed();
}
}
Expand Down
1 change: 0 additions & 1 deletion src/layoutmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ char *LayoutModel::getXkbDefaultLayout()
ret += ",";
}
}
qDebug() << ret;
return ret.toLatin1().data();
}

Expand Down
13 changes: 7 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
#include <QLibraryInfo>
#include <QTranslator>

static void initLocale(QTranslator* qtTranslator, QTranslator* translator)
static void initLocale(QTranslator *qtTranslator, QTranslator *translator)
{
QApplication* app = qApp;
QApplication *app = qApp;
#if PROJECT_TRANSLATION_TEST_ENABLED
QLocale locale(QLocale(PROJECT_TRANSLATION_TEST_LANGUAGE));
QLocale::setDefault(locale);
#else
QLocale locale = QLocale::system();
#endif
// Qt translations (buttons text and the like)
QString translationsPath = QLibraryInfo::path(QLibraryInfo::TranslationsPath);
QString translationsPath = QLibraryInfo::path(QLibraryInfo::TranslationsPath);
QString translationsFileName = QStringLiteral("qt_") + locale.name();

if (qtTranslator->load(translationsFileName, translationsPath))
Expand All @@ -30,7 +30,8 @@ static void initLocale(QTranslator* qtTranslator, QTranslator* translator)
if (!isLoaded) {
// "/usr/share/<appname>/translations
isLoaded = translator->load(translationsFileName,
QStringLiteral(PROJECT_DATA_DIR) + QStringLiteral("/translations"));
QStringLiteral(PROJECT_DATA_DIR)
+ QStringLiteral("/translations"));
}
app->installTranslator(translator);
}
Expand All @@ -47,9 +48,9 @@ int main(int argc, char *argv[])
w.show();

// Make work the window icon also when the application is not (yet) installed
QString iconSuffix = QString("%1%2%3").arg("/", PROJECT_APPSTREAM_ID, QStringLiteral(".svg"));
QString iconSuffix = QString("%1%2%3").arg("/", PROJECT_APPSTREAM_ID, QStringLiteral(".svg"));
QString icoLocalPath = QCoreApplication::applicationDirPath() + iconSuffix;
QString icoSysPath = QStringLiteral(PROJECT_ICON_SYSTEM_PATH) + iconSuffix;
QString icoSysPath = QStringLiteral(PROJECT_ICON_SYSTEM_PATH) + iconSuffix;

QIcon appIcon = QIcon(icoLocalPath);
if (appIcon.isNull())
Expand Down
28 changes: 21 additions & 7 deletions src/maindialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ MainDialog::MainDialog(QWidget *parent) : QDialog(parent), ui(new Ui::MainDialog
m_model = new LayoutModel(this);
ui->layoutView->setModel(m_model);

std::string config_dir = std::getenv("LABWC_CONFIG_DIR") ?: "/.config/labwc";
std::string config_file = std::getenv("HOME") + config_dir + "/rc.xml";
xml_init(config_file.data());
xml_setup_nodes();
std::string config_dir =
std::getenv("LABWC_CONFIG_DIR") ?: std::getenv("HOME") + std::string("/.config/labwc");
std::string config_file = config_dir + "/rc.xml";
initConfig(config_file);

QObject::connect(ui->buttonBox, &QDialogButtonBox::clicked, [&] (QAbstractButton *button) {
QObject::connect(ui->buttonBox, &QDialogButtonBox::clicked, [&](QAbstractButton *button) {
if (ui->buttonBox->standardButton(button) == QDialogButtonBox::Apply) {
onApply();
}
Expand Down Expand Up @@ -89,12 +89,12 @@ void MainDialog::activate()
ui->dropShadows->setCurrentIndex(xml_get_bool_text("/labwc_config/theme/dropShadows"));

/* # BEHAVIOUR */
std::vector policies = { "", "center", "automatic", "cursor" };
std::vector policies = { "", "Center", "Automatic", "Cursor" };
active = -1;
active_id = xml_get("/labwc_config/placement/policy");
int i = 0;
for (auto policy : policies) {
if (active_id && !strcmp(policy, active_id)) {
if (active_id && !strcasecmp(policy, active_id)) {
active = i;
}
ui->placementPolicy->addItem(policy);
Expand Down Expand Up @@ -141,6 +141,20 @@ void MainDialog::activate()
}
}

void MainDialog::initConfig(std::string &config_file)
{
xml_init(config_file.data());

/* Ensure all relevant nodes exist before we start getting/setting */
xpath_add_node("/labwc_config/theme/cornerRadius");
xpath_add_node("/labwc_config/theme/name");
xpath_add_node("/labwc_config/theme/dropShadows");
xpath_add_node("/labwc_config/placement/policy");
xpath_add_node("/labwc_config/libinput/device/naturalScroll");

xml_save();
}

void MainDialog::onApply()
{
/* ~/.config/labwc/rc.xml */
Expand Down
2 changes: 2 additions & 0 deletions src/maindialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ private slots:

private:
LayoutModel *m_model;

void initConfig(std::string &config_file);
void onApply();

Ui::MainDialog *ui;
Expand Down
18 changes: 3 additions & 15 deletions src/xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,24 +136,12 @@ create_basic_rcxml(const char *filename)
fprintf(stderr, "warn: fopen(%s) failed\n", filename);
return;
}
if (!fwrite(rcxml_template, sizeof(rcxml_template), 1, file)) {
if (!fwrite(rcxml_template, sizeof(rcxml_template)-1, 1, file)) {
fprintf(stderr, "warn: error writing to %s", filename);
}
fclose(file);
}

void
xml_setup_nodes(void)
{
/* Ensure all relevant nodes exist before we start getting/setting */
xpath_add_node("/labwc_config/theme/cornerRadius");
xpath_add_node("/labwc_config/theme/name");
xpath_add_node("/labwc_config/theme/dropShadows");
xpath_add_node("/labwc_config/placement/policy");
xpath_add_node("/labwc_config/libinput/device/naturalScroll");
xml_save();
}

void
xml_init(const char *filename)
{
Expand Down Expand Up @@ -255,7 +243,7 @@ xml_get_bool_text(const char *nodename)

/* case-insensitive */
static xmlNode *
xml_get_node(char *nodename)
xml_get_node(const char *nodename)
{
ctx.node = NULL;
ctx.nodename = nodename;
Expand Down Expand Up @@ -326,7 +314,7 @@ xpath_get_node(xmlChar *expr)
}

void
xpath_add_node(char *xpath_expr)
xpath_add_node(const char *xpath_expr)
{
if (xml_get_node(xpath_expr)) {
return;
Expand Down
3 changes: 1 addition & 2 deletions src/xml.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#ifndef __XML_H
#define __XML_H

void xml_setup_nodes(void);
void xml_init(const char *filename);
void xml_save(void);
void xml_save_as(const char *filename);
Expand All @@ -25,6 +24,6 @@ char *xpath_get_content(const char *xpath_expr);
* For example xpath_expr="/labwc_config/a/b/c" creates
* <labwc_config><a><b><c /></b></a></labwc_config>
*/
void xpath_add_node(char *xpath_expr);
void xpath_add_node(const char *xpath_expr);

#endif /* __XML_H */