Skip to content

Commit

Permalink
Save gtk3 configuration to dconf as well
Browse files Browse the repository at this point in the history
Summary:
Currently all gtk3 configuration is stored to a config file in ini format, while
this configuration is still used and supported, it is not used by applications
running under flatpak. To have this configuration available to sandboxed applications
we have to use dconf, which is exposed to flatpak applications.

BUG: 387417

Reviewers: apol

Reviewed By: apol

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D9163
  • Loading branch information
grulja committed Dec 11, 2017
1 parent e941ddf commit 8704096
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 17 deletions.
23 changes: 13 additions & 10 deletions CMakeLists.txt
Expand Up @@ -8,11 +8,14 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" ${ECM_MODULE_P
find_package(Qt5 REQUIRED NO_MODULE COMPONENTS Widgets Test)
find_package(KF5 REQUIRED COMPONENTS I18n KIO ConfigWidgets NewStuff Archive KCMUtils IconThemes)
find_package(X11 REQUIRED)
find_package(GTK3 REQUIRED)
find_package(GSettingSchemas REQUIRED)

include_directories(
${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/src/ui
${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/src/ui
${GTK3_INCLUDE_DIRS}
)

include(ECMSetupVersion)
Expand All @@ -37,21 +40,21 @@ set(kcm_SRCS
src/appearencegtk.cpp
src/abstractappearance.cpp
src/thread.cpp
src/installer.cpp
src/installer.cpp
src/gtkconfigkcmodule.cpp
src/dialog_installer.cpp
src/dialog_uninstaller.cpp
src/dialog_installer.cpp
src/dialog_uninstaller.cpp
src/fontshelpers.cpp
)

ki18n_wrap_ui(kcm_SRCS
src/ui/gui.ui
src/ui/dialog_installer.ui
ki18n_wrap_ui(kcm_SRCS
src/ui/gui.ui
src/ui/dialog_installer.ui
src/ui/dialog_uninstaller.ui
)
add_library(kcm_kdegtkconfig MODULE ${kcm_SRCS})
target_compile_definitions(kcm_kdegtkconfig PRIVATE -DPROJECT_VERSION="${PROJECT_VERSION}")
target_link_libraries(kcm_kdegtkconfig ${X11_Xcursor_LIB} KF5::ConfigCore KF5::I18n KF5::KIOWidgets KF5::NewStuff KF5::Archive KF5::NewStuff KF5::ConfigWidgets KF5::IconThemes)
target_link_libraries(kcm_kdegtkconfig ${X11_Xcursor_LIB} ${GIO2_LIBRARY} ${GLIB2_LIBRARY} ${GTK3_LIBRARY} ${GOBJECT2_LIBRARY} KF5::ConfigCore KF5::I18n KF5::KIOWidgets KF5::NewStuff KF5::Archive KF5::NewStuff KF5::ConfigWidgets KF5::IconThemes)

kcoreaddons_desktop_to_json(kcm_kdegtkconfig kde-gtk-config.desktop)

Expand Down
23 changes: 23 additions & 0 deletions cmake/modules/FindGSettingSchemas.cmake
@@ -0,0 +1,23 @@
find_package(PkgConfig)

pkg_check_modules(PC_GLIB2 REQUIRED glib-2.0)

find_path(GLIB_SCHEMAS_DIR org.gnome.desktop.interface.gschema.xml
HINTS ${PC_GLIB2_PREFIX}/share
PATH_SUFFIXES glib-2.0/schemas)

if (GLIB_SCHEMAS_DIR)
set(GSettingSchemas_FOUND true)
else()
set(GSettingSchemas_FOUND false)
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GSettingSchemas
FOUND_VAR
GSettingSchemas_FOUND
REQUIRED_VARS
GSettingSchemas_FOUND
)

mark_as_advanced(GSettingSchemas_FOUND)
28 changes: 26 additions & 2 deletions cmake/modules/FindGTK3.cmake
Expand Up @@ -35,7 +35,7 @@ FIND_PATH(
GLIB2_INCLUDE_DIR_PART1 glib.h
HINTS ${PC_GLIB2_INCLUDEDIR} ${PC_GLIB2_INCLUDE_DIRS}
PATH_SUFFIXES glib-2.0)

FIND_PATH(
GLIB2_INCLUDE_DIR_PART2 glibconfig.h
HINTS ${PC_GLIB2_INCLUDEDIR} ${PC_GLIB2_INCLUDE_DIRS}
Expand All @@ -58,7 +58,7 @@ FIND_PATH(
GOBJECT2_INCLUDE_DIR_PART1 glib.h
HINTS ${PC_GOBJECT2_INCLUDEDIR} ${PC_GOBJECT2_INCLUDE_DIRS}
PATH_SUFFIXES gobject-2.0)

FIND_PATH(
GOBJECT2_INCLUDE_DIR_PART2 gobject.h
HINTS ${PC_GOBJECT2_INCLUDEDIR} ${PC_GOBJECT2_INCLUDE_DIRS}
Expand All @@ -70,6 +70,30 @@ FIND_LIBRARY(
GOBJECT2_LIBRARY NAMES gobject-2.0
HINTS ${PC_GOBJECT2_LIBDIR} ${PC_GOBJECT2_LIBRARY_DIRS})

#
# gio
#
PKG_CHECK_MODULES(PC_GIO2 REQUIRED gio-2.0)

SET(GLIB2_DEFINITIONS ${PC_GIO2_CXXFLAGS_OTHER})

FIND_PATH(
GIO2_INCLUDE_DIR_PART1 gio.h
HINTS ${PC_GIO2_INCLUDEDIR} ${PC_GIO2_INCLUDE_DIRS}
PATH_SUFFIXES gio)

FIND_PATH(
GIO2_INCLUDE_DIR_PART2 gobject.h
HINTS ${PC_GIO2_INCLUDEDIR} ${PC_GIO2_INCLUDE_DIRS}
PATH_SUFFIXES glib-2.0/gio)

SET(GIO2_INCLUDE_DIR ${GIO2_INCLUDE_DIR_PART1} ${GIO2_INCLUDE_DIR_PART2})

FIND_LIBRARY(
GIO2_LIBRARY NAMES gio-2.0
HINTS ${PC_GIO2_LIBDIR} ${PC_GIO2_LIBRARY_DIRS})


#
# pango
#
Expand Down
42 changes: 37 additions & 5 deletions src/appearancegtk3.cpp
@@ -1,5 +1,5 @@
/* KDE GTK Configuration Module
*
*
* Copyright 2011 José Antonio Sanchez Reynaga <joanzare@gmail.com>
* Copyright 2011 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
*
Expand All @@ -10,13 +10,13 @@
* later version accepted by the membership of KDE e.V. (or its
* successor approved by the membership of KDE e.V.), which shall
* act as a proxy defined in Section 6 of version 3 of the license.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/

Expand All @@ -28,6 +28,11 @@
#include <KSharedConfig>
#include <KConfigGroup>

#undef signals
#include <gio/gio.h>
#include <gtk/gtk.h>
#define signals Q_SIGNALS

QStringList AppearanceGTK3::installedThemes() const
{
QFileInfoList availableThemes;
Expand Down Expand Up @@ -119,7 +124,7 @@ QString AppearanceGTK3::defaultConfigFile() const
QString root = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation);
if(root.isEmpty())
root = QFileInfo(QDir::home(), ".config").absoluteFilePath();

return root + '/' + configFileName();
}

Expand Down Expand Up @@ -153,6 +158,33 @@ bool AppearanceGTK3::loadSettings()

bool AppearanceGTK3::saveSettings() const
{
// FIXME kdebz#387417
// We should maybe use GSettings everywhere in future, but at this moment we
// need this to have this configuration available in sandboxed applications which
// is only possible through dconf
gtk_init(nullptr, nullptr);

g_autoptr(GSettings) gsettings = g_settings_new("org.gnome.desktop.interface");
g_settings_set_string(gsettings, "gtk-theme", m_settings["theme"].toUtf8().constData());
g_settings_set_string(gsettings, "icon-theme", m_settings["icon"].toUtf8().constData());
g_settings_set_string(gsettings, "cursor-theme", m_settings["cursor"].toUtf8().constData());
g_settings_set_string(gsettings, "font-name", m_settings["font"].toUtf8().constData());

QString toolbarStyle;
if (m_settings["toolbar_style"] == QStringLiteral("GTK_TOOLBAR_ICONS")) {
toolbarStyle = QStringLiteral("icons");
} else if (m_settings["toolbar_style"] == QStringLiteral("GTK_TOOLBAR_TEXT")) {
toolbarStyle = QStringLiteral("text");
} else if (m_settings["toolbar_style"] == QStringLiteral("GTK_TOOLBAR_BOTH")) {
toolbarStyle = QStringLiteral("both");
} else if (m_settings["toolbar_style"] == QStringLiteral("GTK_TOOLBAR_BOTH_HORIZ")) {
toolbarStyle = QStringLiteral("both-horiz");
}

g_settings_set_string(gsettings, "toolbar-style", toolbarStyle.toUtf8().constData());

g_object_set(gtk_settings_get_default(), "gtk-application-prefer-dark-theme", getApplicationPreferDarkTheme(), nullptr);

auto cfg = KSharedConfig::openConfig(configFileName(), KConfig::NoGlobals);
return saveSettings(cfg);
}

0 comments on commit 8704096

Please sign in to comment.