diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..70c2b72 --- /dev/null +++ b/.clang-format @@ -0,0 +1,64 @@ +--- +BasedOnStyle: Google +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: 'true' +AlignConsecutiveDeclarations: 'true' +AlignEscapedNewlines: Left +AlignOperands: 'true' +AlignTrailingComments: 'true' +AllowAllParametersOfDeclarationOnNextLine: 'false' +AllowShortBlocksOnASingleLine: 'false' +AllowShortCaseLabelsOnASingleLine: 'true' +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: 'false' +AllowShortLoopsOnASingleLine: 'false' +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: 'false' +AlwaysBreakTemplateDeclarations: 'Yes' +BinPackArguments: 'false' +BinPackParameters: 'false' +BreakBeforeBinaryOperators: All +BreakBeforeBraces: Allman +BreakBeforeTernaryOperators: 'true' +BreakConstructorInitializers: BeforeComma +BreakInheritanceList: BeforeComma +BreakStringLiterals: 'true' +ColumnLimit: '120' +CompactNamespaces: 'true' +ConstructorInitializerAllOnOneLineOrOnePerLine: 'true' +ConstructorInitializerIndentWidth: '3' +ContinuationIndentWidth: '3' +Cpp11BracedListStyle: 'false' +DerivePointerAlignment: 'true' +FixNamespaceComments: 'true' +IncludeBlocks: Preserve +IndentCaseLabels: 'true' +IndentPPDirectives: None +IndentWidth: '3' +IndentWrappedFunctionNames: 'false' +KeepEmptyLinesAtTheStartOfBlocks: 'false' +Language: Cpp +MaxEmptyLinesToKeep: '2' +NamespaceIndentation: None +PointerAlignment: Left +SortIncludes: 'false' +SortUsingDeclarations: 'false' +SpaceAfterCStyleCast: 'false' +SpaceAfterTemplateKeyword: 'true' +SpaceBeforeAssignmentOperators: 'true' +SpaceBeforeCpp11BracedList: 'false' +SpaceBeforeCtorInitializerColon: 'true' +SpaceBeforeInheritanceColon: 'true' +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: 'true' +SpaceInEmptyParentheses: 'false' +SpacesBeforeTrailingComments: '3' +SpacesInAngles: 'false' +SpacesInCStyleCastParentheses: 'false' +SpacesInParentheses: 'false' +SpacesInSquareBrackets: 'true' +Standard: Cpp11 +TabWidth: '3' +UseTab: Never + +... diff --git a/.clangd b/.clangd new file mode 100644 index 0000000..95d65af --- /dev/null +++ b/.clangd @@ -0,0 +1,16 @@ +# vim: set ft=yaml +CompileFlags: + CompilationDatabase: ./build +Diagnostics: + UnusedIncludes: Strict + ClangTidy: + Add: + - linuxkernel-* + - llvmlibc-* + - modernize-* + - portability-* + - readability-* + Remove: + - modernize-macro-to-enum + - readability-identifier-length + - readability-redundant-function-ptr-dereference diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index edb27c7..f24ef34 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,9 +1,2 @@ -# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.163.1/containers/debian/.devcontainer/base.Dockerfile - -# [Choice] Debian version: buster, stretch FROM "xfce/xfce-build" - -# ** [Optional] Uncomment this section to install additional packages. ** -# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ -# && apt-get -y install --no-install-recommends RUN useradd -m vscode diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index c0b4040..b6ad847 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,5 +1,3 @@ -// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: -// https://github.com/microsoft/vscode-dev-containers/tree/v0.163.1/containers/debian { "name": "xfce-build", "build": { @@ -7,23 +5,16 @@ "dockerfile": "Dockerfile" }, - // Set *default* container specific settings.json values on container create. - "settings": { - "terminal.integrated.shell.linux": "/bin/bash" + "customizations": { + "vscode": { + "terminal.integrated.shell.linux": "/bin/bash", + "extensions": [ + "llvm-vs-code-extensions.vscode-clangd" + ] + } }, - - // Add the IDs of extensions you want installed when the container is created. - "extensions": [], - - // Use 'forwardPorts' to make a list of ports inside the container available locally. // "forwardPorts": [], - - // Uncomment to use the Docker CLI from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker. // "mounts": [ "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" ], - - // Uncomment when using a ptrace-based debugger like C++, Go, and Rust - // "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ], - - // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ], "remoteUser": "vscode" } diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..cb12569 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,8 @@ +[Makefile] +indent_style = tab +indent_size = 4 + +[*.{c,h}] +indent_style = space +indent_size = 3 + diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 8dec01a..6bfdd81 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -23,7 +23,7 @@ jobs: # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 # Runs a set of commands using the runners shell - name: Build and Install diff --git a/.gitignore b/.gitignore index 86828c1..41e06ea 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ po/Makefile.in po/POTFILES po/stamp-it po/xfce4-hamster-plugin.pot +compile_commands.json diff --git a/CMakeLists.txt b/CMakeLists.txt index ab1ab42..3eb399a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,8 @@ project(xfce4-hamster-plugin DESCRIPTION "A recreation of the gnome hamster shell extension for the xfce4 panel" LANGUAGES C ) +set(CMAKE_PROJECT_HOMEPAGE_URL "https://github.com/projecthamster/xfce4-hamster-plugin") +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) find_package(PkgConfig REQUIRED) find_package(Gettext REQUIRED) @@ -74,3 +76,18 @@ install(TARGETS hamster LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/xfce4/panel install(FILES ${PROJECT_BINARY_DIR}/hamster.desktop DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/xfce4/panel/plugins/) install(PROGRAMS ${PROJECT_BINARY_DIR}/xfce4-popup-hamstermenu DESTINATION ${CMAKE_INSTALL_BINDIR}) +# CPACK +set(CPACK_ADD_VERSION 2) +set(CPACK_PACKAGE_CONTACT "Hakan Erduman ") + +# deb specific +set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT") +set(CPACK_DEBIAN_PACKAGE_RELEASE ${CPACK_ADD_VERSION}) +set(CPACK_DEBIAN_PACKAGE_SECTION "Xfce") +set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) + +# rpm specific +set(CPACK_RPM_FILE_NAME, "RPM-DEFAULT") +set(CPACK_RPM_PACKAGE_RELEASE ${CPACK_ADD_VERSION}) + +include(CPack) diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..747648a --- /dev/null +++ b/Makefile @@ -0,0 +1,34 @@ +# minimal makefile to ease cmake usage + +CMAKE_BUILD_TYPE ?= RelWithDebInfo # sane, strip later on +CMAKE_INSTALL_PREFIX ?= /usr # panel plugins only work here +CMAKE_GENERATOR ?= $(shell (command -v ninja > /dev/null 2>&1 && echo "Ninja") || echo "Unix Makefiles") + +.PHONY: default info cmake install deb rpm + +default: cmake + +info: + @echo '*** you can override these ***' + @echo "CMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE)" + @echo "CMAKE_INSTALL_PREFIX=$(CMAKE_INSTALL_PREFIX)" + @echo "CMAKE_GENERATOR=$(CMAKE_GENERATOR)" + @echo '*** this one depends on CMAKE_GENERATOR ***' + +./build: + cmake -B build -G $(CMAKE_GENERATOR) -DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE) -DCMAKE_INSTALL_PREFIX=$(CMAKE_INSTALL_PREFIX) + +cmake: ./build + cmake --build build + +install: cmake + cmake --install build + +clean: + rm -rf build + +deb: cmake + cd build && cpack -G DEB + +rpm: cmake + cd build && cpack -G RPM diff --git a/README.md b/README.md index 974f5cd..83474f2 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,9 @@ libxfconf-0-dev libxfce4util-dev` Common: `build-essential cmake intltool` -Tested on Arch with xfce 4.16, Ubuntu 20.04 with xfce 4.14 and -Debian Buster with xfce 4.12. Uses GTK+3 only, requires APIs that are -not available before xfce 4.10. Support for older versions are in +Tested on Arch with xfce 4.18, Ubuntu 22.04 with xfce 4.16 and +Debian Bookworm with xfce 4.18. Uses GTK+3 only, requires APIs that are +not available before xfce 4.10. Support for older versions are available in the git history. Also seen running on Alpine and void (musl). ## Translators @@ -26,9 +26,12 @@ the following bias: ## Compilation Checkout as outlined under Contribution below, cd to the directory and issue `cmake -B build -DCMAKE_INSTALL_PREFIX=/usr`. If this fails, install any missing -dependencies and repeat until success. +dependencies and you may need to rinse and repeat until success. Finally, issue `cmake --build build && sudo cmake --install build`. Restart the xfce4 panel with `xfce4-panel -r`. +If the plugin does not show up, check if the installation location is indeed `/usr`; +the panel does only seek for plugins on a location hardcoded at the time of compilation +of xfce4 itself, so you `/usr/local` may be fine on the \*BSDs. ## Packagers This plug-in is useless without an activatable D-Bus implementation of @@ -41,9 +44,6 @@ If your distribution doesn't, maybe its time to push the issue. The icon from hamster is reused as `org.gnome.Hamster.GUI`. -The generated .lo files are best purged since no linkage or development -packages are provided. - [![Packaging status](https://repology.org/badge/vertical-allrepos/xfce4-hamster-plugin.svg)](https://repology.org/project/xfce4-hamster-plugin/versions) ## Contributing @@ -61,4 +61,8 @@ I'd like to thank the following translators: - Nicolas Reynolds - fauno - +## Development +The Compilation steps are available within a convenience `Makefile`. If CPack is +installed, this Makefile may also generate `.deb` and `.rpm` packages +with the `deb` and `rpm` make targets. Keeping debug info is achieved with `make CMAKE_BUILD_TYPE=DEBUG`. +This will also make `DBG()` output visible in the console. diff --git a/panel-plugin/CMakeLists.txt b/panel-plugin/CMakeLists.txt index 4e50002..2599611 100644 --- a/panel-plugin/CMakeLists.txt +++ b/panel-plugin/CMakeLists.txt @@ -35,6 +35,11 @@ add_compile_definitions( LOCALEDIR="${CMAKE_INSTALL_FULL_LOCALEDIR}" ) +if(CMAKE_BUILD_TYPE STREQUAL "DEBUG") + message("Build DEBUG version") + add_compile_definitions(DEBUG=1) +endif() + target_include_directories( hamster PUBLIC ${GTK_INCLUDE_DIRS} @@ -45,6 +50,9 @@ target_link_directories( hamster PUBLIC ${GTK_LIBRARY_DIRS} ) +target_compile_options( + hamster PUBLIC "-ffile-prefix-map=${CMAKE_SOURCE_DIR}=." +) target_link_libraries( hamster ${GTK_LIBRARIES} diff --git a/panel-plugin/button.c b/panel-plugin/button.c index 6624bfc..5b8727e 100644 --- a/panel-plugin/button.c +++ b/panel-plugin/button.c @@ -44,67 +44,63 @@ * along with this program. If not, see . */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include #include #include -#include #include "button.h" +#include "util.h" #define BOX_SPACING 2 enum { - PROP_0, - PROP_LABEL + PROP_0, + PROP_LABEL, + PROP_ELLIPSIZE }; -static void -places_button_dispose(GObject*); +static void places_button_dispose(GObject * /*object*/); -static void -places_button_resize(PlacesButton*); +static void places_button_resize(PlacesButton * /*self*/); -static void -places_button_mode_changed(XfcePanelPlugin*, XfcePanelPluginMode, PlacesButton*); +static void places_button_mode_changed(const XfcePanelPlugin * /*plugin*/, + XfcePanelPluginMode /*mode*/, + PlacesButton * /*self*/); -static gboolean -places_button_size_changed(XfcePanelPlugin*, gint size, PlacesButton*); +static gboolean places_button_size_changed(const XfcePanelPlugin * /*plugin*/, gint size, PlacesButton * /*self*/); -static void -places_button_theme_changed(PlacesButton*); +static void places_button_theme_changed(PlacesButton * /*self*/); G_DEFINE_TYPE(PlacesButton, places_button, GTK_TYPE_TOGGLE_BUTTON); -void -places_button_set_label(PlacesButton *self, const gchar *label) +void places_button_set_label(PlacesButton *self, const gchar *label) { - g_assert(PLACES_IS_BUTTON(self)); + g_assert(PLACES_IS_BUTTON(self)); - if (label == NULL && self->label_text == NULL) - return; + if (label == NULL && self->label_text == NULL) + { + return; + } - if (label != NULL && self->label_text != NULL && - strcmp(label, self->label_text) == 0) { - return; - } + if (label != NULL && self->label_text != NULL && strcmp(label, self->label_text) == 0) + { + return; + } - DBG("new label text: %s", label); + DBG("new label text: %s", label); - if (self->label_text != NULL) - g_free(self->label_text); + if (self->label_text != NULL) + { + g_free(self->label_text); + } - self->label_text = g_strdup(label); + self->label_text = g_strdup(label); - places_button_resize(self); + places_button_resize(self); } -void -places_button_set_ellipsize(PlacesButton *self, gboolean ellipsize) +void places_button_set_ellipsize(PlacesButton *self, gboolean ellipsize) { g_assert(PLACES_IS_BUTTON(self)); self->ellipsize = ellipsize; @@ -112,306 +108,301 @@ places_button_set_ellipsize(PlacesButton *self, gboolean ellipsize) places_button_resize(self); } -static void -places_button_set_property(GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) +static void places_button_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { - PlacesButton *self; - - self = PLACES_BUTTON(object); + PlacesButton *self = PLACES_BUTTON(object); - switch (property_id) { + switch (property_id) + { + case PROP_LABEL: places_button_set_label(self, g_value_get_string(value)); break; + case PROP_ELLIPSIZE: places_button_set_ellipsize(self, g_value_get_boolean(value)); break; - case PROP_LABEL: - places_button_set_label(self, g_value_get_string(value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); - break; - } + default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); break; + } } -const gchar* -places_button_get_label(PlacesButton *self) +const gchar *places_button_get_label(PlacesButton *self) { - g_assert(PLACES_IS_BUTTON(self)); + g_assert(PLACES_IS_BUTTON(self)); - DBG("returning %s", self->label_text); - return self->label_text; + DBG("returning %s", self->label_text); + return self->label_text; } -gboolean -places_button_get_ellipsize(PlacesButton *self) +gboolean places_button_get_ellipsize(PlacesButton *self) { - g_assert(PLACES_IS_BUTTON(self)); + g_assert(PLACES_IS_BUTTON(self)); - DBG("returning %d", self->ellipsize); - return self->ellipsize; + DBG("returning %d", self->ellipsize); + return self->ellipsize; } -static void -places_button_get_property(GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) +static void places_button_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { - PlacesButton *self; + PlacesButton *self; - self = PLACES_BUTTON(object); + self = PLACES_BUTTON(object); - switch (property_id) { + switch (property_id) + { + case PROP_LABEL: g_value_set_string(value, places_button_get_label(self)); break; + case PROP_ELLIPSIZE: g_value_set_boolean(value, places_button_get_ellipsize(self)); break; - case PROP_LABEL: - g_value_set_string(value, places_button_get_label(self)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); - break; - } + default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); break; + } } - -static void -places_button_class_init(PlacesButtonClass *klass) +static void places_button_class_init(PlacesButtonClass *klass) { - GObjectClass *gobject_class; + GObjectClass *gobject_class; - gobject_class = G_OBJECT_CLASS(klass); + gobject_class = G_OBJECT_CLASS(klass); - gobject_class->dispose = places_button_dispose; + gobject_class->dispose = places_button_dispose; - gobject_class->set_property = places_button_set_property; - gobject_class->get_property = places_button_get_property; + gobject_class->set_property = places_button_set_property; + gobject_class->get_property = places_button_get_property; - g_object_class_install_property(gobject_class, - PROP_LABEL, - g_param_spec_string("label", - "Label", - "Button text", - NULL, - G_PARAM_READABLE|G_PARAM_WRITABLE)); + g_object_class_install_property( + gobject_class, + PROP_LABEL, + g_param_spec_string("label", "Label", "Button text", NULL, G_PARAM_READABLE | G_PARAM_WRITABLE)); + + g_object_class_install_property( + gobject_class, + PROP_ELLIPSIZE, + g_param_spec_boolean( + "ellipsize", "Ellipsize", "Button text ellipsis", FALSE, G_PARAM_READABLE | G_PARAM_WRITABLE)); } -static void -places_button_init(PlacesButton *self) +static void places_button_init(PlacesButton *self) { - self->plugin = NULL; - self->box = NULL; - self->label = NULL; - self->plugin_size = -1; - self->ellipsize = FALSE; + self->plugin = NULL; + self->box = NULL; + self->label = NULL; + self->plugin_size = -1; + self->ellipsize = FALSE; } -static void -places_button_construct(PlacesButton *self, XfcePanelPlugin *plugin) +static void places_button_construct(PlacesButton *self, XfcePanelPlugin *plugin) { - GtkOrientation orientation; - - g_assert(XFCE_IS_PANEL_PLUGIN(plugin)); + GtkOrientation orientation; - g_object_ref(plugin); - self->plugin = plugin; + g_assert(XFCE_IS_PANEL_PLUGIN(plugin)); - gtk_button_set_relief(GTK_BUTTON(self), GTK_RELIEF_NONE); - gtk_widget_set_focus_on_click(GTK_WIDGET(self), FALSE); + g_object_ref(plugin); + self->plugin = plugin; - orientation = xfce_panel_plugin_get_orientation(self->plugin); - self->box = gtk_box_new(orientation, 1); - gtk_container_set_border_width(GTK_CONTAINER(self->box), 0); - gtk_widget_set_halign(self->box, GTK_ALIGN_CENTER); - gtk_container_add(GTK_CONTAINER(self), self->box); - gtk_widget_show(self->box); + gtk_button_set_relief(GTK_BUTTON(self), GTK_RELIEF_NONE); + gtk_widget_set_focus_on_click(GTK_WIDGET(self), FALSE); - places_button_resize(self); + orientation = xfce_panel_plugin_get_orientation(self->plugin); + self->box = gtk_box_new(orientation, 1); + gtk_container_set_border_width(GTK_CONTAINER(self->box), 0); + gtk_widget_set_halign(self->box, GTK_ALIGN_CENTER); + gtk_container_add(GTK_CONTAINER(self), self->box); + gtk_widget_show(self->box); - g_signal_connect(G_OBJECT(plugin), "mode-changed", - G_CALLBACK(places_button_mode_changed), self); + places_button_resize(self); - g_signal_connect(G_OBJECT(plugin), "size-changed", - G_CALLBACK(places_button_size_changed), self); + g_signal_connect(G_OBJECT(plugin), "mode-changed", G_CALLBACK(places_button_mode_changed), self); - self->style_set_id = g_signal_connect(G_OBJECT(self), "style-set", - G_CALLBACK(places_button_theme_changed), NULL); - self->screen_changed_id = g_signal_connect(G_OBJECT(self), "screen-changed", - G_CALLBACK(places_button_theme_changed), NULL); + g_signal_connect(G_OBJECT(plugin), "size-changed", G_CALLBACK(places_button_size_changed), self); + self->style_set_id = g_signal_connect(G_OBJECT(self), "style-set", G_CALLBACK(places_button_theme_changed), NULL); + self->screen_changed_id + = g_signal_connect(G_OBJECT(self), "screen-changed", G_CALLBACK(places_button_theme_changed), NULL); } -GtkWidget* -places_button_new(XfcePanelPlugin *plugin) +GtkWidget *places_button_new(XfcePanelPlugin *plugin) { - PlacesButton *button; + PlacesButton *button; - g_assert(XFCE_IS_PANEL_PLUGIN(plugin)); + g_assert(XFCE_IS_PANEL_PLUGIN(plugin)); - button = (PlacesButton*) g_object_new(PLACES_TYPE_BUTTON, NULL); - places_button_construct(button, plugin); + button = (PlacesButton *)g_object_new(PLACES_TYPE_BUTTON, NULL); + places_button_construct(button, plugin); - return GTK_WIDGET (button); + return GTK_WIDGET(button); } -static void -places_button_dispose(GObject *object) +static void places_button_dispose(GObject *object) { - PlacesButton *self = PLACES_BUTTON(object); - - if (self->style_set_id != 0) { - g_signal_handler_disconnect(self, self->style_set_id); - self->style_set_id = 0; - } - - if (self->screen_changed_id != 0) { - g_signal_handler_disconnect(self, self->screen_changed_id); - self->screen_changed_id = 0; - } - - if (self->plugin != NULL) { - g_object_unref(self->plugin); - self->plugin = NULL; - } + PlacesButton *self = PLACES_BUTTON(object); + + if (self->style_set_id != 0) + { + g_signal_handler_disconnect(self, self->style_set_id); + self->style_set_id = 0; + } + + if (self->screen_changed_id != 0) + { + g_signal_handler_disconnect(self, self->screen_changed_id); + self->screen_changed_id = 0; + } + + if (self->plugin != NULL) + { + g_object_unref(self->plugin); + self->plugin = NULL; + } + + (*G_OBJECT_CLASS(places_button_parent_class)->dispose)(object); +} - (*G_OBJECT_CLASS(places_button_parent_class)->dispose) (object); +static void places_button_destroy_label(PlacesButton *self) +{ + if (self->label != NULL) + { + gtk_widget_destroy(self->label); + g_object_unref(self->label); + self->label = NULL; + } } -static void -places_button_destroy_label(PlacesButton *self) +static void places_button_resize_label(PlacesButton *self, unused gboolean show) { - if (self->label != NULL) { - gtk_widget_destroy(self->label); - g_object_unref(self->label); - self->label = NULL; - } + gboolean vertical = FALSE; + gboolean deskbar = FALSE; + + if (xfce_panel_plugin_get_mode(self->plugin) == XFCE_PANEL_PLUGIN_MODE_DESKBAR) + { + deskbar = TRUE; + } + else if (xfce_panel_plugin_get_mode(self->plugin) == XFCE_PANEL_PLUGIN_MODE_VERTICAL) + { + vertical = TRUE; + } + if (self->label_text == NULL) + { + places_button_destroy_label(self); + return; + } + + if (self->label == NULL) + { + self->label = g_object_ref(gtk_label_new(self->label_text)); + gtk_box_pack_end(GTK_BOX(self->box), self->label, TRUE, TRUE, 0); + } + else + { + gtk_label_set_text(GTK_LABEL(self->label), self->label_text); + } + + if (deskbar || self->ellipsize) + { + gtk_label_set_ellipsize(GTK_LABEL(self->label), PANGO_ELLIPSIZE_END); + } + else + { + gtk_label_set_ellipsize(GTK_LABEL(self->label), PANGO_ELLIPSIZE_NONE); + } + + if (vertical) + { + gtk_label_set_angle(GTK_LABEL(self->label), -RIGTH_ANGLE); + gtk_widget_set_halign(self->label, GTK_ALIGN_CENTER); + gtk_widget_set_valign(self->label, GTK_ALIGN_START); + } + else + { + gtk_label_set_angle(GTK_LABEL(self->label), 0); + gtk_widget_set_halign(self->label, GTK_ALIGN_START); + gtk_widget_set_valign(self->label, GTK_ALIGN_CENTER); + } + if (self->ellipsize) + { + gtk_label_set_max_width_chars(GTK_LABEL(self->label), MIN_FACT_LEN); + } + else + { + gtk_label_set_max_width_chars(GTK_LABEL(self->label), MAX_FACT_LEN); + } + + gtk_widget_show(self->label); } -static void -places_button_resize_label(PlacesButton *self, - gboolean show) + +static void places_button_resize(PlacesButton *self) { - gboolean vertical = FALSE; - gboolean deskbar = FALSE; - - if (xfce_panel_plugin_get_mode(self->plugin) == XFCE_PANEL_PLUGIN_MODE_DESKBAR) { - deskbar = TRUE; - } - else if (xfce_panel_plugin_get_mode(self->plugin) == XFCE_PANEL_PLUGIN_MODE_VERTICAL) { - vertical = TRUE; - } - if (self->label_text == NULL) { - places_button_destroy_label(self); - return; - } - - if (self->label == NULL) { - self->label = g_object_ref(gtk_label_new(self->label_text)); - gtk_box_pack_end(GTK_BOX(self->box), self->label, TRUE, TRUE, 0); - } - else - gtk_label_set_text(GTK_LABEL(self->label), self->label_text); - - if (deskbar || self->ellipsize) - gtk_label_set_ellipsize (GTK_LABEL (self->label), PANGO_ELLIPSIZE_END); - else - gtk_label_set_ellipsize (GTK_LABEL (self->label), PANGO_ELLIPSIZE_NONE); - - if (vertical) + gboolean show_label; + gint new_size; + gboolean vertical = FALSE; + gboolean deskbar = FALSE; + + if (self->plugin == NULL) + { + return; + } + + new_size = xfce_panel_plugin_get_size(self->plugin); + self->plugin_size = new_size; + DBG("Panel size: %d", new_size); + + show_label = self->label_text != NULL; + + if (xfce_panel_plugin_get_mode(self->plugin) == XFCE_PANEL_PLUGIN_MODE_DESKBAR) + { + deskbar = TRUE; + } + else if (xfce_panel_plugin_get_mode(self->plugin) == XFCE_PANEL_PLUGIN_MODE_VERTICAL) + { + vertical = TRUE; + } + + if (show_label) + { + xfce_panel_plugin_set_small(self->plugin, deskbar ? FALSE : TRUE); + if (vertical) { - gtk_label_set_angle (GTK_LABEL (self->label), -90); - gtk_widget_set_halign(self->label, GTK_ALIGN_CENTER); - gtk_widget_set_valign(self->label, GTK_ALIGN_START); + gtk_widget_set_halign(self->box, GTK_ALIGN_CENTER); + gtk_widget_set_valign(self->box, GTK_ALIGN_START); } - else + else { - gtk_label_set_angle (GTK_LABEL (self->label), 0); - gtk_widget_set_halign(self->label, GTK_ALIGN_START); - gtk_widget_set_valign(self->label, GTK_ALIGN_CENTER); + gtk_widget_set_halign(self->box, GTK_ALIGN_START); + gtk_widget_set_valign(self->box, GTK_ALIGN_CENTER); } - if(self->ellipsize) - gtk_label_set_max_width_chars (GTK_LABEL (self->label), 25); - else - gtk_label_set_max_width_chars (GTK_LABEL (self->label), 255); - - gtk_widget_show(self->label); + } + else + { + xfce_panel_plugin_set_small(self->plugin, TRUE); + gtk_widget_set_halign(self->box, GTK_ALIGN_CENTER); + gtk_widget_set_valign(self->box, GTK_ALIGN_CENTER); + } + + /* label */ + places_button_resize_label(self, show_label); } - -static void -places_button_resize(PlacesButton *self) +static void places_button_mode_changed(unused const XfcePanelPlugin *plugin, + XfcePanelPluginMode mode, + PlacesButton *self) { - gboolean show_label; - gint new_size; - gboolean vertical = FALSE; - gboolean deskbar = FALSE; - gint nrows = 1; - - if (self->plugin == NULL) - return; - - new_size = xfce_panel_plugin_get_size(self->plugin); - self->plugin_size = new_size; - DBG("Panel size: %d", new_size); - - show_label = self->label_text != NULL; - - if (xfce_panel_plugin_get_mode(self->plugin) == XFCE_PANEL_PLUGIN_MODE_DESKBAR) - deskbar = TRUE; - else if (xfce_panel_plugin_get_mode(self->plugin) == XFCE_PANEL_PLUGIN_MODE_VERTICAL) - vertical = TRUE; - nrows = xfce_panel_plugin_get_nrows(self->plugin); - - new_size /= nrows; - - if (show_label) { - xfce_panel_plugin_set_small (self->plugin, deskbar ? FALSE : TRUE); - if (vertical) { - gtk_widget_set_halign(self->box, GTK_ALIGN_CENTER); - gtk_widget_set_valign(self->box, GTK_ALIGN_START); - } - else { - gtk_widget_set_halign(self->box, GTK_ALIGN_START); - gtk_widget_set_valign(self->box, GTK_ALIGN_CENTER); - } - } else { - xfce_panel_plugin_set_small(self->plugin, TRUE); - gtk_widget_set_halign(self->box, GTK_ALIGN_CENTER); - gtk_widget_set_valign(self->box, GTK_ALIGN_CENTER); - } - - /* label */ - places_button_resize_label(self, show_label); -} - -static void -places_button_mode_changed(XfcePanelPlugin *plugin, XfcePanelPluginMode mode, PlacesButton *self) -{ - DBG("orientation changed"); - gtk_orientable_set_orientation(GTK_ORIENTABLE(self->box), - (mode == XFCE_PANEL_PLUGIN_MODE_VERTICAL) ? - GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL); - places_button_resize(self); + DBG("orientation changed"); + gtk_orientable_set_orientation( + GTK_ORIENTABLE(self->box), + (mode == XFCE_PANEL_PLUGIN_MODE_VERTICAL) ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL); + places_button_resize(self); } -static gboolean -places_button_size_changed(XfcePanelPlugin *plugin, gint size, PlacesButton *self) +static gboolean places_button_size_changed(unused const XfcePanelPlugin *plugin, gint size, PlacesButton *self) { - if (self->plugin_size == size) - return TRUE; + if (self->plugin_size == size) + { + return TRUE; + } - DBG("size changed"); - places_button_resize(self); - return TRUE; + DBG("size changed"); + places_button_resize(self); + return TRUE; } -static void -places_button_theme_changed(PlacesButton *self) +static void places_button_theme_changed(PlacesButton *self) { - DBG("theme changed"); - places_button_resize(self); + DBG("theme changed"); + places_button_resize(self); } - -/* vim: set ai et tabstop=4: */ diff --git a/panel-plugin/button.h b/panel-plugin/button.h index f1f4718..582bb46 100644 --- a/panel-plugin/button.h +++ b/panel-plugin/button.h @@ -25,6 +25,7 @@ #define _XFCE_PANEL_PLACES_BUTTON_H #include +#include #define PLACES_TYPE_BUTTON (places_button_get_type ()) #define PLACES_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PLACES_TYPE_BUTTON, PlacesButton)) @@ -62,7 +63,7 @@ GType places_button_get_type(); GtkWidget* -places_button_new(); +places_button_new(XfcePanelPlugin *plugin); void places_button_set_label(PlacesButton*, const gchar *label); diff --git a/panel-plugin/plugin.c b/panel-plugin/plugin.c index a816a39..9781029 100644 --- a/panel-plugin/plugin.c +++ b/panel-plugin/plugin.c @@ -1,6 +1,6 @@ /* xfce4-hamster-plugin * - * Copyright (c) 2014 Hakan Erduman + * Copyright (c) 2014-2023 Hakan Erduman * * 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 @@ -16,10 +16,6 @@ * along with this program; If not, see . */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include #include @@ -32,10 +28,10 @@ */ gboolean hamster_popup_remote(XfcePanelPlugin *plugin, gchar *name, - GValue *value, HamsterView *view) + GValue const * value, HamsterView *view) { gboolean atPointer; - DBG("Popup remote: %s", name); + DBG("Popup remote: %s at %s(%d)", name, xfce_panel_plugin_get_name(plugin), xfce_panel_plugin_get_unique_id(plugin)); atPointer = g_value_get_boolean(value); hview_popup_show(view, atPointer); return TRUE; @@ -47,7 +43,7 @@ hamster_popup_remote(XfcePanelPlugin *plugin, gchar *name, static void hamster_finalize(XfcePanelPlugin *plugin, HamsterView *view) { - DBG("Finalize: %s", PLUGIN_NAME); + DBG("Finalize: %s(%d)", xfce_panel_plugin_get_name(plugin), xfce_panel_plugin_get_unique_id(plugin)); hamster_view_finalize(view); } @@ -65,7 +61,7 @@ hamster_construct(XfcePanelPlugin *plugin) return; } - DBG("Construct: %s(%d)", PLUGIN_NAME, xfce_panel_plugin_get_unique_id(plugin)); + DBG("Construct: %s(%d)", xfce_panel_plugin_get_name(plugin), xfce_panel_plugin_get_unique_id(plugin)); view = hamster_view_init(plugin); /* Set up i18n */ xfce_textdomain(GETTEXT_PACKAGE, LOCALEDIR, "UTF-8"); @@ -82,5 +78,3 @@ hamster_construct(XfcePanelPlugin *plugin) } XFCE_PANEL_PLUGIN_REGISTER(hamster_construct); - -/* vim: set ai et tabstop=4: */ diff --git a/panel-plugin/settings.c b/panel-plugin/settings.c index 41e5263..1888c7d 100644 --- a/panel-plugin/settings.c +++ b/panel-plugin/settings.c @@ -1,6 +1,6 @@ /* xfce4-hamster-plugin * - * Copyright (c) 2014 Hakan Erduman + * Copyright (c) 2014-2023 Hakan Erduman * * 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 @@ -16,28 +16,28 @@ * along with this program; If not, see . */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif +#include "libxfce4panel/xfce-panel-plugin.h" #include #include #include #include "settings.h" -void -config_show(XfcePanelPlugin *plugin, XfconfChannel *channel) +void config_show(XfcePanelPlugin *plugin, XfconfChannel *channel) { + DBG("cb:%s", xfce_panel_plugin_get_name(plugin)); GtkWidget *dlg = xfce_titled_dialog_new(); - GtkWidget *cnt, *lbl, *chk; + GtkWidget *cnt; + GtkWidget *lbl; + GtkWidget *chk; g_object_set(G_OBJECT(dlg), - "title", _("Hamster"), - "icon_name", "org.gnome.Hamster.GUI", - "subtitle", _("Time bookkeeping plugin"), - NULL); - g_signal_connect_swapped (dlg, - "response", - G_CALLBACK (gtk_widget_destroy), - dlg); + "title", + _("Hamster"), + "icon_name", + "org.gnome.Hamster.GUI", + "subtitle", + _("Time bookkeeping plugin"), + NULL); + g_signal_connect_swapped(dlg, "response", G_CALLBACK(gtk_widget_destroy), dlg); cnt = gtk_dialog_get_content_area(GTK_DIALOG(dlg)); @@ -65,5 +65,6 @@ config_show(XfcePanelPlugin *plugin, XfconfChannel *channel) gtk_widget_show_all(dlg); gtk_dialog_run(GTK_DIALOG(dlg)); - gtk_widget_destroy(dlg); + // this dialog self-destructs its widget + DBG("EOF settings"); } diff --git a/panel-plugin/settings.h b/panel-plugin/settings.h index 9b92303..ce83223 100644 --- a/panel-plugin/settings.h +++ b/panel-plugin/settings.h @@ -1,6 +1,6 @@ /* xfce4-hamster-plugin * - * Copyright (c) 2014 Hakan Erduman + * Copyright (c) 2014-2023 Hakan Erduman * * 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 diff --git a/panel-plugin/util.c b/panel-plugin/util.c index ec0977c..6cad3cd 100644 --- a/panel-plugin/util.c +++ b/panel-plugin/util.c @@ -1,6 +1,6 @@ /* xfce4-hamster-plugin * - * Copyright (c) 2014 Hakan Erduman + * Copyright (c) 2014-2023 Hakan Erduman * * 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 @@ -21,7 +21,6 @@ fact * fact_new(GVariant *in) { - //bzero(out, sizeof(fact)); fact *out = g_new0(fact, 1); g_variant_get(in, "(iiissisasii)", &out->id, diff --git a/panel-plugin/util.h b/panel-plugin/util.h index ddd257e..42b71a9 100644 --- a/panel-plugin/util.h +++ b/panel-plugin/util.h @@ -1,6 +1,6 @@ /* xfce4-hamster-plugin * - * Copyright (c) 2014 Hakan Erduman + * Copyright (c) 2014-2023 Hakan Erduman * * 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 @@ -39,3 +39,8 @@ fact_new(GVariant *in); void fact_free(fact *in); + +#define MAX_FACT_LEN (256) +#define unused __attribute__((__unused__)) +#define RIGTH_ANGLE (90) +#define MIN_FACT_LEN (25) // something@somewhere should not be ellipsized diff --git a/panel-plugin/view.c b/panel-plugin/view.c index f734a0e..cef3adf 100644 --- a/panel-plugin/view.c +++ b/panel-plugin/view.c @@ -1,6 +1,6 @@ /* xfce4-hamster-plugin * - * Copyright (c) 2014 Hakan Erduman + * Copyright (c) 2014-2023 Hakan Erduman * * 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 @@ -13,14 +13,10 @@ * GNU Library General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; If not, see . + * along with this program; If not, see . */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif -#include -#include + #include #include #include @@ -35,163 +31,155 @@ struct _HamsterView { - /* plugin */ - XfcePanelPlugin *plugin; - - /* view */ - GtkWidget *button; - GtkWidget *popup; - GtkWidget *vbx; - GtkWidget *entry; - GtkWidget *treeview; - GtkWidget *summary; - gboolean alive; - guint sourceTimeout; - gboolean inCellEdit; - - /* model */ - GtkListStore *storeFacts; - GtkListStore *storeActivities; - Hamster *hamster; - WindowServer *windowserver; - GtkEntryCompletion *completion; - - - /* config */ - XfconfChannel *channel; - gboolean donthide; - gboolean tooltips; - gboolean dropdown; + /* plugin */ + XfcePanelPlugin *plugin; + + /* view */ + GtkWidget *button; + GtkWidget *popup; + GtkWidget *vbx; + GtkWidget *entry; + GtkWidget *treeview; + GtkWidget *summary; + gboolean alive; + guint sourceTimeout; + gboolean inCellEdit; + + /* model */ + GtkListStore *storeFacts; + GtkListStore *storeActivities; + Hamster *hamster; + WindowServer *windowserver; + GtkEntryCompletion *completion; + + /* config */ + XfconfChannel *channel; + gboolean donthide; + gboolean tooltips; + gboolean dropdown; }; enum _HamsterViewColumns { - TIME_SPAN, // 09:00 - 10:15 - TITLE, // namedchore, without category - DURATION, // 0h 56min - BTNEDIT, // - BTNCONT, // - ID, // hidden, int - CATEGORY, // hidden, int - NUM_COL // not a column, sentinel + TIME_SPAN, // 09:00 - 10:15 + TITLE, // namedchore, without category + DURATION, // 0h 56min + BTNEDIT, // + BTNCONT, // + ID, // hidden, int + CATEGORY, // hidden, int + NUM_COL // not a column, sentinel }; +const int secsperhour = 3600; +const int secspermin = 60; + /* Button */ -static void -hview_popup_hide(HamsterView *view) +static void hview_popup_hide(HamsterView *view) { - /* untoggle the button */ - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(view->button), FALSE); - - /* empty entry */ - if(view->entry) - { - gtk_entry_set_text(GTK_ENTRY(view->entry), ""); - gtk_widget_grab_focus(view->entry); - } - - /* hide the dialog for reuse */ - if (view->popup) - { - gtk_widget_hide (view->popup); - } - view->alive = FALSE; - view->inCellEdit = FALSE; + if (view->donthide) + { + return; + } + /* untoggle the button */ + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(view->button), FALSE); + + /* empty entry */ + if (view->entry) + { + gtk_entry_set_text(GTK_ENTRY(view->entry), ""); + gtk_widget_grab_focus(view->entry); + } + + /* hide the dialog for reuse */ + if (view->popup) + { + gtk_widget_hide(view->popup); + } + view->alive = FALSE; + view->inCellEdit = FALSE; } /* Button callbacks */ -static void -hview_cb_show_overview(GtkWidget *widget, HamsterView *view) +static void hview_cb_show_overview(GtkWidget *widget, HamsterView *view) { + DBG("cb:%s", gtk_widget_get_name(widget)); window_server_call_overview_sync(view->windowserver, NULL, NULL); - if(!view->donthide) - hview_popup_hide(view); + hview_popup_hide(view); } -static void -hview_cb_stop_tracking(GtkWidget *widget, HamsterView *view) +static void hview_cb_stop_tracking(GtkWidget *widget, HamsterView *view) { - time_t now = time(NULL); - struct tm *tmlt = localtime(&now); + DBG("cb:%s", gtk_widget_get_name(widget)); + time_t now = time(NULL); + struct tm tmlt = { 0 }; + localtime_r(&now, &tmlt); now -= timezone; - if(tmlt->tm_isdst) - now += (daylight * 3600); - GVariant *stopTime = g_variant_new_int32(now); - GVariant *var = g_variant_new_variant(stopTime); + if (tmlt.tm_isdst) + { + now += (daylight * secsperhour); + } + GVariant *stopTime = g_variant_new_int64(now); + GVariant *var = g_variant_new_variant(stopTime); hamster_call_stop_tracking_sync(view->hamster, var, NULL, NULL); - if(!view->donthide) - hview_popup_hide(view); + hview_popup_hide(view); } -static void -hview_cb_add_earlier_activity(GtkWidget *widget, HamsterView *view) +static void hview_cb_add_earlier_activity(GtkWidget *widget, HamsterView *view) { - /* pass empty variants? - GVariant *dummy = g_variant_new_maybe(G_VARIANT_TYPE_VARIANT, NULL); - GVariant *var = g_variant_new_variant(dummy); - window_server_call_edit_sync(view->windowserver, var, NULL, NULL); - */ + DBG("cb:%s", gtk_widget_get_name(widget)); + GVariant *_ret = g_dbus_proxy_call_sync( + G_DBUS_PROXY(view->windowserver), "edit", g_variant_new("()"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL); + if (_ret) { - GVariant *_ret; - _ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (view->windowserver), - "edit", - g_variant_new ("()"), - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - NULL); - if (_ret == NULL) - goto _out; - g_variant_get (_ret, - "()"); - g_variant_unref (_ret); + g_variant_get(_ret, "()"); + g_variant_unref(_ret); } - _out: - if(!view->donthide) - hview_popup_hide(view); + hview_popup_hide(view); } -static void -hview_cb_tracking_settings(GtkWidget *widget, HamsterView *view) +static void hview_cb_tracking_settings(GtkWidget *widget, HamsterView *view) { + DBG("cb:%s", gtk_widget_get_name(widget)); window_server_call_preferences_sync(view->windowserver, NULL, NULL); - if(!view->donthide) - hview_popup_hide(view); + hview_popup_hide(view); } -static gboolean -hview_cb_timeout(HamsterView *view) +static gboolean hview_cb_timeout(HamsterView *view) { hview_popup_hide(view); view->sourceTimeout = 0; return FALSE; } -gboolean -hview_cb_popup_focus_out (GtkWidget *widget, - GdkEventFocus *event, - HamsterView *view) +gboolean hview_cb_popup_focus_out(GtkWidget *widget, GdkEventFocus const *event, HamsterView *view) { - if(view->donthide) + DBG("cb:%s, in=%d", gtk_widget_get_name(widget), event->in); + + if (view->donthide) + { return FALSE; - if(!view->sourceTimeout) + } + if (!view->sourceTimeout) { - view->sourceTimeout = g_timeout_add(50, (GSourceFunc)hview_cb_timeout, view); + const uint doubleBlinkEye = 50; // milliseconds + view->sourceTimeout = g_timeout_add(doubleBlinkEye, (GSourceFunc)hview_cb_timeout, view); return FALSE; } return TRUE; } -static gboolean -hview_cb_match_select(GtkEntryCompletion *widget, - GtkTreeModel *model, - GtkTreeIter *iter, - HamsterView *view) +static gboolean hview_cb_match_select(GtkEntryCompletion *completion, + GtkTreeModel *model, + GtkTreeIter *iter, + HamsterView *view) { - char *activity, *category; - char fact[256]; - int id = 0; + char *activity; + char *category; + char fact[ MAX_FACT_LEN ]; + int id = 0; + DBG("cb:%s", gtk_widget_get_name(GTK_WIDGET(completion))); gtk_tree_model_get(model, iter, 0, &activity, 1, &category, -1); snprintf(fact, sizeof(fact), "%s@%s", activity, category); if (view->inCellEdit) @@ -203,84 +191,78 @@ hview_cb_match_select(GtkEntryCompletion *widget, hamster_call_add_fact_sync(view->hamster, fact, 0, 0, FALSE, &id, NULL, NULL); DBG("selected: %s[%d]", fact, id); } - if (!view->donthide) - hview_popup_hide(view); + hview_popup_hide(view); g_free(activity); g_free(category); return TRUE; } -static const char* -hview_get_fact_by_activity(HamsterView *view, const char* activity, const char* category) +static const char *hview_get_fact_by_activity(HamsterView *view, const char *activity, const char *category) { - static char buffer[256]; + static char buffer[ MAX_FACT_LEN ]; - if (NULL == category) // category to be guessed + if (NULL != category) // category to be appended { - GVariant *res; - GVariant *child; - char *act = NULL; - char *cat = NULL; + snprintf(buffer, sizeof(buffer), "%s@%s", activity, category); + return buffer; + } + + // category to be appended + GVariant *res; + GVariant *child; + char *act = NULL; + char *cat = NULL; - hamster_call_get_activities_sync(view->hamster, activity, &res, 0, 0); - if (NULL != res && g_variant_n_children(res) > 0) + hamster_call_get_activities_sync(view->hamster, activity, &res, 0, 0); + if (NULL != res && g_variant_n_children(res) > 0) + { + child = g_variant_get_child_value(res, 0); // topmost in history is OK + if (child) { - child = g_variant_get_child_value(res, 0); // topmost in history is OK - if (child) + g_variant_get(child, "(ss)", &act, &cat); + if (NULL != act && NULL != cat) { - g_variant_get(child, "(ss)", &act, &cat); - if (NULL != act && NULL != cat) - { - snprintf(buffer, sizeof(buffer), "%s@%s", act, cat); - activity = buffer; - } - g_variant_unref(child); + snprintf(buffer, sizeof(buffer), "%s@%s", act, cat); + activity = buffer; } - } // else category stays empty - } - else // category to be appended - { - snprintf(buffer, sizeof(buffer), "%s@%s", activity, category); - activity = buffer; - } + g_variant_unref(child); + } + } // else category stays empty + return activity; } -static void -hview_cb_entry_activate(GtkEntry *entry, - HamsterView *view) +static void hview_cb_entry_activate(GtkEntry *entry, HamsterView *view) { + DBG("cb:%s", gtk_widget_get_name(GTK_WIDGET(entry))); const char *fact = gtk_entry_get_text(GTK_ENTRY(view->entry)); - int id = 0; + int id = 0; if (!strchr(fact, '@')) { fact = hview_get_fact_by_activity(view, fact, NULL); } - + hamster_call_add_fact_sync(view->hamster, fact, 0, 0, FALSE, &id, NULL, NULL); DBG("activated: %s[%d]", fact, id); - if(!view->donthide) - hview_popup_hide(view); + hview_popup_hide(view); } -static gboolean -hview_cb_tv_query_tooltip(GtkWidget *widget, - gint x, - gint y, - gboolean keyboard_mode, - GtkTooltip *tooltip, - HamsterView *view) +static gboolean hview_cb_tv_query_tooltip(GtkWidget *widget, + gint x, + gint y, + unused gboolean keyboard_mode, + GtkTooltip *tooltip, + const HamsterView *view) { - if(view->tooltips) + if (view->tooltips) { - GtkTreePath *path; + GtkTreePath *path; GtkTreeViewColumn *column; - if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), x, y, &path, - &column, NULL, NULL)) + if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), x, y, &path, &column, NULL, NULL)) { - gchar *text = g_object_get_data(G_OBJECT(column), "tip"); - if (text) + gchar const *text; + if (NULL != (text = g_object_get_data(G_OBJECT(column), "tip"))) { gtk_tooltip_set_text(tooltip, text); return TRUE; @@ -290,247 +272,217 @@ hview_cb_tv_query_tooltip(GtkWidget *widget, return FALSE; } -static gboolean -hview_cb_tv_button_press(GtkWidget *tv, - GdkEventButton* evt, - HamsterView *view) +static gboolean hview_cb_tv_button_press(GtkWidget *tv, const GdkEventButton *evt, HamsterView *view) { - if (evt->button == 1) + if (evt->button != 1) { - GtkTreePath *path; - GtkTreeViewColumn *column; - if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), (int)evt->x, - (int)evt->y, &path, &column, NULL, NULL)) + return FALSE; + } + + GtkTreePath *path; + GtkTreeViewColumn *column; + if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), (int)evt->x, (int)evt->y, &path, &column, NULL, NULL)) + { + return FALSE; + } + + GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tv)); + GtkTreeModel *model = NULL; + GtkTreeIter iter; + if (gtk_tree_selection_get_selected(selection, &model, &iter)) + { + int id; + char *icon; + char *fact; + char *category; + gtk_tree_model_get(model, &iter, ID, &id, BTNCONT, &icon, TITLE, &fact, CATEGORY, &category, -1); + DBG("%s:%s:%s", fact, category, icon); + if (!strcmp(gtk_tree_view_column_get_title(column), "ed")) { - GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tv)); - GtkTreeModel *model = NULL; - GtkTreeIter iter; - if (gtk_tree_selection_get_selected(selection, &model, &iter)) - { - int id; - char* icon; - char* fact; - char* category; - gtk_tree_model_get(model, &iter, - ID, &id, - BTNCONT, &icon, - TITLE, &fact, - CATEGORY, &category, -1); - DBG("%s:%s:%s", fact, category, icon); - if(!strcmp(gtk_tree_view_column_get_title (column), "ed")) - { - GVariant *dummy = g_variant_new_int32(id); - GVariant *var = g_variant_new_variant(dummy); - window_server_call_edit_sync(view->windowserver, var, NULL, NULL); - } - else if(!strcmp(gtk_tree_view_column_get_title(column), "ct") && !strcmp(icon, "gtk-media-play")) - { - char fact_at_category[255]; - snprintf(fact_at_category, sizeof(fact_at_category), "%s@%s", fact, category); - DBG("Resume %s", fact_at_category); - hamster_call_add_fact_sync(view->hamster, fact_at_category, 0, 0, FALSE, &id, NULL, NULL); - } - g_free(icon); - g_free(fact); - g_free(category); - } - gtk_tree_path_free(path); + GVariant *dummy = g_variant_new_int32(id); + GVariant *var = g_variant_new_variant(dummy); + window_server_call_edit_sync(view->windowserver, var, NULL, NULL); } + else if (!strcmp(gtk_tree_view_column_get_title(column), "ct") && !strcmp(icon, "gtk-media-play")) + { + char fact_at_category[ MAX_FACT_LEN ]; + snprintf(fact_at_category, sizeof(fact_at_category), "%s@%s", fact, category); + DBG("Resume %s", fact_at_category); + hamster_call_add_fact_sync(view->hamster, fact_at_category, 0, 0, FALSE, &id, NULL, NULL); + } + g_free(icon); + g_free(fact); + g_free(category); } + gtk_tree_path_free(path); + return FALSE; } -static void -hview_cb_label_allocate( GtkWidget *label, - GtkAllocation *allocation, - HamsterView *view ) +static void hview_cb_label_allocate(GtkWidget *label, unused const GtkAllocation *allocation, HamsterView *view) { - if(gtk_widget_get_sensitive(view->treeview)) + if (gtk_widget_get_sensitive(view->treeview)) { - GtkRequisition req, unused; - gtk_widget_get_preferred_size(view->treeview, &req, &unused); - if(req.width > 0) - gtk_widget_set_size_request( label, req.width, -1); + GtkRequisition req; + GtkRequisition dummy; + gtk_widget_get_preferred_size(view->treeview, &req, &dummy); + if (req.width > 0) + { + gtk_widget_set_size_request(label, req.width, -1); + } } else { - gtk_widget_set_size_request( label, -1, -1 ); + gtk_widget_set_size_request(label, -1, -1); } } -static gboolean -hview_cb_key_pressed(GtkWidget *widget, - GdkEventKey *evt, - HamsterView *view) +static gboolean hview_cb_key_pressed(unused const GtkWidget *widget, const GdkEventKey *evt, HamsterView *view) { - //DBG("%d", evt->keyval); - if(evt->keyval == GDK_KEY_Escape) + if (evt->keyval == GDK_KEY_Escape && !view->inCellEdit) { - if (!view->inCellEdit) - { - hview_popup_hide(view); - } + hview_popup_hide(view); } + return FALSE; } -void -hview_cb_style_set(GtkWidget *widget, GtkStyle *previous, HamsterView *view) +void hview_cb_style_set(unused const GtkWidget *widget, unused const GtkStyle *previous, HamsterView *view) { - guint border = 5; - /* - GtkStyleContext* style = gtk_widget_get_style_context(view->button); - if(style) - border = (2 * MAX(style->xthickness, style->ythickness)) + 2; - */ + const guint border = 5; DBG("style-set %d", border); gtk_container_set_border_width(GTK_CONTAINER(view->vbx), border); } -static gboolean -hview_span_to_times(const char *duration, time_t *start_time, time_t *end_time) +static gboolean hview_span_to_times(const char *duration, time_t *start_time, time_t *end_time) { gboolean rVal = FALSE; if (NULL != start_time && NULL != end_time) { - struct tm sm, em; - time_t now; + struct tm sm; + struct tm em; + time_t now; time(&now); localtime_r(&now, &sm); em = sm; - switch ( // parse '09:30 - 14:30', accept '09:30' or '09:30 -' for ongoing - sscanf(duration, - "%02d:%02d - %02d:%02d", - &sm.tm_hour, &sm.tm_min, - &em.tm_hour, &em.tm_min - ) - ) + switch ( // parse '09:30 - 14:30', accept '09:30' or '09:30 -' for ongoing + sscanf(duration, "%02d:%02d - %02d:%02d", &sm.tm_hour, &sm.tm_min, &em.tm_hour, &em.tm_min)) { - case 2: // hh:mm OK - *start_time = timegm(&sm); - *end_time = 0; // hamster accepts 0 as ongoing - rVal = (-1 != *start_time); - break; - - case 4: // hh:mm - hh:mm OK - *start_time = timegm(&sm); - *end_time = timegm(&em); - rVal = (-1 != *start_time); - rVal &= (-1 != *end_time); - rVal &= (*end_time > *start_time); - break; - - default: - *start_time = -1; - *end_time = -1; - break; + case 2: // hh:mm OK + *start_time = timegm(&sm); + *end_time = 0; // hamster accepts 0 as ongoing + rVal = (-1 != *start_time); + break; + + case 4: // hh:mm - hh:mm OK + *start_time = timegm(&sm); + *end_time = timegm(&em); + rVal = (-1 != *start_time); + rVal &= (-1 != *end_time); + rVal &= (*end_time > *start_time); + break; + + default: + *start_time = -1; + *end_time = -1; + break; } } return rVal; } -static void -hview_cb_editing_done( - GtkCellEditable *cell_editable, - HamsterView *view) +static gboolean hview_editing_cancelled(GtkCellEditable *cell_editable) +{ + gboolean cancelled; + g_object_get(cell_editable, "editing-canceled", &cancelled, NULL); + return cancelled; +} + +static void hview_fact_update(HamsterView *view, int *id, const char *fact, gint start_time, gint stop_time) +{ + // hamster #671 merged upstream? + if (!hamster_call_update_fact_sync(view->hamster, *id, fact, start_time, stop_time, FALSE, id, NULL, NULL)) + { + DBG("UpdateFact did not work: remove, then add fact #%d", *id); + hamster_call_remove_fact_sync(view->hamster, *id, NULL, NULL); + hamster_call_add_fact_sync(view->hamster, fact, start_time, stop_time, FALSE, id, NULL, NULL); + DBG("UpdateFact worked: %d", *id); + return; + } + DBG("UpdateFact worked: new id=%d", *id); +} + + +static void hview_cb_editing_done(GtkCellEditable *cell_editable, HamsterView *view) { - if (GTK_IS_ENTRY(cell_editable)) + view->inCellEdit = FALSE; + + if (!GTK_IS_ENTRY(cell_editable)) + { + return; + } + + if (hview_editing_cancelled(cell_editable)) { - GtkEntry *entry = GTK_ENTRY(cell_editable); - gboolean cancelled; - g_object_get(cell_editable, "editing-canceled", &cancelled, NULL); - const char *type = (const char*)g_object_get_data(G_OBJECT(cell_editable), "type"); - const char *val = gtk_entry_get_text(entry); - DBG("%s:val=%s, type=%s", - cancelled ? "CANCEL" : "DONE", - val, - type - ); - - if (!cancelled) + return; + } + + GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view->treeview)); + GtkTreeModel *model = NULL; + GtkTreeIter iter; + if (!gtk_tree_selection_get_selected(selection, &model, &iter)) + { + return; + } + int id; + const char *fact; + const char *category; + const char *duration; + time_t start_time; + time_t stop_time; + gtk_tree_model_get(model, &iter, ID, &id, TIME_SPAN, &duration, TITLE, &fact, CATEGORY, &category, -1); + + DBG("old: %d:%s:%s:%s", id, duration, fact, category); + + const char *type = (const char *)g_object_get_data(G_OBJECT(cell_editable), "type"); + const char *val = gtk_entry_get_text(GTK_ENTRY(cell_editable)); + if (!strcmp("fact", type)) + { + if (!strcmp(fact, val)) { - GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view->treeview)); - GtkTreeModel *model = NULL; - GtkTreeIter iter; - if (gtk_tree_selection_get_selected(selection, &model, &iter)) - { - int id; - const char* fact; - const char* category; - const char* duration; - time_t start_time, stop_time; - gtk_tree_model_get(model, &iter, - ID, &id, - TIME_SPAN, &duration, - TITLE, &fact, - CATEGORY, &category, - -1); - - DBG("old: %d:%s:%s:%s", id, duration, fact, category); - - if (!strcmp("fact", type)) - { - if (!strcmp(fact, val)) - { - DBG("No change ACK of fact"); - cancelled = TRUE; - } - else - { - fact = hview_get_fact_by_activity(view, val, NULL); - } - } - else if(!strcmp("date", type)) - { - if (!strcmp(duration, val)) - { - DBG("No change ACK of duration"); - cancelled = TRUE; - } - else - { - fact = hview_get_fact_by_activity(view, fact, category); - duration = val; - } - } - if (!cancelled) - { - if (hview_span_to_times(duration, &start_time, &stop_time)) - { - // hamster #671 merged upstream? - if (hamster_call_update_fact_sync(view->hamster, - id, fact, start_time, stop_time, FALSE, &id, NULL, NULL)) - { - DBG("UpdateFact worked: new id=%d", id); - } - else - { - DBG("UpdateFact did not work: remove, then add fact #%d", id); - hamster_call_remove_fact_sync(view->hamster, id, NULL, NULL); - hamster_call_add_fact_sync(view->hamster, - fact, start_time, stop_time, FALSE, &id, NULL, NULL); - DBG("UpdateFact worked: %d", id); - } - } - else - { - DBG("Duration '%s' did not parse.", duration); - } - } - } + DBG("No change ACK of fact"); + return; } + + fact = hview_get_fact_by_activity(view, val, NULL); + } + else if (!strcmp("date", type)) + { + if (!strcmp(duration, val)) + { + DBG("No change ACK of duration"); + return; + } + + fact = hview_get_fact_by_activity(view, fact, category); + duration = val; + } + if (hview_span_to_times(duration, &start_time, &stop_time)) + { + hview_fact_update(view, &id, fact, (gint)start_time, (gint)stop_time); + } + else + { + DBG("Duration '%s' did not parse.", duration); } - view->inCellEdit = FALSE; } -static GtkEntryCompletion * -hview_completion_new(HamsterView *view, GtkEntry *entry) +static GtkEntryCompletion *hview_completion_new(HamsterView *view, GtkEntry *entry) { GtkEntryCompletion *completion = gtk_entry_completion_new(); - g_signal_connect(completion, "match-selected", - G_CALLBACK(hview_cb_match_select), view); + g_signal_connect(completion, "match-selected", G_CALLBACK(hview_cb_match_select), view); gtk_entry_completion_set_text_column(completion, 0); gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(view->storeActivities)); gtk_entry_set_completion(entry, completion); @@ -540,49 +492,48 @@ hview_completion_new(HamsterView *view, GtkEntry *entry) return completion; } -static void -hview_cb_cell_editing_started( - GtkCellRenderer *cell, - GtkCellEditable *editable, - const gchar *path, - HamsterView *view) +static void hview_cb_cell_editing_started(GtkCellRenderer *cell, + GtkCellEditable *editable, + const gchar *path, + HamsterView *view) { if (GTK_IS_ENTRY(editable)) { GtkEntry *entry = GTK_ENTRY(editable); - char *type = g_object_get_data(G_OBJECT(cell), "type"); + char *type = g_object_get_data(G_OBJECT(cell), "type"); DBG("path=%s type=%s", path, type); g_object_set_data_full(G_OBJECT(editable), "path", g_strdup(path), g_free); g_object_set_data(G_OBJECT(editable), "type", type); - if (0 == strcmp("fact", type)) + if (0 == strcmp("fact", type) && NULL == gtk_entry_get_completion(entry)) { - if (NULL == gtk_entry_get_completion(entry)) - { - hview_completion_new(view, entry); - } + hview_completion_new(view, entry); } - g_signal_connect(entry, "editing-done", - G_CALLBACK(hview_cb_editing_done), view); + + g_signal_connect(entry, "editing-done", G_CALLBACK(hview_cb_editing_done), view); view->inCellEdit = TRUE; } } -static void -hview_popup_new(HamsterView *view) +static void hview_popup_new(HamsterView *view) { - GtkWidget *frm, *lbl, *ovw, *stp, *add, *cfg; - GtkCellRenderer *renderer; + GtkWidget *frm; + GtkWidget *lbl; + GtkWidget *ovw; + GtkWidget *stp; + GtkWidget *add; + GtkWidget *cfg; + GtkCellRenderer *renderer; GtkTreeViewColumn *column; + /* Create a new popup */ view->popup = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_type_hint(GTK_WINDOW(view->popup), GDK_WINDOW_TYPE_HINT_UTILITY); gtk_window_set_decorated(GTK_WINDOW(view->popup), FALSE); gtk_window_set_resizable(GTK_WINDOW(view->popup), FALSE); gtk_window_set_position(GTK_WINDOW(view->popup), GTK_WIN_POS_MOUSE); - gtk_window_set_screen(GTK_WINDOW(view->popup), - gtk_widget_get_screen(view->button)); + gtk_window_set_screen(GTK_WINDOW(view->popup), gtk_widget_get_screen(view->button)); gtk_window_set_skip_pager_hint(GTK_WINDOW(view->popup), TRUE); gtk_window_set_skip_taskbar_hint(GTK_WINDOW(view->popup), TRUE); gtk_window_set_keep_above(GTK_WINDOW(view->popup), TRUE); @@ -595,21 +546,18 @@ hview_popup_new(HamsterView *view) view->vbx = gtk_box_new(GTK_ORIENTATION_VERTICAL, 1); gtk_container_add(GTK_CONTAINER(frm), view->vbx); /* handle ESC */ - g_signal_connect(view->popup, "key-press-event", - G_CALLBACK(hview_cb_key_pressed), view); + g_signal_connect(view->popup, "key-press-event", G_CALLBACK(hview_cb_key_pressed), view); // subtitle lbl = gtk_label_new(_("What goes on?")); gtk_container_add(GTK_CONTAINER(view->vbx), lbl); // entry - view->entry = gtk_entry_new(); - g_object_set_data(G_OBJECT(view->entry), "type", "new"); - g_signal_connect(view->completion, "match-selected", - G_CALLBACK(hview_cb_match_select), view); - g_signal_connect(view->entry, "activate", - G_CALLBACK(hview_cb_entry_activate), view); + view->entry = gtk_entry_new(); view->completion = hview_completion_new(view, GTK_ENTRY(view->entry)); + g_object_set_data(G_OBJECT(view->entry), "type", "new"); + g_signal_connect(view->completion, "match-selected", G_CALLBACK(hview_cb_match_select), view); + g_signal_connect(view->entry, "activate", G_CALLBACK(hview_cb_entry_activate), view); gtk_container_add(GTK_CONTAINER(view->vbx), view->entry); // label @@ -624,57 +572,38 @@ hview_popup_new(HamsterView *view) gtk_widget_set_can_focus(view->treeview, TRUE); gtk_tree_view_set_grid_lines(GTK_TREE_VIEW(view->treeview), GTK_TREE_VIEW_GRID_LINES_NONE); - g_signal_connect(view->treeview, "query-tooltip", - G_CALLBACK(hview_cb_tv_query_tooltip), view); - g_signal_connect(view->treeview, "button-release-event", - G_CALLBACK(hview_cb_tv_button_press), view); + g_signal_connect(view->treeview, "query-tooltip", G_CALLBACK(hview_cb_tv_query_tooltip), view); + g_signal_connect(view->treeview, "button-release-event", G_CALLBACK(hview_cb_tv_button_press), view); // time column renderer = gtk_cell_renderer_text_new(); g_object_set(renderer, "editable", TRUE, NULL); g_object_set_data(G_OBJECT(renderer), "type", "date"); - g_signal_connect(renderer, "editing-started", - G_CALLBACK(hview_cb_cell_editing_started), view); + g_signal_connect(renderer, "editing-started", G_CALLBACK(hview_cb_cell_editing_started), view); - column = gtk_tree_view_column_new_with_attributes("Time", - renderer, - "text", TIME_SPAN, - NULL); + column = gtk_tree_view_column_new_with_attributes("Time", renderer, "text", TIME_SPAN, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(view->treeview), column); // fact column renderer = gtk_cell_renderer_text_new(); g_object_set(renderer, "editable", TRUE, NULL); g_object_set_data(G_OBJECT(renderer), "type", "fact"); - g_signal_connect(renderer, "editing-started", - G_CALLBACK(hview_cb_cell_editing_started), view); - column = gtk_tree_view_column_new_with_attributes("Name", - renderer, - "text", TITLE, - NULL); + g_signal_connect(renderer, "editing-started", G_CALLBACK(hview_cb_cell_editing_started), view); + column = gtk_tree_view_column_new_with_attributes("Name", renderer, "text", TITLE, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(view->treeview), column); - + // duration column - renderer = gtk_cell_renderer_text_new(); // back to readonly, calculated - column = gtk_tree_view_column_new_with_attributes("Duration", - renderer, - "text", DURATION, - NULL); + renderer = gtk_cell_renderer_text_new(); // back to readonly, calculated + column = gtk_tree_view_column_new_with_attributes("Duration", renderer, "text", DURATION, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(view->treeview), column); gtk_tree_view_column_set_clickable(column, FALSE); - + // button columns renderer = gtk_cell_renderer_pixbuf_new(); - column = gtk_tree_view_column_new_with_attributes("ed", - renderer, - "stock-id", BTNEDIT, - NULL); + column = gtk_tree_view_column_new_with_attributes("ed", renderer, "stock-id", BTNEDIT, NULL); g_object_set_data(G_OBJECT(column), "tip", _("Edit activity")); gtk_tree_view_append_column(GTK_TREE_VIEW(view->treeview), column); - column = gtk_tree_view_column_new_with_attributes("ct", - renderer, - "stock-id", BTNCONT, - NULL); + column = gtk_tree_view_column_new_with_attributes("ct", renderer, "stock-id", BTNCONT, NULL); g_object_set_data(G_OBJECT(column), "tip", _("Resume activity")); gtk_tree_view_append_column(GTK_TREE_VIEW(view->treeview), column); gtk_container_add(GTK_CONTAINER(view->vbx), view->treeview); @@ -685,37 +614,32 @@ hview_popup_new(HamsterView *view) gtk_label_set_line_wrap(GTK_LABEL(view->summary), TRUE); gtk_label_set_justify(GTK_LABEL(view->summary), GTK_JUSTIFY_RIGHT); gtk_container_add(GTK_CONTAINER(view->vbx), view->summary); - g_signal_connect(G_OBJECT(view->summary), "size-allocate", - G_CALLBACK(hview_cb_label_allocate), view); + g_signal_connect(G_OBJECT(view->summary), "size-allocate", G_CALLBACK(hview_cb_label_allocate), view); // menuish buttons ovw = gtk_button_new_with_label(_("Show overview")); gtk_widget_set_halign(gtk_bin_get_child(GTK_BIN(ovw)), GTK_ALIGN_START); gtk_button_set_relief(GTK_BUTTON(ovw), GTK_RELIEF_NONE); gtk_widget_set_focus_on_click(ovw, FALSE); - g_signal_connect(ovw, "clicked", - G_CALLBACK(hview_cb_show_overview), view); + g_signal_connect(ovw, "clicked", G_CALLBACK(hview_cb_show_overview), view); stp = gtk_button_new_with_label(_("Stop tracking")); gtk_widget_set_halign(gtk_bin_get_child(GTK_BIN(stp)), GTK_ALIGN_START); gtk_button_set_relief(GTK_BUTTON(stp), GTK_RELIEF_NONE); gtk_widget_set_focus_on_click(stp, FALSE); - g_signal_connect(stp, "clicked", - G_CALLBACK(hview_cb_stop_tracking), view); + g_signal_connect(stp, "clicked", G_CALLBACK(hview_cb_stop_tracking), view); add = gtk_button_new_with_label(_("Add earlier activity")); gtk_widget_set_halign(gtk_bin_get_child(GTK_BIN(add)), GTK_ALIGN_START); gtk_button_set_relief(GTK_BUTTON(add), GTK_RELIEF_NONE); gtk_widget_set_focus_on_click(add, FALSE); - g_signal_connect(add, "clicked", - G_CALLBACK(hview_cb_add_earlier_activity), view); + g_signal_connect(add, "clicked", G_CALLBACK(hview_cb_add_earlier_activity), view); cfg = gtk_button_new_with_label(_("Tracking settings")); gtk_widget_set_halign(gtk_bin_get_child(GTK_BIN(cfg)), GTK_ALIGN_START); gtk_button_set_relief(GTK_BUTTON(cfg), GTK_RELIEF_NONE); gtk_widget_set_focus_on_click(cfg, FALSE); - g_signal_connect(cfg, "clicked", - G_CALLBACK(hview_cb_tracking_settings), view); + g_signal_connect(cfg, "clicked", G_CALLBACK(hview_cb_tracking_settings), view); gtk_box_pack_start(GTK_BOX(view->vbx), ovw, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(view->vbx), stp, FALSE, FALSE, 0); @@ -724,51 +648,40 @@ hview_popup_new(HamsterView *view) gtk_widget_show_all(view->popup); - g_signal_connect(G_OBJECT(view->popup), - "focus-out-event", - G_CALLBACK(hview_cb_popup_focus_out), - view); + g_signal_connect(G_OBJECT(view->popup), "focus-out-event", G_CALLBACK(hview_cb_popup_focus_out), view); - g_signal_connect(G_OBJECT(view->button), "style-set", - G_CALLBACK(hview_cb_style_set), view); + g_signal_connect(G_OBJECT(view->button), "style-set", G_CALLBACK(hview_cb_style_set), view); hview_cb_style_set(view->button, NULL, view); } -static void -hview_completion_mode_update(HamsterView *view) +static void hview_completion_mode_update(HamsterView *view) { - view->dropdown = - xfconf_channel_get_bool(view->channel, XFPROP_DROPDOWN, FALSE); + view->dropdown = xfconf_channel_get_bool(view->channel, XFPROP_DROPDOWN, FALSE); - if(view->entry && gtk_widget_get_realized(view->entry)) + if (view->entry && gtk_widget_get_realized(view->entry)) { - GtkEntryCompletion *completion = gtk_entry_get_completion( - GTK_ENTRY(view->entry)); + GtkEntryCompletion *completion = gtk_entry_get_completion(GTK_ENTRY(view->entry)); gtk_entry_completion_set_inline_completion(completion, !view->dropdown); gtk_entry_completion_set_popup_completion(completion, view->dropdown); } } -static void -hview_autohide_mode_update(HamsterView *view) +static void hview_autohide_mode_update(HamsterView *view) { - view->donthide = - xfconf_channel_get_bool(view->channel, XFPROP_DONTHIDE, FALSE); + view->donthide = xfconf_channel_get_bool(view->channel, XFPROP_DONTHIDE, FALSE); } -static void -hview_tooltips_mode_update(HamsterView *view) +static void hview_tooltips_mode_update(HamsterView *view) { - view->tooltips = - xfconf_channel_get_bool(view->channel, XFPROP_TOOLTIPS, TRUE); + view->tooltips = xfconf_channel_get_bool(view->channel, XFPROP_TOOLTIPS, TRUE); } /* Actions */ -void -hview_popup_show(HamsterView *view, gboolean atPointer) +void hview_popup_show(HamsterView *view, gboolean atPointer) { - int x = 0, y = 0; + int x = 0; + int y = 0; /* check if popup is needed, or it needs an update */ if (view->popup == NULL) @@ -784,12 +697,14 @@ hview_popup_show(HamsterView *view, gboolean atPointer) hview_tooltips_mode_update(view); hview_completion_mode_update(view); } - else if(view->alive) + else if (view->alive) { DBG("alive"); - if(view->donthide) + if (view->donthide) + { gdk_window_raise(gtk_widget_get_window(view->popup)); - if(view->sourceTimeout) + } + if (view->sourceTimeout) { g_source_remove(view->sourceTimeout); view->sourceTimeout = 0; @@ -807,67 +722,63 @@ hview_popup_show(HamsterView *view, gboolean atPointer) hview_tooltips_mode_update(view); /* popup popup */ - if(atPointer) + if (atPointer) { DBG("atpointer"); - GdkDisplay* display = gdk_display_get_default(); - GdkSeat* seat = gdk_display_get_default_seat(display); - GdkDevice* pointer = gdk_seat_get_pointer(seat); + GdkDisplay *display = gdk_display_get_default(); + GdkSeat *seat = gdk_display_get_default_seat(display); + GdkDevice *pointer = gdk_seat_get_pointer(seat); - gdk_device_get_position (pointer, NULL, &x, &y); + gdk_device_get_position(pointer, NULL, &x, &y); } else { DBG("atpanel"); - GdkWindow* popup = gtk_widget_get_window(view->popup); - GdkWindow* button = gtk_widget_get_window(view->button); - xfce_panel_plugin_position_widget (view->plugin, view->button, NULL, &x,&y); - switch(xfce_panel_plugin_get_orientation(view->plugin)) + GdkWindow *popup = gtk_widget_get_window(view->popup); + GdkWindow *button = gtk_widget_get_window(view->button); + xfce_panel_plugin_position_widget(view->plugin, view->button, NULL, &x, &y); + switch (xfce_panel_plugin_get_orientation(view->plugin)) { case GTK_ORIENTATION_HORIZONTAL: - x += gdk_window_get_width(button) / 2; - x -= gdk_window_get_width(popup) / 2; - break; + x += gdk_window_get_width(button) / 2; + x -= gdk_window_get_width(popup) / 2; + break; case GTK_ORIENTATION_VERTICAL: - y += gdk_window_get_height(button) / 2; - y -= gdk_window_get_height(popup) / 2; - break; + y += gdk_window_get_height(button) / 2; + y -= gdk_window_get_height(popup) / 2; + break; } } DBG("move x=%d, y=%d", x, y); gtk_window_move(GTK_WINDOW(view->popup), x, y); - gtk_window_present_with_time(GTK_WINDOW(view->popup), - gtk_get_current_event_time()); - gtk_widget_add_events(view->popup, GDK_FOCUS_CHANGE_MASK|GDK_KEY_PRESS_MASK); + gtk_window_present_with_time(GTK_WINDOW(view->popup), gtk_get_current_event_time()); + gtk_widget_add_events(view->popup, GDK_FOCUS_CHANGE_MASK | GDK_KEY_PRESS_MASK); } // Hours and minutes format when given INT_MAX produces "596523h 14min", but // "snprintf" reports max possible output size like below. const int HOURS_AND_MINUTES_MIN_LENGTH = 16; -static void -hview_seconds_to_hours_and_minutes(gchar *duration, int length, int seconds) +static void hview_seconds_to_hours_and_minutes(char *duration, size_t length, int seconds) { - snprintf(duration, length, - "%dh %dmin", seconds / 3600, (seconds / 60) % 60); + snprintf(duration, length, _("%dh %dmin"), seconds / secsperhour, (seconds / secspermin) % secspermin); } -static size_t -hview_time_to_string(char *str, size_t maxsize, time_t time) +static size_t hview_time_to_string(char *str, size_t maxsize, time_t time) { - struct tm *tm = gmtime(&time); + struct tm tm; + gmtime_r(&time, &tm); - return strftime(str, maxsize, "%H:%M", tm); + return strftime(str, maxsize, "%H:%M", &tm); } // Using less than that may cause output to be truncated. const int HVIEW_TIMES_TO_SPAN_MIN_BUF_SIZE = 14; -static void -hview_times_to_span(char *time_span, size_t maxsize, time_t start_time, time_t end_time) +static void hview_times_to_span(char *time_span, size_t maxsize, time_t start_time, time_t end_time) { - char *ptr = time_span; + char *ptr = time_span; size_t charsWritten; charsWritten = hview_time_to_string(ptr, maxsize, start_time); @@ -880,206 +791,245 @@ hview_times_to_span(char *time_span, size_t maxsize, time_t start_time, time_t e ptr += dataWritten; if (end_time) - hview_time_to_string(ptr, maxsize, end_time); + { + hview_time_to_string(ptr, maxsize, end_time); + } } -static gint* -hview_create_category(gchar *category, GHashTable *categories) +static gint *hview_create_category(const char *category, GHashTable *categories) { - gint *duration_in_seconds = g_new0(gint, 1); - g_hash_table_insert(categories, strdup(category), duration_in_seconds); + gint *duration_in_seconds = g_new0(gint, 1); + g_hash_table_insert(categories, strdup(category), duration_in_seconds); - return duration_in_seconds; + return duration_in_seconds; } -static void -hview_increment_category_time(gchar *category, gint duration_in_seconds, GHashTable *categories) +static void hview_increment_category_time(gchar const *category, gint duration_in_seconds, GHashTable *categories) { - gint *category_duration = g_hash_table_lookup(categories, category); - if(category_duration == NULL) - { - category_duration = hview_create_category(category, categories); - } + gint *category_duration = g_hash_table_lookup(categories, category); + if (category_duration == NULL) + { + category_duration = hview_create_category(category, categories); + } - *category_duration += duration_in_seconds; + *category_duration += duration_in_seconds; } -static gboolean -hview_activity_stopped(fact *activity) +static gboolean hview_activity_stopped(fact const *activity) { - if(activity->endTime) - return TRUE; + if (activity->endTime) + { + return TRUE; + } - return FALSE; + return FALSE; } -static void -hview_store_update(HamsterView *view, fact *activity, GHashTable *categories) +static void hview_store_update(HamsterView *view, fact *activity, GHashTable *categories) { - if(NULL == view->storeFacts) + if (NULL == view->storeFacts) + { return; + } - gchar time_span[HVIEW_TIMES_TO_SPAN_MIN_BUF_SIZE]; + gchar time_span[ HVIEW_TIMES_TO_SPAN_MIN_BUF_SIZE ]; hview_times_to_span(time_span, sizeof(time_span), activity->startTime, activity->endTime); - gchar duration[HOURS_AND_MINUTES_MIN_LENGTH]; + gchar duration[ HOURS_AND_MINUTES_MIN_LENGTH ]; hview_seconds_to_hours_and_minutes(duration, sizeof(duration), activity->seconds); - GtkTreeIter iter; - gtk_list_store_append (view->storeFacts, &iter); /* Acquire an iterator */ - gtk_list_store_set (view->storeFacts, &iter, - TIME_SPAN, time_span, - TITLE, activity->name, - DURATION, duration, - BTNEDIT, "gtk-edit", - BTNCONT, hview_activity_stopped(activity) ? "gtk-media-play" : "", - ID, activity->id, - CATEGORY, activity->category, - -1); + GtkTreeIter iter; + gtk_list_store_append(view->storeFacts, &iter); /* Acquire an iterator */ + gtk_list_store_set(view->storeFacts, + &iter, + TIME_SPAN, + time_span, + TITLE, + activity->name, + DURATION, + duration, + BTNEDIT, + "gtk-edit", + BTNCONT, + hview_activity_stopped(activity) ? "gtk-media-play" : "", + ID, + activity->id, + CATEGORY, + activity->category, + -1); hview_increment_category_time(activity->category, activity->seconds, categories); } -static void -hview_summary_update(HamsterView *view, GHashTable *tbl) +static void hview_summary_update(HamsterView *view, GHashTable *tbl) { GHashTableIter iter; - GString *string = g_string_new(""); - gchar *cat; - gint *sum; - guint count; + GString *string = g_string_new(""); + gchar *cat; + gint *sum; + guint count; - if(tbl) + if (tbl) { count = g_hash_table_size(tbl); + gtk_widget_set_sensitive(view->treeview, count > 0); g_hash_table_iter_init(&iter, tbl); - while(g_hash_table_iter_next(&iter, (gpointer)&cat, (gpointer)&sum)) + while (g_hash_table_iter_next(&iter, (gpointer)&cat, (gpointer)&sum)) { count--; - g_string_append_printf(string, count ? "%s: %dh %dmin, " : "%s: %dh %dmin", - cat, *sum / 3600, (*sum / 60) % 60); + g_string_append_printf(string, + count ? "%s: %dh %dmin, " : "%s: %dh %dmin", + cat, + *sum / secsperhour, + (*sum / secspermin) % secspermin); } } else { g_string_append(string, _("No activities yet.")); + gtk_widget_set_sensitive(view->treeview, FALSE); } gtk_label_set_label(GTK_LABEL(view->summary), string->str); g_string_free(string, TRUE); } -static void -hview_completion_update(HamsterView *view) +static void hview_completion_update(HamsterView *view) { GVariant *res; - if(view->inCellEdit) + if (view->inCellEdit) + { return; + } - if(NULL != view->storeActivities) + if (NULL != view->storeActivities) + { gtk_list_store_clear(view->storeActivities); + } - if(NULL != view->hamster) + if (NULL == view->hamster) { - if(hamster_call_get_activities_sync(view->hamster, "", &res, NULL, NULL)) - { - gsize count = 0; - if(NULL != res && (count = g_variant_n_children(res))) - { - gsize i; - for(i=0; i< count; i++) - { - GtkTreeIter iter; - GVariant *dbusAct = g_variant_get_child_value(res, i); - gchar *act, *cat, *actlow; - g_variant_get(dbusAct, "(ss)", &act, &cat); - actlow = g_utf8_casefold(act, -1); - gtk_list_store_append(view->storeActivities, &iter); - gtk_list_store_set(view->storeActivities, &iter, - 0, actlow, 1, cat, -1); - g_free(actlow); - } - g_variant_unref(res); - } - } + return; + } + + if (!hamster_call_get_activities_sync(view->hamster, "", &res, NULL, NULL) || NULL == res) + { + return; + } + + for (gsize i = 0; i < g_variant_n_children(res); i++) + { + GtkTreeIter iter; + GVariant *dbusAct = g_variant_get_child_value(res, i); + gchar *act; + gchar *cat; + gchar *actlow; + g_variant_get(dbusAct, "(ss)", &act, &cat); + actlow = g_utf8_casefold(act, -1); + gtk_list_store_append(view->storeActivities, &iter); + gtk_list_store_set(view->storeActivities, &iter, 0, actlow, 1, cat, -1); + g_free(actlow); } + g_variant_unref(res); } -static void -hview_button_update(HamsterView *view) +static gsize hview_get_facts(HamsterView *view, GVariant **res) { - GVariant *res; gsize count = 0; - gboolean ellipsize; + if (NULL == view->hamster) + { + return count; + } + + if (hamster_call_get_todays_facts_sync(view->hamster, res, NULL, NULL) && NULL != *res) + { + count = g_variant_n_children(*res); + } + return count; +} + +static void hview_label_update(HamsterView *view, fact *last) +{ + gboolean ellipsize = xfconf_channel_get_bool(view->channel, XFPROP_SANITIZE, FALSE); + places_button_set_ellipsize(PLACES_BUTTON(view->button), ellipsize); - if(view->inCellEdit) + if (NULL == last || 0 != last->endTime) + { + places_button_set_label(PLACES_BUTTON(view->button), _("inactive")); + if (view->alive) + { + gtk_window_resize(GTK_WINDOW(view->popup), 1, 1); + } return; + } - if(NULL != view->storeFacts) - gtk_list_store_clear(view->storeFacts); - - if(NULL != view->hamster) + gchar label[ MAX_FACT_LEN ]; + snprintf(label, + sizeof(label), + "%s %d:%02d", + last->name, + last->seconds / secsperhour, + (last->seconds / secspermin) % secspermin); + places_button_set_label(PLACES_BUTTON(view->button), label); +} + +static void hview_button_update(HamsterView *view) +{ + if (view->inCellEdit) { - ellipsize = xfconf_channel_get_bool(view->channel, XFPROP_SANITIZE, FALSE); - places_button_set_ellipsize(PLACES_BUTTON(view->button), ellipsize); + return; + } + + if (NULL != view->storeFacts) + { + gtk_list_store_clear(view->storeFacts); + } - if(hamster_call_get_todays_facts_sync(view->hamster, &res, NULL, NULL)) + GVariant *res; + gsize count = hview_get_facts(view, &res); + DBG("count=%lu", count); + if (count) + { + GHashTable *tbl = g_hash_table_new(g_str_hash, g_str_equal); + for (gsize i = 0; i < count; i++) { - if(NULL != res && (count = g_variant_n_children(res))) + GVariant *dbusFact = g_variant_get_child_value(res, i); + fact *last = fact_new(dbusFact); + g_variant_unref(dbusFact); + hview_store_update(view, last, tbl); + if (last->id && i == count - 1) { - gsize i; - GHashTable *tbl = g_hash_table_new(g_str_hash, g_str_equal); - gtk_widget_set_sensitive(view->treeview, TRUE); - for(i = 0; i < count; i++) - { - GVariant *dbusFact = g_variant_get_child_value(res, i); - fact *last = fact_new(dbusFact); - g_variant_unref(dbusFact); - hview_store_update(view, last, tbl); - if(last->id && i == count -1) - { - hview_summary_update(view, tbl); - if(0 == last->endTime) - { - gchar label[128]; - snprintf(label, sizeof(label), "%s %d:%02d", - last->name, - last->seconds / 3600, - (last->seconds/60) % 60); - places_button_set_label(PLACES_BUTTON(view->button), label); - fact_free(last); - g_hash_table_unref(tbl); - return; - } - } - fact_free(last); - } - g_hash_table_unref(tbl); + hview_summary_update(view, tbl); + hview_label_update(view, last); } + fact_free(last); } - gtk_window_resize(GTK_WINDOW(view->popup), 1, 1); + g_hash_table_unref(tbl); + return; } - places_button_set_label(PLACES_BUTTON(view->button), _("inactive")); - if (!count) - hview_summary_update(view, NULL); - gtk_widget_set_sensitive(view->treeview, count > 0); + + hview_summary_update(view, NULL); + hview_label_update(view, NULL); } -static gboolean -hview_cb_button_pressed(GtkWidget *widget, GdkEventButton *evt, HamsterView *view) +static gboolean hview_cb_button_pressed(unused const GtkWidget *widget, const GdkEventButton *evt, HamsterView *view) { /* (it's the way xfdesktop popup does it...) */ - if ((evt->state & GDK_CONTROL_MASK) - && !(evt->state & (GDK_MOD1_MASK | GDK_SHIFT_MASK | GDK_MOD4_MASK))) + if ((evt->state & GDK_CONTROL_MASK) && !(evt->state & (GDK_MOD1_MASK | GDK_SHIFT_MASK | GDK_MOD4_MASK))) + { return FALSE; + } if (evt->button == 1) { - gboolean isActive = gtk_toggle_button_get_active( - GTK_TOGGLE_BUTTON(view->button)); + gboolean isActive = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(view->button)); if (isActive) + { hview_popup_hide(view); + } else + { hview_popup_show(view, FALSE); + } } else if (evt->button == 2) { @@ -1089,53 +1039,52 @@ hview_cb_button_pressed(GtkWidget *widget, GdkEventButton *evt, HamsterView *vie return TRUE; } -static gboolean -hview_cb_hamster_changed(Hamster *hamster, HamsterView *view) +static gboolean hview_cb_hamster_changed(Hamster *hamster, HamsterView *view) { - DBG("dbus-callback %p", view); + DBG("dbus-callback %p->%p", hamster, view); hview_button_update(view); hview_completion_update(view); return FALSE; } -static gboolean -hview_cb_cyclic(HamsterView *view) +static gboolean hview_cb_cyclic(HamsterView *view) { hview_button_update(view); return TRUE; } -static void -hview_cb_channel(XfconfChannel *channel, - gchar *property, - GValue *value, - HamsterView *view) +static void hview_cb_channel(XfconfChannel *channel, gchar *property, GValue const *value, HamsterView *view) { - DBG("%s=%d", property, g_value_get_boolean(value)); - if(!strcmp(property, XFPROP_DROPDOWN)) + DBG("%s=%d, locked=%d", property, xfconf_channel_is_property_locked(channel, property), g_value_get_boolean(value)); + if (!strcmp(property, XFPROP_DROPDOWN)) + { hview_completion_mode_update(view); - else if(!strcmp(property, XFPROP_DONTHIDE)) + } + else if (!strcmp(property, XFPROP_DONTHIDE)) + { hview_autohide_mode_update(view); - else if(!strcmp(property, XFPROP_TOOLTIPS)) + } + else if (!strcmp(property, XFPROP_TOOLTIPS)) + { hview_tooltips_mode_update(view); - else if(!strcmp(property, XFPROP_SANITIZE)) + } + else if (!strcmp(property, XFPROP_SANITIZE)) + { hview_button_update(view); - + } } -HamsterView* -hamster_view_init(XfcePanelPlugin* plugin) +HamsterView *hamster_view_init(XfcePanelPlugin *plugin) { HamsterView *view; g_assert(plugin != NULL); - view = g_new0(HamsterView, 1); - view->plugin = plugin; + view = g_new0(HamsterView, 1); + view->plugin = plugin; DBG("initializing %p", view); /* init button */ - DBG("init GUI"); /* create the button */ @@ -1145,48 +1094,39 @@ hamster_view_init(XfcePanelPlugin* plugin) gtk_widget_show(view->button); /* button signal */ - g_signal_connect(view->button, "button-press-event", - G_CALLBACK(hview_cb_button_pressed), view); + g_signal_connect(view->button, "button-press-event", G_CALLBACK(hview_cb_button_pressed), view); - g_timeout_add_seconds(60, (GSourceFunc)hview_cb_cyclic, view); + g_timeout_add_seconds(secspermin, (GSourceFunc)hview_cb_cyclic, view); /* remote control */ - view->hamster = hamster_proxy_new_for_bus_sync - ( - G_BUS_TYPE_SESSION, - G_DBUS_PROXY_FLAGS_NONE, - "org.gnome.Hamster", /* bus name */ - "/org/gnome/Hamster", /* object */ - NULL, /* GCancellable* */ - NULL); - - g_signal_connect(view->hamster, "facts-changed", - G_CALLBACK(hview_cb_hamster_changed), view); - g_signal_connect(view->hamster, "activities-changed", - G_CALLBACK(hview_cb_hamster_changed), view); - - view->windowserver = window_server_proxy_new_for_bus_sync - ( - G_BUS_TYPE_SESSION, - G_DBUS_PROXY_FLAGS_NONE, - "org.gnome.Hamster.WindowServer", /* bus name */ - "/org/gnome/Hamster/WindowServer", /* object */ - NULL, /* GCancellable* */ - NULL); + view->hamster = hamster_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_NONE, + "org.gnome.Hamster", /* bus name */ + "/org/gnome/Hamster", /* object */ + NULL, /* GCancellable */ + NULL); + + g_signal_connect(view->hamster, "facts-changed", G_CALLBACK(hview_cb_hamster_changed), view); + g_signal_connect(view->hamster, "activities-changed", G_CALLBACK(hview_cb_hamster_changed), view); + + view->windowserver = window_server_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_NONE, + "org.gnome.Hamster.WindowServer", /* bus name */ + "/org/gnome/Hamster/WindowServer", /* object */ + NULL, /* GCancellable */ + NULL); /* storage */ view->storeActivities = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING); - view->storeFacts = gtk_list_store_new(NUM_COL, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, - G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING); - view->summary = gtk_label_new(NULL); + view->storeFacts = gtk_list_store_new( + NUM_COL, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING); + view->summary = gtk_label_new(NULL); view->treeview = gtk_tree_view_new(); /* config */ view->channel = xfce_panel_plugin_xfconf_channel_new(view->plugin); - g_signal_connect(view->channel, "property-changed", - G_CALLBACK(hview_cb_channel), view); - g_signal_connect(view->plugin, "configure-plugin", - G_CALLBACK(config_show), view->channel); + g_signal_connect(view->channel, "property-changed", G_CALLBACK(hview_cb_channel), view); + g_signal_connect(view->plugin, "configure-plugin", G_CALLBACK(config_show), view->channel); xfce_panel_plugin_menu_show_configure(view->plugin); /* time helpers */ @@ -1201,10 +1141,7 @@ hamster_view_init(XfcePanelPlugin* plugin) return view; } -void -hamster_view_finalize(HamsterView* view) +void hamster_view_finalize(HamsterView *view) { g_free(view); } - - diff --git a/panel-plugin/view.h b/panel-plugin/view.h index 2b1e2a1..4b34a99 100644 --- a/panel-plugin/view.h +++ b/panel-plugin/view.h @@ -1,6 +1,6 @@ /* xfce4-hamster-plugin * - * Copyright (c) 2014 Hakan Erduman + * Copyright (c) 2014-2023 Hakan Erduman * * 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 @@ -38,6 +38,3 @@ config_show(XfcePanelPlugin *plugin, HamsterView *view); /* view.c */ void hview_popup_show(HamsterView *view, gboolean atPointer); - -/* vim: set ai et tabstop=4: */ - diff --git a/po/cs.po b/po/cs.po index 33b3228..3e102c6 100644 --- a/po/cs.po +++ b/po/cs.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: xfce4-hamster-plugin 0.0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-04-05 17:49+0200\n" +"POT-Creation-Date: 2023-07-11 18:00+0200\n" "PO-Revision-Date: 2018-08-06 16:43+0200\n" "Last-Translator: Pavel Borecki \n" "Language-Team: Czech\n" @@ -18,15 +18,20 @@ msgstr "" "Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n" "X-Generator: Poedit 2.0.4\n" +#: ../panel-plugin/view.c:765 +#, c-format +msgid "%dh %dmin" +msgstr "" + #: ../panel-plugin/settings.c:44 msgid "Settings" msgstr "Nastavení" -#: ../panel-plugin/view.c:706 +#: ../panel-plugin/view.c:632 msgid "Add earlier activity" msgstr "Přidat dřívější aktivitu" -#: ../panel-plugin/view.c:672 +#: ../panel-plugin/view.c:604 msgid "Edit activity" msgstr "Upravit aktivitu" @@ -34,7 +39,7 @@ msgstr "Upravit aktivitu" msgid "Entry completion as dropdown" msgstr "Dokončení položky jako rozbalovací nabídka" -#: ../panel-plugin/settings.c:33 ../panel-plugin/hamster.desktop.in.h:1 +#: ../panel-plugin/settings.c:34 ../panel-plugin/hamster.desktop.in.h:1 msgid "Hamster" msgstr "Hamster" @@ -42,11 +47,11 @@ msgstr "Hamster" msgid "Keep popup floating" msgstr "Ponechat vyskakovací okno otevřené" -#: ../panel-plugin/view.c:965 +#: ../panel-plugin/view.c:889 msgid "No activities yet." msgstr "Doposud žádné aktivity." -#: ../panel-plugin/view.c:678 +#: ../panel-plugin/view.c:607 msgid "Resume activity" msgstr "Pokračovat v aktivitě" @@ -55,7 +60,7 @@ msgid "Sanitize label width" msgstr "Přizpůsobit šířku štítku" #. menuish buttons -#: ../panel-plugin/view.c:692 +#: ../panel-plugin/view.c:620 msgid "Show overview" msgstr "Zobrazit přehled" @@ -63,28 +68,28 @@ msgstr "Zobrazit přehled" msgid "Show tooltips on buttons" msgstr "Zobrazovat popisky tlačítek" -#: ../panel-plugin/view.c:699 +#: ../panel-plugin/view.c:626 msgid "Stop tracking" msgstr "Zastavit sledování" -#: ../panel-plugin/settings.c:35 ../panel-plugin/hamster.desktop.in.h:2 +#: ../panel-plugin/settings.c:38 ../panel-plugin/hamster.desktop.in.h:2 msgid "Time bookkeeping plugin" msgstr "Zásuvný modul pro evidenci času" #. label -#: ../panel-plugin/view.c:616 +#: ../panel-plugin/view.c:564 msgid "Today's activities" msgstr "Dnešní aktivity" -#: ../panel-plugin/view.c:713 +#: ../panel-plugin/view.c:638 msgid "Tracking settings" msgstr "Nastavení sledování" #. subtitle -#: ../panel-plugin/view.c:602 +#: ../panel-plugin/view.c:552 msgid "What goes on?" msgstr "Čím se právě zabýváte?" -#: ../panel-plugin/view.c:1061 +#: ../panel-plugin/view.c:957 msgid "inactive" msgstr "neaktivní" diff --git a/po/de.po b/po/de.po index dace67d..faf032b 100644 --- a/po/de.po +++ b/po/de.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: xfce4-hamster-plugin 0.0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-04-05 17:49+0200\n" +"POT-Creation-Date: 2023-07-11 18:00+0200\n" "PO-Revision-Date: 2016-07-27 16:19+0100\n" "Last-Translator: Hakan Erduman \n" "Language-Team: German\n" @@ -18,15 +18,20 @@ msgstr "" "Plural-Forms: nplurals=2; plural=(n != 1);\n" "X-Generator: Poedit 1.5.4\n" +#: ../panel-plugin/view.c:765 +#, c-format +msgid "%dh %dmin" +msgstr "" + #: ../panel-plugin/settings.c:44 msgid "Settings" msgstr "Einstellungen" -#: ../panel-plugin/view.c:706 +#: ../panel-plugin/view.c:632 msgid "Add earlier activity" msgstr "Frühere Aktivität erfassen" -#: ../panel-plugin/view.c:672 +#: ../panel-plugin/view.c:604 msgid "Edit activity" msgstr "Aktivität bearbeiten" @@ -34,7 +39,7 @@ msgstr "Aktivität bearbeiten" msgid "Entry completion as dropdown" msgstr "Vervollständigung als Kombinationsbox" -#: ../panel-plugin/settings.c:33 ../panel-plugin/hamster.desktop.in.h:1 +#: ../panel-plugin/settings.c:34 ../panel-plugin/hamster.desktop.in.h:1 msgid "Hamster" msgstr "Hamster" @@ -42,11 +47,11 @@ msgstr "Hamster" msgid "Keep popup floating" msgstr "Dialog offen lassen" -#: ../panel-plugin/view.c:965 +#: ../panel-plugin/view.c:889 msgid "No activities yet." msgstr "Zurzeit keine Aktivitäten." -#: ../panel-plugin/view.c:678 +#: ../panel-plugin/view.c:607 msgid "Resume activity" msgstr "Aktivität fortsetzen" @@ -55,7 +60,7 @@ msgid "Sanitize label width" msgstr "Leistenschaltfläche verkürzt darstellen" #. menuish buttons -#: ../panel-plugin/view.c:692 +#: ../panel-plugin/view.c:620 msgid "Show overview" msgstr "Übersicht anzeigen" @@ -63,28 +68,28 @@ msgstr "Übersicht anzeigen" msgid "Show tooltips on buttons" msgstr "Kurzhilfen auf Schaltflächen anzeigen" -#: ../panel-plugin/view.c:699 +#: ../panel-plugin/view.c:626 msgid "Stop tracking" msgstr "Erfassung anhalten" -#: ../panel-plugin/settings.c:35 ../panel-plugin/hamster.desktop.in.h:2 +#: ../panel-plugin/settings.c:38 ../panel-plugin/hamster.desktop.in.h:2 msgid "Time bookkeeping plugin" msgstr "Plug-In zur Zeiterfassung" #. label -#: ../panel-plugin/view.c:616 +#: ../panel-plugin/view.c:564 msgid "Today's activities" msgstr "Heutige Aktivitäten" -#: ../panel-plugin/view.c:713 +#: ../panel-plugin/view.c:638 msgid "Tracking settings" msgstr "Einstellungen Zeiterfassung" #. subtitle -#: ../panel-plugin/view.c:602 +#: ../panel-plugin/view.c:552 msgid "What goes on?" msgstr "Was liegt an?" -#: ../panel-plugin/view.c:1061 +#: ../panel-plugin/view.c:957 msgid "inactive" msgstr "inaktiv" diff --git a/po/es.po b/po/es.po index b764188..6db3392 100644 --- a/po/es.po +++ b/po/es.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: xfce4-hamster-plugin 0.0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-04-05 17:49+0200\n" +"POT-Creation-Date: 2023-07-11 18:00+0200\n" "PO-Revision-Date: 2016-08-04 11:36+0200\n" "Last-Translator: Hakan Erduman \n" "Language-Team: Spanish\n" @@ -18,15 +18,20 @@ msgstr "" "Plural-Forms: nplurals=2; plural=(n != 1);\n" "X-Generator: Poedit 1.8.7.1\n" +#: ../panel-plugin/view.c:765 +#, c-format +msgid "%dh %dmin" +msgstr "" + #: ../panel-plugin/settings.c:44 msgid "Settings" msgstr "Preferencias" -#: ../panel-plugin/view.c:706 +#: ../panel-plugin/view.c:632 msgid "Add earlier activity" msgstr "Agregar actividad anterior" -#: ../panel-plugin/view.c:672 +#: ../panel-plugin/view.c:604 msgid "Edit activity" msgstr "Editar actividad" @@ -34,7 +39,7 @@ msgstr "Editar actividad" msgid "Entry completion as dropdown" msgstr "Autocompletado desplegable" -#: ../panel-plugin/settings.c:33 ../panel-plugin/hamster.desktop.in.h:1 +#: ../panel-plugin/settings.c:34 ../panel-plugin/hamster.desktop.in.h:1 msgid "Hamster" msgstr "Hamster" @@ -42,11 +47,11 @@ msgstr "Hamster" msgid "Keep popup floating" msgstr "Mantener abierta la ventana" -#: ../panel-plugin/view.c:965 +#: ../panel-plugin/view.c:889 msgid "No activities yet." msgstr "Sin actividad aun." -#: ../panel-plugin/view.c:678 +#: ../panel-plugin/view.c:607 msgid "Resume activity" msgstr "Retomar actividad" @@ -56,7 +61,7 @@ msgid "Sanitize label width" msgstr "Limitar ancho de la etiqueta" #. menuish buttons -#: ../panel-plugin/view.c:692 +#: ../panel-plugin/view.c:620 msgid "Show overview" msgstr "Mostrar resumen" @@ -64,29 +69,29 @@ msgstr "Mostrar resumen" msgid "Show tooltips on buttons" msgstr "Mostrar ayuda en los botones" -#: ../panel-plugin/view.c:699 +#: ../panel-plugin/view.c:626 msgid "Stop tracking" msgstr "Detener el registro" -#: ../panel-plugin/settings.c:35 ../panel-plugin/hamster.desktop.in.h:2 +#: ../panel-plugin/settings.c:38 ../panel-plugin/hamster.desktop.in.h:2 msgid "Time bookkeeping plugin" msgstr "Complemento de registro de tiempo" #. label -#: ../panel-plugin/view.c:616 +#: ../panel-plugin/view.c:564 msgid "Today's activities" msgstr "Actividades del día" -#: ../panel-plugin/view.c:713 +#: ../panel-plugin/view.c:638 msgid "Tracking settings" msgstr "Preferencias de registro" #. subtitle -#: ../panel-plugin/view.c:602 +#: ../panel-plugin/view.c:552 msgid "What goes on?" msgstr "¿Qué está pasando?" # Is the person inactive or the tracking? -#: ../panel-plugin/view.c:1061 +#: ../panel-plugin/view.c:957 msgid "inactive" msgstr "sin actividad" diff --git a/po/ru.po b/po/ru.po index edb0d87..1bedcff 100644 --- a/po/ru.po +++ b/po/ru.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: xfce4-hamster-plugin 0.0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-04-05 17:49+0200\n" +"POT-Creation-Date: 2023-07-11 18:00+0200\n" "PO-Revision-Date: 2016-07-20 13:37+0300\n" "Last-Translator: Sergey Panasenko \n" "Language-Team: Russian\n" @@ -17,15 +17,20 @@ msgstr "" "X-Poedit-Basepath: ../panel-plugin\n" "X-Poedit-SearchPath-0: .\n" +#: ../panel-plugin/view.c:765 +#, c-format +msgid "%dh %dmin" +msgstr "" + #: ../panel-plugin/settings.c:44 msgid "Settings" msgstr "Установки" -#: ../panel-plugin/view.c:706 +#: ../panel-plugin/view.c:632 msgid "Add earlier activity" msgstr "Добавить предыдущие" -#: ../panel-plugin/view.c:672 +#: ../panel-plugin/view.c:604 msgid "Edit activity" msgstr "Редактировать" @@ -33,7 +38,7 @@ msgstr "Редактировать" msgid "Entry completion as dropdown" msgstr "Завершение ввода в раскрывающемся списке" -#: ../panel-plugin/settings.c:33 ../panel-plugin/hamster.desktop.in.h:1 +#: ../panel-plugin/settings.c:34 ../panel-plugin/hamster.desktop.in.h:1 msgid "Hamster" msgstr "Хомяк (Hamster)" @@ -42,11 +47,11 @@ msgstr "Хомяк (Hamster)" msgid "Keep popup floating" msgstr "Сохранить всплывающее окно" -#: ../panel-plugin/view.c:965 +#: ../panel-plugin/view.c:889 msgid "No activities yet." msgstr "Нет деятельности сейчас." -#: ../panel-plugin/view.c:678 +#: ../panel-plugin/view.c:607 msgid "Resume activity" msgstr "Продолжить" @@ -55,7 +60,7 @@ msgid "Sanitize label width" msgstr "" #. menuish buttons -#: ../panel-plugin/view.c:692 +#: ../panel-plugin/view.c:620 msgid "Show overview" msgstr "Показать обзор" @@ -63,28 +68,28 @@ msgstr "Показать обзор" msgid "Show tooltips on buttons" msgstr "Показывать подсказки на кнопках" -#: ../panel-plugin/view.c:699 +#: ../panel-plugin/view.c:626 msgid "Stop tracking" msgstr "Остановить учет" -#: ../panel-plugin/settings.c:35 ../panel-plugin/hamster.desktop.in.h:2 +#: ../panel-plugin/settings.c:38 ../panel-plugin/hamster.desktop.in.h:2 msgid "Time bookkeeping plugin" msgstr "Плагин учета времени" #. label -#: ../panel-plugin/view.c:616 +#: ../panel-plugin/view.c:564 msgid "Today's activities" msgstr "Активность сегодня" -#: ../panel-plugin/view.c:713 +#: ../panel-plugin/view.c:638 msgid "Tracking settings" msgstr "Установки учета" #. subtitle -#: ../panel-plugin/view.c:602 +#: ../panel-plugin/view.c:552 msgid "What goes on?" msgstr "Что происходит?" -#: ../panel-plugin/view.c:1061 +#: ../panel-plugin/view.c:957 msgid "inactive" msgstr "нет деятельности" diff --git a/po/tr.po b/po/tr.po index 70f1e7a..ffe2417 100644 --- a/po/tr.po +++ b/po/tr.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: xfce4-hamster-plugin 0.0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-04-05 17:49+0200\n" +"POT-Creation-Date: 2023-07-11 18:00+0200\n" "PO-Revision-Date: 2016-07-27 16:24+0100\n" "Last-Translator: Hakan Erduman \n" "Language-Team: Turkish\n" @@ -18,15 +18,20 @@ msgstr "" "Plural-Forms: nplurals=2; plural=(n != 1);\n" "X-Generator: Poedit 1.5.4\n" +#: ../panel-plugin/view.c:765 +#, c-format +msgid "%dh %dmin" +msgstr "" + #: ../panel-plugin/settings.c:44 msgid "Settings" msgstr "Seçenekler" -#: ../panel-plugin/view.c:706 +#: ../panel-plugin/view.c:632 msgid "Add earlier activity" msgstr "Önceki etkinliği ekle" -#: ../panel-plugin/view.c:672 +#: ../panel-plugin/view.c:604 msgid "Edit activity" msgstr "Etkinliği düzenle" @@ -34,7 +39,7 @@ msgstr "Etkinliği düzenle" msgid "Entry completion as dropdown" msgstr "Açılır gibi giriş tamamlama" -#: ../panel-plugin/settings.c:33 ../panel-plugin/hamster.desktop.in.h:1 +#: ../panel-plugin/settings.c:34 ../panel-plugin/hamster.desktop.in.h:1 msgid "Hamster" msgstr "Hamster" @@ -42,11 +47,11 @@ msgstr "Hamster" msgid "Keep popup floating" msgstr "İletişimi açık tut" -#: ../panel-plugin/view.c:965 +#: ../panel-plugin/view.c:889 msgid "No activities yet." msgstr "Şimdilik etkinlik yok." -#: ../panel-plugin/view.c:678 +#: ../panel-plugin/view.c:607 msgid "Resume activity" msgstr "Etkinliğe devam et" @@ -55,7 +60,7 @@ msgid "Sanitize label width" msgstr "Panel düğmesindeki etkinliği kısa kes" #. menuish buttons -#: ../panel-plugin/view.c:692 +#: ../panel-plugin/view.c:620 msgid "Show overview" msgstr "Genel görünüm" @@ -63,28 +68,28 @@ msgstr "Genel görünüm" msgid "Show tooltips on buttons" msgstr "Düğmelerde araç ipuçlarını göster" -#: ../panel-plugin/view.c:699 +#: ../panel-plugin/view.c:626 msgid "Stop tracking" msgstr "Takibi durdur" -#: ../panel-plugin/settings.c:35 ../panel-plugin/hamster.desktop.in.h:2 +#: ../panel-plugin/settings.c:38 ../panel-plugin/hamster.desktop.in.h:2 msgid "Time bookkeeping plugin" msgstr "Zaman takipçisi" #. label -#: ../panel-plugin/view.c:616 +#: ../panel-plugin/view.c:564 msgid "Today's activities" msgstr "Bugünki etkinlikler" -#: ../panel-plugin/view.c:713 +#: ../panel-plugin/view.c:638 msgid "Tracking settings" msgstr "Takip tercihleri" #. subtitle -#: ../panel-plugin/view.c:602 +#: ../panel-plugin/view.c:552 msgid "What goes on?" msgstr "Ne var, ne yok?" -#: ../panel-plugin/view.c:1061 +#: ../panel-plugin/view.c:957 msgid "inactive" msgstr "durgun" diff --git a/po/uk.po b/po/uk.po index c37103c..b926fa2 100644 --- a/po/uk.po +++ b/po/uk.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: xfce4-hamster-plugin 0.0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-04-05 17:49+0200\n" +"POT-Creation-Date: 2023-07-11 18:00+0200\n" "PO-Revision-Date: 2016-07-20 13:49+0300\n" "Last-Translator: Sergey Panasenko \n" "Language-Team: Russian\n" @@ -17,15 +17,20 @@ msgstr "" "X-Poedit-Basepath: ../panel-plugin\n" "X-Poedit-SearchPath-0: .\n" +#: ../panel-plugin/view.c:765 +#, c-format +msgid "%dh %dmin" +msgstr "" + #: ../panel-plugin/settings.c:44 msgid "Settings" msgstr "Налаштування" -#: ../panel-plugin/view.c:706 +#: ../panel-plugin/view.c:632 msgid "Add earlier activity" msgstr "Додати попередню діяльність" -#: ../panel-plugin/view.c:672 +#: ../panel-plugin/view.c:604 msgid "Edit activity" msgstr "Редагувати" @@ -33,7 +38,7 @@ msgstr "Редагувати" msgid "Entry completion as dropdown" msgstr "Завершення введення у вигляді списку" -#: ../panel-plugin/settings.c:33 ../panel-plugin/hamster.desktop.in.h:1 +#: ../panel-plugin/settings.c:34 ../panel-plugin/hamster.desktop.in.h:1 msgid "Hamster" msgstr "Хом'як (Hamster)" @@ -42,11 +47,11 @@ msgstr "Хом'як (Hamster)" msgid "Keep popup floating" msgstr "Тримати спливаюче вікно" -#: ../panel-plugin/view.c:965 +#: ../panel-plugin/view.c:889 msgid "No activities yet." msgstr "Ніякої діяльності." -#: ../panel-plugin/view.c:678 +#: ../panel-plugin/view.c:607 msgid "Resume activity" msgstr "Продовжити" @@ -55,7 +60,7 @@ msgid "Sanitize label width" msgstr "" #. menuish buttons -#: ../panel-plugin/view.c:692 +#: ../panel-plugin/view.c:620 msgid "Show overview" msgstr "Показати огляд" @@ -63,28 +68,28 @@ msgstr "Показати огляд" msgid "Show tooltips on buttons" msgstr "Показати підказки до кнопок" -#: ../panel-plugin/view.c:699 +#: ../panel-plugin/view.c:626 msgid "Stop tracking" msgstr "Припинити облік" -#: ../panel-plugin/settings.c:35 ../panel-plugin/hamster.desktop.in.h:2 +#: ../panel-plugin/settings.c:38 ../panel-plugin/hamster.desktop.in.h:2 msgid "Time bookkeeping plugin" msgstr "Плагін обліку часу" #. label -#: ../panel-plugin/view.c:616 +#: ../panel-plugin/view.c:564 msgid "Today's activities" msgstr "Діяльність за сьогодні" -#: ../panel-plugin/view.c:713 +#: ../panel-plugin/view.c:638 msgid "Tracking settings" msgstr "Налаштування обліку" #. subtitle -#: ../panel-plugin/view.c:602 +#: ../panel-plugin/view.c:552 msgid "What goes on?" msgstr "Що відбувається?" -#: ../panel-plugin/view.c:1061 +#: ../panel-plugin/view.c:957 msgid "inactive" msgstr "не дію"