Adding upstream version 0.9.0.

Signed-off-by: Andrew Lee's avatarAndrew Lee (李健秋) <ajqlee@debian.org>
parents
Copyright:
Copyright (c) 2012-2014 LXQt team
This program is based on source code from the ObConf project
<http://openbox.org/wiki/ObConf:About>
Original authors of obconf and copyright notice:
Copyright (c) 2003-2007 Dana Jansens <danakj@orodu.net>
Copyright (c) 2003 Tim Riley <tr@slackzone.org>
Copyright (c) 2007 Javeed Shaikh <syscrash2k@gmail.com>
License: GNU GPL-2
The full text of the licenses can be found in the 'COPYING' file.
project(obconf-qt)
# newer cmake is required for CMAKE_AUTOMOC Qt support
cmake_minimum_required(VERSION 2.8.6)
find_program(SED_PROGRAM sed)
# additional cmake files
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# Support Qt5
option(USE_QT5 "Build with Qt5." $ENV{USE_QT5})
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_AUTOMOC ON)
if(USE_QT5)
cmake_minimum_required(VERSION 2.8.11)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5X11Extras REQUIRED)
find_package(Qt5LinguistTools REQUIRED QUIET)
message(STATUS "Building with Qt${Qt5Core_VERSION_STRING}")
else()
find_package(Qt4 REQUIRED QtCore QtGui) # Qt
include(${QT_USE_FILE})
message(STATUS "Building with Qt${QTVERSION}")
endif()
find_package(PkgConfig)
pkg_check_modules(GLIB REQUIRED
glib-2.0
)
pkg_check_modules(OPENBOX REQUIRED
obrender-3.5
obt-3.5
)
# add src subdirectory
add_subdirectory(src)
# install an icon for the application
install(
FILES data/obconf-qt.png
DESTINATION share/icons/hicolor/48x48/apps
)
# building tarball with CPack -------------------------------------------------
# To create a source distribution, type:
# make package_source
include (InstallRequiredSystemLibraries)
set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING")
set (CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README")
set (CPACK_PACKAGE_VENDOR "")
set (CPACK_PACKAGE_VERSION_MAJOR "0")
set (CPACK_PACKAGE_VERSION_MINOR "1")
set (CPACK_PACKAGE_VERSION_PATCH "0")
set (CPACK_GENERATOR TBZ2)
set (CPACK_SOURCE_GENERATOR TBZ2)
set (CPACK_SOURCE_IGNORE_FILES /build/;.gitignore;.*~;.git;.kdev4;temp)
# set (CPACK_SOURCE_PACKAGE_FILE_NAME pcmanfm-qt.0.1.0.tar.gz)
include (CPack)
This diff is collapsed.
This is a Qt port of ObConf, configurator of OpenBox window manager.
#=============================================================================
# The lxqt_translate_desktop() function was copied from the the
# LXQt LxQtTranste.cmake
#
# Original Author: Alexander Sokolov <sokoloff.a@gmail.com>
#
# funtion lxqt_translate_desktop(_RESULT
# SOURCES <sources>
# [TRANSLATION_DIR] translation_directory
# )
# Output:
# _RESULT The generated .desktop (.desktop) files
#
# Input:
#
# SOURCES List of input desktop files (.destktop.in) to be translated
# (merged), relative to the CMakeList.txt.
#
# TRANSLATION_DIR Optional path to the directory with the .ts files,
# relative to the CMakeList.txt. Defaults to
# "translations".
#
#=============================================================================
function(lxqt_translate_desktop _RESULT)
# Parse arguments ***************************************
set(oneValueArgs TRANSLATION_DIR)
set(multiValueArgs SOURCES)
cmake_parse_arguments(_ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
# check for unknown arguments
set(_UNPARSED_ARGS ${_ARGS_UNPARSED_ARGUMENTS})
if (NOT ${_UNPARSED_ARGS} STREQUAL "")
MESSAGE(FATAL_ERROR
"Unknown arguments '${_UNPARSED_ARGS}'.\n"
"See lxqt_translate_desktop() documenation for more information.\n"
)
endif()
if (NOT DEFINED _ARGS_SOURCES)
set(${_RESULT} "" PARENT_SCOPE)
return()
else()
set(_sources ${_ARGS_SOURCES})
endif()
if (NOT DEFINED _ARGS_TRANSLATION_DIR)
set(_translationDir "translations")
else()
set(_translationDir ${_ARGS_TRANSLATION_DIR})
endif()
get_filename_component (_translationDir ${_translationDir} ABSOLUTE)
foreach (_inFile ${_sources})
get_filename_component(_inFile ${_inFile} ABSOLUTE)
get_filename_component(_fileName ${_inFile} NAME_WE)
#Extract the real extension ............
get_filename_component(_fileExt ${_inFile} EXT)
string(REPLACE ".in" "" _fileExt ${_fileExt})
#.......................................
set(_outFile "${CMAKE_CURRENT_BINARY_DIR}/${_fileName}${_fileExt}")
file(GLOB _translations
${_translationDir}/${_fileName}_*${_fileExt}
${_translationDir}/local/${_fileName}_*${_fileExt}
)
set(_pattern "'\\[.*]\\s*='")
if (_translations)
add_custom_command(OUTPUT ${_outFile}
COMMAND grep -v "'#TRANSLATIONS_DIR='" ${_inFile} > ${_outFile}
COMMAND grep -h ${_pattern} ${_translations} >> ${_outFile}
COMMENT "Generating ${_fileName}${_fileExt}"
)
else()
add_custom_command(OUTPUT ${_outFile}
COMMAND grep -v "'#TRANSLATIONS_DIR='" ${_inFile} > ${_outFile}
COMMENT "Generating ${_fileName}${_fileExt}"
)
endif()
set(__result ${__result} ${_outFile})
# TX file ***********************************************
set(_txFile "${CMAKE_BINARY_DIR}/tx/${_fileName}${_fileExt}.tx.sh")
string(REPLACE "${CMAKE_SOURCE_DIR}/" "" _tx_translationDir ${_translationDir})
string(REPLACE "${CMAKE_SOURCE_DIR}/" "" _tx_inFile ${_inFile})
string(REPLACE "." "" _fileType ${_fileExt})
file(WRITE ${_txFile}
"[ -f ${_inFile} ] || exit 0\n"
"echo '[lxde-qt.${_fileName}_${_fileType}]'\n"
"echo 'type = DESKTOP'\n"
"echo 'source_lang = en'\n"
"echo 'source_file = ${_tx_inFile}'\n"
"echo 'file_filter = ${_tx_translationDir}/${_fileName}_<lang>${_fileExt}'\n"
"echo ''\n"
)
endforeach()
set(${_RESULT} ${__result} PARENT_SCOPE)
endfunction(lxqt_translate_desktop)
[Project]
Name=obconf-qt
Manager=KDevCMakeManager
VersionControl=
# set visibility to hidden to hide symbols, unlesss they're exporeted manually in the code
set(CMAKE_CXX_FLAGS "-DQT_NO_KEYWORDS -fno-exceptions")
if(USE_QT5)
set(QTX_INCLUDE_DIRS "")
set(QTX_LIBRARIES Qt5::Widgets Qt5::X11Extras)
else()
set(QTX_INCLUDE_DIRS ${QT_QTCORE_INCLUDE_DIR} ${QT_QTGUI_INCLUDE_DIR} ${QT_QTDBUS_DIR})
set(QTX_LIBRARIES ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTDBUS_LIBRARY})
endif()
include_directories(
${QTX_INCLUDE_DIRS}
${GLIB_INCLUDE_DIRS}
${OPENBOX_INCLUDE_DIRS}
${CMAKE_CURRENT_BINARY_DIR}
)
set(obconf-qt_SRCS
obconf-qt.cpp
maindialog.cpp
appearance.cpp
windows.cpp
mouse.cpp
moveresize.cpp
margins.cpp
desktops.cpp
dock.cpp
tree.cpp
archive.cpp
theme.cpp
fontbutton.cpp
)
set(obconf-qt_UIS
obconf.ui
)
if(USE_QT5)
qt5_wrap_ui(obconf-qt_UI_H ${obconf-qt_UIS})
else()
qt4_wrap_ui(obconf-qt_UI_H ${obconf-qt_UIS})
endif()
# The ui code generated by Qt uic contains QMetaObject::connectSlotsByName()
# but we don't want that. Fix it with sed.
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ui_obconf_fixed.h
COMMAND ${SED_PROGRAM}
ARGS "/connectSlotsByName/d" ${obconf-qt_UI_H} > ${CMAKE_CURRENT_BINARY_DIR}/ui_obconf_fixed.h
# DEPENDS
MAIN_DEPENDENCY ${obconf-qt_UI_H}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Fixing generated ui code"
VERBATIM
)
# add translation for obconf-qt
option (UPDATE_TRANSLATIONS "Update source translation translations/*.ts files" OFF)
set(TRANSLATION_TEMPLATE "translations/obconf-qt.ts")
file(GLOB TS_FILES translations/obconf-qt_*.ts)
if(USE_QT5)
if (UPDATE_TRANSLATIONS)
qt5_create_translation(QMS_FILES
${obconf-qt_SRCS}
${obconf-qt_UI_H}
${TRANSLATION_TEMPLATE}
OPTIONS -locations absolute)
qt5_create_translation(QM_FILES
${obconf-qt_SRCS}
${obconf-qt_UI_H}
${TS_FILES}
OPTIONS -locations absolute)
else (UPDATE_TRANSLATIONS)
qt5_add_translation(QM_FILES ${TS_FILES})
endif (UPDATE_TRANSLATIONS)
else(USE_QT5) # use qt4
if (UPDATE_TRANSLATIONS)
qt4_create_translation(QMS_FILES
${obconf-qt_SRCS}
${obconf-qt_UI_H}
${TRANSLATION_TEMPLATE}
OPTIONS -locations absolute)
qt4_create_translation(QMS_FILES
${obconf-qt_SRCS}
${obconf-qt_UI_H}
${TS_FILES}
OPTIONS -locations absolute)
else (UPDATE_TRANSLATIONS)
qt4_add_translation(QM_FILES ${TS_FILES})
endif (UPDATE_TRANSLATIONS)
endif(USE_QT5)
if(UPDATE_TRANSLATIONS)
add_custom_target(update_obconf-qt_translations ALL DEPENDS ${QMS})
endif()
# install a desktop entry file
include(LXQtTranslateDesktop)
lxqt_translate_desktop(DESKTOP_FILES
TRANSLATION_DIR "translations"
SOURCES obconf-qt.desktop.in
)
install(FILES ${DESKTOP_FILES} DESTINATION share/applications)
install(FILES ${QM_FILES} DESTINATION share/obconf-qt/translations)
# prevent the generated files from being deleted during make clean
set_directory_properties(PROPERTIES CLEAN_NO_CUSTOM true)
add_executable(obconf-qt
${obconf-qt_SRCS}
${obconf-qt_UI_H}
${QM_FILES}
${DESKTOP_FILES}
)
add_definitions(
-DPACKAGE_DATA_DIR="${CMAKE_INSTALL_PREFIX}/share/obconf-qt"
-DPIXMAPS_DIR="${CMAKE_INSTALL_PREFIX}/share/pixmaps"
-DTHEME_DIR="{CMAKE_INSTALL_PREFIX}/share/openbox/themes"
)
target_link_libraries(obconf-qt
${QTX_LIBRARIES}
${GLIB_LIBRARIES}
${OPENBOX_LIBRARIES}
)
install(TARGETS obconf-qt RUNTIME DESTINATION bin)
/*
Copyright (C) 2013 Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
Part of the code in this file is taken from obconf:
Copyright (c) 2003-2007 Dana Jansens
Copyright (c) 2003 Tim Riley
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "maindialog.h"
#include <obrender/render.h>
#include "tree.h"
#include <string.h>
using namespace Obconf;
extern RrInstance* rrinst; // defined in obconf-qt.cpp
static RrFont* read_font(Fm::FontButton* button, const gchar* place, gboolean def);
static RrFont* write_font(Fm::FontButton* button, const gchar* place);
void MainDialog::appearance_setup_tab() {
gchar* layout;
RrFont* f;
ui.window_border->setChecked(tree_get_bool("theme/keepBorder", TRUE));
ui.animate_iconify->setChecked(tree_get_bool("theme/animateIconify", TRUE));
layout = tree_get_string("theme/titleLayout", "NLIMC");
ui.title_layout->setText(layout);
// preview_update_set_title_layout(layout); // FIXME
g_free(layout);
f = read_font(ui.font_active, "ActiveWindow", TRUE);
// FIXME preview_update_set_active_font(f);
f = read_font(ui.font_inactive, "InactiveWindow", TRUE);
// FIXME preview_update_set_inactive_font(f);
f = read_font(ui.font_menu_header, "MenuHeader", TRUE);
// FIXME preview_update_set_menu_header_font(f);
f = read_font(ui.font_menu_item, "MenuItem", TRUE);
// FIXME preview_update_set_menu_item_font(f);
if(!(f = read_font(ui.font_active_display, "ActiveOnScreenDisplay", FALSE))) {
f = read_font(ui.font_active_display, "OnScreenDisplay", TRUE);
tree_delete_node("theme/font:place=OnScreenDisplay");
}
// FIXME preview_update_set_osd_active_font(f);
f = read_font(ui.font_inactive_display, "InactiveOnScreenDisplay", TRUE);
// FIXME preview_update_set_osd_inactive_font(f);
}
void MainDialog::on_window_border_toggled(bool checked) {
tree_set_bool("theme/keepBorder", checked);
}
void MainDialog::on_animate_iconify_toggled(bool checked) {
tree_set_bool("theme/animateIconify", checked);
}
void MainDialog::on_title_layout_textChanged(const QString& text) {
QByteArray layout;
// omit unknown chars
for(int i = 0; i < text.length(); ++i) {
char ch = text.at(i).toUpper().toLatin1();
if(strchr("NDSLIMC", ch))
layout += ch;
}
tree_set_string("theme/titleLayout", layout.constData());
// FIXME preview_update_set_title_layout(layout);
}
void MainDialog::on_font_active_changed() {
write_font(ui.font_active, "ActiveWindow");
// FIXME preview_update_set_active_font(write_font(w, "ActiveWindow"));
}
void MainDialog::on_font_inactive_changed() {
write_font(ui.font_inactive, "InactiveWindow");
// FIXME preview_update_set_inactive_font(write_font(w, "InactiveWindow"));
}
void MainDialog::on_font_menu_header_changed() {
write_font(ui.font_menu_header, "MenuHeader");
// FIXME preview_update_set_menu_header_font(write_font(w, "MenuHeader"));
}
void MainDialog::on_font_menu_item_changed() {
write_font(ui.font_menu_item, "MenuItem");
// FIXME preview_update_set_menu_item_font(write_font(w, "MenuItem"));
}
void MainDialog::on_font_active_display_changed() {
write_font(ui.font_active_display, "ActiveOnScreenDisplay");
// FIXME preview_update_set_osd_active_font(write_font(w, "ActiveOnScreenDisplay"));
}
void MainDialog::on_font_inactive_display_changed() {
write_font(ui.font_inactive_display, "InactiveOnScreenDisplay");
// FIXME preview_update_set_osd_inactive_font
// FIXME (write_font(w, "InactiveOnScreenDisplay"));
}
static RrFont* read_font(Fm::FontButton* button, const gchar* place,
gboolean use_default) {
RrFont* font;
gchar* fontstring, *node;
gchar* name, **names;
gchar* size;
gchar* weight;
gchar* slant;
RrFontWeight rr_weight = RR_FONTWEIGHT_NORMAL;
RrFontSlant rr_slant = RR_FONTSLANT_NORMAL;
node = g_strdup_printf("theme/font:place=%s/name", place);
name = tree_get_string(node, use_default ? "Sans" : NULL);
g_free(node);
if(name[0] == '\0') {
g_free(name);
return NULL;
}
node = g_strdup_printf("theme/font:place=%s/size", place);
size = tree_get_string(node, "8");
g_free(node);
node = g_strdup_printf("theme/font:place=%s/weight", place);
weight = tree_get_string(node, "");
g_free(node);
node = g_strdup_printf("theme/font:place=%s/slant", place);
slant = tree_get_string(node, "");
g_free(node);
/* get only the first font in the string */
names = g_strsplit(name, ",", 0);
g_free(name);
name = g_strdup(names[0]);
g_strfreev(names);
/* don't use "normal" in the gtk string */
if(!g_ascii_strcasecmp(weight, "normal")) {
g_free(weight); weight = g_strdup("");
}
if(!g_ascii_strcasecmp(slant, "normal")) {
g_free(slant); slant = g_strdup("");
}
QFont qfont;
qfont.setFamily(name);
// FIXME qfont.setWeight(weight);
qfont.setPointSize(atoi(size));
button->setFont(qfont);
if(!g_ascii_strcasecmp(weight, "Bold")) rr_weight = RR_FONTWEIGHT_BOLD;
if(!g_ascii_strcasecmp(slant, "Italic")) rr_slant = RR_FONTSLANT_ITALIC;
if(!g_ascii_strcasecmp(slant, "Oblique")) rr_slant = RR_FONTSLANT_OBLIQUE;
font = RrFontOpen(rrinst, name, atoi(size), rr_weight, rr_slant);
// g_free(fontstring);
g_free(slant);
g_free(weight);
g_free(size);
g_free(name);
return font;
}
static RrFont* write_font(Fm::FontButton* button, const gchar* place) {
gchar *c;
gchar *node;
RrFontWeight weight = RR_FONTWEIGHT_NORMAL;
RrFontSlant slant = RR_FONTSLANT_NORMAL;
QFont qfont = button->font();
if(qfont.bold())
weight = RR_FONTWEIGHT_BOLD;
QString size = QString("%1").arg(qfont.pointSize());
const char* slantStr = NULL;
switch(qfont.style()) {
case QFont::StyleItalic:
slant = RR_FONTSLANT_ITALIC;
slantStr = "Italic";
break;
case QFont::StyleOblique:
slant = RR_FONTSLANT_OBLIQUE;
slantStr = "Oblique";
break;
default:
slantStr = "Normal";
}
node = g_strdup_printf("theme/font:place=%s/name", place);
tree_set_string(node, qfont.family().toUtf8().constData());
g_free(node);
node = g_strdup_printf("theme/font:place=%s/size", place);
tree_set_string(node, size.toLatin1().constData());
g_free(node);
node = g_strdup_printf("theme/font:place=%s/weight", place);
tree_set_string(node, qfont.bold() ? "Bold" : "Normal");
g_free(node);
node = g_strdup_printf("theme/font:place=%s/slant", place);
tree_set_string(node, slantStr);
g_free(node);
return RrFontOpen(rrinst, qfont.family().toUtf8().constData(), qfont.pointSize(), weight, slant);
}
#include <QMessageBox>
#include <glib.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
static gchar *get_theme_dir();
static gboolean change_dir(const gchar *dir);
static gchar* name_from_dir(const gchar *dir);
static gchar* install_theme_to(const gchar *file, const gchar *to);
static gboolean create_theme_archive(const gchar *dir, const gchar *name,
const gchar *to);
gchar* archive_install(const gchar *path)
{
gchar *dest;
gchar *name;
if (!(dest = get_theme_dir()))
return NULL;
if ((name = install_theme_to(path, dest))) {
QMessageBox::information(NULL, QString(), QObject::tr("\"%1\" was installed to %1")
.arg(QString::fromUtf8(name))
.arg(QString::fromUtf8(dest)));
}
g_free(dest);
return name;
}
void archive_create(const gchar *path)
{
gchar *name;
gchar *dest;
if (!(name = name_from_dir(path)))
return;
{
gchar *file;
file = g_strdup_printf("%s.obt", name);
dest = g_build_path(G_DIR_SEPARATOR_S,
g_get_current_dir(), file, NULL);
g_free(file);
}
if (create_theme_archive(path, name, dest))
QMessageBox::information(NULL, QString(), QObject::tr("\"%1\" was successfully created")
.arg(QString::fromUtf8(dest)));
g_free(dest);
g_free(name);
}
static gboolean create_theme_archive(const gchar *dir, const gchar *name,
const gchar *to)
{
gchar *glob;
gchar **argv;
gchar *errtxt = NULL;
gchar *parentdir;
gint exitcode;
GError *e = NULL;
glob = g_strdup_printf("%s/openbox-3/", name);
parentdir = g_build_path(G_DIR_SEPARATOR_S, dir, "..", NULL);
argv = g_new(gchar*, 9);
argv[0] = g_strdup("tar");
argv[1] = g_strdup("-c");
argv[2] = g_strdup("-z");
argv[3] = g_strdup("-f");
argv[4] = g_strdup(to);
argv[5] = g_strdup("-C");
argv[6] = g_strdup(parentdir);
argv[7] = g_strdup(glob);
argv[8] = NULL;
if (g_spawn_sync(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL,
NULL, &errtxt, &exitcode, &e))
{
if (exitcode != EXIT_SUCCESS)
QMessageBox::critical(NULL, QString(),
QObject::tr("Unable to create the theme archive \"%1\".\nThe following errors were reported:\n%2")
.arg(QString::fromUtf8(to))
.arg(QString::fromUtf8(errtxt)));
}
else
QMessageBox::critical(NULL, QString(),QObject::tr("Unable to run the \"tar\" command: %1")
.arg(QString::fromUtf8(e->message)));
g_strfreev(argv);
if (e) g_error_free(e);
g_free(errtxt);
g_free(parentdir);
g_free(glob);
return exitcode == EXIT_SUCCESS;
}
static gchar *get_theme_dir()
{
gchar *dir;
gint r;
dir = g_build_path(G_DIR_SEPARATOR_S, g_get_home_dir(), ".themes", NULL);
r = mkdir(dir, 0777);
if (r == -1 && errno != EEXIST) {
QMessageBox::critical(NULL, QString(),
QObject::tr("Unable to create directory \"%1\": %2")
.arg(QString::fromUtf8(dir))
.arg(QString::fromUtf8(strerror(errno))));
g_free(dir);
dir = NULL;
}
return dir;
}
static gchar* name_from_dir(const gchar *dir)
{
gchar *rc;
struct stat st;
gboolean r;
rc = g_build_path(G_DIR_SEPARATOR_S, dir, "openbox-3", "themerc", NULL);
r = (stat(rc, &st) == 0 && S_ISREG(st.st_mode));
g_free(rc);
if (!r) {
QMessageBox::critical(NULL, QString(),
QObject::tr("\"%1\" does not appear to be a valid Openbox theme directory")
.arg(QString::fromUtf8(dir)));
return NULL;
}
return g_path_get_basename(dir);
}
static gboolean change_dir(const gchar *dir)
{
if (chdir(dir) == -1) {
QMessageBox::critical(NULL, QString(), QObject::tr("Unable to move to directory \"%1\": %2")
.arg(QString::fromUtf8(dir))
.arg(QString::fromUtf8(strerror(errno))));
return FALSE;
}
return TRUE;
}
static gchar* install_theme_to(const gchar *file, const gchar *to)
{
gchar **argv;
gchar *errtxt = NULL, *outtxt = NULL;
gint exitcode;
GError *e = NULL;